BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends
BDSAcceleratorComponentRegistry Class Reference

A registry of constructed BDSAcceleratorComponent instances that can be searched. More...

#include <BDSAcceleratorComponentRegistry.hh>

Collaboration diagram for BDSAcceleratorComponentRegistry:
Collaboration graph

Public Member Functions

 ~BDSAcceleratorComponentRegistry ()
 
void RegisterComponent (BDSAcceleratorComponent *component, bool isModified=false)
 
G4bool IsRegistered (BDSAcceleratorComponent *component)
 Check whether an accelerator component is already registered. More...
 
G4bool IsRegistered (const G4String &componentName)
 Check whether an accelerator component is already registered by name. More...
 
G4bool IsRegisteredAllocated (const BDSAcceleratorComponent *componentName) const
 Check if a unique component is registered in the allocatedComponents. More...
 
BDSAcceleratorComponentGetComponent (const G4String &name)
 
void RegisterCurvilinearComponent (BDSAcceleratorComponent *component)
 
void RegisterTunnelComponent (BDSAcceleratorComponent *component)
 
std::map< G4String, BDSAcceleratorComponent * > AllComponentsIncludingUnique () const
 
size_t size () const
 Size of registry. More...
 
void PrintNumberOfEachType () const
 Print out the number of each type of component registered. More...
 

Static Public Member Functions

static BDSAcceleratorComponentRegistryInstance ()
 Singleton accessor. More...
 

Private Types

typedef std::map< G4String, BDSAcceleratorComponent * > RegistryMap
 

Private Member Functions

 BDSAcceleratorComponentRegistry ()
 Default constructor is private as singleton. More...
 
BDSAcceleratorComponentRegistryoperator= (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. More...
 
RegistryMap registryForAllocated
 A map for absolutely everything including components that are unique. More...
 
std::set< BDSAcceleratorComponent * > allocatedComponents
 Set of created components not in registry, for memory management. More...
 
std::set< BDSAcceleratorComponent * > curvilinearComponents
 Set of curvilinear components - purely for memory management. More...
 
std::set< BDSAcceleratorComponent * > tunnelComponents
 
std::unordered_map< std::string, int > typeCounter
 

Static Private Attributes

static BDSAcceleratorComponentRegistryinstance = nullptr
 The singleton instance. More...
 

Friends

std::ostream & operator<< (std::ostream &out, BDSAcceleratorComponentRegistry const &r)
 Output stream. More...
 
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
 

Detailed Description

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.

Author
Laurie Nevay

Definition at line 48 of file BDSAcceleratorComponentRegistry.hh.

Member Typedef Documentation

◆ const_iterator

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.

◆ iterator

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.

◆ RegistryMap

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.

Constructor & Destructor Documentation

◆ ~BDSAcceleratorComponentRegistry()

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.

◆ BDSAcceleratorComponentRegistry()

BDSAcceleratorComponentRegistry::BDSAcceleratorComponentRegistry ( )
private

Default constructor is private as singleton.

Definition at line 37 of file BDSAcceleratorComponentRegistry.cc.

Referenced by Instance().

Here is the caller graph for this function:

Member Function Documentation

◆ AllComponentsIncludingUnique()

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().

Here is the caller graph for this function:

◆ begin() [1/2]

iterator BDSAcceleratorComponentRegistry::begin ( )
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.

◆ begin() [2/2]

const_iterator BDSAcceleratorComponentRegistry::begin ( ) const
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.

◆ empty()

G4bool BDSAcceleratorComponentRegistry::empty ( ) const
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.

◆ end() [1/2]

iterator BDSAcceleratorComponentRegistry::end ( )
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.

◆ end() [2/2]

const_iterator BDSAcceleratorComponentRegistry::end ( ) const
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.

◆ GetComponent()

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().

Here is the caller graph for this function:

◆ Instance()

BDSAcceleratorComponentRegistry * BDSAcceleratorComponentRegistry::Instance ( )
static

◆ IsRegistered() [1/2]

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsRegistered() [2/2]

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.

◆ IsRegisteredAllocated()

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().

Here is the caller graph for this function:

◆ PrintNumberOfEachType()

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().

Here is the caller graph for this function:

◆ RegisterComponent()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterCurvilinearComponent()

void BDSAcceleratorComponentRegistry::RegisterCurvilinearComponent ( BDSAcceleratorComponent component)

◆ RegisterTunnelComponent()

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().

Here is the caller graph for this function:

◆ size()

size_t BDSAcceleratorComponentRegistry::size ( ) const
inline

Size of registry.

Definition at line 120 of file BDSAcceleratorComponentRegistry.hh.

References registry.

Referenced by BDSDetectorConstruction::BuildBeamlines().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
BDSAcceleratorComponentRegistry const &  r 
)
friend

Output stream.

Definition at line 141 of file BDSAcceleratorComponentRegistry.cc.

Field Documentation

◆ allocatedComponents

std::set<BDSAcceleratorComponent*> BDSAcceleratorComponentRegistry::allocatedComponents
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().

◆ curvilinearComponents

std::set<BDSAcceleratorComponent*> BDSAcceleratorComponentRegistry::curvilinearComponents
private

Set of curvilinear components - purely for memory management.

Definition at line 143 of file BDSAcceleratorComponentRegistry.hh.

Referenced by RegisterCurvilinearComponent(), and ~BDSAcceleratorComponentRegistry().

◆ instance

BDSAcceleratorComponentRegistry * BDSAcceleratorComponentRegistry::instance = nullptr
staticprivate

The singleton instance.

Definition at line 133 of file BDSAcceleratorComponentRegistry.hh.

Referenced by Instance(), and ~BDSAcceleratorComponentRegistry().

◆ registry

RegistryMap BDSAcceleratorComponentRegistry::registry
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().

◆ registryForAllocated

RegistryMap BDSAcceleratorComponentRegistry::registryForAllocated
private

A map for absolutely everything including components that are unique.

Definition at line 61 of file BDSAcceleratorComponentRegistry.hh.

Referenced by AllComponentsIncludingUnique(), and RegisterComponent().

◆ tunnelComponents

std::set<BDSAcceleratorComponent*> BDSAcceleratorComponentRegistry::tunnelComponents
private

Definition at line 145 of file BDSAcceleratorComponentRegistry.hh.

◆ typeCounter

std::unordered_map<std::string, int> BDSAcceleratorComponentRegistry::typeCounter
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().


The documentation for this class was generated from the following files: