From 9075f52eca9ab231b62820c92bc9c99b8f545985 Mon Sep 17 00:00:00 2001 From: isenri_p Date: Thu, 13 Feb 2025 10:47:01 +0100 Subject: [PATCH] Runnumber corret for provided command line paths --- musrSim.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/musrSim.cc b/musrSim.cc index de5fb49..050c61d 100644 --- a/musrSim.cc +++ b/musrSim.cc @@ -1,3 +1,4 @@ +#include #include "musrDetectorConstruction.hh" #include "musrPhysicsList.hh" #include "musrPrimaryGeneratorAction.hh" @@ -76,9 +77,13 @@ int main(int argc,char** argv) { // UserInitialization classes (mandatory) // musrDetectorConstruction* musrdetector = new musrDetectorConstruction; + //Allow for argv[1] generic paths and only extract the runnumber before .mac if (argc>1) { - G4int myRunNr=atoi(argv[1]); // Get the run number from the name of the - // parameter file, if it starts with a number. + std::regex pattern(R"((\d+)(?=(?=[^/]*\.mac$)))"); // for an input like /some/path987/1234.mac for argv[1]. Matches last number (1234) before ".mac" + std::smatch match; + G4int myRunNr = 0; + std::string argv1str(argv[1]); + if (std::regex_search(argv1str, match, pattern)) myRunNr = G4int(std::stoi(match.str(1))); if (myRunNr>0) {runManager->SetRunIDCounter(myRunNr);} // musrdetector->SetInputParameterFileName(argv[1]); }