Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // @file ChipStat.cxx
0002 // @brief Alpide Chip decoding statistics
0003 // @sa <O2/Detectors/ITSMFT/common/reconstruction/src/DecodingStat.cxx>
0004 //     <3cbcf82df>
0005 
0006 #include "DecodingStat.h"
0007 #include "PixelData.h"
0008 #include "mvtx_utils.h"
0009 
0010 #include <bitset>
0011 #include <sstream>
0012 
0013 using namespace mvtx;
0014 
0015 #if (__cplusplus >= CXX_17)
0016 constexpr std::array<std::string_view, ChipStat::NErrorsDefined> ChipStat::ErrNames;
0017 #endif
0018 
0019 constexpr std::array<uint32_t, ChipStat::NErrorsDefined> ChipStat::ErrActions;
0020 
0021 //________________________________________________________________________________
0022 uint32_t ChipStat::getNErrors() const
0023 {
0024   uint32_t nerr = 0;
0025   for (int i = NErrorsDefined; i--;)
0026   {
0027     nerr += errorCounts[i];
0028   }
0029   return nerr;
0030 }
0031 
0032 //________________________________________________________________________________
0033 /// print link decoding statistics
0034 uint32_t ChipStat::addErrors(uint32_t mask, uint16_t chID, int verbosity)
0035 {
0036   uint32_t res = 0;
0037   if (mask)
0038   {
0039     for (uint32_t i = NErrorsDefined; i--;)
0040     {
0041       if (mask & (0x1U << i))
0042       {
0043         res |= ErrActions[i] & ErrActPropagate;
0044         if (verbosity > -1 && (!errorCounts[i] || verbosity > 1))
0045         {
0046           log_error << "New error registered on the FEEID: " << feeID << ": chip: " << chID << " " << ErrNames[i] << std::endl;
0047           res |= ErrActions[i] & ErrActDump;
0048         }
0049         errorCounts[i]++;
0050       }
0051     }
0052   }
0053   return res;
0054 }
0055 
0056 //________________________________________________________________________________
0057 /// print link decoding statistics
0058 uint32_t ChipStat::addErrors(const ChipPixelData& d, int verbosity)
0059 {
0060   uint32_t res = 0;
0061   if (d.getErrorFlags())
0062   {
0063     for (uint32_t i = NErrorsDefined; i--;)
0064     {
0065       if (d.getErrorFlags() & (0x1U << i))
0066       {
0067         res |= ErrActions[i] & ErrActPropagate;
0068         if (verbosity > -1 && (!errorCounts[i] || verbosity > 1))
0069         {
0070           //          LOGP(info, "New error registered at bc/orbit {}/{} on the FEEID:{:#04x} chip#{}: {}{}",
0071           //               d.getInteractionRecord().bc, d.getInteractionRecord().orbit,
0072           //               feeID, int16_t(d.getChipID()), ErrNames[i], d.getErrorDetails(i));
0073           res |= ErrActions[i] & ErrActDump;
0074         }
0075         errorCounts[i]++;
0076       }
0077     }
0078   }
0079   return res;
0080 }
0081 
0082 //________________________________________________________________________________
0083 /// print chip decoding statistics
0084 void ChipStat::print(bool skipNoErr, const std::string& pref) const
0085 {
0086   uint32_t nErr = 0;
0087   for (int i = NErrorsDefined; i--;)
0088   {
0089     nErr += errorCounts[i];
0090   }
0091   if (!skipNoErr || nErr)
0092   {
0093     std::ostringstream rep(pref.c_str());
0094     rep << feeID << " NHits: " << nHits << " errors: " << nErr;
0095     for (uint32_t i = 0; i < NErrorsDefined; i++)
0096     {
0097       if (!skipNoErr || errorCounts[i])
0098       {
0099         rep << " | Err.: " << ErrNames[i].data() << " : " << errorCounts[i];
0100       }
0101     }
0102     log_error << rep.str().c_str() << std::endl;
0103   }
0104 }
0105 
0106 //________________________________________________________________________________
0107 /// print link decoding statistics
0108 void GBTLinkDecodingStat::print(bool skipNoErr) const
0109 {
0110   int nErr = 0;
0111   for (int i = NErrorsDefined; i--;)
0112   {
0113     nErr += errorCounts[i];
0114   }
0115   if (!skipNoErr || nErr)
0116   {
0117     //    std::string rep = fmt::format("FEEID#{:#04x} Packet States Statistics (total packets: {}, triggers: {})", feeID, nPackets, nTriggers);
0118     //    bool countsSeen = false;
0119     //    for (int i = 0; i < GBTDataTrailer::MaxStateCombinations; i++) {
0120     //      if (packetStates[i]) {
0121     //        if (!countsSeen) {
0122     //          countsSeen = true;
0123     //          rep += " | counts for triggers: ";
0124     //        } else {
0125     //          rep += ", ";
0126     //        }
0127     //        std::bitset<GBTDataTrailer::NStatesDefined> patt(i);
0128     //        rep += fmt::format("b{:s}: {}", patt.to_string().c_str(), packetStates[i]);
0129     //      }
0130     //    }
0131     //    rep += fmt::format(" | Decoding errors: {}", nErr);
0132     //    for (int i = 0; i < NErrorsDefined; i++) {
0133     //      if (!skipNoErr || errorCounts[i]) {
0134     //        rep += fmt::format(" [{}: {}]", ErrNames[i].data(), errorCounts[i]);
0135     //      }
0136     //    }
0137     //    LOG(info) << rep;
0138   }
0139 }