BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSIntegratorSetType.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2022.
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 "BDSIntegratorSetType.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh"
25#include "G4String.hh"
26
27#include <map>
28#include <string>
29
30template<>
31std::map<BDSIntegratorSetType, std::string>* BDSIntegratorSetType::dictionary =
32 new std::map<BDSIntegratorSetType, std::string> ({
33 {BDSIntegratorSetType::geant4, "geant4"},
34 {BDSIntegratorSetType::bdsimone, "bdsimone"},
35 {BDSIntegratorSetType::bdsimtwo, "bdsimtwo"},
36 {BDSIntegratorSetType::bdsimmatrix, "bdsimmatrix"},
37 {BDSIntegratorSetType::bdsimmatrixfringescaling, "bdsimmatrixfringescaling"}
38#if G4VERSION_NUMBER > 1039
39 ,
40 {BDSIntegratorSetType::geant4dp, "geant4dp"}
41#endif
42 });
43
45{
46 std::map<G4String, BDSIntegratorSetType> types;
47 types["bdsim"] = BDSIntegratorSetType::bdsimtwo; // alias for bdsim two the default
48 types["geant4"] = BDSIntegratorSetType::geant4;
49 types["bdsimone"] = BDSIntegratorSetType::bdsimone;
50 types["bdsimtwo"] = BDSIntegratorSetType::bdsimtwo;
51 types["bdsimmatrix"] = BDSIntegratorSetType::bdsimmatrix;
52 types["bdsimmatrixfringescaling"] = BDSIntegratorSetType::bdsimmatrixfringescaling;
53#if G4VERSION_NUMBER > 1039
54 types["geant4dp"] = BDSIntegratorSetType::geant4dp;
55#endif
56
57 integratorSet = BDS::LowerCase(integratorSet);
58
59 auto result = types.find(integratorSet);
60 if (result == types.end())
61 {// it's not a valid key
62 G4String msg = "\"" + integratorSet + "\" is not a valid integrator set\n";
63 msg += "Available sets are:\n";
64 for (const auto& it : types)
65 {msg += "\"" + it.first + "\"\n";}
66 throw BDSException(__METHOD_NAME__, msg);
67 }
68
69#ifdef BDSDEBUG
70 G4cout << __METHOD_NAME__ << "determined integrator set to be " << result->second << G4endl;
71#endif
72 return result->second;
73}
General exception with possible name of object and message.
Definition: BDSException.hh:35
static std::map< BDSTypeSafeEnum< integratorsettype_def, int >, std::string > * dictionary
BDSIntegratorSetType DetermineIntegratorSetType(G4String integratorSet)
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.