BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSTunnelType.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 "BDSTunnelType.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 BDSTunnelType
31template<>
32std::map<BDSTunnelType, std::string>* BDSTunnelType::dictionary =
33 new std::map<BDSTunnelType, std::string> ({
34 {BDSTunnelType::circular, "circular"},
35 {BDSTunnelType::elliptical, "elliptical"},
36 {BDSTunnelType::square, "square"},
37 {BDSTunnelType::rectangular, "rectangular"},
38 {BDSTunnelType::rectaboveground,"rectaboveground"},
39 {BDSTunnelType::ilc, "ilc"}
40});
41
43{
44 std::map<G4String, BDSTunnelType> types;
45 types["circular"] = BDSTunnelType::circular;
46 types["elliptical"] = BDSTunnelType::elliptical;
47 types["square"] = BDSTunnelType::square;
48 types["rectangular"] = BDSTunnelType::rectangular;
49 types["ilc"] = BDSTunnelType::ilc;
50 types["rectaboveground"] = BDSTunnelType::rectaboveground;
51
52 tunnelType = BDS::LowerCase(tunnelType);
53
54 auto result = types.find(tunnelType);
55 if (result == types.end() )
56 {// it's not a valid key
57 G4String msg = "\"" + tunnelType + "\" is not a valid tunnel type\n";
58 msg += "Available tunnel types are:\n";
59 for (const auto& it : types)
60 {msg += "\"" + it.first + "\"\n";}
61 throw BDSException(__METHOD_NAME__, msg);
62 }
63
64#ifdef BDSDEBUG
65 G4cout << __METHOD_NAME__ << " determined tunnel type to be " << result->second << G4endl;
66#endif
67 return result->second;
68}
General exception with possible name of object and message.
Definition: BDSException.hh:35
static std::map< BDSTypeSafeEnum< tunneltypes_def, int >, std::string > * dictionary
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
BDSTunnelType DetermineTunnelType(G4String tunnelType)
Function to determine the enum type of the tunnel (case-insensitive)