BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSBunchType.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 "BDSBunchType.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 BDSBunchType
30template<>
31std::map<BDSBunchType, std::string>* BDSBunchType::dictionary =
32 new std::map<BDSBunchType, std::string> ({
33 {BDSBunchType::reference, "reference"},
34 {BDSBunchType::gaussmatrix, "gaussmatrix"},
35 {BDSBunchType::gauss, "gauss"},
36 {BDSBunchType::gausstwiss, "gausstwiss"},
37 {BDSBunchType::gaussmatrixslowext, "gaussmatrixslowext"},
38 {BDSBunchType::gaussslowext, "gaussslowext"},
39 {BDSBunchType::gausstwissslowext, "gausstwissslowext"},
40 {BDSBunchType::circle, "circle"},
41 {BDSBunchType::square, "square"},
42 {BDSBunchType::ring, "ring"},
43 {BDSBunchType::eshell, "eshell"},
44 {BDSBunchType::halo, "halo"},
45 {BDSBunchType::composite, "composite"},
46 {BDSBunchType::userfile, "userfile"},
47 {BDSBunchType::ptc, "ptc"},
48 {BDSBunchType::sixtrack, "sixtrack"},
49 {BDSBunchType::eventgeneratorfile, "eventgeneratorfile"},
50 {BDSBunchType::sphere, "sphere"},
51 {BDSBunchType::compositesde,"compositespacedirectionenergy"},
52 {BDSBunchType::box, "box"},
53 {BDSBunchType::halosigma, "halosigma"},
54 {BDSBunchType::bdsimsampler,"bdsimsampler"},
55 {BDSBunchType::hdf5, "hdf5"},
56 {BDSBunchType::slowext, "slowext"},
57});
58
60{
61 std::map<G4String, BDSBunchType> types;
62
63 types["reference"] = BDSBunchType::reference;
64 types["gaussmatrix"] = BDSBunchType::gaussmatrix;
65 types["gauss-matrix"] = BDSBunchType::gaussmatrix;
66 types["gauss"] = BDSBunchType::gauss;
67 types["gausstwiss"] = BDSBunchType::gausstwiss;
68 types["gauss-twiss"] = BDSBunchType::gausstwiss;
69 types["gaussmatrixslowext"] = BDSBunchType::gaussmatrixslowext;
70 types["gauss-matrix-slow-ext"] = BDSBunchType::gaussmatrixslowext;
71 types["gaussslowext"] = BDSBunchType::gaussslowext;
72 types["gauss-slow-ext"] = BDSBunchType::gaussslowext;
73 types["gausstwissslowext"] = BDSBunchType::gausstwissslowext;
74 types["gauss-twiss-slow-ext"] = BDSBunchType::gausstwissslowext;
75 types["circle"] = BDSBunchType::circle;
76 types["square"] = BDSBunchType::square;
77 types["ring"] = BDSBunchType::ring;
78 types["eshell"] = BDSBunchType::eshell;
79 types["halo"] = BDSBunchType::halo;
80 types["composite"] = BDSBunchType::composite;
81 types["userfile"] = BDSBunchType::userfile;
82 types["user-file"] = BDSBunchType::userfile;
83 types["ptc"] = BDSBunchType::ptc;
84 types["sixtrack"] = BDSBunchType::sixtrack;
85 types["eventgeneratorfile"] = BDSBunchType::eventgeneratorfile;
86 types["event-generator-file"] = BDSBunchType::eventgeneratorfile;
87 types["sphere"] = BDSBunchType::sphere;
88 types["compositespacedirectionenergy"] = BDSBunchType::compositesde;
89 types["composite-space-direction-energy"] = BDSBunchType::compositesde;
90 types["compositesde"] = BDSBunchType::compositesde;
91 types["box"] = BDSBunchType::box;
92 types["halosigma"] = BDSBunchType::halosigma;
93 types["halo-sigma"] = BDSBunchType::halosigma;
94 types["bdsimsampler"] = BDSBunchType::bdsimsampler;
95 types["bdsim-sampler"] = BDSBunchType::bdsimsampler;
96 types["hdf5"] = BDSBunchType::hdf5;
97 types["slowext"] = BDSBunchType::slowext;
98 types["slow-ext"] = BDSBunchType::slowext;
99
100 distrType = BDS::LowerCase(distrType);
101
102 auto result = types.find(distrType);
103 if (result == types.end())
104 {// it's not a valid key
105 G4String message = "\"" + distrType + "\" is not a valid distribution\n";
106 message += "Available distributions are:\n";
107 for (const auto& it : types)
108 {message += it.first + "\n";}
109 throw BDSException(__METHOD_NAME__, message);
110 }
111
112#ifdef BDSDEBUG
113 G4cout << __METHOD_NAME__ << "determined distribution to be " << result->second << G4endl;
114#endif
115 return result->second;
116}
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.
BDSBunchType DetermineBunchType(G4String distrType)
Function that gives corresponding enum value for string (case-insensitive).