BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
BDSParser.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 "BDSParser.hh"
22#include "BDSUtilities.hh"
23
24#include <string>
25
27
29{
30 if (!instance)
31 {
32 std::cerr << "BDSParser has not been initialised!" << std::endl;
33 exit(1);
34 }
35 return instance;
36}
37
38BDSParser* BDSParser::Instance(const std::string& name)
39{
40 if (instance)
41 {
42 std::cerr << "WARNING BDSParser was already initialised!" << std::endl;
43 delete instance;
44 }
45 instance = new BDSParser(name);
46 return instance;
47}
48
50{
51 return instance ? true : false;
52}
53
55{
56 instance = nullptr;
57}
58
59BDSParser::BDSParser(const std::string& name):
60 GMAD::Parser(name)
61{
62 std::cout << __METHOD_NAME__ << "Using input file: "<< name << std::endl;
63}
64
66 G4bool recreate)
67{
68 // We only amalgamate when we're running normally. If we're recreating
69 // all beam parameters will be in the output file.
70 if (recreate)
71 {beam = execBeamIn;} // execBeamIn already has loaded recreation beam parameters
72 else
73 {beam.Amalgamate(execBeamIn, true);}
74}
75
77{
78 if (optionsIn.recreate)
79 {options = optionsIn;} // totally overwrite options
80 else
81 {options.Amalgamate(optionsIn, true);}
82}
83
85{
86 if (options.nGenerate <= 0) // run at least 1 event!
87 {options.nGenerate = 1;}
88
89 if (options.lengthSafety < 1e-15)
90 { // protect against poor lengthSafety choices that would cause potential overlaps
91 std::cerr << "Dangerously low \"lengthSafety\" value of: " << options.lengthSafety
92 << " m that will result in potential geometry overlaps!" << std::endl;
93 std::cerr << "This affects all geometry construction and should be carefully chosen!!!" << std::endl;
94 std::cerr << "The default value is 1 pm" << std::endl;
95 exit(1);
96 }
97
98 if (options.thinElementLength < 3*options.lengthSafety)
99 {throw BDSException(__METHOD_NAME__, "thinElementLength must be at least 3x lengthSafety");}
100
101 if (options.nturns < 1)
102 {options.nturns = 1;}
103
104 if (BDS::IsFinite(options.beamlineS) && beam.S0 == 0)
106}
General exception with possible name of object and message.
Definition: BDSException.hh:35
Const entry to parser objects.
Definition: BDSParser.hh:36
void AmalgamateBeam(const GMAD::Beam &beamIn, bool recreate)
Amalgamate the input beam definition with the ones stored in teh parser.
Definition: BDSParser.cc:65
void CheckOptions()
Check options for consistency. This also checks the beam options.
Definition: BDSParser.cc:84
static BDSParser * Instance()
Access method.
Definition: BDSParser.cc:28
static BDSParser * instance
Instance.
Definition: BDSParser.hh:143
static bool IsInitialised()
Returns if parser is initialised.
Definition: BDSParser.cc:49
BDSParser()=delete
No default constructor.
void AmalgamateOptions(const GMAD::Options &optionsIn)
Amalgamate the input options with the ones stored in the parser.
Definition: BDSParser.cc:76
virtual ~BDSParser()
Destructor.
Definition: BDSParser.cc:54
double S0
initial beam centroid
Definition: beamBase.h:62
Beam class.
Definition: beam.h:44
void Amalgamate(const Beam &optionsIn, bool override, int startFromEvent=0)
Definition: beam.cc:97
int nGenerate
The number of primary events to simulate.
Definition: optionsBase.h:91
double beamlineS
Initial beam line transform w.r.t. the world coordinate frame.
Definition: optionsBase.h:141
bool recreate
Whether to recreate from a file or not.
Definition: optionsBase.h:92
Options class.
Definition: options.h:44
void Amalgamate(const Options &optionsIn, bool override)
Definition: options.cc:98
Options options
General options.
Definition: parser.h:225
Beam beam
Beam instance;.
Definition: parser.h:223
G4bool IsFinite(G4double value, G4double tolerance=std::numeric_limits< double >::epsilon())
Parser namespace for GMAD language. Combination of Geant4 and MAD.