BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBeamPipeType.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 "BDSBeamPipeType.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh"
25#include "G4String.hh"
26
27#include <map>
28#include <string>
29
30// dictionary for BDSBeamPipeType
31template<>
32std::map<BDSBeamPipeType, std::string>* BDSBeamPipeType::dictionary =
33 new std::map<BDSBeamPipeType, std::string> ({
34 {BDSBeamPipeType::circular, "circular"},
35 {BDSBeamPipeType::elliptical, "elliptical"},
36 {BDSBeamPipeType::lhc, "lhc"},
37 {BDSBeamPipeType::lhcdetailed, "lhcdetailed"},
38 {BDSBeamPipeType::rectangular, "rectangular"},
39 {BDSBeamPipeType::rectellipse, "rectellipse"},
40 {BDSBeamPipeType::racetrack, "racetrack"},
41 {BDSBeamPipeType::octagonal, "octagonal"},
42 {BDSBeamPipeType::circularvacuum, "circularvacuum"},
43 {BDSBeamPipeType::clicpcl, "clicpcl"},
44 {BDSBeamPipeType::rhombus, "rhombus"}
45});
46
48{
49 std::map<G4String, BDSBeamPipeType> types;
50 types["circular"] = BDSBeamPipeType::circular;
51 types["elliptical"] = BDSBeamPipeType::elliptical;
52 types["rectangular"] = BDSBeamPipeType::rectangular;
53 types["lhc"] = BDSBeamPipeType::lhc;
54 types["lhcscreen"] = BDSBeamPipeType::lhc; // shortcut for madx compatability
55 types["lhcdetailed"] = BDSBeamPipeType::lhcdetailed;
56 types["rectellipse"] = BDSBeamPipeType::rectellipse;
57 types["racetrack"] = BDSBeamPipeType::racetrack;
58 types["octagonal"] = BDSBeamPipeType::octagonal;
59 types["circularvacuum"] = BDSBeamPipeType::circularvacuum;
60 types["clicpcl"] = BDSBeamPipeType::clicpcl;
61 types["pointsfile"] = BDSBeamPipeType::pointsfile; // added only so the error print out will be correct
62 types["rhombus"] = BDSBeamPipeType::rhombus;
63
64 apertureType = BDS::LowerCase(apertureType);
65
66 // string will be pointsfile:somefile.dat, so we specially
67 // detect this one as it won't match exactly
68 if (BDS::StrContains(apertureType, "pointsfile"))
69 {return BDSBeamPipeType::pointsfile;}
70
71 auto result = types.find(apertureType);
72 if (result == types.end())
73 {// it's not a valid key
74 G4String msg = "\"" + apertureType + "\" is not a valid apertureType\n";
75 msg += "Available geometry types are:\n";
76 for (const auto& it : types)
77 {msg += "\"" + it.first + "\"\n";}
78 throw BDSException(__METHOD_NAME__, msg);
79 }
80
81#ifdef BDSDEBUG
82 G4cout << __METHOD_NAME__ << "determined aperture type to be " << result->second << G4endl;
83#endif
84 return result->second;
85}
General exception with possible name of object and message.
Definition: BDSException.hh:35
static std::map< BDSTypeSafeEnum< beampipetypes_def, int >, std::string > * dictionary
G4bool StrContains(const G4String &str, const G4String &test)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
Definition: BDSUtilities.cc:66
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
BDSBeamPipeType DetermineBeamPipeType(G4String apertureType)
Function that gives corresponding enum value for string (case-insensitive).