guts
gutilities Namespace Reference

Enumerations

enum  randomModel { uniform , gaussian , cosine , sphere }
 Enumeration of random models. More...
 

Functions

string removeLeadingAndTrailingSpacesFromString (const std::string &input)
 Removes leading and trailing spaces and tabs from a string. More...
 
string removeAllSpacesFromString (const std::string &str)
 Removes all spaces from a string. More...
 
string getFileFromPath (const std::string &path)
 Extracts the filename from a given file path. More...
 
string getDirFromPath (const std::string &path)
 Extracts the directory path from a given file path. More...
 
vector< std::string > getStringVectorFromString (const std::string &input)
 Splits a string into a vector of strings using spaces as delimiters. More...
 
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. More...
 
string replaceAllStringsWithString (const string &source, const string &from, const string &to)
 Replaces all occurrences of a substring with another string. More...
 
string fillDigits (const string &word, const string &c, int ndigits)
 Pads a string with a specified character until it reaches a desired length. More...
 
double getG4Number (const string &v, bool warnIfNotUnit=false)
 Converts a string representation of a number with optional units to a double. More...
 
double getG4Number (double input, const string &unit)
 Converts a numeric value with a unit into a G4 number format and returns the converted value. More...
 
vector< double > getG4NumbersFromStringVector (const vector< string > &vstring, bool warnIfNotUnit=false)
 Converts a vector of strings representing numbers with units to a vector of doubles. More...
 
vector< double > getG4NumbersFromString (const string &vstring, bool warnIfNotUnit=false)
 Converts a comma-separated string of numbers with units to a vector of doubles. More...
 
string parseFileAndRemoveComments (const string &filename, const string &commentChars="#", int verbosity=0)
 Parses a file and removes all lines containing specified comment characters. More...
 
string retrieveStringBetweenChars (const string &input, const string &firstDelimiter, const string &secondDelimiter)
 Retrieves a substring between two specified delimiters in a string. More...
 
vector< string > getStringVectorFromStringWithDelimiter (const string &input, const string &x)
 Splits a string into a vector of substrings using a specified delimiter. More...
 
bool directoryExists (const std::string &path)
 Checks if a directory exists at the given path. More...
 
string searchForDirInLocations (const string &dirName, const vector< string > &possibleLocations)
 Searches for a directory within a list of possible locations. More...
 
bool hasExtension (const string &filename, const vector< string > &extensions)
 Checks if a filename has one of the specified extensions. More...
 
vector< string > getListOfFilesInDirectory (const string &dirName, const vector< string > &extensions)
 Retrieves a list of files with specific extensions from a directory. More...
 
string convertToLowercase (const string &str)
 Converts a string to lowercase. More...
 
template<class KEY , class VALUE >
vector< KEY > getKeys (const map< KEY, VALUE > &map)
 Retrieves all keys from a map. More...
 
randomModel stringToRandomModel (const std::string &str)
 Converts a string to a corresponding randomModel enum value. More...
 

Enumeration Type Documentation

◆ randomModel

Enumerator
uniform 

Uniform distribution.

gaussian 

Gaussian distribution.

cosine 

Cosine distribution.

sphere 

Sphere distribution.

Definition at line 275 of file gutilities.h.

Function Documentation

◆ convertToLowercase()

string gutilities::convertToLowercase ( const string &  str)

This function transforms all characters in the input string to lowercase.

Parameters
strThe string to convert.
Returns
The lowercase version of the input string.

Definition at line 360 of file gutilities.cc.

◆ directoryExists()

bool gutilities::directoryExists ( const std::string &  path)

This function checks the file system to determine whether a directory exists at the specified path.

Parameters
pathThe path to check for a directory.
Returns
true if the directory exists, false otherwise.

Definition at line 309 of file gutilities.cc.

◆ fillDigits()

string gutilities::fillDigits ( const string &  word,
const string &  c,
int  ndigits 
)

This function prepends the specified character to the given word until its length is equal to the specified number of digits.

Parameters
wordThe original string to be padded.
cThe character to use for padding.
ndigitsThe target length of the padded string.
Returns
A new string padded to the specified length.

