20#include "BDSException.hh"
21#include "BDSFieldBuilder.hh"
22#include "BDSFieldFactory.hh"
23#include "BDSFieldInfo.hh"
24#include "BDSFieldObjects.hh"
26#include "G4LogicalVolume.hh"
40BDSFieldBuilder::~BDSFieldBuilder()
47 size_t defaultSize = 30;
48 infos.reserve(defaultSize);
49 lvs.reserve(defaultSize);
54 const std::vector<G4LogicalVolume*>& logicalVolumes,
55 const G4bool propagateToDaughters,
57 const G4String& scalingKey)
62 G4cout << __METHOD_NAME__ <<
"Registering info: " << info
64 for (
auto vol : logicalVolumes)
65 {G4cout << vol->GetName() <<
" ";}
68 infos.push_back(info);
69 lvs.push_back(logicalVolumes);
71 if (info->AutoScale())
73 G4int index = (G4int)
infos.size() - 1;
81 G4LogicalVolume* logicalVolume,
82 const G4bool propagateToDaughters,
84 const G4String& scalingKey)
86 std::vector<G4LogicalVolume*> lvsForThisInfo = {logicalVolume};
90 magnetStrengthForScaling,
95 const std::set<G4LogicalVolume*>& logicalVolumes,
96 const G4bool propagateToDaughters,
98 const G4String& scalingKey)
101 std::vector<G4LogicalVolume*> lvsForThisInfo;
102 lvsForThisInfo.reserve(logicalVolumes.size());
103 for (
auto lv : logicalVolumes)
104 {lvsForThisInfo.push_back(lv);}
107 propagateToDaughters,
108 magnetStrengthForScaling,
112std::vector<BDSFieldObjects*> BDSFieldBuilder::CreateAndAttachAll()
114 std::vector<BDSFieldObjects*> fields;
115 fields.reserve(
infos.size());
116 for (G4int i = 0; i < (G4int)
infos.size(); i++)
133 e.AppendToMessage(
"\nField would be attached to logical volume named \"" +
lvs[i][0]->
GetName() +
"\"");
138 fields.push_back(field);
General exception with possible name of object and message.
Register for all fields to be built and volumes to be attached to.
std::map< G4int, G4String > scalingKeys
Optional register of scaling strengths and keys.
std::vector< const BDSFieldInfo * > infos
Register of components to build.
std::map< G4int, const BDSMagnetStrength * > scalingStrengths
Optional register of scaling strengths and keys.
std::vector< G4bool > propagators
Register of components to build.
void RegisterFieldForConstruction(const BDSFieldInfo *info, G4LogicalVolume *logicalVolume, const G4bool propagateToDaughters=false, const BDSMagnetStrength *magnetStrengthForScaling=nullptr, const G4String &scalingKey="none")
std::vector< std::vector< G4LogicalVolume * > > lvs
Register of components to build.
static BDSFieldBuilder * instance
Singleton instance.
BDSFieldBuilder()
Private default constructor to enforce singleton pattern.
static BDSFieldBuilder * Instance()
Singleton pattern accessor.
static BDSFieldFactory * Instance()
Public accessor method for singleton pattern.
BDSFieldObjects * CreateField(const BDSFieldInfo &info, const BDSMagnetStrength *scalingStrength=nullptr, const G4String &scalingKey="none")
Main interface to field factory.
All info required to build complete field of any type.
G4bool AutoScale() const
Accessor.
A holder for all the Geant4 field related objects.
void AttachToVolume(G4LogicalVolume *volume, G4bool penetrateToDaughterVolumes=true) const
Interface to easily attach to logical volume.
Efficient storage of magnet strengths.
const char * GetName(int)
Name of element.