Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:11:19

0001 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
0002 #include "DQM/SiPixelMonitorRawData/interface/SiPixelRawDataErrorModule.h"
0003 #include "DQMServices/Core/interface/DQMStore.h"
0004 // Framework
0005 #include "FWCore/ServiceRegistry/interface/Service.h"
0006 // STL
0007 #include <cstdlib>
0008 #include <iostream>
0009 #include <memory>
0010 #include <sstream>
0011 #include <string>
0012 #include <vector>
0013 
0014 // Data Formats
0015 #include "DataFormats/DetId/interface/DetId.h"
0016 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0017 #include "DataFormats/SiPixelDetId/interface/PixelBarrelNameUpgrade.h"
0018 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0019 #include "DataFormats/SiPixelDetId/interface/PixelEndcapNameUpgrade.h"
0020 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
0021 
0022 using namespace std;
0023 
0024 const int SiPixelRawDataErrorModule::LINK_bits = 6;
0025 const int SiPixelRawDataErrorModule::ROC_bits = 5;
0026 const int SiPixelRawDataErrorModule::DCOL_bits = 5;
0027 const int SiPixelRawDataErrorModule::PXID_bits = 8;
0028 const int SiPixelRawDataErrorModule::ADC_bits = 8;
0029 const int SiPixelRawDataErrorModule::DataBit_bits = 1;
0030 
0031 const int SiPixelRawDataErrorModule::ADC_shift = 0;
0032 const int SiPixelRawDataErrorModule::PXID_shift = ADC_shift + ADC_bits;
0033 const int SiPixelRawDataErrorModule::DCOL_shift = PXID_shift + PXID_bits;
0034 const int SiPixelRawDataErrorModule::ROC_shift = DCOL_shift + DCOL_bits;
0035 const int SiPixelRawDataErrorModule::LINK_shift = ROC_shift + ROC_bits;
0036 const int SiPixelRawDataErrorModule::DB0_shift = 0;
0037 const int SiPixelRawDataErrorModule::DB1_shift = DB0_shift + DataBit_bits;
0038 const int SiPixelRawDataErrorModule::DB2_shift = DB1_shift + DataBit_bits;
0039 const int SiPixelRawDataErrorModule::DB3_shift = DB2_shift + DataBit_bits;
0040 const int SiPixelRawDataErrorModule::DB4_shift = DB3_shift + DataBit_bits;
0041 const int SiPixelRawDataErrorModule::DB5_shift = DB4_shift + DataBit_bits;
0042 const int SiPixelRawDataErrorModule::DB6_shift = DB5_shift + DataBit_bits;
0043 const int SiPixelRawDataErrorModule::DB7_shift = DB6_shift + DataBit_bits;
0044 
0045 const uint32_t SiPixelRawDataErrorModule::LINK_mask = ~(~uint32_t(0) << LINK_bits);
0046 const uint32_t SiPixelRawDataErrorModule::ROC_mask = ~(~uint32_t(0) << ROC_bits);
0047 const uint32_t SiPixelRawDataErrorModule::DCOL_mask = ~(~uint32_t(0) << DCOL_bits);
0048 const uint32_t SiPixelRawDataErrorModule::PXID_mask = ~(~uint32_t(0) << PXID_bits);
0049 const uint32_t SiPixelRawDataErrorModule::ADC_mask = ~(~uint32_t(0) << ADC_bits);
0050 const uint32_t SiPixelRawDataErrorModule::DataBit_mask = ~(~uint32_t(0) << DataBit_bits);
0051 
0052 const int SiPixelRawDataErrorModule::TRLRBGN_bits = 32;
0053 const int SiPixelRawDataErrorModule::EVTLGT_bits = 24;
0054 const int SiPixelRawDataErrorModule::TRLREND_bits = 8;
0055 
0056 const int SiPixelRawDataErrorModule::TRLRBGN_shift = 0;
0057 const int SiPixelRawDataErrorModule::EVTLGT_shift = TRLRBGN_shift + TRLRBGN_bits;
0058 const int SiPixelRawDataErrorModule::TRLREND_shift = EVTLGT_shift + EVTLGT_bits;
0059 
0060 const unsigned long long SiPixelRawDataErrorModule::TRLREND_mask = ~(~0ULL << TRLREND_bits);
0061 const unsigned long long SiPixelRawDataErrorModule::EVTLGT_mask = ~(~0ULL << EVTLGT_bits);
0062 const unsigned long long SiPixelRawDataErrorModule::TRLRBGN_mask = ~(~0ULL << TRLRBGN_bits);
0063 //
0064 // Constructors
0065 //
0066 SiPixelRawDataErrorModule::SiPixelRawDataErrorModule() : id_(0), ncols_(416), nrows_(160) { _debug_ = false; }
0067 //
0068 SiPixelRawDataErrorModule::SiPixelRawDataErrorModule(const uint32_t &id) : id_(id), ncols_(416), nrows_(160) {
0069   _debug_ = false;
0070 }
0071 //
0072 SiPixelRawDataErrorModule::SiPixelRawDataErrorModule(const uint32_t &id, const int &ncols, const int &nrows)
0073     : id_(id), ncols_(ncols), nrows_(nrows) {
0074   _debug_ = false;
0075 }
0076 //
0077 // Destructor
0078 //
0079 SiPixelRawDataErrorModule::~SiPixelRawDataErrorModule() {}
0080 //
0081 // Book histograms for errors with detId
0082 //
0083 void SiPixelRawDataErrorModule::book(const edm::ParameterSet &iConfig,
0084                                      DQMStore::IBooker &iBooker,
0085                                      int type,
0086                                      bool isUpgrade) {}
0087 //
0088 // Fill histograms
0089 //
0090 int SiPixelRawDataErrorModule::fill(const edm::DetSetVector<SiPixelRawDataError> &input,
0091                                     std::map<std::string, MonitorElement **> *meMapFEDs,
0092                                     bool modon,
0093                                     bool ladon,
0094                                     bool bladeon) {
0095   bool barrel = DetId(id_).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
0096   bool endcap = DetId(id_).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
0097 
0098   // Get DQM interface
0099 
0100   unsigned int numberOfSeriousErrors = 0;
0101 
0102   edm::DetSetVector<SiPixelRawDataError>::const_iterator isearch = input.find(id_);  // search  errors of detid
0103 
0104   if (isearch != input.end()) {  // Not at empty iterator
0105     // Look at errors now
0106     edm::DetSet<SiPixelRawDataError>::const_iterator di;
0107     for (di = isearch->data.begin(); di != isearch->data.end(); di++) {
0108       int FedId = di->getFedId();  // FED the error came from
0109       int chanNmbr = 0;
0110       int errorType = di->getType();  // type of error
0111       int TBMType = -1;
0112       int TBMMessage = -1;
0113       int evtSize = -1;
0114       int evtNbr = -1;
0115       int fullType = -1;
0116       bool notReset = true;
0117       const int LINK_bits = 6;
0118       const int LINK_shift = 26;
0119       const uint32_t LINK_mask = ~(~(uint32_t)(0) << LINK_bits);
0120 
0121       if (modon) {
0122         if (errorType == 32 || errorType == 33 || errorType == 34) {
0123           long long errorWord = di->getWord64();  // for 64-bit error words
0124           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0125           if (errorType == 34)
0126             evtSize = (errorWord >> EVTLGT_shift) & EVTLGT_mask;
0127         } else {
0128           uint32_t errorWord = di->getWord32();              // for 32-bit error words
0129           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;  // default way to get channel number.  Only
0130                                                              // different for case 29 below.
0131           switch (errorType) {                               // fill in the appropriate monitorables based on
0132                                                              // the information stored in the error word
0133             case (28): {
0134               int NFa = (errorWord >> DB0_shift) & DataBit_mask;
0135               int NFb = (errorWord >> DB1_shift) & DataBit_mask;
0136               int NFc = (errorWord >> DB2_shift) & DataBit_mask;
0137               int NFd = (errorWord >> DB3_shift) & DataBit_mask;
0138               int NFe = (errorWord >> DB4_shift) & DataBit_mask;
0139               int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
0140               int L1A = (errorWord >> DB7_shift) & DataBit_mask;
0141               if (NFa == 1) {
0142                 fullType = 1;
0143                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0144               }
0145               if (NFb == 1) {
0146                 fullType = 2;
0147                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0148               }
0149               if (NFc == 1) {
0150                 fullType = 3;
0151                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0152               }
0153               if (NFd == 1) {
0154                 fullType = 4;
0155                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0156               }
0157               if (NFe == 1) {
0158                 fullType = 5;
0159                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0160               }
0161               if (NF2 == 1) {
0162                 fullType = 6;
0163                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0164               }
0165               if (L1A == 1) {
0166                 fullType = 7;
0167                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0168               }
0169               chanNmbr = 0;  // signifies channel not known
0170               break;
0171             }
0172             case (29): {
0173               int CH1 = (errorWord >> DB0_shift) & DataBit_mask;
0174               int CH2 = (errorWord >> DB1_shift) & DataBit_mask;
0175               int CH3 = (errorWord >> DB2_shift) & DataBit_mask;
0176               int CH4 = (errorWord >> DB3_shift) & DataBit_mask;
0177               int CH5 = (errorWord >> DB4_shift) & DataBit_mask;
0178               int BLOCK_bits = 3;
0179               int BLOCK_shift = 8;
0180               uint32_t BLOCK_mask = ~(~uint32_t(0) << BLOCK_bits);
0181               int BLOCK = (errorWord >> BLOCK_shift) & BLOCK_mask;
0182               int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
0183               if (BLOCK % 2 == 0)
0184                 chanNmbr = (BLOCK / 2) * 9 + localCH;
0185               else
0186                 chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
0187               if ((chanNmbr < 1) || (chanNmbr > 36))
0188                 chanNmbr = 0;  // signifies unexpected result
0189               break;
0190             }
0191             case (30): {
0192               int T0 = (errorWord >> DB0_shift) & DataBit_mask;
0193               int T1 = (errorWord >> DB1_shift) & DataBit_mask;
0194               int T2 = (errorWord >> DB2_shift) & DataBit_mask;
0195               int T3 = (errorWord >> DB3_shift) & DataBit_mask;
0196               int T4 = (errorWord >> DB4_shift) & DataBit_mask;
0197               int T5 = (errorWord >> DB5_shift) & DataBit_mask;
0198               int T6 = (errorWord >> DB6_shift) & DataBit_mask;
0199               int T7 = (errorWord >> DB7_shift) & DataBit_mask;
0200               if (T0 == 1)
0201                 TBMMessage = 0;
0202               if (T1 == 1)
0203                 TBMMessage = 1;
0204               if (T2 == 1)
0205                 TBMMessage = 2;
0206               if (T3 == 1)
0207                 TBMMessage = 3;
0208               if (T4 == 1)
0209                 TBMMessage = 4;
0210               if (T5 == 1)
0211                 TBMMessage = 5;
0212               if (T6 == 1)
0213                 TBMMessage = 6;
0214               if (T7 == 1)
0215                 TBMMessage = 7;
0216               if (TBMMessage == 5 || TBMMessage == 6)
0217                 notReset = false;
0218               int StateMach_bits = 4;
0219               int StateMach_shift = 8;
0220               uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
0221               int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
0222               switch (StateMach) {
0223                 case (0): {
0224                   TBMType = 0;
0225                   break;
0226                 }
0227                 case (1):
0228                 case (9): {
0229                   TBMType = 1;
0230                   break;
0231                 }
0232                 case (2):
0233                 case (4):
0234                 case (6): {
0235                   TBMType = 2;
0236                   break;
0237                 }
0238                 case (8): {
0239                   TBMType = 3;
0240                   break;
0241                 }
0242                 default:
0243                   TBMType = 4;
0244               };
0245               break;
0246             }
0247             case (31): {
0248               evtNbr = (errorWord >> ADC_shift) & ADC_mask;
0249               break;
0250             }
0251             case (36): {
0252               // ROCId = (errorWord >> ROC_shift) & ROC_mask;
0253               break;
0254             }
0255             case (37): {
0256               // DCOLId = (errorWord >> DCOL_shift) & DCOL_mask;
0257               // PXId = (errorWord >> PXID_shift) & PXID_mask;
0258               break;
0259             }
0260             case (38): {
0261               // ROCNmbr = (errorWord >> ROC_shift) & ROC_mask;
0262               break;
0263             }
0264             default:
0265               break;
0266           };
0267         }  // end if not double precision
0268       }    // end if modon
0269 
0270       if (ladon && barrel) {
0271         if (errorType == 32 || errorType == 33 || errorType == 34) {
0272           long long errorWord = di->getWord64();  // for 64-bit error words
0273           if (errorType == 34)
0274             evtSize = (errorWord >> EVTLGT_shift) & EVTLGT_mask;
0275           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0276         } else {
0277           uint32_t errorWord = di->getWord32();  // for 32-bit error words
0278           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0279           switch (errorType) {  // fill in the appropriate monitorables based on
0280                                 // the information stored in the error word
0281             case (28): {
0282               int NFa = (errorWord >> DB0_shift) & DataBit_mask;
0283               int NFb = (errorWord >> DB1_shift) & DataBit_mask;
0284               int NFc = (errorWord >> DB2_shift) & DataBit_mask;
0285               int NFd = (errorWord >> DB3_shift) & DataBit_mask;
0286               int NFe = (errorWord >> DB4_shift) & DataBit_mask;
0287               int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
0288               int L1A = (errorWord >> DB7_shift) & DataBit_mask;
0289               if (NFa == 1) {
0290                 fullType = 1;
0291                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0292               }
0293               if (NFb == 1) {
0294                 fullType = 2;
0295                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0296               }
0297               if (NFc == 1) {
0298                 fullType = 3;
0299                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0300               }
0301               if (NFd == 1) {
0302                 fullType = 4;
0303                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0304               }
0305               if (NFe == 1) {
0306                 fullType = 5;
0307                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0308               }
0309               if (NF2 == 1) {
0310                 fullType = 6;
0311                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0312               }
0313               if (L1A == 1) {
0314                 fullType = 7;
0315                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0316               }
0317               chanNmbr = 0;
0318               break;
0319             }
0320             case (29): {
0321               int CH1 = (errorWord >> DB0_shift) & DataBit_mask;
0322               int CH2 = (errorWord >> DB1_shift) & DataBit_mask;
0323               int CH3 = (errorWord >> DB2_shift) & DataBit_mask;
0324               int CH4 = (errorWord >> DB3_shift) & DataBit_mask;
0325               int CH5 = (errorWord >> DB4_shift) & DataBit_mask;
0326               int BLOCK_bits = 3;
0327               int BLOCK_shift = 8;
0328               uint32_t BLOCK_mask = ~(~uint32_t(0) << BLOCK_bits);
0329               int BLOCK = (errorWord >> BLOCK_shift) & BLOCK_mask;
0330               int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
0331               if (BLOCK % 2 == 0)
0332                 chanNmbr = (BLOCK / 2) * 9 + localCH;
0333               else
0334                 chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
0335               if ((chanNmbr < 1) || (chanNmbr > 36))
0336                 chanNmbr = 0;  // signifies unexpected result
0337               break;
0338             }
0339             case (30): {
0340               int T0 = (errorWord >> DB0_shift) & DataBit_mask;
0341               int T1 = (errorWord >> DB1_shift) & DataBit_mask;
0342               int T2 = (errorWord >> DB2_shift) & DataBit_mask;
0343               int T3 = (errorWord >> DB3_shift) & DataBit_mask;
0344               int T4 = (errorWord >> DB4_shift) & DataBit_mask;
0345               int T5 = (errorWord >> DB5_shift) & DataBit_mask;
0346               int T6 = (errorWord >> DB6_shift) & DataBit_mask;
0347               int T7 = (errorWord >> DB7_shift) & DataBit_mask;
0348               if (T0 == 1)
0349                 TBMMessage = 0;
0350               if (T1 == 1)
0351                 TBMMessage = 1;
0352               if (T2 == 1)
0353                 TBMMessage = 2;
0354               if (T3 == 1)
0355                 TBMMessage = 3;
0356               if (T4 == 1)
0357                 TBMMessage = 4;
0358               if (T5 == 1)
0359                 TBMMessage = 5;
0360               if (T6 == 1)
0361                 TBMMessage = 6;
0362               if (T7 == 1)
0363                 TBMMessage = 7;
0364               int StateMach_bits = 4;
0365               int StateMach_shift = 8;
0366               uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
0367               int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
0368               switch (StateMach) {
0369                 case (0): {
0370                   TBMType = 0;
0371                   break;
0372                 }
0373                 case (1):
0374                 case (9): {
0375                   TBMType = 1;
0376                   break;
0377                 }
0378                 case (2):
0379                 case (4):
0380                 case (6): {
0381                   TBMType = 2;
0382                   break;
0383                 }
0384                 case (8): {
0385                   TBMType = 3;
0386                   break;
0387                 }
0388                 default:
0389                   TBMType = 4;
0390               };
0391               break;
0392             }
0393             case (31): {
0394               evtNbr = (errorWord >> ADC_shift) & ADC_mask;
0395               break;
0396             }
0397             case (36): {
0398               // int ROCId = (errorWord >> ROC_shift) & ROC_mask;
0399               break;
0400             }
0401             case (37): {
0402               // int DCOLId = (errorWord >> DCOL_shift) & DCOL_mask;
0403               // int PXId = (errorWord >> PXID_shift) & PXID_mask;
0404               break;
0405             }
0406             case (38): {
0407               // int ROCNmbr = (errorWord >> ROC_shift) & ROC_mask;
0408               break;
0409             }
0410             default:
0411               break;
0412           };
0413         }
0414       }  // end if ladderon
0415 
0416       if (bladeon && endcap) {
0417         if (errorType == 32 || errorType == 33 || errorType == 34) {
0418           long long errorWord = di->getWord64();  // for 64-bit error words
0419           if (errorType == 34)
0420             evtSize = (errorWord >> EVTLGT_shift) & EVTLGT_mask;
0421           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0422         } else {
0423           uint32_t errorWord = di->getWord32();  // for 32-bit error words
0424           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0425           switch (errorType) {  // fill in the appropriate monitorables based on
0426                                 // the information stored in the error word
0427             case (28): {
0428               int NFa = (errorWord >> DB0_shift) & DataBit_mask;
0429               int NFb = (errorWord >> DB1_shift) & DataBit_mask;
0430               int NFc = (errorWord >> DB2_shift) & DataBit_mask;
0431               int NFd = (errorWord >> DB3_shift) & DataBit_mask;
0432               int NFe = (errorWord >> DB4_shift) & DataBit_mask;
0433               int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
0434               int L1A = (errorWord >> DB7_shift) & DataBit_mask;
0435               if (NFa == 1) {
0436                 fullType = 1;
0437                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0438               }
0439               if (NFb == 1) {
0440                 fullType = 2;
0441                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0442               }
0443               if (NFc == 1) {
0444                 fullType = 3;
0445                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0446               }
0447               if (NFd == 1) {
0448                 fullType = 4;
0449                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0450               }
0451               if (NFe == 1) {
0452                 fullType = 5;
0453                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0454               }
0455               if (NF2 == 1) {
0456                 fullType = 6;
0457                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0458               }
0459               if (L1A == 1) {
0460                 fullType = 7;
0461                 ((*meMapFEDs)["meFullType_"][FedId])->Fill((int)fullType);
0462               }
0463               chanNmbr = 0;
0464               break;
0465             }
0466             case (29): {
0467               int CH1 = (errorWord >> DB0_shift) & DataBit_mask;
0468               int CH2 = (errorWord >> DB1_shift) & DataBit_mask;
0469               int CH3 = (errorWord >> DB2_shift) & DataBit_mask;
0470               int CH4 = (errorWord >> DB3_shift) & DataBit_mask;
0471               int CH5 = (errorWord >> DB4_shift) & DataBit_mask;
0472               int BLOCK_bits = 3;
0473               int BLOCK_shift = 8;
0474               uint32_t BLOCK_mask = ~(~uint32_t(0) << BLOCK_bits);
0475               int BLOCK = (errorWord >> BLOCK_shift) & BLOCK_mask;
0476               int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
0477               if (BLOCK % 2 == 0)
0478                 chanNmbr = (BLOCK / 2) * 9 + localCH;
0479               else
0480                 chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
0481               if ((chanNmbr < 1) || (chanNmbr > 36))
0482                 chanNmbr = 0;  // signifies unexpected result
0483               break;
0484             }
0485             case (30): {
0486               int T0 = (errorWord >> DB0_shift) & DataBit_mask;
0487               int T1 = (errorWord >> DB1_shift) & DataBit_mask;
0488               int T2 = (errorWord >> DB2_shift) & DataBit_mask;
0489               int T3 = (errorWord >> DB3_shift) & DataBit_mask;
0490               int T4 = (errorWord >> DB4_shift) & DataBit_mask;
0491               int T5 = (errorWord >> DB5_shift) & DataBit_mask;
0492               int T6 = (errorWord >> DB6_shift) & DataBit_mask;
0493               int T7 = (errorWord >> DB7_shift) & DataBit_mask;
0494               if (T0 == 1)
0495                 TBMMessage = 0;
0496               if (T1 == 1)
0497                 TBMMessage = 1;
0498               if (T2 == 1)
0499                 TBMMessage = 2;
0500               if (T3 == 1)
0501                 TBMMessage = 3;
0502               if (T4 == 1)
0503                 TBMMessage = 4;
0504               if (T5 == 1)
0505                 TBMMessage = 5;
0506               if (T6 == 1)
0507                 TBMMessage = 6;
0508               if (T7 == 1)
0509                 TBMMessage = 7;
0510               int StateMach_bits = 4;
0511               int StateMach_shift = 8;
0512               uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
0513               int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
0514               switch (StateMach) {
0515                 case (0): {
0516                   TBMType = 0;
0517                   break;
0518                 }
0519                 case (1):
0520                 case (9): {
0521                   TBMType = 1;
0522                   break;
0523                 }
0524                 case (2):
0525                 case (4):
0526                 case (6): {
0527                   TBMType = 2;
0528                   break;
0529                 }
0530                 case (8): {
0531                   TBMType = 3;
0532                   break;
0533                 }
0534                 default:
0535                   TBMType = 4;
0536               };
0537               break;
0538             }
0539             case (31): {
0540               evtNbr = (errorWord >> ADC_shift) & ADC_mask;
0541               break;
0542             }
0543             case (36): {
0544               // int ROCId = (errorWord >> ROC_shift) & ROC_mask;
0545               break;
0546             }
0547             case (37): {
0548               // int DCOLId = (errorWord >> DCOL_shift) & DCOL_mask;
0549               // int PXId = (errorWord >> PXID_shift) & PXID_mask;
0550               break;
0551             }
0552             case (38): {
0553               // int ROCNmbr = (errorWord >> ROC_shift) & ROC_mask;
0554               break;
0555             }
0556             default:
0557               break;
0558           };
0559         }
0560       }  // end if bladeon
0561 
0562       // Example to mask a specific bad channel -->
0563       // if(!(FedId==38&&chanNmbr==7)){
0564       if (!(errorType == 30) || notReset) {
0565         std::string hid;
0566         static const char chNfmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChNErr_%d";
0567         char chNbuf[sizeof(chNfmt) + 2 * 32];  // 32 digits is enough for up to 2^105 + sign.
0568         sprintf(chNbuf, chNfmt, FedId, chanNmbr);
0569         hid = chNbuf;
0570         if ((*meMapFEDs)["meFedChNErr_"][FedId])
0571           (*meMapFEDs)["meFedChNErr_"][FedId]->Fill(chanNmbr);
0572 
0573         static const char chLfmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChLErr_%d";
0574         char chLbuf[sizeof(chLfmt) + 2 * 32];  // 32 digits is enough for up to 2^105 + sign.
0575         sprintf(chLbuf, chLfmt, FedId, chanNmbr);
0576         hid = chLbuf;
0577         if ((*meMapFEDs)["meFedChLErr_"][FedId])
0578           (*meMapFEDs)["meFedChLErr_"][FedId]->setBinContent(chanNmbr + 1, errorType);
0579 
0580         numberOfSeriousErrors++;
0581         int messageType = 99;
0582         if (errorType < 30)
0583           messageType = errorType - 25;
0584         else if (errorType > 30)
0585           messageType = errorType - 19;
0586         else if (errorType == 30 && TBMMessage == 0)
0587           messageType = errorType - 25;
0588         else if (errorType == 30 && TBMMessage == 1)
0589           messageType = errorType - 24;
0590         else if (errorType == 30 && (TBMMessage == 2 || TBMMessage == 3 || TBMMessage == 4))
0591           messageType = errorType - 23;
0592         else if (errorType == 30 && TBMMessage == 7)
0593           messageType = errorType - 22;
0594         else if (errorType == 30 && TBMType == 1)
0595           messageType = errorType - 21;
0596         else if (errorType == 30 && TBMType == 2)
0597           messageType = errorType - 20;
0598         else if (errorType == 30 && TBMType == 3)
0599           messageType = errorType - 19;
0600         if (messageType <= 20) {
0601           static const char fmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedETypeNErr_%d";
0602           char buf[sizeof(fmt) + 2 * 32];  // 32 digits is enough for up to 2^105 + sign.
0603           sprintf(buf, fmt, FedId, messageType);
0604           hid = buf;
0605           if ((*meMapFEDs)["meFedETypeNErr_"][FedId])
0606             (*meMapFEDs)["meFedETypeNErr_"][FedId]->Fill(messageType);
0607         }
0608       }
0609 
0610       (*meMapFEDs)["meNErrors_"][FedId]->Fill((int)numberOfSeriousErrors);
0611       (*meMapFEDs)["meTBMMessage_"][FedId]->Fill((int)TBMMessage);
0612       (*meMapFEDs)["meTBMType_"][FedId]->Fill((int)TBMType);
0613       (*meMapFEDs)["meErrorType_"][FedId]->Fill((int)errorType);
0614       (*meMapFEDs)["meFullType_"][FedId]->Fill((int)fullType);
0615       (*meMapFEDs)["meEvtNbr_"][FedId]->setBinContent(1, (int)evtNbr);
0616       (*meMapFEDs)["meEvtSize_"][FedId]->setBinContent(1, (int)evtSize);
0617     }
0618   }  // end if not an empty iterator
0619   return numberOfSeriousErrors;
0620 }
0621 
0622 int SiPixelRawDataErrorModule::fillFED(const edm::DetSetVector<SiPixelRawDataError> &input,
0623                                        std::map<std::string, MonitorElement **> *meMapFEDs) {
0624   unsigned int numberOfSeriousErrors = 0;
0625 
0626   edm::DetSetVector<SiPixelRawDataError>::const_iterator isearch = input.find(0xffffffff);  // search  errors of detid
0627   if (isearch != input.end()) {                                                             // Not an empty iterator
0628     // Look at FED errors now
0629     edm::DetSet<SiPixelRawDataError>::const_iterator di;
0630     for (di = isearch->data.begin(); di != isearch->data.end(); di++) {
0631       int FedId = di->getFedId();  // FED the error came from
0632       int chanNmbr = -1;
0633       int errorType = 0;  // type of error
0634       if (FedId == static_cast<int>(id_)) {
0635         errorType = di->getType();  // type of error
0636         ((*meMapFEDs)["meErrorType_"][id_])->Fill((int)errorType);
0637         bool notReset = true;
0638         int TBMType = -1;
0639         int TBMMessage = -1;
0640         int evtSize = -1;
0641         int fullType = -1;
0642         const int LINK_bits = 6;
0643         const int LINK_shift = 26;
0644         const uint32_t LINK_mask = ~(~(uint32_t)(0) << LINK_bits);
0645         if ((errorType == 32) || (errorType == 33) || (errorType == 34)) {
0646           long long errorWord = di->getWord64();  // for 64-bit error words
0647           chanNmbr = 0;
0648           switch (errorType) {  // fill in the appropriate monitorables based on
0649                                 // the information stored in the error word
0650             case (32): {
0651               break;
0652             }
0653             case (33): {
0654               break;
0655             }
0656             case (34): {
0657               evtSize = (errorWord >> EVTLGT_shift) & EVTLGT_mask;
0658               ((*meMapFEDs)["meEvtSize_"][id_])->setBinContent(1, (int)evtSize);
0659               break;
0660             }
0661             default:
0662               break;
0663           };
0664         } else {
0665           uint32_t errorWord = di->getWord32();  // for 32-bit error words
0666           switch (errorType) {                   // fill in the appropriate monitorables based on
0667                                                  // the information stored in the error word
0668             case (25):
0669             case (39): {
0670               chanNmbr = 0;
0671               break;
0672             }
0673             case (28): {
0674               int NFa = (errorWord >> DB0_shift) & DataBit_mask;
0675               int NFb = (errorWord >> DB1_shift) & DataBit_mask;
0676               int NFc = (errorWord >> DB2_shift) & DataBit_mask;
0677               int NFd = (errorWord >> DB3_shift) & DataBit_mask;
0678               int NFe = (errorWord >> DB4_shift) & DataBit_mask;
0679               int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
0680               int L1A = (errorWord >> DB7_shift) & DataBit_mask;
0681               if (NFa == 1) {
0682                 fullType = 1;
0683                 ((*meMapFEDs)["meFullType_"][id_])->Fill((int)fullType);
0684               }
0685               if (NFb == 1) {
0686                 fullType = 2;
0687                 ((*meMapFEDs)["meFullType_"][id_])->Fill((int)fullType);
0688               }
0689               if (NFc == 1) {
0690                 fullType = 3;
0691                 ((*meMapFEDs)["meFullType_"][id_])->Fill((int)fullType);
0692               }
0693               if (NFd == 1) {
0694                 fullType = 4;
0695                 ((*meMapFEDs)["meFullType_"][id_])->Fill((int)fullType);
0696               }
0697               if (NFe == 1) {
0698                 fullType = 5;
0699                 ((*meMapFEDs)["meFullType_"][id_])->Fill((int)fullType);
0700               }
0701               if (NF2 == 1) {
0702                 fullType = 6;
0703                 ((*meMapFEDs)["meFullType_"][id_])->Fill((int)fullType);
0704               }
0705               if (L1A == 1) {
0706                 fullType = 7;
0707                 ((*meMapFEDs)["meFullType_"][id_])->Fill((int)fullType);
0708               }
0709               chanNmbr = 0;
0710               break;
0711             }
0712             case (29): {
0713               int CH1 = (errorWord >> DB0_shift) & DataBit_mask;
0714               int CH2 = (errorWord >> DB1_shift) & DataBit_mask;
0715               int CH3 = (errorWord >> DB2_shift) & DataBit_mask;
0716               int CH4 = (errorWord >> DB3_shift) & DataBit_mask;
0717               int CH5 = (errorWord >> DB4_shift) & DataBit_mask;
0718               int BLOCK_bits = 3;
0719               int BLOCK_shift = 8;
0720               uint32_t BLOCK_mask = ~(~uint32_t(0) << BLOCK_bits);
0721               int BLOCK = (errorWord >> BLOCK_shift) & BLOCK_mask;
0722               int localCH = 1 * CH1 + 2 * CH2 + 3 * CH3 + 4 * CH4 + 5 * CH5;
0723               if (BLOCK % 2 == 0)
0724                 chanNmbr = (BLOCK / 2) * 9 + localCH;
0725               else
0726                 chanNmbr = ((BLOCK - 1) / 2) * 9 + 4 + localCH;
0727               if ((chanNmbr < 1) || (chanNmbr > 36))
0728                 chanNmbr = 0;  // signifies unexpected result
0729               break;
0730             }
0731             case (30): {
0732               int T0 = (errorWord >> DB0_shift) & DataBit_mask;
0733               int T1 = (errorWord >> DB1_shift) & DataBit_mask;
0734               int T2 = (errorWord >> DB2_shift) & DataBit_mask;
0735               int T3 = (errorWord >> DB3_shift) & DataBit_mask;
0736               int T4 = (errorWord >> DB4_shift) & DataBit_mask;
0737               int T5 = (errorWord >> DB5_shift) & DataBit_mask;
0738               int T6 = (errorWord >> DB6_shift) & DataBit_mask;
0739               int T7 = (errorWord >> DB7_shift) & DataBit_mask;
0740               if (!(FedId == 38 && chanNmbr == 7)) {
0741                 if (T0 == 1) {
0742                   TBMMessage = 0;
0743                   ((*meMapFEDs)["meTBMMessage_"][id_])->Fill((int)TBMMessage);
0744                 }
0745                 if (T1 == 1) {
0746                   TBMMessage = 1;
0747                   ((*meMapFEDs)["meTBMMessage_"][id_])->Fill((int)TBMMessage);
0748                 }
0749                 if (T2 == 1) {
0750                   TBMMessage = 2;
0751                   ((*meMapFEDs)["meTBMMessage_"][id_])->Fill((int)TBMMessage);
0752                 }
0753                 if (T3 == 1) {
0754                   TBMMessage = 3;
0755                   ((*meMapFEDs)["meTBMMessage_"][id_])->Fill((int)TBMMessage);
0756                 }
0757                 if (T4 == 1) {
0758                   TBMMessage = 4;
0759                   ((*meMapFEDs)["meTBMMessage_"][id_])->Fill((int)TBMMessage);
0760                 }
0761                 if (T5 == 1) {
0762                   TBMMessage = 5;
0763                   ((*meMapFEDs)["meTBMMessage_"][id_])->Fill((int)TBMMessage);
0764                 }
0765                 if (T6 == 1) {
0766                   TBMMessage = 6;
0767                   ((*meMapFEDs)["meTBMMessage_"][id_])->Fill((int)TBMMessage);
0768                 }
0769                 if (T7 == 1) {
0770                   TBMMessage = 7;
0771                   ((*meMapFEDs)["meTBMMessage_"][id_])->Fill((int)TBMMessage);
0772                 }
0773               }
0774               if (TBMMessage == 5 || TBMMessage == 6)
0775                 notReset = false;
0776               int StateMach_bits = 4;
0777               int StateMach_shift = 8;
0778               uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
0779               int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
0780               switch (StateMach) {
0781                 case (0): {
0782                   TBMType = 0;
0783                   break;
0784                 }
0785                 case (1):
0786                 case (9): {
0787                   TBMType = 1;
0788                   break;
0789                 }
0790                 case (2):
0791                 case (4):
0792                 case (6): {
0793                   TBMType = 2;
0794                   break;
0795                 }
0796                 case (8): {
0797                   TBMType = 3;
0798                   break;
0799                 }
0800                 default:
0801                   TBMType = 4;
0802               };
0803               if (!(FedId == 38 && chanNmbr == 7))
0804                 ((*meMapFEDs)["meTBMType_"][id_])->Fill((int)TBMType);
0805               chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0806               break;
0807             }
0808             case (31): {
0809               int evtNbr = (errorWord >> ADC_shift) & ADC_mask;
0810               if (!(FedId == 38 && chanNmbr == 7))
0811                 ((*meMapFEDs)["meEvtNbr_"][id_])->setBinContent(1, (int)evtNbr);
0812               chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0813               break;
0814             }
0815             case (35):
0816             case (36):
0817             case (37):
0818             case (38): {
0819               chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
0820               break;
0821             }
0822             default:
0823               break;
0824           };
0825         }  // end if errorType
0826 
0827         if (!(errorType == 30) || notReset) {
0828           std::string hid;
0829           static const char chNfmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChNErr_%d";
0830           char chNbuf[sizeof(chNfmt) + 2 * 32];  // 32 digits is enough for up to 2^105 + sign.
0831           sprintf(chNbuf, chNfmt, FedId, chanNmbr);
0832           hid = chNbuf;
0833           if ((*meMapFEDs)["meFedChNErr_"][id_])
0834             (*meMapFEDs)["meFedChNErr_"][id_]->Fill(chanNmbr);
0835 
0836           static const char chLfmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChLErr_%d";
0837           char chLbuf[sizeof(chLfmt) + 2 * 32];  // 32 digits is enough for up to 2^105 + sign.
0838           sprintf(chLbuf, chLfmt, FedId, chanNmbr);
0839           hid = chLbuf;
0840           if ((*meMapFEDs)["meFedChLErr_"][id_])
0841             (*meMapFEDs)["meFedChLErr_"][id_]->setBinContent(chanNmbr + 1, errorType);
0842 
0843           numberOfSeriousErrors++;
0844           int messageType = 99;
0845           if (errorType < 30)
0846             messageType = errorType - 25;
0847           else if (errorType > 30)
0848             messageType = errorType - 19;
0849           else if (errorType == 30 && TBMMessage == 0)
0850             messageType = errorType - 25;
0851           else if (errorType == 30 && TBMMessage == 1)
0852             messageType = errorType - 24;
0853           else if (errorType == 30 && (TBMMessage == 2 || TBMMessage == 3 || TBMMessage == 4))
0854             messageType = errorType - 23;
0855           else if (errorType == 30 && TBMMessage == 7)
0856             messageType = errorType - 22;
0857           else if (errorType == 30 && TBMType == 1)
0858             messageType = errorType - 21;
0859           else if (errorType == 30 && TBMType == 2)
0860             messageType = errorType - 20;
0861           else if (errorType == 30 && TBMType == 3)
0862             messageType = errorType - 19;
0863           if (messageType <= 20) {
0864             static const char fmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedETypeNErr_%d";
0865             char buf[sizeof(fmt) + 2 * 32];  // 32 digits is enough for up to 2^105 + sign.
0866             sprintf(buf, fmt, FedId, messageType);
0867             hid = buf;
0868             if ((*meMapFEDs)["meFedETypeNErr_"][id_])
0869               (*meMapFEDs)["meFedETypeNErr_"][id_]->Fill(messageType);
0870           }
0871         }  // end if not 30 || notReset
0872       }    // end if
0873     }      // end for
0874     if (numberOfSeriousErrors > 0)
0875       ((*meMapFEDs)["meNErrors_"][id_])->Fill((float)numberOfSeriousErrors);
0876   }  // end if not an empty iterator
0877   return numberOfSeriousErrors;
0878 }