ATLAS Offline Software
ITkPixelDecodingAlg.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef ITKPIXEL_DECODINGALG_H
6 #define ITKPIXEL_DECODINGALG_H
7 
10 #include "GaudiKernel/MsgStream.h"
14 #include "Identifier/Identifier.h"
18 #include "itksw/pix/endec/DecCore.hpp"
19 #include <chrono>
20 
21 
22 using namespace itksw::pix::endec;
23 
24 //class PixelID;
25 
27 {
28  public:
29 
30  ITkPixelDecodingAlg(const std::string &name, ISvcLocator *pSvcLocator);
31 
32  virtual StatusCode initialize() override;
33 
34  virtual StatusCode execute (const EventContext& ctx) const override;
35 
36  virtual StatusCode finalize() override;
37 
38 
39  private:
40 
41  typedef std::vector< std::vector<uint32_t >> ITkPacketCollection;
42 
43  ServiceHandle<IROBDataProviderSvc> m_robDataProviderSvc{ this, "ROBDataProvider", "ROBDataProviderSvc" };
44 
45  SG::ReadCondHandleKey<ITkPixelCablingData> m_pixelCablingKey{this, "PixelCablingKey", "ITkPixelCablingData", "Cond Key of Pixel Cabling"};
46 
47  SG::WriteHandleKey<PixelRDO_Container> m_pixelRDOKey{this, "pixelRDOKey", "PixelRDOs", "StoreGate Key of Pixel RDOs"};
48 
49  std::vector<uint32_t> m_sourceIDs;
50 
51  const PixelID* m_idHelper{};
52 
53 };
54 
55 namespace ITkPixelDecoding{
56  struct ScopedTimer {
57  std::string m_label;
58  std::chrono::time_point<std::chrono::high_resolution_clock> m_start;
59  MsgStream& m_msg_source;
60 
61  ScopedTimer(std::string lbl, MsgStream& src) : m_label(std::move(lbl)), m_start(std::chrono::high_resolution_clock::now()), m_msg_source(src) {}
64  auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(end - m_start).count();
65  m_msg_source << MSG::DEBUG << m_label << " took " << ms << " ms" << endmsg;
66  }
67 
68  };
69 }
70 
71 namespace PixelCallbacks{
72  //Forms pixel RDOs from the decoded hits & fills them into a container
73  class RDOCallback {
74 
75  public:
76  explicit RDOCallback(PixelRDO_Container* rdoContainer, const PixelID* idHelper) :
77  m_rdoContainer(rdoContainer),
78  m_idHelper(idHelper)
79  {};
80 
81  ~RDOCallback() = default;
82 
83  //non-negotiable concepts
84  inline void evt_init([[maybe_unused]] uint8_t tag) {
85  m_identifier = Identifier(m_offlineID);
86  const auto waferHash = m_idHelper->wafer_hash(m_identifier);
87  if (m_rdoContainer->indexFind(waferHash) == m_rdoContainer->end()){
88  m_rdoCollection = std::make_unique<PixelRDO_Collection>(waferHash);
89  m_rdoCollection->reserve(1000);
90  }
91  else {
92  m_rdoCollection.reset(m_rdoContainer->removeCollection(waferHash));
93  }
94 
95  };
96 
97  inline void evt_next([[maybe_unused]] uint8_t tag) {};
98 
99  inline void evt_done() {
100  m_rdoContainer->addCollection(m_rdoCollection.release(), m_idHelper->wafer_hash(m_identifier)).ignore();
101  };
102 
103  inline void add_hit(uint16_t col, uint16_t row, uint16_t tot){
104  //Translate the col, row into module coordinates
105  ITkPixelCabling::chipToModuleTransform(m_transform, m_chipID, col, row);
106  m_rdoCollection->emplace_back(new Pixel1RawData(m_idHelper->pixel_id(m_identifier, row, col), tot, 0, 0, 0));
107  };
108 
109  inline void add_hmap([[maybe_unused]] uint8_t qcol, [[maybe_unused]] uint8_t qrow, [[maybe_unused]] uint16_t hmap, [[maybe_unused]] uint64_t tots) {};
110 
111  inline void add_qcore([[maybe_unused]] uint8_t qcol, [[maybe_unused]] uint8_t qrow, [[maybe_unused]] uint64_t qtot) {};
112 
113  inline uint8_t on_error([[maybe_unused]] itksw::pix::endec::intf::EventError error) {return 0;};
114  //end of non-negotiable concepts
115 
116  //extra members
117 
118  //this is needed to properly identify the module.
119  inline void setOfflineID(const uint32_t& offlineID){
120  m_offlineID = offlineID;
121  };
122 
123  //this is needed to properly translate hits on a quad
124  inline void setChipID(const uint8_t& chipID){
125  m_chipID = chipID;
126  }
127 
128  //translate
130  m_transform = transform;
131  }
132 
133  private:
135  uint32_t m_offlineID = 0;
136  uint8_t m_chipID = 0;
139  std::unique_ptr<PixelRDO_Collection> m_rdoCollection;
141  };
142 
143  //This prints the decoded hits on the screen,
144  //useful for testing purposes
146  public:
147  TestEventCallback(MsgStream& src): m_msg_source(src) {};
148  ~TestEventCallback() = default;
149 
150  inline void evt_init(uint8_t tag) {
151  m_msg_source << MSG::DEBUG << "evt_init(" << tag << ")" << std::endl;
152  }
153 
154  inline void evt_next(uint8_t tag) {
155  m_msg_source << MSG::DEBUG << "evt_next(" << tag << ")" << std::endl;
156  }
157 
158  inline void evt_done() {
159  m_msg_source << MSG::DEBUG << "evt_done()" << std::endl;
160  }
161 
162  inline void add_hit(uint16_t col, uint16_t row, uint16_t tot) {
163  m_msg_source << MSG::DEBUG << "add_hit(" << col << "," << row << "," << tot << ")" << std::endl;
164  }
165 
166  inline void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots) {
167  m_msg_source << MSG::DEBUG << "add_hmap(qcol=" << qcol << ",qrow=" << qrow
168  << ",hmap=" << hmap << ",tots=" << tots << ")" << std::endl;
169  }
170 
171  inline void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot) {
172  m_msg_source << MSG::DEBUG << "add_qcore(qcol=" << qcol << ",qrow=" << qrow
173  << ",qtot=" << qtot << ")" << std::endl;
174  }
175 
176  inline uint8_t on_error(itksw::pix::endec::intf::EventError error) {
177  m_msg_source << MSG::DEBUG << "on_error(" << error.code << ")" << std::endl;
178  return 0;
179  }
180 
181  MsgStream& m_msg_source;
182 
183  };
184 }
185 
186 
187 #endif
188 
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
PixelID.h
This is an Identifier helper class for the Pixel subdetector. This class is a factory for creating co...
PixelCallbacks::RDOCallback::m_idHelper
const PixelID * m_idHelper
Definition: ITkPixelDecodingAlg.h:140
PixelCallbacks::RDOCallback::m_transform
ITkPixelCabling::TransformType m_transform
Definition: ITkPixelDecodingAlg.h:138
PixelCallbacks::RDOCallback::evt_done
void evt_done()
Definition: ITkPixelDecodingAlg.h:99
PixelCallbacks::RDOCallback::m_rdoCollection
std::unique_ptr< PixelRDO_Collection > m_rdoCollection
Definition: ITkPixelDecodingAlg.h:139
ITkPixelDecodingAlg::m_sourceIDs
std::vector< uint32_t > m_sourceIDs
Definition: ITkPixelDecodingAlg.h:49
python.tests.PyTestsLib.finalize
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
Definition: PyTestsLib.py:50
ITkPixelDecoding::ScopedTimer::~ScopedTimer
~ScopedTimer()
Definition: ITkPixelDecodingAlg.h:62
ITkPixelDecoding::ScopedTimer::m_msg_source
MsgStream & m_msg_source
Definition: ITkPixelDecodingAlg.h:59
ITkPixelCablingData.h
PixelCallbacks::RDOCallback::on_error
uint8_t on_error([[maybe_unused]] itksw::pix::endec::intf::EventError error)
Definition: ITkPixelDecodingAlg.h:113
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:558
PixelCallbacks::RDOCallback::setChipID
void setChipID(const uint8_t &chipID)
Definition: ITkPixelDecodingAlg.h:124
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
PixelCallbacks::TestEventCallback::evt_done
void evt_done()
Definition: ITkPixelDecodingAlg.h:158
WriteCellNoiseToCool.src
src
Definition: WriteCellNoiseToCool.py:513
initialize
void initialize()
Definition: run_EoverP.cxx:894
PixelCallbacks::RDOCallback::add_hmap
void add_hmap([[maybe_unused]] uint8_t qcol, [[maybe_unused]] uint8_t qrow, [[maybe_unused]] uint16_t hmap, [[maybe_unused]] uint64_t tots)
Definition: ITkPixelDecodingAlg.h:109
ITkPixelDecoding
Definition: ITkPixelDecodingAlg.h:55
PixelCallbacks::TestEventCallback::add_hit
void add_hit(uint16_t col, uint16_t row, uint16_t tot)
Definition: ITkPixelDecodingAlg.h:162
PixelCallbacks::TestEventCallback::on_error
uint8_t on_error(itksw::pix::endec::intf::EventError error)
Definition: ITkPixelDecodingAlg.h:176
keylayer_zslicemap.row
row
Definition: keylayer_zslicemap.py:155
InDetRawDataContainer
Definition: InDetRawDataContainer.h:27
PixelCallbacks::TestEventCallback::evt_init
void evt_init(uint8_t tag)
Definition: ITkPixelDecodingAlg.h:150
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:92
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
PixelCallbacks::RDOCallback::RDOCallback
RDOCallback(PixelRDO_Container *rdoContainer, const PixelID *idHelper)
Definition: ITkPixelDecodingAlg.h:76
PixelCallbacks::TestEventCallback::~TestEventCallback
~TestEventCallback()=default
PixelCallbacks
Definition: ITkPixelDecodingAlg.h:71
python.handimod.now
now
Definition: handimod.py:674
SG::WriteHandleKey< PixelRDO_Container >
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
PixelRDO_Collection.h
PixelCallbacks::TestEventCallback::TestEventCallback
TestEventCallback(MsgStream &src)
Definition: ITkPixelDecodingAlg.h:147
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
Pixel1RawData
Definition: Pixel1RawData.h:23
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
ITkPixelDecodingAlg::ITkPacketCollection
std::vector< std::vector< uint32_t > > ITkPacketCollection
Definition: ITkPixelDecodingAlg.h:41
PixelCallbacks::RDOCallback::evt_init
void evt_init([[maybe_unused]] uint8_t tag)
Definition: ITkPixelDecodingAlg.h:84
m_start
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
Definition: ColumnarPhysliteTest.cxx:65
PixelCallbacks::TestEventCallback::m_msg_source
MsgStream & m_msg_source
Definition: ITkPixelDecodingAlg.h:181
PixelCallbacks::TestEventCallback::add_hmap
void add_hmap(uint8_t qcol, uint8_t qrow, uint16_t hmap, uint64_t tots)
Definition: ITkPixelDecodingAlg.h:166
PixelCallbacks::TestEventCallback::evt_next
void evt_next(uint8_t tag)
Definition: ITkPixelDecodingAlg.h:154
AthReentrantAlgorithm.h
ITkPixelDecoding::ScopedTimer
Definition: ITkPixelDecodingAlg.h:56
PixelCalibrationConfig.tot
tot
Definition: PixelCalibrationConfig.py:28
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
ITkPixelDecoding::ScopedTimer::m_start
std::chrono::time_point< std::chrono::high_resolution_clock > m_start
Definition: ITkPixelDecodingAlg.h:58
PixelRDO_Container.h
SG::ReadCondHandleKey< ITkPixelCablingData >
PixelCallbacks::RDOCallback::evt_next
void evt_next([[maybe_unused]] uint8_t tag)
Definition: ITkPixelDecodingAlg.h:97
ITkPixelDecoding::ScopedTimer::ScopedTimer
ScopedTimer(std::string lbl, MsgStream &src)
Definition: ITkPixelDecodingAlg.h:61
PixelCallbacks::RDOCallback::~RDOCallback
~RDOCallback()=default
PixelCallbacks::RDOCallback
Definition: ITkPixelDecodingAlg.h:73
PixelCallbacks::RDOCallback::m_identifier
Identifier m_identifier
Definition: ITkPixelDecodingAlg.h:137
DEBUG
#define DEBUG
Definition: page_access.h:11
AthMessaging.h
PixelCallbacks::TestEventCallback
Definition: ITkPixelDecodingAlg.h:145
PixelCallbacks::TestEventCallback::add_qcore
void add_qcore(uint8_t qcol, uint8_t qrow, uint64_t qtot)
Definition: ITkPixelDecodingAlg.h:171
PixelCallbacks::RDOCallback::add_hit
void add_hit(uint16_t col, uint16_t row, uint16_t tot)
Definition: ITkPixelDecodingAlg.h:103
ITkPixelCabling::TransformType
TransformType
Definition: ITkPixelCablingData.h:38
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:23
PixelID
Definition: PixelID.h:67
error
Definition: IImpactPoint3dEstimator.h:70
PixelCallbacks::RDOCallback::add_qcore
void add_qcore([[maybe_unused]] uint8_t qcol, [[maybe_unused]] uint8_t qrow, [[maybe_unused]] uint64_t qtot)
Definition: ITkPixelDecodingAlg.h:111
PixelCallbacks::RDOCallback::setTransformType
void setTransformType(const ITkPixelCabling::TransformType &transform)
Definition: ITkPixelDecodingAlg.h:129
IROBDataProviderSvc.h
ITkPixelDecodingAlg
Definition: ITkPixelDecodingAlg.h:27
ITkPixelDecoding::ScopedTimer::m_label
std::string m_label
Definition: ITkPixelDecodingAlg.h:57
PixelCallbacks::RDOCallback::m_rdoContainer
PixelRDO_Container * m_rdoContainer
Definition: ITkPixelDecodingAlg.h:134
ServiceHandle< IROBDataProviderSvc >
python.SystemOfUnits.ms
float ms
Definition: SystemOfUnits.py:148
PixelCallbacks::RDOCallback::setOfflineID
void setOfflineID(const uint32_t &offlineID)
Definition: ITkPixelDecodingAlg.h:119
Identifier
Definition: IdentifierFieldParser.cxx:14