BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSAcceleratorComponentRegistry.hh
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
4
5This file is part of BDSIM.
6
7BDSIM is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published
9by the Free Software Foundation version 3 of the License.
10
11BDSIM is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
18*/
19#ifndef BDSACCELERATORCOMPONENTREGISTRY_H
20#define BDSACCELERATORCOMPONENTREGISTRY_H
21
22#include "globals.hh" // geant4 globals / types
23
24#include <iterator>
25#include <map>
26#include <set>
27#include <string>
28#include <unordered_map>
29
31
49{
50private:
51 // Typedefs up first so we can declare public iterators.
55 typedef std::map<G4String, BDSAcceleratorComponent*> RegistryMap;
56
59
62
63public:
66
70
79 bool isModified = false);
80
82 G4bool IsRegistered(BDSAcceleratorComponent* component);
83
85 G4bool IsRegistered(const G4String& componentName);
86
88 G4bool IsRegisteredAllocated(const BDSAcceleratorComponent* componentName) const;
89
93 BDSAcceleratorComponent* GetComponent(const G4String& name);
94
98
102
105 std::map<G4String, BDSAcceleratorComponent*> AllComponentsIncludingUnique() const;
106
110 typedef RegistryMap::iterator iterator;
111 typedef RegistryMap::const_iterator const_iterator;
112 iterator begin() {return registry.begin();}
113 iterator end() {return registry.end();}
114 const_iterator begin() const {return registry.begin();}
115 const_iterator end() const {return registry.end();}
116 G4bool empty() const {return registry.empty();}
118
120 size_t size() const {return registry.size();}
121
123 friend std::ostream& operator<< (std::ostream &out, BDSAcceleratorComponentRegistry const &r);
124
126 void PrintNumberOfEachType() const;
127
128private:
131
134
138
140 std::set<BDSAcceleratorComponent*> allocatedComponents;
141
143 std::set<BDSAcceleratorComponent*> curvilinearComponents;
144
145 std::set<BDSAcceleratorComponent*> tunnelComponents;
146
151 std::unordered_map<std::string, int> typeCounter;
152};
153
154#endif
A registry of constructed BDSAcceleratorComponent instances that can be searched.
std::map< G4String, BDSAcceleratorComponent * > RegistryMap
void RegisterCurvilinearComponent(BDSAcceleratorComponent *component)
static BDSAcceleratorComponentRegistry * Instance()
Singleton accessor.
std::map< G4String, BDSAcceleratorComponent * > AllComponentsIncludingUnique() const
void RegisterTunnelComponent(BDSAcceleratorComponent *component)
void RegisterComponent(BDSAcceleratorComponent *component, bool isModified=false)
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.
friend std::ostream & operator<<(std::ostream &out, BDSAcceleratorComponentRegistry const &r)
Output stream.
static BDSAcceleratorComponentRegistry * instance
The singleton instance.
G4bool IsRegisteredAllocated(const BDSAcceleratorComponent *componentName) const
Check if a unique component is registered in the allocatedComponents.
void PrintNumberOfEachType() const
Print out the number of each type of component registered.
BDSAcceleratorComponent * GetComponent(const G4String &name)
std::unordered_map< std::string, int > typeCounter
G4bool IsRegistered(BDSAcceleratorComponent *component)
Check whether an accelerator component is already registered.
BDSAcceleratorComponentRegistry()
Default constructor is private as singleton.
BDSAcceleratorComponentRegistry & operator=(const BDSAcceleratorComponentRegistry &)
assignment and copy constructor not implemented nor used
RegistryMap registry
Registry is a map - note 'register' is a protected keyword.
RegistryMap registryForAllocated
A map for absolutely everything including components that are unique.
Abstract class that represents a component of an accelerator.