12#ifndef ALICEO2_CHIPMAPPINGITS_H
13#define ALICEO2_CHIPMAPPINGITS_H
33#define _OVERRIDE_RUID_HACK_
51 static constexpr std::string_view
getName() {
return "ITS"; }
60 static constexpr int getNRUs() {
return NStavesSB[
IB] + NStavesSB[
MB] + NStavesSB[
OB]; }
63 static constexpr int getNChips() {
return NChipsSB[
IB] + NChipsSB[
MB] + NChipsSB[
OB]; }
75 static constexpr int getNChipsPerLr(
int l) {
return NStavesOnLr[l] * NChipsPerStaveSB[RUTypeLr[l]]; }
78 uint16_t
composeFEEId(uint16_t lr, uint16_t ruOnLr, uint16_t link)
const {
return (lr << 12) + (link << 8) + (ruOnLr); }
81 void expandFEEId(uint16_t feeID, uint16_t& lr, uint16_t& ruOnLr, uint16_t& link)
const
84 ruOnLr = feeID & 0x3f;
85 link = (feeID >> 8) & 0x3;
86#ifdef _OVERRIDE_RUID_HACK_
87 ruOnLr %= NStavesOnLr[lr];
98 feeID |= (0x3 & linkID) << 8;
103 void expandChipInfoSW(
int idSW,
int& lay,
int& sta,
int& ssta,
int& mod,
int& chipInMod)
const;
106 void expandChipInfoHW(
int idSW,
int& lay,
int& sta,
int& ssta,
int& mod,
int& chipInMod)
const;
117 return &mChipsInfo[mChipInfoEntrySB[staveType] + chOnRUSW];
124 if (chipSW > NChipsSB[
IB] + NChipsSB[
MB] - 1) {
125 chipSW -= NChipsSB[
IB] + NChipsSB[
MB];
127 auto dvRU = std::div(chipSW, NChipsPerStaveSB[
OB]);
128 chInfo.
ru = NStavesSB[
IB] + NStavesSB[
MB] + dvRU.quot;
130 }
else if (chipSW > NChipsSB[
IB] - 1) {
131 chipSW -= NChipsSB[
IB];
133 auto dvRU = std::div(chipSW, NChipsPerStaveSB[
MB]);
134 chInfo.
ru = NStavesSB[
IB] + dvRU.quot;
138 auto dvRU = std::div(chipSW, NChipsPerStaveSB[
IB]);
139 chInfo.
ru = dvRU.quot;
148 if (cableHW <= MaxHWCableID[ruInfo.
ruType] && globalID != 0xffff) {
154 for (
int ihw = 0; ihw < 15; ihw++) {
155 if (HWCableHWChip2ChipOnRU_MB[cableHW][ihw] == chipOnRU)
160 for (
int ihw = 0; ihw < 15; ihw++) {
161 if (HWCableHWChip2ChipOnRU_OB[cableHW][ihw] == chipOnRU)
173 const RUInfo& ruInfo)
const
175 if (chOnModuleHW < MaxHWChipIDPerModuleSB[ruInfo.
ruType] &&
176 cableHW <= MaxHWCableID[ruInfo.
ruType]) {
177 uint16_t chipOnRU = 0xff;
180 if (cableHW == chOnModuleHW)
184 chipOnRU = HWCableHWChip2ChipOnRU_MB[cableHW][chOnModuleHW];
187 chipOnRU = HWCableHWChip2ChipOnRU_OB[cableHW][chOnModuleHW];
190 return chipOnRU < 0xff ? ruInfo.
firstChipIDSW + chipOnRU : 0xffff;
199 if (RUTypeLr[lay] != 0) {
200 id += modSW * NChipsPerModuleSB[RUTypeLr[lay]];
208#ifdef _OVERRIDE_RUID_HACK_
209 uint16_t lr, ruOnLr, link;
213 return mFEEId2RUSW[hw];
219 uint16_t feeID = mStavesInfo[
sw].idHW;
236 uint8_t
getGBTHeaderRUType(
int ruType,
int cableHW) {
return GBTHeaderFlagSB[ruType] + (cableHW & 0x1f); }
239 uint8_t
cableHW2Pos(uint8_t ruType, uint8_t hwid)
const {
return mCableHW2Pos[ruType][hwid]; }
242 uint8_t
cableHW2SW(uint8_t ruType, uint8_t hwid)
const {
return hwid < mCableHW2SW[ruType].size() ? mCableHW2SW[ruType][hwid] : 0xff; }
245 uint8_t
cablePos(uint8_t ruType, uint8_t
id)
const {
return mCablePos[ruType][
id]; }
263 if (ruID > NStavesSB[
IB] + NStavesSB[
MB] - 1) {
266 if (ruID > NStavesSB[
IB] - 1) {
275 return ruType ==
IB ? hwIDinMod : ChipOBModHW2SW[hwIDinMod];
281 return ruType ==
IB ? swIDinMod : ChipOBModSW2HW[swIDinMod];
292 sid += NStavesOnLr[
i];
301 if (chipSW < FirstChipsOnLr[
i] + NChipsOnLr[
i]) {
317 static constexpr std::array<uint8_t, NSubB> GBTHeaderFlagSB = {0x1 << 5, 0x1 << 6, 0x1 << 6};
320 static constexpr std::array<int, NSubB> NChipsPerCableSB = {1, 7, 7};
323 static constexpr std::array<int, NSubB> NModulesAlongStaveSB = {1, 4, 7};
326 static constexpr std::array<int, NSubB> NChipsPerModuleSB = {9, 14, 14};
329 static constexpr std::array<int, NSubB> MaxHWChipIDPerModuleSB = {9, 15, 15};
332 static constexpr std::array<int, NSubB> NCablesPerModule = {9, 2, 2};
335 static constexpr std::array<int, NSubB> NModulesPerStaveSB = {1, 8, 14};
338 static constexpr std::array<int, NLayers> NStavesOnLr = {12, 16, 20, 24, 30, 42, 48};
341 static constexpr std::array<int, NLayers> FirstStaveOnLr = {0, 12, 28, 48, 72, 102, 144};
344 static constexpr std::array<int, NLayers> NChipsOnLr = {108, 144, 180, 2688, 3360, 8232, 9408};
347 static constexpr std::array<int, NLayers> FirstChipsOnLr = {0, 108, 252, 432, 3120, 6480, 14712};
350 static constexpr std::array<uint8_t, NLayers> RUTypeLr = {
IB,
IB,
IB,
MB,
MB,
OB,
OB};
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]};
362 static constexpr std::array<int, NSubB> NCablesPerStaveSB = {NCablesPerModule[
IB] * NModulesPerStaveSB[
IB],
363 NCablesPerModule[
MB] * NModulesPerStaveSB[
MB],
364 NCablesPerModule[
OB] * NModulesPerStaveSB[
OB]};
367 static constexpr std::array<int, NSubB> NChipsSB = {NChipsPerStaveSB[
IB] * NStavesSB[
IB],
368 NChipsPerStaveSB[
MB] * NStavesSB[
MB],
369 NChipsPerStaveSB[
OB] * NStavesSB[
OB]};
371 static constexpr int NChips = NChipsSB[
IB] + NChipsSB[
MB] + NChipsSB[
OB];
381 static constexpr std::uint8_t ChipOBModSW2HW[14] = {0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14};
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;
390 std::array<ChipOnRUInfo, NChipsPerStaveSB[IB] + NChipsPerStaveSB[MB] + NChipsPerStaveSB[OB]> mChipsInfo;
391 int mChipInfoEntrySB[
NSubB] = {0};
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];
398 std::array<int, NSubB> mCablesOnStaveSB = {0};
399 std::array<std::array<uint8_t, 15>, MaxHWCableID[
MB] + 1> HWCableHWChip2ChipOnRU_MB;
400 std::array<std::array<uint8_t, 15>, MaxHWCableID[
OB] + 1> HWCableHWChip2ChipOnRU_OB;
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
~ChipMappingITS()=default
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 o2::detectors::DetID::ID getDetID()
int getNChipsOnRUType(int ruType) const
get RU type from the sequential ID of the RU
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
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
constexpr o2::header::DataOrigin gDataOriginITS
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
const ChipOnRUInfo * chOnRU
these public methods must be defined in the mapping class for raw data encoding/decoding
OverlappingRow rowSideOverlap[2]