Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-06 08:17:18

0001 // @file DecodingStat.h
0002 // @brief Alpide Chip and GBT link decoding statistics
0003 // @sa <O2/Detectors/ITSMFT/common/reconstruction/include/ITSMFTReconstruction/DecodingStat.h>
0004 //     <5ca140c87>
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,      // do nothing
0023     ErrActPropagate = 0x1, // propagate to decoded data
0024     ErrActDump = 0x2       // produce raw data dump
0025   };
0026 
0027   enum DecErrors : uint32_t {
0028     BusyViolation,                // Busy violation
0029     DataOverrun,                  // Data overrun
0030     Fatal,                        // Fatal (?)
0031     BusyOn,                       // Busy On
0032     BusyOff,                      // Busy Off
0033     TruncatedChipEmpty,           // Data was truncated after ChipEmpty
0034     TruncatedChipHeader,          // Data was truncated after ChipHeader
0035     TruncatedRegion,              // Data was truncated after Region record
0036     TruncatedLondData,            // Data was truncated in the LongData record
0037     WrongDataLongPattern,         // LongData pattern has highest bit set
0038     NoDataFound,                  // Region is not followed by Short or Long data
0039     UnknownWord,                  // Unknown word was seen
0040     RepeatingPixel,               // Same pixel fired more than once
0041     WrongRow,                     // Non-existing row decoded
0042     APE_STRIP,                    // lane data stripped for this chip event (behaviour changed with RU FW v1.16.0, for general APE behaviour see  https://alice.its.cern.ch/jira/browse/O2-1717)
0043     APE_RESERVED_F3,              // reserved F3
0044     APE_DET_TIMEOUT,              // detector timeout (FATAL)
0045     APE_OOT_START,                // 8b10b OOT (FATAL, start)
0046     APE_PROTOCOL_ERROR,           // event protocol error marker (FATAL, start)
0047     APE_LANE_FIFO_OVERFLOW_ERROR, // lane FIFO overflow error (FATAL)
0048     APE_FSM_ERROR,                // FSM error (FATAL, SEU error, reached an unknown state)
0049     APE_OCCUPANCY_RATE_LIMIT,     // pending detector events limit (FATAL)
0050     APE_OCCUPANCY_RATE_LIMIT_2,   // pending detector events limit in packager(FATAL)
0051     APE_LANE_PROTOCOL_ERROR,      // lane protocol error
0052     APE_RESERVED_FC,              // reserved FC
0053     APE_ERROR_NON_CRITICAL_BYTE,  // Error in non critical byte
0054     APE_OOT_NON_CRITICAL,         // OOT non-critical
0055     WrongDColOrder,               // DColumns non increasing
0056     InterleavedChipData,          // Chip data interleaved on the cable
0057     TruncatedBuffer,              // truncated buffer, 0 padding
0058     TrailerAfterHeader,           // trailer seen after header w/o FE of FD set
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",                        // BusyViolation
0068     "DataOverrun flag ON",                          // DataOverrun
0069     "Fatal flag ON",                                // Fatal
0070     "BusyON",                                       // BusyOn
0071     "BusyOFF",                                      // BusyOff
0072     "Data truncated after ChipEmpty",               // TruncatedChipEmpty
0073     "Data truncated after ChipHeader",              // TruncatedChipHeader
0074     "Data truncated after Region",                  // TruncatedRegion
0075     "Data truncated after LongData",                // TruncatedLondData
0076     "LongData pattern has highest bit set",         // WrongDataLongPattern
0077     "Region is not followed by Short or Long data", // NoDataFound
0078     "Unknown word",                                 // UnknownWord
0079     "Same pixel fired multiple times",              // RepeatingPixel
0080     "Non-existing row decoded",                     // WrongRow
0081     "APE_STRIP",                                    // lane data stripped for this chip event (behaviour changed with RU FW v1.16.0, for general APE behaviour see  https://alice.its.cern.ch/jira/browse/O2-1717)
0082     "APE_RESERVED_F3",                              // reserved F3
0083     "APE_DET_TIMEOUT",                              // detector timeout (FATAL)
0084     "APE_OOT_START",                                // 8b10b OOT (FATAL, start)
0085     "APE_PROTOCOL_ERROR",                           // event event protocol error marker (FATAL, start)
0086     "APE_LANE_FIFO_OVERFLOW_ERROR",                 // lane FIFO overflow error (FATAL)
0087     "APE_FSM_ERROR",                                // FSM error (FATAL, SEU error, reached an unknown state)
0088     "APE_OCCUPANCY_RATE_LIMIT",                     // pending detector events limit (FATAL)
0089     "APE_OCCUPANCY_RATE_LIMIT_2",                   // pending detector events limit in packager(FATAL)
0090     "APE_LANE_PROTOCOL_ERROR",                      // lane protocol error
0091     "APE_RESERVED_FC",                              // reserved
0092     "APE_ERROR_IN_NON_CRITICAL_BYTE",               // Error in non critical byte
0093     "APE_OOT_NON_CRITICAL",                         // OOT non-critical
0094     "DColumns non-increasing",                      // DColumns non increasing
0095     "Chip data interleaved on the cable",           // Chip data interleaved on the cable
0096     "TruncatedBuffer",                              // truncated buffer, 0 padding
0097     "TrailerAfterHeader"                            // trailer seen after header w/o FE of FD set
0098   };
0099 
0100   static constexpr std::array<uint32_t, NErrorsDefined> ErrActions = {
0101     ErrActPropagate | ErrActDump, // Busy violation
0102     ErrActPropagate | ErrActDump, // Data overrun
0103     ErrActPropagate | ErrActDump, // Fatal (?)
0104     ErrActNone,                   // Busy On
0105     ErrActNone,                   // Busy Off
0106     ErrActPropagate | ErrActDump, // Data was truncated after ChipEmpty
0107     ErrActPropagate | ErrActDump, // Data was truncated after ChipHeader
0108     ErrActPropagate | ErrActDump, // Data was truncated after Region record
0109     ErrActPropagate | ErrActDump, // Data was truncated in the LongData record
0110     ErrActPropagate | ErrActDump, // LongData pattern has highest bit set
0111     ErrActPropagate | ErrActDump, // Region is not followed by Short or Long data
0112     ErrActPropagate | ErrActDump, // Unknown word was seen
0113     ErrActPropagate,              // Same pixel fired more than once
0114     ErrActPropagate | ErrActDump, // Non-existing row decoded
0115     ErrActPropagate | ErrActDump, // lane data stripped for this chip event (behaviour changed with RU FW v1.16.0, for general APE behaviour see  https://alice.its.cern.ch/jira/browse/O2-1717)
0116     ErrActPropagate | ErrActDump, // reserved F3
0117     ErrActPropagate | ErrActDump, // detector timeout (FATAL)
0118     ErrActPropagate | ErrActDump, // 8b10b OOT (FATAL, start)
0119     ErrActPropagate | ErrActDump, // event protocol error marker (FATAL, start)
0120     ErrActPropagate | ErrActDump, // lane FIFO overflow error (FATAL)
0121     ErrActPropagate | ErrActDump, // FSM error (FATAL, SEU error, reached an unknown state)
0122     ErrActPropagate | ErrActDump, // pending detector events limit (FATAL)
0123     ErrActPropagate | ErrActDump, // pending detector events limit in packager(FATAL)
0124     ErrActPropagate | ErrActDump, // lane protocol error
0125     ErrActPropagate | ErrActDump, // reserved FC
0126     ErrActPropagate | ErrActDump, // Error in non critical byte
0127     ErrActPropagate | ErrActDump, // OOT non-critical
0128     ErrActPropagate | ErrActDump, // DColumns non increasing
0129     ErrActPropagate | ErrActDump, // Chip data interleaved on the cable
0130     ErrActPropagate | ErrActDump, // Truncated buffer while something was expected
0131     ErrActPropagate | ErrActDump  // trailer seen after header w/o FE of FD set
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   // return APE DecErrors code or -1 if not APE error, set fatal flag if needd
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 //  ClassDefNV(ChipStat, 1);
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 //  ClassDefNV(ChipError, 1);
0180 };
0181 
0182 /// Statistics for per-link decoding
0183 struct GBTLinkDecodingStat {
0184   /// counters for format checks
0185 
0186   enum DecErrors : int {
0187     ErrNoRDHAtStart,             // page does not start with RDH
0188     ErrPageNotStopped,           // RDH is stopped, but the time is not matching the ~stop packet
0189     ErrStopPageNotEmpty,         // Page with RDH.stop is not empty
0190     ErrPageCounterDiscontinuity, // RDH page counters for the same RU/trigger are not continuous
0191     ErrRDHvsGBTHPageCnt,         // RDH and GBT header page counters are not consistent
0192     ErrMissingGBTTrigger,        // GBT trigger word was expected but not found
0193     ErrMissingGBTHeader,         // GBT payload header was expected but not found
0194     ErrMissingGBTTrailer,        // GBT payload trailer was expected but not found
0195     ErrNonZeroPageAfterStop,     // all lanes were stopped but the page counter in not 0
0196     ErrUnstoppedLanes,           // end of FEE data reached while not all lanes received stop
0197     ErrDataForStoppedLane,       // data was received for stopped lane
0198     ErrNoDataForActiveLane,      // no data was seen for lane (which was not in timeout)
0199     ErrIBChipLaneMismatch,       // chipID (on module) was different from the lane ID on the IB stave
0200     ErrCableDataHeadWrong,       // cable data does not start with chip header or empty chip
0201     ErrInvalidActiveLanes,       // active lanes pattern conflicts with expected for given RU type
0202     ErrPacketCounterJump,        // jump in RDH.packetCounter
0203     ErrPacketDoneMissing,        // packet done is missing in the trailer while CRU page is not over
0204     ErrMissingDiagnosticWord,    // missing diagnostic word after RDH with stop
0205     ErrGBTWordNotRecognized,     // GBT word not recognized
0206     ErrWrongeCableID,            // Invalid cable ID
0207     ErrWrongAlignmentWord,       // unexpected alignment word
0208     ErrMissingROF,               // missing ROF (desync?)
0209     ErrOldROF,                   // old ROF (desync?)
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",                             // ErrNoRDHAtStart
0219     "RDH is stopped, but the time is not matching the stop packet",      // ErrPageNotStopped
0220     "Page with RDH.stop does not contain diagnostic word only",          // ErrStopPageNotEmpty
0221     "RDH page counters for the same RU/trigger are not continuous",      // ErrPageCounterDiscontinuity
0222     "RDH and GBT header page counters are not consistent",               // ErrRDHvsGBTHPageCnt
0223     "GBT trigger word was expected but not found",                       // ErrMissingGBTTrigger
0224     "GBT payload header was expected but not found",                     // ErrMissingGBTHeader
0225     "GBT payload trailer was expected but not found",                    // ErrMissingGBTTrailer
0226     "All lanes were stopped but the page counter in not 0",              // ErrNonZeroPageAfterStop
0227     "End of FEE data reached while not all lanes received stop",         // ErrUnstoppedLanes
0228     "Data was received for stopped lane",                                // ErrDataForStoppedLane
0229     "No data was seen for lane (which was not in timeout)",              // ErrNoDataForActiveLane
0230     "ChipID (on module) was different from the lane ID on the IB stave", // ErrIBChipLaneMismatch
0231     "Cable data does not start with chip header or empty chip",          // ErrCableDataHeadWrong
0232     "Active lanes pattern conflicts with expected for given RU type",    // ErrInvalidActiveLanes
0233     "Jump in RDH_packetCounter",                                         // ErrPacketCounterJump
0234     "Packet done is missing in the trailer while CRU page is not over",  // ErrPacketDoneMissing
0235     "Missing diagnostic GBT word after RDH with stop",                   // ErrMissingDiagnosticWord
0236     "GBT word not recognized",                                           // ErrGBTWordNotRecognized
0237     "Wrong cable ID"                                                     // ErrWrongeCableID
0238     "Unexpected CRU page alignment padding word",                        // ErrWrongAlignmentWord
0239     "ROF in future, pause decoding to synchronize",                      // ErrMissingROF
0240     "Old ROF, discarding",                                               // ErrOldROF
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; // FeeID
0285   std::array<uint32_t, NErrorsDefined> errorCounts = {};                        // error counters
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 //  ClassDefNV(GBTLinkDecodingStat, 2);
0297 };
0298 
0299 } // namespace mvtx
0300 #endif