Skip to content

Commit 061aaf2

Browse files
authored
Merge pull request #127 from rest-for-physics/lobis-download
Option to set run number from cli
2 parents 8d720c7 + 3a0fdd0 commit 061aaf2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

include/Application.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ struct Options {
2626
int nRequestedEntries = 0;
2727
int timeLimitSeconds = 0;
2828

29+
int runNumber = -1;
30+
2931
// reference to original argc and argv necessary to pass to G4UIExecutive
3032
int argc;
3133
char** argv;

src/Application.cxx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,18 @@ Options ProcessCommandLineOptions(int argc, char* const argv[]) {
244244
cerr << "--time option requires one argument." << endl;
245245
exit(1);
246246
}
247+
} else if (arg == "--runNumber") {
248+
if (i + 1 < argc) { // Make sure we aren't at the end of argv!
249+
options.runNumber =
250+
stoi(argv[++i]); // Increment 'i' so we don't get the argument as the next argv[i].
251+
if (options.runNumber < 0) {
252+
cout << "--runNumber option error: runNumber cannot be negative" << endl;
253+
exit(1);
254+
}
255+
} else {
256+
cerr << "--runNumber option requires one argument." << endl;
257+
exit(1);
258+
}
247259
} else {
248260
const string argument = argv[i];
249261
if (argument[0] == '-') {
@@ -347,6 +359,10 @@ void Application::Run(const CommandLineOptions::Options& options) {
347359

348360
run->LoadConfigFromFile(inputRmlClean);
349361

362+
if (options.runNumber >= 0) {
363+
run->SetRunNumber(options.runNumber);
364+
}
365+
350366
if (!options.outputFile.empty()) {
351367
run->SetOutputFileName(options.outputFile);
352368
}
@@ -362,7 +378,6 @@ void Application::Run(const CommandLineOptions::Options& options) {
362378

363379
run->AddMetadata(fSimulationManager.GetRestMetadata());
364380
run->AddMetadata(fSimulationManager.GetRestPhysicsLists());
365-
366381
run->PrintMetadata();
367382

368383
run->FormOutputFile();

0 commit comments

Comments
 (0)