ATLAS Offline Software
Loading...
Searching...
No Matches
ITkPixelCablingData.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4#ifndef ITkPixelCablingData_h
5#define ITkPixelCablingData_h
12
14
15// Athena includes
16#include "Identifier/Identifier.h"
19
20//STL
21#include <unordered_map>
22#include <iosfwd>
23
24namespace ITkPixelCabling {
25
26 //types of modules we have
34
35 //types of coordinate transformations
36 //kept separate from the chip types
37 //in case per-module specifics are
38 //needed
45
46 //We need to know what module type
47 //we're dealing with from the readout
48 //PoV, so that we can translate accordingly.
49 template <class ID>
55
56 //Update to a realistic ROB structure that has ROBs
57 //identified with sourceID (32b) and holds data from
58 //multiple 'elinks' (front-ends, to all practicality)
59 //in the payload, each data block prepended by
60 //'DetectorResourceID'.
61
62 //For **encoding**
63 //1. we read in an RDO that contains offline ID only
64 //2. that RDO also gives us chipID based on where in
65 // the module the row, col are
66 //3. from that we can build (offline ID) << 2 | chipID,
67 // which gives us (almost) the entire DetectorResourceID
68 //4. the online part of the DetectorResourceID has to come from cabling
69 //5. What we need for encoding is therefore Offline part of
70 // DetectorResourceID -> {online part, sourceID} mapping. That way we
71 // can fill in a map of <(sourceID << 32 | DetectorResourceID), HitMap>
72 // and encode and place it in the ROB fragments accordingly with no further
73 // need for cabling.
74 //
75 // We will use ITkPixelOnlineId to store sourceID | DetectorResourceId in
76 // 64b.
77
78 //define transforms, assuming
79 // Y | 2 | 3 |
80 // | 0 | 1 |
81 // X
82 //to be confirmed and revisited
83
84 using TransformFn = void(*)(uint16_t&, uint16_t&);
85
86 //LUT for quad translation functions indexed by chip ID
87 //The RD53C/ITkPixV2 chip dimensions are 400 columns, 384 rows,
88 //indexing starts at 0, hence the possible values of col in [0, 399]
89 //and row in [0, 383]. A quad is 2x2 chips, hence the total dimensions
90 //of 800 columns and 768 rows, again indexed from 0, i. e. col in [0, 799]
91 //and row in [0, 767].
92 static constexpr TransformFn nominalQuadTable[4] = {
93 []([[maybe_unused]] uint16_t& col, uint16_t& row){row = 383 - row;},
94 []([[maybe_unused]] uint16_t& col, uint16_t& row){row = 383 - row; col += 400;},
95 []([[maybe_unused]] uint16_t& col, uint16_t& row){row = 767 - row;},
96 []([[maybe_unused]] uint16_t& col, uint16_t& row){row = 767 - row; col += 400;}
97 };
98
99 static constexpr TransformFn ibTransformFn =
100 [](uint16_t& col, uint16_t& row){
101 row = 2 * (383 - row) + (col & 1);
102 col >>= 1;
103 };
104
105 static constexpr TransformFn iecTransformFn =
106 [](uint16_t& col, uint16_t& row) {
107 std::swap(col, row);
108 };
109
110 static constexpr TransformFn nominalQuadInverseTable[4] = {
111 []([[maybe_unused]] uint16_t& col, uint16_t& row){row = 383 - row;},
112 []([[maybe_unused]] uint16_t& col, uint16_t& row){row = 383 - row; col -= 400;},
113 []([[maybe_unused]] uint16_t& col, uint16_t& row){row = 767 - row;},
114 []([[maybe_unused]] uint16_t& col, uint16_t& row){row = 767 - row; col -= 400;}
115 };
116
118 [](uint16_t& col, uint16_t& row) {
119 const uint16_t parity = row & 1;
120 row = 383 - (row >> 1);
121 col = (col << 1) | parity;
122 };
123
125 [](uint16_t& col, uint16_t& row) {
126 std::swap(col, row);
127 };
128
129
130 static inline void chipToModuleTransform(const TransformType& transform, const uint8_t& chipID, uint16_t& col, uint16_t& row){
131 switch (transform){
133 nominalQuadTable[chipID](col, row);
134 break;
136 ibTransformFn(col, row);
137 break;
139 iecTransformFn(col, row);
140 break;
142 break;
143 }
144 }
145
146 static inline void chipToModuleInverseTransform(const TransformType& transform, const uint8_t& chipID, uint16_t& col, uint16_t& row){
147 switch (transform){
149 nominalQuadInverseTable[chipID](col, row);
150 break;
152 ibInverseTransformFn(col, row);
153 break;
155 iecInverseTransformFn(col, row);
156 break;
158 break;
159 }
160 }
161
162}
163
165public:
167 friend std::istream& operator>>(std::istream & is, ITkPixelCablingData & cabling);
169 friend std::ostream& operator<<(std::ostream & os, const ITkPixelCablingData & cabling);
170 bool empty() const;
171 std::size_t size() const;
172 ITkPixelOnlineId onlineId(const Identifier & id) const;
174
177
178 //Updating to a realistic ROB structure
179 ITkPixelOnlineId onlineId(const uint32_t& offlineDetectorResourceID) const;
180 const std::unordered_map<uint32_t, ITkPixelOnlineId>& onlineIdMap() const {return m_offlineDetectorResourceID2OnlineIdMap;}
181 const std::vector<uint32_t>& sourceIDs() const {return m_sourceIDs;}
182 ITkPixelCabling::TransformType transformType(const uint32_t& moduleID) const;
183 template<typename Func> void forEachOffOn(Func&& f) const {
184 for (const auto& [key, val] : m_offlineDetectorResourceID2OnlineIdMap){
185 f(key, val);
186 }
187 }
188
189 // chip ID number from 0 to 3
190 static uint8_t chipID(const ITkPixelCabling::TransformType& t, const uint16_t& col, const uint16_t& row) ;
191
192 //Add entry to the offline->online map. This is only for producing test streams,
193 //from MC, and needs to propagate the type of the module. We also can at most map
194 //with 4-fold degeneracy due to non-merged quads, which have 4 online IDs mapped to
195 //a single offline ID.
196 void addEntryOffOn(const Identifier& idOff, const ITkPixelOnlineId& idOn);
197 void addEntryOffOn(const Identifier& idOff, const ITkPixelCabling::ModuleInfo<ITkPixelOnlineId>& moduleInfo);
198
199 //Updating to a realistic ROB structure, working with the detectorResourceIDs
200 //a la Data Handler, mapping the 'offline part' of the detectorResourceID (module ID << 2 | chipID)
201 //to the full detectorResourceId and sourceID (a. k. a. ROB ID)
202 void addEntryOffOn(const uint32_t& offlineDetectorResourceID, const ITkPixelOnlineId& onlineId);
203
204 void addSourceID(const uint32_t& sourceID);
205
206 void addTransformType(const uint32_t& moduleID, const ITkPixelCabling::TransformType& transform);
207
208 //Add entry to the online->offline map. This is for decoding. For quick access,
209 //these maps can also cache the type of the module, so that we know how to translate
210 //the hit coordinates from chip to module
211 void addEntryOnOff(const ITkPixelOnlineId& idOn, const Identifier& idOff);
213
214 void print() const;
215
216 //Add entries to the
217
218private:
219 //offline->online base map
220 std::unordered_map<Identifier, ITkPixelOnlineId> m_offline2OnlineMap;
221
222 //offline->online base map with info on module type
223 std::unordered_map<Identifier, ITkPixelCabling::ModuleInfo<ITkPixelOnlineId>> m_offline2ModuleInfoMap;
224
225 //simple online->offline map
226 std::unordered_map<ITkPixelOnlineId, Identifier> m_online2OfflineMap;
227
228 //online->offline map with info on module type
229 std::unordered_map<ITkPixelOnlineId, ITkPixelCabling::ModuleInfo<Identifier>> m_online2ModuleInfoMap;
230
231 //online base -> module type
232 std::unordered_map<ITkPixelOnlineId, ITkPixelCabling::ModuleType> m_online2ModuleType;
233
234 //offline -> module type
235 std::unordered_map<Identifier, ITkPixelCabling::ModuleType> m_offline2ModuleType;
236
237 //offline part of DetectorResourceID -> {online part of DetectorResourceID, sourceID}
238 std::unordered_map<uint32_t, ITkPixelOnlineId> m_offlineDetectorResourceID2OnlineIdMap{};
239
240 //list of sourceIDs
241 std::vector<uint32_t> m_sourceIDs{};
242
243 //list of IDs in l0 barrel - needed for decoding
244 std::unordered_map<uint32_t, ITkPixelCabling::TransformType> m_module2TransformTypeMap{};
245
246};
247// Magic "CLassID" for storage/retrieval in StoreGate
248// These values produced using clid script.
249// "clid ITkPixelCablingData"
250// 140860927 ITkPixelCablingData
252//"clid -cs ITkPixelCablingData"
253//143807283
255#endif
Hold mappings of ranges to condition objects.
#define CONDCONT_DEF(...)
Definition CondCont.h:1413
macros to associate a CLID to a type
#define CLASS_DEF(NAME, CID, VERSION)
associate a clid and a version to a type eg
std::vector< uint32_t > m_sourceIDs
const std::unordered_map< uint32_t, ITkPixelOnlineId > & onlineIdMap() const
ITkPixelOnlineId onlineId(const Identifier &id) const
ITkPixelCabling::ModuleInfo< ITkPixelOnlineId > onlineModuleInfo(const Identifier &id) const
Identifier offlineId(const ITkPixelOnlineId &id) const
std::unordered_map< ITkPixelOnlineId, ITkPixelCabling::ModuleInfo< Identifier > > m_online2ModuleInfoMap
std::unordered_map< uint32_t, ITkPixelCabling::TransformType > m_module2TransformTypeMap
std::unordered_map< uint32_t, ITkPixelOnlineId > m_offlineDetectorResourceID2OnlineIdMap
ITkPixelCabling::TransformType transformType(const uint32_t &moduleID) const
static uint8_t chipID(const ITkPixelCabling::TransformType &t, const uint16_t &col, const uint16_t &row)
void addEntryOnOff(const ITkPixelOnlineId &idOn, const Identifier &idOff)
std::size_t size() const
std::unordered_map< Identifier, ITkPixelOnlineId > m_offline2OnlineMap
std::unordered_map< Identifier, ITkPixelCabling::ModuleInfo< ITkPixelOnlineId > > m_offline2ModuleInfoMap
const std::vector< uint32_t > & sourceIDs() const
friend std::ostream & operator<<(std::ostream &os, const ITkPixelCablingData &cabling)
stream insertion for debugging
void forEachOffOn(Func &&f) const
void addTransformType(const uint32_t &moduleID, const ITkPixelCabling::TransformType &transform)
std::unordered_map< Identifier, ITkPixelCabling::ModuleType > m_offline2ModuleType
std::unordered_map< ITkPixelOnlineId, Identifier > m_online2OfflineMap
std::unordered_map< ITkPixelOnlineId, ITkPixelCabling::ModuleType > m_online2ModuleType
ITkPixelCabling::ModuleInfo< Identifier > offlineModuleInfo(const ITkPixelOnlineId &id) const
friend std::istream & operator>>(std::istream &is, ITkPixelCablingData &cabling)
stream extraction to read value from stream into ITkPixelCablingData
void addEntryOffOn(const Identifier &idOff, const ITkPixelOnlineId &idOn)
void addSourceID(const uint32_t &sourceID)
static void chipToModuleInverseTransform(const TransformType &transform, const uint8_t &chipID, uint16_t &col, uint16_t &row)
static constexpr TransformFn nominalQuadTable[4]
static constexpr TransformFn ibTransformFn
static constexpr TransformFn iecTransformFn
static constexpr TransformFn ibInverseTransformFn
static void chipToModuleTransform(const TransformType &transform, const uint8_t &chipID, uint16_t &col, uint16_t &row)
void(*)(uint16_t &, uint16_t &) TransformFn
static constexpr TransformFn iecInverseTransformFn
static constexpr TransformFn nominalQuadInverseTable[4]
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)