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) 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 "BDSTunnelType.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 BDSTunnelType
30template<>
31std::map<BDSTunnelType, std::string>* BDSTunnelType::dictionary =
32 new std::map<BDSTunnelType, std::string> ({
33 {BDSTunnelType::circular, "circular"},
34 {BDSTunnelType::elliptical, "elliptical"},
35 {BDSTunnelType::square, "square"},
36 {BDSTunnelType::rectangular, "rectangular"},
37 {BDSTunnelType::rectaboveground,"rectaboveground"},
38 {BDSTunnelType::ilc, "ilc"}
39});
40
42{
43 std::map<G4String, BDSTunnelType> types;
44 types["circular"] = BDSTunnelType::circular;
45 types["elliptical"] = BDSTunnelType::elliptical;
46 types["square"] = BDSTunnelType::square;
47 types["rectangular"] = BDSTunnelType::rectangular;
48 types["ilc"] = BDSTunnelType::ilc;
49 types["rectaboveground"] = BDSTunnelType::rectaboveground;
50
51 tunnelType = BDS::LowerCase(tunnelType);
52
53 auto result = types.find(tunnelType);
54 if (result == types.end() )
55 {// it's not a valid key
56 G4String msg = "\"" + tunnelType + "\" is not a valid tunnel type\n";
57 msg += "Available tunnel types are:\n";
58 for (const auto& it : types)
59 {msg += "\"" + it.first + "\"\n";}
60 throw BDSException(__METHOD_NAME__, msg);
61 }
62
63#ifdef BDSDEBUG
64 G4cout << __METHOD_NAME__ << " determined tunnel type to be " << result->second << G4endl;
65#endif
66 return result->second;
67}
General exception with possible name of object and message.
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)