BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSLinkRegistry.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
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 "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSLinkOpaqueBox.hh"
22#include "BDSLinkRegistry.hh"
23
24#include "G4Transform3D.hh"
25#include "G4Types.hh"
26
27#include <map>
28#include <string>
29
30BDSLinkRegistry::BDSLinkRegistry()
31{;}
32
33BDSLinkRegistry::~BDSLinkRegistry()
34{;}
35
36G4int BDSLinkRegistry::Register(BDSLinkOpaqueBox* componentIn,
37 const G4Transform3D& globalToInputIn)
38{
39 G4int newID = componentIn->PlaceOutputSampler();
40 G4cout << "New ID " << newID << " for " << componentIn->LinkName() << G4endl;
41 G4bool noRotation = !(componentIn->Angled());
42 BDSLinkRegistry::LinkEntry le = {noRotation, componentIn, globalToInputIn, globalToInputIn.inverse(), newID};
43 byName[componentIn->LinkName()] = le;
44 byID[newID] = le;
45 return newID;
46}
47
48const G4Transform3D& BDSLinkRegistry::Transform(const std::string& name) const
49{
50 auto search = byName.find(name);
51 if (search != byName.end())
52 {return search->second.transform;}
53 else
54 {throw BDSException(__METHOD_NAME__, "unknown link element name \"" + name + "\"");}
55}
56
57const G4Transform3D& BDSLinkRegistry::Transform(const G4int ID) const
58{
59 auto search = byID.find(ID);
60 if (search != byID.end())
61 {return search->second.transform;}
62 else
63 {throw BDSException(__METHOD_NAME__, "unknown link element ID " + std::to_string(ID));}
64}
65
66const G4Transform3D& BDSLinkRegistry::TransformInverse(const std::string& name) const
67{
68 auto search = byName.find(name);
69 if (search != byName.end())
70 {return search->second.transformInverse;}
71 else
72 {throw BDSException(__METHOD_NAME__, "unknown link element name \"" + name + "\"");}
73}
74
75const G4Transform3D& BDSLinkRegistry::TransformInverse(const G4int ID) const
76{
77 auto search = byID.find(ID);
78 if (search != byID.end())
79 {return search->second.transformInverse;}
80 else
81 {throw BDSException(__METHOD_NAME__, "unknown link element ID " + std::to_string(ID));}
82}
83
84G4bool BDSLinkRegistry::NoRotation(const std::string& name) const
85{
86 auto search = byName.find(name);
87 if (search != byName.end())
88 {return search->second.noRotation;}
89 else
90 {throw BDSException(__METHOD_NAME__, "unknown link element name \"" + name + "\"");}
91}
92
93G4bool BDSLinkRegistry::NoRotation(G4int ID) const
94{
95 auto search = byID.find(ID);
96 if (search != byID.end())
97 {return search->second.noRotation;}
98 else
99 {throw BDSException(__METHOD_NAME__, "unknown link element ID " + std::to_string(ID));}
100}
General exception with possible name of object and message.
Definition: BDSException.hh:35
Wrapper box for an accelerator component.
G4bool Angled() const
Accessor.
G4String LinkName() const
Accessor.
G4int PlaceOutputSampler()
Place the output sampler.