CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/DQM/HcalMonitorTasks/src/HcalDataIntegrityTask.cc

Go to the documentation of this file.
00001 #include "DQM/HcalMonitorTasks/interface/HcalDataIntegrityTask.h"
00002 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00003 #include "EventFilter/HcalRawToDigi/interface/HcalHTRData.h"
00004 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00005 #include "DataFormats/FEDRawData/interface/FEDTrailer.h"
00006 #include <iostream>
00007 
00008 HcalDataIntegrityTask::HcalDataIntegrityTask(const edm::ParameterSet& ps) 
00009 {
00010 
00011   Online_                = ps.getUntrackedParameter<bool>("online",false);
00012   mergeRuns_             = ps.getUntrackedParameter<bool>("mergeRuns",false);
00013   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup",false);
00014   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00015   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal"); 
00016   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00017     prefixME_.append("/");
00018   subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder","HcalDataIntegrityTask");
00019   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00020     subdir_.append("/");
00021   subdir_=prefixME_+subdir_;
00022   AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00023   skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",false);
00024   NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
00025   makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00026 
00027   // Specific Data Integrity Task parameters
00028   inputLabelRawData_     = ps.getUntrackedParameter<edm::InputTag>("RawDataLabel",edm::InputTag("source"));
00029   inputLabelReport_      = ps.getUntrackedParameter<edm::InputTag>("UnpackerReportLabel",edm::InputTag("hcalDigis"));
00030 
00031 } // HcalDataIntegrityTask::HcalDataIntegrityTask()
00032 
00033 HcalDataIntegrityTask::~HcalDataIntegrityTask() {}
00034 
00035 void HcalDataIntegrityTask::reset()
00036 {
00037   if (debug_>0)  std::cout <<"HcalDataIntegrityTask::reset()"<<std::endl;
00038   HcalBaseDQMonitor::reset();
00039   fedEntries_->Reset();
00040   fedFatal_->Reset();
00041   fedNonFatal_->Reset();
00042 
00043 }
00044 
00045 void HcalDataIntegrityTask::cleanup()
00046 {
00047   if(dbe_)
00048     {
00049       dbe_->setCurrentFolder(subdir_);
00050       dbe_->removeContents();
00051     }
00052 
00053 } // void HcalDataIntegrityTask::cleanup()
00054 
00055 
00056 void HcalDataIntegrityTask::beginRun(const edm::Run& run, const edm::EventSetup& c)
00057 {
00058 
00059   if (debug_>0) std::cout <<"HcalDataIntegrityTask::beginRun():  task =  '"<<subdir_<<"'"<<std::endl;
00060 
00061   HcalBaseDQMonitor::beginRun(run, c);
00062   if (mergeRuns_ && tevt_>0) return;
00063 
00064   if (debug_>1)  std::cout<<"\t<HcalDataIntegrityTask::getting eMap..."<<std::endl;
00065   edm::ESHandle<HcalDbService> pSetup;
00066   c.get<HcalDbRecord>().get( pSetup );
00067   readoutMap_=pSetup->getHcalMapping();
00068 
00069   if (tevt_==0) // create histograms, if they haven't been created already
00070     this->setup();
00071   // Clear histograms at the start of each run if not merging runs
00072   if (mergeRuns_==false)
00073   this->reset();
00074 
00075 } // beginRun(const edm::Run& run, const edm::EventSetup& c)
00076 
00077 
00078 void HcalDataIntegrityTask::setup()
00079 {
00080   // Setup Creates all necessary histograms
00081   HcalBaseDQMonitor::setup();
00082   
00083   //Initialize phatmap to a vector of vectors of uint64_t 0
00084   static size_t iphirange = IPHIMAX - IPHIMIN;
00085   static size_t ietarange = IETAMAX - IETAMIN;
00086   
00087   std::vector<uint64_t> phatv (iphirange + 1, 0);
00088   
00089   if (debug_>0) std::cout <<"<HcalDataIntegrityTask::setup>  Clearing old vectors"<<std::endl;
00090   // Clear any old vectors
00091   phatmap.clear();
00092   HBmap.clear();
00093   HEmap.clear();
00094   HFmap.clear();
00095   HOmap.clear();
00096   problemhere.clear();
00097   problemHB.clear();
00098   problemHE.clear();
00099   problemHF.clear();
00100   problemHO.clear();
00101 
00102   // ... nothing goes at ieta=0, so an extra bin goes there.
00103   phatmap = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00104   HBmap   = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00105   HEmap   = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00106   HFmap   = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00107   HOmap   = std::vector< std::vector < uint64_t> > ( ietarange + 1, phatv);
00108   std::vector<bool> probvect (iphirange + 1, 0);
00109   // ... nothing goes at ieta=0, so an extra bin goes there.
00110   problemhere = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00111   problemHB   = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00112   problemHE   = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00113   problemHF   = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00114   problemHO   = std::vector< std::vector <bool> > ( ietarange + 1, probvect);
00115 
00116 
00117 
00118   if(debug_>1) 
00119     std::cout << "About to pushback fedUnpackList_" << std::endl;
00120 
00121   // Use this in CMSSW_3_0_X and above:
00122   firstFED_ = FEDNumbering::MINHCALFEDID;
00123   for (int i=FEDNumbering::MINHCALFEDID; 
00124        i<=FEDNumbering::MAXHCALFEDID;
00125        ++i)
00126     {
00127       if(debug_>1) std::cout << "[DFMon:]Pushback for fedUnpackList_: " << i <<std::endl;
00128       fedUnpackList_.push_back(i);
00129     }
00130 
00131   if ( dbe_ ) 
00132     {
00133       
00134       if (debug_>1)
00135         std::cout <<"\t<HcalDataIntegrityTask> Setting folder to "<<subdir_<<std::endl;
00136 
00137       dbe_->setCurrentFolder(subdir_);
00138       
00139       fedEntries_ = dbe_->book1D("FEDEntries","# entries per HCAL FED",32,700,732);
00140       fedFatal_ = dbe_->book1D("FEDFatal","# fatal errors HCAL FED",32,700,732);
00141       fedNonFatal_ = dbe_->book1D("FEDNonFatal","# non-fatal errors HCAL FED",32,700,732);
00142     } // if (dbe_)
00143 
00144   this->reset(); // clear all histograms at start
00145   return;
00146 }
00147 
00148 void HcalDataIntegrityTask::analyze(edm::Event const&e, edm::EventSetup const&s)
00149 {
00150   if (!IsAllowedCalibType()) return;
00151   if (LumiInOrder(e.luminosityBlock())==false) return;
00152   
00153   // Now get the collections we need
00154   
00155   edm::Handle<FEDRawDataCollection> rawraw;
00156   
00157   // Trying new getByLabel
00158   if (!(e.getByLabel(inputLabelRawData_,rawraw)))
00159     {
00160       if (debug_>0) edm::LogWarning("HcalDataIntegrityTask")<<" raw data with label "<<inputLabelRawData_<<" not available";
00161       return;
00162     }
00163   
00164   edm::Handle<HcalUnpackerReport> report;
00165   if (!(e.getByLabel(inputLabelReport_,report)))
00166     {
00167       if (debug_>0) edm::LogWarning("HcalDataIntegrityTask")<<" UnpackerReport with label "<<inputLabelReport_<<" \not available";
00168       return;
00169     }
00170   
00171   // Collections were found; increment counters
00172   HcalBaseDQMonitor::analyze(e,s);
00173 
00174   processEvent(*rawraw, *report, *readoutMap_);
00175 }
00176 
00177 
00178 
00179 void HcalDataIntegrityTask::processEvent(const FEDRawDataCollection& rawraw, 
00180                                          const HcalUnpackerReport& report, 
00181                                          const HcalElectronicsMap& emap){
00182   
00183   if(!dbe_) 
00184     { 
00185       std::cout<<"HcalDataIntegrityTask::processEvent DQMStore not instantiated!!!"<<std::endl;  
00186       return;
00187     }
00188 
00189   // Loop over all FEDs reporting the event, unpacking if good.
00190   for (std::vector<int>::const_iterator i=fedUnpackList_.begin();i!=fedUnpackList_.end(); i++) 
00191     {
00192       const FEDRawData& fed = rawraw.FEDData(*i);
00193       if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
00194       unpack(fed,emap);
00195     }
00196 
00197   return;
00198 } //void HcalDataIntegrityTask::processEvent()
00199 
00200 
00201 // Process one FED's worth (one DCC's worth) of the event data.
00202 void HcalDataIntegrityTask::unpack(const FEDRawData& raw, 
00203                                    const HcalElectronicsMap& emap){
00204   // get the DCC header
00205   const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
00206   if(!dccHeader) return;
00207 
00208   // get the DCC trailer 
00209   unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
00210   FEDTrailer trailer = FEDTrailer(trailer_ptr);
00211 
00212   int dccid=dccHeader->getSourceId();
00213 
00215   bool CDFProbThisDCC = false; 
00216   /* 1 */ //There should always be a second CDF header word indicated.
00217   if (!dccHeader->thereIsASecondCDFHeaderWord()) 
00218     {
00219       CDFProbThisDCC = true; 
00220     }
00221 
00222   /* 2 */ //Make sure a reference CDF Version value has been recorded for this dccid
00223   CDFvers_it = CDFversionNumber_list.find(dccid);
00224   if (CDFvers_it  == CDFversionNumber_list.end()) 
00225     {
00226       CDFversionNumber_list.insert(std::pair<int,short>
00227                                    (dccid,dccHeader->getCDFversionNumber() ) );
00228       CDFvers_it = CDFversionNumber_list.find(dccid);
00229     } // then check against it.
00230 
00231   if (dccHeader->getCDFversionNumber()!= CDFvers_it->second) 
00232     {
00233       CDFProbThisDCC = true; 
00234     }
00235   
00236   /* 3 */ //Make sure a reference CDF EventType value has been recorded for this dccid
00237   CDFEvT_it = CDFEventType_list.find(dccid);
00238   if (CDFEvT_it  == CDFEventType_list.end()) 
00239     {
00240       CDFEventType_list.insert(std::pair<int,short>
00241                                (dccid,dccHeader->getCDFEventType() ) );
00242       CDFEvT_it = CDFEventType_list.find(dccid);
00243     } // then check against it.
00244   
00245   if (dccHeader->getCDFEventType()!= CDFEvT_it->second) 
00246     {
00247       // On probation until safe against Orbit Gap Calibration Triggers...
00248       // CDFProbThisDCC = true; 
00249     }
00250 
00251   /* 4 */ //There should always be a '5' in CDF Header word 0, bits [63:60]
00252   if (dccHeader->BOEshouldBe5Always()!=5) 
00253     {
00254       CDFProbThisDCC = true; 
00255     }
00256 
00257   /* 5 */ //There should never be a third CDF Header word indicated.
00258   if (dccHeader->thereIsAThirdCDFHeaderWord()) 
00259     {
00260       CDFProbThisDCC = true; 
00261     }
00262 
00263   /* 6 */ //Make sure a reference value of Reserved Bits has been recorded for this dccid
00264 
00265   CDFReservedBits_it = CDFReservedBits_list.find(dccid);
00266   if (CDFReservedBits_it  == CDFReservedBits_list.end()) {
00267     CDFReservedBits_list.insert(std::pair<int,short>
00268                                 (dccid,dccHeader->getSlink64ReservedBits() ) );
00269     CDFReservedBits_it = CDFReservedBits_list.find(dccid);
00270   } // then check against it.
00271   
00272   if ((int) dccHeader->getSlink64ReservedBits()!= CDFReservedBits_it->second) 
00273     {
00274     // On probation until safe against Orbit Gap Calibration Triggers...
00275     //       CDFProbThisDCC = true; 
00276     }
00277 
00278   /* 7 */ //There should always be 0x0 in CDF Header word 1, bits [63:60]
00279   if (dccHeader->BOEshouldBeZeroAlways() !=0) 
00280     {
00281       CDFProbThisDCC = true; 
00282     }
00283   
00284   /* 8 */ //There should only be one trailer
00285   if (trailer.moreTrailers()) 
00286     {
00287       CDFProbThisDCC = true; 
00288     }
00289   //  if trailer.
00290 
00291   /* 9 */ //CDF Trailer [55:30] should be the # 64-bit words in the EvFragment
00292   if ((uint64_t) raw.size() != ( (uint64_t) trailer.lenght()*sizeof(uint64_t)) )  //The function name is a typo! Awesome.
00293     {
00294       CDFProbThisDCC = true; 
00295     }
00296   /*10 */ //There is a rudimentary sanity check built into the FEDTrailer class
00297   if (!trailer.check()) 
00298     {
00299       CDFProbThisDCC = true; 
00300     }
00301 
00302   if (CDFProbThisDCC)
00303     fedFatal_->Fill(dccid);
00304   fedEntries_->Fill(dccid);
00305 
00306   return;
00307 } // void HcalDataIntegrityTask::unpack()
00308 
00309 DEFINE_FWK_MODULE(HcalDataIntegrityTask);
00310