CMS 3D CMS Logo

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