CMS 3D CMS Logo

ErrorChecker.cc

Go to the documentation of this file.
00001 #include "EventFilter/SiPixelRawToDigi/interface/ErrorChecker.h"
00002 
00003 #include "CondFormats/SiPixelObjects/interface/SiPixelFrameConverter.h"
00004 
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00007 #include "DataFormats/FEDRawData/interface/FEDHeader.h"
00008 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00009 
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 
00012 #include <bitset>
00013 #include <sstream>
00014 #include <iostream>
00015 
00016 using namespace std;
00017 using namespace edm;
00018 using namespace sipixelobjects;
00019 
00020 const int ErrorChecker::LINK_bits = 6;
00021 const int ErrorChecker::ROC_bits  = 5;
00022 const int ErrorChecker::DCOL_bits = 5;
00023 const int ErrorChecker::PXID_bits = 8;
00024 const int ErrorChecker::ADC_bits  = 8;
00025 
00026 const int ErrorChecker::ADC_shift  = 0;
00027 const int ErrorChecker::PXID_shift = ADC_shift + ADC_bits;
00028 const int ErrorChecker::DCOL_shift = PXID_shift + PXID_bits;
00029 const int ErrorChecker::ROC_shift  = DCOL_shift + DCOL_bits;
00030 const int ErrorChecker::LINK_shift = ROC_shift + ROC_bits;
00031 
00032 const uint32_t ErrorChecker::dummyDetId = 0xffffffff;
00033 
00034 
00035 ErrorChecker::ErrorChecker() {
00036   includeErrors = false;
00037 }
00038 
00039 void ErrorChecker::setErrorStatus(bool ErrorStatus)
00040 {
00041   includeErrors = ErrorStatus;
00042 }
00043 
00044 bool ErrorChecker::checkCRC(bool& errorsInEvent, int fedId, const Word64* trailer, Errors& errors)
00045 {
00046   int CRC_bits = 1;
00047   int CRC_shift = 2;
00048   Word64 CRC_mask = ~(~Word64(0) << CRC_bits);
00049   int CRC_BIT = (*trailer >> CRC_shift) & CRC_mask;
00050   if (CRC_BIT == 0) return true;
00051   errorsInEvent = true;
00052   if (includeErrors) {
00053     int errorType = 39;
00054     SiPixelRawDataError error(*trailer, errorType, fedId);
00055     errors[dummyDetId].push_back(error);
00056   }
00057   return false;
00058 }
00059 
00060 bool ErrorChecker::checkHeader(bool& errorsInEvent, int fedId, const Word64* header, Errors& errors)
00061 {
00062   FEDHeader fedHeader( reinterpret_cast<const unsigned char*>(header));
00063   if ( !fedHeader.check() ) return false; // throw exception?
00064   if ( fedHeader.sourceID() != fedId) { 
00065     LogDebug("PixelDataFormatter::interpretRawData, fedHeader.sourceID() != fedId")
00066       <<", sourceID = " <<fedHeader.sourceID()
00067       <<", fedId = "<<fedId<<", errorType = 32"; 
00068     errorsInEvent = true;
00069     if (includeErrors) {
00070       int errorType = 32;
00071       SiPixelRawDataError error(*header, errorType, fedId);
00072       errors[dummyDetId].push_back(error);
00073     }
00074   }
00075   return fedHeader.moreHeaders();
00076 }
00077 
00078 bool ErrorChecker::checkTrailer(bool& errorsInEvent, int fedId, int nWords, const Word64* trailer, Errors& errors)
00079 {
00080   FEDTrailer fedTrailer(reinterpret_cast<const unsigned char*>(trailer));
00081   if ( !fedTrailer.check()) { 
00082     if(includeErrors) {
00083       int errorType = 33;
00084       SiPixelRawDataError error(*trailer, errorType, fedId);
00085       errors[dummyDetId].push_back(error);
00086     }
00087     errorsInEvent = true;
00088     LogError("PixelDataFormatter::interpretRawData, fedTrailer.check: ")
00089       <<"fedTrailer.check failed, Fed: " << fedId << ", errorType = 33";
00090     return false; 
00091   } 
00092   if ( fedTrailer.lenght()!= nWords) {
00093     LogError("PROBLEM in PixelDataFormatter,  fedTrailer.lenght()!= nWords !!")<< " Fed: " << fedId << ", errorType = 34";
00094     errorsInEvent = true;
00095     if(includeErrors) {
00096       int errorType = 34;
00097       SiPixelRawDataError error(*trailer, errorType, fedId);
00098       errors[dummyDetId].push_back(error);
00099     }
00100   }
00101   return fedTrailer.moreTrailers();
00102 }
00103 
00104 bool ErrorChecker::checkROC(bool& errorsInEvent, int fedId, const SiPixelFrameConverter* converter, Word32& errorWord, Errors& errors)
00105 {
00106  static const Word32 ERROR_mask = ~(~Word32(0) << ROC_bits); 
00107  int errorType = (errorWord >> ROC_shift) & ERROR_mask;
00108 
00109  switch (errorType) {
00110     case(25) : {
00111      LogDebug("")<<"  invalid ROC=25 found (errorType=25)";
00112      errorsInEvent = true;
00113      break;
00114    }
00115    case(26) : {
00116      //LogDebug("")<<"  gap word found (errorType=26)";
00117      return false;
00118    }
00119    case(27) : {
00120      //LogDebug("")<<"  dummy word found (errorType=27)";
00121      return false;
00122    }
00123    case(28) : {
00124      LogDebug("")<<"  error fifo nearly full (errorType=28)";
00125      errorsInEvent = true;
00126      break;
00127    }
00128    case(29) : {
00129      LogDebug("")<<"  timeout on a channel (errorType=29)";
00130      errorsInEvent = true;
00131      break;
00132    }
00133    case(30) : {
00134      LogDebug("")<<"  TBM error trailer (errorType=30)";
00135      errorsInEvent = true;
00136      break;
00137    }
00138    case(31) : {
00139      LogDebug("")<<"  event number error (errorType=31)";
00140      errorsInEvent = true;
00141      break;
00142    }
00143    default: return true;
00144  };
00145 
00146  if(includeErrors) {
00147    SiPixelRawDataError error(errorWord, errorType, fedId);
00148    uint32_t detId;
00149    detId = errorDetId(converter, errorType, errorWord);
00150    errors[detId].push_back(error);
00151  }
00152  return false;
00153 }
00154 
00155 void ErrorChecker::conversionError(int fedId, const SiPixelFrameConverter* converter, int status, Word32& errorWord, Errors& errors)
00156 {
00157   switch (status) {
00158   case(1) : {
00159     LogDebug("ErrorChecker::conversionError") << " Fed: " << fedId << "  invalid channel Id (errorType=35)";
00160     if(includeErrors) {
00161       int errorType = 35;
00162       SiPixelRawDataError error(errorWord, errorType, fedId);
00163       uint32_t detId = errorDetId(converter, errorType, errorWord);
00164       errors[detId].push_back(error);
00165     }
00166     break;
00167   }
00168   case(2) : {
00169     LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << "  invalid ROC Id (errorType=36)";
00170     if(includeErrors) {
00171       int errorType = 36;
00172       SiPixelRawDataError error(errorWord, errorType, fedId);
00173       uint32_t detId = errorDetId(converter, errorType, errorWord);
00174       errors[detId].push_back(error);
00175     }
00176     break;
00177   }
00178   case(3) : {
00179     LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << "  invalid dcol/pixel value (errorType=37)";
00180     if(includeErrors) {
00181       int errorType = 37;
00182       SiPixelRawDataError error(errorWord, errorType, fedId);
00183       uint32_t detId = errorDetId(converter, errorType, errorWord);
00184       errors[detId].push_back(error);
00185     }
00186     break;
00187   }
00188   case(4) : {
00189     LogDebug("ErrorChecker::conversionError")<< " Fed: " << fedId << "  dcol/pixel read out of order (errorType=38)";
00190     if(includeErrors) {
00191       int errorType = 38;
00192       SiPixelRawDataError error(errorWord, errorType, fedId);
00193       uint32_t detId = errorDetId(converter, errorType, errorWord);
00194       errors[detId].push_back(error);
00195     }
00196     break;
00197   }
00198   default: LogDebug("ErrorChecker::conversionError")<<"  cabling check returned unexpected result, status = "<< status;
00199   };
00200 }
00201 
00202 // this function finds the detId for an error word, which cannot be processed in word2digi
00203 uint32_t ErrorChecker::errorDetId(const SiPixelFrameConverter* converter, 
00204     int errorType, const Word32 & word) const
00205 {
00206   if (!converter) return dummyDetId;
00207 
00208   ElectronicIndex cabling;
00209 
00210   static const Word32 LINK_mask = ~(~Word32(0) << LINK_bits);
00211   static const Word32 ROC_mask  = ~(~Word32(0) << ROC_bits);
00212   static const Word32 DCOL_mask = ~(~Word32(0) << DCOL_bits);
00213   static const Word32 PXID_mask = ~(~Word32(0) << PXID_bits);
00214 
00215   switch (errorType) {
00216     case  30 : case  31: case  36: {
00217       // set dummy values for cabling just to get detId from link if in Barrel
00218       cabling.dcol = 0;
00219       cabling.pxid = 2;
00220       cabling.roc  = 1;
00221       cabling.link = (word >> LINK_shift) & LINK_mask;  
00222 
00223       DetectorIndex detIdx;
00224       int status = converter->toDetector(cabling, detIdx);
00225       
00226       if(DetId::DetId(detIdx.rawId).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) return detIdx.rawId;
00227       break;
00228     }
00229     case  37 : case  38: {
00230       cabling.dcol = 0;
00231       cabling.pxid = 2;
00232       cabling.roc  = (word >> ROC_shift) & ROC_mask;
00233       cabling.link = (word >> LINK_shift) & LINK_mask;
00234 
00235       DetectorIndex detIdx;
00236       int status = converter->toDetector(cabling, detIdx);
00237 
00238       return detIdx.rawId;
00239       break;
00240     }
00241   default : break;
00242   };
00243   return dummyDetId;
00244 }

Generated on Tue Jun 9 17:34:49 2009 for CMSSW by  doxygen 1.5.4