Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 08:19:58

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/Podio/PodioReader.hpp"
0010 
0011 #include "Acts/Utilities/ScopedTimer.hpp"
0012 #include "ActsExamples/Framework/DataHandle.hpp"
0013 #include "ActsPlugins/EDM4hep/PodioUtil.hpp"
0014 
0015 #include <filesystem>
0016 
0017 #include <podio/Frame.h>
0018 #include <tbb/enumerable_thread_specific.h>
0019 
0020 namespace ActsExamples {
0021 
0022 class PodioReader::Impl {
0023  public:
0024   explicit Impl(PodioReader::Config cfg, PodioReader& parent)
0025       : m_frameWriteHandle(&parent, "EDM4hepFrameOutput"),
0026         m_cfg(std::move(cfg)) {
0027     m_eventsRange = std::make_pair(0, reader().getEntries("events"));
0028     if (!std::filesystem::exists(m_cfg.inputPath)) {
0029       throw std::invalid_argument("Input file does not exist");
0030     }
0031     if (m_cfg.outputFrame.empty()) {
0032       throw std::invalid_argument("Output frame name is not set");
0033     }
0034     if (m_cfg.category.empty()) {
0035       throw std::invalid_argument("Category name is not set");
0036     }
0037 
0038     m_frameWriteHandle.initialize(m_cfg.outputFrame);
0039   }
0040 
0041   ActsPlugins::PodioUtil::ROOTReader& reader() {
0042     bool exists = false;
0043     auto& reader = m_reader.local(exists);
0044     if (!exists) {
0045       reader.openFile(m_cfg.inputPath);
0046     }
0047 
0048     return reader;
0049   }
0050 
0051   WriteDataHandle<podio::Frame> m_frameWriteHandle;
0052   std::pair<std::size_t, std::size_t> m_eventsRange;
0053 
0054   tbb::enumerable_thread_specific<ActsPlugins::PodioUtil::ROOTReader> m_reader;
0055   PodioReader::Config m_cfg;
0056 };
0057 
0058 PodioReader::PodioReader(const Config& config, Acts::Logging::Level level)
0059     : m_impl(std::make_unique<Impl>(config, *this)),
0060       m_logger(Acts::getDefaultLogger("PodioReader", level)) {}
0061 
0062 PodioReader::~PodioReader() = default;
0063 
0064 ProcessCode PodioReader::read(const AlgorithmContext& context) {
0065   Acts::ScopedTimer timer("Reading PODIO inputs", logger(),
0066                           Acts::Logging::DEBUG);
0067   podio::Frame frame = m_impl->reader().readEntry(
0068       m_impl->m_cfg.category, static_cast<unsigned int>(context.eventNumber));
0069   m_impl->m_frameWriteHandle(context, std::move(frame));
0070 
0071   return ProcessCode::SUCCESS;
0072 }
0073 
0074 std::pair<std::size_t, std::size_t> PodioReader::availableEvents() const {
0075   return m_impl->m_eventsRange;
0076 }
0077 
0078 std::string PodioReader::name() const {
0079   return "PodioReader";
0080 }
0081 
0082 const PodioReader::Config& PodioReader::config() const {
0083   return m_impl->m_cfg;
0084 }
0085 
0086 }  // namespace ActsExamples