CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch2/src/DQM/HcalMonitorTasks/src/HcalRawDataMonitor.cc

Go to the documentation of this file.
00001 
00002 #include "DQM/HcalMonitorTasks/interface/HcalRawDataMonitor.h"
00003 #include "EventFilter/HcalRawToDigi/interface/HcalDCCHeader.h"
00004 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00005 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00006 #include "FWCore/Framework/interface/LuminosityBlock.h"
00007 
00008 
00009 HcalRawDataMonitor::HcalRawDataMonitor(const edm::ParameterSet& ps) {
00010   Online_                = ps.getParameter<bool>("online");
00011   mergeRuns_             = ps.getParameter<bool>("mergeRuns");
00012   enableCleanup_         = ps.getUntrackedParameter<bool>("enableCleanup");
00013   debug_                 = ps.getUntrackedParameter<int>("debug",0);
00014   prefixME_              = ps.getUntrackedParameter<std::string>("subSystemFolder", "Hcal/"); // Hcal
00015   if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
00016     prefixME_.append("/");
00017   subdir_                = ps.getUntrackedParameter<std::string>("TaskFolder", "RawDataMonitor_Hcal/"); // RawDataMonitor_Hcal
00018   if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
00019     subdir_.append("/");
00020   subdir_=prefixME_+subdir_;
00021   AllowedCalibTypes_     = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
00022   skipOutOfOrderLS_      = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",true);
00023   NLumiBlocks_           = ps.getUntrackedParameter<int>("NLumiBlocks",-1);
00024   makeDiagnostics_       = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
00025 
00026   FEDRawDataCollection_  = ps.getUntrackedParameter<edm::InputTag>("FEDRawDataCollection");
00027   digiLabel_             = ps.getUntrackedParameter<edm::InputTag>("digiLabel");
00028 
00029   excludeHORing2_       = ps.getUntrackedParameter<bool>("excludeHORing2",false);
00030 
00031   //inputLabelReport_      = ps.getUntrackedParameter<edm::InputTag>("UnpackerReport");
00032   
00033   // Initialize an array of MonitorElements
00034   meChann_DataIntegrityCheck_[0] =meCh_DataIntegrityFED00_;
00035   meChann_DataIntegrityCheck_[1] =meCh_DataIntegrityFED01_;
00036   meChann_DataIntegrityCheck_[2] =meCh_DataIntegrityFED02_;
00037   meChann_DataIntegrityCheck_[3] =meCh_DataIntegrityFED03_;
00038   meChann_DataIntegrityCheck_[4] =meCh_DataIntegrityFED04_;
00039   meChann_DataIntegrityCheck_[5] =meCh_DataIntegrityFED05_;
00040   meChann_DataIntegrityCheck_[6] =meCh_DataIntegrityFED06_;
00041   meChann_DataIntegrityCheck_[7] =meCh_DataIntegrityFED07_;
00042   meChann_DataIntegrityCheck_[8] =meCh_DataIntegrityFED08_;
00043   meChann_DataIntegrityCheck_[9] =meCh_DataIntegrityFED09_;
00044   meChann_DataIntegrityCheck_[10]=meCh_DataIntegrityFED10_;
00045   meChann_DataIntegrityCheck_[11]=meCh_DataIntegrityFED11_;
00046   meChann_DataIntegrityCheck_[12]=meCh_DataIntegrityFED12_;
00047   meChann_DataIntegrityCheck_[13]=meCh_DataIntegrityFED13_;
00048   meChann_DataIntegrityCheck_[14]=meCh_DataIntegrityFED14_;
00049   meChann_DataIntegrityCheck_[15]=meCh_DataIntegrityFED15_;
00050   meChann_DataIntegrityCheck_[16]=meCh_DataIntegrityFED16_;
00051   meChann_DataIntegrityCheck_[17]=meCh_DataIntegrityFED17_;
00052   meChann_DataIntegrityCheck_[18]=meCh_DataIntegrityFED18_;
00053   meChann_DataIntegrityCheck_[19]=meCh_DataIntegrityFED19_;
00054   meChann_DataIntegrityCheck_[20]=meCh_DataIntegrityFED20_;
00055   meChann_DataIntegrityCheck_[21]=meCh_DataIntegrityFED21_;
00056   meChann_DataIntegrityCheck_[22]=meCh_DataIntegrityFED22_;
00057   meChann_DataIntegrityCheck_[23]=meCh_DataIntegrityFED23_;
00058   meChann_DataIntegrityCheck_[24]=meCh_DataIntegrityFED24_;
00059   meChann_DataIntegrityCheck_[25]=meCh_DataIntegrityFED25_;
00060   meChann_DataIntegrityCheck_[26]=meCh_DataIntegrityFED26_;
00061   meChann_DataIntegrityCheck_[27]=meCh_DataIntegrityFED27_;
00062   meChann_DataIntegrityCheck_[28]=meCh_DataIntegrityFED28_;
00063   meChann_DataIntegrityCheck_[29]=meCh_DataIntegrityFED29_;
00064   meChann_DataIntegrityCheck_[30]=meCh_DataIntegrityFED30_;
00065   meChann_DataIntegrityCheck_[31]=meCh_DataIntegrityFED31_;
00066   
00067   this->reset();
00068 } // HcalRawDataMonitor::HcalRawDataMonitor()
00069 
00070 // destructor
00071 HcalRawDataMonitor::~HcalRawDataMonitor(){}
00072 
00073 // reset
00074 void HcalRawDataMonitor::reset(void)
00075 {
00076 
00077   for (int f=0; f<NUMDCCS; f++) {
00078     for (int s=0; s<15; s++) {
00079       UScount[f][s]=0;}}
00080 
00081   for (int x=0; x<THREE_FED; x++)
00082     for (int y=0; y<THREE_SPG; y++)
00083       HalfHTRDataCorruptionIndicators_  [x][y]=0;
00084 
00085   for (int x=0; x<THREE_FED; x++)
00086     for (int y=0; y<THREE_SPG; y++)
00087       LRBDataCorruptionIndicators_  [x][y]=0;
00088          
00089   for (int x=0; x<TWO___FED; x++)
00090     for (int y=0; y<TWO__SPGT; y++)
00091       ChannSumm_DataIntegrityCheck_[x][y]=0;
00092 
00093   for (int x=0; x<TWO___FED; x++)
00094     for (int y=0; y<THREE_SPG; y++)
00095       DataFlowInd_[x][y]=0;
00096 
00097   for (int f=0; f<NUMDCCS; f++)
00098     for (int x=0; x<  TWO_CHANN; x++)
00099       for (int y=0; y<TWO__SPGT; y++)      
00100         Chann_DataIntegrityCheck_  [f][x][y]=0;
00101 
00102   for (int i=0; i<(NUMDCCS * NUMSPIGS * HTRCHANMAX); i++) 
00103     hashedHcalDetId_[i]=HcalDetId::Undefined;
00104 
00105   for (int d=0; d<DEPTHBINS; d++) {
00106     for (int eta=0; eta<ETABINS; eta++) {
00107       for (int phi=0; phi<PHIBINS; phi++){
00108         uniqcounter[eta][phi][d] = 0.0;
00109         problemcount[eta][phi][d] = 0.0;
00110         problemfound[eta][phi][d] = false;
00111       }
00112     }
00113   }
00114 
00115   // Properly initialze bylumi counters.
00116   NumBadHB=0;
00117   NumBadHE=0;
00118   NumBadHO=0;
00119   NumBadHF=0;
00120   NumBadHFLUMI=0;
00121   NumBadHO0=0;
00122   NumBadHO12=0;
00123 
00124 } // HcalRawDataMonitor::HcalRawDataMonitor()
00125 
00126 // BeginRun
00127 void HcalRawDataMonitor::beginRun(const edm::Run& run, const edm::EventSetup& c){
00128   HcalBaseDQMonitor::beginRun(run,c);
00129   edm::ESHandle<HcalDbService> pSetup;
00130   c.get<HcalDbRecord>().get( pSetup );
00131 
00132   readoutMap_=pSetup->getHcalMapping();
00133   DetId detid_;
00134   HcalDetId hcaldetid_; 
00135 
00136   // Build a map of readout hardware unit to calorimeter channel
00137   std::vector <HcalElectronicsId> AllElIds = readoutMap_->allElectronicsIdPrecision();
00138   uint32_t itsdcc    =0;
00139   uint32_t itsspigot =0;
00140   uint32_t itshtrchan=0;
00141   
00142   // by looping over all precision (non-trigger) items.
00143   for (std::vector <HcalElectronicsId>::iterator eid = AllElIds.begin();
00144        eid != AllElIds.end();
00145        eid++) {
00146 
00147     //Get the HcalDetId from the HcalElectronicsId
00148     detid_ = readoutMap_->lookup(*eid);
00149     // NULL if illegal; ignore
00150     if (!detid_.null()) {
00151       if (detid_.det()!=4) continue; //not Hcal
00152       if (detid_.subdetId()!=HcalBarrel &&
00153           detid_.subdetId()!=HcalEndcap &&
00154           detid_.subdetId()!=HcalOuter  &&
00155           detid_.subdetId()!=HcalForward) continue;
00156 
00157       itsdcc    =(uint32_t) eid->dccid(); 
00158       itsspigot =(uint32_t) eid->spigot();
00159       itshtrchan=(uint32_t) eid->htrChanId();
00160       hcaldetid_ = HcalDetId(detid_);
00161       stashHDI(hashup(itsdcc,itsspigot,itshtrchan),
00162                hcaldetid_);
00163     } // if (!detid_.null()) 
00164   } 
00165 }
00166 
00167 // Begin LumiBlock
00168 void HcalRawDataMonitor::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00169                                               const edm::EventSetup& c) {
00170   if (LumiInOrder(lumiSeg.luminosityBlock())==false) return;
00171   HcalBaseDQMonitor::beginLuminosityBlock(lumiSeg,c);
00172   //zeroCounters(); // zero hot cell counters at the start of each luminosity block
00173   ProblemsCurrentLB->Reset();
00174   return;
00175 }
00176 // Setup
00177 void HcalRawDataMonitor::setup(void){
00178   // Call base class setup
00179   HcalBaseDQMonitor::setup();
00180   if (!dbe_) {
00181     if (debug_>1)
00182       std::cout <<"<HcalRawDataMonitor::setup>  No DQMStore instance available. Bailing out."<<std::endl;
00183     return;}
00184 
00185   /******* Set up all histograms  ********/
00186   if (debug_>1)
00187     std::cout <<"<HcalRawDataMonitor::beginRun>  Setting up histograms"<<std::endl;
00188   
00189   dbe_->setCurrentFolder(subdir_);
00190   ProblemsVsLB=dbe_->bookProfile("RAW_Problems_HCAL_vs_LS",
00191                                  "Total HCAL RAW Problems vs lumi section", 
00192                                  NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,10000);
00193 
00194   ProblemsVsLB_HB=dbe_->bookProfile("Total_RAW_Problems_HB_vs_LS",
00195                                     "Total HB RAW Problems vs lumi section",
00196                                     NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,3000);
00197   ProblemsVsLB_HE=dbe_->bookProfile("Total_RAW_Problems_HE_vs_LS",
00198                                     "Total HE RAW Problems vs lumi section",
00199                                     NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,3000);
00200   ProblemsVsLB_HO=dbe_->bookProfile("Total_RAW_Problems_HO_vs_LS",
00201                                     "Total HO RAW Problems vs lumi section",
00202                                     NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,3000);
00203   ProblemsVsLB_HF=dbe_->bookProfile("Total_RAW_Problems_HF_vs_LS",
00204                                     "Total HF RAW Problems vs lumi section",
00205                                     NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,2000);
00206   ProblemsVsLB_HBHEHF=dbe_->bookProfile("Total_RAW_Problems_HBHEHF_vs_LS",
00207                                     "Total HBHEHF RAW Problems vs lumi section",
00208                                     NLumiBlocks_,0.5,NLumiBlocks_+0.5,100,0,2000);
00209  
00210   ProblemsVsLB->getTProfile()->SetMarkerStyle(20);
00211   ProblemsVsLB_HB->getTProfile()->SetMarkerStyle(20);
00212   ProblemsVsLB_HE->getTProfile()->SetMarkerStyle(20);
00213   ProblemsVsLB_HO->getTProfile()->SetMarkerStyle(20);
00214   ProblemsVsLB_HF->getTProfile()->SetMarkerStyle(20);
00215   ProblemsVsLB_HBHEHF->getTProfile()->SetMarkerStyle(20);
00216   MonitorElement* excludeHO2=dbe_->bookInt("ExcludeHOring2");
00217   // Fill with 0 if ring is not to be excluded; fill with 1 if it is to be excluded
00218   if (excludeHO2) excludeHO2->Fill(excludeHORing2_==true ? 1 : 0);
00219 
00220 
00221   //  Already done in base class:
00222   //dbe_->setCurrentFolder(subdir_);
00223   //meIevt_ = dbe_->bookInt("EventsProcessed");
00224   //if (meIevt_) meIevt_->Fill(-1);
00225   //meLevt_ = dbe_->bookInt("EventsProcessed_currentLS");
00226   //if (meLevt_) meLevt_->Fill(-1);
00227   //meTevt_ = dbe_->bookInt("EventsProcessed_All");
00228   //if (meTevt_) meTevt_->Fill(-1);
00229   //meTevtHist_=dbe_->book1D("EventsProcessed_AllHists","Counter of Events Processed By This Task",1,0.5,1.5);
00230   //if (meTevtHist_) meTevtHist_->Reset();
00231   
00232   std::string type;
00233       
00234   dbe_->setCurrentFolder(subdir_ + "Corruption"); 
00235   type = "01 Common Data Format violations";
00236   meCDFErrorFound_ = dbe_->book2D(type,type,32,699.5,731.5,9,0.5,9.5);
00237   meCDFErrorFound_->setAxisTitle("HCAL FED ID", 1);
00238   meCDFErrorFound_->setBinLabel(1, "Hdr1BitUnset", 2);
00239   meCDFErrorFound_->setBinLabel(2, "FmtNumChange", 2);
00240   meCDFErrorFound_->setBinLabel(3, "BOE not '0x5'", 2);
00241   meCDFErrorFound_->setBinLabel(4, "Hdr2Bit Set", 2);
00242   meCDFErrorFound_->setBinLabel(5, "Hdr1 36-55", 2);
00243   meCDFErrorFound_->setBinLabel(6, "BOE not 0", 2);
00244   meCDFErrorFound_->setBinLabel(7, "Trlr1Bit Set", 2);
00245   meCDFErrorFound_->setBinLabel(8, "Size Error", 2);
00246   meCDFErrorFound_->setBinLabel(9, "TrailerBad", 2);
00247       
00248   type = "02 DCC Event Format violation";
00249   meDCCEventFormatError_ = dbe_->book2D(type,type,32,699.5,731.5,6,0.5,6.5);
00250   meDCCEventFormatError_->setAxisTitle("HCAL FED ID", 1);
00251   meDCCEventFormatError_->setBinLabel(1, "FmtVers Changed", 2);
00252   meDCCEventFormatError_->setBinLabel(2, "StrayBits Changed", 2);
00253   meDCCEventFormatError_->setBinLabel(3, "HTRStatusPad", 2);
00254   meDCCEventFormatError_->setBinLabel(4, "32bitPadErr", 2);
00255   meDCCEventFormatError_->setBinLabel(5, "Number Mismatch Bit Miscalc", 2);      
00256   meDCCEventFormatError_->setBinLabel(6, "Low 8 HTR Status Bits Miscopy", 2);          
00257       
00258   type = "04 HTR BCN when OrN Diff";
00259   meBCNwhenOrNDiff_ = dbe_->book1D(type,type,3564,-0.5,3563.5);
00260   meBCNwhenOrNDiff_->setAxisTitle("BCN",1);
00261   meBCNwhenOrNDiff_->setAxisTitle("# of Entries",2);
00262       
00263   type = "03 OrN NonZero Difference HTR - DCC";
00264   meOrNCheck_ = dbe_->book1D(type,type,65,-32.5,32.5);
00265   meOrNCheck_->setAxisTitle("htr OrN - dcc OrN",1);
00266       
00267   type = "03 OrN Inconsistent - HTR vs DCC";
00268   meOrNSynch_= dbe_->book2D(type,type,32,700,732, 15,0,15);
00269   meOrNSynch_->setAxisTitle("FED #",1);
00270   meOrNSynch_->setAxisTitle("Spigot #",2);
00271       
00272   type = "05 BCN NonZero Difference HTR - DCC";
00273   meBCNCheck_ = dbe_->book1D(type,type,501,-250.5,250.5);
00274   meBCNCheck_->setAxisTitle("htr BCN - dcc BCN",1);
00275       
00276   type = "05 BCN Inconsistent - HTR vs DCC";
00277   meBCNSynch_= dbe_->book2D(type,type,32,700,732, 15,0,15);
00278   meBCNSynch_->setAxisTitle("FED #",1);
00279   meBCNSynch_->setAxisTitle("Slot #",2);
00280       
00281   type = "06 EvN NonZero Difference HTR - DCC";
00282   meEvtNCheck_ = dbe_->book1D(type,type,601,-300.5,300.5);
00283   meEvtNCheck_->setAxisTitle("htr Evt # - dcc Evt #",1);
00284       
00285   type = "06 EvN Inconsistent - HTR vs DCC";
00286   meEvtNumberSynch_= dbe_->book2D(type,type,32,700,732, 15,0,15);
00287   meEvtNumberSynch_->setAxisTitle("FED #",1);
00288   meEvtNumberSynch_->setAxisTitle("Slot #",2);
00289       
00290   //     ---------------- 
00291   //     | E!P | UE | TR |                                           
00292   // ----|  ND | OV | ID |                                             
00293   // | T | CRC | ST | ODD|                                             
00294   // --------------------                                              
00295   type="07 LRB Data Corruption Indicators";  
00296   meLRBDataCorruptionIndicators_= dbe_->book2D(type,type,
00297                                                 THREE_FED,0,THREE_FED,
00298                                                 THREE_SPG,0,THREE_SPG);
00299   label_xFEDs   (meLRBDataCorruptionIndicators_, 4); // 3 bins + 1 margin per ch.
00300   label_ySpigots(meLRBDataCorruptionIndicators_, 4); // 3 bins + 1 margin each spgt
00301       
00302   //     ---------------- 
00303   //     | CT | BE |    |
00304   //     | HM | 15 | WW | (Wrong Wordcount)
00305   //     | TM | CK | IW | (Illegal Wordcount)
00306   //     ---------------- 
00307   type="08 Half-HTR Data Corruption Indicators";
00308   meHalfHTRDataCorruptionIndicators_= dbe_->book2D(type,type,
00309                                                     THREE_FED,0,THREE_FED,
00310                                                     THREE_SPG,0,THREE_SPG);
00311   label_xFEDs   (meHalfHTRDataCorruptionIndicators_, 4); // 3 bins + 1 margin per ch.
00312   label_ySpigots(meHalfHTRDataCorruptionIndicators_, 4); // 3 bins + 1 margin each spgt
00313       
00314   //    ------------
00315   //    | !DV | Er  |
00316   //    | NTS | Cap |
00317   //    ------------
00318   type = "09 Channel Integrity Summarized by Spigot";
00319   meChannSumm_DataIntegrityCheck_= dbe_->book2D(type,type,
00320                                                  TWO___FED,0,TWO___FED,
00321                                                  TWO__SPGT,0,TWO__SPGT);
00322   label_xFEDs   (meChannSumm_DataIntegrityCheck_, 3); // 2 bins + 1 margin per ch.
00323   label_ySpigots(meChannSumm_DataIntegrityCheck_, 3); // 2 bins + 1 margin per spgt
00324       
00325   dbe_->setCurrentFolder(subdir_ + "Corruption/Channel Data Integrity");
00326   char label[256];
00327   for (int f=0; f<NUMDCCS; f++){      
00328     snprintf(label, 256, "FED %03d Channel Integrity", f+700);
00329     meChann_DataIntegrityCheck_[f] =  dbe_->book2D(label,label,
00330                                                     TWO_CHANN,0,TWO_CHANN,
00331                                                     TWO__SPGT,0,TWO__SPGT);
00332     label_xChanns (meChann_DataIntegrityCheck_[f], 3); // 2 bins + 1 margin per ch.
00333     label_ySpigots(meChann_DataIntegrityCheck_[f], 3); // 2 bins + 1 margin per spgt
00334     ;}
00335       
00336   dbe_->setCurrentFolder(subdir_ + "Data Flow"); 
00337   type="DCC Event Counts";
00338   mefedEntries_ = dbe_->book1D(type,type,32,699.5,731.5);
00339       
00340   type = "BCN from DCCs";
00341   medccBCN_ = dbe_->book1D(type,type,3564,-0.5,3563.5);
00342   medccBCN_->setAxisTitle("BCN",1);
00343   medccBCN_->setAxisTitle("# of Entries",2);
00344       
00345   type = "BCN from HTRs";
00346   meBCN_ = dbe_->book1D(type,type,3564,-0.5,3563.5);
00347   meBCN_->setAxisTitle("BCN",1);
00348   meBCN_->setAxisTitle("# of Entries",2);
00349       
00350   type = "DCC Data Block Size Distribution";
00351   meFEDRawDataSizes_=dbe_->book1D(type,type,1200,-0.5,12000.5);
00352   meFEDRawDataSizes_->setAxisTitle("# of bytes",1);
00353   meFEDRawDataSizes_->setAxisTitle("# of Data Blocks",2);
00354       
00355   type = "DCC Data Block Size Profile";
00356   meEvFragSize_ = dbe_->bookProfile(type,type,32,699.5,731.5,100,-1000.0,12000.0,"");
00357   type = "DCC Data Block Size Each FED";
00358   meEvFragSize2_ =  dbe_->book2D(type,type,64,699.5,731.5, 240,0,12000);
00359       
00360   //     ------------
00361   //     | OW | OFW |    "Two Caps HTR; Three Caps FED."
00362   //     | BZ | BSY |
00363   //     | EE | RL  |
00364   // ----------------
00365   // | CE |            (corrected error, Hamming code)
00366   // ------
00367   type = "01 Data Flow Indicators";
00368   meDataFlowInd_= dbe_->book2D(type,type,
00369                                 TWO___FED,0,TWO___FED,
00370                                 THREE_SPG,0,THREE_SPG);
00371   label_xFEDs   (meDataFlowInd_, 3); // 2 bins + 1 margin per ch.
00372   label_ySpigots(meDataFlowInd_, 4); // 3 bins + 1 margin each spgt
00373       
00374   dbe_->setCurrentFolder(subdir_ + "Diagnostics"); 
00375 
00376   type = "DCC Firmware Version";
00377   meDCCVersion_ = dbe_->bookProfile(type,type, 32, 699.5, 731.5, 256, -0.5, 255.5);
00378   meDCCVersion_ ->setAxisTitle("FED ID", 1);
00379       
00380   type = "HTR Status Word HBHE";
00381   HTR_StatusWd_HBHE =  dbe_->book1D(type,type,16,-0.5,15.5);
00382   labelHTRBits(HTR_StatusWd_HBHE,1);
00383       
00384   type = "HTR Status Word HF";
00385   HTR_StatusWd_HF =  dbe_->book1D(type,type,16,-0.5,15.5);
00386   labelHTRBits(HTR_StatusWd_HF,1);
00387       
00388   type = "HTR Status Word HO";
00389   HTR_StatusWd_HO = dbe_->book1D(type,type,16,-0.5,15.5);
00390   labelHTRBits(HTR_StatusWd_HO,1);
00391       
00392   int maxbits = 16;//Look at all 16 bits of the Error Words
00393   type = "HTR Status Word by Crate";
00394   meStatusWdCrate_ = dbe_->book2D(type,type,18,-0.5,17.5,maxbits,-0.5,maxbits-0.5);
00395   meStatusWdCrate_ -> setAxisTitle("Crate #",1);
00396   labelHTRBits(meStatusWdCrate_,2);
00397       
00398   type = "Unpacking - HcalHTRData check failures";
00399   meInvHTRData_= dbe_->book2D(type,type,16,-0.5,15.5,32,699.5,731.5);
00400   meInvHTRData_->setAxisTitle("Spigot #",1);
00401   meInvHTRData_->setAxisTitle("DCC #",2);
00402       
00403   type = "HTR Fiber Orbit Message BCN";
00404   meFibBCN_ = dbe_->book1D(type,type,3564,-0.5,3563.5);
00405   meFibBCN_->setAxisTitle("BCN of Fib Orb Msg",1);
00406       
00407   type = "HTR Status Word - Crate 0";
00408   meCrate0HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00409   meCrate0HTRStatus_ ->setAxisTitle("Slot #",1);
00410   labelHTRBits(meCrate0HTRStatus_,2);
00411       
00412   type = "HTR Status Word - Crate 1";
00413   meCrate1HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00414   meCrate1HTRStatus_ ->setAxisTitle("Slot #",1);
00415   labelHTRBits(meCrate1HTRStatus_,2);
00416       
00417   type = "HTR Status Word - Crate 2";
00418   meCrate2HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00419   meCrate2HTRStatus_ ->setAxisTitle("Slot #",1);
00420   labelHTRBits(meCrate2HTRStatus_,2);
00421       
00422   type = "HTR Status Word - Crate 3";
00423   meCrate3HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00424   meCrate3HTRStatus_ ->setAxisTitle("Slot #",1);
00425   labelHTRBits(meCrate3HTRStatus_,2);
00426       
00427   type = "HTR Status Word - Crate 4";
00428   meCrate4HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00429   meCrate4HTRStatus_ ->setAxisTitle("Slot #",1);
00430   labelHTRBits(meCrate4HTRStatus_,2);
00431 
00432   type = "HTR Status Word - Crate 5";
00433   meCrate5HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00434   meCrate5HTRStatus_ ->setAxisTitle("Slot #",1);
00435   labelHTRBits(meCrate5HTRStatus_,2);
00436 
00437   type = "HTR Status Word - Crate 6";
00438   meCrate6HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00439   meCrate6HTRStatus_ ->setAxisTitle("Slot #",1);
00440   labelHTRBits(meCrate6HTRStatus_,2);
00441 
00442   type = "HTR Status Word - Crate 7";
00443   meCrate7HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00444   meCrate7HTRStatus_ ->setAxisTitle("Slot #",1);
00445   labelHTRBits(meCrate7HTRStatus_,2);
00446 
00447   type = "HTR Status Word - Crate 9";
00448   meCrate9HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00449   meCrate9HTRStatus_ ->setAxisTitle("Slot #",1);
00450   labelHTRBits(meCrate9HTRStatus_,2);
00451 
00452   type = "HTR Status Word - Crate 10";
00453   meCrate10HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00454   meCrate10HTRStatus_ ->setAxisTitle("Slot #",1);
00455   labelHTRBits(meCrate10HTRStatus_,2);
00456 
00457   type = "HTR Status Word - Crate 11";
00458   meCrate11HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00459   meCrate11HTRStatus_ ->setAxisTitle("Slot #",1);
00460   labelHTRBits(meCrate11HTRStatus_,2);
00461 
00462   type = "HTR Status Word - Crate 12";
00463   meCrate12HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00464   meCrate12HTRStatus_ ->setAxisTitle("Slot #",1);
00465   labelHTRBits(meCrate12HTRStatus_,2);
00466 
00467   type = "HTR Status Word - Crate 13";
00468   meCrate13HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00469   meCrate13HTRStatus_ ->setAxisTitle("Slot #",1);
00470   labelHTRBits(meCrate13HTRStatus_,2);
00471 
00472   type = "HTR Status Word - Crate 14";
00473   meCrate14HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00474   meCrate14HTRStatus_ ->setAxisTitle("Slot #",1);
00475   labelHTRBits(meCrate14HTRStatus_,2);
00476 
00477   type = "HTR Status Word - Crate 15";
00478   meCrate15HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00479   meCrate15HTRStatus_ ->setAxisTitle("Slot #",1);
00480   labelHTRBits(meCrate15HTRStatus_,2);
00481 
00482   type = "HTR Status Word - Crate 17";
00483   meCrate17HTRStatus_ = dbe_->book2D(type,type,40,-0.25,19.75,maxbits,-0.5,maxbits-0.5);
00484   meCrate17HTRStatus_ ->setAxisTitle("Slot #",1);
00485   labelHTRBits(meCrate17HTRStatus_,2);
00486 
00487   type = "HTR UnSuppressed Event Fractions";
00488   meUSFractSpigs_ = dbe_->book1D(type,type,481,0,481);
00489   for(int f=0; f<NUMDCCS; f++) {
00490     snprintf(label, 256, "FED 7%02d", f);
00491     meUSFractSpigs_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f), label);
00492     for(int s=1; s<HcalDCCHeader::SPIGOT_COUNT; s++) {
00493       snprintf(label, 256, "sp%02d", s);
00494       meUSFractSpigs_->setBinLabel(1+(HcalDCCHeader::SPIGOT_COUNT*f)+s, label);}}
00495 
00496   // Firmware version
00497   type = "HTR Firmware Version";
00498   //  Maybe change to Profile histo eventually
00499   //meHTRFWVersion_ = dbe_->bookProfile(type,type,18,-0.5,17.5,245,10.0,255.0,"");
00500   meHTRFWVersion_ = dbe_->book2D(type,type ,18,-0.5,17.5,180,75.5,255.5);
00501   meHTRFWVersion_->setAxisTitle("Crate #",1);
00502   meHTRFWVersion_->setAxisTitle("HTR Firmware Version",2);
00503 
00504   type = "HTR Fiber 1 Orbit Message BCNs";
00505   meFib1OrbMsgBCN_= dbe_->book2D(type,type,40,-0.25,19.75,18,-0.5,17.5);
00506   type = "HTR Fiber 2 Orbit Message BCNs";
00507   meFib2OrbMsgBCN_= dbe_->book2D(type,type,40,-0.25,19.75,18,-0.5,17.5);
00508   type = "HTR Fiber 3 Orbit Message BCNs";
00509   meFib3OrbMsgBCN_= dbe_->book2D(type,type,40,-0.25,19.75,18,-0.5,17.5);
00510   type = "HTR Fiber 4 Orbit Message BCNs";
00511   meFib4OrbMsgBCN_= dbe_->book2D(type,type,40,-0.25,19.75,18,-0.5,17.5);
00512   type = "HTR Fiber 5 Orbit Message BCNs";
00513   meFib5OrbMsgBCN_= dbe_->book2D(type,type,40,-0.25,19.75,18,-0.5,17.5);
00514   type = "HTR Fiber 6 Orbit Message BCNs";
00515   meFib6OrbMsgBCN_= dbe_->book2D(type,type,40,-0.25,19.75,18,-0.5,17.5);
00516   type = "HTR Fiber 7 Orbit Message BCNs";
00517   meFib7OrbMsgBCN_= dbe_->book2D(type,type,40,-0.25,19.75,18,-0.5,17.5);
00518   type = "HTR Fiber 8 Orbit Message BCNs";
00519   meFib8OrbMsgBCN_= dbe_->book2D(type,type,40,-0.25,19.75,18,-0.5,17.5);
00520 
00521 }
00522 
00523 // Analyze
00524 void HcalRawDataMonitor::analyze(const edm::Event& e, const edm::EventSetup& s){
00525   if (!IsAllowedCalibType()) return;
00526   if (LumiInOrder(e.luminosityBlock())==false) return;
00527 
00528   HcalBaseDQMonitor::analyze(e,s); // base class increments ievt_, etc. counters
00529   
00530   // try to get die Data
00531   edm::Handle<FEDRawDataCollection> rawraw;
00532   if (!(e.getByLabel(FEDRawDataCollection_,rawraw)))
00533   //  if (!(e.getByType(rawraw)))
00534     {
00535       edm::LogWarning("HcalRawDataMonitor")<<" raw data with label "<<FEDRawDataCollection_ <<" not available";
00536       return;
00537     }
00538   edm::Handle<HcalUnpackerReport> report;  
00539   if (!(e.getByLabel(digiLabel_,report)))
00540     {
00541       edm::LogWarning("HcalRawDataMonitor")<<" Unpacker Report "<<digiLabel_<<" not available";
00542       return;
00543     }
00544 
00545   // all objects grabbed; event is good
00546   if (debug_>1) std::cout <<"\t<HcalRawDataMonitor::analyze>  Processing good event! event # = "<<ievt_<<std::endl;
00547   
00548   // Raw Data collection was grabbed successfully; process the Event
00549   processEvent(*rawraw, *report);
00550 
00551   //Loop over all cells, tallying problem counts before resetting
00552   //Extract the subdetector region given the location 
00553   for (int d=0; d<DEPTHBINS; d++) {
00554     for (int eta=0; eta<ETABINS; eta++) {
00555       int ieta=CalcIeta(eta,d+1);
00556       if (ieta==-9999) continue;
00557       for (int phi=0; phi<PHIBINS; phi++){
00558         if (problemcount[eta][phi][d]) {
00559           //      std::cout<<" "<<eta<<","<<phi<<","<<d<<" count:"<<problemcount[eta][phi][d]<<std::endl;           
00560           HcalSubdetector subdet=HcalEmpty;
00561           if (isHB(eta,d+1))subdet=HcalBarrel;
00562           else if (isHE(eta,d+1)) subdet=HcalEndcap;
00563           else if (isHF(eta,d+1)) subdet=HcalForward;
00564           else if (isHO(eta,d+1)) subdet=HcalOuter;
00565           if (subdet!=HcalEmpty){
00566             if (subdet==HcalBarrel)       {if(uniqcounter[eta][phi][d]<1) NumBadHB+= problemcount[eta][phi][d]; uniqcounter[eta][phi][d]++; }
00567             else if (subdet==HcalEndcap)  {if(uniqcounter[eta][phi][d]<1) NumBadHE+= problemcount[eta][phi][d]; uniqcounter[eta][phi][d]++; }
00569             else if (subdet==HcalOuter)  
00570               {
00571                 if(uniqcounter[eta][phi][d]<1) 
00572                   NumBadHO += problemcount[eta][phi][d];
00573                 uniqcounter[eta][phi][d]++; 
00574                 if (abs(ieta)<5) NumBadHO0+= problemcount[eta][phi][d];
00575                 else NumBadHO12+= problemcount[eta][phi][d];
00576               }
00577             else if (subdet==HcalForward)
00578               {
00579                 if(uniqcounter[eta][phi][d]<1) 
00580                   NumBadHF+= problemcount[eta][phi][d];
00581                 uniqcounter[eta][phi][d]++; 
00582                 if (d==1 && (abs(ieta)==33 || abs(ieta)==34))
00583                   NumBadHFLUMI+= problemcount[eta][phi][d];
00584                 else if (d==2 && (abs(ieta)==35 || abs(ieta)==36))
00585                   NumBadHFLUMI+= problemcount[eta][phi][d];
00586               }
00587           }
00588           problemcount[eta][phi][d]=0;
00589         }
00590       }
00591     }
00592   }
00593 }
00594 
00595 void HcalRawDataMonitor::processEvent(const FEDRawDataCollection& rawraw, 
00596                                       const HcalUnpackerReport& report){
00597   if(!dbe_) { 
00598     if (debug_>1)
00599       printf("HcalRawDataMonitor::processEvent DQMStore not instantiated!\n");  
00600     return;}
00601   
00602   // Fill event counters (underflow bins of histograms)
00603   meLRBDataCorruptionIndicators_->update();
00604   meHalfHTRDataCorruptionIndicators_->update();
00605   meChannSumm_DataIntegrityCheck_->update();
00606   for (int f=0; f<NUMDCCS; f++)      
00607     meChann_DataIntegrityCheck_[f]->update();
00608   meDataFlowInd_->update();
00609 
00610   // Loop over all FEDs reporting the event, unpacking if good.
00611   for (int i=FEDNumbering::MINHCALFEDID; i<=FEDNumbering::MAXHCALFEDID; i++) {
00612     const FEDRawData& fed = rawraw.FEDData(i);
00613     if (fed.size()<12) continue;  //At least the size of headers and trailers of a DCC.
00614 
00615     int value = (int)((const HcalDCCHeader*)(fed.data()))->getCalibType() ;
00616     if(value>7) 
00617       {
00618         edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Unexpected Calibration type: "<< value << " in FED: "<<i<<" (should be 0-7). I am bailing out...";
00619         return;
00620       }
00621 
00622     unpack(fed); //Interpret data, fill histograms, everything.
00623   }
00624   
00625   //increment problemcount[] where problemfound[], and clear problemfound[]
00626   for (int x=0; x<ETABINS; x++)
00627       for (int y=0; y<PHIBINS; y++)
00628         for (int z=0; z<DEPTHBINS; z++) 
00629           if (problemfound[x][y][z]) {
00630             problemcount[x][y][z]++;
00631             problemfound[x][y][z]=false;
00632           }
00633   return;
00634 } //void HcalRawDataMonitor::processEvent()
00635 
00636 // Process one FED's worth (one DCC's worth) of the event data.
00637 void HcalRawDataMonitor::unpack(const FEDRawData& raw){
00638 
00639   // get the DCC header & trailer (or bail out)
00640   const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(raw.data());
00641   if(!dccHeader) return;
00642   unsigned char* trailer_ptr = (unsigned char*) (raw.data()+raw.size()-sizeof(uint64_t));
00643   FEDTrailer trailer = FEDTrailer(trailer_ptr);
00644 
00645   // FED id declared in the header
00646   int dccid=dccHeader->getSourceId();
00647   //Force 0<= dcc_ <= 31
00648   int dcc_=std::max(0,dccid-700);  
00649   dcc_ = std::min(dcc_,31);       
00650   if(debug_>1) std::cout << "DCC " << dccid << std::endl;
00651   uint64_t* dccfw= (uint64_t*) (raw.data()+(sizeof(uint64_t)*2)); //64-bit DAQ word number 2 (from 0)
00652   int dcc_fw =  ( ((*dccfw)>>(6*8))&0x00000000000000FF );         //Shift right 6 bytes, get that low byte.
00653   meDCCVersion_ -> Fill(dccid,dcc_fw);
00654 
00655   //Before all else, how much data are we dealing with here?
00656   uint64_t* lastDataWord = (uint64_t*) ( raw.data()+(raw.size())-(1*sizeof(uint64_t)) );
00657   int EvFragLength = (int) (*lastDataWord>>(4*8)) & 0x0000000000FFFFFF ; //Shift right 4 bytes, get low 3 bytes.
00658   meFEDRawDataSizes_->Fill(EvFragLength*8);      //# 64-bit DAQ words *8 = # bytes. 
00659   meEvFragSize_ ->Fill(dccid, EvFragLength*8);   //# 64-bit DAQ words *8 = # bytes. 
00660   meEvFragSize2_ ->Fill(dccid, EvFragLength*8);  //# 64-bit DAQ words *8 = # bytes. 
00661   
00662   //Orbit, BunchCount, and Event Numbers
00663   unsigned long dccEvtNum = dccHeader->getDCCEventNumber();
00664   int dccBCN = dccHeader->getBunchId();
00665   //Mask down to 5 bits, since only used for comparison to HTR's five bit number...
00666   unsigned int dccOrN = (unsigned int) (dccHeader->getOrbitNumber() & 0x0000001F);
00667   medccBCN_ -> Fill(dccBCN);
00668 
00670   bool CDFProbThisDCC = false; 
00671   /* 1 */ //There should always be a second CDF header word indicated.
00672   if (!dccHeader->thereIsASecondCDFHeaderWord()
00673       //TESTME_HCALRAWDATA//
00674       //|| ((dccid==702)&&(tevt_%2==0))
00675       ) {
00676     meCDFErrorFound_->Fill(dccid, 1);
00677     CDFProbThisDCC = true; 
00678   }
00679   /* 2 */ //Make sure a reference CDF Version value has been recorded for this dccid
00680   CDFvers_it = CDFversionNumber_list.find(dccid);
00681   if (CDFvers_it  == CDFversionNumber_list.end()) {
00682     CDFversionNumber_list.insert(std::pair<int,short>
00683                                  (dccid,dccHeader->getCDFversionNumber() ) );
00684     CDFvers_it = CDFversionNumber_list.find(dccid);
00685   } // then check against it.
00686   if (dccHeader->getCDFversionNumber()!= CDFvers_it->second) {
00687     meCDFErrorFound_->Fill(dccid,2);
00688     CDFProbThisDCC = true; 
00689   }
00690   /* 3 */ //There should always be a '5' in CDF Header word 0, bits [63:60]
00691   if (dccHeader->BOEshouldBe5Always()!=5) {
00692     meCDFErrorFound_->Fill(dccid, 3);
00693     CDFProbThisDCC = true; 
00694   }
00695   /* 4 */ //There should never be a third CDF Header word indicated.
00696   if (dccHeader->thereIsAThirdCDFHeaderWord()) {
00697     meCDFErrorFound_->Fill(dccid, 4);
00698     CDFProbThisDCC = true; 
00699   }
00700   /* 5 */ //Make sure a reference value of Reserved Bits has been recorded for this dccid
00701   CDFReservedBits_it = CDFReservedBits_list.find(dccid);
00702   if (CDFReservedBits_it  == CDFReservedBits_list.end()) {
00703     CDFReservedBits_list.insert(std::pair<int,short>
00704                                 (dccid,dccHeader->getSlink64ReservedBits() & 0x0000FFFF ) );
00705     CDFReservedBits_it = CDFReservedBits_list.find(dccid);
00706   } // then check against it.
00707   if (((int) dccHeader->getSlink64ReservedBits() & 0x0000FFFF ) != CDFReservedBits_it->second) {
00708     meCDFErrorFound_->Fill(dccid,5);
00709     //CDFProbThisDCC = true; 
00710   }
00711   /* 6 */ //There should always be 0x0 in CDF Header word 1, bits [63:60]
00712   if (dccHeader->BOEshouldBeZeroAlways() !=0) {
00713     meCDFErrorFound_->Fill(dccid, 6);
00714     CDFProbThisDCC = true; 
00715   }
00716   /* 7 */ //There should only be one trailer
00717   if (trailer.moreTrailers()) {
00718     meCDFErrorFound_->Fill(dccid, 7);
00719     CDFProbThisDCC = true; 
00720   }
00721   //  if trailer.
00722   /* 8 */ //CDF Trailer [55:30] should be the # 64-bit words in the EvFragment
00723   if ((uint64_t) raw.size() != ( (uint64_t) trailer.lenght()*sizeof(uint64_t)) )  //The function name is a typo! Awesome.
00724     {
00725       meCDFErrorFound_->Fill(dccid, 8);
00726       CDFProbThisDCC = true; 
00727     }
00728   /* 9 */ //There is a rudimentary sanity check built into the FEDTrailer class
00729   if (!trailer.check()) {
00730     meCDFErrorFound_->Fill(dccid, 9);
00731     CDFProbThisDCC = true; 
00732   }
00733   if (CDFProbThisDCC) {
00734     //Set the problem flag for the ieta, iphi of any channel in this DCC
00735     mapDCCproblem(dcc_);
00736     if (debug_>0) std::cout <<"CDFProbThisDCC"<<std::endl;
00737   }
00738 
00739   mefedEntries_->Fill(dccid);
00740 
00741   CDFProbThisDCC = false;  // reset for the next go-round.
00742   
00743   char CRC_err;
00744   for(int i=0; i<HcalDCCHeader::SPIGOT_COUNT; i++) {
00745     CRC_err = ((dccHeader->getSpigotSummary(i) >> 10) & 0x00000001);
00746     if (CRC_err) {
00747       mapDCCproblem(dcc_);
00748       //Set the problem flag for the ieta, iphi of any channel in this DCC
00749       if (debug_>0) std::cout <<"HTR Problem: CRC_err"<<std::endl;
00750     }
00751   }
00752   
00753   // The DCC TTS state at event-sending time
00754   char TTS_state = (char)trailer.ttsBits();
00755   // The DCC TTS state at time L1A received (event enqueued to be built)
00756   char L1AtimeTTS_state=(char) dccHeader->getAcceptTimeTTS();
00757   if (TTS_state==L1AtimeTTS_state) ;//party
00758 
00760   /* 1 */ //Make sure a reference value of the DCC Event Format version has been noted for this dcc.
00761   DCCEvtFormat_it = DCCEvtFormat_list.find(dccid);
00762   if (DCCEvtFormat_it == DCCEvtFormat_list.end()) {
00763     DCCEvtFormat_list.insert(std::pair<int,short>
00764                              (dccid,dccHeader->getDCCDataFormatVersion() ) );
00765     DCCEvtFormat_it = DCCEvtFormat_list.find(dccid);
00766   } // then check against it.
00767   if (dccHeader->getDCCDataFormatVersion()!= DCCEvtFormat_it->second) {
00768     meDCCEventFormatError_->Fill(dccid,1);
00769     mapDCCproblem(dcc_);
00770     if (debug_>0)std::cout <<"DCC Error Type 1"<<std::endl;
00771   }
00772   /* 2 */ //Check for ones where there should always be zeros
00773   if (false) //dccHeader->getByte1Zeroes() || dccHeader->getByte3Zeroes() || dccHeader->getByte567Zeroes()) 
00774   {
00775     meDCCEventFormatError_->Fill(dccid,2);
00776     mapDCCproblem(dcc_);
00777     if (debug_>0)std::cout <<"DCC Error Type 2"<<std::endl;
00778   }
00779   /* 3 */ //Check that there are zeros following the HTR Status words.
00780   int SpigotPad = HcalDCCHeader::SPIGOT_COUNT;
00781   if (  (((uint64_t) dccHeader->getSpigotSummary(SpigotPad)  ) 
00782          | ((uint64_t) dccHeader->getSpigotSummary(SpigotPad+1)) 
00783          | ((uint64_t) dccHeader->getSpigotSummary(SpigotPad+2)))  != 0){
00784     meDCCEventFormatError_->Fill(dccid,3);
00785     mapDCCproblem(dcc_);
00786   if (debug_>0)std::cout <<"DCC Error Type 3"<<std::endl;
00787   }
00788   /* 4 */ //Check that there are zeros following the HTR Payloads, if needed.
00789   int nHTR32BitWords=0;
00790   // add up all the declared HTR Payload lengths
00791   for(int i=0; i<HcalDCCHeader::SPIGOT_COUNT; i++) {
00792     nHTR32BitWords += dccHeader->getSpigotDataLength(i);  }
00793   // if it's an odd number, check for the padding zeroes
00794   if (( nHTR32BitWords % 2) == 1) {
00795     uint64_t* lastDataWord = (uint64_t*) ( raw.data()+raw.size()-(2*sizeof(uint64_t)) );
00796     if ((*lastDataWord>>32) != 0x00000000){
00797       meDCCEventFormatError_->Fill(dccid, 4);
00798       mapDCCproblem(dcc_);
00799       if (debug_>0)std::cout <<"DCC Error Type 4"<<std::endl;
00800     }
00801   }
00802   
00803   //unsigned char HTRErrorList=0; 
00804   //for(int j=0; j<HcalDCCHeader::SPIGOT_COUNT; j++) {
00805   //  HTRErrorList=dccHeader->getSpigotErrorBits(j);    
00806   //}
00807 
00808   // These will be used in FED-vs-spigot 2D Histograms
00809   const int fed3offset = 1 + (4*dcc_); //3 bins, plus one of margin, each DCC
00810   const int fed2offset = 1 + (3*dcc_); //2 bins, plus one of margin, each DCC
00811   if (TTS_state & 0x8) /*RDY*/ 
00812     ;
00813   if (TTS_state & 0x2) /*SYN*/ 
00814     {
00815       mapDCCproblem(dcc_);
00816       if (debug_>0)std::cout <<"TTS_state Error:sync"<<std::endl;
00817     }
00818   //Histogram per-Spigot bits from the DCC Header
00819   int WholeErrorList=0; 
00820   for(int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {
00821     if (!( dccHeader->getSpigotEnabled((unsigned int) spigot)) )
00822       continue; //skip when not enabled
00823     // This will be used in FED-vs-spigot 2D Histograms
00824     const int spg3offset = 1 + (4*spigot); //3 bins, plus one of margin, each spigot
00825     
00826     if (TTS_state & 0x4) /*BSY*/ 
00827       ++DataFlowInd_[fed2offset+1][spg3offset+1];
00828     if (TTS_state & 0x1) /*OFW*/ 
00829       ++DataFlowInd_[fed2offset+1][spg3offset+2];
00830 
00831     WholeErrorList=dccHeader->getLRBErrorBits((unsigned int) spigot);
00832     if (WholeErrorList!=0) {
00833       if ((WholeErrorList>>0)&0x01)  //HammingCode Corrected -- Not data corruption!
00834         DataFlowInd_[fed2offset-1][spg3offset-1]++;
00835       if (((WholeErrorList>>1)&0x01)!=0)  {//HammingCode Uncorrected Error
00836         LRBDataCorruptionIndicators_[fed3offset+1][spg3offset+2]++;
00837         mapHTRproblem(dcc_,spigot);
00838       }
00839       if (((WholeErrorList>>2)&0x01)!=0)  {//Truncated data coming into LRB
00840         LRBDataCorruptionIndicators_[fed3offset+2][spg3offset+2]++;
00841         mapHTRproblem(dcc_,spigot);
00842       }
00843       if (((WholeErrorList>>3)&0x01)!=0)  {//FIFO Overflow
00844         LRBDataCorruptionIndicators_[fed3offset+1][spg3offset+1]++;
00845         mapHTRproblem(dcc_,spigot);
00846       }
00847       if (((WholeErrorList>>4)&0x01)!=0)  {//ID (EvN Mismatch), htr payload metadeta
00848         LRBDataCorruptionIndicators_[fed3offset+2][spg3offset+1]++;
00849         mapHTRproblem(dcc_,spigot);
00850       }
00851       if (((WholeErrorList>>5)&0x01)!=0)  {//STatus: hdr/data/trlr error
00852         LRBDataCorruptionIndicators_[fed3offset+1][spg3offset+0]++;
00853         mapHTRproblem(dcc_,spigot);
00854       }
00855       if (((WholeErrorList>>6)&0x01)!=0)  {//ODD 16-bit word count from HTR
00856         LRBDataCorruptionIndicators_[fed3offset+2][spg3offset+0]++;
00857         mapHTRproblem(dcc_,spigot);
00858       }
00859     }
00860     if (!dccHeader->getSpigotPresent((unsigned int) spigot)){
00861       LRBDataCorruptionIndicators_[fed3offset+0][spg3offset+2]++;  //Enabled, but data not present!
00862       mapHTRproblem(dcc_,spigot);
00863       if (debug_>0)std::cout <<"HTR Problem: Spigot Not Present"<<std::endl;
00864     } else {
00865       if ( dccHeader->getSpigotDataTruncated((unsigned int) spigot)) {
00866         LRBDataCorruptionIndicators_[fed3offset-1][spg3offset+0]++;  // EventBuilder truncated babbling LRB
00867         mapHTRproblem(dcc_,spigot);
00868         if (debug_>0)std::cout <<"HTR Problem: Spigot Data Truncated"<<std::endl;
00869       }
00870       if ( dccHeader->getSpigotCRCError((unsigned int) spigot)) {
00871         LRBDataCorruptionIndicators_[fed3offset+0][spg3offset+0]++; 
00872         mapHTRproblem(dcc_,spigot);
00873       }
00874     } //else spigot marked "Present"
00875     if (dccHeader->getSpigotDataLength(spigot) <(unsigned long)4) {
00876       LRBDataCorruptionIndicators_[fed3offset+0][spg3offset+1]++;  //Lost HTR Data for sure.
00877       mapHTRproblem(dcc_,spigot);
00878       if (debug_>0)std::cout <<"HTR Problem: Spigot Data Length too small"<<std::endl;
00879     }    
00880   }
00881 
00882   // Walk through the HTR data...
00883   HcalHTRData htr;  
00884   for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++) {    
00885     const int spg3offset = 1 + (4*spigot); //3 bins, plus one of margin, each spigot
00886     const int spg2offset = 1 + (3*spigot); //3 bins, plus one of margin, each spigot
00887     if (!dccHeader->getSpigotPresent(spigot)) continue;
00888 
00889     // Load the given decoder with the pointer and length from this spigot.
00890     // i.e.     initialize htr, within dcc raw data size.
00891     dccHeader->getSpigotData(spigot,htr, raw.size()); 
00892     const unsigned short* HTRraw = htr.getRawData();
00893 
00894     // check min length, correct wordcount, empty event, or total length if histo event.
00895     if (!htr.check()) {
00896       meInvHTRData_ -> Fill(spigot,dccid);
00897       mapHTRproblem(dcc_,spigot);
00898       if (debug_>0)std::cout <<"HTR Problem: HTR check fails"<<std::endl;
00899     }
00900 
00901     unsigned short HTRwdcount = htr.getRawLength();
00902     if (HTRwdcount == 0) 
00903       {
00904         edm::LogWarning("HcalMonitorModule::RawDataTas") << "Unexpected Raw Length: "<< HTRwdcount <<" I am bailing out...";    
00905         continue;
00906       }
00907 
00908     // Size checks for internal consistency
00909     // getNTP(), get NDD() seems to be mismatched with format. Manually:
00910     int NTP = ((htr.getExtHdr6() >> 8) & 0x00FF);
00911     int NDAQ = (HTRraw[htr.getRawLength() - 4] & 0x7FF);
00912 
00913     if ( !  ((HTRwdcount != 8)               ||
00914              (HTRwdcount != 12 + NTP + NDAQ) ||
00915              (HTRwdcount != 20 + NTP + NDAQ)    )) {
00916       ++HalfHTRDataCorruptionIndicators_[fed3offset+2][spg3offset+0];
00917       mapHTRproblem(dcc_,spigot);
00918       if (debug_>0)std::cout <<"HTR Problem: NTP+NDAQ size consistency check fails"<<std::endl;
00919       //incompatible Sizes declared. Skip it.
00920       continue; }
00921     bool EE = ((dccHeader->getSpigotErrorBits(spigot) >> 2) & 0x01);
00922     if (EE) { 
00923       if (HTRwdcount != 8) {    //incompatible Sizes declared. Skip it.
00924         ++HalfHTRDataCorruptionIndicators_[fed3offset+2][spg3offset+1];
00925         if (debug_>0)std::cout <<"HTR Problem: HTRwdcount !=8"<<std::endl;      
00926       }
00927       DataFlowInd_[fed2offset+0][spg3offset+0]++;
00928       continue;}
00929     else{ //For non-EE, both CompactMode and !CompactMode
00930       bool CM = (htr.getExtHdr7() >> 14)&0x0001;
00931       int paddingsize = ((NDAQ+NTP)%2); //Extra padding to make HTRwdcount even
00932       if (( CM && ( (HTRwdcount-NDAQ-NTP-paddingsize) != 12) )
00933           ||                                
00934           (!CM && ( (HTRwdcount-NDAQ-NTP-paddingsize) != 20) )  ) {     //incompatible Sizes declared. Skip it.
00935         ++HalfHTRDataCorruptionIndicators_[fed3offset+2][spg3offset+1];
00936         mapHTRproblem(dcc_,spigot);
00937         continue;} }
00938 
00939     if (htr.isHistogramEvent()) continue;
00940 
00941     //We trust the data now.  Finish with the check against DCCHeader
00942     unsigned int htrOrN = htr.getOrbitNumber(); 
00943     unsigned int htrBCN = htr.getBunchNumber(); 
00944     unsigned int htrEvtN = htr.getL1ANumber();
00945     meBCN_->Fill(htrBCN);  //The only periodic number for whole events.
00946 
00947     if (( (htrOrN  == dccOrN ) &&
00948           (htrBCN  == (unsigned int) dccBCN) )  
00949         != (dccHeader->getBxMismatchWithDCC(spigot))  ){
00950       meDCCEventFormatError_->Fill(dccid,5);
00951       mapHTRproblem(dcc_,spigot);
00952       if (debug_>0)std::cout <<"Orbit or BCN  HTR/DCC mismatch"<<std::endl;
00953     }
00954     if ( (htrEvtN == dccEvtNum) != 
00955          dccHeader->getSpigotValid(spigot) ) {
00956       meDCCEventFormatError_->Fill(dccid,5);
00957       mapHTRproblem(dcc_,spigot);
00958       if (debug_>0)std::cout <<"DCC invalid spigot"<<std::endl;
00959     }
00960     int cratenum = htr.readoutVMECrateId();
00961     float slotnum = htr.htrSlot() + 0.5*htr.htrTopBottom();
00962     if (debug_ > 0) HTRPrint(htr,debug_);
00963     unsigned int htrFWVer = htr.getFirmwareRevision() & 0xFF;
00964     meHTRFWVersion_->Fill(cratenum,htrFWVer);  
00965 
00967     int EvtNdiff = htrEvtN - dccEvtNum;
00968     if (EvtNdiff!=0) {
00969       meEvtNumberSynch_->Fill(dccid,spigot);
00970       mapHTRproblem(dcc_,spigot);
00971       meEvtNCheck_->Fill(EvtNdiff);
00972       if (debug_ == 1)std::cout << "++++ Evt # out of sync, ref, this HTR: "<< dccEvtNum << "  "<<htrEvtN <<std::endl;
00973     }
00974 
00976     int BCNdiff = htrBCN-dccBCN;
00977     if ((BCNdiff!=0) 
00978         //TESTME_HCALRAWDATA//
00979         //|| ((dccid==727) && (spigot==8) && (dccEvtNum%3==0))
00980         ){
00981       meBCNSynch_->Fill(dccid,spigot);
00982       mapHTRproblem(dcc_,spigot);
00983       meBCNCheck_->Fill(BCNdiff);
00984       if (debug_==1)std::cout << "++++ BCN # out of sync, ref, this HTR: "<< dccBCN << "  "<<htrBCN <<std::endl;
00985     }
00986 
00988     int OrNdiff = htrOrN-dccOrN;
00989     if (OrNdiff!=0) {
00990       meOrNSynch_->Fill(dccid,spigot);
00991       mapHTRproblem(dcc_,spigot);
00992       meOrNCheck_->Fill(OrNdiff);
00993       meBCNwhenOrNDiff_->Fill(htrBCN); // Are there special BCN where OrN mismatched occur? Let's see.
00994       if (debug_==1)std::cout << "++++ OrN # out of sync, ref, this HTR: "<< dccOrN << "  "<<htrOrN <<std::endl;
00995     }
00996 
00997     bool htrUnSuppressed=(HTRraw[6]>>15 & 0x0001);
00998     if (htrUnSuppressed) {
00999       UScount[dcc_][spigot]++;
01000       int here=1+(HcalDCCHeader::SPIGOT_COUNT*(dcc_))+spigot;
01001       meUSFractSpigs_->Fill(here,
01002                             ((double)UScount[dcc_][spigot]));}
01003 
01004     MonitorElement* tmpErr = 0;
01005     HcalDetId HDI = hashedHcalDetId_[hashup(dcc_,spigot)];
01006     if (HDI != HcalDetId::Undefined) {
01007       switch (HDI.subdetId()) {
01008       case (HcalBarrel): {
01009         tmpErr = HTR_StatusWd_HBHE;
01010       } break;
01011       case (HcalEndcap): {
01012         tmpErr = HTR_StatusWd_HBHE;
01013       } break;
01014       case (HcalOuter): {
01015         tmpErr = HTR_StatusWd_HO;
01016       } break;
01017       case (HcalForward): {
01018         tmpErr = HTR_StatusWd_HF; 
01019       } break;
01020       default: break;
01021       }
01022     }
01023    
01024     int errWord = htr.getErrorsWord() & 0xFFFF;
01025     if (  (((dccHeader->getSpigotSummary( spigot))>>24)&0x00FF)
01026           != (errWord&0x00FF) ){
01027       meDCCEventFormatError_->Fill(dccid,6);//Low 8 bits miscopied into DCCHeader
01028       mapHTRproblem(dcc_,spigot);
01029       if (debug_>0)std::cout <<"DCC spigot summary error or HTR error word"<<std::endl;
01030       //What other problems may lurk? Spooky.
01031     }
01032     if(tmpErr!=NULL){
01033       for(int i=0; i<16; i++){
01034         int errbit = errWord&(0x01<<i);
01035         // Bit 15 should always be 1; consider it an error if it isn't.
01036         if (i==15) errbit = errbit - 0x8000;
01037         if (errbit !=0) {
01038           tmpErr->Fill(i);
01039           //Only certain bits indicate corrupted data:
01040           switch (i) {
01041           case (14): //CT (obsolete Calibration Trigger scheme used)
01042             HalfHTRDataCorruptionIndicators_[fed3offset+0][spg3offset+2]++;
01043             mapHTRproblem(dcc_,spigot);
01044             if (debug_>0)std::cout <<"HTR Problem: Case 14"<<std::endl;
01045             break;
01046           case (13): //HM
01047             HalfHTRDataCorruptionIndicators_[fed3offset+0][spg3offset+1]++;
01048             mapHTRproblem(dcc_,spigot);
01049             if (debug_>0)std::cout <<"HTR Problem: Case 13"<<std::endl;
01050             break;
01051           case (12): //TM
01052             HalfHTRDataCorruptionIndicators_[fed3offset+0][spg3offset+0]++;
01053             mapHTRproblem(dcc_,spigot);
01054             if (debug_>0)std::cout <<"HTR Problem: Case 12"<<std::endl;
01055             break;
01056           case ( 8): //BE
01057             HalfHTRDataCorruptionIndicators_[fed3offset+1][spg3offset+2]++;
01058             mapHTRproblem(dcc_,spigot);
01059             if (debug_>0)std::cout <<"HTR Problem: Case 8"<<std::endl;
01060             break;
01061           case (15): //b15
01062             HalfHTRDataCorruptionIndicators_[fed3offset+1][spg3offset+1]++;
01063             mapHTRproblem(dcc_,spigot);
01064             break;
01065           case ( 7): //CK
01066             HalfHTRDataCorruptionIndicators_[fed3offset+1][spg3offset+0]++;
01067             mapHTRproblem(dcc_,spigot);
01068             if (debug_>0)std::cout <<"HTR Problem: Case 7"<<std::endl;
01069             break;
01070           //\\case ( 5): //LW removed 2010.02.16
01071           //\\  HalfHTRDataCorruptionIndicators_[fed3offset+2][spg3offset+2]++;
01072           //\\  //Sometimes set spuriously at startup, per-fiber, .: Leniency: 8
01073           //\\  if (HalfHTRDataCorruptionIndicators_[fed3offset+2][spg3offset+2] > 8) { 
01074           //\\    if (debug_>0)std::cout <<"HTR Problem: Case 5"<<std::endl;
01075           //\\    break; 
01076           //\\  }
01077           case ( 3): //L1 (previous L1A violated trigger rules)
01078             DataFlowInd_[fed2offset+1][spg3offset+0]++; break;
01079           case ( 1): //BZ
01080             DataFlowInd_[fed2offset+0][spg3offset+1]++; break;
01081           case ( 0): //OW
01082             DataFlowInd_[fed2offset+0][spg3offset+2]++;
01083           default: break;
01084           }
01085           meStatusWdCrate_->Fill(cratenum,i);
01086           if      (cratenum == 0) meCrate0HTRStatus_ -> Fill(slotnum,i);
01087           else if (cratenum == 1) meCrate1HTRStatus_ -> Fill(slotnum,i);
01088           else if (cratenum == 2) meCrate2HTRStatus_ -> Fill(slotnum,i);
01089           else if (cratenum == 3) meCrate3HTRStatus_ -> Fill(slotnum,i);
01090           else if (cratenum == 4) meCrate4HTRStatus_ -> Fill(slotnum,i);
01091           else if (cratenum == 5) meCrate5HTRStatus_ -> Fill(slotnum,i);
01092           else if (cratenum == 6) meCrate6HTRStatus_ -> Fill(slotnum,i);
01093           else if (cratenum == 7) meCrate7HTRStatus_ -> Fill(slotnum,i);
01094           else if (cratenum == 9) meCrate9HTRStatus_ -> Fill(slotnum,i);
01095           else if (cratenum ==10)meCrate10HTRStatus_ -> Fill(slotnum,i);
01096           else if (cratenum ==11)meCrate11HTRStatus_ -> Fill(slotnum,i);
01097           else if (cratenum ==12)meCrate12HTRStatus_ -> Fill(slotnum,i);
01098           else if (cratenum ==13)meCrate13HTRStatus_ -> Fill(slotnum,i);
01099           else if (cratenum ==14)meCrate14HTRStatus_ -> Fill(slotnum,i);
01100           else if (cratenum ==15)meCrate15HTRStatus_ -> Fill(slotnum,i);
01101           else if (cratenum ==17)meCrate17HTRStatus_ -> Fill(slotnum,i);
01102         } 
01103       }
01104     }
01105  
01106     // Fish out Front-End Errors from the precision channels
01107     const short unsigned int* daq_first, *daq_last, *tp_first, *tp_last;
01108     const HcalQIESample* qie_begin, *qie_end, *qie_work;
01109     
01110     // get pointers
01111     htr.dataPointers(&daq_first,&daq_last,&tp_first,&tp_last);
01112     qie_begin=(HcalQIESample*)daq_first;
01113     qie_end=(HcalQIESample*)(daq_last+1); // one beyond last..
01114     
01115     //TESTME_HCALRAWDATA//if (dccid==715 && spigot==5 && tevt_%3==0)
01116     //TESTME_HCALRAWDATA//  Chann_DataIntegrityCheck_[dcc_][16][spg2offset]++;    
01117 
01119     if (htr.getFormatVersion() < 6 ) { //HcalHTRData::FORMAT_VERSION_COMPACT_DATA is 6
01120 
01121       int lastcapid=-1;
01122       int samplecounter=-1;
01123       int htrchan=-1; // Valid: [1,24]
01124       int chn2offset=0; 
01125       int NTS = htr.getNDD(); //number time slices, in precision channels
01126 
01127       ChannSumm_DataIntegrityCheck_  [fed2offset-1][spg2offset+0]=-NTS;//For normalization by client - NB! negative!
01128       // Run over DAQ words for this spigot
01129       for (qie_work=qie_begin; qie_work!=qie_end; qie_work++) {
01130         if (qie_work->raw()==0xFFFF)  // filler word
01131           continue;
01132         //Beginning a channel's samples?
01133         if (( 1 + ( 3* (qie_work->fiber()-1) ) + qie_work->fiberChan() )  != htrchan) { //new channel starting
01134           // A fiber [1..8] carries three fiber channels, each is [0..2]. Make htrchan [1..24]
01135           htrchan= (3* (qie_work->fiber()-1) ) + qie_work->fiberChan(); 
01136           chn2offset = (htrchan*3)+1;
01137           --ChannSumm_DataIntegrityCheck_  [fed2offset-1][spg2offset-1];//event tally -- NB! negative!
01138           --Chann_DataIntegrityCheck_[dcc_][chn2offset-1][spg2offset-1];//event tally -- NB! negative!
01139           if (samplecounter !=-1) { //Wrap up the previous channel if there is one
01140             //Check the previous digi for number of timeslices
01141             if (((samplecounter != NTS) &&
01142                  (samplecounter != 1)             )
01143                 //||
01144                 //((htrchan==5) && (spigot==5) && (dcc_==5))
01145                 )
01146               { //Wrong DigiSize
01147                 ++ChannSumm_DataIntegrityCheck_  [fed2offset+0][spg2offset+0];
01148                 ++Chann_DataIntegrityCheck_[dcc_][chn2offset+0][spg2offset+0];
01149                 mapChannproblem(dcc_,spigot,htrchan);
01150                 if (debug_)std::cout <<"mapChannelProblem:  Wrong Digi Size"<<std::endl;
01151               } 
01152           }     
01153           //set up for this new channel
01154           lastcapid=qie_work->capid();
01155           samplecounter=1;} // fi (qie_work->fiberAndChan() != lastfibchan)
01156         else { //precision samples not the first timeslice
01157           int hope = lastcapid +1;// What capid would we hope for here?
01158           if (hope==4) hope = 0;  // What capid would we hope for here?
01159           if (qie_work->capid() != hope){
01160             ++ChannSumm_DataIntegrityCheck_  [fed2offset+1][spg2offset+0];
01161             ++Chann_DataIntegrityCheck_[dcc_][chn2offset+1][spg2offset+0];
01162             mapChannproblem(dcc_,spigot,htrchan);
01163             if (debug_)std::cout <<"mapChannelProblem:  Wrong Cap ID"<<std::endl;
01164           }
01165           lastcapid=qie_work->capid();
01166           samplecounter++;}
01167         //For every sample, whether the first of the channel or not, !DV, Er
01168         if (!(qie_work->dv())){
01169           ++ChannSumm_DataIntegrityCheck_  [fed2offset+0][spg2offset+1];
01170           ++Chann_DataIntegrityCheck_[dcc_][chn2offset+0][spg2offset+1];
01171         }
01172         if (qie_work->er()) {      // FEE - Front End Error
01173           ++ChannSumm_DataIntegrityCheck_  [fed2offset+1][spg2offset+1];
01174           ++Chann_DataIntegrityCheck_[dcc_][chn2offset+1][spg2offset+1]; 
01175           mapChannproblem(dcc_,spigot,htrchan);
01176           if (debug_)std::cout <<"mapChannelProblem:  FE Error"<<std::endl;     
01177         }
01178       } // for (qie_work = qie_begin;...)  end loop over all timesamples in this spigot
01179       //Wrap up the last channel
01180       //Check the last digi for number of timeslices
01181       if ((samplecounter != NTS) &&
01182           (samplecounter != 1)            &&
01183           (samplecounter !=-1)             ) { //Wrong DigiSize (unexpected num. timesamples)
01184         ++ChannSumm_DataIntegrityCheck_  [fed2offset+0][spg2offset+0];
01185         ++Chann_DataIntegrityCheck_[dcc_][chn2offset+0][spg2offset+0];
01186         mapChannproblem(dcc_,spigot,htrchan);
01187         if (debug_)std::cout <<"mapChannelProblem:  Wrong Digi Size (last digi)"<<std::endl;
01188       }
01189     } else { // this is the branch for unpacking the compact data format with per-channel headers
01190       const unsigned short* ptr_header=daq_first;
01191       const unsigned short* ptr_end=daq_last+1;
01192       int flavor, error_flags, capid0, channelid;
01193       // int samplecounter=-1;  // for a digisize check
01194       int htrchan=-1; // Valid: [1,24]
01195       int chn2offset=0; 
01196       int NTS = htr.getNDD(); //number time slices, in precision channels
01197       int Nchan = 3; // 3 channels per fiber
01198       while (ptr_header!=ptr_end) {
01199         if (*ptr_header==0xFFFF) { // impossible filler word
01200           ptr_header++;
01201           continue;
01202         }
01203         error_flags = capid0 = channelid = 0;
01204         // unpack the header word
01205         bool isheader=HcalHTRData::unpack_per_channel_header(*ptr_header,flavor,error_flags,capid0,channelid);
01206         if (!isheader) {
01207           ptr_header++;
01208           continue;
01209         }
01210         // A fiber [1..8] carries three fiber channels, each is [0..2]. Make htrchan [1..24]
01211         int fiber = 1 + ((channelid & 0x1C) >> 2); //Mask and shift to get bits [2:4]
01212         int chan = channelid & 0x3; //bits [0:1]
01213         htrchan = ((fiber -1) * Nchan) + chan + 1;  //ta-dah! I really wish everything counted from zero...
01214         chn2offset = ((htrchan-1)*3)+1; //For placing the errors on the histogram. Also very tidy. Sorry.
01215         //debug// if (error_flags) std::cout<<fiber<<","<<chan<<" = "<<htrchan<<"   @"<<chn2offset<<std::endl;
01216         ChannSumm_DataIntegrityCheck_  [fed2offset-1][spg2offset-1] -= NTS;//event tally -- NB: negative!
01217         Chann_DataIntegrityCheck_[dcc_][chn2offset-1][spg2offset-1] -= NTS;//event tally -- NB: negative!
01218         if (error_flags & 2) { //a CapId violation (non correct rotation)
01219           ++ChannSumm_DataIntegrityCheck_  [fed2offset+1][spg2offset+0];
01220           ++Chann_DataIntegrityCheck_[dcc_][chn2offset+1][spg2offset+0];
01221           mapChannproblem(dcc_,spigot,htrchan);
01222         }
01223         if (error_flags & 1) { //an asserted Link-Error (Er)
01224           ++ChannSumm_DataIntegrityCheck_  [fed2offset+1][spg2offset+1];
01225           ++Chann_DataIntegrityCheck_[dcc_][chn2offset+1][spg2offset+1]; 
01226           mapChannproblem(dcc_,spigot,htrchan);
01227         }
01228 
01229         for (ptr_header++;
01230              ptr_header!=ptr_end && !HcalHTRData::is_channel_header(*ptr_header);
01231              ptr_header++);      
01232       }
01233     }
01234     unsigned int fib1BCN = htr.getFib1OrbMsgBCN();
01235     unsigned int fib2BCN = htr.getFib2OrbMsgBCN();
01236     unsigned int fib3BCN = htr.getFib3OrbMsgBCN();
01237     unsigned int fib4BCN = htr.getFib4OrbMsgBCN();
01238     unsigned int fib5BCN = htr.getFib5OrbMsgBCN();
01239     unsigned int fib6BCN = htr.getFib6OrbMsgBCN();
01240     unsigned int fib7BCN = htr.getFib7OrbMsgBCN();
01241     unsigned int fib8BCN = htr.getFib8OrbMsgBCN();
01242     meFibBCN_->Fill(fib1BCN);
01243     meFibBCN_->Fill(fib2BCN);
01244     meFibBCN_->Fill(fib3BCN);
01245     meFibBCN_->Fill(fib4BCN);
01246     meFibBCN_->Fill(fib5BCN);
01247     meFibBCN_->Fill(fib6BCN);
01248     meFibBCN_->Fill(fib7BCN);
01249     meFibBCN_->Fill(fib8BCN);
01250     // Disable for now?
01251     meFib1OrbMsgBCN_->Fill(slotnum, cratenum, fib1BCN);
01252     meFib2OrbMsgBCN_->Fill(slotnum, cratenum, fib2BCN);
01253     meFib3OrbMsgBCN_->Fill(slotnum, cratenum, fib3BCN);
01254     meFib4OrbMsgBCN_->Fill(slotnum, cratenum, fib4BCN);
01255     meFib5OrbMsgBCN_->Fill(slotnum, cratenum, fib5BCN);
01256     meFib6OrbMsgBCN_->Fill(slotnum, cratenum, fib6BCN);
01257     meFib7OrbMsgBCN_->Fill(slotnum, cratenum, fib7BCN);
01258     meFib8OrbMsgBCN_->Fill(slotnum, cratenum, fib8BCN);
01259     
01260   } //  loop over spigots 
01261   return;
01262 } // loop over DCCs void HcalRawDataMonitor::unpack(
01263 
01264 
01265 // End LumiBlock
01266 void HcalRawDataMonitor::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
01267                                             const edm::EventSetup& c){
01268   
01269   
01270   ProblemsVsLB_HB->Fill(lumiSeg.luminosityBlock(),NumBadHB);
01271   ProblemsVsLB_HE->Fill(lumiSeg.luminosityBlock(),NumBadHE);
01272   ProblemsVsLB_HO->Fill(lumiSeg.luminosityBlock(),NumBadHO);
01273   ProblemsVsLB_HF->Fill(lumiSeg.luminosityBlock(),NumBadHF);
01274   ProblemsVsLB_HBHEHF->Fill(lumiSeg.luminosityBlock(),NumBadHB+NumBadHE+NumBadHF);
01275   ProblemsVsLB->Fill(lumiSeg.luminosityBlock(),NumBadHB+NumBadHE+NumBadHO+NumBadHF);
01276   
01277   // Reset current LS histogram, if it exists
01278   if (ProblemsCurrentLB)
01279     ProblemsCurrentLB->Reset();
01280   if (ProblemsCurrentLB)
01281     {
01282      
01283       ProblemsCurrentLB->setBinContent(0,0, levt_);  // underflow bin contains number of events
01284       ProblemsCurrentLB->setBinContent(1,1, NumBadHB*levt_);
01285       ProblemsCurrentLB->setBinContent(2,1, NumBadHE*levt_);
01286       ProblemsCurrentLB->setBinContent(3,1, NumBadHO*levt_);
01287       ProblemsCurrentLB->setBinContent(4,1, NumBadHF*levt_);
01288       ProblemsCurrentLB->setBinContent(5,1, NumBadHO0*levt_);
01289       ProblemsCurrentLB->setBinContent(6,1, NumBadHO12*levt_);
01290       ProblemsCurrentLB->setBinContent(7,1, NumBadHFLUMI*levt_);
01291 
01292     }
01293 
01294   for (int d=0; d<DEPTHBINS; d++) {
01295     for (int eta=0; eta<ETABINS; eta++) {
01296       for (int phi=0; phi<PHIBINS; phi++){
01297         uniqcounter[eta][phi][d] = 0.0;
01298       }
01299     }
01300   }
01301 
01302   UpdateMEs();
01303 }
01304 // EndRun -- Anything to do here?
01305 void HcalRawDataMonitor::endRun(const edm::Run& run, const edm::EventSetup& c){}
01306 
01307 // EndJob
01308 void HcalRawDataMonitor::endJob(void){
01309   if (debug_>0) std::cout <<"HcalRawDataMonitor::endJob()"<<std::endl;
01310   if (enableCleanup_) cleanup(); // when do we force cleanup?
01311 }
01312 
01313 //No size checking; better have enough y-axis bins!
01314 void HcalRawDataMonitor::label_ySpigots(MonitorElement* me_ptr, int ybins) {
01315   char label[32];
01316   for (int spig=0; spig<HcalDCCHeader::SPIGOT_COUNT; spig++) {
01317     snprintf(label, 32, "Spgt %02d", spig);
01318     me_ptr->setBinLabel((2+(spig*ybins)), label, 2); //margin of 1 at low value
01319   }
01320 }
01321 
01322 //No size checking; better have enough x-axis bins!
01323 void HcalRawDataMonitor::label_xChanns(MonitorElement* me_ptr, int xbins) {
01324   char label[32];
01325   for (int ch=0; ch<HcalHTRData::CHANNELS_PER_SPIGOT; ch++) {
01326     snprintf(label, 32, "Ch %02d", ch+1);
01327     me_ptr->setBinLabel((2+(ch*xbins)), label, 1); //margin of 3 at low value
01328   }
01329 }
01330 
01331 //No size checking; better have enough x-axis bins!
01332 void HcalRawDataMonitor::label_xFEDs(MonitorElement* me_ptr, int xbins) {
01333   char label[32];
01334   for (int thfed=0; thfed<NUMDCCS; thfed++) {
01335     snprintf(label, 32, "%03d", thfed+700);
01336     me_ptr->setBinLabel((2+(thfed*xbins)), label, 1); //margin of 1 at low value
01337   }
01338 }
01339 
01340 void HcalRawDataMonitor::labelHTRBits(MonitorElement* mePlot,unsigned int axisType) {
01341 
01342   if (axisType !=1 && axisType != 2) return;
01343 
01344   mePlot -> setBinLabel(1,"Overflow Warn",axisType);
01345   mePlot -> setBinLabel(2,"Buffer Busy",axisType);
01346   mePlot -> setBinLabel(3,"Empty Event",axisType);
01347   mePlot -> setBinLabel(4,"Rejected L1A",axisType);
01348   mePlot -> setBinLabel(5,"Invalid Stream",axisType);
01349   mePlot -> setBinLabel(6,"Latency Warn",axisType);
01350   mePlot -> setBinLabel(7,"OptDat Err",axisType);
01351   mePlot -> setBinLabel(8,"Clock Err",axisType);
01352   mePlot -> setBinLabel(9,"Bunch Err",axisType);
01353   mePlot -> setBinLabel(10,"b9",axisType);
01354   mePlot -> setBinLabel(11,"b10",axisType);
01355   mePlot -> setBinLabel(12,"b11",axisType);
01356   mePlot -> setBinLabel(13,"Test Mode",axisType);
01357   mePlot -> setBinLabel(14,"Histo Mode",axisType);
01358   mePlot -> setBinLabel(15,"Calib Trig",axisType);
01359   mePlot -> setBinLabel(16,"Bit15 Err",axisType);
01360 
01361   return;
01362 }
01363 
01364 void HcalRawDataMonitor::stashHDI(int thehash, HcalDetId thehcaldetid) {
01365   //Let's not allow indexing off the array...
01366   if ((thehash<0)||(thehash>(NUMDCCS*NUMSPIGS*HTRCHANMAX)))return;
01367   //...but still do the job requested.
01368   hashedHcalDetId_[thehash] = thehcaldetid;
01369 }
01370 
01371 //Debugging output for single half-HTRs (single spigot) 
01372 //-->Class member debug_ usually passed for prtlvl argument.<--
01373 void HcalRawDataMonitor::HTRPrint(const HcalHTRData& htr,int prtlvl){
01374   if (prtlvl == 1){ 
01375     int cratenum = htr.readoutVMECrateId();
01376     float slotnum = htr.htrSlot() + 0.5*htr.htrTopBottom();
01377     printf("Crate,Slot,ErrWord,Evt#,BCN:  %3i %4.1f %6X %7i %4X \n", cratenum,slotnum,htr.getErrorsWord(),htr.getL1ANumber(),htr.getBunchNumber());
01378     //    printf(" DLLunlk,TTCrdy:%2i %2i \n",htr.getDLLunlock(),htr.getTTCready());
01379   }
01380   // This one needs new version of HcalHTRData.h to activate
01381   else if (prtlvl == 2){
01382     int cratenum = htr.readoutVMECrateId();
01383     float slotnum = htr.htrSlot() + 0.5*htr.htrTopBottom();
01384     printf("Crate, Slot:%3i %4.1f \n", cratenum,slotnum);
01385     //    printf("  Ext Hdr: %4X %4X %4X %4X %4X %4X %4X %4X \n",htr.getExtHdr1(),htr.getExtHdr2(),htr.getExtHdr3(),htr.getExtHdr4(),htr.getExtHdr5(),htr.getExtHdr6(),htr.getExtHdr7(),htr.getExtHdr8());
01386   }
01387 
01388   else if (prtlvl == 3){
01389     int cratenum = htr.readoutVMECrateId();
01390     float slotnum = htr.htrSlot() + 0.5*htr.htrTopBottom();
01391     printf("Crate, Slot:%3i %4.1f", cratenum,slotnum);
01392     printf(" FibOrbMsgBCNs: %4X %4X %4X %4X %4X %4X %4X %4X \n",htr.getFib1OrbMsgBCN(),htr.getFib2OrbMsgBCN(),htr.getFib3OrbMsgBCN(),htr.getFib4OrbMsgBCN(),htr.getFib5OrbMsgBCN(),htr.getFib6OrbMsgBCN(),htr.getFib7OrbMsgBCN(),htr.getFib8OrbMsgBCN());
01393   }
01394 
01395   return;
01396 }
01397 
01398 
01399 void HcalRawDataMonitor::UpdateMEs (void ) {
01400   tevt_=0;
01401   if (meTevtHist_) tevt_= (int)meTevtHist_->getBinContent(1);
01402   NumBadHB=0;
01403   NumBadHE=0;
01404   NumBadHO=0;
01405   NumBadHF=0;
01406   NumBadHFLUMI=0;
01407   NumBadHO0=0;
01408   NumBadHO12=0;
01409 
01410 
01411   meLRBDataCorruptionIndicators_->setBinContent(0,0,tevt_);
01412   for (int x=0; x<THREE_FED; x++)
01413     for (int y=0; y<THREE_SPG; y++)
01414       if (LRBDataCorruptionIndicators_  [x][y]) 
01415         meLRBDataCorruptionIndicators_->setBinContent(x+1,y+1,LRBDataCorruptionIndicators_[x][y]);
01416         
01417   meHalfHTRDataCorruptionIndicators_->setBinContent(0,0,tevt_);
01418   for (int x=0; x<THREE_FED; x++)
01419     for (int y=0; y<THREE_SPG; y++)
01420       if (HalfHTRDataCorruptionIndicators_  [x][y])
01421         meHalfHTRDataCorruptionIndicators_->setBinContent(x+1,y+1,HalfHTRDataCorruptionIndicators_[x][y]);
01422 
01423   meChannSumm_DataIntegrityCheck_->setBinContent(0,0,tevt_);     
01424   for (int x=0; x<TWO___FED; x++)
01425     for (int y=0; y<TWO__SPGT; y++)
01426       if (ChannSumm_DataIntegrityCheck_[x][y]) 
01427         meChannSumm_DataIntegrityCheck_->setBinContent(x+1,y+1,ChannSumm_DataIntegrityCheck_[x][y]);
01428 
01429   for (int f=0; f<NUMDCCS; f++){
01430     meChann_DataIntegrityCheck_[f]->setBinContent(0,0,tevt_);
01431     for (int x=0; x<TWO_CHANN; x++)
01432       for (int y=0; y<TWO__SPGT; y++)      
01433         if (Chann_DataIntegrityCheck_[f][x][y])
01434           meChann_DataIntegrityCheck_[f]->setBinContent(x+1,y+1,Chann_DataIntegrityCheck_ [f][x][y]);
01435   }
01436   
01437   meDataFlowInd_->setBinContent(0,0,tevt_);
01438   for (int x=0; x<TWO___FED; x++)
01439     for (int y=0; y<THREE_SPG; y++)      
01440       if (DataFlowInd_[x][y])
01441         meDataFlowInd_->setBinContent(x+1,y+1,DataFlowInd_[x][y]);
01442 } //UpdateMEs
01443 
01444 //Increment the NumBad counter for this LS, for this Hcal subdet
01445 void HcalRawDataMonitor::whosebad(int subdet) {
01446 //  if (subdet==HcalBarrel)       ++NumBadHB;
01447 //  else if (subdet==HcalEndcap)  ++NumBadHE;
01448 //  else if (subdet==HcalOuter)  
01449 //    {
01450 //      ++NumBadHO;
01451 //      if (abs(ieta)<5) ++NumBadHO0;
01452 //      else ++NumBadHO12;
01453 //    }
01454 //  else if (subdet==HcalForward)
01455 //    {
01456 //      ++NumBadHF;
01457 //      if (depth==1 && (abs(ieta)==33 || abs(ieta)==34))
01458 //      ++NumBadHFLUMI;
01459 //      else if (depth==2 && (abs(ieta)==35 || abs(ieta)==36))
01460 //      ++NumBadHFLUMI;
01461 //    }
01462 }
01463 
01464 void HcalRawDataMonitor::mapDCCproblem(int dcc) {
01465   int myeta   = 0;
01466   int myphi   =-1;
01467   int mydepth = 0;
01468   HcalDetId HDI;
01469   //Light up all affected cells.
01470   for (int i=hashup(dcc); 
01471        i<hashup(dcc)+(NUMSPIGS*HTRCHANMAX); 
01472        i++) {
01473     HDI = hashedHcalDetId_[i];
01474     if (HDI==HcalDetId::Undefined) 
01475       continue;
01476     mydepth = HDI.depth();
01477     myphi   = HDI.iphi();
01478     myeta = CalcEtaBin(HDI.subdet(),
01479                        HDI.ieta(),
01480                        mydepth);
01481     //Protect against indexing off array
01482     if (myeta>=0 && myeta<85 &&
01483         (myphi-1)>=0 && (myphi-1)<72 &&
01484         (mydepth-1)>=0 && (mydepth-1)<4){
01485       problemfound[myeta][myphi-1][mydepth-1] = true;
01486 
01487       //exlcude the decommissioned HO ring2, except SiPMs 
01488       if(mydepth==4 && excludeHORing2_==true)
01489         if (abs(HDI.ieta())>=11 && abs(HDI.ieta())<=15  && !isSiPM(HDI.ieta(),HDI.iphi(),mydepth))
01490           problemfound[myeta][myphi-1][mydepth-1] = false;
01491       
01492       if (debug_>0)
01493         std::cout<<" mapDCCproblem found error! "<<HDI.subdet()<<"("<<HDI.ieta()<<", "<<HDI.iphi()<<", "<<HDI.depth()<<")"<<std::endl;
01494     }
01495   }
01496 }
01497 void HcalRawDataMonitor::mapHTRproblem(int dcc, int spigot) {
01498   int myeta = 0;
01499   int myphi   =-1;
01500   int mydepth = 0;
01501   HcalDetId HDI;
01502   //Light up all affected cells.
01503   for (int i=hashup(dcc,spigot); 
01504        i<hashup(dcc,spigot)+(HTRCHANMAX); //nice, linear hash....
01505        i++) {
01506     HDI = hashedHcalDetId_[i];
01507     if (HDI==HcalDetId::Undefined) {
01508       continue;
01509     }
01510     mydepth = HDI.depth();
01511     myphi   = HDI.iphi();
01512     myeta = CalcEtaBin(HDI.subdet(),
01513                        HDI.ieta(),
01514                        mydepth);
01515     //Protect against indexing off array
01516     if (myeta>=0 && myeta<85 &&
01517         (myphi-1)>=0 && (myphi-1)<72 &&
01518         (mydepth-1)>=0 && (mydepth-1)<4){
01519       problemfound[myeta][myphi-1][mydepth-1] = true;
01520       
01521       //exlcude the decommissioned HO ring2, except SiPMs 
01522       if(mydepth==4 && excludeHORing2_==true)
01523         if (abs(HDI.ieta())>=11 && abs(HDI.ieta())<=15  && !isSiPM(HDI.ieta(),HDI.iphi(),mydepth))
01524           problemfound[myeta][myphi-1][mydepth-1] = false;
01525       
01526       if (debug_>0)
01527         std::cout<<" mapDCCproblem found error! "<<HDI.subdet()<<"("<<HDI.ieta()<<", "<<HDI.iphi()<<", "<<HDI.depth()<<")"<<std::endl;
01528     }
01529 
01530   }
01531 }   // void HcalRawDataMonitor::mapHTRproblem(...)
01532 
01533 void HcalRawDataMonitor::mapChannproblem(int dcc, int spigot, int htrchan) {
01534   int myeta = 0;
01535   int myphi   =-1;
01536   int mydepth = 0;
01537   HcalDetId HDI;
01538   //Light up the affected cell.
01539   int i=hashup(dcc,spigot,htrchan); 
01540   HDI = HashToHDI(i);
01541   if (HDI==HcalDetId::Undefined) {
01542     return; // Do nothing at all, instead.
01543   } 
01544   mydepth = HDI.depth();
01545   myphi   = HDI.iphi();
01546   myeta = CalcEtaBin(HDI.subdet(),
01547                      HDI.ieta(),
01548                      mydepth);
01549   //Protect against indexing off array
01550   if (myeta>=0 && myeta<85 &&
01551       (myphi-1)>=0 && (myphi-1)<72 &&
01552       (mydepth-1)>=0 && (mydepth-1)<4){
01553     problemfound[myeta][myphi-1][mydepth-1] = true;
01554 
01555     //exlcude the decommissioned HO ring2, except SiPMs 
01556     if(mydepth==4 && excludeHORing2_==true)
01557       if (abs(HDI.ieta())>=11 && abs(HDI.ieta())<=15  && !isSiPM(HDI.ieta(),HDI.iphi(),mydepth))
01558           problemfound[myeta][myphi-1][mydepth-1] = false;
01559 
01560     if (debug_>0)
01561       std::cout<<" mapDCCproblem found error! "<<HDI.subdet()<<"("<<HDI.ieta()<<", "<<HDI.iphi()<<", "<<HDI.depth()<<")"<<std::endl;
01562   }
01563 }   // void HcalRawDataMonitor::mapChannproblem(...)
01564 
01565 
01566 DEFINE_FWK_MODULE(HcalRawDataMonitor);