@@ -129,17 +129,19 @@ HEPMC3FileReader::HEPMC3FileReader(const std::string& nam)
129129 printout (INFO," HEPMC3FileReader" ," Created file reader. Try to open input %s" , nam.c_str ());
130130 m_reader = HepMC3::deduce_reader (nam);
131131#if HEPMC3_VERSION_CODE >= 3002006
132- // to get the runInfo in the Ascii reader we have to force HepMC to read the first event
133- HepMC3::GenEvent dummy;
134- m_reader->read_event (dummy);
135- // then we get the run info (shared pointer)
136- auto runInfo = m_reader->run_info ();
137- // and deallocate the reader
138- m_reader.reset ();
139- // so we can open the file again from the start
140- m_reader = HepMC3::deduce_reader (nam);
141- // and set the run info object now
142- m_reader->set_run_info (std::move (runInfo));
132+ if (std::dynamic_pointer_cast<HepMC3::ReaderAscii>(m_reader) != nullptr ) {
133+ // to get the runInfo in the Ascii reader we have to force HepMC to read the first event
134+ HepMC3::GenEvent dummy;
135+ m_reader->read_event (dummy);
136+ // then we get the run info (shared pointer)
137+ auto runInfo = m_reader->run_info ();
138+ // and deallocate the reader
139+ m_reader.reset ();
140+ // so we can open the file again from the start
141+ m_reader = HepMC3::deduce_reader (nam);
142+ // and set the run info object now
143+ m_reader->set_run_info (std::move (runInfo));
144+ }
143145#endif
144146 m_directAccess = false ;
145147}
0 commit comments