CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/DQM/SiPixelMonitorRawData/src/SiPixelRawDataErrorModule.cc

Go to the documentation of this file.
00001 #include "DQM/SiPixelMonitorRawData/interface/SiPixelRawDataErrorModule.h"
00002 #include "DQMServices/Core/interface/DQMStore.h"
00003 #include "DQM/SiPixelCommon/interface/SiPixelHistogramId.h"
00004 // Framework
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 // STL
00007 #include <vector>
00008 #include <memory>
00009 #include <string>
00010 #include <iostream>
00011 #include <stdlib.h>
00012 #include <sstream>
00013 
00014 // Data Formats
00015 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00016 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00017 #include "DataFormats/DetId/interface/DetId.h"
00018 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00019 
00020 using namespace std;
00021 
00022 const int SiPixelRawDataErrorModule::LINK_bits = 6;
00023 const int SiPixelRawDataErrorModule::ROC_bits  = 5;
00024 const int SiPixelRawDataErrorModule::DCOL_bits = 5;
00025 const int SiPixelRawDataErrorModule::PXID_bits = 8;
00026 const int SiPixelRawDataErrorModule::ADC_bits  = 8;
00027 const int SiPixelRawDataErrorModule::DataBit_bits = 1;
00028 
00029 const int SiPixelRawDataErrorModule::ADC_shift  = 0;
00030 const int SiPixelRawDataErrorModule::PXID_shift = ADC_shift + ADC_bits;
00031 const int SiPixelRawDataErrorModule::DCOL_shift = PXID_shift + PXID_bits;
00032 const int SiPixelRawDataErrorModule::ROC_shift  = DCOL_shift + DCOL_bits;
00033 const int SiPixelRawDataErrorModule::LINK_shift = ROC_shift + ROC_bits;
00034 const int SiPixelRawDataErrorModule::DB0_shift = 0;
00035 const int SiPixelRawDataErrorModule::DB1_shift = DB0_shift + DataBit_bits;
00036 const int SiPixelRawDataErrorModule::DB2_shift = DB1_shift + DataBit_bits;
00037 const int SiPixelRawDataErrorModule::DB3_shift = DB2_shift + DataBit_bits;
00038 const int SiPixelRawDataErrorModule::DB4_shift = DB3_shift + DataBit_bits;
00039 const int SiPixelRawDataErrorModule::DB5_shift = DB4_shift + DataBit_bits;
00040 const int SiPixelRawDataErrorModule::DB6_shift = DB5_shift + DataBit_bits;
00041 const int SiPixelRawDataErrorModule::DB7_shift = DB6_shift + DataBit_bits;
00042 
00043 const uint32_t SiPixelRawDataErrorModule::LINK_mask = ~(~uint32_t(0) << LINK_bits);
00044 const uint32_t SiPixelRawDataErrorModule::ROC_mask  = ~(~uint32_t(0) << ROC_bits);
00045 const uint32_t SiPixelRawDataErrorModule::DCOL_mask = ~(~uint32_t(0) << DCOL_bits);
00046 const uint32_t SiPixelRawDataErrorModule::PXID_mask = ~(~uint32_t(0) << PXID_bits);
00047 const uint32_t SiPixelRawDataErrorModule::ADC_mask  = ~(~uint32_t(0) << ADC_bits);
00048 const uint32_t SiPixelRawDataErrorModule::DataBit_mask = ~(~uint32_t(0) << DataBit_bits);
00049 
00050 const int SiPixelRawDataErrorModule::TRLRBGN_bits = 32;
00051 const int SiPixelRawDataErrorModule::EVTLGT_bits  = 24;
00052 const int SiPixelRawDataErrorModule::TRLREND_bits = 8;
00053 
00054 const int SiPixelRawDataErrorModule::TRLRBGN_shift = 0;
00055 const int SiPixelRawDataErrorModule::EVTLGT_shift  = TRLRBGN_shift + TRLRBGN_bits;
00056 const int SiPixelRawDataErrorModule::TRLREND_shift = EVTLGT_shift + EVTLGT_bits;
00057 
00058 const long long SiPixelRawDataErrorModule::TRLREND_mask = ~(~(long long)(0) << TRLREND_bits);
00059 const long long SiPixelRawDataErrorModule::EVTLGT_mask  = ~(~(long long)(0) << EVTLGT_bits);
00060 const long long SiPixelRawDataErrorModule::TRLRBGN_mask = ~(~(long long)(0) << TRLRBGN_bits);
00061 //
00062 // Constructors
00063 //
00064 SiPixelRawDataErrorModule::SiPixelRawDataErrorModule() : 
00065   id_(0),
00066   ncols_(416),
00067   nrows_(160) 
00068 { 
00069   _debug_ = false;
00070   for(int i=0; i!=40; i++) for(int j=0; j!=37; j++){
00071     FedChNErrArray[i][j]=0; 
00072     FedChLErrArray[i][j]=0; 
00073     if(j<21) FedETypeNErrArray[i][j]=0;
00074   }
00075 }
00076 //
00077 SiPixelRawDataErrorModule::SiPixelRawDataErrorModule(const uint32_t& id) : 
00078   id_(id),
00079   ncols_(416),
00080   nrows_(160)
00081 { 
00082   _debug_ = false;
00083   for(int i=0; i!=40; i++) for(int j=0; j!=37; j++){
00084     FedChNErrArray[i][j]=0; 
00085     FedChLErrArray[i][j]=0; 
00086     if(j<21) FedETypeNErrArray[i][j]=0;
00087   }
00088 }
00089 //
00090 SiPixelRawDataErrorModule::SiPixelRawDataErrorModule(const uint32_t& id, const int& ncols, const int& nrows) : 
00091   id_(id),
00092   ncols_(ncols),
00093   nrows_(nrows)
00094 { 
00095   _debug_ = false;
00096   for(int i=0; i!=40; i++) for(int j=0; j!=37; j++){
00097     FedChNErrArray[i][j]=0; 
00098     FedChLErrArray[i][j]=0; 
00099     if(j<21) FedETypeNErrArray[i][j]=0;
00100   }
00101 } 
00102 //
00103 // Destructor
00104 //
00105 SiPixelRawDataErrorModule::~SiPixelRawDataErrorModule() {}
00106 //
00107 // Book histograms for errors with detId
00108 //
00109 void SiPixelRawDataErrorModule::book(const edm::ParameterSet& iConfig, int type) {
00110 }
00111 //
00112 // Book histograms for errors within a FED
00113 //
00114 void SiPixelRawDataErrorModule::bookFED(const edm::ParameterSet& iConfig) {
00115 //std::cout<<"Entering SiPixelRawDataErrorModule::bookFED: "<<std::endl;
00116   std::string hid;
00117   // Get collection name and instantiate Histo Id builder
00118   edm::InputTag src = iConfig.getParameter<edm::InputTag>( "src" );
00119   SiPixelHistogramId* theHistogramId = new SiPixelHistogramId( src.label() );
00120   // Get DQM interface
00121   DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00122   // Types of errors
00123   hid = theHistogramId->setHistoId("errorType",id_);
00124   meErrorType_ = theDMBE->book1D(hid,"Type of errors",15,24.5,39.5);
00125   meErrorType_->setAxisTitle("Type of errors",1);
00126   // Number of errors
00127   hid = theHistogramId->setHistoId("NErrors",id_);
00128   meNErrors_ = theDMBE->book1D(hid,"Number of errors",36,0.,36.);
00129   meNErrors_->setAxisTitle("Number of errors",1);
00130   // Type of FIFO full (errorType = 28).  FIFO 1 is 1-5 (where fullType = channel of FIFO 1), 
00131   // fullType = 6 signifies FIFO 2 nearly full, 7 signifies trigger FIFO nearly full, 8 
00132   // indicates an unexpected result
00133   hid = theHistogramId->setHistoId("fullType",id_);
00134   meFullType_ = theDMBE->book1D(hid,"Type of FIFO full",7,0.5,7.5);
00135   meFullType_->setAxisTitle("FIFO type",1);
00136   // For error type 30, the type of problem encoded in the TBM trailer
00137   // 0 = stack full, 1 = Pre-cal issued, 2 = clear trigger counter, 3 = sync trigger, 
00138   // 4 = sync trigger error, 5 = reset ROC, 6 = reset TBM, 7 = no token bit pass
00139   hid = theHistogramId->setHistoId("TBMMessage",id_);
00140   meTBMMessage_ = theDMBE->book1D(hid,"TBM trailer message",8,-0.5,7.5);
00141   meTBMMessage_->setAxisTitle("TBM message",1);
00142   // For error type 30, the type of problem encoded in the TBM error trailer 0 = none
00143   // 1 = data stream too long, 2 = FSM errors, 3 = invalid # of ROCs, 4 = multiple
00144   hid = theHistogramId->setHistoId("TBMType",id_);
00145   meTBMType_ = theDMBE->book1D(hid,"Type of TBM trailer",5,-0.5,4.5);
00146   meTBMType_->setAxisTitle("TBM Type",1);
00147   // For error type 31, the event number of the TBM header with the error
00148   hid = theHistogramId->setHistoId("EvtNbr",id_);
00149   meEvtNbr_ = theDMBE->bookInt(hid);
00150   // For errorType = 34, datastream size according to error word
00151   hid = theHistogramId->setHistoId("evtSize",id_);
00152   meEvtSize_ = theDMBE->bookInt(hid);
00153   
00154   for(int j=0; j!=37; j++){
00155     std::stringstream temp; temp << j;
00156     hid = "FedChNErrArray_" + temp.str();
00157     meFedChNErrArray_[j] = theDMBE->bookInt(hid);
00158     hid = "FedChLErrArray_" + temp.str();
00159     meFedChLErrArray_[j] = theDMBE->bookInt(hid);
00160     hid = "FedETypeNErrArray_" + temp.str();
00161     if(j<21) meFedETypeNErrArray_[j] = theDMBE->bookInt(hid);
00162   }
00163   delete theHistogramId;
00164 //std::cout<<"...leaving SiPixelRawDataErrorModule::bookFED. "<<std::endl;
00165 }
00166 //
00167 // Fill histograms
00168 //
00169 int SiPixelRawDataErrorModule::fill(const edm::DetSetVector<SiPixelRawDataError>& input, bool modon, bool ladon, bool bladeon) {
00170 //std::cout<<"Entering SiPixelRawDataErrorModule::fill: "<<std::endl;
00171   bool barrel = DetId(id_).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel);
00172   bool endcap = DetId(id_).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap);
00173   bool isHalfModule = false;
00174   uint32_t DBladder = 0;
00175   if(barrel){
00176     isHalfModule = PixelBarrelName(DetId(id_)).isHalfModule(); 
00177     DBladder = PixelBarrelName(DetId(id_)).ladderName();
00178 //    int FedId = DetId(id_).getFedId();                  // FED the error came from
00179 
00180   }
00181   
00182   // Get DQM interface
00183   DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00184   
00185   unsigned int numberOfSeriousErrors = 0;
00186   
00187   edm::DetSetVector<SiPixelRawDataError>::const_iterator isearch = input.find(id_); // search  errors of detid
00188   
00189   if( isearch != input.end() ) {  // Not at empty iterator
00190     // Look at errors now
00191     edm::DetSet<SiPixelRawDataError>::const_iterator  di;
00192     for(di = isearch->data.begin(); di != isearch->data.end(); di++) {
00193       int FedId = di->getFedId();                  // FED the error came from
00194       int chanNmbr = -1;
00195       int errorType = di->getType();               // type of error
00196       int TBMType=-1; int TBMMessage=-1; int evtSize=-1; int evtNbr=-1; int fullType=-1;
00197       bool notReset = true;
00198       const int LINK_bits = 6;
00199       const int LINK_shift = 26;
00200       const uint32_t LINK_mask = ~(~(uint32_t)(0) << LINK_bits);
00201 
00202       if(modon){
00203         if(errorType == 32 || errorType == 33 || errorType == 34) {
00204           long long errorWord = di->getWord64();     // for 64-bit error words
00205           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00206           if(errorType == 34) evtSize = (errorWord >> EVTLGT_shift) & EVTLGT_mask;
00207         } else {
00208           uint32_t errorWord = di->getWord32();      // for 32-bit error words
00209           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00210           switch(errorType) {  // fill in the appropriate monitorables based on the information stored in the error word
00211           case(28) : {
00212             int NFa = (errorWord >> DB0_shift) & DataBit_mask;
00213             int NFb = (errorWord >> DB1_shift) & DataBit_mask;
00214             int NFc = (errorWord >> DB2_shift) & DataBit_mask;
00215             int NFd = (errorWord >> DB3_shift) & DataBit_mask;
00216             int NFe = (errorWord >> DB4_shift) & DataBit_mask;
00217             int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
00218             int L1A = (errorWord >> DB7_shift) & DataBit_mask;
00219             if (NFa==1) fullType = 1; (meFullType_)->Fill((int)fullType);
00220             if (NFb==1) fullType = 2; (meFullType_)->Fill((int)fullType);
00221             if (NFc==1) fullType = 3; (meFullType_)->Fill((int)fullType);
00222             if (NFd==1) fullType = 4; (meFullType_)->Fill((int)fullType);
00223             if (NFe==1) fullType = 5; (meFullType_)->Fill((int)fullType);
00224             if (NF2==1) fullType = 6; (meFullType_)->Fill((int)fullType);
00225             if (L1A==1) fullType = 7; (meFullType_)->Fill((int)fullType);
00226             chanNmbr = 0;
00227             break; }
00228           case(30) : {
00229             int T0 = (errorWord >> DB0_shift) & DataBit_mask;
00230             int T1 = (errorWord >> DB1_shift) & DataBit_mask;
00231             int T2 = (errorWord >> DB2_shift) & DataBit_mask;
00232             int T3 = (errorWord >> DB3_shift) & DataBit_mask;
00233             int T4 = (errorWord >> DB4_shift) & DataBit_mask;
00234             int T5 = (errorWord >> DB5_shift) & DataBit_mask;
00235             int T6 = (errorWord >> DB6_shift) & DataBit_mask;
00236             int T7 = (errorWord >> DB7_shift) & DataBit_mask;
00237             if (T0==1) TBMMessage=0;
00238             if (T1==1) TBMMessage=1;
00239             if (T2==1) TBMMessage=2;
00240             if (T3==1) TBMMessage=3;
00241             if (T4==1) TBMMessage=4;
00242             if (T5==1) TBMMessage=5;
00243             if (T6==1) TBMMessage=6;
00244             if (T7==1) TBMMessage=7;
00245             if(TBMMessage==5 || TBMMessage==6) notReset=false;
00246             int StateMach_bits      = 4;
00247             int StateMach_shift     = 8;
00248             uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
00249             int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
00250             switch(StateMach) {
00251             case(0) : {
00252               TBMType = 0;
00253               break; }
00254             case(1) : case(9) : {
00255               TBMType = 1;
00256               break; }
00257             case(2) : case(4) : case(6) : {
00258               TBMType = 2;
00259               break; }
00260             case(8) : {
00261               TBMType = 3;
00262               break; }
00263             default : TBMType = 4;
00264             };
00265             break; }
00266           case(31) : {
00267             evtNbr = (errorWord >> ADC_shift) & ADC_mask;
00268             break; }
00269           case(36) : {
00270             //ROCId = (errorWord >> ROC_shift) & ROC_mask;
00271             break; }
00272           case(37) : {
00273             //DCOLId = (errorWord >> DCOL_shift) & DCOL_mask;
00274             //PXId = (errorWord >> PXID_shift) & PXID_mask;
00275             break; }
00276           case(38) : {
00277             //ROCNmbr = (errorWord >> ROC_shift) & ROC_mask;
00278             break; }
00279           default : break;
00280           };
00281         }//end if not double precision  
00282       }//end if modon
00283 
00284       if(ladon && barrel){
00285         if(errorType == 32 || errorType == 33 || errorType == 34){
00286           long long errorWord = di->getWord64();     // for 64-bit error words
00287           if(errorType == 34) evtSize = (errorWord >> EVTLGT_shift) & EVTLGT_mask;
00288           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00289         } else {
00290           uint32_t errorWord = di->getWord32();      // for 32-bit error words
00291           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00292           switch(errorType) {  // fill in the appropriate monitorables based on the information stored in the error word
00293           case(28) : {
00294             int NFa = (errorWord >> DB0_shift) & DataBit_mask;
00295             int NFb = (errorWord >> DB1_shift) & DataBit_mask;
00296             int NFc = (errorWord >> DB2_shift) & DataBit_mask;
00297             int NFd = (errorWord >> DB3_shift) & DataBit_mask;
00298             int NFe = (errorWord >> DB4_shift) & DataBit_mask;
00299             int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
00300             int L1A = (errorWord >> DB7_shift) & DataBit_mask;
00301             if (NFa==1) fullType = 1; (meFullType_)->Fill((int)fullType);
00302             if (NFb==1) fullType = 2; (meFullType_)->Fill((int)fullType);
00303             if (NFc==1) fullType = 3; (meFullType_)->Fill((int)fullType);
00304             if (NFd==1) fullType = 4; (meFullType_)->Fill((int)fullType);
00305             if (NFe==1) fullType = 5; (meFullType_)->Fill((int)fullType);
00306             if (NF2==1) fullType = 6; (meFullType_)->Fill((int)fullType);
00307             if (L1A==1) fullType = 7; (meFullType_)->Fill((int)fullType);
00308             chanNmbr = 0;
00309             break; }
00310           case(30) : {
00311             int T0 = (errorWord >> DB0_shift) & DataBit_mask;
00312             int T1 = (errorWord >> DB1_shift) & DataBit_mask;
00313             int T2 = (errorWord >> DB2_shift) & DataBit_mask;
00314             int T3 = (errorWord >> DB3_shift) & DataBit_mask;
00315             int T4 = (errorWord >> DB4_shift) & DataBit_mask;
00316             int T5 = (errorWord >> DB5_shift) & DataBit_mask;
00317             int T6 = (errorWord >> DB6_shift) & DataBit_mask;
00318             int T7 = (errorWord >> DB7_shift) & DataBit_mask;
00319             if (T0==1) TBMMessage=0;
00320             if (T1==1) TBMMessage=1;
00321             if (T2==1) TBMMessage=2;
00322             if (T3==1) TBMMessage=3;
00323             if (T4==1) TBMMessage=4;
00324             if (T5==1) TBMMessage=5;
00325             if (T6==1) TBMMessage=6;
00326             if (T7==1) TBMMessage=7;
00327             int StateMach_bits      = 4;
00328             int StateMach_shift     = 8;
00329             uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
00330             int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
00331             switch(StateMach) {
00332             case(0) : {
00333               TBMType = 0;
00334               break; }
00335             case(1) : case(9) : {
00336               TBMType = 1;
00337               break; }
00338             case(2) : case(4) : case(6) : {
00339               TBMType = 2;
00340               break; }
00341             case(8) : {
00342               TBMType = 3;
00343               break; }
00344             default : TBMType = 4;
00345             };
00346             break; }
00347           case(31) : {
00348             evtNbr = (errorWord >> ADC_shift) & ADC_mask;
00349             break; }
00350           case(36) : {
00351             //int ROCId = (errorWord >> ROC_shift) & ROC_mask;
00352             break; }
00353           case(37) : {
00354             //int DCOLId = (errorWord >> DCOL_shift) & DCOL_mask;
00355             //int PXId = (errorWord >> PXID_shift) & PXID_mask;
00356             break; }
00357           case(38) : {
00358             //int ROCNmbr = (errorWord >> ROC_shift) & ROC_mask;
00359             break; }
00360           default : break;
00361           };
00362         }
00363       }//end if ladderon
00364 
00365       if(bladeon && endcap){
00366         if(errorType == 32 || errorType == 33 || errorType == 34){
00367           long long errorWord = di->getWord64();     // for 64-bit error words
00368           if(errorType == 34) evtSize = (errorWord >> EVTLGT_shift) & EVTLGT_mask;
00369           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00370         } else {
00371           uint32_t errorWord = di->getWord32();      // for 32-bit error words
00372           chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00373           switch(errorType) {  // fill in the appropriate monitorables based on the information stored in the error word
00374           case(28) : {
00375             int NFa = (errorWord >> DB0_shift) & DataBit_mask;
00376             int NFb = (errorWord >> DB1_shift) & DataBit_mask;
00377             int NFc = (errorWord >> DB2_shift) & DataBit_mask;
00378             int NFd = (errorWord >> DB3_shift) & DataBit_mask;
00379             int NFe = (errorWord >> DB4_shift) & DataBit_mask;
00380             int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
00381             int L1A = (errorWord >> DB7_shift) & DataBit_mask;
00382             if (NFa==1) fullType = 1; (meFullType_)->Fill((int)fullType);
00383             if (NFb==1) fullType = 2; (meFullType_)->Fill((int)fullType);
00384             if (NFc==1) fullType = 3; (meFullType_)->Fill((int)fullType);
00385             if (NFd==1) fullType = 4; (meFullType_)->Fill((int)fullType);
00386             if (NFe==1) fullType = 5; (meFullType_)->Fill((int)fullType);
00387             if (NF2==1) fullType = 6; (meFullType_)->Fill((int)fullType);
00388             if (L1A==1) fullType = 7; (meFullType_)->Fill((int)fullType);
00389             chanNmbr = 0;
00390             break; }
00391           case(30) : {
00392             int T0 = (errorWord >> DB0_shift) & DataBit_mask;
00393             int T1 = (errorWord >> DB1_shift) & DataBit_mask;
00394             int T2 = (errorWord >> DB2_shift) & DataBit_mask;
00395             int T3 = (errorWord >> DB3_shift) & DataBit_mask;
00396             int T4 = (errorWord >> DB4_shift) & DataBit_mask;
00397             int T5 = (errorWord >> DB5_shift) & DataBit_mask;
00398             int T6 = (errorWord >> DB6_shift) & DataBit_mask;
00399             int T7 = (errorWord >> DB7_shift) & DataBit_mask;
00400             if (T0==1) TBMMessage=0;
00401             if (T1==1) TBMMessage=1;
00402             if (T2==1) TBMMessage=2;
00403             if (T3==1) TBMMessage=3;
00404             if (T4==1) TBMMessage=4;
00405             if (T5==1) TBMMessage=5;
00406             if (T6==1) TBMMessage=6;
00407             if (T7==1) TBMMessage=7;
00408             int StateMach_bits      = 4;
00409             int StateMach_shift     = 8;
00410             uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
00411             int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
00412             switch(StateMach) {
00413             case(0) : {
00414               TBMType = 0;
00415               break; }
00416             case(1) : case(9) : {
00417               TBMType = 1;
00418               break; }
00419             case(2) : case(4) : case(6) : {
00420               TBMType = 2;
00421               break; }
00422             case(8) : {
00423               TBMType = 3;
00424               break; }
00425             default : TBMType = 4;
00426             };
00427             break; }
00428           case(31) : {
00429             evtNbr = (errorWord >> ADC_shift) & ADC_mask;
00430             break; }
00431           case(36) : {
00432             //int ROCId = (errorWord >> ROC_shift) & ROC_mask;
00433             break; }
00434           case(37) : {
00435             //int DCOLId = (errorWord >> DCOL_shift) & DCOL_mask;
00436             //int PXId = (errorWord >> PXID_shift) & PXID_mask;
00437             break; }
00438           case(38) : {
00439             //int ROCNmbr = (errorWord >> ROC_shift) & ROC_mask;
00440             break; }
00441           default : break;
00442           };
00443         }
00444       }//end if bladeon
00445       
00446       if(!(errorType==30) || notReset){
00447         if(!(FedId==38&&chanNmbr==7)){ // mask slow channel that spits out lots of EventNumber errors even when in STDBY!
00448           numberOfSeriousErrors++;
00449           FedChNErrArray[FedId][chanNmbr]++;
00450           FedChLErrArray[FedId][chanNmbr] = errorType;
00451           if(errorType<30) FedETypeNErrArray[FedId][errorType-25]++;
00452           else if(errorType>30) FedETypeNErrArray[FedId][errorType-19]++;
00453           else if(errorType==30 && TBMMessage==0) FedETypeNErrArray[FedId][errorType-25]++;
00454           else if(errorType==30 && TBMMessage==1) FedETypeNErrArray[FedId][errorType-24]++;
00455           else if(errorType==30 && (TBMMessage==2 || TBMMessage==3 || TBMMessage==4)) FedETypeNErrArray[FedId][errorType-23]++;
00456           else if(errorType==30 && TBMMessage==7) FedETypeNErrArray[FedId][errorType-22]++;
00457           else if(errorType==30 && TBMType==1) FedETypeNErrArray[FedId][errorType-21]++;
00458           else if(errorType==30 && TBMType==2) FedETypeNErrArray[FedId][errorType-20]++;
00459           else if(errorType==30 && TBMType==3) FedETypeNErrArray[FedId][errorType-19]++;
00460         }
00461       }
00462       if(!(FedId==38&&chanNmbr==7)){ // mask slow channel that spits out lots of EventNumber errors even when in STDBY!
00463         std::string currDir = theDMBE->pwd();
00464         static const char buf[] = "Pixel/AdditionalPixelErrors/FED_%d";
00465         char feddir[sizeof(buf)+2]; 
00466         sprintf(feddir,buf,FedId);
00467         theDMBE->cd(feddir);
00468         MonitorElement* me;
00469         static const char buf1[] = "Pixel/AdditionalPixelErrors/FED_%d/NErrors_siPixelDigis_%d";
00470         char hname1[sizeof(buf1)+4];
00471         sprintf(hname1,buf1,FedId,FedId);
00472         me = theDMBE->get(hname1);
00473         if(me) me->Fill((int)numberOfSeriousErrors);
00474         static const char buf2[] = "Pixel/AdditionalPixelErrors/FED_%d/TBMMessage_siPixelDigis_%d";
00475         char hname2[sizeof(buf2)+4];
00476         sprintf(hname2,buf2,FedId,FedId);
00477         me = theDMBE->get(hname2);
00478         if(me) me->Fill((int)TBMMessage);
00479         static const char buf3[] = "Pixel/AdditionalPixelErrors/FED_%d/TBMType_siPixelDigis_%d";
00480         char hname3[sizeof(buf3)+4];
00481         sprintf(hname3,buf3,FedId,FedId);
00482         me = theDMBE->get(hname3);
00483         if(me) me->Fill((int)TBMType);
00484         static const char buf4[] = "Pixel/AdditionalPixelErrors/FED_%d/errorType_siPixelDigis_%d";
00485         char hname4[sizeof(buf4)+4];
00486         sprintf(hname4,buf4,FedId,FedId);
00487         me = theDMBE->get(hname4);
00488         if(me) me->Fill((int)errorType);
00489         static const char buf5[] = "Pixel/AdditionalPixelErrors/FED_%d/fullType_siPixelDigis_%d";
00490         char hname5[sizeof(buf5)+4];
00491         sprintf(hname5,buf5,FedId,FedId);
00492         me = theDMBE->get(hname5);
00493         if(me) me->Fill((int)fullType);
00494         static const char buf6[] = "Pixel/AdditionalPixelErrors/FED_%d/EvtNbr_siPixelDigis_%d";
00495         char hname6[sizeof(buf6)+4];
00496         sprintf(hname6,buf6,FedId,FedId);
00497         me = theDMBE->get(hname6);
00498         if(me) me->Fill((int)evtNbr);
00499         static const char buf7[] = "Pixel/AdditionalPixelErrors/FED_%d/evtSize_siPixelDigis_%d";
00500         char hname7[sizeof(buf7)+4];
00501         sprintf(hname7,buf7,FedId,FedId);
00502         me = theDMBE->get(hname7);
00503         if(me) me->Fill((int)evtSize);
00504         theDMBE->cd(currDir);
00505       }
00506     }//for loop
00507     
00508     std::string hid;
00509     for(int i=0; i!=40; i++){
00510       for(int j=0; j!=37; j++){
00511         if(FedChNErrArray[i][j]>0){
00512           static const char fmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChNErrArray_%d";
00513           char buf[sizeof(fmt) + 2*32]; // 32 digits is enough for up to 2^105 + sign.
00514           sprintf(buf, fmt, i, j);
00515           hid = buf;
00516           meFedChNErrArray_[j] = theDMBE->get(hid); 
00517           if(meFedChNErrArray_[j]) meFedChNErrArray_[j]->Fill(FedChNErrArray[i][j]); 
00518         }
00519         if(FedChLErrArray[i][j]>0){
00520           static const char fmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChLErrArray_%d";
00521           char buf[sizeof(fmt) + 2*32]; // 32 digits is enough for up to 2^105 + sign.
00522           sprintf(buf, fmt, i, j);
00523           hid = buf;
00524           meFedChLErrArray_[j] = theDMBE->get(hid); 
00525           if(meFedChLErrArray_[j]) meFedChLErrArray_[j]->Fill(FedChLErrArray[i][j]); 
00526         }
00527         if(j<=20 && FedETypeNErrArray[i][j]>0){
00528           static const char fmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedETypeNErrArray_%d";
00529           char buf[sizeof(fmt) + 2*32]; // 32 digits is enough for up to 2^105 + sign.
00530           sprintf(buf, fmt, i, j);
00531           hid = buf;
00532           meFedETypeNErrArray_[j] = theDMBE->get(hid); 
00533           if(meFedETypeNErrArray_[j]) meFedETypeNErrArray_[j]->Fill(FedETypeNErrArray[i][j]); 
00534         }
00535       }//end for j
00536     }//end for i
00537   }//end if not an empty iterator
00538   
00539   return numberOfSeriousErrors;
00540 }
00541 
00542 int SiPixelRawDataErrorModule::fillFED(const edm::DetSetVector<SiPixelRawDataError>& input) {
00543   //std::cout<<"Entering   SiPixelRawDataErrorModule::fillFED: "<<static_cast<int>(id_)<<std::endl;
00544   unsigned int numberOfSeriousErrors = 0;
00545   
00546   edm::DetSetVector<SiPixelRawDataError>::const_iterator isearch = input.find(0xffffffff); // search  errors of detid
00547   if( isearch != input.end() ) {  // Not an empty iterator
00548     // Look at FED errors now   
00549     edm::DetSet<SiPixelRawDataError>::const_iterator  di;
00550     for(di = isearch->data.begin(); di != isearch->data.end(); di++) {
00551       int FedId = di->getFedId();                  // FED the error came from
00552       int chanNmbr = -1;
00553       int errorType = 0;               // type of error
00554       if(FedId==static_cast<int>(id_)) {
00555         errorType = di->getType();               // type of error
00556         (meErrorType_)->Fill((int)errorType);
00557         bool notReset=true;
00558         int TBMType=-1; int TBMMessage=-1; int evtSize=-1; int fullType=-1;
00559         const int LINK_bits = 6;
00560         const int LINK_shift = 26;
00561         const uint32_t LINK_mask = ~(~(uint32_t)(0) << LINK_bits);
00562         if((errorType == 32)||(errorType == 33)||(errorType == 34)) {
00563           long long errorWord = di->getWord64();     // for 64-bit error words
00564           chanNmbr = 0;
00565           switch(errorType) {  // fill in the appropriate monitorables based on the information stored in the error word
00566           case(32) : {
00567             break; }
00568           case(33) : {
00569             break; }
00570           case(34) : {
00571             evtSize = (errorWord >> EVTLGT_shift) & EVTLGT_mask;
00572             if(!(FedId==38&&chanNmbr==7)) (meEvtSize_)->Fill((int)evtSize); 
00573             break; }
00574           default : break;
00575           };
00576         } else {
00577           uint32_t errorWord = di->getWord32();      // for 32-bit error words
00578           switch(errorType) {  // fill in the appropriate monitorables based on the information stored in the error word
00579           case(25) : case(39) : {
00580             chanNmbr = 0;
00581             break; }
00582           case(28) : {
00583             int NFa = (errorWord >> DB0_shift) & DataBit_mask;
00584             int NFb = (errorWord >> DB1_shift) & DataBit_mask;
00585             int NFc = (errorWord >> DB2_shift) & DataBit_mask;
00586             int NFd = (errorWord >> DB3_shift) & DataBit_mask;
00587             int NFe = (errorWord >> DB4_shift) & DataBit_mask;
00588             int NF2 = (errorWord >> DB6_shift) & DataBit_mask;
00589             int L1A = (errorWord >> DB7_shift) & DataBit_mask;
00590             if (NFa==1) fullType = 1; (meFullType_)->Fill((int)fullType);
00591             if (NFb==1) fullType = 2; (meFullType_)->Fill((int)fullType);
00592             if (NFc==1) fullType = 3; (meFullType_)->Fill((int)fullType);
00593             if (NFd==1) fullType = 4; (meFullType_)->Fill((int)fullType);
00594             if (NFe==1) fullType = 5; (meFullType_)->Fill((int)fullType);
00595             if (NF2==1) fullType = 6; (meFullType_)->Fill((int)fullType);
00596             if (L1A==1) fullType = 7; (meFullType_)->Fill((int)fullType);
00597             chanNmbr = 0;
00598             break; }
00599           case(29) : {
00600             int CH1 = (errorWord >> DB0_shift) & DataBit_mask;
00601             int CH2 = (errorWord >> DB1_shift) & DataBit_mask;
00602             int CH3 = (errorWord >> DB2_shift) & DataBit_mask;
00603             int CH4 = (errorWord >> DB3_shift) & DataBit_mask;
00604             int CH5 = (errorWord >> DB4_shift) & DataBit_mask;
00605             int BLOCK_bits      = 3;
00606             int BLOCK_shift     = 8;
00607             uint32_t BLOCK_mask = ~(~uint32_t(0) << BLOCK_bits);
00608             int BLOCK = (errorWord >> BLOCK_shift) & BLOCK_mask;
00609             int localCH = 1*CH1+2*CH2+3*CH3+4*CH4+5*CH5;
00610             if (BLOCK%2==0) chanNmbr=(BLOCK/2)*9+localCH;
00611             else chanNmbr = ((BLOCK-1)/2)*9+4+localCH;
00612             if ((chanNmbr<1)||(chanNmbr>36)) chanNmbr=0;  // signifies unexpected result
00613             break; }
00614           case(30) : {
00615             int T0 = (errorWord >> DB0_shift) & DataBit_mask;
00616             int T1 = (errorWord >> DB1_shift) & DataBit_mask;
00617             int T2 = (errorWord >> DB2_shift) & DataBit_mask;
00618             int T3 = (errorWord >> DB3_shift) & DataBit_mask;
00619             int T4 = (errorWord >> DB4_shift) & DataBit_mask;
00620             int T5 = (errorWord >> DB5_shift) & DataBit_mask;
00621             int T6 = (errorWord >> DB6_shift) & DataBit_mask;
00622             int T7 = (errorWord >> DB7_shift) & DataBit_mask;
00623             if(!(FedId==38&&chanNmbr==7)){
00624               if (T0==1) { TBMMessage=0; (meTBMMessage_)->Fill((int)TBMMessage); }
00625               if (T1==1) { TBMMessage=1; (meTBMMessage_)->Fill((int)TBMMessage); }
00626               if (T2==1) { TBMMessage=2; (meTBMMessage_)->Fill((int)TBMMessage); }
00627               if (T3==1) { TBMMessage=3; (meTBMMessage_)->Fill((int)TBMMessage); }
00628               if (T4==1) { TBMMessage=4; (meTBMMessage_)->Fill((int)TBMMessage); }
00629               if (T5==1) { TBMMessage=5; (meTBMMessage_)->Fill((int)TBMMessage); }
00630               if (T6==1) { TBMMessage=6; (meTBMMessage_)->Fill((int)TBMMessage); }
00631               if (T7==1) { TBMMessage=7; (meTBMMessage_)->Fill((int)TBMMessage); }
00632             }
00633             if(TBMMessage==5 || TBMMessage==6) notReset=false;
00634             int StateMach_bits      = 4;
00635             int StateMach_shift     = 8;
00636             uint32_t StateMach_mask = ~(~uint32_t(0) << StateMach_bits);
00637             int StateMach = (errorWord >> StateMach_shift) & StateMach_mask;
00638             switch(StateMach) {
00639             case(0) : {
00640               TBMType = 0;
00641               break; }
00642             case(1) : case(9) : {
00643               TBMType = 1;
00644               break; }
00645             case(2) : case(4) : case(6) : {
00646               TBMType = 2;
00647               break; }
00648             case(8) : {
00649               TBMType = 3;
00650               break; }
00651             default : TBMType = 4;
00652             };
00653             if(!(FedId==38&&chanNmbr==7)) (meTBMType_)->Fill((int)TBMType);
00654             chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00655             break; }
00656           case(31) : {
00657             int evtNbr = (errorWord >> ADC_shift) & ADC_mask;
00658             if(!(FedId==38&&chanNmbr==7))(meEvtNbr_)->Fill((int)evtNbr);
00659             chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00660             break; }
00661           case(35) : case(36) : case(37) : case(38) : {
00662             chanNmbr = (errorWord >> LINK_shift) & LINK_mask;
00663             break; }
00664           default : break;
00665           };
00666         }// end if errorType
00667 
00668         if(!(errorType==30) || notReset){
00669           if(!(FedId==38&&chanNmbr==7)){ // mask slow channel that spits out lots of EventNumber errors even when in STDBY!
00670             numberOfSeriousErrors++;
00671             FedChNErrArray[FedId][chanNmbr]++;
00672             FedChLErrArray[FedId][chanNmbr] = errorType;
00673             if(errorType<30) FedETypeNErrArray[FedId][errorType-25]++;
00674             else if(errorType>30) FedETypeNErrArray[FedId][errorType-19]++;
00675             else if(errorType==30 && TBMMessage==0) FedETypeNErrArray[FedId][errorType-25]++;
00676             else if(errorType==30 && TBMMessage==1) FedETypeNErrArray[FedId][errorType-24]++;
00677             else if(errorType==30 && (TBMMessage==2 || TBMMessage==3 || TBMMessage==4)) FedETypeNErrArray[FedId][errorType-23]++;
00678             else if(errorType==30 && TBMMessage==7) FedETypeNErrArray[FedId][errorType-22]++;
00679             else if(errorType==30 && TBMType==1) FedETypeNErrArray[FedId][errorType-21]++;
00680             else if(errorType==30 && TBMType==2) FedETypeNErrArray[FedId][errorType-20]++;
00681             else if(errorType==30 && TBMType==3) FedETypeNErrArray[FedId][errorType-19]++;
00682           }
00683         }
00684       }// end if FedId
00685     }// end for loop over all error words
00686     
00687     if(numberOfSeriousErrors>0) (meNErrors_)->Fill((float)numberOfSeriousErrors);
00688     std::string hid;
00689     // Get DQM interface
00690     DQMStore* theDMBE = edm::Service<DQMStore>().operator->();
00691     for(int i=0; i!=40; i++){
00692       if(static_cast<int>(id_) == i){
00693         for(int j=0; j!=37; j++){
00694           if(FedChNErrArray[i][j]>0){
00695             static const char fmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChNErrArray_%d";
00696             char buf[sizeof(fmt) + 2*32]; // 32 digits is enough for up to 2^105 + sign.
00697             sprintf(buf, fmt, i, j);
00698             hid = buf;
00699             meFedChNErrArray_[j] = theDMBE->get(hid); 
00700             if(meFedChNErrArray_[j]) meFedChNErrArray_[j]->Fill(FedChNErrArray[i][j]); 
00701           }
00702           if(FedChLErrArray[i][j]>0){
00703             static const char fmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedChLErrArray_%d";
00704             char buf[sizeof(fmt) + 2*32]; // 32 digits is enough for up to 2^105 + sign.
00705             sprintf(buf, fmt, i, j);
00706             hid = buf;
00707             meFedChLErrArray_[j] = theDMBE->get(hid); 
00708             if(meFedChLErrArray_[j]) meFedChLErrArray_[j]->Fill(FedChLErrArray[i][j]); 
00709           }
00710           if(j<=20 && FedETypeNErrArray[i][j]>0){
00711             static const char fmt[] = "Pixel/AdditionalPixelErrors/FED_%d/FedETypeNErrArray_%d";
00712             char buf[sizeof(fmt) + 2*32]; // 32 digits is enough for up to 2^105 + sign.
00713             sprintf(buf, fmt, i, j);
00714             hid = buf;
00715             meFedETypeNErrArray_[j] = theDMBE->get(hid); 
00716             if(meFedETypeNErrArray_[j]) meFedETypeNErrArray_[j]->Fill(FedETypeNErrArray[i][j]); 
00717           }
00718         }//end for
00719       }//end if
00720     }//end for
00721   }// end if not an empty iterator
00722   
00723 //std::cout<<"...leaving   SiPixelRawDataErrorModule::fillFED. "<<std::endl;
00724   return numberOfSeriousErrors;
00725 }