Skip to content
Snippets Groups Projects
Commit 08a983ca authored by Andre Sailer's avatar Andre Sailer
Browse files

HepMC3Reader: make sure we have a runInfo object when we create the reader

because the ASCII reader does not parse the run info when not reading a full event, we open the file, skip an event (which makes it read the run info), and then close and open again
parent 33568354
No related branches found
No related tags found
No related merge requests found
...@@ -125,12 +125,18 @@ DECLARE_GEANT4_EVENT_READER_NS(dd4hep::sim,HEPMC3FileReader) ...@@ -125,12 +125,18 @@ DECLARE_GEANT4_EVENT_READER_NS(dd4hep::sim,HEPMC3FileReader)
HEPMC3FileReader::HEPMC3FileReader(const std::string& nam) HEPMC3FileReader::HEPMC3FileReader(const std::string& nam)
: HEPMC3EventReader(nam) : HEPMC3EventReader(nam)
{ {
m_reader = HepMC3::deduce_reader(nam);
printout(INFO,"HEPMC3FileReader","Created file reader. Try to open input %s", nam.c_str()); printout(INFO,"HEPMC3FileReader","Created file reader. Try to open input %s", nam.c_str());
// to read potential run_info in HepMC3 ASCII files, we have to call skip(-1), otherwise run_info is only read when we m_reader = HepMC3::deduce_reader(nam);
// read the first event. This is different for different readers, and may or may not work :shrug: // to get the runInfo in the Ascii reader we have to force HepMC to read the first event
// skip(-1) is also a no-op for RootReader, and for RootReader the RunInfo is read when the file is opened m_reader->skip(1);
m_reader->skip(-1); // then we get the run info (shared pointer)
auto runInfo = m_reader->run_info();
// and close the reader
m_reader->close();
// so we can open the file again from the start
m_reader = HepMC3::deduce_reader(nam);
// and set the run info object now
m_reader->set_run_info(runInfo);
m_directAccess = false; m_directAccess = false;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment