Skip to content

Commit

Permalink
implemented additional options to command line parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lobis committed Mar 5, 2022
1 parent c86aa2f commit 5dcd994
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 13 additions & 0 deletions restG4.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ Int_t N_events;
int main(int argc, char** argv) {
auto start_time = chrono::steady_clock::now();

char cwd[kMAXPATHLEN];
cout << "Current working directory: " << getcwd(cwd, sizeof(cwd)) << endl;

CommandLineParameters commandLineParameters = CommandLineSetup::ProcessParameters(argc, argv);
CommandLineSetup::Print(commandLineParameters);

Expand All @@ -76,6 +79,10 @@ int main(int argc, char** argv) {

restG4Metadata = new TRestGeant4Metadata(inputRMLClean);

if (!commandLineParameters.geometryFile.IsNull()) {
restG4Metadata->Set_GDML_Filename(commandLineParameters.geometryFile.Data());
}

string geant4Version = TRestTools::Execute("geant4-config --version");
restG4Metadata->SetGeant4Version(geant4Version);

Expand All @@ -88,6 +95,8 @@ int main(int argc, char** argv) {
auto gdml = new TRestGDMLParser();

// This call will generate a new single file GDML output
auto geometryFilename = restG4Metadata->Get_GDML_Filename();
cout << "Geometry Filename: " << geometryFilename << endl;
gdml->Load((string)restG4Metadata->Get_GDML_Filename());

// We redefine the value of the GDML file to be used in DetectorConstructor.
Expand All @@ -102,6 +111,10 @@ int main(int argc, char** argv) {
restRun = new TRestRun();
restRun->LoadConfigFromFile(inputRMLClean);

if (!commandLineParameters.outputFile.IsNull()) {
restRun->SetOutputFileName(commandLineParameters.outputFile.Data());
}

TRestTools::ReturnToPreviousDirectory();

TString runTag = restRun->GetRunTag();
Expand Down
14 changes: 9 additions & 5 deletions src/CommandLineSetup.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@

#include <getopt.h>
#include <unistd.h>

#include <iostream>

using namespace std;

void CommandLineSetup::ShowUsage() {
cout << "restG4 requires at least one parameter, the rml configuration file (-c is optional)" << endl
cout << "restG4 requires at least one parameter, the rml configuration file" << endl
<< endl
<< "example: restG4 example.rml" << endl
<< endl
<< "there are other convenient optional parameters that override the ones in the rml file:" << endl
<< "\t-h or --help | show usage (this text)" << endl
<< "\t-c example.rml | specify RML file (same as calling restG4 example.rml)" << endl
<< "\t-o output.root | specify output file" << endl
<< "\t-g geometry.gdml | specify geometry file" << endl
<< "\t-i | set interactive mode (default=false)" << endl
<< "\t-s | set serial mode (no multithreading) (default=true)" << endl
Expand All @@ -30,7 +32,7 @@ CommandLineParameters CommandLineSetup::ProcessParameters(int argc, char** argv)
if (argc >= 2) {
// presumably invoked as `restG4 example.rml` or `restG4 --help`
TString argument = argv[1];
if (argument.EqualTo("--help") | argument.EqualTo("-h")) {
if (argument.EqualTo("--help") || argument.EqualTo("-h")) {
ShowUsage();
exit(0);
} else {
Expand Down Expand Up @@ -81,9 +83,7 @@ CommandLineParameters CommandLineSetup::ProcessParameters(int argc, char** argv)
case 'g':
if (!parameters.geometryFile.IsNull()) {
cout << "CommandLineParameters::ProcessParameters - Cannot specify multiple geometry "
"files "
"via the -g flag. "
"Please use at most one"
"files via the -g flag. Please use at most one"
<< endl;
exit(1);
}
Expand All @@ -105,9 +105,13 @@ CommandLineParameters CommandLineSetup::ProcessParameters(int argc, char** argv)

return parameters;
}

void CommandLineSetup::Print(const CommandLineParameters& parameters) {
cout << "Command line parameters configuration:" << endl
<< "\t- RML file: " << parameters.rmlFile << endl
<< (!parameters.outputFile.IsNull() ? "\t- Output file: " + parameters.outputFile + "\n" : "")
<< (!parameters.geometryFile.IsNull() ? "\t- Geometry file: " + parameters.geometryFile + "\n" : "")
<< (parameters.interactive ? "\t- Interactive: True\n" : "") //
<< "\t- Execution mode: "
<< (parameters.serialMode ? "serial"
: "multithreading (N = " + std::to_string(parameters.nThreads) + ")")
Expand Down

0 comments on commit 5dcd994

Please sign in to comment.