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