BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBLMType.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 "BDSBLMType.hh"
19#include "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSUtilities.hh"
22
23#include "globals.hh"
24#include "G4String.hh"
25
26#include <map>
27#include <string>
28
29// dictionary for BDSBLMType
30template<>
31std::map<BDSBLMType, std::string>* BDSBLMType::dictionary =
32 new std::map<BDSBLMType, std::string> ({
33 {BDSBLMType::cylinder, "cylinder"},
34 {BDSBLMType::cube, "cube"},
35 {BDSBLMType::sphere, "sphere"}
36 });
37
39{
40 std::map<G4String, BDSBLMType> types;
41 types["cylinder"] = BDSBLMType::cylinder;
42 types["cube"] = BDSBLMType::cube;
43 types["sphere"] = BDSBLMType::sphere;
44
45 blmType = BDS::LowerCase(blmType);
46
47 auto result = types.find(blmType);
48 if (result == types.end())
49 {// it's not a valid key
50 G4String msg = "\"" + blmType + "\" is not a valid blmType\n";
51 msg += "Available geometry 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 blm type to be " << result->second << G4endl;
59#endif
60 return result->second;
61}
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
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
BDSBLMType DetermineBLMType(G4String blmType)
function that gives corresponding enum value for string (case-insensitive)
Definition BDSBLMType.cc:38