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) 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 "BDSDebug.hh"
19#include "BDSException.hh"
20#include "BDSModulatorType.hh"
21#include "BDSUtilities.hh"
22
23#include "G4String.hh"
24
25#include <map>
26#include <string>
27
28// dictionary for BDSModulatorType for reflexivity
29template<>
30std::map<BDSModulatorType, std::string>* BDSModulatorType::dictionary =
31 new std::map<BDSModulatorType, std::string> ({
32 {BDSModulatorType::lineart, "lineart"},
33 {BDSModulatorType::none, "none"},
34 {BDSModulatorType::sint, "sint"},
35 {BDSModulatorType::singlobalt, "singlobalt"},
36 {BDSModulatorType::tophatt, "tophatt"}
37 });
38
40{
41 std::map<G4String, BDSModulatorType> types;
42 types["lineart"] = BDSModulatorType::lineart;
43 types["none"] = BDSModulatorType::none;
44 types["sint"] = BDSModulatorType::sint;
45 types["singlobalt"] = BDSModulatorType::singlobalt;
46 types["tophatt"] = BDSModulatorType::tophatt;
47
48 mType = BDS::LowerCase(mType);
49
50 auto result = types.find(mType);
51 if (result == types.end())
52 {// it's not a valid key
53 G4String msg = "\"" + mType + "\" is not a valid modulator type\n";
54 msg += "Available modulator types are:\n";
55 for (const auto& it : types)
56 {msg += "\"" + it.first + "\"\n";}
57 throw BDSException(__METHOD_NAME__, msg);
58 }
59
60#ifdef BDSDEBUG
61 G4cout << __METHOD_NAME__ << "determined modulator type to be " << result->second << G4endl;
62#endif
63 return result->second;
64}
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.