Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EDM4hepParticleWriter.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EDM4hepParticleWriter.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 
15 
16 #include <stdexcept>
17 
18 #include <edm4hep/MCParticle.h>
19 #include <edm4hep/MCParticleCollection.h>
20 #include <podio/Frame.h>
21 
22 namespace ActsExamples {
23 
26  : WriterT(cfg.inputParticles, "EDM4hepParticleWriter", lvl),
27  m_cfg(cfg),
28  m_writer(cfg.outputPath) {
29  ACTS_VERBOSE("Created output file " << cfg.outputPath);
30 
31  if (m_cfg.inputParticles.empty()) {
32  throw std::invalid_argument("Missing particles input collection");
33  }
34 }
35 
37  m_writer.finish();
38 
39  return ProcessCode::SUCCESS;
40 }
41 
43  const AlgorithmContext& /*ctx*/, const SimParticleContainer& particles) {
44  podio::Frame frame;
45 
46  edm4hep::MCParticleCollection mcParticleCollection;
47 
48  for (const auto& particle : particles) {
49  auto p = mcParticleCollection->create();
51  }
52 
53  frame.put(std::move(mcParticleCollection), m_cfg.outputParticles);
54 
55  m_writer.writeFrame(frame, "events");
56 
57  return ProcessCode::SUCCESS;
58 }
59 
60 } // namespace ActsExamples