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