BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
|
Configuration and configuration parser class. More...
#include <Config.hh>
Public Member Functions | |
void | ParseInputFile () |
const std::vector< HistogramDef * > & | HistogramDefinitions (const std::string &treeName) const |
Access all histogram definitions. | |
const std::vector< HistogramDef * > & | HistogramDefinitionsSimple (const std::string &treeName) const |
Access all simple histogram definitions - throws exception if out of range. | |
const std::vector< HistogramDef * > & | HistogramDefinitionsPerEntry (const std::string &treeName) const |
Access all per entry histogram definitions - throws exception if out of range. | |
const std::vector< HistogramDefSet * > & | EventHistogramSetDefinitionsSimple () const |
const std::vector< HistogramDefSet * > & | EventHistogramSetDefinitionsPerEntry () const |
const std::vector< std::string > & | EventParticleSetNamesSimple () const |
const std::vector< std::string > & | EventParticleSetNamesPerEntry () const |
const RBDS::VectorString & | BranchesToBeActivated (const std::string &treeName) const |
const RBDS::BranchMap & | BranchesToBeActivated () const |
Access the map of all branches to be activated per tree. | |
bool | AllBranchesToBeActivated () const |
void | SetBranchToBeActivated (const std::string &treeName, const std::string &branchName) |
Set a branch to be activated if not already. | |
void | PrintHistogramSetDefinitions () const |
std::string | GetOptionString (const std::string &key) const |
General accessor for option. | |
bool | GetOptionBool (const std::string &key) const |
General accessor for option. | |
double | GetOptionNumber (const std::string &key) const |
General accessor for option. | |
std::string | InputFilePath () const |
Accessor. | |
std::string | OutputFileName () const |
Accessor. | |
std::string | CalculateOpticalFunctionsFileName () const |
Accessor. | |
bool | Debug () const |
Accessor. | |
bool | CalculateOpticalFunctions () const |
Accessor. | |
bool | EmittanceOnTheFly () const |
Accessor. | |
bool | ProcessSamplers () const |
Accessor. | |
bool | PrintOut () const |
Accessor. | |
double | PrintModuloFraction () const |
Accessor. | |
bool | PerEntryBeam () const |
bool | PerEntryEvent () const |
bool | PerEntryRun () const |
bool | PerEntryOption () const |
bool | PerEntryModel () const |
Static Public Member Functions | |
static Config * | Instance (const std::string &fileName="", const std::string &inputFilePath="", const std::string &outputFileName="", const std::string &defaultOutputFileSuffix="_ana") |
Singleton accessor. | |
Protected Member Functions | |
Config ()=delete | |
Private constructor for singleton pattern. | |
Config (const std::string &inputFilePathIn, const std::string &outputFileNameIn, const std::string &defaultOutputFileSuffix="_ana") | |
Constructor used when merging only. | |
Config (const std::string &fileNameIn, const std::string &inputFilePathIn, const std::string &outputFileNameIn, const std::string &defaultOutputFileSuffix) | |
Desired constructor, also private for singleton pattern. | |
void | InitialiseOptions (const std::string &analysisFile) |
void | ParseHistogramLine (const std::string &line) |
Parse a line beginning with histogram. Uses other functions if appropriately defined. | |
void | ParseSpectraLine (const std::string &line) |
Parse a spectra definition line. | |
void | ParseParticleSetLine (const std::string &line) |
Parse a particle set line. | |
void | ParseHistogram (const std::string &line, const int nDim) |
Parse everything after the histogram declaration and check all parameters. | |
void | ParsePerEntry (const std::string &name, bool &perEntry) const |
bool | ContainsWordCI (const std::string &input, const std::string &word) const |
Return true if 'input' contains 'word' - CI = case insensitive. | |
void | ParseLog (const std::string &definition, bool &xLog, bool &yLog, bool &zLog) const |
Parse whether each dimension is log or linear. | |
void | UpdateRequiredBranches (const HistogramDef *def) |
void | UpdateRequiredBranches (const std::string &treeName, const std::string &var) |
bool | InvalidTreeName (const std::string &treeName) const |
void | CheckValidTreeName (std::string &treeName) const |
void | ParseBins (const std::string &bins, int nDim, BinSpecification &xBinning, BinSpecification &yBinning, BinSpecification &zBinning) const |
void | ParseBinning (const std::string &binning, int nDim, BinSpecification &xBinning, BinSpecification &yBinning, BinSpecification &zBinning, bool xLog, bool yLog, bool zLog) const |
std::vector< std::string > | SplitOnWhiteSpace (const std::string &line) const |
Return a vector of strings by splitting on whitespace. | |
std::set< ParticleSpec > | ParseParticles (const std::string &word) const |
Parser a list of particle PDG IDs into a set. | |
void | ParseSetting (const std::string &line) |
Parse a settings line in input file and appropriate update member map. | |
std::string | LowerCase (const std::string &st) const |
Return a lower case copy of a string. | |
bool | RegisterHistogramName (const std::string &newHistName) |
ClassDef (Config, 1) | |
Protected Attributes | |
int | lineCounter = 0 |
Index of which line in the file we're on while parsing - for feedback. | |
RBDS::BranchMap | branches |
Cache of which branches need to be activated for this analysis. | |
bool | allBranchesActivated |
Whether all branches will be activated - ie for optics. | |
std::map< std::string, int > | spectraNames |
std::set< std::string > | histogramNames |
Static Protected Attributes | |
static Config * | instance |
static std::vector< std::string > | treeNames |
Vector of permitted tree names. | |
Private Attributes | |
std::map< std::string, std::string > | alternateKeys |
Private members first as required in accessors. | |
std::map< std::string, std::vector< HistogramDef * > > | histoDefs |
std::map< std::string, std::vector< HistogramDef * > > | histoDefsSimple |
Copy of definition used to identify only 'simple' histogram definitions. Doesn't own. | |
std::map< std::string, std::vector< HistogramDef * > > | histoDefsPerEntry |
Copy of definition used to identify only 'per entry' histogram definitions. Doesn't own. | |
std::vector< HistogramDefSet * > | eventHistoDefSetsSimple |
Sets of histogram definitions per particle. Only for event branch. | |
std::vector< HistogramDefSet * > | eventHistoDefSetsPerEntry |
std::vector< std::string > | eventParticleSetBranches |
List of branches in event tree to produce ParticleSet objects on. (per event and simple). | |
std::vector< std::string > | eventParticleSetSimpleBranches |
std::map< std::string, bool > | optionsBool |
Storage of options. | |
std::map< std::string, std::string > | optionsString |
Storage of options. | |
std::map< std::string, double > | optionsNumber |
Storage of options. | |
|
protected |
Constructor used when merging only.
Definition at line 50 of file Config.cc.
References branches, RBDS::DefaultOutputName(), InitialiseOptions(), optionsBool, and optionsString.
|
protected |
Desired constructor, also private for singleton pattern.
Definition at line 75 of file Config.cc.
References RBDS::DefaultOutputName(), InitialiseOptions(), and optionsString.
|
inline |
Boolean whether all branches should be turned on irrespective of map of individual branches to turn on.
Definition at line 122 of file Config.hh.
References allBranchesActivated.
|
inline |
|
inline |
Access all branches that are required for activation. This does not specialise on the leaf inside the branch and if one variable is required, the whole branch will be activated as there isn't much difference. This can of course be revised in future.
Definition at line 114 of file Config.hh.
References branches.
|
inline |
|
inline |
|
protected |
Check whether the tree name ends in a '.' or not and fix it (simple mistake. Then apply InvalidTreeName and throw std::string error if it's a problem.
Definition at line 563 of file Config.cc.
References InvalidTreeName(), and treeNames.
Referenced by ParseHistogram().
|
protected |
Return true if 'input' contains 'word' - CI = case insensitive.
Definition at line 494 of file Config.cc.
References LowerCase().
Referenced by ParseSpectraLine().
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Access all per entry histogram definitions - throws exception if out of range.
Definition at line 99 of file Config.hh.
References histoDefsPerEntry.
|
inline |
Access all simple histogram definitions - throws exception if out of range.
Definition at line 95 of file Config.hh.
References histoDefsSimple.
Referenced by Analysis::SimpleHistograms().
|
protected |
Set defaults in member maps for all options so that the keys can always be accessed.
Definition at line 114 of file Config.cc.
References alternateKeys, branches, histoDefs, histoDefsPerEntry, histoDefsSimple, optionsBool, optionsNumber, optionsString, and treeNames.
Referenced by Config().
|
inline |
|
static |
Singleton accessor.
Definition at line 155 of file Config.cc.
References Config().
Referenced by Analysis::PreparePerEntryHistograms(), Analysis::SimpleHistograms(), and EventAnalysis::SimpleHistograms().
|
protected |
Check if the supplied tree name is one of the static member vector of allowed tree names.
Definition at line 579 of file Config.cc.
References treeNames.
Referenced by CheckValidTreeName().
|
protected |
Return a lower case copy of a string.
Definition at line 762 of file Config.cc.
Referenced by ContainsWordCI(), ParseHistogram(), ParseHistogramLine(), ParseLog(), ParseParticles(), ParsePerEntry(), and ParseSetting().
|
inline |
|
protected |
Parse binning substring and check it has the right number of dimensions. Writes out via reference to pre-existing variables.
Definition at line 602 of file Config.cc.
References lineCounter, and RBDS::LoadBins().
Referenced by ParseHistogram(), and ParseSpectraLine().
|
protected |
Parse the bin substring and check it has the right number of dimensions. Writes out via reference to pre-existing variables.
Definition at line 584 of file Config.cc.
Referenced by ParseHistogram(), and ParseSpectraLine().
|
protected |
Parse everything after the histogram declaration and check all parameters.
Definition at line 278 of file Config.cc.
References CheckValidTreeName(), histoDefs, histoDefsPerEntry, histoDefsSimple, LowerCase(), optionsBool, ParseBinning(), ParseBins(), ParseLog(), ParsePerEntry(), RegisterHistogramName(), and UpdateRequiredBranches().
Referenced by ParseHistogramLine().
|
protected |
Parse a line beginning with histogram. Uses other functions if appropriately defined.
Definition at line 252 of file Config.cc.
References LowerCase(), ParseHistogram(), and ParseSetting().
|
protected |
Parse whether each dimension is log or linear.
Definition at line 502 of file Config.cc.
References LowerCase().
Referenced by ParseHistogram(), and ParseSpectraLine().
|
protected |
Parser a list of particle PDG IDs into a set.
Definition at line 697 of file Config.cc.
References LowerCase().
Referenced by ParseSpectraLine().
|
protected |
Parse a particle set line.
Definition at line 469 of file Config.cc.
References eventParticleSetBranches, ParsePerEntry(), SetBranchToBeActivated(), and SplitOnWhiteSpace().
|
protected |
Check whether a histogram definition word contains the world 'simple' and if so, it's not a per-entry histogram.
Definition at line 488 of file Config.cc.
References LowerCase().
Referenced by ParseHistogram(), ParseParticleSetLine(), and ParseSpectraLine().
|
protected |
Parse a settings line in input file and appropriate update member map.
Definition at line 769 of file Config.cc.
References alternateKeys, LowerCase(), optionsBool, optionsNumber, and optionsString.
Referenced by ParseHistogramLine().
|
protected |
Parse a spectra definition line.
Definition at line 391 of file Config.cc.
References ContainsWordCI(), eventHistoDefSetsSimple, ParseBinning(), ParseBins(), ParseLog(), ParseParticles(), ParsePerEntry(), SetBranchToBeActivated(), spectraNames, and SplitOnWhiteSpace().
|
inline |
Whether per entry loading is needed. Alternative is only TTree->Draw().
Definition at line 139 of file Config.hh.
References optionsBool.
|
inline |
Whether per entry loading is needed. Alternative is only TTree->Draw().
Definition at line 140 of file Config.hh.
References optionsBool.
|
inline |
Whether per entry loading is needed. Alternative is only TTree->Draw().
Definition at line 143 of file Config.hh.
References optionsBool.
|
inline |
Whether per entry loading is needed. Alternative is only TTree->Draw().
Definition at line 142 of file Config.hh.
References optionsBool.
|
inline |
Whether per entry loading is needed. Alternative is only TTree->Draw().
Definition at line 141 of file Config.hh.
References optionsBool.
void Config::PrintHistogramSetDefinitions | ( | ) | const |
Print out the per event and simple histogram set definitions as these are (assumed to be) spectra definitions that people might want to see expanded.
Definition at line 553 of file Config.cc.
References eventHistoDefSetsSimple.
|
inline |
|
inline |
|
inline |
|
protected |
Register a histogram name for future checking against. If it already exists, the function returns true, else false for successful registration.
Definition at line 809 of file Config.cc.
Referenced by ParseHistogram().
void Config::SetBranchToBeActivated | ( | const std::string & | treeName, |
const std::string & | branchName | ||
) |
Set a branch to be activated if not already.
Definition at line 545 of file Config.cc.
References branches.
Referenced by ParseParticleSetLine(), ParseSpectraLine(), and UpdateRequiredBranches().
|
protected |
Return a vector of strings by splitting on whitespace.
Definition at line 682 of file Config.cc.
Referenced by ParseParticleSetLine(), and ParseSpectraLine().
|
protected |
Update the vector of required branches for a particular tree to be activated for analysis. Note this is not required for simple histograms that will be used with TTree->Draw(). Only per-entry histograms require loading the data.
Definition at line 520 of file Config.cc.
References UpdateRequiredBranches().
Referenced by ParseHistogram(), and UpdateRequiredBranches().
|
protected |
Update the vector of required branches for a particular tree to be activated for analysis based on a single string definition such as Primary.x.
Definition at line 526 of file Config.cc.
References SetBranchToBeActivated().
|
protected |
Whether all branches will be activated - ie for optics.
Definition at line 258 of file Config.hh.
Referenced by AllBranchesToBeActivated().
|
private |
Private members first as required in accessors.
Optional version of option keys in file.
Definition at line 47 of file Config.hh.
Referenced by InitialiseOptions(), and ParseSetting().
|
protected |
Cache of which branches need to be activated for this analysis.
Definition at line 255 of file Config.hh.
Referenced by BranchesToBeActivated(), Config(), InitialiseOptions(), and SetBranchToBeActivated().
|
private |
|
private |
Sets of histogram definitions per particle. Only for event branch.
Definition at line 66 of file Config.hh.
Referenced by ParseSpectraLine(), and PrintHistogramSetDefinitions().
|
private |
List of branches in event tree to produce ParticleSet objects on. (per event and simple).
Definition at line 70 of file Config.hh.
Referenced by ParseParticleSetLine().
|
private |
|
private |
Storage of histogram options. This owns the HistogramDef objects. Key is tree name, value is vector of all histogram definitions for that tree.
Definition at line 57 of file Config.hh.
Referenced by HistogramDefinitions(), InitialiseOptions(), and ParseHistogram().
|
private |
Copy of definition used to identify only 'per entry' histogram definitions. Doesn't own.
Definition at line 63 of file Config.hh.
Referenced by HistogramDefinitionsPerEntry(), InitialiseOptions(), and ParseHistogram().
|
private |
Copy of definition used to identify only 'simple' histogram definitions. Doesn't own.
Definition at line 60 of file Config.hh.
Referenced by HistogramDefinitionsSimple(), InitialiseOptions(), and ParseHistogram().
|
protected |
Index of which line in the file we're on while parsing - for feedback.
Definition at line 252 of file Config.hh.
Referenced by ParseBinning().
|
private |
Storage of options.
Definition at line 50 of file Config.hh.
Referenced by CalculateOpticalFunctions(), Config(), Debug(), EmittanceOnTheFly(), GetOptionBool(), InitialiseOptions(), ParseHistogram(), ParseSetting(), PerEntryBeam(), PerEntryEvent(), PerEntryModel(), PerEntryOption(), PerEntryRun(), PrintOut(), and ProcessSamplers().
|
private |
Storage of options.
Definition at line 52 of file Config.hh.
Referenced by GetOptionNumber(), InitialiseOptions(), ParseSetting(), and PrintModuloFraction().
|
private |
Storage of options.
Definition at line 51 of file Config.hh.
Referenced by CalculateOpticalFunctionsFileName(), Config(), GetOptionString(), InitialiseOptions(), InputFilePath(), OutputFileName(), and ParseSetting().
|
protected |
Cache of all spectra names declared to permit unique naming of histograms when there's more than one spectra per branch used.
Definition at line 262 of file Config.hh.
Referenced by ParseSpectraLine().
|
staticprotected |
Vector of permitted tree names.
Definition at line 249 of file Config.hh.
Referenced by CheckValidTreeName(), InitialiseOptions(), and InvalidTreeName().