BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSBunchType.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 "BDSBunchType.hh"
20#include "BDSDebug.hh"
21#include "BDSException.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh"
25#include "G4String.hh"
26
27#include <map>
28#include <string>
29
30// dictionary for BDSBunchType
31template<>
32std::map<BDSBunchType, std::string>* BDSBunchType::dictionary =
33 new std::map<BDSBunchType, std::string> ({
34 {BDSBunchType::reference, "reference"},
35 {BDSBunchType::gaussmatrix, "gaussmatrix"},
36 {BDSBunchType::gauss, "gauss"},
37 {BDSBunchType::gausstwiss, "gausstwiss"},
38 {BDSBunchType::circle, "circle"},
39 {BDSBunchType::square, "square"},
40 {BDSBunchType::ring, "ring"},
41 {BDSBunchType::eshell, "eshell"},
42 {BDSBunchType::halo, "halo"},
43 {BDSBunchType::composite, "composite"},
44 {BDSBunchType::userfile, "userfile"},
45 {BDSBunchType::ptc, "ptc"},
46 {BDSBunchType::sixtrack, "sixtrack"},
47 {BDSBunchType::eventgeneratorfile, "eventgeneratorfile"},
48 {BDSBunchType::sphere, "sphere"},
49 {BDSBunchType::compositesde,"compositespacedirectionenergy"},
50 {BDSBunchType::box, "box"},
51 {BDSBunchType::halosigma, "halosigma"},
52 {BDSBunchType::bdsimsampler, "bdsimsampler"}
53});
54
56{
57 std::map<G4String, BDSBunchType> types;
58
59 types["reference"] = BDSBunchType::reference;
60 types["gaussmatrix"] = BDSBunchType::gaussmatrix;
61 types["gauss"] = BDSBunchType::gauss;
62 types["gausstwiss"] = BDSBunchType::gausstwiss;
63 types["circle"] = BDSBunchType::circle;
64 types["square"] = BDSBunchType::square;
65 types["ring"] = BDSBunchType::ring;
66 types["eshell"] = BDSBunchType::eshell;
67 types["halo"] = BDSBunchType::halo;
68 types["composite"] = BDSBunchType::composite;
69 types["userfile"] = BDSBunchType::userfile;
70 types["ptc"] = BDSBunchType::ptc;
71 types["sixtrack"] = BDSBunchType::sixtrack;
72 types["eventgeneratorfile"] = BDSBunchType::eventgeneratorfile;
73 types["sphere"] = BDSBunchType::sphere;
74 types["compositespacedirectionenergy"] = BDSBunchType::compositesde;
75 types["compositesde"] = BDSBunchType::compositesde;
76 types["box"] = BDSBunchType::box;
77 types["halosigma"] = BDSBunchType::halosigma;
78 types["bdsimsampler"] = BDSBunchType::bdsimsampler;
79
80 distrType = BDS::LowerCase(distrType);
81
82 auto result = types.find(distrType);
83 if (result == types.end())
84 {// it's not a valid key
85 G4String message = "\"" + distrType + "\" is not a valid distribution\n";
86 message += "Available distributions are:\n";
87 for (const auto& it : types)
88 {message += it.first + "\n";}
89 throw BDSException(__METHOD_NAME__, message);
90 }
91
92#ifdef BDSDEBUG
93 G4cout << __METHOD_NAME__ << "determined distribution to be " << result->second << G4endl;
94#endif
95 return result->second;
96}
General exception with possible name of object and message.
Definition: BDSException.hh:35
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.
BDSBunchType DetermineBunchType(G4String distrType)
Function that gives corresponding enum value for string (case-insensitive).
Definition: BDSBunchType.cc:55