BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSModulatorType.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 "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSModulatorType.hh"
22#include "BDSUtilities.hh"
23
24#include "G4String.hh"
25
26#include <map>
27#include <string>
28
29// dictionary for BDSModulatorType for reflexivity
30template<>
31std::map<BDSModulatorType, std::string>* BDSModulatorType::dictionary =
32 new std::map<BDSModulatorType, std::string> ({
33 {BDSModulatorType::lineart, "lineart"},
34 {BDSModulatorType::none, "none"},
35 {BDSModulatorType::sint, "sint"},
36 {BDSModulatorType::singlobalt, "singlobalt"},
37 {BDSModulatorType::tophatt, "tophatt"}
38 });
39
41{
42 std::map<G4String, BDSModulatorType> types;
43 types["lineart"] = BDSModulatorType::lineart;
44 types["none"] = BDSModulatorType::none;
45 types["sint"] = BDSModulatorType::sint;
46 types["singlobalt"] = BDSModulatorType::singlobalt;
47 types["tophatt"] = BDSModulatorType::tophatt;
48
49 mType = BDS::LowerCase(mType);
50
51 auto result = types.find(mType);
52 if (result == types.end())
53 {// it's not a valid key
54 G4String msg = "\"" + mType + "\" is not a valid modulator type\n";
55 msg += "Available modulator types are:\n";
56 for (const auto& it : types)
57 {msg += "\"" + it.first + "\"\n";}
58 throw BDSException(__METHOD_NAME__, msg);
59 }
60
61#ifdef BDSDEBUG
62 G4cout << __METHOD_NAME__ << "determined modulator type to be " << result->second << G4endl;
63#endif
64 return result->second;
65}
General exception with possible name of object and message.
static std::map< BDSTypeSafeEnum< modulatortypes_def, int >, std::string > * dictionary
BDSModulatorType DetermineModulatorType(G4String mType)
Function that gives corresponding enum value for string (case-insensitive)
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.