From f2a3880a60a8b4b566768e6c43d0f2fe87fd1261 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Thu, 20 Jun 2019 14:55:37 -0400 Subject: [PATCH] - one last fix to the way run numbers are assigned, based on input from various sources -- see control.in for details [rtj] --- src/hdgeant4.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/hdgeant4.cc b/src/hdgeant4.cc index d7b1ffc..6e816ac 100644 --- a/src/hdgeant4.cc +++ b/src/hdgeant4.cc @@ -91,14 +91,24 @@ int main(int argc,char** argv) } if (run_number == 0) { std::map runno_opts; + std::map infile_opts; if (opts.Find("RUNNO", runno_opts) || opts.Find("RUNG", runno_opts)) { run_number = runno_opts[1]; } - else { - G4cerr << "Warning - " - << "no run number specified in control.in, " - << "default value of 0 assumed." << G4endl; - run_number = 0; + else if (opts.Find("INFILE", infile_opts) || + opts.Find("INFI", infile_opts)) + { + std::ifstream fin(infile_opts[1].c_str()); + if (!fin.is_open()) { + G4cerr << "Input error: Unable to open HDDM input file: " + << infile_opts[1] << G4endl; + exit(-1); + } + hddm_s::istream ifs(fin); + hddm_s::HDDM record; + while (record.getPhysicsEvents().size() == 0) + ifs >> record; + run_number = record.getPhysicsEvents()(0).getRunNo(); } }