Project
Loading...
Searching...
No Matches
ChipMappingITS.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef ALICEO2_CHIPMAPPINGITS_H
13#define ALICEO2_CHIPMAPPINGITS_H
14
15// \file ChipMappingITS.h
16// \brief ITS chip <-> module mapping
17
18#include <Rtypes.h>
19#include <array>
20#include <cstdlib>
21#include <cstdint>
22#include <string>
23#include "Headers/DataHeader.h"
26#include "Framework/Logger.h"
27
28namespace o2
29{
30namespace itsmft
31{
32
33#define _OVERRIDE_RUID_HACK_
34
36{
37 public:
38 struct Overlaps {
39 enum OverlappingRow : signed char { NONE = -1,
40 LowRow = 0,
42 NSides = 2 };
43 int16_t rowSide[2] = {NONE, NONE}; // chip overlapping from low/high row side
45 };
46
49 ~ChipMappingITS() = default;
50
51 static constexpr std::string_view getName() { return "ITS"; }
54
55 const std::vector<uint8_t>& getCableHWFirstChip(int s) const { return mCableHWFirstChip[s]; }
56
57 static constexpr std::int16_t getRUDetectorField() { return 0x0; }
58
60 static constexpr int getNRUs() { return NStavesSB[IB] + NStavesSB[MB] + NStavesSB[OB]; }
61
63 static constexpr int getNChips() { return NChipsSB[IB] + NChipsSB[MB] + NChipsSB[OB]; }
64
66 static constexpr int getNChips(int b) { return NChipsSB[b]; }
67
69 static constexpr int getNStavesOnLr(int l) { return NStavesOnLr[l]; }
70
72 static constexpr int getFirstStavesOnLr(int l) { return FirstStaveOnLr[l]; }
73
75 static constexpr int getNChipsPerLr(int l) { return NStavesOnLr[l] * NChipsPerStaveSB[RUTypeLr[l]]; }
76
78 uint16_t composeFEEId(uint16_t lr, uint16_t ruOnLr, uint16_t link) const { return (lr << 12) + (link << 8) + (ruOnLr); }
79
81 void expandFEEId(uint16_t feeID, uint16_t& lr, uint16_t& ruOnLr, uint16_t& link) const
82 {
83 lr = feeID >> 12;
84 ruOnLr = feeID & 0x3f;
85 link = (feeID >> 8) & 0x3;
86#ifdef _OVERRIDE_RUID_HACK_
87 ruOnLr %= NStavesOnLr[lr];
88#endif
89 }
90
92 void imposeFEEId2RUSW(uint16_t feeID, uint16_t ruSW);
93
95 uint16_t modifyLinkInFEEId(uint16_t feeID, uint16_t linkID) const
96 {
97 feeID &= ~(0x3 << 8);
98 feeID |= (0x3 & linkID) << 8;
99 return feeID;
100 }
101
103 void expandChipInfoSW(int idSW, int& lay, int& sta, int& ssta, int& mod, int& chipInMod) const;
104
106 void expandChipInfoHW(int idSW, int& lay, int& sta, int& ssta, int& mod, int& chipInMod) const;
107
109 std::string getChipNameHW(int idSW) const;
110
111 void print() const;
112
115 const ChipOnRUInfo* getChipOnRUInfo(int staveType, int chOnRUSW) const
116 {
117 return &mChipsInfo[mChipInfoEntrySB[staveType] + chOnRUSW];
118 }
119
121 void getChipInfoSW(int chipSW, ChipInfo& chInfo) const
122 {
123 chInfo.id = chipSW;
124 if (chipSW > NChipsSB[IB] + NChipsSB[MB] - 1) { // OB
125 chipSW -= NChipsSB[IB] + NChipsSB[MB];
126 chInfo.ruType = OB;
127 auto dvRU = std::div(chipSW, NChipsPerStaveSB[OB]);
128 chInfo.ru = NStavesSB[IB] + NStavesSB[MB] + dvRU.quot; // RU ID == stave ID
129 chInfo.chOnRU = getChipOnRUInfo(OB, dvRU.rem);
130 } else if (chipSW > NChipsSB[IB] - 1) { // MB
131 chipSW -= NChipsSB[IB];
132 chInfo.ruType = MB;
133 auto dvRU = std::div(chipSW, NChipsPerStaveSB[MB]);
134 chInfo.ru = NStavesSB[IB] + dvRU.quot; // RU ID == stave ID
135 chInfo.chOnRU = getChipOnRUInfo(MB, dvRU.rem);
136 } else { // IB
137 chInfo.ruType = IB;
138 auto dvRU = std::div(chipSW, NChipsPerStaveSB[IB]);
139 chInfo.ru = dvRU.quot; // RU ID == stave ID = module ID
140 chInfo.chOnRU = getChipOnRUInfo(IB, dvRU.rem);
141 }
142 }
143
145 uint16_t getLocalChipID(uint16_t globalID, int cableHW, const RUInfo& ruInfo)
146 const
147 {
148 if (cableHW <= MaxHWCableID[ruInfo.ruType] && globalID != 0xffff) {
149 uint16_t chipOnRU = globalID - ruInfo.firstChipIDSW;
150 switch (ruInfo.ruType) {
151 case IB:
152 return chipOnRU;
153 case MB:
154 for (int ihw = 0; ihw < 15; ihw++) {
155 if (HWCableHWChip2ChipOnRU_MB[cableHW][ihw] == chipOnRU)
156 return ihw;
157 }
158 break;
159 case OB:
160 for (int ihw = 0; ihw < 15; ihw++) {
161 if (HWCableHWChip2ChipOnRU_OB[cableHW][ihw] == chipOnRU)
162 return ihw;
163 }
164 break;
165 }
166 }
167 return 0xffff;
168 }
169
172 uint16_t getGlobalChipID(uint16_t chOnModuleHW, int cableHW,
173 const RUInfo& ruInfo) const
174 {
175 if (chOnModuleHW < MaxHWChipIDPerModuleSB[ruInfo.ruType] &&
176 cableHW <= MaxHWCableID[ruInfo.ruType]) {
177 uint16_t chipOnRU = 0xff;
178 switch (ruInfo.ruType) {
179 case IB:
180 if (cableHW == chOnModuleHW)
181 chipOnRU = cableHW;
182 break;
183 case MB:
184 chipOnRU = HWCableHWChip2ChipOnRU_MB[cableHW][chOnModuleHW];
185 break;
186 case OB:
187 chipOnRU = HWCableHWChip2ChipOnRU_OB[cableHW][chOnModuleHW];
188 break;
189 }
190 return chipOnRU < 0xff ? ruInfo.firstChipIDSW + chipOnRU : 0xffff;
191 }
192 return 0xffff;
193 }
194
196 uint16_t getGlobalChipIDSW(int lay, int staSW, int modSW, int chipInModSW) const
197 {
198 uint16_t id = getFirstChipsOnLayer(lay) + (staSW - getFirstStavesOnLr(lay)) * NChipsPerStaveSB[RUTypeLr[lay]] + chipInModSW;
199 if (RUTypeLr[lay] != 0) {
200 id += modSW * NChipsPerModuleSB[RUTypeLr[lay]];
201 }
202 return id;
203 }
204
206 uint8_t FEEId2RUSW(uint16_t hw) const
207 {
208#ifdef _OVERRIDE_RUID_HACK_
209 uint16_t lr, ruOnLr, link;
210 expandFEEId(hw, lr, ruOnLr, link);
211 hw = composeFEEId(lr, ruOnLr, link);
212#endif
213 return mFEEId2RUSW[hw];
214 }
215
217 uint16_t RUSW2FEEId(uint16_t sw, uint16_t linkID = 0) const
218 {
219 uint16_t feeID = mStavesInfo[sw].idHW; // this is valid for link 0 only
220 return linkID ? modifyLinkInFEEId(feeID, linkID) : feeID;
221 }
222
224 uint16_t RUSW2Layer(uint16_t sw) const { return mStavesInfo[sw].layer; }
225
227 uint16_t RUSW2RUType(uint16_t sw) const { return mStavesInfo[sw].ruType; }
228
230 const RUInfo* getRUInfoSW(int ruSW) const { return &mStavesInfo[ruSW]; }
231
233 const RUInfo* getRUInfoFEEId(int feeID) const { return &mStavesInfo[FEEId2RUSW(feeID)]; }
234
236 uint8_t getGBTHeaderRUType(int ruType, int cableHW) { return GBTHeaderFlagSB[ruType] + (cableHW & 0x1f); }
237
239 uint8_t cableHW2Pos(uint8_t ruType, uint8_t hwid) const { return mCableHW2Pos[ruType][hwid]; }
240
242 uint8_t cableHW2SW(uint8_t ruType, uint8_t hwid) const { return hwid < mCableHW2SW[ruType].size() ? mCableHW2SW[ruType][hwid] : 0xff; }
243
245 uint8_t cablePos(uint8_t ruType, uint8_t id) const { return mCablePos[ruType][id]; }
246
248 int getNChipsPerCable(int ruType) { return NChipsPerCableSB[ruType]; }
249
251 int getNCablesOnRUType(int ruType) const { return NCablesPerStaveSB[ruType]; }
252
254 int getCablesOnRUType(int ruType) const { return mCablesOnStaveSB[ruType]; }
255
257 int getNChipsOnRUType(int ruType) const { return NChipsPerStaveSB[ruType]; }
258
260 int getRUType(int ruID) const
261 {
263 if (ruID > NStavesSB[IB] + NStavesSB[MB] - 1) {
264 return OB;
265 }
266 if (ruID > NStavesSB[IB] - 1) {
267 return MB;
268 }
269 return IB;
270 }
271
273 int chipModuleIDHW2SW(int ruType, int hwIDinMod) const
274 {
275 return ruType == IB ? hwIDinMod : ChipOBModHW2SW[hwIDinMod];
276 }
277
279 int chipModuleIDSW2HW(int ruType, int swIDinMod) const
280 {
281 return ruType == IB ? swIDinMod : ChipOBModSW2HW[swIDinMod];
282 }
283
285 int getRUIDSW(int lr, int ruOnLr) const
286 {
287 int sid = 0;
288 for (int i = 0; i < NLayers; i++) {
289 if (i >= lr) {
290 break;
291 }
292 sid += NStavesOnLr[i];
293 }
294 return sid + ruOnLr;
295 }
296
297 static constexpr int getLayer(int chipSW)
298 {
299 int i = 0;
300 do {
301 if (chipSW < FirstChipsOnLr[i] + NChipsOnLr[i]) {
302 break;
303 }
304 } while (++i < NLayers);
305 return i;
306 }
307 static constexpr int getNModulesPerStave(int ruType) { return NModulesPerStaveSB[ruType]; }
308 static constexpr int getNChipsOnLayer(int lr) { return NChipsOnLr[lr]; }
309 static constexpr int getFirstChipsOnLayer(int lr) { return FirstChipsOnLr[lr]; }
310
311 std::vector<Overlaps> getOverlapsInfo() const;
312
313 // sub-barrel types, their number, N layers, Max N GBT Links per RU
314 static constexpr int IB = 0, MB = 1, OB = 2, NSubB = 3, NLayers = 7, NLinks = 3;
315
316 private:
317 static constexpr std::array<uint8_t, NSubB> GBTHeaderFlagSB = {0x1 << 5, 0x1 << 6, 0x1 << 6}; // prefixes for data GBT header byte
318
320 static constexpr std::array<int, NSubB> NChipsPerCableSB = {1, 7, 7};
321
323 static constexpr std::array<int, NSubB> NModulesAlongStaveSB = {1, 4, 7};
324
326 static constexpr std::array<int, NSubB> NChipsPerModuleSB = {9, 14, 14};
327
329 static constexpr std::array<int, NSubB> MaxHWChipIDPerModuleSB = {9, 15, 15};
330
332 static constexpr std::array<int, NSubB> NCablesPerModule = {9, 2, 2}; // NChipsPerModuleSB[]/NChipsPerCableSB[]
333
335 static constexpr std::array<int, NSubB> NModulesPerStaveSB = {1, 8, 14};
336
338 static constexpr std::array<int, NLayers> NStavesOnLr = {12, 16, 20, 24, 30, 42, 48};
339
341 static constexpr std::array<int, NLayers> FirstStaveOnLr = {0, 12, 28, 48, 72, 102, 144};
342
344 static constexpr std::array<int, NLayers> NChipsOnLr = {108, 144, 180, 2688, 3360, 8232, 9408};
345
347 static constexpr std::array<int, NLayers> FirstChipsOnLr = {0, 108, 252, 432, 3120, 6480, 14712};
348
350 static constexpr std::array<uint8_t, NLayers> RUTypeLr = {IB, IB, IB, MB, MB, OB, OB};
351
353 static constexpr std::array<int, NSubB> NStavesSB = {NStavesOnLr[0] + NStavesOnLr[1] + NStavesOnLr[2],
354 NStavesOnLr[3] + NStavesOnLr[4],
355 NStavesOnLr[5] + NStavesOnLr[6]};
357 static constexpr std::array<int, NSubB> NChipsPerStaveSB = {NModulesPerStaveSB[IB] * NChipsPerModuleSB[IB],
358 NModulesPerStaveSB[MB] * NChipsPerModuleSB[MB],
359 NModulesPerStaveSB[OB] * NChipsPerModuleSB[OB]};
360
362 static constexpr std::array<int, NSubB> NCablesPerStaveSB = {NCablesPerModule[IB] * NModulesPerStaveSB[IB],
363 NCablesPerModule[MB] * NModulesPerStaveSB[MB],
364 NCablesPerModule[OB] * NModulesPerStaveSB[OB]};
365
367 static constexpr std::array<int, NSubB> NChipsSB = {NChipsPerStaveSB[IB] * NStavesSB[IB],
368 NChipsPerStaveSB[MB] * NStavesSB[MB],
369 NChipsPerStaveSB[OB] * NStavesSB[OB]};
370
371 static constexpr int NChips = NChipsSB[IB] + NChipsSB[MB] + NChipsSB[OB];
372
374 /*
375 SW/HW correspondence
376 13/14|12/13|11/12|10/11| 9/10| 8/ 9| 7/ 8
377 ----- ----- ----- ----- ----- ----- -----
378 0/ 0| 1/ 1| 2/ 2| 3/ 3| 4/ 4| 5/ 5| 6/ 6
379 */
380 // SW ID -> HW ID within the module
381 static constexpr std::uint8_t ChipOBModSW2HW[14] = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14};
382 // HW ID -> SW ID within the module
383 static constexpr std::uint8_t ChipOBModHW2SW[15] = {0, 1, 2, 3, 4, 5, 6, 255, 7, 8, 9, 10, 11, 12, 13};
384 static constexpr std::array<int, NSubB> MaxHWCableID = {8, 27, 30};
386 std::array<RUInfo, NStavesSB[IB] + NStavesSB[MB] + NStavesSB[OB]> mStavesInfo;
387 std::vector<uint8_t> mFEEId2RUSW; // HW RU ID -> SW ID conversion
388
389 // info on chips info within the stave
390 std::array<ChipOnRUInfo, NChipsPerStaveSB[IB] + NChipsPerStaveSB[MB] + NChipsPerStaveSB[OB]> mChipsInfo;
391 int mChipInfoEntrySB[NSubB] = {0};
392
393 std::vector<uint8_t> mCableHW2SW[NSubB];
394 std::vector<uint8_t> mCableHW2Pos[NSubB];
395 std::vector<uint8_t> mCablePos[NSubB];
396 std::vector<uint8_t> mCableHWFirstChip[NSubB];
397
398 std::array<int, NSubB> mCablesOnStaveSB = {0};
399 std::array<std::array<uint8_t, 15>, MaxHWCableID[MB] + 1> HWCableHWChip2ChipOnRU_MB; // mapping from HW cable ID / HW chip ID to Chip on RU, 255 means NA
400 std::array<std::array<uint8_t, 15>, MaxHWCableID[OB] + 1> HWCableHWChip2ChipOnRU_OB; // mapping from HW cable ID / HW chip ID to Chip on RU, 255 means NA
401
402 ClassDefNV(ChipMappingITS, 1);
403};
404} // namespace itsmft
405} // namespace o2
406
407#endif
int32_t i
static constexpr ID ITS
Definition DetID.h:63
static constexpr int getNChips(int b)
number of staves on layer
void expandChipInfoSW(int idSW, int &lay, int &sta, int &ssta, int &mod, int &chipInMod) const
expand SW chip ID to HW id's for layer, stave, substave, module, chipOnModule
int getNChipsPerCable(int ruType)
get number cables on the RU served by a given RU type
int chipModuleIDSW2HW(int ruType, int swIDinMod) const
convert layer ID and RU sequential ID on Layer to absolute RU IDSW
uint16_t getGlobalChipIDSW(int lay, int staSW, int modSW, int chipInModSW) const
get SW id of the RU from RU HW id
int getCablesOnRUType(int ruType) const
get number of chips served by RU of given type (i.e. RU type for ITS)
static constexpr int MB
static constexpr o2::detectors::DetID::ID getDetID()
int getNChipsOnRUType(int ruType) const
get RU type from the sequential ID of the RU
static constexpr int IB
static constexpr int getNChipsPerLr(int l)
compose FEEid for given stave (ru) relative to layer and link, see documentation in the constructor
static constexpr int getNChips()
number of chips per barrel
static constexpr int getFirstStavesOnLr(int l)
numbes of chips per layer
static constexpr int getNModulesPerStave(int ruType)
const ChipOnRUInfo * getChipOnRUInfo(int staveType, int chOnRUSW) const
extract information about the chip with SW ID
const RUInfo * getRUInfoFEEId(int feeID) const
get number of chips served by single cable on given RU type
const std::vector< uint8_t > & getCableHWFirstChip(int s) const
uint16_t RUSW2FEEId(uint16_t sw, uint16_t linkID=0) const
get layer of the RU (from the software id of the RU)
static constexpr int NSubB
std::vector< Overlaps > getOverlapsInfo() const
static constexpr int getLayer(int chipSW)
int chipModuleIDHW2SW(int ruType, int hwIDinMod) const
convert SW id of chip in the module to HW ID
int getNCablesOnRUType(int ruType) const
get pattern of lanes on the RU served by a given RU type
uint8_t cablePos(uint8_t ruType, uint8_t id) const
get number of chips served by single cable on given RU type
uint8_t FEEId2RUSW(uint16_t hw) const
get FEEId of the RU (software id of the RU), read via given link
static constexpr int getNChipsOnLayer(int lr)
static constexpr int getNRUs()
total number of chips
void expandChipInfoHW(int idSW, int &lay, int &sta, int &ssta, int &mod, int &chipInMod) const
convert global SW chip ID to name in HW conventions
uint16_t RUSW2RUType(uint16_t sw) const
get info on sw RU
static constexpr int OB
uint8_t getGBTHeaderRUType(int ruType, int cableHW)
convert HW cable ID to its position on the ActiveLanes word in the GBT.header for given RU type
int getRUType(int ruID) const
convert HW id of chip in the module to SW ID (sequential ID on the module)
void expandFEEId(uint16_t feeID, uint16_t &lr, uint16_t &ruOnLr, uint16_t &link) const
impose user defined FEEId -> ruSW (staveID) conversion, to be used only for forced decoding of corrup...
uint16_t getLocalChipID(uint16_t globalID, int cableHW, const RUInfo &ruInfo) const
uint16_t RUSW2Layer(uint16_t sw) const
get layer of the RU (from the software id of the RU)
void getChipInfoSW(int chipSW, ChipInfo &chInfo) const
get chipID on module from chip global SW ID, cable SW ID and stave (RU) info
int getRUIDSW(int lr, int ruOnLr) const
uint8_t cableHW2SW(uint8_t ruType, uint8_t hwid) const
convert cable iterator ID to the position on the ActiveLanes word in the GBT.header for given RU type...
static constexpr int NLinks
uint16_t composeFEEId(uint16_t lr, uint16_t ruOnLr, uint16_t link) const
decompose FEEid to layer, stave (ru) relative to layer, link, see documentation in the constructor
static constexpr int NLayers
std::string getChipNameHW(int idSW) const
impose user defined FEEId -> ruSW (staveID) conversion, to be used only for forced decoding of corrup...
static constexpr std::string_view getName()
uint16_t modifyLinkInFEEId(uint16_t feeID, uint16_t linkID) const
expand SW chip ID to SW (continuous) id's for layer, stave, substave etc.
static constexpr std::int16_t getRUDetectorField()
total number of RUs
void imposeFEEId2RUSW(uint16_t feeID, uint16_t ruSW)
modify linkID field in FEEId
const RUInfo * getRUInfoSW(int ruSW) const
get info on sw RU
static constexpr int getNStavesOnLr(int l)
first staves of layer
uint8_t cableHW2Pos(uint8_t ruType, uint8_t hwid) const
convert HW cable ID to SW ID for given RU type (see ChipOnRUInfo.cableSW explanation)
static constexpr int getFirstChipsOnLayer(int lr)
static constexpr o2::header::DataOrigin getOrigin()
uint16_t getGlobalChipID(uint16_t chOnModuleHW, int cableHW, const RUInfo &ruInfo) const
get chip global SW ID from Layer, abs Stave, module in Stave and chipID_on_module SW IDs
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint id
Definition glcorearb.h:650
constexpr o2::header::DataOrigin gDataOriginITS
Definition DataHeader.h:570
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::uint16_t id
Definition RUInfo.h:62
const ChipOnRUInfo * chOnRU
Definition RUInfo.h:59
std::uint16_t ru
Definition RUInfo.h:63
std::uint16_t ruType
Definition RUInfo.h:64
these public methods must be defined in the mapping class for raw data encoding/decoding
uint16_t firstChipIDSW
Definition RUInfo.h:33
uint8_t ruType
Definition RUInfo.h:35
TStopwatch sw