BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
|
#include <parser.h>
Public Member Functions | |
Parser ()=delete | |
No default constructor. | |
virtual | ~Parser () |
Destructor. More... | |
void | quit () |
Exit method. More... | |
void | write_table (std::string *name, ElementType type, bool isLine=false) |
Method that transfers parameters to element properties. More... | |
void | expand_line (FastList< Element > &target, const std::string &name, std::string start="", std::string end="") |
void | expand_line (const std::string &name, std::string start, std::string end) |
Expand the main beamline as defined by the use command. More... | |
const FastList< Element > & | get_sequence (const std::string &name) |
int | add_sampler_partIDSet (std::list< int > *samplerPartIDListIn) |
void | add_sampler (const std::string &name, int count, ElementType type, std::string samplerType, std::list< int > *samplerPartIDListIn=nullptr) |
insert a sampler into beamline_list More... | |
template<class C , class Container = FastList<C>> | |
void | Add () |
Insert global object of parser class C in Container class. More... | |
template<class C , class Container = FastList<C>> | |
void | Add (bool unique, const std::string &className) |
template<class C > | |
C & | GetGlobal () |
Get global object of parser class C. | |
template<class C , class Container = FastList<C>> | |
Container & | GetList () |
Get list for parser class C. | |
const std::set< std::set< int > > & | GetSamplerFilters () const |
const std::map< int, std::set< int > > & | GetSamplerFilterIDToSet () const |
Element & | find_element (const std::string &element_name) |
find element More... | |
const Element & | find_element (const std::string &element_name) const |
find element (const) More... | |
const Element * | find_element_safe (const std::string &element_name) const |
find element by pointer - nullptr if not found - searches element_list More... | |
const Element * | find_placement_element_safe (const std::string &element_name) const |
search placement_element More... | |
double | property_lookup (const std::string &element_name, const std::string &property_name) const |
access property of Element with element_name More... | |
void | add_element_temp (const std::string &name, int number, bool pushfront, ElementType linetype) |
add element to temporary element sequence tmp_list More... | |
int | copy_element_to_params (const std::string &elementName) |
copy properties from Element into params, returns element type as integer, returs _NONE if not found More... | |
bool | InvalidSymbolName (const std::string &s, std::string &errorReason) |
Symtab * | symcreate (const std::string &s) |
create new parser symbol More... | |
Symtab * | symlook (const std::string &s) |
look up parser symbol More... | |
void | ClearParams () |
template<class C , typename T > | |
void | SetValue (std::string property, T value) |
Set value for parser class. More... | |
template<class C > | |
double | GetValue (std::string property) |
Get value for parser class (only for doubles) More... | |
template<typename T > | |
std::list< T > * | ArrayToList (Array *) |
template<typename T > | |
void | ExtendValue (const std::string &property, T value) |
Add value to be extended to object. | |
void | Overwrite (const std::string &objectName) |
Overwrite object with current values. More... | |
void | AddVariable (std::string *name) |
Add variable memory to variable list for memory management. More... | |
bool | TryPrintingObject (const std::string &objectName) const |
const FastList< Element > & | GetBeamline () const |
template<> | |
Beam & | GetGlobal () |
template<> | |
FastList< Region > & | GetList () |
template<> | |
FastList< NewColour > & | GetList () |
template<> | |
FastList< Crystal > & | GetList () |
template<> | |
FastList< Field > & | GetList () |
template<> | |
FastList< Query > & | GetList () |
template<> | |
FastList< Atom > & | GetList () |
template<> | |
FastList< Material > & | GetList () |
template<> | |
FastList< Tunnel > & | GetList () |
template<> | |
FastList< CavityModel > & | GetList () |
template<> | |
FastList< Scorer > & | GetList () |
template<> | |
FastList< ScorerMesh > & | GetList () |
template<> | |
FastList< Placement > & | GetList () |
template<> | |
FastList< PhysicsBiasing > & | GetList () |
template<> | |
FastList< SamplerPlacement > & | GetList () |
template<> | |
FastList< BLMPlacement > & | GetList () |
template<> | |
FastList< Aperture > & | GetList () |
template<> | |
void | ExtendValue (const std::string &property, double value) |
template<> | |
void | ExtendValue (const std::string &property, std::string value) |
template<> | |
void | ExtendValue (const std::string &property, Array *value) |
template<> | |
void | Add (bool unique, const std::string &className) |
void | Store (double value) |
Add value to front of temporary list. More... | |
void | Store (const std::string &name) |
Add value to front of temporary list. More... | |
void | FillArray (Array *) |
void | FillString (Array *) |
void | PrintBeamline () const |
Print methods. More... | |
void | PrintElements () const |
Print methods. More... | |
void | PrintOptions () const |
Print methods. More... | |
Static Public Member Functions | |
static Parser * | Instance (const std::string &filename) |
Constructor method. More... | |
static Parser * | Instance () |
Access method. More... | |
Data Fields | |
std::string | current_line |
Name of beamline. More... | |
std::string | current_start |
Name of beamline. More... | |
std::string | current_end |
Name of beamline. More... | |
Protected Member Functions | |
Parser (std::string filename) | |
Constructor from filename. More... | |
Protected Attributes | |
Beam | beam |
Beam instance;. More... | |
Options | options |
General options. More... | |
FastList< Element > | beamline_list |
Beamline. More... | |
FastList< Atom > | atom_list |
List of parser defined atoms. More... | |
FastList< NewColour > | colour_list |
List of parser defined colours. More... | |
FastList< Crystal > | crystal_list |
FastList< Field > | field_list |
List of parser defined fields. More... | |
FastList< Material > | material_list |
List of parser defined materials. More... | |
FastList< Query > | query_list |
List of parser defined query objects. More... | |
FastList< Region > | region_list |
List of parser defined regions. More... | |
FastList< Tunnel > | tunnel_list |
List of parser defined tunnels. More... | |
FastList< PhysicsBiasing > | xsecbias_list |
List of parser defined cross section biasing objects. More... | |
FastList< Placement > | placement_list |
List of parser defined placements. More... | |
FastList< CavityModel > | cavitymodel_list |
List of parser defined rf cavity models. More... | |
FastList< SamplerPlacement > | samplerplacement_list |
List of parser defined sampler placements. More... | |
FastList< Scorer > | scorer_list |
FastList< ScorerMesh > | scorermesh_list |
FastList< Aperture > | aperture_list |
List of parser defined apertures. More... | |
FastList< BLMPlacement > | blm_list |
List of parser defined blms. More... | |
Private Member Functions | |
void | Initialise () |
Initialisation of parser functions and constants. More... | |
void | ParseFile (FILE *f) |
Parse the input file and construct beamline_list and options. More... | |
void | set_sampler (const std::string &name, int count, ElementType type, const std::string &samplerType, double samplerRadius=0, int particleSetID=-1) |
Set sampler. More... | |
void | add_func (std::string name, double(*func)(double)) |
Add function to parser. More... | |
void | add_var (std::string name, double value, int is_reserved=0) |
void | expand_sequences () |
Expand all sequences define with 'line' into FastLists. More... | |
template<class C > | |
bool | FindAndExtend (const std::string &objectName) |
Find object by name in list. More... | |
template<class C > | |
void | ExtendObject (C &object) |
Extend object with maps. More... | |
Private Attributes | |
const int | MAX_EXPAND_ITERATIONS = 50 |
maximum number of nested lines More... | |
std::vector< std::list< Element > * > | allocated_lines |
Parameters | params |
Parameters to copy to Element. More... | |
Atom | atom |
Atom instance;. More... | |
NewColour | colour |
NewColour instance. More... | |
Crystal | crystal |
Field | field |
Field instance;. More... | |
Material | material |
Material instance;. More... | |
PhysicsBiasing | xsecbias |
PhysicsBiasing instance. More... | |
Placement | placement |
Placement instance. More... | |
Query | query |
Query instance. More... | |
Region | region |
Region instance;. More... | |
Tunnel | tunnel |
Tunnel instance. More... | |
CavityModel | cavitymodel |
RF Cavity model instance. More... | |
SamplerPlacement | samplerplacement |
Sampler placement instance. More... | |
Scorer | scorer |
Scorer instance. More... | |
ScorerMesh | scorermesh |
ScorerMesh instance. More... | |
Aperture | aperture |
Aperture instance. More... | |
BLMPlacement | blm |
BLM instance. More... | |
std::map< std::string, double > | extendedNumbers |
Map for options of type double for extending objects. More... | |
std::map< std::string, std::string > | extendedStrings |
Map for options of type string for extending objects. More... | |
std::map< std::string, Array * > | extendedVectors |
Map for options of type vector for extending objects. More... | |
FastList< Element > | element_list |
List of all encountered elements. More... | |
FastList< Element > | placement_elements |
std::list< Element > | tmp_list |
Temporary list. More... | |
std::vector< std::string > | sequences |
Names of all defined sequences in the parser with 'line'. More... | |
std::map< std::string, FastList< Element > * > | expandedSequences |
Cached copy of expanded sequences. More... | |
SymbolMap | symtab_map |
Parser symbol map. More... | |
std::vector< std::string * > | var_list |
Variable vector for memory storage. More... | |
std::set< std::set< int > > | samplerFilters |
std::map< int, std::set< int > > | samplerFilterIDToSet |
std::map< std::set< int >, int > | setToSamplerFilterID |
std::list< double > | tmparray |
temporary list for reading of arrays in parser More... | |
std::list< std::string > | tmpstring |
temporary list for reading of arrays in parser More... | |
Static Private Attributes | |
static Parser * | instance = nullptr |
Instance. More... | |
|
virtual |
Destructor.
Definition at line 114 of file parser.cc.
References allocated_lines, beamline_list, and instance.
|
explicitprotected |
Constructor from filename.
Definition at line 124 of file parser.cc.
References Initialise(), instance, and ParseFile().
void GMAD::Parser::Add |
void GMAD::Parser::Add | ( | bool | unique, |
const std::string & | className | ||
) |
Specialisation for Placements where we separately cache an Element. Note we can't do a partial specialisation so we have to do a full explicit one. Therefore we also have to be careful about the order we declare this because of where these functions are used. Also, we can't implement it in the header because we'd get multiple symbols. Therefore, declared here, but implemented in cc file with explicit instantiation of templates we need in rest of cc file.
Definition at line 1056 of file parser.cc.
References GMAD::Placement::bdsimElement, GMAD::Placement::clear(), GMAD::Placement::name, and GMAD::Placement::print().
void GMAD::Parser::Add | ( | bool | unique, |
const std::string & | className | ||
) |
void Parser::add_element_temp | ( | const std::string & | name, |
int | number, | ||
bool | pushfront, | ||
ElementType | linetype | ||
) |
add element to temporary element sequence tmp_list
Definition at line 639 of file parser.cc.
References GMAD::Element::lst, tmp_list, and GMAD::Element::type.
|
private |
Add function to parser.
Definition at line 678 of file parser.cc.
References GMAD::Symtab::Set(), GMAD::SymbolMap::symcreate(), and symtab_map.
Referenced by Initialise().
void Parser::add_sampler | ( | const std::string & | name, |
int | count, | ||
ElementType | type, | ||
std::string | samplerType, | ||
std::list< int > * | samplerPartIDListIn = nullptr |
||
) |
insert a sampler into beamline_list
Definition at line 571 of file parser.cc.
References add_sampler_partIDSet(), and set_sampler().
int Parser::add_sampler_partIDSet | ( | std::list< int > * | samplerPartIDListIn | ) |
Add a particle set for a sampler and return a unique integer ID for that set. If no list or empty list given, returns -1, the default for 'no filter'.
Definition at line 553 of file parser.cc.
References samplerFilters.
Referenced by add_sampler().
|
private |
void Parser::AddVariable | ( | std::string * | name | ) |
std::list< T > * GMAD::Parser::ArrayToList | ( | Array * | arrayIn | ) |
void Parser::ClearParams | ( | ) |
Reset parameters
Definition at line 729 of file parser.cc.
References GMAD::Parameters::flush(), params, and samplerFilters.
int Parser::copy_element_to_params | ( | const std::string & | elementName | ) |
copy properties from Element into params, returns element type as integer, returs _NONE if not found
Definition at line 663 of file parser.cc.
References find_element(), GMAD::Parameters::inherit_properties(), params, and GMAD::Element::type.
void Parser::expand_line | ( | const std::string & | name, |
std::string | start, | ||
std::string | end | ||
) |
Expand the main beamline as defined by the use command.
Definition at line 300 of file parser.cc.
References beamline_list, and expand_line().
void Parser::expand_line | ( | FastList< Element > & | target, |
const std::string & | name, | ||
std::string | start = "" , |
||
std::string | end = "" |
||
) |
Expand a sequence by name from start to end into the target list. This removes sublines from the beamline into one LINE.
Definition at line 305 of file parser.cc.
References find_element(), and GMAD::Element::type.
Referenced by expand_line(), and expand_sequences().
|
private |
Expand all sequences define with 'line' into FastLists.
Definition at line 290 of file parser.cc.
References expand_line(), expandedSequences, and sequences.
Referenced by ParseFile().
|
private |
Extend object with maps.
Definition at line 804 of file parser.cc.
References extendedNumbers, extendedStrings, and extendedVectors.
Referenced by FindAndExtend(), and Overwrite().
void GMAD::Parser::ExtendValue | ( | const std::string & | property, |
Array * | value | ||
) |
void GMAD::Parser::ExtendValue | ( | const std::string & | property, |
double | value | ||
) |
void GMAD::Parser::ExtendValue | ( | const std::string & | property, |
std::string | value | ||
) |
void Parser::FillArray | ( | Array * | array | ) |
Fill array object from temporary list and clear temporary list
Definition at line 717 of file parser.cc.
References GMAD::Array::Copy(), and tmparray.
void Parser::FillString | ( | Array * | array | ) |
Fill array object from temporary list and clear temporary list
Definition at line 723 of file parser.cc.
References GMAD::Array::Copy(), and tmpstring.
Element & Parser::find_element | ( | const std::string & | element_name | ) |
find element
Definition at line 582 of file parser.cc.
References element_list.
Referenced by copy_element_to_params(), expand_line(), and property_lookup().
const Element & Parser::find_element | ( | const std::string & | element_name | ) | const |
const Element * Parser::find_element_safe | ( | const std::string & | element_name | ) | const |
find element by pointer - nullptr if not found - searches element_list
Definition at line 621 of file parser.cc.
References element_list.
Referenced by BDSParser::GetElement().
const Element * Parser::find_placement_element_safe | ( | const std::string & | element_name | ) | const |
search placement_element
Definition at line 609 of file parser.cc.
References placement_elements.
Referenced by BDSParser::GetPlacementElement().
|
private |
Find object by name in list.
Definition at line 791 of file parser.cc.
References GMAD::FastList< T >::end(), ExtendObject(), and GMAD::FastList< T >::find().
Find the sequence defined in the parser and expand it if not already done so. Cache result in map of fastlists.
Definition at line 458 of file parser.cc.
References expandedSequences.
Referenced by BDSParser::GetSequence().
Beamline Access.
Definition at line 896 of file parser.cc.
References beamline_list.
Referenced by BDSDetectorConstruction::BuildBeamlines(), and BDSDetectorConstruction::UpdateSamplerDiameterAndCountSamplers().
FastList< CavityModel > & GMAD::Parser::GetList | ( | ) |
FastList< ScorerMesh > & GMAD::Parser::GetList | ( | ) |
FastList< PhysicsBiasing > & GMAD::Parser::GetList | ( | ) |
FastList< SamplerPlacement > & GMAD::Parser::GetList | ( | ) |
FastList< BLMPlacement > & GMAD::Parser::GetList | ( | ) |
|
inline |
|
inline |
double GMAD::Parser::GetValue | ( | std::string | property | ) |
|
private |
Initialisation of parser functions and constants.
Definition at line 187 of file parser.cc.
References add_func(), GMAD::Parameters::flush(), and params.
Referenced by Parser().
|
static |
|
static |
bool Parser::InvalidSymbolName | ( | const std::string & | s, |
std::string & | errorReason | ||
) |
void Parser::Overwrite | ( | const std::string & | objectName | ) |
Overwrite object with current values.
Definition at line 735 of file parser.cc.
References element_list, extendedNumbers, extendedStrings, extendedVectors, ExtendObject(), and xsecbias_list.
|
private |
Parse the input file and construct beamline_list and options.
Definition at line 155 of file parser.cc.
References GMAD::SymbolMap::clear(), element_list, expand_sequences(), symtab_map, tmp_list, and var_list.
Referenced by Parser().
void Parser::PrintBeamline | ( | ) | const |
void Parser::PrintElements | ( | ) | const |
void Parser::PrintOptions | ( | ) | const |
Print methods.
Definition at line 829 of file parser.cc.
References options, and GMAD::OptionsBase::print().
double Parser::property_lookup | ( | const std::string & | element_name, |
const std::string & | property_name | ||
) | const |
access property of Element with element_name
Definition at line 633 of file parser.cc.
References find_element(), and GMAD::Element::property_lookup().
|
private |
Set sampler.
Definition at line 468 of file parser.cc.
References beamline_list.
Referenced by add_sampler().
void GMAD::Parser::SetValue | ( | std::string | property, |
T | value | ||
) |
void Parser::Store | ( | const std::string & | name | ) |
void Parser::Store | ( | double | value | ) |
Symtab * Parser::symcreate | ( | const std::string & | s | ) |
create new parser symbol
Definition at line 698 of file parser.cc.
References GMAD::SymbolMap::symcreate(), and symtab_map.
Symtab * Parser::symlook | ( | const std::string & | s | ) |
look up parser symbol
Definition at line 703 of file parser.cc.
References GMAD::SymbolMap::symlook(), and symtab_map.
bool Parser::TryPrintingObject | ( | const std::string & | objectName | ) | const |
Search each member vector for an object with the matching name. Return true if successfully printed.
Definition at line 834 of file parser.cc.
References aperture_list, atom_list, blm_list, cavitymodel_list, colour_list, crystal_list, field_list, material_list, placement_list, query_list, region_list, samplerplacement_list, tunnel_list, and xsecbias_list.
void Parser::write_table | ( | std::string * | name, |
ElementType | type, | ||
bool | isLine = false |
||
) |
Method that transfers parameters to element properties.
Definition at line 273 of file parser.cc.
References allocated_lines, element_list, GMAD::Element::lst, params, sequences, GMAD::Element::set(), and tmp_list.
|
private |
vector of defined lines for memory management
Definition at line 269 of file parser.h.
Referenced by write_table(), and ~Parser().
List of parser defined apertures.
Definition at line 253 of file parser.h.
Referenced by BDSParser::GetApertures(), and TryPrintingObject().
List of parser defined atoms.
Definition at line 229 of file parser.h.
Referenced by BDSParser::GetAtoms(), and TryPrintingObject().
|
protected |
Beam instance;.
Definition at line 223 of file parser.h.
Referenced by BDSParser::AmalgamateBeam(), BDSParser::CheckOptions(), BDSParser::GetBeam(), and BDSParser::GetBeamBase().
Beamline.
Definition at line 227 of file parser.h.
Referenced by expand_line(), GetBeamline(), PrintBeamline(), set_sampler(), and ~Parser().
|
private |
|
protected |
List of parser defined blms.
Definition at line 255 of file parser.h.
Referenced by BDSParser::GetBLMs(), and TryPrintingObject().
|
private |
|
protected |
List of parser defined rf cavity models.
Definition at line 247 of file parser.h.
Referenced by BDSParser::GetCavityModels(), and TryPrintingObject().
List of parser defined colours.
Definition at line 230 of file parser.h.
Referenced by BDSParser::GetColours(), and TryPrintingObject().
List of parser defined crystals.
Definition at line 231 of file parser.h.
Referenced by BDSParser::GetCrystals(), and TryPrintingObject().
List of all encountered elements.
Definition at line 319 of file parser.h.
Referenced by find_element(), find_element_safe(), Overwrite(), ParseFile(), PrintElements(), and write_table().
Cached copy of expanded sequences.
Definition at line 333 of file parser.h.
Referenced by expand_sequences(), and get_sequence().
|
private |
Map for options of type double for extending objects.
Definition at line 312 of file parser.h.
Referenced by ExtendObject(), and Overwrite().
|
private |
Map for options of type string for extending objects.
Definition at line 314 of file parser.h.
Referenced by ExtendObject(), and Overwrite().
|
private |
Map for options of type vector for extending objects.
Definition at line 316 of file parser.h.
Referenced by ExtendObject(), and Overwrite().
List of parser defined fields.
Definition at line 233 of file parser.h.
Referenced by BDSParser::GetFields(), and TryPrintingObject().
|
staticprivate |
Instance.
Definition at line 94 of file parser.h.
Referenced by Instance(), Parser(), and ~Parser().
|
private |
List of parser defined materials.
Definition at line 235 of file parser.h.
Referenced by BDSParser::GetMaterials(), and TryPrintingObject().
|
private |
|
protected |
General options.
Definition at line 225 of file parser.h.
Referenced by BDSParser::AmalgamateOptions(), BDSParser::CheckOptions(), BDSParser::GetOptions(), BDSParser::GetOptionsBase(), and PrintOptions().
|
private |
Parameters to copy to Element.
Definition at line 272 of file parser.h.
Referenced by ClearParams(), copy_element_to_params(), Initialise(), and write_table().
|
private |
List of element definitions that are used in placements - keep separately a copy so that when we clear all the lists after expanding the lines we still have the element definitions we need
Definition at line 324 of file parser.h.
Referenced by find_placement_element_safe().
List of parser defined placements.
Definition at line 245 of file parser.h.
Referenced by BDSParser::GetPlacements(), and TryPrintingObject().
List of parser defined query objects.
Definition at line 237 of file parser.h.
Referenced by BDSParser::GetQuery(), and TryPrintingObject().
List of parser defined regions.
Definition at line 239 of file parser.h.
Referenced by BDSParser::GetRegions(), and TryPrintingObject().
|
private |
|
private |
Set of unique sets of particle IDs. This will allow us to build up unique Sensitive detectors for particles later on.
Definition at line 342 of file parser.h.
Referenced by add_sampler_partIDSet(), and ClearParams().
|
private |
|
protected |
List of parser defined sampler placements.
Definition at line 249 of file parser.h.
Referenced by BDSParser::GetSamplerPlacements(), and TryPrintingObject().
|
private |
ScorerMesh instance.
|
protected |
|
private |
Names of all defined sequences in the parser with 'line'.
Definition at line 330 of file parser.h.
Referenced by expand_sequences(), and write_table().
|
private |
|
private |
Parser symbol map.
Definition at line 336 of file parser.h.
Referenced by add_func(), ParseFile(), symcreate(), and symlook().
|
private |
Temporary list.
Definition at line 327 of file parser.h.
Referenced by add_element_temp(), ParseFile(), and write_table().
|
private |
temporary list for reading of arrays in parser
Definition at line 265 of file parser.h.
Referenced by FillArray(), and Store().
|
private |
temporary list for reading of arrays in parser
Definition at line 266 of file parser.h.
Referenced by FillString(), and Store().
List of parser defined tunnels.
Definition at line 241 of file parser.h.
Referenced by TryPrintingObject().
|
private |
Variable vector for memory storage.
Definition at line 338 of file parser.h.
Referenced by AddVariable(), and ParseFile().
|
private |
PhysicsBiasing instance.
|
protected |
List of parser defined cross section biasing objects.
Definition at line 243 of file parser.h.
Referenced by BDSParser::GetBiasing(), Overwrite(), and TryPrintingObject().