10 #include "G4Colour.hh"
83 const std::string& replacement);
110 string fillDigits(
const string& word,
const string& c,
int ndigits);
122 double getG4Number(
const string& v,
bool warnIfNotUnit =
false);
133 double getG4Number(
double input,
const string& unit);
226 bool hasExtension(
const string& filename,
const vector<string>& extensions);
259 template <
class KEY,
class VALUE>
260 vector<KEY>
getKeys(
const map<KEY, VALUE>& map);
286 case uniform:
return "uniform";
288 case cosine:
return "cosine";
289 case sphere:
return "sphere";
308 #include <filesystem>
310 #if defined(__APPLE__)
311 #include <mach-o/dyld.h>
312 #elif defined(__linux__)
315 #elif defined(_WIN32)
319 #error "Unsupported platform"
326 #if defined(__APPLE__)
328 uint32_t sz =
sizeof(buf);
329 if (_NSGetExecutablePath(buf, &sz) != 0) {
330 std::string big(sz,
'\0');
331 if (_NSGetExecutablePath(big.data(), &sz) != 0)
332 throw std::runtime_error(
"_NSGetExecutablePath failed");
333 return std::filesystem::canonical(big);
335 return std::filesystem::canonical(buf);
337 #elif defined(__linux__)
339 ssize_t len = ::readlink(
"/proc/self/exe", buf,
sizeof(buf)-1);
341 throw std::runtime_error(
"readlink(/proc/self/exe) failed");
343 return std::filesystem::canonical(buf);
345 #elif defined(_WIN32)
346 std::wstring buf(MAX_PATH, L
'\0');
347 DWORD len = ::GetModuleFileNameW(
nullptr, buf.data(), buf.size());
349 throw std::runtime_error(
"GetModuleFileNameW failed");
352 if (len == buf.size()) {
354 len = ::GetModuleFileNameW(
nullptr, buf.data(), buf.size());
357 return std::filesystem::canonical(std::filesystem::path(buf));
367 if (!std::filesystem::exists(
gemc_root /
"api"))
368 throw std::runtime_error(
"Cannot locate directory >api< check directory layout");
string replaceAllStringsWithString(const string &source, const string &from, const string &to)
Replaces all occurrences of a substring with another string.
double getG4Number(const string &v, bool warnIfNotUnit)
Converts a string representation of a number with optional units to a double.
bool hasExtension(const std::string &filename, const std::vector< std::string > &extensions)
Checks if a filename has one of the specified extensions.
vector< double > getG4NumbersFromString(const string &vstring, bool warnIfNotUnit)
Converts a comma-separated string of numbers with units to a vector of doubles.
string removeAllSpacesFromString(const std::string &str)
Removes all spaces from a string.
std::filesystem::path executable_path()
vector< string > getStringVectorFromStringWithDelimiter(const string &input, const string &x)
Splits a string into a vector of substrings using a specified delimiter.
randomModel stringToRandomModel(const std::string &str)
Converts a string to a corresponding randomModel enum value.
std::filesystem::path gemc_root()
constexpr const char * to_string(randomModel m) noexcept
vector< string > getListOfFilesInDirectory(const string &dirName, const vector< string > &extensions)
Retrieves a list of files with specific extensions from a directory.
vector< double > getG4NumbersFromStringVector(const vector< string > &vstring, bool warnIfNotUnit)
Converts a vector of strings representing numbers with units to a vector of doubles.
string retrieveStringBetweenChars(const string &input, const string &firstDelimiter, const string &secondDelimiter)
Retrieves a substring between two specified delimiters in a string.
string replaceCharInStringWithChars(const std::string &input, const std::string &toReplace, const std::string &replacement)
Replaces all occurrences of specified characters in a string with another string.
string fillDigits(const string &word, const string &c, int ndigits)
Pads a string with a specified character until it reaches a desired length.
randomModel
Enumeration of random models.
@ gaussian
Gaussian distribution.
@ uniform
Uniform distribution.
@ sphere
Sphere distribution.
@ cosine
Cosine distribution.
string getDirFromPath(const std::string &path)
Extracts the directory path from a given file path.
string convertToLowercase(const string &str)
Converts a string to lowercase.
bool directoryExists(const std::string &path)
Checks if a directory exists at the given path.
G4Colour makeColour(std::string_view code)
Convert a hex colour string to G4Colour.
vector< KEY > getKeys(const map< KEY, VALUE > &map)
Retrieves all keys from a map.
string removeLeadingAndTrailingSpacesFromString(const std::string &input)
Removes leading and trailing spaces and tabs from a string.
string searchForDirInLocations(const string &dirName, const vector< string > &possibleLocations)
Searches for a directory within a list of possible locations.
string parseFileAndRemoveComments(const string &filename, const string &commentChars, int verbosity)
Parses a file and removes all lines containing specified comment characters.
string getFileFromPath(const std::string &path)
Extracts the filename from a given file path.
vector< std::string > getStringVectorFromString(const std::string &input)
Splits a string into a vector of strings using spaces as delimiters.