ATLAS Offline Software
Loading...
Searching...
No Matches
MaterialTrackReader.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "GaudiKernel/IInterface.h"
7
9
10#include "TTree.h"
11#include "TFile.h"
12
13
15
17{
19
20 if (m_fileNames.empty()) {
21 ATH_MSG_ERROR("No input files given... Please check!!");
22 return StatusCode::FAILURE;
23 }
24
25 // set up the input chain
26 m_inputChain = std::make_unique<TChain>(m_treeName.value().c_str());
27
28 // loop over the input files
29 for (const auto& inputFile : m_fileNames) {
30 // add file to the input chain
31 ATH_MSG_DEBUG("Adding File " << inputFile << " to tree '" << m_treeName << "'.");
32 if (!m_inputChain->Add(inputFile.c_str())) {
33 ATH_MSG_ERROR("Failed to load file "<<inputFile);
34 return StatusCode::FAILURE;
35 }
36 }
37
38 // Connect the branches
39 m_accessor.connectForRead(*m_inputChain);
40 // get the number of events, which also loads the tree
41 m_nTreeEntries = m_inputChain->GetEntries();
42
43 if (m_skipEvents >0ul) {
44 std::optional<std::uint32_t> evt{0ul};
45 std::size_t procEvts{0ul};
46 ATH_MSG_DEBUG("Skip "<<m_skipEvents<<" events. ");
48 m_inputChain->GetEntry(m_currEntry);
49 if (!evt) {
50 evt = m_accessor.eventId();
51 } else if ((*evt) != m_accessor.eventId()) {
52 ++procEvts;
53 evt = m_accessor.eventId();
54 }
55 if (procEvts == m_skipEvents) {
56 break;
57 }
58 }
59 ATH_MSG_INFO("Skipped "<<procEvts<<" events. Corresponding to "
60 <<m_currEntry<<" tree entries");
61 }
62 if (!m_nTreeEntries) {
63 ATH_MSG_ERROR("Input does not contain any recorded track");
64 return StatusCode::FAILURE;
65 }
66 ATH_MSG_INFO("Material files contain " << m_nTreeEntries << " entries. Process "
67 <<m_batchSize.value()<<" material events per athena event. Until "
68 <<m_maxEvents.value()<<" events are processed or the tree is finished");
69 return StatusCode::SUCCESS;
70}
71
73 if (m_inputChain) {
74 ATH_MSG_ERROR("Not all entries / events have been processed. Processed entries: "
75 <<(m_currEntry+ 1)<<"/"<<m_nTreeEntries<<", processed events: "
76 <<m_procEvents<<"/"<<m_maxEvents.value());
77 }
78 return StatusCode::SUCCESS;
79}
80
81StatusCode
83 const EventContext& ctx{Gaudi::Hive::currentContext()};
84 // Write to the collection to the EventStore
86
87 // Record the collection once per event if not already there
88 if (!materialTracks.isPresent()) {
89 ATH_CHECK(materialTracks.record(std::make_unique<ActsTrk::RecordedMaterialTrackCollection>()));
90 }
91
93 m_inputChain.reset();
94 return StatusCode::SUCCESS;
95 }
96
97 std::size_t nProcEvents{0ul};
98 std::size_t nCurrentEvt{m_accessor.eventId()};
99
101 ATH_MSG_VERBOSE("Fetched entry "<<m_currEntry<<", eventId: "<<m_accessor.eventId());
102 // get the correspoing entry and read it
103 m_inputChain->GetEntry(m_currEntry);
104 Acts::RecordedMaterialTrack rmTrack = m_accessor.read();
105 m_accessor.eventId();
106
107 ATH_MSG_VERBOSE("Track vertex: " << Amg::toString(rmTrack.first.first)
108 <<", momentum:" << Amg::toString(rmTrack.first.second));
109
110 // filling the collection
111 materialTracks->push_back(std::move(rmTrack));
112 if (nCurrentEvt != m_accessor.eventId()) {
113 ++nProcEvents;
114 ++m_procEvents;
115 nCurrentEvt = m_accessor.eventId();
116 }
117
118 if (m_procEvents >= m_maxEvents) {
119 ATH_MSG_INFO("All "<<m_maxEvents<<" events have been processed");
121 return StatusCode::SUCCESS;
122 }
123
124 if (nProcEvents >=m_batchSize) {
125 ATH_MSG_DEBUG("Batch processing "<<nProcEvents<<" completed. ");
126 break;
127 }
128
129 }
130 return StatusCode::SUCCESS;
131}
132
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
std::unique_ptr< TChain > m_inputChain
The input chain of entries.
Gaudi::Property< std::size_t > m_batchSize
The batch size (number of track per events).
ActsPlugins::RootMaterialTrackIo m_accessor
The read - write payload.
Gaudi::Property< std::size_t > m_skipEvents
The number of events in the file to skip.
virtual StatusCode initialize() override
Gaudi::Property< std::size_t > m_maxEvents
The number of events in the processed.
virtual StatusCode finalize() override
Gaudi::Property< std::vector< std::string > > m_fileNames
The list of input filenames.
Gaudi::Property< std::string > m_treeName
The name of the input tree.
virtual StatusCode execute() override
std::size_t m_nTreeEntries
The number of entries in the tree to read.
SG::WriteHandleKey< RecordedMaterialTrackCollection > m_materialTrackCollectionKey
The RecordedMaterialTrackCollection to write.
std::size_t m_currEntry
The current processed tree entry.
std::size_t m_procEvents
The number of processed tree events.
bool isPresent() const
Is the referenced object present in SG?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.