BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSMagnetGeometryType.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
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 "BDSMagnetGeometryType.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 BDSMagnetGeometryType
31template<>
32std::map<BDSMagnetGeometryType, std::string>* BDSMagnetGeometryType::dictionary =
33 new std::map<BDSMagnetGeometryType, std::string> ({
34 {BDSMagnetGeometryType::none, "none"},
35 {BDSMagnetGeometryType::cylindrical, "cylindrical"},
36 {BDSMagnetGeometryType::polescircular, "polescircular"},
37 {BDSMagnetGeometryType::polessquare, "polessquare"},
38 {BDSMagnetGeometryType::polesfacet, "polesfacet"},
39 {BDSMagnetGeometryType::polesfacetcrop,"polesfacetcrop"},
40 {BDSMagnetGeometryType::lhcleft, "lhcleft"},
41 {BDSMagnetGeometryType::lhcright, "lhcright"},
42 {BDSMagnetGeometryType::external, "external"}
43});
44
46{
47 // If it contains a colon ":" it must be external geometry format format:filepath
48 if (BDS::StrContains(geometryType, ":"))
49 {return BDSMagnetGeometryType::external;}
50
51 std::map<G4String, BDSMagnetGeometryType> types;
52 types["none"] = BDSMagnetGeometryType::none;
53 types["cylindrical"] = BDSMagnetGeometryType::cylindrical;
54 types["polescircular"] = BDSMagnetGeometryType::polescircular;
55 types["polessquare"] = BDSMagnetGeometryType::polessquare;
56 types["polesfacet"] = BDSMagnetGeometryType::polesfacet;
57 types["polesfacetcrop"] = BDSMagnetGeometryType::polesfacetcrop;
58 types["lhcleft"] = BDSMagnetGeometryType::lhcleft;
59 types["lhcright"] = BDSMagnetGeometryType::lhcright;
60 types["format:filepath"] = BDSMagnetGeometryType::external;
61
62 geometryType = BDS::LowerCase(geometryType);
63
64 auto result = types.find(geometryType);
65 if (result == types.end())
66 {// it's not a valid key
67 G4String msg = "\"" + geometryType + "\" is not a valid geometry type\n";
68 msg += "Available magnet geometry types are:\n";
69 for (const auto& it : types)
70 {msg += "\"" + it.first + "\"\n";}
71 throw BDSException(__METHOD_NAME__, msg);
72 }
73
74#ifdef BDSDEBUG
75 G4cout << __METHOD_NAME__ << " determined geometry type to be " << result->second << G4endl;
76#endif
77 return result->second;
78}
General exception with possible name of object and message.
Definition: BDSException.hh:35
static std::map< BDSTypeSafeEnum< magnetgeometrytypes_def, G4int >, std::string > * dictionary
BDSMagnetGeometryType DetermineMagnetGeometryType(G4String geometryType)
function to determine the enum type of the magnet geometry (case-insensitive)
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.