CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DQM/HcalMonitorTasks/src/HcalRawDataMonitor.cc

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