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