19#ifndef BDSSAMPLERREGISTRY_H
20#define BDSSAMPLERREGISTRY_H
22#include "BDSException.hh"
23#include "BDSSamplerPlacementRecord.hh"
24#include "BDSSamplerType.hh"
27#include "G4Transform3D.hh"
62 typedef std::vector<BDSSamplerPlacementRecord>
InfoVector;
88 const G4Transform3D& transform = G4Transform3D(),
107 inline G4String
GetName(G4int index)
const;
118 std::vector<G4String>
GetNames()
const;
122 std::vector<G4String> GetUniqueNamesPlane()
const;
123 std::vector<G4String> GetUniqueNamesCylinder()
const;
124 std::vector<G4String> GetUniqueNamesSphere()
const;
131 inline std::vector<G4int> GetSamplerIDsPlane()
const {
return samplerIDsPerType.at(BDSSamplerType::plane);}
132 inline std::vector<G4int> GetSamplerIDsCylinder()
const {
return samplerIDsPerType.at(BDSSamplerType::cylinder);}
133 inline std::vector<G4int> GetSamplerIDsSphere()
const {
return samplerIDsPerType.at(BDSSamplerType::sphere);}
140 inline size_t size()
const;
142 inline G4bool SafeIndex(G4int index)
const {
return index < (G4int)
infos.size();}
165 std::map<BDSSamplerType, std::vector<G4int>> samplerIDsPerType;
169{
return SafeIndex(index) ?
infos.at(index).Name() :
throw BDSException(__METHOD_NAME__,
"invalid index");}
172{
return SafeIndex(index) ?
infos.at(index).UniqueName() :
throw BDSException(__METHOD_NAME__,
"invalid index");}
175{
return SafeIndex(index) ?
infos.at(index).Sampler() :
throw BDSException(__METHOD_NAME__,
"invalid index");}
178{
return SafeIndex(index) ?
infos.at(index).Transform() :
throw BDSException(__METHOD_NAME__,
"invalid index");}
181{
return SafeIndex(index) ?
infos.at(index).TransformInverse() :
throw BDSException(__METHOD_NAME__,
"invalid index");}
184{
return SafeIndex(index) ?
infos.at(index).SPosition() :
throw BDSException(__METHOD_NAME__,
"invalid index");}
189inline size_t BDSSamplerRegistry::size()
const
190{
return infos.size();}
193{
return SafeIndex(index) ?
infos.at(index).BeamlineIndex() :
throw BDSException(__METHOD_NAME__,
"invalid index");}
A class that holds a fully constructed BDSAcceleratorComponent as well as any information relevant to...
General exception with possible name of object and message.
Information about a registered sampler.
Associated information for the placement of a sampler.
std::vector< std::pair< G4String, G4double > > GetUniquePlaneNamesAndSPosition() const
Access all the unique names and their corresponding s position at once.
std::map< BDSSamplerType, BDSSamplerType > samplerTypeToCategory
Map to reduce 'forward' sampler types to simple sampler types for keeping a record of IDs.
G4Transform3D GetTransform(G4int index) const
Accessor.
InfoVector::iterator iterator
Iterator mechanics.
InfoVector::const_iterator const_iterator
Iterator mechanics.
std::map< std::string, double > GetUniqueNameToRadiusSphere() const
For output in standard C++ types. Also in m for units.
iterator begin()
Iterator mechanics.
iterator end()
Iterator mechanics.
BDSSampler * GetSampler(G4int index) const
Accessor.
G4int GetBeamlineIndex(G4int index) const
Accessor.
std::vector< BDSSamplerPlacementRecord > InfoVector
Typedefs up first so we can declare public iterators.
std::map< G4String, G4int > existingNames
static BDSSamplerRegistry * Instance()
Accessor for registry.
const_iterator begin() const
Iterator mechanics.
G4bool empty() const
Iterator mechanics.
G4double GetSPosition(G4int index) const
Accessor.
std::vector< G4String > GetUniqueNames() const
Access all the unique names at once.
const BDSSamplerPlacementRecord & GetInfo(G4int index) const
Accessor.
InfoVector infos
Storage of registered information.
static BDSSamplerRegistry * instance
Singleton instance.
G4int NumberOfExistingSamplers() const
Get number of registered samplers.
std::vector< G4String > GetNames() const
Access all names at once.
G4String GetNameUnique(G4int index) const
Accessor.
BDSSamplerRegistry()
Private constructor to enforce singleton pattern.
std::set< BDSSampler * > samplerObjects
Cache of unique sampler objects for memory management.
const_iterator end() const
Iterator mechanics.
G4int RegisterSampler(const G4String &name, BDSSampler *sampler, const G4Transform3D &transform=G4Transform3D(), G4double S=-1000, const BDSBeamlineElement *element=nullptr, BDSSamplerType type=BDSSamplerType::plane, G4double radius=0)
G4String GetName(G4int index) const
Accessor.
G4Transform3D GetTransformInverse(G4int index) const
Accessor.
std::map< std::string, double > GetUniqueNameToRadiusCylinder() const
For output in standard C++ types. Also in m for units.
Base class and registry of sampler instances.