Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EDM4hepParticleReader.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EDM4hepParticleReader.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2022 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 
16 
17 #include <stdexcept>
18 
19 #include <podio/Frame.h>
20 
21 namespace ActsExamples {
22 
25  : m_cfg(config),
26  m_logger(Acts::getDefaultLogger("EDM4hepParticleReader", level)) {
27  if (m_cfg.outputParticles.empty()) {
28  throw std::invalid_argument("Missing output collection");
29  }
30 
31  m_reader.openFile(m_cfg.inputPath);
32 
33  m_eventsRange = std::make_pair(0, m_reader.getEntries("events"));
34 
36 }
37 
39  return "EDM4hepParticleReader";
40 }
41 
42 std::pair<size_t, size_t> EDM4hepParticleReader::availableEvents() const {
43  return m_eventsRange;
44 }
45 
47  podio::Frame frame = m_reader.readEntry("events", ctx.eventNumber);
48  const auto& mcParticleCollection =
49  frame.get<edm4hep::MCParticleCollection>(m_cfg.inputParticles);
50 
51  SimParticleContainer::sequence_type unordered;
52 
53  for (const auto& mcParticle : mcParticleCollection) {
54  auto particle =
55  EDM4hepUtil::readParticle(mcParticle, [](const edm4hep::MCParticle& p) {
56  ActsFatras::Barcode result;
57  // TODO dont use podio internal id
58  result.setParticle(p.id());
59  return result;
60  });
61  unordered.push_back(particle);
62  }
63 
64  // Write ordered particles container to the EventStore
66  particles.insert(unordered.begin(), unordered.end());
67  m_outputParticles(ctx, std::move(particles));
68 
69  return ProcessCode::SUCCESS;
70 }
71 
72 } // namespace ActsExamples