Project
Loading...
Searching...
No Matches
RUDecodeData.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
14#ifndef ALICEO2_ITSMFT_RUDECODEDATA_H_
15#define ALICEO2_ITSMFT_RUDECODEDATA_H_
16
17#include <array>
18#include <memory>
24
25namespace o2
26{
27namespace itsmft
28{
29struct GBTLink;
30
32
33 static constexpr int MaxCablesPerRU = 28; // max number of cables RU can readout
34 static constexpr int MaxChipsPerRU = 196; // max number of chips the RU can readout
35 static constexpr int MaxLinksPerRU = 3; // max number of GBT links per RU
36
37 std::array<PayLoadCont, MaxCablesPerRU> cableData{}; // cable data in compressed ALPIDE format
38 std::vector<o2::itsmft::ChipPixelData> chipsData{}; // fully decoded data in 1st nChipsFired chips
39 std::map<int, ChipPixelData*> seenChips{}; // Map that records chip data by global ID
40 std::vector<uint16_t> seenChipIDsInCable{}; // IDs of chips seen in the current cable
41 std::vector<uint16_t> seenChipIDs{}; // IDs of all chips seen during ROF decoding, including empty ones
42 std::array<int, MaxLinksPerRU> links{}; // link entry RSTODO: consider removing this and using pointer
43 std::array<uint8_t, MaxCablesPerRU> cableHWID{}; // HW ID of cable whose data is in the corresponding slot of cableData
44 std::array<uint8_t, MaxCablesPerRU> cableLinkID{}; // ID of the GBT link transmitting this cable data
45 std::array<GBTLink*, MaxCablesPerRU> cableLinkPtr{}; // Ptr of the GBT link transmitting this cable data
46 std::unordered_map<uint64_t, uint32_t> linkHBFToDump{}; // FEEID<<32+hbfEntry to dump in case of error
47 int ruSWID = -1; // SW (stave) ID
48 int nChipsFired = 0; // number of chips with data or with errors
49 int lastChipChecked = 0; // last chips checked among nChipsFired
50 int nNonEmptyLinks = 0; // number of non-empty links for current ROF
51 int nLinks = 0; // number of links seen for this TF
52 int nLinksDone = 0; // number of links finished for this TF
53 int verbosity = 0; // verbosity level, for -1,0 print only summary data, for 1: print once every error
54 bool ROFRampUpStage = false; // flag that the data come from the ROF rate ramp-up stage
55 GBTCalibData calibData{}; // calibration info from GBT calibration word
56 std::unordered_map<uint32_t, std::pair<uint32_t, uint32_t>> chipErrorsTF{}; // vector of chip decoding errors seen in the given TF
57 std::vector<ErrorMessage> errMsgVecTF; // Specific errors info collected for sending for the whole TF
58
59 const RUInfo* ruInfo = nullptr;
60
62 {
63 memset(&links[0], -1, MaxLinksPerRU * sizeof(int));
64 }
65 void clear();
67 {
68 seenChipIDs.clear();
69 }
70 void setROFInfo(ChipPixelData* chipData, const GBTLink* lnk);
71 template <class Mapping>
72 int decodeROF(const Mapping& mp, const o2::InteractionRecord ir, bool verifyDecoder);
73 void fillChipStatistics(int icab, const ChipPixelData* chipData);
74 void dumpcabledata(int icab);
75 bool checkLinkInSync(int icab, const o2::InteractionRecord ir);
77};
78
81template <class Mapping>
82int RUDecodeData::decodeROF(const Mapping& mp, const o2::InteractionRecord ir, bool verifyDecoder)
83{
84 nChipsFired = 0;
86 int ntot = 0;
87 // poll majority ROF IR to detect desynchronization between the liks
88
89 std::array<bool, Mapping::getNChips()> doneChips{};
90 auto* chipData = &chipsData[0];
91 seenChipIDs.clear();
92 for (int icab = 0; icab < ruInfo->nCables; icab++) { // cableData is ordered in such a way to have chipIDs in increasing order
93 if (!cableData[icab].getSize()) {
94 continue;
95 }
96 if (!checkLinkInSync(icab, ir)) { // apparently there was desynchronization
97 continue;
98 }
99 auto cabHW = cableHWID[icab];
100 auto chIdGetter = [this, &mp, cabHW](int cid) {
101 // return mp.getGlobalChipID(cid, cabHW, *this->ruInfo);
102 auto chip = mp.getGlobalChipID(cid, cabHW, *this->ruInfo);
103 return chip;
104 };
105 auto localChipIdGetter = [this, &mp, cabHW](int gid) {
106 auto localID = mp.getLocalChipID(gid, cabHW, *this->ruInfo);
107 return localID;
108 };
109
110 int ret = 0;
111 // dumpcabledata(icab);
112
113 std::vector<uint16_t>* seenChipIDsPtr = &seenChipIDs;
114 if (verifyDecoder) {
115 seenChipIDsInCable.clear();
116 seenChipIDsPtr = &seenChipIDsInCable;
117 seenChips.clear();
118 }
119 while ((ret = AlpideCoder::decodeChip(*chipData, cableData[icab], *seenChipIDsPtr, chIdGetter)) || chipData->isErrorSet()) { // we register only chips with hits or errors flags set
120 setROFInfo(chipData, cableLinkPtr[icab]);
121 if (verifyDecoder) {
122 auto ID = chipData->getChipID();
123 // Since the errored chips are not recorded, we need to add them
124 // separately
125 if (seenChipIDsInCable.empty() || seenChipIDsInCable.back() != ID) {
126 seenChipIDsInCable.push_back(ID);
127 }
128 seenChips[ID] = chipData;
129 }
130 auto nhits = chipData->getData().size();
131 if (nhits && doneChips[chipData->getChipID()]) {
132 if (chipData->getChipID() == chipsData[nChipsFired - 1].getChipID()) {
133 LOGP(debug, "re-entry into the data of the chip {} after previously detector error", chipData->getChipID());
134 }
135#ifdef ALPIDE_DECODING_STAT
136 else {
137 chipData->setError(ChipStat::InterleavedChipData);
138 }
139#endif
140 ret = -1; // discard decoded data
141 nhits = 0;
142 }
143#ifdef ALPIDE_DECODING_STAT
144 fillChipStatistics(icab, chipData);
145#endif
146 if (nhits && chipData->getChipID() < Mapping::getNChips()) {
147 doneChips[chipData->getChipID()] = true;
148 ntot += nhits;
149 if (++nChipsFired < chipsData.size()) { // fetch next free chip
150 chipData = &chipsData[nChipsFired];
151 } else {
152 break; // last chip decoded
153 }
154 }
155 if (ret < 0) {
156 break; // negative code was returned by decoder: abandon cable data
157 }
158 }
159 if (verifyDecoder) {
161 seenChipIDsInCable, localChipIdGetter,
162 chIdGetter);
163 seenChipIDs.insert(seenChipIDs.end(), seenChipIDsInCable.begin(), seenChipIDsInCable.end());
164 }
165 cableData[icab].clear();
166 }
167 return ntot;
168}
169
170} // namespace itsmft
171} // namespace o2
172
173#endif
class for the ALPIDE data decoding/encoding
Calibration data from GBT data.
Declaration of class for continuos buffer of ALPIDE data.
Transient data classes for single pixel and set of pixels from current chip.
std::ostringstream debug
Checks validity of hardware address (HW) and transform it to digit AbsId index.
static bool verifyDecodedCable(std::map< int, ChipPixelData * > &seenChips, PayLoadCont &buffer, std::vector< uint16_t > &seenChipIDs, LG lidGetter, CG cidGetter)
static int decodeChip(ChipPixelData &chipData, T &buffer, std::vector< uint16_t > &seenChips, CG cidGetter)
decode alpide data for the next non-empty chip from the buffer
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< o2::itsmft::ChipPixelData > chipsData
std::unordered_map< uint64_t, uint32_t > linkHBFToDump
void dumpcabledata(int icab)
std::unordered_map< uint32_t, std::pair< uint32_t, uint32_t > > chipErrorsTF
std::vector< uint16_t > seenChipIDsInCable
void setROFInfo(ChipPixelData *chipData, const GBTLink *lnk)
std::map< int, ChipPixelData * > seenChips
static constexpr int MaxChipsPerRU
std::array< int, MaxLinksPerRU > links
std::array< PayLoadCont, MaxCablesPerRU > cableData
static constexpr int MaxCablesPerRU
static constexpr int MaxLinksPerRU
std::array< uint8_t, MaxCablesPerRU > cableHWID
ClassDefNV(RUDecodeData, 2)
std::array< GBTLink *, MaxCablesPerRU > cableLinkPtr
std::vector< ErrorMessage > errMsgVecTF
bool checkLinkInSync(int icab, const o2::InteractionRecord ir)
int decodeROF(const Mapping &mp, const o2::InteractionRecord ir, bool verifyDecoder)
std::vector< uint16_t > seenChipIDs
std::array< uint8_t, MaxCablesPerRU > cableLinkID
void fillChipStatistics(int icab, const ChipPixelData *chipData)
uint8_t nCables
Definition RUInfo.h:36
o2::InteractionRecord ir(0, 0)