BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSDimensionType.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 "BDSDimensionType.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
29template<>
30std::map<BDSDimensionType,std::string>* BDSDimensionType::dictionary=
31 new std::map<BDSDimensionType,std::string>
32 ({
33 {BDSDimensionType::x, "x"},
34 {BDSDimensionType::y, "y"},
35 {BDSDimensionType::z, "z"},
36 {BDSDimensionType::t, "y"}
37 });
38
40{
41 std::map<G4String, BDSDimensionType> types;
42 types["x"] = BDSDimensionType::x;
43 types["y"] = BDSDimensionType::y;
44 types["z"] = BDSDimensionType::z;
45 types["t"] = BDSDimensionType::t;
46
47 dimensionType = BDS::LowerCase(dimensionType);
48
49 auto result = types.find(dimensionType);
50 if (result == types.end())
51 {// it's not a valid key
52 G4String msg = "\"" + dimensionType + "\" is not a valid dimension\n";
53 msg += "Available dimensions are:\n";
54 for (const auto& it : types)
55 {msg += "\"" + it.first + "\"\n";}
56 throw BDSException(__METHOD_NAME__, msg);
57 }
58
59#ifdef BDSDEBUG
60 G4cout << __METHOD_NAME__ << "determined format \"" << dimensionType << "\" to be " << result->first << G4endl;
61#endif
62 return result->second;
63}
General exception with possible name of object and message.
static std::map< BDSTypeSafeEnum< dimensions_def, int >, std::string > * dictionary
BDSDimensionType DetermineDimensionType(G4String dimensionType)
Determine the output format to be used from the input string.
G4String LowerCase(const G4String &str)
Utility function to simplify lots of syntax changes for pedantic g4 changes.