ATLAS Offline Software
Loading...
Searching...
No Matches
ITkPixelDecodingPhaseIIRDOAlg.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ITKPIXEL_DECODINGPHASEIIRDOALG_H
6#define ITKPIXEL_DECODINGPHASEIIRDOALG_H
7
8
11#include "GaudiKernel/MsgStream.h"
15#include "Identifier/Identifier.h"
20#include "itksw/pix/endec/DecCore.hpp"
21#include <chrono>
22#include <limits>
23#include <cstdint> //for uint8_t etc.
24
25//class PixelID;
26
28{
29 public:
30
31 ITkPixelDecodingPhaseIIRDOAlg(const std::string &name, ISvcLocator *pSvcLocator);
32
33 virtual StatusCode initialize() override;
34
35 virtual StatusCode execute (const EventContext& ctx) const override;
36
37 virtual StatusCode finalize() override;
38
39
40 private:
41
42 typedef std::vector< std::vector<uint32_t >> ITkPacketCollection;
43
45 { this, "ROBDataProvider", "ROBDataProviderSvc" };
46
48 {this, "PixelCablingKey", "ITkPixelCablingData", "Cond Key of Pixel Cabling"};
49
51 {this, "pixelRDOKey", "PixelRDOs", "StoreGate Key of Pixel RDOs"};
52
53 std::vector<uint32_t> m_sourceIDs;
54
56
57 const Gaudi::Property<uint32_t> m_n_rdos_est {this, "nRDOs", 1300000, "Estimated number of RDOs per event"};
58
59};
60
62 struct ScopedTimer {
63 std::string m_label;
64 std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
65 MsgStream& m_msg_source;
66
67 ScopedTimer(std::string lbl, MsgStream& src) : m_label(std::move(lbl)), m_start(std::chrono::high_resolution_clock::now()), m_msg_source(src) {}
69 auto end = std::chrono::high_resolution_clock::now();
70 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - m_start).count();
71 m_msg_source << MSG::DEBUG << m_label << " took " << ms << " ms" << endmsg;
72 }
73
74 };
75}
76
78 //Forms pixel RDOs from the decoded hits & fills them into a container
80
81 public:
83 PhaseIIPixelRawDataContainerMT::ContainerPtr rdo_container_dest, const PixelID* idHelper, MsgStream& msg_source) :
84 m_rdo_container_dest(rdo_container_dest),
85 m_cont_coll(cont_coll),
86 m_dest_range_guard(rdo_container_dest),
88 m_idHelper(idHelper),
89 m_msg_source(msg_source)
90 {};
91
93
94 //Obligatory members for the interface
105
106 inline void evt_next([[maybe_unused]] uint8_t tag) {};
107
108 inline void evt_done() {
109 };
110
111 inline void add_hit(uint16_t col, uint16_t row, uint16_t tot){
112 //Translate the col, row into module coordinates
113 // after that, row and col are phi_index and eta_index, respectively
115
116 //Set dummy values at 0 for these:
117 int bcid = 0;
118 int lvl0a = 0;
119 int lvl0d = 0;
120 if(col >= 400 || row >= 400) {
121 //This check is needed because the decoder can call add_hit with invalid col and row to signal an error
122 m_msg_source << MSG::WARNING << "Decoded hit with col and row >= 400, skipping. col=" << col << " row=" << row << endmsg;
123 }
126 std::array<std::int16_t,2>{static_cast<std::int16_t>(row), static_cast<std::int16_t>(col)},
127 PhaseII::PixelRawDataContainer::makeWord( tot, bcid, lvl0a, lvl0d ));
128 };
129
130 inline void add_hmap([[maybe_unused]] uint8_t qcol,
131 [[maybe_unused]] uint8_t qrow,
132 [[maybe_unused]] uint16_t hmap,
133 [[maybe_unused]] uint64_t tots)
134 {};
135
136 inline void add_qcore([[maybe_unused]] uint8_t qcol,
137 [[maybe_unused]] uint8_t qrow,
138 [[maybe_unused]] uint64_t qtot)
139 {};
140
141 inline uint8_t on_error([[maybe_unused]] itksw::pix::endec::intf::EventError error) {return 0;};
142 //end of interface-mandated methods
143
144 inline void registerLastModule() {
145 if (!m_dest_range_guard.empty()) {
146 // register the RDO range for this module, or erase the newly added
147 if (!m_cont_coll->registerOrEraseNewData(m_currentIdentifierHash,m_dest_range_guard.range())) {
149 }
150 // in the process of adding hits to the original container, its capacity may have
151 // been exceeded and the container may have been changed for the current module. To
152 // ensure that the same container is used for the next module get the container, that
153 // contains the hits for the current module from the the range_guard.
155 m_n_rdos += m_dest_range_guard.range().size();
156 }
157 }
158
159 //this is needed to properly identify the module.
160 inline void setOfflineID(const uint32_t& offlineID){
161 m_offlineID = offlineID;
162 };
163
164 //this is needed to properly translate hits on a quad
165 inline void setChipID(const uint8_t& chipID){
166 m_chipID = chipID;
167 }
168
169 //translate
171 m_transform = transform;
172 }
173
174
175 private:
176
177 // the RDO (=hits) container
179
180 // the collection of RDO containers
182
183 // RDO container range guard
185
186 // current offline ID hash
187 unsigned int m_currentIdentifierHash{std::numeric_limits<unsigned int>::max()};
188
189 // statistics
190 unsigned int m_n_rejected_work{};
191
192 // module offline ID as defined in InnerDetector/InDetDetDescr/InDetIdentifier/InDetIdentifier/PixelID.h
193 uint32_t m_offlineID = 0;
194
195 // front-end chip ID, from 0 to 4 for merged quads, 0 otherwise
196 uint8_t m_chipID = 0;
197
198 // RDO counter
199 uint32_t m_n_rdos = 0;
200
201 //offline identifier
203
204 //transform type for cabling package
206
207 // Identifier helper
209
210 // Athena message stream for debug output
211 MsgStream& m_msg_source;
212 };
213
214 //This prints the decoded hits on the screen,
215 //useful for testing purposes
217 public:
218 TestEventCallback(MsgStream& src): m_msg_source(src) {};
220
221 inline void evt_init(uint8_t tag) {
222 m_msg_source << MSG::DEBUG << "evt_init(" << tag << ")" << std::endl;
223 }
224
225 inline void evt_next(uint8_t tag) {
226 m_msg_source << MSG::DEBUG << "evt_next(" << tag << ")" << std::endl;
227 }
228
229 inline void evt_done() {
230 m_msg_source << MSG::DEBUG << "evt_done()" << std::endl;
231 }
232
233 inline void add_hit(uint16_t col, uint16_t row, uint16_t tot) {
234 m_msg_source << MSG::DEBUG << "add_hit(" << col << "," << row << "," << tot << ")" << std::endl;
235 }
236
237 inline void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots) {
238 m_msg_source << MSG::DEBUG << "add_hmap(qcol=" << qcol << ",qrow=" << qrow
239 << ",hmap=" << hmap << ",tots=" << tots << ")" << std::endl;
240 }
241
242 inline void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot) {
243 m_msg_source << MSG::DEBUG << "add_qcore(qcol=" << qcol << ",qrow=" << qrow
244 << ",qtot=" << qtot << ")" << std::endl;
245 }
246
247 inline uint8_t on_error(itksw::pix::endec::intf::EventError error) {
248 m_msg_source << MSG::DEBUG << "on_error(" << error.code << ")" << std::endl;
249 return 0;
250 }
251
252 MsgStream& m_msg_source;
253
254 };
255}
256
257
258#endif
259
#define endmsg
PhaseII::IndexedRangesMT< PhaseII::PixelRawDataContainer > PhaseIIPixelRawDataContainerMT
A container derived from PhaseIIPixelRawDataContainer which extends the container by a dynamic contai...
This is an Identifier helper class for the Pixel subdetector.
Property holding a SG store/key/clid from which a ReadHandle is made.
An algorithm that can be simultaneously executed in multiple threads.
ServiceHandle< IROBDataProviderSvc > m_robDataProviderSvc
SG::WriteHandleKey< PhaseIIPixelRawDataContainer > m_pixelRDOKey
SG::ReadCondHandleKey< ITkPixelCablingData > m_pixelCablingKey
std::vector< std::vector< uint32_t > > ITkPacketCollection
virtual StatusCode execute(const EventContext &ctx) const override
const Gaudi::Property< uint32_t > m_n_rdos_est
ITkPixelDecodingPhaseIIRDOAlg(const std::string &name, ISvcLocator *pSvcLocator)
Helper class to keep track of a range of elements added to the end of a container.
typename DynamicContainerListHelper< PhaseII::PixelRawDataContainer >::ContainerPtr ContainerPtr
static std::uint32_t makeWord(int tot, int bcid, int lvl1a, int lvl1d)
uint8_t on_error(itksw::pix::endec::intf::EventError error)
void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots)
PhaseIIRDOCallback(PhaseIIPixelRawDataContainerMT *cont_coll, PhaseIIPixelRawDataContainerMT::ContainerPtr rdo_container_dest, const PixelID *idHelper, MsgStream &msg_source)
void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot)
PhaseIIPixelRawDataContainerMT::ContainerPtr m_rdo_container_dest
void setTransformType(const ITkPixelCabling::TransformType &transform)
void add_hit(uint16_t col, uint16_t row, uint16_t tot)
PhaseII::ContainerRangeGuard< PhaseII::DataRange, PhaseIIPixelRawDataContainerMT::ContainerPtr > m_dest_range_guard
void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots)
void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot)
void add_hit(uint16_t col, uint16_t row, uint16_t tot)
uint8_t on_error(itksw::pix::endec::intf::EventError error)
This is an Identifier helper class for the Pixel subdetector.
Definition PixelID.h:69
Property holding a SG store/key/clid from which a WriteHandle is made.
static void chipToModuleTransform(const TransformType &transform, const uint8_t &chipID, uint16_t &col, uint16_t &row)
void addDataForModule(T_RawDataContainerCollection &rdo_container_collection, ContainerRangeGuard< T_RawDataContainerPtr, T_RangeType > &range_guard, T_Coordinates &&coordinates, std::uint32_t data_word)
convenience method to add data to an RDO container, add a new RDO container, copy the data added for ...
STL namespace.
std::chrono::time_point< std::chrono::high_resolution_clock > m_start