ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Tracking
Acts
ActsMaterial
src
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
5
#include "
MaterialTrackReader.h
"
6
#include "GaudiKernel/IInterface.h"
7
8
#include "
GeoPrimitives/GeoPrimitivesToStringConverter.h
"
9
10
#include "TTree.h"
11
#include "TFile.h"
12
13
14
ActsTrk::MaterialTrackReader::~MaterialTrackReader
() =
default
;
15
16
StatusCode
ActsTrk::MaterialTrackReader::initialize
()
17
{
18
ATH_CHECK
(
m_materialTrackCollectionKey
.initialize());
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. "
);
47
for
(;
m_currEntry
<
m_nTreeEntries
; ++
m_currEntry
) {
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
72
StatusCode
ActsTrk::MaterialTrackReader::finalize
() {
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
81
StatusCode
82
ActsTrk::MaterialTrackReader::execute
(
const
EventContext& ctx) {
83
// Write to the collection to the EventStore
84
SG::WriteHandle
materialTracks{
m_materialTrackCollectionKey
, ctx};
85
86
// Record the collection once per event if not already there
87
if
(!materialTracks.
isPresent
()) {
88
ATH_CHECK
(materialTracks.
record
(std::make_unique<ActsTrk::RecordedMaterialTrackCollection>()));
89
}
90
91
if
(
m_currEntry
>=
m_nTreeEntries
) {
92
m_inputChain
.reset();
93
return
StatusCode::SUCCESS;
94
}
95
96
std::size_t nProcEvents{0ul};
97
std::size_t nCurrentEvt{
m_accessor
.eventId()};
98
99
for
(;
m_currEntry
<
m_nTreeEntries
; ++
m_currEntry
) {
100
ATH_MSG_VERBOSE
(
"Fetched entry "
<<
m_currEntry
<<
", eventId: "
<<
m_accessor
.eventId());
101
// get the correspoing entry and read it
102
m_inputChain
->GetEntry(
m_currEntry
);
103
Acts::RecordedMaterialTrack rmTrack =
m_accessor
.read();
104
m_accessor
.eventId();
105
106
ATH_MSG_VERBOSE
(
"Track vertex: "
<<
Amg::toString
(rmTrack.first.first)
107
<<
", momentum:"
<<
Amg::toString
(rmTrack.first.second));
108
109
if
(nCurrentEvt !=
m_accessor
.eventId()) {
110
++nProcEvents;
111
++
m_procEvents
;
112
nCurrentEvt =
m_accessor
.eventId();
113
}
114
115
if
(
m_procEvents
>=
m_maxEvents
) {
116
ATH_MSG_INFO
(
"All "
<<
m_maxEvents
<<
" events have been processed"
);
117
m_currEntry
=
m_nTreeEntries
;
118
return
StatusCode::SUCCESS;
119
}
120
121
if
(nProcEvents >=
m_batchSize
) {
122
ATH_MSG_DEBUG
(
"Batch processing "
<<nProcEvents<<
" completed. "
);
123
break
;
124
}
125
126
// filling the collection
127
materialTracks->push_back(std::move(rmTrack));
128
129
}
130
return
StatusCode::SUCCESS;
131
}
132
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition
AthMsgStreamMacros.h:28
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
GeoPrimitivesToStringConverter.h
MaterialTrackReader.h
ActsTrk::MaterialTrackReader::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
MaterialTrackReader.cxx:82
ActsTrk::MaterialTrackReader::m_inputChain
std::unique_ptr< TChain > m_inputChain
The input chain of entries.
Definition
MaterialTrackReader.h:63
ActsTrk::MaterialTrackReader::m_batchSize
Gaudi::Property< std::size_t > m_batchSize
The batch size (number of track per events).
Definition
MaterialTrackReader.h:47
ActsTrk::MaterialTrackReader::m_accessor
ActsPlugins::RootMaterialTrackIo m_accessor
The read - write payload.
Definition
MaterialTrackReader.h:61
ActsTrk::MaterialTrackReader::m_skipEvents
Gaudi::Property< std::size_t > m_skipEvents
The number of events in the file to skip.
Definition
MaterialTrackReader.h:45
ActsTrk::MaterialTrackReader::initialize
virtual StatusCode initialize() override
Definition
MaterialTrackReader.cxx:16
ActsTrk::MaterialTrackReader::m_maxEvents
Gaudi::Property< std::size_t > m_maxEvents
The number of events in the processed.
Definition
MaterialTrackReader.h:43
ActsTrk::MaterialTrackReader::finalize
virtual StatusCode finalize() override
Definition
MaterialTrackReader.cxx:72
ActsTrk::MaterialTrackReader::m_fileNames
Gaudi::Property< std::vector< std::string > > m_fileNames
The list of input filenames.
Definition
MaterialTrackReader.h:55
ActsTrk::MaterialTrackReader::m_treeName
Gaudi::Property< std::string > m_treeName
The name of the input tree.
Definition
MaterialTrackReader.h:57
ActsTrk::MaterialTrackReader::~MaterialTrackReader
virtual ~MaterialTrackReader()
ActsTrk::MaterialTrackReader::m_nTreeEntries
std::size_t m_nTreeEntries
The number of entries in the tree to read.
Definition
MaterialTrackReader.h:49
ActsTrk::MaterialTrackReader::m_materialTrackCollectionKey
SG::WriteHandleKey< RecordedMaterialTrackCollection > m_materialTrackCollectionKey
The RecordedMaterialTrackCollection to write.
Definition
MaterialTrackReader.h:65
ActsTrk::MaterialTrackReader::m_currEntry
std::size_t m_currEntry
The current processed tree entry.
Definition
MaterialTrackReader.h:51
ActsTrk::MaterialTrackReader::m_procEvents
std::size_t m_procEvents
The number of processed tree events.
Definition
MaterialTrackReader.h:53
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition
StoreGate/src/VarHandleBase.cxx:400
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
Amg::toString
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Definition
GeoPrimitivesToStringConverter.h:40
Generated on
for ATLAS Offline Software by
1.17.0