BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
|
A registry of constructed BDSAcceleratorComponent instances that can be searched. More...
#include <BDSAcceleratorComponentRegistry.hh>
Public Member Functions | |
~BDSAcceleratorComponentRegistry () | |
void | RegisterComponent (BDSAcceleratorComponent *component, bool isModified=false) |
G4bool | IsRegistered (BDSAcceleratorComponent *component) |
Check whether an accelerator component is already registered. | |
G4bool | IsRegistered (const G4String &componentName) |
Check whether an accelerator component is already registered by name. | |
G4bool | IsRegisteredAllocated (const BDSAcceleratorComponent *componentName) const |
Check if a unique component is registered in the allocatedComponents. | |
BDSAcceleratorComponent * | GetComponent (const G4String &name) |
void | RegisterCurvilinearComponent (BDSAcceleratorComponent *component) |
void | RegisterTunnelComponent (BDSAcceleratorComponent *component) |
std::map< G4String, BDSAcceleratorComponent * > | AllComponentsIncludingUnique () const |
size_t | size () const |
Size of registry. | |
void | PrintNumberOfEachType () const |
Print out the number of each type of component registered. | |
Static Public Member Functions | |
static BDSAcceleratorComponentRegistry * | Instance () |
Singleton accessor. | |
Private Types | |
typedef std::map< G4String, BDSAcceleratorComponent * > | RegistryMap |
Private Member Functions | |
BDSAcceleratorComponentRegistry () | |
Default constructor is private as singleton. | |
BDSAcceleratorComponentRegistry & | operator= (const BDSAcceleratorComponentRegistry &) |
assignment and copy constructor not implemented nor used | |
BDSAcceleratorComponentRegistry (BDSAcceleratorComponentRegistry &) | |
Private Attributes | |
RegistryMap | registry |
Registry is a map - note 'register' is a protected keyword. | |
RegistryMap | registryForAllocated |
A map for absolutely everything including components that are unique. | |
std::set< BDSAcceleratorComponent * > | allocatedComponents |
Set of created components not in registry, for memory management. | |
std::set< BDSAcceleratorComponent * > | curvilinearComponents |
Set of curvilinear components - purely for memory management. | |
std::set< BDSAcceleratorComponent * > | tunnelComponents |
std::unordered_map< std::string, int > | typeCounter |
Static Private Attributes | |
static BDSAcceleratorComponentRegistry * | instance = nullptr |
The singleton instance. | |
Friends | |
std::ostream & | operator<< (std::ostream &out, BDSAcceleratorComponentRegistry const &r) |
Output stream. | |
typedef RegistryMap::iterator | iterator |
typedef RegistryMap::const_iterator | const_iterator |
iterator | begin () |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
G4bool | empty () const |
A registry of constructed BDSAcceleratorComponent instances that can be searched.
Uses an std::map rather than unordered map as although slower to access (less often and only at construction), a map is faster for iterating than an unordered map, which will be required to apply wrapper physics processes - relatively common.
NOTE, the iterations of the registry applies only to components that can be reused. The AllAllocatedComponents function should be used to access all components held in memory in the registry.
Definition at line 48 of file BDSAcceleratorComponentRegistry.hh.
typedef RegistryMap::const_iterator BDSAcceleratorComponentRegistry::const_iterator |
NOTE the iterator works only over components that can be reused and not allocated components. Iterator mechanics
Definition at line 111 of file BDSAcceleratorComponentRegistry.hh.
typedef RegistryMap::iterator BDSAcceleratorComponentRegistry::iterator |
NOTE the iterator works only over components that can be reused and not allocated components. Iterator mechanics
Definition at line 110 of file BDSAcceleratorComponentRegistry.hh.
|
private |
Use a typedef for this specific map implementation so we can easily define iterators and internal member variables without risking getting the exact map declaration wrong.
Definition at line 55 of file BDSAcceleratorComponentRegistry.hh.
BDSAcceleratorComponentRegistry::~BDSAcceleratorComponentRegistry | ( | ) |
Destructor resets instance to 0 so that the class can be reinstantiated if necessary.
Definition at line 40 of file BDSAcceleratorComponentRegistry.cc.
References allocatedComponents, curvilinearComponents, instance, and registry.
|
private |
Default constructor is private as singleton.
Definition at line 37 of file BDSAcceleratorComponentRegistry.cc.
Referenced by Instance().
std::map< G4String, BDSAcceleratorComponent * > BDSAcceleratorComponentRegistry::AllComponentsIncludingUnique | ( | ) | const |
Access a map of all accelerator components by name, including ones that are uniquely built and stored only for memory management.
Definition at line 133 of file BDSAcceleratorComponentRegistry.cc.
References registry, and registryForAllocated.
Referenced by BDSDetectorConstruction::BuildPhysicsBias().
|
inline |
NOTE the iterator works only over components that can be reused and not allocated components. Iterator mechanics
Definition at line 112 of file BDSAcceleratorComponentRegistry.hh.
References registry.
|
inline |
NOTE the iterator works only over components that can be reused and not allocated components. Iterator mechanics
Definition at line 114 of file BDSAcceleratorComponentRegistry.hh.
References registry.
|
inline |
NOTE the iterator works only over components that can be reused and not allocated components. Iterator mechanics
Definition at line 116 of file BDSAcceleratorComponentRegistry.hh.
References registry.
|
inline |
NOTE the iterator works only over components that can be reused and not allocated components. Iterator mechanics
Definition at line 113 of file BDSAcceleratorComponentRegistry.hh.
References registry.
|
inline |
NOTE the iterator works only over components that can be reused and not allocated components. Iterator mechanics
Definition at line 115 of file BDSAcceleratorComponentRegistry.hh.
References registry.
BDSAcceleratorComponent * BDSAcceleratorComponentRegistry::GetComponent | ( | const G4String & | name | ) |
Access an already constructed component - will return null if no such component found. This is safe as this registry is primarily used by BDSComponentFactory which can return nullptr to BDSDetectorConstruction safely if an invalid component is requested.
Definition at line 112 of file BDSAcceleratorComponentRegistry.cc.
References registry.
Referenced by BDSComponentFactory::CreateComponent().
|
static |
Singleton accessor.
Definition at line 30 of file BDSAcceleratorComponentRegistry.cc.
References BDSAcceleratorComponentRegistry(), and instance.
Referenced by BDSAcceleratorModel::BDSAcceleratorModel(), BDSDetectorConstruction::BuildBeamlines(), BDSDetectorConstruction::BuildPhysicsBias(), BDSCurvilinearBuilder::CreateAngledBridgeComponent(), BDSCurvilinearBuilder::CreateBonusSectionEnd(), BDSCurvilinearBuilder::CreateBonusSectionStart(), BDSComponentFactory::CreateComponent(), BDSCurvilinearBuilder::CreateCurvilinearElement(), BDSCurvilinearBuilder::CreateDefaultBridgeComponent(), BDSCurvilinearBuilder::CreateStraightBridgeComponent(), and BDSTunnelFactoryBase::PrepareTunnelSection().
G4bool BDSAcceleratorComponentRegistry::IsRegistered | ( | BDSAcceleratorComponent * | component | ) |
Check whether an accelerator component is already registered.
Definition at line 96 of file BDSAcceleratorComponentRegistry.cc.
References BDSAcceleratorComponent::GetName(), and IsRegistered().
Referenced by IsRegistered(), and RegisterComponent().
G4bool BDSAcceleratorComponentRegistry::IsRegistered | ( | const G4String & | componentName | ) |
Check whether an accelerator component is already registered by name.
Definition at line 106 of file BDSAcceleratorComponentRegistry.cc.
References registry.
G4bool BDSAcceleratorComponentRegistry::IsRegisteredAllocated | ( | const BDSAcceleratorComponent * | componentName | ) | const |
Check if a unique component is registered in the allocatedComponents.
Definition at line 101 of file BDSAcceleratorComponentRegistry.cc.
References allocatedComponents.
Referenced by RegisterComponent().
void BDSAcceleratorComponentRegistry::PrintNumberOfEachType | ( | ) | const |
Print out the number of each type of component registered.
Definition at line 152 of file BDSAcceleratorComponentRegistry.cc.
References typeCounter.
Referenced by BDSDetectorConstruction::BuildBeamlines().
void BDSAcceleratorComponentRegistry::RegisterComponent | ( | BDSAcceleratorComponent * | component, |
bool | isModified = false |
||
) |
Register a BDSAcceleratorComponent. Once in the registry, can be reused through GetComponent function. Optional flag isModified indicates that the component was modified beyond its original parser definition (ie likely to match the face of another component) and should not be reused even if it appears later in the lattice. In this case, it is stored here, purely for memory management. Note, the registry of allocated components relies on unique naming for unique components. ie sb1_mod_0 and sb1_mod_1.
Definition at line 57 of file BDSAcceleratorComponentRegistry.cc.
References allocatedComponents, BDSAcceleratorComponent::GetName(), BDSAcceleratorComponent::GetType(), IsRegistered(), IsRegisteredAllocated(), RegisterComponent(), registry, registryForAllocated, and typeCounter.
Referenced by BDSComponentFactory::CreateComponent(), and RegisterComponent().
void BDSAcceleratorComponentRegistry::RegisterCurvilinearComponent | ( | BDSAcceleratorComponent * | component | ) |
Register a curvilinear component - purely to keep track of and delete at the end of the program.
Definition at line 123 of file BDSAcceleratorComponentRegistry.cc.
References curvilinearComponents.
Referenced by BDSCurvilinearBuilder::CreateAngledBridgeComponent(), BDSCurvilinearBuilder::CreateBonusSectionEnd(), BDSCurvilinearBuilder::CreateBonusSectionStart(), BDSCurvilinearBuilder::CreateCurvilinearElement(), BDSCurvilinearBuilder::CreateDefaultBridgeComponent(), and BDSCurvilinearBuilder::CreateStraightBridgeComponent().
void BDSAcceleratorComponentRegistry::RegisterTunnelComponent | ( | BDSAcceleratorComponent * | component | ) |
Register a tunnel component - purely to keep track of and delete at the end of the program.
Definition at line 128 of file BDSAcceleratorComponentRegistry.cc.
Referenced by BDSTunnelFactoryBase::PrepareTunnelSection().
|
inline |
Size of registry.
Definition at line 120 of file BDSAcceleratorComponentRegistry.hh.
References registry.
Referenced by BDSDetectorConstruction::BuildBeamlines().
|
friend |
Output stream.
Definition at line 141 of file BDSAcceleratorComponentRegistry.cc.
|
private |
Set of created components not in registry, for memory management.
Definition at line 140 of file BDSAcceleratorComponentRegistry.hh.
Referenced by IsRegisteredAllocated(), RegisterComponent(), and ~BDSAcceleratorComponentRegistry().
|
private |
Set of curvilinear components - purely for memory management.
Definition at line 143 of file BDSAcceleratorComponentRegistry.hh.
Referenced by RegisterCurvilinearComponent(), and ~BDSAcceleratorComponentRegistry().
|
staticprivate |
The singleton instance.
Definition at line 133 of file BDSAcceleratorComponentRegistry.hh.
Referenced by Instance(), and ~BDSAcceleratorComponentRegistry().
|
private |
Registry is a map - note 'register' is a protected keyword.
Definition at line 58 of file BDSAcceleratorComponentRegistry.hh.
Referenced by AllComponentsIncludingUnique(), begin(), empty(), end(), GetComponent(), IsRegistered(), RegisterComponent(), size(), and ~BDSAcceleratorComponentRegistry().
|
private |
A map for absolutely everything including components that are unique.
Definition at line 61 of file BDSAcceleratorComponentRegistry.hh.
Referenced by AllComponentsIncludingUnique(), and RegisterComponent().
|
private |
Definition at line 145 of file BDSAcceleratorComponentRegistry.hh.
|
private |
Map to count the number of each type registered. We have to use std::string as G4String doesn't provide a hash for the unordered map. We use unordered map because it's faster for insertions and retrievals but slow for range iteration which we only do for debug print out or once.
Definition at line 151 of file BDSAcceleratorComponentRegistry.hh.
Referenced by PrintNumberOfEachType(), and RegisterComponent().