BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSEventGeneratorFileType.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2023.
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 "BDSEventGeneratorFileType.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 BDSEventGeneratorFileType
31template<>
32std::map<BDSEventGeneratorFileType, std::string>* BDSEventGeneratorFileType::dictionary =
33 new std::map<BDSEventGeneratorFileType, std::string> ({
34 {BDSEventGeneratorFileType::hepmc2, "hepmc2"},
35 {BDSEventGeneratorFileType::hepmc3, "hepmc3"},
36 {BDSEventGeneratorFileType::hpe, "hpe"},
37 {BDSEventGeneratorFileType::root, "root"},
38 {BDSEventGeneratorFileType::treeroot, "treeroot"},
39 {BDSEventGeneratorFileType::lhef, "lhef"},
40});
41
43{
44 std::map<G4String, BDSEventGeneratorFileType> types;
45
46 types["hepmc2"] = BDSEventGeneratorFileType::hepmc2;
47 types["hepmc3"] = BDSEventGeneratorFileType::hepmc3;
48 types["hpe"] = BDSEventGeneratorFileType::hpe;
49 types["root"] = BDSEventGeneratorFileType::root;
50 types["treeroot"] = BDSEventGeneratorFileType::treeroot;
51 types["lhef"] = BDSEventGeneratorFileType::lhef;
52
53 distrType = BDS::LowerCase(distrType);
54
55 auto result = types.find(distrType);
56 if (result == types.end())
57 {// it's not a valid key
58 G4String msg = "\"" + distrType + "\" is not a valid event generator file format\n";
59 msg += "Available formats are:\n";
60 for (const auto& it : types)
61 {msg += "\"" + it.first + "\"\n";}
62 throw BDSException(__METHOD_NAME__, msg);
63 }
64
65#ifdef BDSDEBUG
66 G4cout << __METHOD_NAME__ << "determined event generator file format to be " << result->second << G4endl;
67#endif
68 return result->second;
69}
General exception with possible name of object and message.
Definition: BDSException.hh:35
static std::map< BDSTypeSafeEnum< eventgeneratorfiletypes_def, int >, std::string > * dictionary
BDSEventGeneratorFileType DetermineEventGeneratorFileType(G4String distrType)
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.