Definition at line 102 of file gutilities.cc.

◆ getDirFromPath()

std::string gutilities::getDirFromPath ( const std::string &  path)

This function extracts and returns the directory path from a given POSIX file path.

Parameters
pathThe input file path.
Returns
The directory path extracted from the path.

Definition at line 48 of file gutilities.cc.

◆ getFileFromPath()

std::string gutilities::getFileFromPath ( const std::string &  path)

This function extracts and returns the filename from a given POSIX file path.

Parameters
pathThe input file path.
Returns
The filename extracted from the path.

Definition at line 39 of file gutilities.cc.

◆ getG4Number() [1/2]

double gutilities::getG4Number ( const string &  v,
bool  warnIfNotUnit = false 
)

This function extracts the numeric value from the input string and multiplies it by the appropriate unit conversion factor. If no units are specified, it issues a warning if warnIfNotUnit is true and the value is non-zero.

Parameters
vThe input string containing the number and optional units, formatted as "number*unit".
warnIfNotUnitFlag indicating whether to issue a warning if the units are not present.
Returns
The numeric value converted to a double, taking into account the units if provided.

Definition at line 117 of file gutilities.cc.

◆ getG4Number() [2/2]

double gutilities::getG4Number ( double  input,
const string &  unit 
)

This function concatenates a numeric value and a unit into a G4 number format and then converts it to the appropriate unit.

Parameters
inputThe numeric value to convert.
unitThe unit associated with the numeric value.
Returns
The converted numeric value as a double.

Definition at line 191 of file gutilities.cc.

◆ getG4NumbersFromString()

vector< double > gutilities::getG4NumbersFromString ( const string &  vstring,
bool  warnIfNotUnit = false 
)

This function splits the input string by commas and converts each segment to a double, taking into account the specified units.

Parameters
vstringA comma-separated string of numbers with optional units.
warnIfNotUnitFlag indicating whether to issue a warning if the units are not present.
Returns
A vector of doubles representing the converted numeric values.

Definition at line 207 of file gutilities.cc.

◆ getG4NumbersFromStringVector()

vector< double > gutilities::getG4NumbersFromStringVector ( const vector< string > &  vstring,
bool  warnIfNotUnit = false 
)

This function parses each string in the input vector and converts it into a double, taking into account the specified units.

Parameters
vstringA vector of strings, each containing a number with optional units.
warnIfNotUnitFlag indicating whether to issue a warning if the units are not present.
Returns
A vector of doubles representing the converted numeric values.

Definition at line 196 of file gutilities.cc.

◆ getKeys()

template<class KEY , class VALUE >
vector< KEY > gutilities::getKeys ( const map< KEY, VALUE > &  map)

This function extracts and returns all the keys from the given map.

Template Parameters
KEYThe type of keys in the map.
VALUEThe type of values in the map.
Parameters
mapThe map from which to extract keys.
Returns
A vector containing all the keys from the map.

Definition at line 368 of file gutilities.cc.

◆ getListOfFilesInDirectory()

vector< string > gutilities::getListOfFilesInDirectory ( const string &  dirName,
const vector< string > &  extensions 
)

This function opens the specified directory and retrieves a list of files that match the given extensions.

Parameters
dirNameThe name of the directory to search in.
extensionsA vector of file extensions to filter the files.
Returns
A vector of file names that have the specified extensions.

Definition at line 338 of file gutilities.cc.

◆ getStringVectorFromString()

std::vector< std::string > gutilities::getStringVectorFromString ( const std::string &  input)

This function splits the input string into a vector of strings, using spaces as the delimiter, and removes leading and trailing spaces from each substring.

Parameters
inputThe input string to split.
Returns
A vector of strings obtained by splitting the input string.

Definition at line 54 of file gutilities.cc.

◆ getStringVectorFromStringWithDelimiter()

vector< string > gutilities::getStringVectorFromStringWithDelimiter ( const string &  input,
const string &  x 
)

This function splits the input string by the given single-character delimiter and returns the substrings as a vector.

Parameters
inputThe input string to split.
xThe delimiter character used to split the string.
Returns
A vector of strings containing the split substrings.

