BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSApertureType.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 "BDSApertureType.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 BDSApertureType
31template<>
32std::map<BDSApertureType, std::string>* BDSApertureType::dictionary =
33 new std::map<BDSApertureType, std::string> ({
34 {BDSApertureType::circular, "circular"},
35 {BDSApertureType::elliptical, "elliptical"},
36 {BDSApertureType::lhc, "lhc"},
37 {BDSApertureType::lhcdetailed, "lhcdetailed"},
38 {BDSApertureType::rectangular, "rectangular"},
39 {BDSApertureType::rectellipse, "rectellipse"},
40 {BDSApertureType::racetrack, "racetrack"},
41 {BDSApertureType::octagonal, "octagonal"},
42 {BDSApertureType::circularvacuum, "circularvacuum"},
43 {BDSApertureType::clicpcl, "clicpcl"}
44});
45
47{
48 std::map<G4String, BDSApertureType> types;
49 types["circular"] = BDSApertureType::circular;
50 types["elliptical"] = BDSApertureType::elliptical;
51 types["rectangular"] = BDSApertureType::rectangular;
52 types["lhc"] = BDSApertureType::lhc;
53 types["lhcscreen"] = BDSApertureType::lhc; // shortcut for madx compatability
54 types["lhcdetailed"] = BDSApertureType::lhcdetailed;
55 types["rectellipse"] = BDSApertureType::rectellipse;
56 types["racetrack"] = BDSApertureType::racetrack;
57 types["octagonal"] = BDSApertureType::octagonal;
58 types["circularvacuum"] = BDSApertureType::circularvacuum;
59 types["clicpcl"] = BDSApertureType::clicpcl;
60
61 apertureType = BDS::LowerCase(apertureType);
62
63 auto result = types.find(apertureType);
64 if (result == types.end())
65 {// it's not a valid key
66 G4String msg = "\"" + apertureType + "\" is not a valid apertureType\n";
67 msg += "Available geometry types are:\n";
68 for (const auto& it : types)
69 {msg += "\"" + it.first + "\"\n";}
70 throw BDSException(__METHOD_NAME__, msg);
71 }
72
73#ifdef BDSDEBUG
74 G4cout << __METHOD_NAME__ << "determined aperture type to be " << result->second << G4endl;
75#endif
76 return result->second;
77}
General exception with possible name of object and message.
Definition: BDSException.hh:35
static std::map< BDSTypeSafeEnum< aperturetypes_def, int >, std::string > * dictionary
BDSApertureType DetermineApertureType(G4String apertureType)
function that gives corresponding enum value for string (case-insensitive)
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.