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) Royal Holloway,
3University of London 2001 - 2024.
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 "BDSCavityFieldType.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSFieldType.hh"
23#include "BDSUtilities.hh"
24
25#include "globals.hh"
26#include "G4String.hh"
27
28#include <map>
29#include <string>
30
31// dictionary for BDSCavityFieldType
32template<>
33std::map<BDSCavityFieldType, std::string>* BDSCavityFieldType::dictionary =
34 new std::map<BDSCavityFieldType, std::string> ({
35 {BDSCavityFieldType::constantinz, "constantinz"},
36 {BDSCavityFieldType::pillbox, "pillbox"}
37});
38
40{
41 std::map<G4String, BDSCavityFieldType> types;
42 types["constantinz"] = BDSCavityFieldType::constantinz;
43 types["pillbox"] = BDSCavityFieldType::pillbox;
44
45 cavityFieldType = BDS::LowerCase(cavityFieldType);
46
47 auto result = types.find(cavityFieldType);
48 if (result == types.end())
49 {// it's not a valid key
50 G4String msg = "\"" + cavityFieldType + "\" is not a valid cavity field type\n";
51 msg += "Available cavity field types are:\n";
52 for (const auto& it : types)
53 {msg += "\"" + it.first + "\"\n";}
54 throw BDSException(__METHOD_NAME__, msg);
55 }
56
57#ifdef BDSDEBUG
58 G4cout << __METHOD_NAME__ << " determined cavity field type to be " << result->second << G4endl;
59#endif
60 return result->second;
61}
62
63BDSFieldType BDS::FieldTypeFromCavityFieldType(BDSCavityFieldType cavityFieldType)
64{
65 BDSFieldType result;
66 switch (cavityFieldType.underlying())
67 {
68 case BDSCavityFieldType::constantinz:
69 {result = BDSFieldType::rfconstantinz; break;}
70 case BDSCavityFieldType::pillbox:
71 {result = BDSFieldType::rfpillbox; break;}
72 }
73 return result;
74}
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.