File indexing completed on 2025-08-06 08:17:18
0001
0002
0003
0004
0005
0006 #ifndef MVTXDECODER_DECODINGSTAT_H
0007 #define MVTXDECODER_DECODINGSTAT_H
0008
0009 #define CXX_17 201703L
0010
0011 #include <array>
0012 #include <cstdint>
0013 #include <cstring>
0014 #include <string>
0015
0016 namespace mvtx
0017 {
0018 class ChipPixelData;
0019
0020 struct ChipStat {
0021 enum ActionOnError : uint32_t {
0022 ErrActNone = 0x0,
0023 ErrActPropagate = 0x1,
0024 ErrActDump = 0x2
0025 };
0026
0027 enum DecErrors : uint32_t {
0028 BusyViolation,
0029 DataOverrun,
0030 Fatal,
0031 BusyOn,
0032 BusyOff,
0033 TruncatedChipEmpty,
0034 TruncatedChipHeader,
0035 TruncatedRegion,
0036 TruncatedLondData,
0037 WrongDataLongPattern,
0038 NoDataFound,
0039 UnknownWord,
0040 RepeatingPixel,
0041 WrongRow,
0042 APE_STRIP,
0043 APE_RESERVED_F3,
0044 APE_DET_TIMEOUT,
0045 APE_OOT_START,
0046 APE_PROTOCOL_ERROR,
0047 APE_LANE_FIFO_OVERFLOW_ERROR,
0048 APE_FSM_ERROR,
0049 APE_OCCUPANCY_RATE_LIMIT,
0050 APE_OCCUPANCY_RATE_LIMIT_2,
0051 APE_LANE_PROTOCOL_ERROR,
0052 APE_RESERVED_FC,
0053 APE_ERROR_NON_CRITICAL_BYTE,
0054 APE_OOT_NON_CRITICAL,
0055 WrongDColOrder,
0056 InterleavedChipData,
0057 TruncatedBuffer,
0058 TrailerAfterHeader,
0059 NErrorsDefined
0060 };
0061
0062 #if ( __cplusplus >= CXX_17 )
0063 static constexpr std::array<std::string_view, NErrorsDefined> ErrNames = {
0064 #else
0065 const std::array<const std::string, NErrorsDefined> ErrNames = {
0066 #endif
0067 "BusyViolation flag ON",
0068 "DataOverrun flag ON",
0069 "Fatal flag ON",
0070 "BusyON",
0071 "BusyOFF",
0072 "Data truncated after ChipEmpty",
0073 "Data truncated after ChipHeader",
0074 "Data truncated after Region",
0075 "Data truncated after LongData",
0076 "LongData pattern has highest bit set",
0077 "Region is not followed by Short or Long data",
0078 "Unknown word",
0079 "Same pixel fired multiple times",
0080 "Non-existing row decoded",
0081 "APE_STRIP",
0082 "APE_RESERVED_F3",
0083 "APE_DET_TIMEOUT",
0084 "APE_OOT_START",
0085 "APE_PROTOCOL_ERROR",
0086 "APE_LANE_FIFO_OVERFLOW_ERROR",
0087 "APE_FSM_ERROR",
0088 "APE_OCCUPANCY_RATE_LIMIT",
0089 "APE_OCCUPANCY_RATE_LIMIT_2",
0090 "APE_LANE_PROTOCOL_ERROR",
0091 "APE_RESERVED_FC",
0092 "APE_ERROR_IN_NON_CRITICAL_BYTE",
0093 "APE_OOT_NON_CRITICAL",
0094 "DColumns non-increasing",
0095 "Chip data interleaved on the cable",
0096 "TruncatedBuffer",
0097 "TrailerAfterHeader"
0098 };
0099
0100 static constexpr std::array<uint32_t, NErrorsDefined> ErrActions = {
0101 ErrActPropagate | ErrActDump,
0102 ErrActPropagate | ErrActDump,
0103 ErrActPropagate | ErrActDump,
0104 ErrActNone,
0105 ErrActNone,
0106 ErrActPropagate | ErrActDump,
0107 ErrActPropagate | ErrActDump,
0108 ErrActPropagate | ErrActDump,
0109 ErrActPropagate | ErrActDump,
0110 ErrActPropagate | ErrActDump,
0111 ErrActPropagate | ErrActDump,
0112 ErrActPropagate | ErrActDump,
0113 ErrActPropagate,
0114 ErrActPropagate | ErrActDump,
0115 ErrActPropagate | ErrActDump,
0116 ErrActPropagate | ErrActDump,
0117 ErrActPropagate | ErrActDump,
0118 ErrActPropagate | ErrActDump,
0119 ErrActPropagate | ErrActDump,
0120 ErrActPropagate | ErrActDump,
0121 ErrActPropagate | ErrActDump,
0122 ErrActPropagate | ErrActDump,
0123 ErrActPropagate | ErrActDump,
0124 ErrActPropagate | ErrActDump,
0125 ErrActPropagate | ErrActDump,
0126 ErrActPropagate | ErrActDump,
0127 ErrActPropagate | ErrActDump,
0128 ErrActPropagate | ErrActDump,
0129 ErrActPropagate | ErrActDump,
0130 ErrActPropagate | ErrActDump,
0131 ErrActPropagate | ErrActDump
0132 };
0133 uint16_t feeID = -1;
0134 size_t nHits = 0;
0135 std::array<uint32_t, NErrorsDefined> errorCounts = {};
0136 ChipStat() = default;
0137 ChipStat(uint16_t _feeID) : feeID(_feeID) {}
0138
0139 void clear()
0140 {
0141 memset(errorCounts.data(), 0, sizeof(uint32_t) * errorCounts.size());
0142 nHits = 0;
0143 }
0144
0145 static int getAPENonCritical(uint8_t c)
0146 {
0147 if (c == 0xfd || c == 0xfe) {
0148 return APE_STRIP + c - 0xf2;
0149 }
0150 return -1;
0151 }
0152
0153
0154 static int getAPECode(uint8_t c, bool& ft)
0155 {
0156 if (c < 0xf2 || c > 0xfe) {
0157 ft = false;
0158 return -1;
0159 }
0160 ft = c >= 0xf2 && c <= 0xfe;
0161 return APE_STRIP + c - 0xf2;
0162 }
0163 uint32_t getNErrors() const;
0164 uint32_t addErrors(uint32_t mask, uint16_t chID, int verbosity);
0165 uint32_t addErrors(const ChipPixelData& d, int verbosity);
0166 void print(bool skipNoErr = true, const std::string& pref = "FEEID") const;
0167
0168
0169 };
0170
0171 struct ChipError {
0172 uint32_t id = -1;
0173 uint32_t nerrors = 0;
0174 uint32_t errors = 0;
0175
0176 int16_t getChipID() const { return int16_t(id & 0xffff); }
0177 uint16_t getFEEID() const { return uint16_t(id >> 16); }
0178 static uint32_t composeID(uint16_t feeID, int16_t chipID) { return uint32_t(feeID) << 16 | uint16_t(chipID); }
0179
0180 };
0181
0182
0183 struct GBTLinkDecodingStat {
0184
0185
0186 enum DecErrors : int {
0187 ErrNoRDHAtStart,
0188 ErrPageNotStopped,
0189 ErrStopPageNotEmpty,
0190 ErrPageCounterDiscontinuity,
0191 ErrRDHvsGBTHPageCnt,
0192 ErrMissingGBTTrigger,
0193 ErrMissingGBTHeader,
0194 ErrMissingGBTTrailer,
0195 ErrNonZeroPageAfterStop,
0196 ErrUnstoppedLanes,
0197 ErrDataForStoppedLane,
0198 ErrNoDataForActiveLane,
0199 ErrIBChipLaneMismatch,
0200 ErrCableDataHeadWrong,
0201 ErrInvalidActiveLanes,
0202 ErrPacketCounterJump,
0203 ErrPacketDoneMissing,
0204 ErrMissingDiagnosticWord,
0205 ErrGBTWordNotRecognized,
0206 ErrWrongeCableID,
0207 ErrWrongAlignmentWord,
0208 ErrMissingROF,
0209 ErrOldROF,
0210 NErrorsDefined
0211 };
0212
0213 #if ( __cplusplus >= CXX_17 )
0214 static constexpr std::array<std::string_view, NErrorsDefined> ErrNames = {
0215 #else
0216 const std::array<std::string, NErrorsDefined> ErrNames = {
0217 #endif
0218 "Page data not start with expected RDH",
0219 "RDH is stopped, but the time is not matching the stop packet",
0220 "Page with RDH.stop does not contain diagnostic word only",
0221 "RDH page counters for the same RU/trigger are not continuous",
0222 "RDH and GBT header page counters are not consistent",
0223 "GBT trigger word was expected but not found",
0224 "GBT payload header was expected but not found",
0225 "GBT payload trailer was expected but not found",
0226 "All lanes were stopped but the page counter in not 0",
0227 "End of FEE data reached while not all lanes received stop",
0228 "Data was received for stopped lane",
0229 "No data was seen for lane (which was not in timeout)",
0230 "ChipID (on module) was different from the lane ID on the IB stave",
0231 "Cable data does not start with chip header or empty chip",
0232 "Active lanes pattern conflicts with expected for given RU type",
0233 "Jump in RDH_packetCounter",
0234 "Packet done is missing in the trailer while CRU page is not over",
0235 "Missing diagnostic GBT word after RDH with stop",
0236 "GBT word not recognized",
0237 "Wrong cable ID"
0238 "Unexpected CRU page alignment padding word",
0239 "ROF in future, pause decoding to synchronize",
0240 "Old ROF, discarding",
0241 };
0242
0243 enum BitMaps : int {
0244 ORBIT = 0,
0245 HB = 1,
0246 HBr = 2,
0247 HC = 3,
0248 PHYSICS = 4,
0249 PP = 5,
0250 CAL = 6,
0251 SOT = 7,
0252 EOT = 8,
0253 SOC = 9,
0254 EOC = 10,
0255 TF = 11,
0256 FE_RST = 12,
0257 RT = 13,
0258 RS = 14,
0259 nBitMap = 15
0260 };
0261
0262 #if ( __cplusplus >= CXX_17 )
0263 static constexpr std::array<std::string_view, nBitMap> BitMapName = {
0264 #else
0265 const std::array<std::string, nBitMap> BitMapName = {
0266 #endif
0267 "ORBIT",
0268 "HB",
0269 "HBr",
0270 "HC",
0271 "PHYSICS",
0272 "PP",
0273 "CAL",
0274 "SOT",
0275 "EOT",
0276 "SOC",
0277 "EOC",
0278 "TF",
0279 "FE_RST",
0280 "RT",
0281 "RS"
0282 };
0283
0284 uint16_t feeID = 0;
0285 std::array<uint32_t, NErrorsDefined> errorCounts = {};
0286 std::array<uint32_t, nBitMap> trgBitCounts = {};
0287
0288 void clear()
0289 {
0290 errorCounts.fill(0);
0291 trgBitCounts.fill(0);
0292 }
0293
0294 void print(bool skipNoErr = true) const;
0295
0296
0297 };
0298
0299 }
0300 #endif