Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:52

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include "ActsExamples/Io/EDM4hep/EDM4hepParticleWriter.hpp"
0010 
0011 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0012 
0013 #include <stdexcept>
0014 
0015 #include <edm4hep/MCParticle.h>
0016 #include <edm4hep/MCParticleCollection.h>
0017 #include <podio/Frame.h>
0018 
0019 namespace ActsExamples {
0020 
0021 EDM4hepParticleWriter::EDM4hepParticleWriter(
0022     const EDM4hepParticleWriter::Config& cfg, Acts::Logging::Level lvl)
0023     : WriterT(cfg.inputParticles, "EDM4hepParticleWriter", lvl),
0024       m_cfg(cfg),
0025       m_writer(cfg.outputPath) {
0026   ACTS_VERBOSE("Created output file " << cfg.outputPath);
0027 
0028   if (m_cfg.inputParticles.empty()) {
0029     throw std::invalid_argument("Missing particles input collection");
0030   }
0031 }
0032 
0033 ActsExamples::ProcessCode EDM4hepParticleWriter::finalize() {
0034   m_writer.finish();
0035 
0036   return ProcessCode::SUCCESS;
0037 }
0038 
0039 ProcessCode EDM4hepParticleWriter::writeT(
0040     const AlgorithmContext& /*ctx*/, const SimParticleContainer& particles) {
0041   podio::Frame frame;
0042 
0043   edm4hep::MCParticleCollection mcParticleCollection;
0044 
0045   for (const auto& particle : particles) {
0046     auto p = mcParticleCollection->create();
0047     EDM4hepUtil::writeParticle(particle, p);
0048   }
0049 
0050   frame.put(std::move(mcParticleCollection), m_cfg.outputParticles);
0051 
0052   std::lock_guard guard(m_writeMutex);
0053   m_writer.writeFrame(frame, "events");
0054 
0055   return ProcessCode::SUCCESS;
0056 }
0057 
0058 }  // namespace ActsExamples