CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/CastorMonitor/src/CastorDataIntegrityMonitor.cc

Go to the documentation of this file.
00001 #include "DQM/CastorMonitor/interface/CastorDataIntegrityMonitor.h"
00002 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00003 #include "EventFilter/HcalRawToDigi/interface/HcalHTRData.h"
00004 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00005 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00006 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00007 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00008 
00009 #include "DQMServices/Core/interface/DQMStore.h"
00010 #include "DQMServices/Core/interface/MonitorElement.h"
00011 #include <iostream>
00012 
00013 //****************************************************//
00014 //********** CastorDataIntegrityMonitor  ******************//
00015 //********** Author: Dmytro Volyanskyy   *************//
00016 //********** Date  : 16.03.2011 (first version) ******// 
00017 //****************************************************//
00020 
00021 
00022 //==================================================================//
00023 //======================= Constructor ==============================//
00024 //==================================================================//
00025 CastorDataIntegrityMonitor::CastorDataIntegrityMonitor() {
00026 }
00027 
00028 
00029 //==================================================================//
00030 //======================= Destructor ===============================//
00031 //==================================================================//
00032 CastorDataIntegrityMonitor::~CastorDataIntegrityMonitor() {
00033 }
00034 
00035 
00036 //==================================================================//
00037 //=========================== reset  ===============================//
00038 //==================================================================//
00039 void CastorDataIntegrityMonitor::reset(){
00040  
00041 }
00042 
00043 //==================================================================//
00044 //=========================== cleanup  =============================//
00045 //==================================================================//
00046 
00047 void CastorDataIntegrityMonitor::cleanup(){
00048  
00049 } 
00050 
00051 //==================================================================//
00052 //=========================== setup  ==============================//
00053 //==================================================================//
00054 
00055 void CastorDataIntegrityMonitor::setup(const edm::ParameterSet& ps, DQMStore* dbe)
00056 {
00057  
00058  if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::setup (start)" << std::endl;
00059  CastorBaseMonitor::setup(ps,dbe);
00060  baseFolder_ = rootFolder_+"CastorDataIntegrityMonitor";
00061  ievt_=0;
00062  spigotStatus=-99;
00063  statusSpigotDCC=-99;
00064  CDFProbThisDCC = false; 
00065 
00066 
00068   for (int row=0; row<15; row++) 
00069     for (int col=0; col<3; col++)
00070         problemsSpigot[row][col] = 0;
00071  
00072 
00073 
00075  for (int i=FEDNumbering::MINCASTORFEDID; i<=FEDNumbering:: MAXCASTORFEDID; ++i)       
00076       fedUnpackList_.push_back(i);
00077 
00078   if ( m_dbe !=NULL ) {
00079     m_dbe->setCurrentFolder(baseFolder_);
00081     meEVT_      = m_dbe->bookInt("Digi Task Event Number");
00082     fedEntries  = m_dbe->book1D("FEDEntries_CASTOR" ,"Number of Entries per CASTOR FED",3,690,693); //-- FED 693 take out for the time being
00083     fedFatal    = m_dbe->book1D("CASTOR FEDFatal errors"   ,"Number of Fatal Errors per CASTOR FED",3,690,693); //-- FED 693 take out for the time being
00084     //fedNonFatal = m_dbe->book1D("FEDNonFatal_CASTOR","Number of non-fatal errors CASTOR FED",3,690,693); //-- take it out for the time being
00085 
00086     //meDCCVersion =  m_dbe->bookProfile("DCC Firmware Version","DCC Firmware Version", 3, 690, 693, 256, -0.5, 255.5);
00087     //meDCCVersion->setAxisTitle("FED ID", 1);
00088     spigotStatusMap = m_dbe->book2D("CASTOR spigot status","CASTOR spigot status",15,0,15,4,690,694); //-- get some space for the legend
00089 
00090   }
00091   
00092    else{ 
00093    if(fVerbosity>0) std::cout << "CastorDigiMonitor::setup - NO DQMStore service" << std::endl; 
00094   }
00095 
00096   if(fVerbosity>0) std::cout << "CastorDigiMonitor::setup (end)" << std::endl;
00097 
00098  return;
00099 
00100 }
00101 
00102 
00103 void CastorDataIntegrityMonitor::processEvent(const FEDRawDataCollection& RawData, const HcalUnpackerReport& unpackReport, const CastorElectronicsMap& emap){
00104 
00105   if(fVerbosity>0) std::cout << "CastorDataIntegrityMonitor::processEvent" << std::endl;
00106 
00107   meEVT_->Fill(ievt_); 
00108 
00110   ievt_++;
00111 
00113   for (std::vector<int>::const_iterator i=fedUnpackList_.begin();i!=fedUnpackList_.end(); i++)  {
00114       const FEDRawData& fed = RawData.FEDData(*i);
00115       if (fed.size()<12) continue;
00116       unpack(fed,emap);
00117     }
00118 
00120   for (int spigot=0; spigot<15; spigot++){
00121     for (int dcc=0; dcc<3; dcc++){
00122 
00123       if( problemsSpigot[spigot][dcc] == 0)  statusSpigotDCC=1.0;
00124       else if( double(problemsSpigot[spigot][dcc])/double(ievt_)  < 0.05) statusSpigotDCC=0.;       
00125       else statusSpigotDCC=-1.0;
00127       spigotStatusMap->getTH2F()->SetBinContent(spigot+1,dcc+1,statusSpigotDCC);
00128       if(fVerbosity>0) 
00129       std::cout<< "==> SpigotNr:"<< spigot+1 <<" DCC_ID:"<< dcc+690 << " # problems=" << problemsSpigot[spigot][dcc]
00130                << "==> ievt_:"<< ievt_ << " ratio=" << double(problemsSpigot[spigot][dcc])/double(ievt_) << " STATUS=" << statusSpigotDCC << std::endl;
00131     }
00132   }
00133 
00134 
00135 
00136    
00137    
00138 
00139   return;
00140 } 
00141 
00142 
00143 //=======================================================//
00144 //=============== unpack CASTOR FED =====================//
00145 //=======================================================//
00146 
00147 void CastorDataIntegrityMonitor::unpack(const FEDRawData& raw, const CastorElectronicsMap& emap) {
00148 
00149 
00151   const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
00152   if(!dccHeader) return;
00153 
00155   unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
00156   FEDTrailer trailer = FEDTrailer(trailer_ptr);
00157 
00158   dccid=dccHeader->getSourceId();
00159 
00160   HcalHTRData htr;
00161 
00163   CDFProbThisDCC = false; 
00164 
00165 
00166   //================ BASIC CHECKS OF DATA INTEGRITY ====================//
00167 
00168  
00170 
00171   /* 1 */ //There should always be a second CDF header word indicated.
00172   if (!dccHeader->thereIsASecondCDFHeaderWord()) 
00173     {
00174       CDFProbThisDCC = true;  
00175     }
00176 
00177   /* 2 */ //Make sure a reference CDF Version value has been recorded for this dccid
00178   CDFvers_it = CDFversionNumber_list.find(dccid);
00179   if (CDFvers_it  == CDFversionNumber_list.end()) 
00180     {
00181       CDFversionNumber_list.insert(std::pair<int,short>
00182                                    (dccid,dccHeader->getCDFversionNumber() ) );
00183       CDFvers_it = CDFversionNumber_list.find(dccid);
00184     } // then check against it.
00185 
00186   if (dccHeader->getCDFversionNumber()!= CDFvers_it->second) 
00187     {
00188       CDFProbThisDCC = true;  
00189     }
00190   
00191   /* 3 */ //Make sure a reference CDF EventType value has been recorded for this dccid
00192   CDFEvT_it = CDFEventType_list.find(dccid);
00193   if (CDFEvT_it  == CDFEventType_list.end()) 
00194     {
00195       CDFEventType_list.insert(std::pair<int,short>
00196                                (dccid,dccHeader->getCDFEventType() ) );
00197       CDFEvT_it = CDFEventType_list.find(dccid);
00198     } // then check against it.
00199   
00200   if (dccHeader->getCDFEventType()!= CDFEvT_it->second) 
00201     {
00202       // On probation until safe against Orbit Gap Calibration Triggers...
00203        CDFProbThisDCC = true;  
00204     }
00205 
00206   /* 4 */ //There should always be a '5' in CDF Header word 0, bits [63:60]
00207   if (dccHeader->BOEshouldBe5Always()!=5) 
00208     {
00209       CDFProbThisDCC = true;  
00210     }
00211 
00212   /* 5 */ //There should never be a third CDF Header word indicated.
00213   if (dccHeader->thereIsAThirdCDFHeaderWord()) 
00214     {
00215       CDFProbThisDCC = true;  
00216     }
00217 
00218   /* 6 */ //Make sure a reference value of Reserved Bits has been recorded for this dccid
00219 
00220   CDFReservedBits_it = CDFReservedBits_list.find(dccid);
00221   if (CDFReservedBits_it  == CDFReservedBits_list.end()) {
00222     CDFReservedBits_list.insert(std::pair<int,short>
00223                                 (dccid,dccHeader->getSlink64ReservedBits() ) );
00224     CDFReservedBits_it = CDFReservedBits_list.find(dccid);
00225   } // then check against it.
00226   
00227   if ((int) dccHeader->getSlink64ReservedBits()!= CDFReservedBits_it->second) 
00228     {
00229     // On probation until safe against Orbit Gap Calibration Triggers...
00230     //       CDFProbThisDCC = true;
00231     }
00232 
00233   /* 7 */ //There should always be 0x0 in CDF Header word 1, bits [63:60]
00234   if (dccHeader->BOEshouldBeZeroAlways() !=0) 
00235     {
00236       CDFProbThisDCC = true;
00237     }
00238   
00239   /* 8 */ //There should only be one trailer
00240   if (trailer.moreTrailers()) 
00241     {
00242       CDFProbThisDCC = true; 
00243     }
00244   //  if trailer.
00245 
00246   /* 9 */ //CDF Trailer [55:30] should be the # 64-bit words in the EvFragment
00247   if ((uint64_t) raw.size() != ( (uint64_t) trailer.lenght()*sizeof(uint64_t)) )  //The function name is a typo! Awesome.
00248     {
00249       CDFProbThisDCC = true; 
00250     }
00251   /*10 */ //There is a rudimentary sanity check built into the FEDTrailer class
00252   if (!trailer.check()) 
00253     {
00254       CDFProbThisDCC = true; 
00255     }
00256 
00258   if (CDFProbThisDCC) fedFatal->Fill(dccid);
00259 
00261   fedEntries->Fill(dccid);
00262         
00263 
00264 
00265   //================== do similar what HCALRawDataMonitor does   
00267   //uint64_t* dccfw= (uint64_t*) (raw.data()+(sizeof(uint64_t)*2)); //64-bit DAQ word number 2 (from 0)
00268   //int dcc_fw =  ( ((*dccfw)>>(6*8))&0x00000000000000FF );         //Shift right 6 bytes, get that low byte.
00269   //meDCCVersion->Fill(dccid,dcc_fw);
00270   //char TTS_state = (char)trailer.ttsBits();
00271 
00272   //errors per-Spigot bits from the DCC Header
00273   int WholeErrorList=0; 
00274 
00276   for(int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
00277 
00278   if (!( dccHeader->getSpigotEnabled((unsigned int) spigot)) ) continue; //-- skip when not enabled
00279 
00280   //-- set OK here 
00281   spigotStatus=1;
00282   //-- get DCC id
00283   dccid=dccHeader->getSourceId();
00284 
00285   if (dccid==693) continue; //-- skip this one
00286 
00288    WholeErrorList=dccHeader->getLRBErrorBits((unsigned int) spigot);
00289     if (WholeErrorList!=0) {
00290 
00291       if ((WholeErrorList>>0)&0x01) {
00292         if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor:: error==> " << std::endl;
00293         spigotStatus=-1; 
00294         ++problemsSpigot[spigot][dccid-690];
00295       }
00296 
00297       if (((WholeErrorList>>1)&0x01)!=0)  {
00298         if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor:: error ==> Uncorrected Error" << std::endl; 
00299            if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00300            spigotStatus=-1;
00301        }
00302 
00303       if (((WholeErrorList>>2)&0x01)!=0)  {
00304         if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor:: error ==> Truncated data coming into LRB" << std::endl; 
00305           if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00306           spigotStatus=-1;
00307       }
00308 
00309       if (((WholeErrorList>>3)&0x01)!=0)  {
00310         if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor: error ==>: FIFO Overflow" << std::endl; 
00311         if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00312         spigotStatus=-1;
00313       }
00314 
00315       if (((WholeErrorList>>4)&0x01)!=0)  {
00316         if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor:: error ==> (EvN Mismatch), htr payload metadeta" << std::endl; 
00317          if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00318          spigotStatus=-1;
00319       }
00320 
00321       if (((WholeErrorList>>5)&0x01)!=0)  {
00322         if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor:: error ==> STatus: hdr/data/trlr error" << std::endl; 
00323         if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00324         spigotStatus=-1;
00325       }
00326 
00327       if (((WholeErrorList>>6)&0x01)!=0)  {
00328         if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor:: error ==> ODD 16-bit word count from HT error" << std::endl;  
00329         if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00330         spigotStatus=-1;
00331       }
00332 
00333     }
00334 
00336 
00337     if (!dccHeader->getSpigotPresent((unsigned int) spigot)){
00338           if(fVerbosity>0)  std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Not Present"<<std::endl;
00339           if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00340           spigotStatus=-1;
00341     }
00342    else {
00343       if ( dccHeader->getSpigotDataTruncated((unsigned int) spigot)) {
00344         if(fVerbosity>0)  std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Data Truncated"<<std::endl;
00345         if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00346         spigotStatus=-1;
00347       }
00348       if ( dccHeader->getSpigotCRCError((unsigned int) spigot)) {
00349         if(fVerbosity>0)  std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot CRC Error"<<std::endl; 
00350         if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00351         spigotStatus=-1;
00352       }
00353      if (dccHeader->getSpigotDataLength(spigot) <(unsigned long)4) {
00354       if(fVerbosity>0)  std::cout <<"CastorDataIntegrityMonitor:: HTR Problem: Spigot Data Length too small"<<std::endl; 
00355       if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];  
00356       spigotStatus=-1;
00357      }  
00358 
00359      if (dccHeader->getSpigotData(spigot,htr,raw.size())==-1) {
00360         if(fVerbosity>0)  std::cout<< "CastorDataIntegrityMonitor:: Invalid HTR data (data beyond payload size) observed on spigot " << spigot 
00361                  << " of DCC with source id " << dccHeader->getSourceId()<< std::endl;
00362       if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
00363        spigotStatus=-1;
00364      }
00365         
00366     if (!htr.check()) {
00367       if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor:: Invalid HTR data observed on spigot " << spigot << " of DCC with source id " << dccHeader->getSourceId() << std::endl;
00368      if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
00369      spigotStatus=-1;
00370     }
00371 
00372     if (htr.isHistogramEvent()) {
00373      if(fVerbosity>0)  std::cout << "CastorDataIntegrityMonitor:: Histogram data passed to non-histogram unpacker on spigot " << spigot << " of DCC with source id " 
00374      << dccHeader->getSourceId() << std::endl; 
00375      if(spigotStatus>0) ++problemsSpigot[spigot][dccid-690];
00376      spigotStatus=-1;
00377     }
00378   
00379    }
00380     
00381   } //-- end of loop over spigots
00382 
00383   return;
00384 }