File indexing completed on 2025-08-06 08:10:47
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/EDM4hep/EDM4hepParticleWriter.hpp"
0010
0011 #include "Acts/Definitions/Units.hpp"
0012 #include "ActsExamples/Framework/WhiteBoard.hpp"
0013 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0014 #include "ActsExamples/Utilities/Paths.hpp"
0015
0016 #include <stdexcept>
0017
0018 #include <edm4hep/MCParticle.h>
0019 #include <edm4hep/MCParticleCollection.h>
0020 #include <podio/Frame.h>
0021
0022 namespace ActsExamples {
0023
0024 EDM4hepParticleWriter::EDM4hepParticleWriter(
0025 const EDM4hepParticleWriter::Config& cfg, Acts::Logging::Level lvl)
0026 : WriterT(cfg.inputParticles, "EDM4hepParticleWriter", lvl),
0027 m_cfg(cfg),
0028 m_writer(cfg.outputPath) {
0029 ACTS_VERBOSE("Created output file " << cfg.outputPath);
0030
0031 if (m_cfg.inputParticles.empty()) {
0032 throw std::invalid_argument("Missing particles input collection");
0033 }
0034 }
0035
0036 ActsExamples::ProcessCode EDM4hepParticleWriter::finalize() {
0037 m_writer.finish();
0038
0039 return ProcessCode::SUCCESS;
0040 }
0041
0042 ProcessCode EDM4hepParticleWriter::writeT(
0043 const AlgorithmContext& , const SimParticleContainer& particles) {
0044 podio::Frame frame;
0045
0046 edm4hep::MCParticleCollection mcParticleCollection;
0047
0048 for (const auto& particle : particles) {
0049 auto p = mcParticleCollection->create();
0050 EDM4hepUtil::writeParticle(particle, p);
0051 }
0052
0053 frame.put(std::move(mcParticleCollection), m_cfg.outputParticles);
0054
0055 std::lock_guard guard(m_writeMutex);
0056 m_writer.writeFrame(frame, "events");
0057
0058 return ProcessCode::SUCCESS;
0059 }
0060
0061 }