BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSOutputType.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 "BDSDebug.hh"
20#include "BDSException.hh"
21#include "BDSOutputType.hh"
22#include "BDSUtilities.hh"
23
24#include "globals.hh"
25#include "G4String.hh"
26
27#include <map>
28#include <string>
29
30template<>
31std::map<BDSOutputType,std::string>* BDSOutputType::dictionary=
32 new std::map<BDSOutputType,std::string> ({
33 {BDSOutputType::none,"none"},
34 {BDSOutputType::rootevent,"rootevent"}
35 });
36
38{
39 std::map<G4String, BDSOutputType> types;
40 types["none"] = BDSOutputType::none;
41 types["rootevent"] = BDSOutputType::rootevent;
42
43 outputType = BDS::LowerCase(outputType);
44
45 auto result = types.find(outputType);
46 if (result == types.end())
47 {// it's not a valid key
48 G4String msg = "\"" + outputType + "\" is not a valid output format\n";
49 msg += "Available output formats are:\n";
50 for (const auto& it : types)
51 {msg += "\"" + it.first + "\"\n";}
52 throw BDSException(__METHOD_NAME__, msg);
53 }
54
55#ifdef BDSDEBUG
56 G4cout << __METHOD_NAME__ << "determined format \"" << outputType << "\" to be " << result->first << G4endl;
57#endif
58 return result->second;
59}
General exception with possible name of object and message.
Definition: BDSException.hh:35
static std::map< BDSTypeSafeEnum< outputformats_def, int >, std::string > * dictionary
BDSOutputType DetermineOutputType(G4String outputType)
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.