BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSCavityFieldType.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 "BDSCavityFieldType.hh"
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSFieldType.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 BDSCavityFieldType
31template<>
32std::map<BDSCavityFieldType, std::string>* BDSCavityFieldType::dictionary =
33 new std::map<BDSCavityFieldType, std::string> ({
34 {BDSCavityFieldType::constantinz, "constantinz"},
35 {BDSCavityFieldType::pillbox, "pillbox"}
36});
37
39{
40 std::map<G4String, BDSCavityFieldType> types;
41 types["constantinz"] = BDSCavityFieldType::constantinz;
42 types["pillbox"] = BDSCavityFieldType::pillbox;
43
44 cavityFieldType = BDS::LowerCase(cavityFieldType);
45
46 auto result = types.find(cavityFieldType);
47 if (result == types.end())
48 {// it's not a valid key
49 G4String msg = "\"" + cavityFieldType + "\" is not a valid cavity field type\n";
50 msg += "Available cavity field types are:\n";
51 for (const auto& it : types)
52 {msg += "\"" + it.first + "\"\n";}
53 throw BDSException(__METHOD_NAME__, msg);
54 }
55
56#ifdef BDSDEBUG
57 G4cout << __METHOD_NAME__ << " determined cavity field type to be " << result->second << G4endl;
58#endif
59 return result->second;
60}
61
62BDSFieldType BDS::FieldTypeFromCavityFieldType(BDSCavityFieldType cavityFieldType)
63{
64 BDSFieldType result;
65 switch (cavityFieldType.underlying())
66 {
67 case BDSCavityFieldType::constantinz:
68 {result = BDSFieldType::rfconstantinz; break;}
69 case BDSCavityFieldType::pillbox:
70 {result = BDSFieldType::rfpillbox; break;}
71 }
72 return result;
73}
General exception with possible name of object and message.
Improve type-safety of native enum data type in C++.
static std::map< BDSTypeSafeEnum< def, inner >, std::string > * dictionary
type underlying() const
return underlying value (can be used in switch statement)
BDSCavityFieldType DetermineCavityFieldType(G4String cavityFieldType)
function to determine the enum type of the cavity field type (case-insensitive)
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.