CMS 3D CMS Logo

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