Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:19:54

0001 // @file DecodingStat.h
0002 // @brief Alpide Chip and GBT link decoding statistics
0003 // @sa
0004 // <O2/Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/DecodingStat.h>
0005 //     <5ca140c87>
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,       // do nothing
0026       ErrActPropagate = 0x1,  // propagate to decoded data
0027       ErrActDump = 0x2        // produce raw data dump
0028     };
0029 
0030     enum DecErrors : int
0031     {
0032       BusyViolation,                 // Busy violation
0033       DataOverrun,                   // Data overrun
0034       Fatal,                         // Fatal (?)
0035       BusyOn,                        // Busy On
0036       BusyOff,                       // Busy Off
0037       TruncatedChipEmpty,            // Data was truncated after ChipEmpty
0038       TruncatedChipHeader,           // Data was truncated after ChipHeader
0039       TruncatedRegion,               // Data was truncated after Region record
0040       TruncatedLondData,             // Data was truncated in the LongData record
0041       WrongDataLongPattern,          // LongData pattern has highest bit set
0042       NoDataFound,                   // Region is not followed by Short or Long data
0043       UnknownWord,                   // Unknown word was seen
0044       RepeatingPixel,                // Same pixel fired more than once
0045       WrongRow,                      // Non-existing row decoded
0046       APE_STRIP,                     // lane data stripped for this chip event (behaviour changed with
0047                                      // RU FW v1.16.0, for general APE behaviour see
0048                                      // https://alice.its.cern.ch/jira/browse/O2-1717)
0049       APE_RESERVED_F3,               // reserved F3
0050       APE_DET_TIMEOUT,               // detector timeout (FATAL)
0051       APE_OOT_START,                 // 8b10b OOT (FATAL, start)
0052       APE_PROTOCOL_ERROR,            // event protocol error marker (FATAL, start)
0053       APE_LANE_FIFO_OVERFLOW_ERROR,  // lane FIFO overflow error (FATAL)
0054       APE_FSM_ERROR,                 // FSM error (FATAL, SEU error, reached an unknown state)
0055       APE_OCCUPANCY_RATE_LIMIT,      // pending detector events limit (FATAL)
0056       APE_OCCUPANCY_RATE_LIMIT_2,    // pending detector events limit in
0057                                      // packager(FATAL)
0058       APE_LANE_PROTOCOL_ERROR,       // lane protocol error
0059       APE_RESERVED_FC,               // reserved FC
0060       APE_ERROR_NON_CRITICAL_BYTE,   // Error in non critical byte
0061       APE_OOT_NON_CRITICAL,          // OOT non-critical
0062       WrongDColOrder,                // DColumns non increasing
0063       InterleavedChipData,           // Chip data interleaved on the cable
0064       TruncatedBuffer,               // truncated buffer, 0 padding
0065       TrailerAfterHeader,            // trailer seen after header w/o FE of FD set
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",                         // BusyViolation
0075         "DataOverrun flag ON",                           // DataOverrun
0076         "Fatal flag ON",                                 // Fatal
0077         "BusyON",                                        // BusyOn
0078         "BusyOFF",                                       // BusyOff
0079         "Data truncated after ChipEmpty",                // TruncatedChipEmpty
0080         "Data truncated after ChipHeader",               // TruncatedChipHeader
0081         "Data truncated after Region",                   // TruncatedRegion
0082         "Data truncated after LongData",                 // TruncatedLondData
0083         "LongData pattern has highest bit set",          // WrongDataLongPattern
0084         "Region is not followed by Short or Long data",  // NoDataFound
0085         "Unknown word",                                  // UnknownWord
0086         "Same pixel fired multiple times",               // RepeatingPixel
0087         "Non-existing row decoded",                      // WrongRow
0088         "APE_STRIP",                                     // lane data stripped for this chip event (behaviour changed
0089                                                          // with RU FW v1.16.0, for general APE behaviour see
0090                                                          // https://alice.its.cern.ch/jira/browse/O2-1717)
0091         "APE_RESERVED_F3",                               // reserved F3
0092         "APE_DET_TIMEOUT",                               // detector timeout (FATAL)
0093         "APE_OOT_START",                                 // 8b10b OOT (FATAL, start)
0094         "APE_PROTOCOL_ERROR",                            // event event protocol error marker (FATAL, start)
0095         "APE_LANE_FIFO_OVERFLOW_ERROR",                  // lane FIFO overflow error (FATAL)
0096         "APE_FSM_ERROR",                                 // FSM error (FATAL, SEU error, reached an unknown state)
0097         "APE_OCCUPANCY_RATE_LIMIT",                      // pending detector events limit (FATAL)
0098         "APE_OCCUPANCY_RATE_LIMIT_2",                    // pending detector events limit in
0099                                                          // packager(FATAL)
0100         "APE_LANE_PROTOCOL_ERROR",                       // lane protocol error
0101         "APE_RESERVED_FC",                               // reserved
0102         "APE_ERROR_IN_NON_CRITICAL_BYTE",                // Error in non critical byte
0103         "APE_OOT_NON_CRITICAL",                          // OOT non-critical
0104         "DColumns non-increasing",                       // DColumns non increasing
0105         "Chip data interleaved on the cable",            // Chip data interleaved on the
0106                                                          // cable
0107         "TruncatedBuffer",                               // truncated buffer, 0 padding
0108         "TrailerAfterHeader"                             // trailer seen after header w/o FE of FD set
0109     };
0110 
0111     static constexpr std::array<uint32_t, NErrorsDefined> ErrActions = {
0112         ErrActPropagate | ErrActDump,  // Busy violation
0113         ErrActPropagate | ErrActDump,  // Data overrun
0114         ErrActPropagate | ErrActDump,  // Fatal (?)
0115         ErrActNone,                    // Busy On
0116         ErrActNone,                    // Busy Off
0117         ErrActPropagate | ErrActDump,  // Data was truncated after ChipEmpty
0118         ErrActPropagate | ErrActDump,  // Data was truncated after ChipHeader
0119         ErrActPropagate | ErrActDump,  // Data was truncated after Region record
0120         ErrActPropagate | ErrActDump,  // Data was truncated in the LongData record
0121         ErrActPropagate | ErrActDump,  // LongData pattern has highest bit set
0122         ErrActPropagate |
0123             ErrActDump,                // Region is not followed by Short or Long data
0124         ErrActPropagate | ErrActDump,  // Unknown word was seen
0125         ErrActPropagate,               // Same pixel fired more than once
0126         ErrActPropagate | ErrActDump,  // Non-existing row decoded
0127         ErrActPropagate |
0128             ErrActDump,                // lane data stripped for this chip event (behaviour
0129                                        // changed with RU FW v1.16.0, for general APE behaviour
0130                                        // see  https://alice.its.cern.ch/jira/browse/O2-1717)
0131         ErrActPropagate | ErrActDump,  // reserved F3
0132         ErrActPropagate | ErrActDump,  // detector timeout (FATAL)
0133         ErrActPropagate | ErrActDump,  // 8b10b OOT (FATAL, start)
0134         ErrActPropagate |
0135             ErrActDump,                // event protocol error marker (FATAL, start)
0136         ErrActPropagate | ErrActDump,  // lane FIFO overflow error (FATAL)
0137         ErrActPropagate |
0138             ErrActDump,                // FSM error (FATAL, SEU error, reached an unknown state)
0139         ErrActPropagate | ErrActDump,  // pending detector events limit (FATAL)
0140         ErrActPropagate |
0141             ErrActDump,                // pending detector events limit in packager(FATAL)
0142         ErrActPropagate | ErrActDump,  // lane protocol error
0143         ErrActPropagate | ErrActDump,  // reserved FC
0144         ErrActPropagate | ErrActDump,  // Error in non critical byte
0145         ErrActPropagate | ErrActDump,  // OOT non-critical
0146         ErrActPropagate | ErrActDump,  // DColumns non increasing
0147         ErrActPropagate | ErrActDump,  // Chip data interleaved on the cable
0148         ErrActPropagate |
0149             ErrActDump,               // Truncated buffer while something was expected
0150         ErrActPropagate | ErrActDump  // trailer seen after header w/o FE of FD set
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     // return APE DecErrors code or -1 if not APE error, set fatal flag if needd
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     //  ClassDefNV(ChipStat, 1);
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     //  ClassDefNV(ChipError, 1);
0208   };
0209 
0210   /// Statistics for per-link decoding
0211   struct GBTLinkDecodingStat
0212   {
0213     /// counters for format checks
0214 
0215     enum DecErrors : int
0216     {
0217       ErrNoRDHAtStart,              // page does not start with RDH
0218       ErrPageNotStopped,            // RDH is stopped, but the time is not matching the ~stop
0219                                     // packet
0220       ErrStopPageNotEmpty,          // Page with RDH.stop is not empty
0221       ErrPageCounterDiscontinuity,  // RDH page counters for the same RU/trigger
0222                                     // are not continuous
0223       ErrRDHvsGBTHPageCnt,          // RDH and GBT header page counters are not consistent
0224       ErrMissingGBTTrigger,         // GBT trigger word was expected but not found
0225       ErrMissingGBTHeader,          // GBT payload header was expected but not found
0226       ErrMissingGBTTrailer,         // GBT payload trailer was expected but not found
0227       ErrNonZeroPageAfterStop,      // all lanes were stopped but the page counter in
0228                                     // not 0
0229       ErrUnstoppedLanes,            // end of FEE data reached while not all lanes received
0230                                     // stop
0231       ErrDataForStoppedLane,        // data was received for stopped lane
0232       ErrNoDataForActiveLane,       // no data was seen for lane (which was not in
0233                                     // timeout)
0234       ErrIBChipLaneMismatch,        // chipID (on module) was different from the lane ID
0235                                     // on the IB stave
0236       ErrCableDataHeadWrong,        // cable data does not start with chip header or
0237                                     // empty chip
0238       ErrInvalidActiveLanes,        // active lanes pattern conflicts with expected for
0239                                     // given RU type
0240       ErrPacketCounterJump,         // jump in RDH.packetCounter
0241       ErrPacketDoneMissing,         // packet done is missing in the trailer while CRU
0242                                     // page is not over
0243       ErrMissingDiagnosticWord,     // missing diagnostic word after RDH with stop
0244       ErrGBTWordNotRecognized,      // GBT word not recognized
0245       ErrWrongeCableID,             // Invalid cable ID
0246       ErrWrongAlignmentWord,        // unexpected alignment word
0247       ErrMissingROF,                // missing ROF (desync?)
0248       ErrOldROF,                    // old ROF (desync?)
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",                              // ErrNoRDHAtStart
0258         "RDH is stopped, but the time is not matching the stop packet",       // ErrPageNotStopped
0259         "Page with RDH.stop does not contain diagnostic word only",           // ErrStopPageNotEmpty
0260         "RDH page counters for the same RU/trigger are not continuous",       // ErrPageCounterDiscontinuity
0261         "RDH and GBT header page counters are not consistent",                // ErrRDHvsGBTHPageCnt
0262         "GBT trigger word was expected but not found",                        // ErrMissingGBTTrigger
0263         "GBT payload header was expected but not found",                      // ErrMissingGBTHeader
0264         "GBT payload trailer was expected but not found",                     // ErrMissingGBTTrailer
0265         "All lanes were stopped but the page counter in not 0",               // ErrNonZeroPageAfterStop
0266         "End of FEE data reached while not all lanes received stop",          // ErrUnstoppedLanes
0267         "Data was received for stopped lane",                                 // ErrDataForStoppedLane
0268         "No data was seen for lane (which was not in timeout)",               // ErrNoDataForActiveLane
0269         "ChipID (on module) was different from the lane ID on the IB stave",  // ErrIBChipLaneMismatch
0270         "Cable data does not start with chip header or empty chip",           // ErrCableDataHeadWrong
0271         "Active lanes pattern conflicts with expected for given RU type",     // ErrInvalidActiveLanes
0272         "Jump in RDH_packetCounter",                                          // ErrPacketCounterJump
0273         "Packet done is missing in the trailer while CRU page is not over",   // ErrPacketDoneMissing
0274         "Missing diagnostic GBT word after RDH with stop",                    // ErrMissingDiagnosticWord
0275         "GBT word not recognized",                                            // ErrGBTWordNotRecognized
0276         "Wrong cable ID"                                                      // ErrWrongeCableID
0277         "Unexpected CRU page alignment padding word",                         // ErrWrongAlignmentWord
0278         "ROF in future, pause decoding to synchronize",                       // ErrMissingROF
0279         "Old ROF, discarding",                                                // ErrOldROF
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;                                     // FeeID
0311     std::array<uint32_t, NErrorsDefined> errorCounts = {};  // error counters
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     //  ClassDefNV(GBTLinkDecodingStat, 2);
0323   };
0324 
0325 }  // namespace mvtx
0326 #endif