BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSComponentFactoryUser.cc
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#include "BDSComponentConstructor.hh"
20#include "BDSComponentFactoryUser.hh"
21#include "BDSParticleDefinition.hh"
22
23#include "globals.hh"
24
25#include <map>
26#include <string>
27
28BDSComponentFactoryUser::BDSComponentFactoryUser():
29 designParticle(nullptr),
30 brho(0),
31 beta0(0)
32{;}
33
34BDSComponentFactoryUser::~BDSComponentFactoryUser()
35{
36 for (auto& constructor : userFunctions)
37 {delete constructor.second;}
38}
39
41{
42 designParticle = designParticleIn;
45}
46
47void BDSComponentFactoryUser::RegisterComponent(const G4String& componentTypeName,
48 BDSComponentConstructor* componentConstructor)
49{
50 userFunctions[componentTypeName] = componentConstructor;
51}
52
53G4bool BDSComponentFactoryUser::CanConstructComponentByName(const G4String& componentTypeName) const
54{
55 return userFunctions.find(componentTypeName) != userFunctions.end();
56}
57
59 GMAD::Element const* elementIn,
60 GMAD::Element const* prevElementIn,
61 GMAD::Element const* nextElementIn,
62 G4double currentArcLengthIn)
63{
64 return userFunctions[componentTypeName]->Construct(elementIn,
65 prevElementIn,
66 nextElementIn,
67 currentArcLengthIn,
68 brho,
69 beta0);
70}
Abstract class that represents a component of an accelerator.
Interface class the developer should derive to construct their element.
const BDSParticleDefinition * designParticle
Particle w.r.t. which elements are built.
G4bool CanConstructComponentByName(const G4String &componentTypeName) const
Check whether a component can be constructed - ie if the name exists.
void RegisterComponent(const G4String &componentTypeName, BDSComponentConstructor *componentConstructor)
Register a constructor instance by a given name.
G4double brho
Cache of nominal beam rigidity.
std::map< G4String, BDSComponentConstructor * > userFunctions
Map of user component name with constructors to build a component.
void SetDesignParticle(const BDSParticleDefinition *designParticleIn)
Update values for nominal rigidity and relativisitic beta of the beam particle.
G4double beta0
Cache of nominal relativistic beta for the beam particle.
BDSAcceleratorComponent * ConstructComponent(const G4String &componentTypeName, GMAD::Element const *elementIn, GMAD::Element const *prevElementIn, GMAD::Element const *nextElementIn, G4double currentArcLength=0)
Wrapper for particle definition.
G4double BRho() const
Accessor.
G4double Beta() const
Accessor.
Element class.
Definition: element.h:43