Skip to content

Commit 16a675d

Browse files
authored
fix: avoid double deduce/open for HEPMC3FileReader when not ReaderAscii (#1495)
1 parent c4f9052 commit 16a675d

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

DDG4/hepmc/HepMC3FileReader.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)