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