19#include "BDSExecOptions.hh"
29#include "BDSColourFromMaterial.hh"
30#include "BDSColours.hh"
31#include "BDSMaterials.hh"
32#include "BDSOutputLoader.hh"
33#include "BDSUtilities.hh"
35#include "parser/beam.h"
36#include "parser/getEnv.h"
37#include "parser/options.h"
55 G4cout << __METHOD_NAME__ <<
"BDSIMPATH set to: " <<
options.
bdsimPath << G4endl;
60 G4cout << __METHOD_NAME__ <<
"Recreation mode. Loading options from recreate file:\n\""
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 },
84 {
"verboseSteppingBDSIM", 0, 0, 0 },
85 {
"verbose_event", 0, 0, 0 },
86 {
"verboseEventBDSIM", 0, 0, 0 },
87 {
"verbose_event_num", 1, 0, 0 },
88 {
"verboseEventNumber", 1, 0, 0 },
89 {
"verboseEventStart", 1, 0, 0 },
90 {
"verboseEventContinueFor", 1, 0, 0 },
91 {
"verbose_G4run", 1, 0, 0 },
92 {
"verboseRunLevel", 1, 0, 0},
93 {
"verbose_G4event", 1, 0, 0 },
94 {
"verboseEventLevel", 1, 0, 0},
95 {
"verbose_G4tracking", 1, 0, 0 },
96 {
"verboseTrackingLevel", 1, 0, 0 },
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 },
103 {
"distrFile", 1, 0, 0 },
104 {
"distrFileNLinesSkip", 1, 0, 0 },
108 {
"vis_debug", 0, 0, 0 },
109 {
"vis_mac", 1, 0, 0 },
110 {
"geant4Macro", 1, 0, 0 },
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 },
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},
139 int OptionNumber = 0;
140 const char* optionName;
142 bool conversion =
true;
148 int c = getopt_long(argc, argv,
"Vv",
149 LongOptions, &OptionIndex );
158 G4cout <<
"invalid option for command " << argv[0] << G4endl << G4endl << G4endl;
166 optionName = LongOptions[OptionIndex].name;
167 if ( !strcmp(optionName ,
"help") )
172 else if ( !strcmp(optionName,
"reference") || !strcmp(optionName,
"citation") )
177 else if ( !strcmp(optionName,
"version") )
179 G4cout <<
"@BDSIM_VERSION@" << G4endl;
182 else if ( !strcmp(optionName,
"versionGit") )
184 G4cout <<
"@BDSIM_VERSION@ based on git commit SHA1: @VERSION_SHA1@" << G4endl;
187 else if ( !strcmp(optionName ,
"batch") )
189 else if ( !strcmp(optionName ,
"verbose") )
191 else if ( !strcmp(optionName ,
"verbose_step") || !strcmp(optionName ,
"verboseSteppingBDSIM"))
196 else if ( !strcmp(optionName ,
"verbose_event") || !strcmp(optionName,
"verboseEventBDSIM") )
198 else if ( !strcmp(optionName ,
"verbose_event_num") || !strcmp(optionName ,
"verboseEventNumber"))
205 else if ( !strcmp(optionName ,
"verboseEventStart") )
211 else if ( !strcmp(optionName ,
"verboseEventContinueFor") )
217 else if ( !strcmp(optionName ,
"verbose_G4run") || !strcmp(optionName ,
"verboseRunLevel") )
223 else if ( !strcmp(optionName ,
"verbose_G4event") || !strcmp(optionName ,
"verboseEventLevel") )
229 else if ( !strcmp(optionName ,
"verbose_G4tracking") || !strcmp(optionName ,
"verboseTrackingLevel") )
235 else if ( !strcmp(optionName ,
"verbose_G4stepping") || !strcmp(optionName ,
"verboseSteppingLevel"))
241 else if ( !strcmp(optionName ,
"verboseSteppingEventStart") )
247 else if ( !strcmp(optionName ,
"verboseSteppingEventContinueFor") )
253 else if ( !strcmp(optionName ,
"verboseSteppingPrimaryOnly") )
255 else if ( !strcmp(optionName ,
"output") )
257 else if ( !strcmp(optionName ,
"outfile") )
259 else if ( !strcmp(optionName ,
"survey") )
264 else if ( !strcmp(optionName ,
"file") )
266 else if ( !strcmp(optionName,
"distrFile") )
271 else if ( !strcmp(optionName,
"distrFileNLinesSkip") )
277 else if (!strcmp(optionName,
"E0") )
283 else if (!strcmp(optionName,
"P0") )
289 else if (!strcmp(optionName,
"Ek0") )
295 else if ( !strcmp(optionName,
"vis_debug") )
297 else if ( !strcmp(optionName,
"vis_mac") )
299 else if ( !strcmp(optionName,
"geant4Macro") || !strcmp(optionName,
"genat4MacroFileName") )
301 else if ( !strcmp(optionName,
"geant4PhysicsMacroFileName") )
306 else if ( !strcmp(optionName,
"colours") )
312 else if ( !strcmp(optionName,
"materials") )
317 else if ( !strcmp(optionName,
"circular") )
319 else if ( !strcmp(optionName,
"seed") )
325 else if ( !strcmp(optionName,
"recreate") )
330 else if ( !strcmp(optionName,
"startFromEvent") )
336 else if ( !strcmp(optionName,
"writeSeedState") )
338 else if ( !strcmp(optionName,
"seedState") || !strcmp(optionName,
"seedStateFileName"))
343 else if ( !strcmp(optionName,
"ngenerate") || !strcmp(optionName,
"nGenerate"))
350 else if ( !strcmp(optionName,
"nturns") || !strcmp(optionName,
"nTurns"))
356 else if ( !strcmp(optionName,
"printFractionEvents") )
362 else if ( !strcmp(optionName,
"printFractionTurns") )
368 else if ( !strcmp(optionName,
"printPhysicsProcesses") )
370 else if ( !strcmp(optionName,
"generatePrimariesOnly") )
372 else if ( !strcmp(optionName,
"ignoresigint") )
374 else if ( !strcmp(optionName,
"exportGeometryTo") )
376 std::string fn = optarg;
377 if (fn.substr(fn.find_last_of(
".") + 1) ==
"gdml")
384 G4cerr << __METHOD_NAME__ <<
"Unknown geometry format \""
385 << fn.substr(fn.find_last_of(
".") + 1) <<
"\"\n"
386 <<
"Please specify a valid filename extension - options are: \"gdml\"" << G4endl;
393 if (conversion ==
false)
396 G4cerr << __METHOD_NAME__ <<
"Conversion to number (or integer) went wrong for \""
397 << optionName <<
"\" with value: \"" << optarg <<
"\"" << G4endl;
405 G4cout <<
"WARNING unknown returned character code " << c << G4endl;
411 if (OptionNumber < argc - 1)
413 G4cout << __METHOD_NAME__ <<
"there are remaining unknown options: " << G4endl;
414 for (
int i=1; i<argc; i++)
417 if (strncmp(argv[i],
"-", 1))
418 {G4cout <<
"\"" << argv[i] <<
"\"" << G4endl;}
421 G4cout <<
"Please check your command line arguments" << G4endl;
428 G4cout<<
"Usage: bdsim [options]" << G4endl;
429 G4cout<<
"Note options are case sensitive." << G4endl;
430 G4cout<<
"bdsim --help : display this message" << G4endl;
431 G4cout<<
"Options (alphabetically):" << G4endl;
432 G4cout<<
"--file=<filename> : specify the input file " << G4endl
433 <<
"--batch : batch mode - no graphics" << G4endl
434 <<
"--reference or --citation : print the citation information then quit" << G4endl
435 <<
"--circular : assume circular machine - turn control" << G4endl
436 <<
"--colours : list available colours included in bdsim" << G4endl
437 <<
" by default" << G4endl
438 <<
"--exportGeometryTo=<filename.extension> : export the fully constructed geometry" << G4endl
439 <<
" to a file. Only gdml extension supported." << G4endl
440 <<
"--E0=N : set E0 for the bunch for this run (GeV only)" << G4endl
441 <<
"--Ek0=N : set Ek0 for the bunch for this run (GeV only)" << G4endl
442 <<
"--geant4MacroFileName=<filename> : macro run after visualisation" << G4endl
443 <<
"--geant4PhysicsMacroFileName=<filename> : physics macro file name" << G4endl
444 <<
"--generatePrimariesOnly : generate N primary particle coordinates" << G4endl
445 <<
" without simulation then quit" << G4endl
446 <<
"--materials : list materials included in bdsim by default" << G4endl
447 <<
"--ngenerate=N : the number of primary events to simulate:" << G4endl
448 <<
" overrides ngenerate option in the input gmad file" << G4endl
449 <<
"--nturns=N : the number of turns to simulate:" << G4endl
450 <<
" overrides nturns option in the input gmad file" << G4endl
451 <<
"--output=<fmt> : output format (rootevent|none), default rootevent" << G4endl
452 <<
"--outfile=<file> : output file name. Will be appended with _N" << G4endl
453 <<
" where N = 0, 1, 2, 3... etc." << G4endl
454 <<
"--printFractionEvents=N : fraction of events to print out (default 0.1)" << G4endl
455 <<
" -1 is all, range [0-1]" << G4endl
456 <<
"--printFractionTurns=N : fraction of turns to print out (default 0.2)" << G4endl
457 <<
" -1 is all, range [0-1]" << G4endl
458 <<
"--printPhysicsProcesses : print out every particle registered and all " << G4endl
459 <<
" their processes - depends on physics list in input"<< G4endl
460 <<
"--P0=N : set P0 for the bunch for this run (GeV only)" << G4endl
461 <<
"--recreate=<file> : the rootevent file to recreate events from" << G4endl
462 <<
"--seed=N : the seed to use for the random number generator" << G4endl
463 <<
"--seedStateFileName=<file> : use this ASCII file seed state to run an event" << G4endl
464 <<
"--startFromEvent=N : event offset to start from when recreating events" << G4endl
465 <<
"--survey=<file> : print survey info to <file>" << G4endl
466 <<
"--verbose : display general parameters before run" << G4endl
467 <<
"--verboseRunLevel=N : set Geant4 verbosity at run level [0:5]" << G4endl
468 <<
"--verboseEventLevel=N : set Geant4 event manager verbosity level" << G4endl
469 <<
"--verboseEventStart=N : display tracking information from event number N" << G4endl
470 <<
"--verboseEventContinueFor=N : number of events to continue verbose event info for" << G4endl
471 <<
"--verboseTrackingLevel=N : set Geant4 verbosity about new tracks." << G4endl
472 <<
"--verboseSteppingLevel=N : set Geant4 Stepping manager verbosity level [0:5]" << G4endl
473 <<
"--verboseSteppingEventStart=N : event to start verbose stepping." << G4endl
474 <<
"--verboseSteppingEventContinueFor=N : number of events to continue verbose stepping" << G4endl
475 <<
" information for" << G4endl
476 <<
"--verboseSteppingPrimaryOnly : only print out verbose stepping for primary particle" << G4endl
477 <<
"--verboseEventBDSIM : display BDSIM information for every event " << G4endl
478 <<
"--verboseSteppingBDSIM : display BDSIM tracking information after each step"<< G4endl
479 <<
"--version : display version number" << G4endl
480 <<
"--versionGit : display version number including git commit SHA1" << G4endl
481 <<
"--vis_debug : display all volumes in visualiser" << G4endl
482 <<
"--vis_mac=<file> : file with the visualisation macro script, default" << G4endl
483 <<
" provided by BDSIM openGL (OGLSQt))" << G4endl
484 <<
"--writeseedstate : write an ASCII file seed state for each event" << G4endl;
490 G4cout<<
"BDSIM : version @BDSIM_VERSION@"<<G4endl;
491 G4cout<<
" (C) 2001-@CURRENT_YEAR@ Royal Holloway University London - GPLv3" << G4endl;
493 G4cout<<
" Reference: Computer Physics Communications, 107200 (2020)" << G4endl;
494 G4cout<<
" https://doi.org/10.1016/j.cpc.2020.107200" << G4endl;
495 G4cout<<
" https://arxiv.org/abs/1808.10745" << G4endl;
496 G4cout<<
" Website: http://www.pp.rhul.ac.uk/bdsim"<<G4endl;
502 G4cout <<
"BDSIM: An accelerator tracking code with particle-matter interactions." << G4endl;
503 G4cout <<
"L.J. Nevay et al., Computer Physics Communications, 1070200 (2020)" << G4endl;
504 G4cout <<
"https://doi.org/10.1016/j.cpc.2020.107200" << G4endl << G4endl;
505 G4cout << R
"(@article{NEVAY2020107200,)" << G4endl;
506 G4cout << R"(title = {BDSIM: An accelerator tracking code with particle–matter interactions},)" << G4endl;
507 G4cout << R"(journal = {Computer Physics Communications},)" << G4endl;
508 G4cout << R"(volume = {252},)" << G4endl;
509 G4cout << R"(pages = {107200},)" << G4endl;
510 G4cout << R"(year = {2020},)" << G4endl;
511 G4cout << R"(issn = {0010-4655},)" << G4endl;
512 G4cout << R"(doi = {https://doi.org/10.1016/j.cpc.2020.107200},)" << G4endl;
513 G4cout << R"(url = {https://www.sciencedirect.com/science/article/pii/S0010465520300400},)" << G4endl;
514 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;
515 G4cout << R"(})" << G4endl;
520 for (
const auto& key :
options.KeysOfSetValues())
521 {G4cout <<
"Executable option> " << std::setw(27) << std::left << key <<
": " << std::setw(15) << std::left <<
options.get_value_string(key) << G4endl;}
522 for (
const auto& key :
beam.KeysOfSetValues())
523 {G4cout <<
"Executable option> " << std::setw(27) << std::left << key <<
": " << std::setw(15) << std::left <<
beam.get_value_string(key) << G4endl;}
530 G4String fullPath = getEnv(
"BDSIMPATH");
532 G4cout << __METHOD_NAME__ <<
"filename = " << fileName << G4endl;
534 if (fullPath.empty())
536 G4String inputFilepath =
"";
538 G4String::size_type found = fileName.rfind(
"/");
539 if (found != G4String::npos)
540 {inputFilepath = fileName.substr(0,found);}
543 if ((fileName.substr(0,1)) ==
"/")
545 fullPath = inputFilepath;
550 fullPath = curDir +
"/" + inputFilepath;
554 if (fullPath.back() !=
'/')
557 G4cout << __METHOD_NAME__ <<
"fullpath = " << fullPath << G4endl;
static BDSColourFromMaterial * Instance()
Singleton pattern.
static BDSColours * Instance()
singleton pattern
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.
void Amalgamate(const Beam &optionsIn, bool override, int startFromEvent=0)
void set_value(std::string name, T value)
set methods by property name
bool batch
Flag for batch / interactive mode.
std::string inputFileName
Input filename.
std::string recreateFileName
The file path to recreate a run from.
int startFromEvent
Event to start from when recreating.
bool recreate
Whether to recreate from a file or not.
void Amalgamate(const Options &optionsIn, bool override)
void set_value(std::string name, T value)
set methods by property name
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.