Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HepMC3Reader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file HepMC3Reader.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2018-2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
10 
13 
14 #include <HepMC3/Units.h>
15 
17  HepMC3::GenEvent& event) {
18  // Read event and store it
19  return reader.read_event(event);
20 }
21 
22 bool ActsExamples::HepMC3AsciiReader::status(HepMC3::ReaderAscii& reader) {
23  return !reader.failed();
24 }
25 
29  : m_cfg(cfg),
30  m_eventsRange(
31  determineEventFilesRange(cfg.inputDir, cfg.inputStem + ".hepmc3")),
32  m_logger(Acts::getDefaultLogger("HepMC3AsciiReader", lvl)) {
33  if (m_cfg.inputStem.empty()) {
34  throw std::invalid_argument("Missing input filename stem");
35  }
36  if (m_cfg.outputEvents.empty()) {
37  throw std::invalid_argument("Missing output collection");
38  }
39 
41 }
42 
44  return "HepMC3AsciiReader";
45 }
46 
48  const {
49  return m_eventsRange;
50 }
51 
53  const ActsExamples::AlgorithmContext& ctx) {
54  std::vector<HepMC3::GenEvent> events;
55  HepMC3::GenEvent event(HepMC3::Units::GEV, HepMC3::Units::MM);
56 
57  auto path = perEventFilepath(m_cfg.inputDir, m_cfg.inputStem + ".hepmc3",
58  ctx.eventNumber);
59 
60  ACTS_DEBUG("Attempting to read event from " << path);
61  HepMC3::ReaderAscii reader(path);
62 
63  reader.read_event(event);
64  while (!reader.failed()) {
65  events.push_back(std::move(event));
66  event.clear();
67  reader.read_event(event);
68  }
69 
70  if (events.empty()) {
71  return ActsExamples::ProcessCode::ABORT;
72  }
73 
74  ACTS_VERBOSE(events.size()
75  << " events read, writing to " << m_cfg.outputEvents);
76  m_outputEvents(ctx, std::move(events));
77 
78  reader.close();
80 }