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) BDSIM Collaboration, 2001 - 2026.
3
4This file is part of BDSIM.
5
6BDSIM is free software: you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published
8by the Free Software Foundation version 3 of the License.
9
10BDSIM is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with BDSIM. If not, see <http://www.gnu.org/licenses/>.
17*/
18#include "BDSDebug.hh"
19#include "BDSException.hh"
20#include "BDSLinkOpaqueBox.hh"
21#include "BDSLinkRegistry.hh"
22
23#include "G4Transform3D.hh"
24#include "G4Types.hh"
25
26#include <map>
27#include <string>
28
29BDSLinkRegistry::BDSLinkRegistry()
30{;}
31
32BDSLinkRegistry::~BDSLinkRegistry()
33{;}
34
35G4int BDSLinkRegistry::Register(BDSLinkOpaqueBox* componentIn,
36 const G4Transform3D& globalToInputIn)
37{
38 G4int newID = componentIn->PlaceOutputSampler();
39 G4cout << "New ID " << newID << " for " << componentIn->LinkName() << G4endl;
40 G4bool noRotation = !(componentIn->Angled());
41 BDSLinkRegistry::LinkEntry le = {noRotation, componentIn, globalToInputIn, globalToInputIn.inverse(), newID};
42 byName[componentIn->LinkName()] = le;
43 byID[newID] = le;
44 return newID;
45}
46
47const G4Transform3D& BDSLinkRegistry::Transform(const std::string& name) const
48{
49 auto search = byName.find(name);
50 if (search != byName.end())
51 {return search->second.transform;}
52 else
53 {throw BDSException(__METHOD_NAME__, "unknown link element name \"" + name + "\"");}
54}
55
56const G4Transform3D& BDSLinkRegistry::Transform(const G4int ID) const
57{
58 auto search = byID.find(ID);
59 if (search != byID.end())
60 {return search->second.transform;}
61 else
62 {throw BDSException(__METHOD_NAME__, "unknown link element ID " + std::to_string(ID));}
63}
64
65const G4Transform3D& BDSLinkRegistry::TransformInverse(const std::string& name) const
66{
67 auto search = byName.find(name);
68 if (search != byName.end())
69 {return search->second.transformInverse;}
70 else
71 {throw BDSException(__METHOD_NAME__, "unknown link element name \"" + name + "\"");}
72}
73
74const G4Transform3D& BDSLinkRegistry::TransformInverse(const G4int ID) const
75{
76 auto search = byID.find(ID);
77 if (search != byID.end())
78 {return search->second.transformInverse;}
79 else
80 {throw BDSException(__METHOD_NAME__, "unknown link element ID " + std::to_string(ID));}
81}
82
83G4bool BDSLinkRegistry::NoRotation(const std::string& name) const
84{
85 auto search = byName.find(name);
86 if (search != byName.end())
87 {return search->second.noRotation;}
88 else
89 {throw BDSException(__METHOD_NAME__, "unknown link element name \"" + name + "\"");}
90}
91
92G4bool BDSLinkRegistry::NoRotation(G4int ID) const
93{
94 auto search = byID.find(ID);
95 if (search != byID.end())
96 {return search->second.noRotation;}
97 else
98 {throw BDSException(__METHOD_NAME__, "unknown link element ID " + std::to_string(ID));}
99}
General exception with possible name of object and message.
Wrapper box for an accelerator component.
G4bool Angled() const
Accessor.
G4String LinkName() const
Accessor.
G4int PlaceOutputSampler()
Place the output sampler.