BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSComponentFactoryUser.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
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
22#include "G4Types.hh"
23
24#include <map>
25
26BDSComponentFactoryUser::BDSComponentFactoryUser()
27{;}
28
29BDSComponentFactoryUser::~BDSComponentFactoryUser()
30{
31 for (auto& constructor : userFunctions)
32 {delete constructor.second;}
33}
34
35void BDSComponentFactoryUser::RegisterComponent(const G4String& componentTypeName,
36 BDSComponentConstructor* componentConstructor)
37{
38 userFunctions[componentTypeName] = componentConstructor;
39}
40
41G4bool BDSComponentFactoryUser::CanConstructComponentByName(const G4String& componentTypeName) const
42{
43 return userFunctions.find(componentTypeName) != userFunctions.end();
44}
45
47 GMAD::Element const* elementIn,
48 GMAD::Element const* prevElementIn,
49 GMAD::Element const* nextElementIn,
50 const BDSBeamlineIntegral& integral)
51{
52 return userFunctions[componentTypeName]->Construct(elementIn,
53 prevElementIn,
54 nextElementIn,
55 integral);
56}
Abstract class that represents a component of an accelerator.
A class that holds the current integrated quantities along a beam line.
Interface class the developer should derive to construct their element.
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.
std::map< G4String, BDSComponentConstructor * > userFunctions
Map of user component name with constructors to build a component.
BDSAcceleratorComponent * ConstructComponent(const G4String &componentTypeName, GMAD::Element const *elementIn, GMAD::Element const *prevElementIn, GMAD::Element const *nextElementIn, const BDSBeamlineIntegral &integral)
Element class.
Definition element.h:45