Definition at line 250 of file gutilities.cc.

◆ hasExtension()

bool gutilities::hasExtension ( const string &  filename,
const vector< string > &  extensions 
)

This function checks whether a given filename ends with any of the extensions specified in a list.

Parameters
filenameThe name of the file to check.
extensionsA vector of extensions to check against.
Returns
true if the filename has one of the specified extensions, false otherwise.

Definition at line 328 of file gutilities.cc.

◆ parseFileAndRemoveComments()

string gutilities::parseFileAndRemoveComments ( const string &  filename,
const string &  commentChars = "#",
int  verbosity = 0 
)

This function reads the content of a file, removes lines containing the specified comment characters, and returns the processed string.

Parameters
filenameThe name of the file to parse.
commentCharsThe characters indicating the start of a comment in the file.
verbosityThe verbosity level for logging information.
Returns
A string representing the content of the file with comments removed.

Definition at line 212 of file gutilities.cc.

◆ removeAllSpacesFromString()

std::string gutilities::removeAllSpacesFromString ( const std::string &  str)

This function removes all spaces from the input string and returns the modified string.

Parameters
strThe input string from which spaces will be removed.
Returns
A new string with all spaces removed.

Definition at line 33 of file gutilities.cc.

◆ removeLeadingAndTrailingSpacesFromString()

std::string gutilities::removeLeadingAndTrailingSpacesFromString ( const std::string &  input)

This function trims any whitespace, including spaces and tabs, from both the beginning and the end of the input string.

Parameters
inputThe string to be trimmed.
Returns
A new string with leading and trailing spaces and tabs removed.

Definition at line 20 of file gutilities.cc.

◆ replaceAllStringsWithString()

string gutilities::replaceAllStringsWithString ( const string &  source,
const string &  from,
const string &  to 
)

This function searches for all occurrences of the specified substring in the source string and replaces them with the provided replacement string.

Parameters
sourceThe original string where replacements will occur.
fromThe substring to be replaced.
toThe string to replace each occurrence of the substring.
Returns
A new string with all occurrences of the substring replaced.

Definition at line 80 of file gutilities.cc.

◆ replaceCharInStringWithChars()

std::string gutilities::replaceCharInStringWithChars ( const std::string &  input,
const std::string &  toReplace,
const std::string &  replacement 
)

This function replaces every occurrence of any character from the 'toReplace' string in the input string with the specified replacement string.

Parameters
inputThe input string in which characters are to be replaced.
toReplaceA string containing characters to be replaced.
replacementThe string to replace each occurrence of characters in 'toReplace'.
Returns
A new string with specified characters replaced by the replacement string.

Definition at line 68 of file gutilities.cc.

◆ retrieveStringBetweenChars()

string gutilities::retrieveStringBetweenChars ( const string &  input,
const string &  firstDelimiter,
const string &  secondDelimiter 
)

This function extracts and returns the substring found between the first and second delimiters within the input string.

Parameters
inputThe input string containing the delimiters.
firstDelimiterThe delimiter marking the start of the substring.
secondDelimiterThe delimiter marking the end of the substring.
Returns
The substring found between the specified delimiters, or an empty string if delimiters are not found.

Definition at line 240 of file gutilities.cc.

◆ searchForDirInLocations()

string gutilities::searchForDirInLocations ( const string &  dirName,
const vector< string > &  possibleLocations 
)

This function iterates over a list of possible locations to find the first directory that matches the specified name.

Parameters
dirNameThe name of the directory to search for.
possibleLocationsA vector of paths where the directory might be located.
Returns
The path to the found directory or "UNINITIALIZEDSTRINGQUANTITY" if not found.

Definition at line 317 of file gutilities.cc.

◆ stringToRandomModel()

randomModel gutilities::stringToRandomModel ( const std::string &  str)

This function maps a given string to its corresponding randomModel enum value. If the string does not match any known model, an exception is thrown.

Parameters
strThe string representation of the random model.
Returns
The corresponding randomModel enum value.
Exceptions
std::invalid_argumentif the string does not match any valid model.

Definition at line 379 of file gutilities.cc.