BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSParser.cc
1/*
2Beam Delivery Simulation (BDSIM) Copyright (C) Royal Holloway,
3University of London 2001 - 2024.
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 "BDSParser.hh"
22#include "BDSUtilities.hh"
23
24#include <map>
25#include <string>
26#include <vector>
27
29
31{
32 if (!instance)
33 {
34 std::cerr << "BDSParser has not been initialised!" << std::endl;
35 exit(1);
36 }
37 return instance;
38}
39
40BDSParser* BDSParser::Instance(const std::string& name)
41{
42 if (instance)
43 {
44 std::cerr << "WARNING BDSParser was already initialised! " << std::endl;
45 delete instance;
46 }
47 instance = new BDSParser(name);
48 return instance;
49}
50
52{
53 return instance ? true : false;
54}
55
57{
58 std::cout << "BDSParser::~BDSParser" << std::endl;
59 instance = nullptr;
60 std::cout << "BDSParser::~BDSParser " << instance << std::endl;
61}
62
63BDSParser::BDSParser(const std::string& name):
64 GMAD::Parser(name)
65{
66 std::cout << __METHOD_NAME__ << "Using input file: "<< name << std::endl;
67}
68
70{
71 std::cout << __METHOD_NAME__ << "Only for python " << std::endl;
72 instance = this;
73}
74
76 G4bool recreate)
77{
78 // We only amalgamate when we're running normally. If we're recreating
79 // all beam parameters will be in the output file.
80 if (recreate)
81 {beam = execBeamIn;} // execBeamIn already has loaded recreation beam parameters
82 else
83 {beam.Amalgamate(execBeamIn, true);}
84}
85
87{
88 if (optionsIn.recreate)
89 {options = optionsIn;} // totally overwrite options
90 else
91 {options.Amalgamate(optionsIn, true);}
92}
93
95{
96 if (options.nGenerate <= 0) // run at least 1 event!
97 {options.nGenerate = 1;}
98
99 if (options.lengthSafety < 1e-15)
100 { // protect against poor lengthSafety choices that would cause potential overlaps
101 std::cerr << "Dangerously low \"lengthSafety\" value of: " << options.lengthSafety
102 << " m that will result in potential geometry overlaps!" << std::endl;
103 std::cerr << "This affects all geometry construction and should be carefully chosen!!!" << std::endl;
104 std::cerr << "The default value is 1 pm" << std::endl;
105 exit(1);
106 }
107
108 if (options.thinElementLength < 3*options.lengthSafety)
109 {throw BDSException(__METHOD_NAME__, "thinElementLength must be at least 3x lengthSafety");}
110
111 if (options.nturns < 1)
112 {options.nturns = 1;}
113
114 if (BDS::IsFinite(options.beamlineS) && beam.S0 == 0)
116}
117
119{
120 auto m = coolingchannel_list.getMap();
121 auto search = m.find(objectName);
122 if (search != m.end())
123 {return search->second;}
124 else
125 {throw BDSException(__METHOD_NAME__, "no such coolingDefinition \"" + objectName + "\"");}
126}
General exception with possible name of object and message.
Const entry to parser objects.
Definition BDSParser.hh:37
BDSParser()
Default constructor.
Definition BDSParser.cc:69
void AmalgamateBeam(const GMAD::Beam &beamIn, bool recreate)
Amalgamate the input beam definition with the ones stored in teh parser.
Definition BDSParser.cc:75
void CheckOptions()
Check options for consistency. This also checks the beam options.
Definition BDSParser.cc:94
static BDSParser * Instance()
Access method.
Definition BDSParser.cc:30
static BDSParser * instance
Instance.
Definition BDSParser.hh:128
GMAD::CoolingChannel GetCoolingChannel(const std::string &objectName)
Return a cooling channel object by name. Throws an exception if it doesn't exist.
Definition BDSParser.cc:118
static bool IsInitialised()
Returns if parser is initialised.
Definition BDSParser.cc:51
void AmalgamateOptions(const GMAD::Options &optionsIn)
Amalgamate the input options with the ones stored in the parser.
Definition BDSParser.cc:86
virtual ~BDSParser()
Destructor.
Definition BDSParser.cc:56
double S0
initial beam centroid
Definition beamBase.h:70
Beam class.
Definition beam.h:44
void Amalgamate(const Beam &optionsIn, bool override, int startFromEvent=0)
Definition beam.cc:97
Cooling channel parameters.
int nGenerate
The number of primary events to simulate.
Definition optionsBase.h:94
double beamlineS
Initial beam line transform w.r.t. the world coordinate frame.
bool recreate
Whether to recreate from a file or not.
Definition optionsBase.h:95
Options class.
Definition options.h:44
void Amalgamate(const Options &optionsIn, bool override)
Definition options.cc:98
Options options
General options.
Definition parser.h:235
FastList< CoolingChannel > coolingchannel_list
List of parser defined instances of that object.
Definition parser.h:242
Beam beam
Beam instance;.
Definition parser.h:233
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())
Parser namespace for GMAD language. Combination of Geant4 and MAD.