File indexing completed on 2025-01-18 09:11:52
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include "ActsExamples/Io/EDM4hep/EDM4hepTrackReader.hpp"
0010
0011 #include "Acts/Plugins/EDM4hep/EDM4hepUtil.hpp"
0012 #include "ActsExamples/Io/EDM4hep/EDM4hepUtil.hpp"
0013
0014 #include <stdexcept>
0015
0016 #include <edm4hep/TrackCollection.h>
0017 #include <podio/Frame.h>
0018
0019 namespace ActsExamples {
0020
0021 EDM4hepTrackReader::EDM4hepTrackReader(const Config& config,
0022 Acts::Logging::Level level)
0023 : m_cfg(config),
0024 m_logger(Acts::getDefaultLogger("EDM4hepSimHitReader", level)) {
0025 if (m_cfg.outputTracks.empty()) {
0026 throw std::invalid_argument("Missing output trajectories collection");
0027 }
0028
0029 m_outputTracks.initialize(m_cfg.outputTracks);
0030
0031 m_eventsRange = {0, reader().getEntries("events")};
0032 }
0033
0034 std::pair<std::size_t, std::size_t> EDM4hepTrackReader::availableEvents()
0035 const {
0036 return m_eventsRange;
0037 }
0038
0039 std::string EDM4hepTrackReader::EDM4hepTrackReader::name() const {
0040 return "EDM4hepTrackReader";
0041 }
0042
0043 ProcessCode EDM4hepTrackReader::read(const AlgorithmContext& ctx) {
0044 podio::Frame frame = reader().readEntry("events", ctx.eventNumber);
0045
0046 const auto& trackCollection =
0047 frame.get<edm4hep::TrackCollection>(m_cfg.inputTracks);
0048
0049 auto trackContainer = std::make_shared<Acts::VectorTrackContainer>();
0050 auto trackStateContainer = std::make_shared<Acts::VectorMultiTrajectory>();
0051 TrackContainer tracks(trackContainer, trackStateContainer);
0052
0053 for (const auto& inputTrack : trackCollection) {
0054 auto track = tracks.makeTrack();
0055 Acts::EDM4hepUtil::readTrack(inputTrack, track, m_cfg.Bz);
0056 }
0057
0058 ConstTrackContainer constTracks{
0059 std::make_shared<Acts::ConstVectorTrackContainer>(
0060 std::move(*trackContainer)),
0061 std::make_shared<Acts::ConstVectorMultiTrajectory>(
0062 std::move(*trackStateContainer))};
0063
0064 m_outputTracks(ctx, std::move(constTracks));
0065
0066 return ProcessCode::SUCCESS;
0067 }
0068
0069 Acts::PodioUtil::ROOTReader& EDM4hepTrackReader::reader() {
0070 bool exists = false;
0071 auto& reader = m_reader.local(exists);
0072 if (!exists) {
0073 reader.openFile(m_cfg.inputPath);
0074 }
0075
0076 return reader;
0077 }
0078
0079 }