13#include "G4SystemOfUnits.hh"
14#include "G4UnitsTable.hh"
19 inline constexpr G4double
nanogray = 1.e-9 * gray;
20 inline constexpr G4double
picogray = 1.e-12 * gray;
118 const std::string& replacement);
147string fillDigits(
const string& word,
const string& c,
int ndigits);
199 const std::vector<std::string>& locations,
200 std::string_view filename);
223 const string& dirName,
const vector<string>& possibleLocations);
236bool hasExtension(
const string& filename,
const vector<string>& extensions);
281double getG4Number(
const string& v,
bool warnIfNotUnit =
false);
293double getG4Number(
double input,
const string& unit);
358 const string& secondDelimiter);
402template <
class KEY,
class VALUE>
403vector<KEY>
getKeys(
const map<KEY, VALUE>& map);
441 case uniform:
return "uniform";
443 case cosine:
return "cosine";
444 case sphere:
return "sphere";
464G4Colour
makeG4Colour(std::string_view code,
double opacity);
472#if defined(__APPLE__)
473#include <mach-o/dyld.h>
474#elif defined(__linux__)
481#error "Unsupported platform"
501#if defined(__APPLE__)
503 uint32_t sz =
sizeof(buf);
504 if (_NSGetExecutablePath(buf, &sz) != 0) {
506 std::string big(sz,
'\0');
507 if (_NSGetExecutablePath(big.data(), &sz) != 0)
508 throw std::runtime_error(
"_NSGetExecutablePath failed");
509 return std::filesystem::canonical(big);
511 return std::filesystem::canonical(buf);
513#elif defined(__linux__)
515 ssize_t len = ::readlink(
"/proc/self/exe", buf,
sizeof(buf) - 1);
517 throw std::runtime_error(
"readlink(/proc/self/exe) failed");
519 return std::filesystem::canonical(buf);
522 std::wstring buf(MAX_PATH, L
'\0');
523 DWORD len = ::GetModuleFileNameW(
nullptr, buf.data(), buf.size());
525 throw std::runtime_error(
"GetModuleFileNameW failed");
528 if (len == buf.size()) {
530 len = ::GetModuleFileNameW(
nullptr, buf.data(), buf.size());
533 return std::filesystem::canonical(std::filesystem::path(buf));
555 std::filesystem::path root;
558 if (exe_dir.filename() ==
"build") {
559 root = exe_dir.parent_path();
562 else if (exe_dir.filename() ==
"bin") {
563 root = exe_dir.parent_path();
564 if (std::filesystem::exists(root /
"build.ninja")) {
566 root = root.parent_path();
567 }
else if (!std::filesystem::exists(root /
"lib")) {
568 throw std::runtime_error(
569 "Cannot locate directory <lib> under " + root.string() +
570 ". Check installation layout."
602inline std::string
success_or_fail(
bool condition) {
return condition ?
"success" :
"fail"; }
constexpr G4double milligray
constexpr G4double nanogray
constexpr G4double microgray
constexpr G4double picogray
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.
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()
Get the absolute canonical path to the current executable.
vector< string > getStringVectorFromStringWithDelimiter(const string &input, const string &x)
Splits a string into a vector of substrings using a specified delimiter.
G4Colour makeG4Colour(std::string_view code, double opacity)
Convert a hex colour string to G4Colour.
randomModel stringToRandomModel(const std::string &str)
Converts a string to a corresponding randomModel enum value.
std::filesystem::path gemc_root()
Infer the GEMC installation root directory from the executable location.
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.
std::string success_or_fail(bool condition)
Convert a boolean condition to a stable status string.
bool is_unset(std::string_view s)
Determine whether a string should be treated as "unset".
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.
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.
std::optional< std::string > searchForFileInLocations(const std::vector< std::string > &locations, std::string_view filename)
Search for a regular file across candidate locations.
void apply_uimanager_commands(const std::string &command)
Apply a single Geant4 UI command if a UI manager is available.
std::optional< std::filesystem::path > 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.
bool hasExtension(const std::string &filename, const std::vector< std::string > &extensions)
string getFileFromPath(const std::string &path)
Extracts the filename from a given file path.
constexpr const char * to_string(randomModel m) noexcept
Convert a randomModel enum value to a stable string token.
vector< std::string > getStringVectorFromString(const std::string &input)
Splits a string into a vector of strings using whitespace as delimiters.