Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:45:46

0001 #include "EventFilter/SiPixelRawToDigi/interface/ErrorChecker.h"
0002 
0003 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
0004 
0005 #include "DataFormats/DetId/interface/DetId.h"
0006 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0007 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
0008 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
0009 
0010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0011 
0012 #include <bitset>
0013 #include <sstream>
0014 #include <iostream>
0015 
0016 using namespace std;
0017 using namespace edm;
0018 using namespace sipixelobjects;
0019 using namespace sipixelconstants;
0020 
0021 ErrorChecker::ErrorChecker() : ErrorCheckerBase(){};
0022 
0023 bool ErrorChecker::checkROC(bool& errorsInEvent,
0024                             int fedId,
0025                             const SiPixelFrameConverter* converter,
0026                             const SiPixelFedCabling* theCablingTree,
0027                             Word32& errorWord,
0028                             SiPixelFormatterErrors& errors) const {
0029   int errorType = (errorWord >> ROC_shift) & ERROR_mask;
0030   if LIKELY (errorType < 25)
0031     return true;
0032   unsigned int channel = (errorWord >> LINK_shift) & LINK_mask;
0033   unsigned int roc = 1;
0034 
0035   switch (errorType) {
0036     case (25): {
0037       CablingPathToDetUnit cablingPath = {unsigned(fedId), channel, 1};
0038       if (!theCablingTree->findItem(cablingPath)) {
0039         return false;
0040       }
0041       LogDebug("") << "  invalid ROC=25 found (errorType=25)";
0042       errorsInEvent = true;
0043       break;
0044     }
0045     case (26): {
0046       //LogDebug("")<<"  gap word found (errorType=26)";
0047       return false;
0048     }
0049     case (27): {
0050       //LogDebug("")<<"  dummy word found (errorType=27)";
0051       return false;
0052     }
0053     case (28): {
0054       LogDebug("") << "  error fifo nearly full (errorType=28)";
0055       errorsInEvent = true;
0056       break;
0057     }
0058     case (29): {
0059       LogDebug("") << "  timeout on a channel (errorType=29)";
0060       errorsInEvent = true;
0061       if (!((errorWord >> OMIT_ERR_shift) & OMIT_ERR_mask)) {  //exit on the 2nd TO word
0062         LogDebug("") << "  ...2nd errorType=29 error, skip";
0063         return false;
0064       }
0065       break;
0066     }
0067     case (30): {
0068       LogDebug("") << "  TBM error trailer (errorType=30)";
0069       int StateMatch_bits = 4;
0070       int StateMatch_shift = 8;
0071       uint32_t StateMatch_mask = ~(~uint32_t(0) << StateMatch_bits);
0072       int StateMatch = (errorWord >> StateMatch_shift) & StateMatch_mask;
0073       if (StateMatch != 1 && StateMatch != 8) {
0074         LogDebug("") << " FED error 30 with unexpected State Bits (errorType=30)";
0075         return false;
0076       }
0077       if (StateMatch == 1)
0078         errorType = 40;  // 1=Overflow -> 40, 8=number of ROCs -> 30
0079       errorsInEvent = true;
0080       break;
0081     }
0082     case (31): {
0083       LogDebug("") << "  event number error (errorType=31)";
0084       errorsInEvent = true;
0085       break;
0086     }
0087     case (37):
0088     case (38): {
0089       roc = (errorWord >> ROC_shift) & ROC_mask;
0090       break;
0091     }
0092     default:
0093       return true;
0094   };
0095 
0096   if (includeErrors_) {
0097     // store error
0098     SiPixelRawDataError error(errorWord, errorType, fedId);
0099     cms_uint32_t detId = errorDetIdSimple(converter, errorType, channel, roc);
0100     errors[detId].push_back(error);
0101   }
0102   return false;
0103 }
0104 
0105 // new, simpler version
0106 cms_uint32_t ErrorChecker::errorDetIdSimple(const SiPixelFrameConverter* converter,
0107                                             int errorType,
0108                                             unsigned int channel,
0109                                             unsigned int roc) const {
0110   if (!converter) {
0111     return dummyDetId;
0112   }
0113 
0114   ElectronicIndex cabling;
0115   DetectorIndex detIdx;
0116   cabling.dcol = 0;
0117   cabling.pxid = 2;
0118   cabling.roc = roc;
0119   cabling.link = channel;
0120   int status = converter->toDetector(cabling, detIdx);
0121   if (!status) {
0122     return detIdx.rawId;
0123   }  // all OK return valid module id
0124 
0125   return dummyDetId;  // failed, return dummy
0126 }
0127 
0128 // this function finds the detId for an error word that cannot be processed in word2digi
0129 cms_uint32_t ErrorChecker::errorDetId(const SiPixelFrameConverter* converter, int errorType, const Word32& word) const {
0130   if (!converter) {
0131     return dummyDetId;
0132   }
0133   ElectronicIndex cabling;
0134 
0135   switch (errorType) {
0136     case 25:
0137     case 30:
0138     case 31:
0139     case 36:
0140     case 40: {
0141       // set dummy values for cabling just to get detId from link
0142       cabling.dcol = 0;
0143       cabling.pxid = 2;
0144       cabling.roc = 1;
0145       cabling.link = (word >> LINK_shift) & LINK_mask;
0146 
0147       DetectorIndex detIdx;
0148       int status = converter->toDetector(cabling, detIdx);
0149       if (!status) {
0150         return detIdx.rawId;
0151       }
0152       break;
0153     }
0154     case 29: {
0155       int chanNmbr = 0;
0156       const int DB0_shift = 0;
0157       const int DB1_shift = DB0_shift + 1;
0158       const int DB2_shift = DB1_shift + 1;
0159       const int DB3_shift = DB2_shift + 1;
0160       const int DB4_shift = DB3_shift + 1;
0161       const cms_uint32_t DataBit_mask = ~(~cms_uint32_t(0) << 1);
0162 
0163       int CH1 = (word >> DB0_shift) & DataBit_mask;
0164       int CH2 = (word >> DB1_shift) & DataBit_mask;
0165       int CH3 = (word >> DB2_shift) & DataBit_mask;
0166       int CH4 = (word >> DB3_shift) & DataBit_mask;
0167       int CH5 = (word >> DB4_shift) & DataBit_mask;
0168       int BLOCK_bits = 3;
0169       int BLOCK_shift = 8;
0170       cms_uint32_t BLOCK_mask = ~(~cms_uint32_t(0) << BLOCK_bits);
0171       int BLOCK = (word >> BLOCK_shift) & BLOCK_mask;
0172       int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
0173       if (BLOCK % 2 == 0)
0174         chanNmbr = (BLOCK / 2) * 9 + localCH;
0175       else
0176         chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
0177 
0178       if ((chanNmbr < 1) || (chanNmbr > 36)) {
0179         break;  // signifies unexpected result  WRONG!
0180       }
0181       // set dummy values for cabling just to get detId from link if in Barrel
0182       cabling.dcol = 0;
0183       cabling.pxid = 2;
0184       cabling.roc = 1;
0185       cabling.link = chanNmbr;
0186       DetectorIndex detIdx;
0187       int status = converter->toDetector(cabling, detIdx);
0188       if (!status) {
0189         return detIdx.rawId;
0190       }
0191       break;
0192     }
0193     case 37:
0194     case 38: {
0195       cabling.dcol = 0;
0196       cabling.pxid = 2;
0197       cabling.roc = (word >> ROC_shift) & ROC_mask;
0198       cabling.link = (word >> LINK_shift) & LINK_mask;
0199 
0200       DetectorIndex detIdx;
0201       int status = converter->toDetector(cabling, detIdx);
0202       if (status)
0203         break;
0204 
0205       return detIdx.rawId;
0206       break;
0207     }
0208     default:
0209       break;
0210   };
0211 
0212   return dummyDetId;
0213 }