Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-06 23:49:39

0001 #include "EventFilter/SiPixelRawToDigi/interface/ErrorCheckerBase.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 ErrorCheckerBase::ErrorCheckerBase() : includeErrors_(false) {}
0022 
0023 void ErrorCheckerBase::setErrorStatus(bool ErrorStatus) { includeErrors_ = ErrorStatus; }
0024 
0025 void ErrorCheckerBase::addErrorToCollectionDummy(int errorType,
0026                                                  int fedId,
0027                                                  Word64 word,
0028                                                  SiPixelFormatterErrors& errors) const {
0029   if (includeErrors_) {
0030     SiPixelRawDataError error(word, errorType, fedId);
0031     errors[sipixelconstants::dummyDetId].push_back(error);
0032   }
0033 }
0034 
0035 bool ErrorCheckerBase::checkCRC(bool& errorsInEvent,
0036                                 int fedId,
0037                                 const Word64* trailer,
0038                                 SiPixelFormatterErrors& errors) const {
0039   const int CRC_BIT = (*trailer >> CRC_shift) & CRC_mask;
0040   const bool isCRCcorrect = (CRC_BIT == 0);
0041   if (!isCRCcorrect)
0042     addErrorToCollectionDummy(39, fedId, *trailer, errors);
0043   errorsInEvent = (errorsInEvent || !isCRCcorrect);
0044   return isCRCcorrect;
0045 }
0046 
0047 bool ErrorCheckerBase::checkHeader(bool& errorsInEvent,
0048                                    int fedId,
0049                                    const Word64* header,
0050                                    SiPixelFormatterErrors& errors) const {
0051   FEDHeader fedHeader(reinterpret_cast<const unsigned char*>(header));
0052   const bool fedHeaderCorrect = fedHeader.check();
0053   // if not fedHeaderCorrect throw exception?
0054   if (fedHeaderCorrect && (fedHeader.sourceID() != fedId)) {
0055     int errorType = 32;
0056     addErrorToCollectionDummy(errorType, fedId, *header, errors);
0057     LogDebug("PixelDataFormatter::interpretRawData, fedHeader.sourceID() != fedId")
0058         << ", sourceID = " << fedHeader.sourceID() << ", fedId = " << fedId << ", errorType = " << errorType;
0059     errorsInEvent = true;
0060   }
0061   return fedHeaderCorrect && fedHeader.moreHeaders();
0062 }
0063 
0064 bool ErrorCheckerBase::checkTrailer(
0065     bool& errorsInEvent, int fedId, unsigned int nWords, const Word64* trailer, SiPixelFormatterErrors& errors) const {
0066   FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
0067   const bool fedTrailerCorrect = fedTrailer.check();
0068   if (!fedTrailerCorrect) {
0069     int errorType = 33;
0070     addErrorToCollectionDummy(errorType, fedId, *trailer, errors);
0071     LogError("FedTrailerCheck") << "fedTrailer.check failed, Fed: " << fedId << ", errorType = " << errorType;
0072     errorsInEvent = true;
0073   } else if (fedTrailer.fragmentLength() != nWords) {
0074     int errorType = 34;
0075     addErrorToCollectionDummy(errorType, fedId, *trailer, errors);
0076     LogError("FedTrailerLenght") << "fedTrailer.fragmentLength()!= nWords !! Fed: " << fedId
0077                                  << ", errorType = " << errorType;
0078     errorsInEvent = true;
0079   }
0080   return fedTrailerCorrect && fedTrailer.moreTrailers();
0081 }
0082 
0083 void ErrorCheckerBase::conversionError(int fedId,
0084                                        const SiPixelFrameConverter* converter,
0085                                        int status,
0086                                        Word32& errorWord,
0087                                        SiPixelFormatterErrors& errors) const {
0088   const int errorType = getConversionErrorTypeAndIssueLogMessage(status, fedId);
0089   // errorType == 0 means unexpected error, in this case we don't include it in the error collection
0090   if (errorType && includeErrors_) {
0091     SiPixelRawDataError error(errorWord, errorType, fedId);
0092     cms_uint32_t detId = errorDetId(converter, errorType, errorWord);
0093     errors[detId].push_back(error);
0094   }
0095 }
0096 
0097 int ErrorCheckerBase::getConversionErrorTypeAndIssueLogMessage(int status, int fedId) const {
0098   int errorType = 0;
0099   std::string debugMessage;
0100   switch (status) {
0101     case (1): {
0102       debugMessage = "invalid channel Id";
0103       errorType = 35;
0104       break;
0105     }
0106     case (2): {
0107       debugMessage = "invalid ROC Id";
0108       errorType = 36;
0109       break;
0110     }
0111     case (3): {
0112       debugMessage = "invalid dcol/pixel value";
0113       errorType = 37;
0114       break;
0115     }
0116     case (4): {
0117       debugMessage = "dcol/pixel read out of order";
0118       errorType = 38;
0119       break;
0120     }
0121   };
0122   if (errorType) {
0123     LogDebug("ErrorChecker::conversionError") << "Fed:" << fedId << debugMessage << "(errorType =" << errorType << ")";
0124   } else {
0125     LogDebug("ErrorChecker::conversionError") << "cabling check returned unexpected result, status =" << status;
0126   }
0127   return errorType;
0128 }