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) 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 "BDSApertureType.hh"
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSUtilities.hh"
22
23#include "globals.hh"
24#include "G4String.hh"
25
26#include <map>
27#include <string>
28
29// dictionary for BDSApertureType
30template<>
31std::map<BDSApertureType, std::string>* BDSApertureType::dictionary =
32 new std::map<BDSApertureType, std::string> ({
33 {BDSApertureType::circular, "circular"},
34 {BDSApertureType::elliptical, "elliptical"},
35 {BDSApertureType::lhc, "lhc"},
36 {BDSApertureType::lhcdetailed, "lhcdetailed"},
37 {BDSApertureType::rectangular, "rectangular"},
38 {BDSApertureType::rectellipse, "rectellipse"},
39 {BDSApertureType::racetrack, "racetrack"},
40 {BDSApertureType::octagonal, "octagonal"},
41 {BDSApertureType::circularvacuum, "circularvacuum"},
42 {BDSApertureType::clicpcl, "clicpcl"}
43});
44
46{
47 std::map<G4String, BDSApertureType> types;
48 types["circular"] = BDSApertureType::circular;
49 types["elliptical"] = BDSApertureType::elliptical;
50 types["rectangular"] = BDSApertureType::rectangular;
51 types["lhc"] = BDSApertureType::lhc;
52 types["lhcscreen"] = BDSApertureType::lhc; // shortcut for madx compatability
53 types["lhcdetailed"] = BDSApertureType::lhcdetailed;
54 types["rectellipse"] = BDSApertureType::rectellipse;
55 types["racetrack"] = BDSApertureType::racetrack;
56 types["octagonal"] = BDSApertureType::octagonal;
57 types["circularvacuum"] = BDSApertureType::circularvacuum;
58 types["clicpcl"] = BDSApertureType::clicpcl;
59
60 apertureType = BDS::LowerCase(apertureType);
61
62 auto result = types.find(apertureType);
63 if (result == types.end())
64 {// it's not a valid key
65 G4String msg = "\"" + apertureType + "\" is not a valid apertureType\n";
66 msg += "Available geometry types are:\n";
67 for (const auto& it : types)
68 {msg += "\"" + it.first + "\"\n";}
69 throw BDSException(__METHOD_NAME__, msg);
70 }
71
72#ifdef BDSDEBUG
73 G4cout << __METHOD_NAME__ << "determined aperture type to be " << result->second << G4endl;
74#endif
75 return result->second;
76}
General exception with possible name of object and message.
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.