BDSIM
BDSIM is a Geant4 extension toolkit for simulation of particle transport in accelerator beamlines.
Loading...
Searching...
No Matches
BDSExecOptions.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 "BDSExecOptions.hh"
20
21#include <cstdlib>
22#include <getopt.h>
23#include <iomanip>
24#include <string>
25
26#include "globals.hh" // geant4 types / globals
27
28#include "BDSDebug.hh"
29#include "BDSColourFromMaterial.hh"
30#include "BDSColours.hh"
31#include "BDSMaterials.hh"
32#include "BDSOutputLoader.hh"
33#include "BDSUtilities.hh"
34
35#include "parser/beam.h"
36#include "parser/getEnv.h"
37#include "parser/options.h"
38
39BDSExecOptions::BDSExecOptions(int argc, char **argv):
40 options(GMAD::Options()),
41 beam(GMAD::Beam()),
42 ignoreSIGINT(false)
43{
44 if (argc == 1)
45 {// require at least 1 executable option (--file) - else print help message
46 Usage();
47 exit(0);
48 }
49 Parse(argc, argv);
50
52 std::string bp = GetPath(options.inputFileName);
53 options.set_value("bdsimPath", bp);
54#ifdef BDSDEBUG
55 G4cout << __METHOD_NAME__ << "BDSIMPATH set to: " << options.bdsimPath << G4endl;
56#endif
57
58 if (options.recreate)
59 {
60 G4cout << __METHOD_NAME__ << "Recreation mode. Loading options from recreate file:\n\""
61 << options.recreateFileName << "\"\n" << G4endl;
62 bool runBatch = options.batch;
64 GMAD::Options recreateOptions = loader.Options();
65 GMAD::Beam recreateBeam = loader.Beam();
66 // Give precedence to exec options - only ones that have been set.
67 recreateOptions.Amalgamate(options, true);
68 recreateBeam.Amalgamate(beam, true, options.startFromEvent);
69 options = recreateOptions; // Now replace member.
70 options.batch = runBatch; // override batch flag to allow control
71 beam = recreateBeam;
72 }
73}
74
75void BDSExecOptions::Parse(int argc, char **argv)
76{
77 static struct option LongOptions[] = {{ "help" , 0, 0, 0 },
78 { "reference", 0, 0, 0},
79 { "citation", 0, 0, 0},
80 { "version", 0, 0, 0 },
81 { "versionGit", 0, 0, 0 },
82 { "verbose", 0, 0, 0 },
83 { "verbose_step", 0, 0, 0 }, // old
84 { "verboseSteppingBDSIM", 0, 0, 0 }, // new
85 { "verbose_event", 0, 0, 0 }, // old
86 { "verboseEventBDSIM", 0, 0, 0 }, // new
87 { "verbose_event_num", 1, 0, 0 }, // old
88 { "verboseEventNumber", 1, 0, 0 }, // new
89 { "verboseEventStart", 1, 0, 0 },
90 { "verboseEventContinueFor", 1, 0, 0 },
91 { "verbose_G4run", 1, 0, 0 }, // old
92 { "verboseRunLevel", 1, 0, 0}, // new
93 { "verbose_G4event", 1, 0, 0 }, // old
94 { "verboseEventLevel", 1, 0, 0}, // new
95 { "verbose_G4tracking", 1, 0, 0 }, // old
96 { "verboseTrackingLevel", 1, 0, 0 }, // new
97 { "verbose_G4stepping", 1, 0, 0 },
98 { "verboseSteppingLevel", 1, 0, 0 },
99 { "verboseSteppingEventStart", 1, 0, 0 },
100 { "verboseSteppingEventContinueFor", 1, 0, 0 },
101 { "verboseSteppingPrimaryOnly", 0, 0, 0 },
102 { "file", 1, 0, 0 },
103 { "distrFile", 1, 0, 0 },
104 { "distrFileNLinesSkip", 1, 0, 0 },
105 { "distrFileLoopNTimes", 1, 0, 0 },
106 { "E0", 1, 0, 0},
107 { "P0", 1, 0, 0},
108 { "Ek0", 1, 0, 0},
109 { "vis_debug", 0, 0, 0 },
110 { "vis_mac", 1, 0, 0 },
111 { "geant4Macro", 1, 0, 0 }, // old
112 { "geant4MacroFileName", 1, 0, 0 },
113 { "geant4PhysicsMacroFileName", 1, 0, 0 },
114 { "output", 1, 0, 0 },
115 { "outfile", 1, 0, 0 },
116 { "batch", 0, 0, 0 },
117 { "colours", 0, 0, 0 },
118 { "materials", 0, 0, 0 },
119 { "circular", 0, 0, 0 },
120 { "seed", 1, 0, 0},
121 { "recreate", 1, 0, 0},
122 { "startFromEvent", 1, 0, 0},
123 { "writeSeedState", 0, 0, 0},
124 { "seedState", 1, 0, 0},
125 { "seedStateFileName", 1, 0, 0},
126 { "survey", 1, 0, 0 },
127 { "ngenerate", 1, 0, 0 },
128 { "nGenerate", 1, 0, 0 },
129 { "nturns", 1, 0, 0 },
130 { "nTurns", 1, 0, 0 },
131 { "printFractionEvents", 1, 0, 0},
132 { "printFractionTurns", 1, 0, 0},
133 { "printPhysicsProcesses", 0, 0, 0},
134 { "exportGeometryTo", 1, 0, 0 },
135 { "generatePrimariesOnly", 0, 0, 0 },
136 { "ignoresigint", 0, 0, 0},
137 { 0, 0, 0, 0 }};
138
139 int OptionIndex = 0;
140 int OptionNumber = 0;
141 const char* optionName;
142 // number conversion check
143 bool conversion = true;
144 for (;;)
145 {
146 OptionIndex = 0;
147
148 // see e.g. http://linux.die.net/man/3/getopt
149 int c = getopt_long(argc, argv, "Vv",
150 LongOptions, &OptionIndex );
151
152 if (c == -1) // end of options list
153 {break;}
154
155 switch (c)
156 {
157 case '?': // unrecognised option
158 {
159 G4cout << "invalid option for command " << argv[0] << G4endl << G4endl << G4endl;
160 Usage();
161 exit(1);
162 break;
163 }
164 case 0:
165 {
166 OptionNumber++;
167 optionName = LongOptions[OptionIndex].name;
168 if ( !strcmp(optionName , "help") )
169 {
170 Usage();
171 exit(0);
172 }
173 else if ( !strcmp(optionName, "reference") || !strcmp(optionName, "citation") )
174 {
176 exit(0);
177 }
178 else if ( !strcmp(optionName, "version") )
179 {
180 G4cout << "@BDSIM_VERSION@" << G4endl;
181 exit(0);
182 }
183 else if ( !strcmp(optionName, "versionGit") )
184 {
185 G4cout << "@BDSIM_VERSION@ based on git commit SHA1: @VERSION_SHA1@" << G4endl;
186 exit(0);
187 }
188 else if ( !strcmp(optionName , "batch") )
189 {options.set_value("batch",true);}
190 else if ( !strcmp(optionName , "verbose") )
191 {options.set_value("verbose", true);}
192 else if ( !strcmp(optionName , "verbose_step") || !strcmp(optionName , "verboseSteppingBDSIM"))
193 {// we shouldn't have verbose steps without (minimally) verbose events
194 options.set_value("verboseSteppingBDSIM", true);
195 options.set_value("verboseEventBDSIM", true);
196 }
197 else if ( !strcmp(optionName , "verbose_event") || !strcmp(optionName, "verboseEventBDSIM") )
198 {options.set_value("verboseEventBDSIM", true);}
199 else if ( !strcmp(optionName , "verbose_event_num") || !strcmp(optionName , "verboseEventNumber"))
200 {
201 int result = -1;
202 conversion = BDS::IsInteger(optarg, result);
203 options.set_value("verboseEventStart", result);
204 options.set_value("verboseEventContinueFor", 1);
205 }
206 else if ( !strcmp(optionName , "verboseEventStart") )
207 {
208 int result = 0;
209 conversion = BDS::IsInteger(optarg, result);
210 options.set_value("verboseEventStart", result);
211 }
212 else if ( !strcmp(optionName , "verboseEventContinueFor") )
213 {
214 int result = 0;
215 conversion = BDS::IsInteger(optarg, result);
216 options.set_value("verboseEventContinueFor", result);
217 }
218 else if ( !strcmp(optionName , "verbose_G4run") || !strcmp(optionName , "verboseRunLevel") )
219 {
220 int result = 0;
221 conversion = BDS::IsInteger(optarg, result);
222 options.set_value("verboseRunLevel", result);
223 }
224 else if ( !strcmp(optionName , "verbose_G4event") || !strcmp(optionName , "verboseEventLevel") )
225 {
226 int result = 0;
227 conversion = BDS::IsInteger(optarg, result);
228 options.set_value("verboseEventLevel", result);
229 }
230 else if ( !strcmp(optionName , "verbose_G4tracking") || !strcmp(optionName , "verboseTrackingLevel") )
231 {
232 int result = 0;
233 conversion = BDS::IsInteger(optarg, result);
234 options.set_value("verboseTrackingLevel", result);
235 }
236 else if ( !strcmp(optionName , "verbose_G4stepping") || !strcmp(optionName , "verboseSteppingLevel"))
237 {
238 int result = 0;
239 conversion = BDS::IsInteger(optarg, result);
240 options.set_value("verboseSteppingLevel", result);
241 }
242 else if ( !strcmp(optionName , "verboseSteppingEventStart") )
243 {
244 int result = 0;
245 conversion = BDS::IsInteger(optarg, result);
246 options.set_value("verboseSteppingEventStart", result);
247 }
248 else if ( !strcmp(optionName , "verboseSteppingEventContinueFor") )
249 {
250 int result = 0;
251 conversion = BDS::IsInteger(optarg, result);
252 options.set_value("verboseSteppingEventContinueFor", result);
253 }
254 else if ( !strcmp(optionName , "verboseSteppingPrimaryOnly") )
255 {options.set_value("verboseSteppingPrimaryOnly", true);}
256 else if ( !strcmp(optionName , "output") )
257 {options.set_value("outputFormat", std::string(optarg));}
258 else if ( !strcmp(optionName , "outfile") )
259 {options.set_value("outputFileName", std::string(optarg));}
260 else if ( !strcmp(optionName , "survey") )
261 {
262 options.set_value("surveyFileName", std::string(optarg));
263 options.set_value("survey", true);
264 }
265 else if ( !strcmp(optionName , "file") )
266 {options.set_value("inputFileName", std::string(optarg));}
267 else if ( !strcmp(optionName, "distrFile") )
268 {// build absolute path
269 beam.set_value("distrFile", std::string(optarg));
270 beam.set_value("distrFileFromExecOptions", true);
271 }
272 else if ( !strcmp(optionName, "distrFileNLinesSkip") )
273 {
274 int result = 0;
275 conversion = BDS::IsInteger(optarg, result);
276 beam.set_value("nlinesSkip", result);
277 }
278 else if ( !strcmp(optionName, "distrFileLoopNTimes") )
279 {
280 int result = 0;
281 conversion = BDS::IsInteger(optarg, result);
282 beam.set_value("distrFileLoopNTimes", result);
283 beam.set_value("distrFileLoop", true);
284 }
285 else if (!strcmp(optionName, "E0") )
286 {
287 double result = 1;
288 conversion = BDS::IsNumber(optarg, result);
289 beam.set_value("E0", result);
290 }
291 else if (!strcmp(optionName, "P0") )
292 {
293 double result = 1;
294 conversion = BDS::IsNumber(optarg, result);
295 beam.set_value("P0", result);
296 }
297 else if (!strcmp(optionName, "Ek0") )
298 {
299 double result = 1;
300 conversion = BDS::IsNumber(optarg, result);
301 beam.set_value("Ek0", result);
302 }
303 else if ( !strcmp(optionName, "vis_debug") )
304 {options.set_value("visDebug", true);}
305 else if ( !strcmp(optionName, "vis_mac") )
306 {options.set_value("visMacroFileName", std::string(optarg));}
307 else if ( !strcmp(optionName, "geant4Macro") || !strcmp(optionName, "genat4MacroFileName") )
308 {options.set_value("geant4MacroFileName", std::string(optarg));}
309 else if ( !strcmp(optionName, "geant4PhysicsMacroFileName") )
310 {
311 options.set_value("geant4PhysicsMacroFileName", std::string(optarg));
312 options.set_value("geant4PhysicsMacroFileNameFromExecOptions", true);
313 }
314 else if ( !strcmp(optionName, "colours") )
315 {
316 BDSColourFromMaterial::Instance(); // force construction of extra colours
318 exit(0);// return after printing colour list
319 }
320 else if ( !strcmp(optionName, "materials") )
321 {
323 exit(0);// return after printing material list
324 }
325 else if ( !strcmp(optionName, "circular") )
326 {options.set_value("circular", true);}
327 else if ( !strcmp(optionName, "seed") )
328 {
329 int result = -1;
330 conversion = BDS::IsInteger(optarg, result);
331 options.set_value("seed", result);
332 }
333 else if ( !strcmp(optionName, "recreate") )
334 {
335 options.set_value("recreate", true);
336 options.set_value("recreateFileName", std::string(optarg));
337 }
338 else if ( !strcmp(optionName, "startFromEvent") )
339 {
340 int result = 0;
341 conversion = BDS::IsInteger(optarg, result);
342 options.set_value("startFromEvent", result);
343 }
344 else if ( !strcmp(optionName, "writeSeedState") )
345 {options.set_value("writeSeedState", true);}
346 else if ( !strcmp(optionName, "seedState") || !strcmp(optionName, "seedStateFileName"))
347 {
348 options.set_value("useASCIISeedState", true);
349 options.set_value("seedStateFileName", std::string(optarg));
350 }
351 else if ( !strcmp(optionName, "ngenerate") || !strcmp(optionName, "nGenerate"))
352 {
353 int result = 1;
354 conversion = BDS::IsInteger(optarg, result);
355 options.set_value("ngenerate", result);
356 beam.set_value("distrFileMatchLength", false); // ngenerate overrides.
357 }
358 else if ( !strcmp(optionName, "nturns") || !strcmp(optionName, "nTurns"))
359 {
360 int result = 1;
361 conversion = BDS::IsInteger(optarg, result);
362 options.set_value("nturns", result);
363 }
364 else if ( !strcmp(optionName, "printFractionEvents") )
365 {
366 double result = 1;
367 conversion = BDS::IsNumber(optarg, result);
368 options.set_value("printFractionEvents", result);
369 }
370 else if ( !strcmp(optionName, "printFractionTurns") )
371 {
372 double result = 1;
373 conversion = BDS::IsNumber(optarg, result);
374 options.set_value("printFractionTurns", result);
375 }
376 else if ( !strcmp(optionName, "printPhysicsProcesses") )
377 {options.set_value("printPhysicsProcesses", true);}
378 else if ( !strcmp(optionName, "generatePrimariesOnly") )
379 {options.set_value("generatePrimariesOnly", true);}
380 else if ( !strcmp(optionName, "ignoresigint") )
381 {ignoreSIGINT = true;}
382 else if ( !strcmp(optionName, "exportGeometryTo") )
383 {// TODO - this should be put into geometry classes
384 std::string fn = optarg;
385 if (fn.substr(fn.find_last_of(".") + 1) == "gdml")
386 {
387 options.set_value("exportType", std::string("gdml"));
388 options.set_value("exportFileName", fn);
389 }
390 else
391 {
392 G4cerr << __METHOD_NAME__ << "Unknown geometry format \""
393 << fn.substr(fn.find_last_of(".") + 1) << "\"\n"
394 << "Please specify a valid filename extension - options are: \"gdml\"" << G4endl;
395 exit(1);
396 }
397 options.set_value("exportGeometry", true);
398 }
399 // remember if you extend this to do it also in the usage print out
400
401 if (conversion == false)
402 {
403 // conversion from character string to number went wrong, exit
404 G4cerr << __METHOD_NAME__ << "Conversion to number (or integer) went wrong for \""
405 << optionName << "\" with value: \"" << optarg << "\"" << G4endl;
406 exit(1);
407 }
408
409 break;
410 }
411 default:
412 {
413 G4cout << "WARNING unknown returned character code " << c << G4endl;
414 break;
415 }
416 }
417 }
418 // there should be no remaining options
419 if (OptionNumber < argc - 1)
420 {
421 G4cout << __METHOD_NAME__ << "there are remaining unknown options: " << G4endl;
422 for (int i=1; i<argc; i++)
423 {
424 // options with '-' are ignored by getopt_long, other unknown options are covered
425 if (strncmp(argv[i], "-", 1))
426 {G4cout << "\"" << argv[i] << "\"" << G4endl;}
427 }
428
429 G4cout << "Please check your command line arguments" << G4endl;
430 exit(1);
431 }
432 }
433
435{
436 G4cout<<"Usage: bdsim [options]" << G4endl;
437 G4cout<<"Note options are case sensitive." << G4endl;
438 G4cout<<"bdsim --help : display this message" << G4endl;
439 G4cout<<"Options (alphabetically):" << G4endl;
440 G4cout<<"--file=<filename> : specify the input file " << G4endl
441 <<"--batch : batch mode - no graphics" << G4endl
442 <<"--reference or --citation : print the citation information then quit" << G4endl
443 <<"--circular : assume circular machine - turn control" << G4endl
444 <<"--colours : list available colours included in bdsim" << G4endl
445 <<" by default" << G4endl
446 <<"--distrFile=<filename> : file to use for bunch distribution" << G4endl
447 <<"--distrFileNLinesSkip=N : skip N lines in the file (userfile)" << G4endl
448 <<"--distrFileLoopNTimes=N : repeat the distribution file N times" << G4endl
449 <<"--exportGeometryTo=<filename.extension> : export the fully constructed geometry" << G4endl
450 <<" to a file. Only gdml extension supported." << G4endl
451 <<"--E0=N : set E0 for the bunch for this run (GeV only)" << G4endl
452 <<"--Ek0=N : set Ek0 for the bunch for this run (GeV only)" << G4endl
453 <<"--geant4MacroFileName=<filename> : macro run after visualisation" << G4endl
454 <<"--geant4PhysicsMacroFileName=<filename> : physics macro file name" << G4endl
455 <<"--generatePrimariesOnly : generate N primary particle coordinates" << G4endl
456 <<" without simulation then quit" << G4endl
457 <<"--materials : list materials included in bdsim by default" << G4endl
458 <<"--ngenerate=N : the number of primary events to simulate:" << G4endl
459 <<" overrides ngenerate option in the input gmad file" << G4endl
460 <<"--nturns=N : the number of turns to simulate:" << G4endl
461 <<" overrides nturns option in the input gmad file" << G4endl
462 <<"--output=<fmt> : output format (rootevent|none), default rootevent" << G4endl
463 <<"--outfile=<file> : output file name. Will be appended with _N" << G4endl
464 <<" where N = 0, 1, 2, 3... etc." << G4endl
465 <<"--printFractionEvents=N : fraction of events to print out (default 0.1)" << G4endl
466 <<" -1 is all, range [0-1]" << G4endl
467 <<"--printFractionTurns=N : fraction of turns to print out (default 0.2)" << G4endl
468 <<" -1 is all, range [0-1]" << G4endl
469 <<"--printPhysicsProcesses : print out every particle registered and all " << G4endl
470 <<" their processes - depends on physics list in input"<< G4endl
471 <<"--P0=N : set P0 for the bunch for this run (GeV only)" << G4endl
472 <<"--recreate=<file> : the rootevent file to recreate events from" << G4endl
473 <<"--seed=N : the seed to use for the random number generator" << G4endl
474 <<"--seedStateFileName=<file> : use this ASCII file seed state to run an event" << G4endl
475 <<"--startFromEvent=N : event offset to start from when recreating events" << G4endl
476 <<"--survey=<file> : print survey info to <file>" << G4endl
477 <<"--verbose : display general parameters before run" << G4endl
478 <<"--verboseRunLevel=N : set Geant4 verbosity at run level [0:5]" << G4endl
479 <<"--verboseEventLevel=N : set Geant4 event manager verbosity level" << G4endl
480 <<"--verboseEventStart=N : display tracking information from event number N" << G4endl
481 <<"--verboseEventContinueFor=N : number of events to continue verbose event info for" << G4endl
482 <<"--verboseTrackingLevel=N : set Geant4 verbosity about new tracks." << G4endl
483 <<"--verboseSteppingLevel=N : set Geant4 Stepping manager verbosity level [0:5]" << G4endl
484 <<"--verboseSteppingEventStart=N : event to start verbose stepping." << G4endl
485 <<"--verboseSteppingEventContinueFor=N : number of events to continue verbose stepping" << G4endl
486 <<" information for" << G4endl
487 <<"--verboseSteppingPrimaryOnly : only print out verbose stepping for primary particle" << G4endl
488 <<"--verboseEventBDSIM : display BDSIM information for every event " << G4endl
489 <<"--verboseSteppingBDSIM : display BDSIM tracking information after each step"<< G4endl
490 <<"--version : display version number" << G4endl
491 <<"--versionGit : display version number including git commit SHA1" << G4endl
492 <<"--vis_debug : display all volumes in visualiser" << G4endl
493 <<"--vis_mac=<file> : file with the visualisation macro script, default" << G4endl
494 <<" provided by BDSIM openGL (OGLSQt))" << G4endl
495 <<"--writeSeedState : write an ASCII file seed state for each event" << G4endl;
496}
497
499{
500 // Print header & program information
501 G4cout<<"BDSIM : version @BDSIM_VERSION@"<<G4endl;
502 G4cout<<" (C) 2001-@CURRENT_YEAR@ Royal Holloway University London - GPLv3" << G4endl;
503 G4cout<<G4endl;
504 G4cout<<" Reference: Computer Physics Communications, 107200 (2020)" << G4endl;
505 G4cout<<" https://doi.org/10.1016/j.cpc.2020.107200" << G4endl;
506 G4cout<<" https://arxiv.org/abs/1808.10745" << G4endl;
507 G4cout<<" Website: http://www.pp.rhul.ac.uk/bdsim"<<G4endl;
508 G4cout<<G4endl;
509}
510
512{
513 G4cout << "BDSIM: An accelerator tracking code with particle-matter interactions." << G4endl;
514 G4cout << "L.J. Nevay et al., Computer Physics Communications, 1070200 (2020)" << G4endl;
515 G4cout << "https://doi.org/10.1016/j.cpc.2020.107200" << G4endl << G4endl;
516 G4cout << R"(@article{NEVAY2020107200,)" << G4endl;
517 G4cout << R"(title = {BDSIM: An accelerator tracking code with particle–matter interactions},)" << G4endl;
518 G4cout << R"(journal = {Comput. Phys. Commun.},)" << G4endl;
519 G4cout << R"(volume = {252},)" << G4endl;
520 G4cout << R"(pages = {107200},)" << G4endl;
521 G4cout << R"(year = {2020},)" << G4endl;
522 G4cout << R"(issn = {0010-4655},)" << G4endl;
523 G4cout << R"(doi = {https://doi.org/10.1016/j.cpc.2020.107200},)" << G4endl;
524 G4cout << R"(url = {https://www.sciencedirect.com/science/article/pii/S0010465520300400},)" << G4endl;
525 G4cout << R"(author = {L.J. Nevay and S.T. Boogert and J. Snuverink and A. Abramov and L.C. Deacon and H. Garcia-Morales and H. Lefebvre and S.M. Gibson and R. Kwee-Hinzmann and W. Shields and S.D. Walker},)" << G4endl;
526 G4cout << R"(})" << G4endl;
527}
528
530{
531 for (const auto& key : options.KeysOfSetValues())
532 {G4cout << "Executable option> " << std::setw(27) << std::left << key << ": " << std::setw(15) << std::left << options.get_value_string(key) << G4endl;}
533 for (const auto& key : beam.KeysOfSetValues())
534 {G4cout << "Executable option> " << std::setw(27) << std::left << key << ": " << std::setw(15) << std::left << beam.get_value_string(key) << G4endl;}
535}
536
537G4String BDSExecOptions::GetPath(G4String fileName)
538{
539 // Set fullPath to mirror what is done in parser.l (i.e. if no environment
540 // variable set, assume base filename path is that of the gmad file).
541 G4String fullPath = getEnv("BDSIMPATH");
542#ifdef BDSDEBUG
543 G4cout << __METHOD_NAME__ << "filename = " << fileName << G4endl;
544#endif
545 if (fullPath.empty())
546 {
547 G4String inputFilepath = "";
548 // get the path part of the supplied path to the main input file
549 G4String::size_type found = fileName.rfind("/"); // find the last '/'
550 if (found != G4String::npos)
551 {inputFilepath = fileName.substr(0,found);} // the path is the bit before that
552 // else remains empty string
553 // need to know whether it's an absolute or relative path
554 if ((fileName.substr(0,1)) == "/")
555 {// the main file has an absolute path
556 fullPath = inputFilepath;
557 }
558 else
559 {
560 G4String curDir = BDS::GetCurrentDir();
561 fullPath = curDir + "/" + inputFilepath;
562 }
563 }
564
565 if (fullPath.back() != '/') // ensure ends in '/'
566 {fullPath += "/";} // only add if needed
567#ifdef BDSDEBUG
568 G4cout << __METHOD_NAME__ << "fullpath = " << fullPath << G4endl;
569#endif
570 return fullPath;
571}
static BDSColourFromMaterial * Instance()
Singleton pattern.
static BDSColours * Instance()
singleton pattern
Definition: BDSColours.cc:33
void Print()
Definition: BDSColours.cc:181
GMAD::Options options
The options instance that is populated by parsing the command line options.
GMAD::Beam beam
The beam instance that is populated by parsing some command line options.
void Print() const
Print out the commands and their set values.
void PrintCitation() const
Print academic citation information.
G4bool ignoreSIGINT
Whether to ignore Ctrl-C or not - used for ctest.
void Usage() const
Print out the available executable commands (no exit).
void PrintCopyright() const
Print out the copyright information (no exit).
void Parse(int argc, char **argv)
G4String GetPath(G4String filename)
Helper method to set the BDSIMPath correctly.
BDSExecOptions()
Private default constructor to force use of provided one.
static BDSMaterials * Instance()
Singleton pattern access.
Definition: BDSMaterials.cc:39
void ListMaterials() const
output available materials
Loader of ROOT Event output for recreating events.
Beam loader.
Definition: Beam.hh:37
Beam class.
Definition: beam.h:44
void Amalgamate(const Beam &optionsIn, bool override, int startFromEvent=0)
Definition: beam.cc:97
void set_value(std::string name, T value)
set methods by property name
Definition: beam.h:76
std::string bdsimPath
Definition: optionsBase.h:112
bool batch
Flag for batch / interactive mode.
Definition: optionsBase.h:59
std::string inputFileName
Input filename.
Definition: optionsBase.h:40
std::string recreateFileName
The file path to recreate a run from.
Definition: optionsBase.h:95
int startFromEvent
Event to start from when recreating.
Definition: optionsBase.h:96
bool recreate
Whether to recreate from a file or not.
Definition: optionsBase.h:94
Options class.
Definition: options.h:44
void Amalgamate(const Options &optionsIn, bool override)
Definition: options.cc:98
void set_value(std::string name, T value)
set methods by property name
Definition: options.h:76
Options loader.
Definition: Options.hh:36
std::string GetCurrentDir()
Get the current dir the program was executed from.
G4bool IsNumber(const char *s, double &convertedNumber)
Check if character array is an integer, and returns the double by reference.
G4bool IsInteger(const char *s, int &convertedInteger)
Check if character array is an integer, and returns the integer by reference.
Parser namespace for GMAD language. Combination of Geant4 and MAD.