Go to the documentation of this file.00001 #include "DQM/HcalMonitorModule/interface/ZDCMonitorModule.h"
00002 #include "DQM/HcalMonitorTasks/interface/HcalZDCMonitor.h"
00003
00004 #include "DQMServices/Core/interface/DQMStore.h"
00005 #include "DQMServices/Core/interface/MonitorElement.h"
00006
00007 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00008 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00009 #include "FWCore/Framework/interface/LuminosityBlock.h"
00010 #include "FWCore/Utilities/interface/CPUTimer.h"
00011
00012 #include "DataFormats/Provenance/interface/EventID.h"
00013 #include "DataFormats/HcalDigi/interface/HcalUnpackerReport.h"
00014 #include "DataFormats/HcalDigi/interface/HcalCalibrationEventTypes.h"
00015 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
00016 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
00017 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetupFwd.h"
00018 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00019 #include "DataFormats/DetId/interface/DetId.h"
00020 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00021 #include "DQM/HcalMonitorTasks/interface/HcalZDCMonitor.h"
00022
00023 #include "CondFormats/HcalObjects/interface/HcalChannelStatus.h"
00024 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00025 #include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
00026
00027 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00028
00029 #include <memory>
00030 #include <iostream>
00031 #include <fstream>
00032 #include <vector>
00033 #include <string>
00034 #include <sys/time.h>
00035
00036
00037 ZDCMonitorModule::ZDCMonitorModule(const edm::ParameterSet& ps){
00038
00039 irun_=0; ilumisec=0; ievent_=0; itime_=0;
00040
00041 meStatus_=0;
00042 meFEDS_=0;
00043 meLatency_=0; meQuality_=0;
00044 fedsListed_ = false;
00045 zdcMon_ = 0;
00046
00047
00048 ZDCpresent_=0;
00049
00050 inputLabelDigi_ = ps.getParameter<edm::InputTag>("digiLabel");
00051 inputLabelRecHitZDC_ = ps.getParameter<edm::InputTag>("zdcRecHitLabel");
00052 showTiming_ = ps.getUntrackedParameter<bool>("showTiming", false);
00053 dump2database_ = ps.getUntrackedParameter<bool>("dump2database",false);
00054
00055 Online_ = ps.getUntrackedParameter<bool>("Online",false);
00056 checkZDC_=ps.getUntrackedParameter<bool>("checkZDC", true);
00057 dbe_ = edm::Service<DQMStore>().operator->();
00058 debug_ = ps.getUntrackedParameter<int>("debug", 0);
00059
00060
00061 if (checkZDC_)
00062 {
00063 zdcMon_ = new HcalZDCMonitor();
00064 zdcMon_->setup(ps, dbe_);
00065 }
00066
00067
00068 prescaleEvt_ = ps.getUntrackedParameter<int>("diagnosticPrescaleEvt", -1);
00069 if(debug_>1) std::cout << "===>ZDCMonitor event prescale = " << prescaleEvt_ << " event(s)"<< std::endl;
00070
00071 prescaleLS_ = ps.getUntrackedParameter<int>("diagnosticPrescaleLS", -1);
00072 if(debug_>1) std::cout << "===>ZDCMonitor lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< std::endl;
00073
00074
00075 std::string subsystemname = ps.getUntrackedParameter<std::string>("subSystemFolder", "ZDC") ;
00076 if(debug_>0) std::cout << "===>ZDCMonitor name = " << subsystemname << std::endl;
00077 rootFolder_ = subsystemname + "/";
00078
00079 gettimeofday(&psTime_.updateTV,NULL);
00081 psTime_.updateTime = (psTime_.updateTV.tv_sec*1000.0+psTime_.updateTV.tv_usec/1000.0);
00082 psTime_.updateTime /= 1000.0;
00083 psTime_.elapsedTime=0;
00084 psTime_.vetoTime=psTime_.updateTime;
00085 }
00086
00087
00088 ZDCMonitorModule::~ZDCMonitorModule()
00089 {
00090 if (!checkZDC_) return;
00091 if (dbe_!=0)
00092 {
00093 if (zdcMon_!=0) zdcMon_->clearME();
00094 dbe_->setCurrentFolder(rootFolder_);
00095 dbe_->removeContents();
00096 }
00097
00098 if (zdcMon_!=0)
00099 {
00100 delete zdcMon_; zdcMon_=0;
00101 }
00102 }
00103
00104
00105
00106 void ZDCMonitorModule::beginJob()
00107 {
00108 if (!checkZDC_) return;
00109
00110 ievt_ = 0;
00111 ievt_pre_=0;
00112
00113
00114 ievt_rawdata_=0;
00115 ievt_digi_=0;
00116 ievt_rechit_=0;
00117 return;
00118 }
00119
00120
00121 void ZDCMonitorModule::beginRun(const edm::Run& run, const edm::EventSetup& c)
00122 {
00123 if (!checkZDC_) return;
00124 fedsListed_ = false;
00125 ZDCpresent_ = 0;
00126
00127 reset();
00128
00129 if ( dbe_ != NULL ){
00130 dbe_->setCurrentFolder(rootFolder_+"DQM Job Status" );
00131
00132 meIEVTALL_ = dbe_->bookInt("Events Processed");
00133 meIEVTRAW_ = dbe_->bookInt("Events with Raw Data");
00134 meIEVTDIGI_= dbe_->bookInt("Events with Digis");
00135 meIEVTRECHIT_ = dbe_->bookInt("Events with RecHits");
00136 meIEVTALL_->Fill(ievt_);
00137 meIEVTRAW_->Fill(ievt_rawdata_);
00138 meIEVTDIGI_->Fill(ievt_digi_);
00139 meIEVTRECHIT_->Fill(ievt_rechit_);
00140 meStatus_ = dbe_->bookInt("STATUS");
00141
00142 meFEDS_ = dbe_->book1D("FEDs Unpacked","FEDs Unpacked",1+(FEDNumbering::MAXHCALFEDID-FEDNumbering::MINHCALFEDID),FEDNumbering::MINHCALFEDID-0.5,FEDNumbering::MAXHCALFEDID+0.5);
00143
00144 meLatency_ = dbe_->book1D("Process Latency","Process Latency",200,0,10);
00145 meQuality_ = dbe_->book1D("Quality Status","Quality Status",100,0,1);
00146
00147 meZDC_ = dbe_->bookInt("ZDCpresent");
00148
00149 meStatus_->Fill(0);
00150
00151 meZDC_->Fill(ZDCpresent_);
00152
00153 }
00154
00155 if (zdcMon_) zdcMon_->beginRun();
00156
00157 edm::ESHandle<HcalDbService> pSetup;
00158 c.get<HcalDbRecord>().get( pSetup );
00159
00160
00161
00162
00163
00164 c.get<HcalDbRecord>().get(conditions_);
00165
00166
00167
00168
00169
00170
00171
00172 return;
00173 }
00174
00175
00176 void ZDCMonitorModule::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00177 const edm::EventSetup& context)
00178 {
00179
00180
00181
00182
00183
00184 if (!checkZDC_) return;
00185 if (Online_ && lumiSeg.luminosityBlock()<ilumisec)
00186 return;
00187
00188
00189 ilumisec = lumiSeg.luminosityBlock();
00190 if (zdcMon_!=0) { zdcMon_->beginLuminosityBlock(ilumisec);}
00191 }
00192
00193
00194
00195 void ZDCMonitorModule::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00196 const edm::EventSetup& context)
00197 {
00198 if (!checkZDC_) return;
00199
00200 if (Online_ && lumiSeg.luminosityBlock()<ilumisec)
00201 return;
00202
00203
00204 if (zdcMon_!=0) { zdcMon_->endLuminosityBlock();}
00205
00206 if (prescaleLS_>-1 && !prescale())
00207 {
00208 }
00209 return;
00210 }
00211
00212
00213 void ZDCMonitorModule::endRun(const edm::Run& r, const edm::EventSetup& context)
00214 {
00215 if (!checkZDC_) return;
00216 if (debug_>0)
00217 std::cout <<"ZDCMonitorModule::endRun(...) ievt = "<<ievt_<<std::endl;
00218
00219
00220
00221 if (zdcMon_!=0) { zdcMon_->endLuminosityBlock();}
00222
00223 return;
00224 }
00225
00226
00227
00228 void ZDCMonitorModule::endJob(void)
00229 {
00230 if (!checkZDC_) return;
00231 if ( dbe_ != NULL ){
00232 meStatus_ = dbe_->get(rootFolder_+"DQM Job Status/STATUS");
00233 }
00234
00235 if ( meStatus_ ) meStatus_->Fill(2);
00236
00237 return;
00238
00239 if (zdcMon_!=NULL) zdcMon_->done();
00240
00241 return;
00242 }
00243
00244
00245 void ZDCMonitorModule::reset(){
00246 if (!checkZDC_) return;
00247 if (zdcMon_!=NULL) zdcMon_->reset();
00248
00249 }
00250
00251
00252 void ZDCMonitorModule::analyze(const edm::Event& e, const edm::EventSetup& eventSetup)
00253 {
00254 if (!checkZDC_) return;
00255
00256 irun_ = e.id().run();
00257 ievent_ = e.id().event();
00258 itime_ = e.time().value();
00259
00260 if (Online_ && e.luminosityBlock()<ilumisec)
00261 return;
00262
00263 if (debug_>1) std::cout << "ZDCMonitorModule: evts: "<< nevt_ << ", run: " << irun_ << ", LS: " << e.luminosityBlock() << ", evt: " << ievent_ << ", time: " << itime_ << std::endl <<"\t counter = "<<ievt_pre_<<"\t total count = "<<ievt_<<std::endl;
00264
00265 if ( meStatus_ ) meStatus_->Fill(1);
00266 meLatency_->Fill(psTime_.elapsedTime);
00267
00268
00270 bool rawOK_ = true;
00271 bool digiOK_ = true;
00272 bool zdchitOK_ = true;
00273
00274 edm::Handle<HcalUnpackerReport> report;
00275 e.getByLabel(inputLabelDigi_,report);
00276 if (!report.isValid())
00277 {
00278 rawOK_=false;
00279 edm::LogWarning("ZDCMonitorModule")<<" Unpacker Report Digi Collection "<<inputLabelDigi_<<" not available";
00280 }
00281 if (rawOK_)
00282 {
00283 if(!fedsListed_){
00284 const std::vector<int> feds = (*report).getFedsUnpacked();
00285 for(unsigned int f=0; f<feds.size(); f++){
00286 meFEDS_->Fill(feds[f]);
00287 }
00288 fedsListed_ = true;
00289 fedss = feds;
00290 }
00291 }
00292 if (rawOK_==true) ++ievt_rawdata_;
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 ++ievt_;
00333 if(prescaleEvt_>0 && prescale()) return;
00334
00336
00337 edm::Handle<ZDCDigiCollection> zdc_digi;
00338 e.getByLabel(inputLabelDigi_,zdc_digi);
00339 if (!zdc_digi.isValid())
00340 {
00341 digiOK_=false;
00342 if (debug_>1) std::cout <<"<ZDCMonitorModule> COULDN'T GET ZDC DIGI"<<std::endl;
00343
00344 }
00345 if (digiOK_) ++ievt_digi_;
00346
00348
00349
00350 edm::Handle<ZDCRecHitCollection> zdc_hits;
00351 e.getByLabel(inputLabelRecHitZDC_,zdc_hits);
00352 if (!zdc_hits.isValid())
00353 {
00354 zdchitOK_=false;
00355
00356 if (debug_>0)
00357 edm::LogWarning("ZDCMonitorModule")<< inputLabelRecHitZDC_<<" not available";
00358 }
00359 if (zdchitOK_) ++ievt_rechit_;
00360
00361
00363
00364
00365 meIEVTALL_->Fill(ievt_);
00366 meIEVTRAW_->Fill(ievt_rawdata_);
00367 meIEVTDIGI_->Fill(ievt_digi_);
00368 meIEVTRECHIT_->Fill(ievt_rechit_);
00369
00370 if (ZDCpresent_==0 && (digiOK_ || zdchitOK_))
00371 {
00372 ZDCpresent_=1;
00373 meZDC_->Fill(ZDCpresent_);
00374 }
00375
00376
00377 if (showTiming_)
00378 {
00379 cpu_timer.reset(); cpu_timer.start();
00380 }
00381
00382 if (zdcMon_!=NULL && zdchitOK_ && digiOK_)
00383 zdcMon_->processEvent(*zdc_digi,*zdc_hits);
00384
00385 if (showTiming_)
00386 {
00387 cpu_timer.stop();
00388 if (zdcMon_ !=NULL) std::cout <<"TIMER:: ZDC MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
00389 cpu_timer.reset(); cpu_timer.start();
00390 }
00391
00392
00393
00394 if(debug_>0 && ievt_%1000 == 0)
00395 std::cout << "ZDCMonitorModule: processed " << ievt_ << " events" << std::endl;
00396
00397 if(debug_>1)
00398 {
00399 std::cout << "ZDCMonitorModule: processed " << ievt_ << " events" << std::endl;
00400 std::cout << " ZDC RAW Data ==> " << rawOK_<< std::endl;
00401 std::cout << " ZDC Digis ==> " << digiOK_<< std::endl;
00402 std::cout << " ZDC RecHits ==> " << zdchitOK_<< std::endl;
00403 }
00404
00405 return;
00406 }
00407
00408
00409 bool ZDCMonitorModule::prescale()
00410 {
00411 if (!checkZDC_) return true;
00412
00415 if (debug_>1) std::cout <<"ZDCMonitorModule::prescale: ievt = "<<ievt_<<std::endl;
00416
00417 if(prescaleEvt_<=0 && prescaleLS_<=0) return false;
00418
00419
00420 bool keepEvent=false;
00421
00422
00423 if(prescaleLS_>0 && (ilumisec%prescaleLS_)==0) keepEvent = true;
00424 if (prescaleEvt_>0 && (ievt_%prescaleEvt_)==0) keepEvent = true;
00425
00426
00427 if (keepEvent) return false;
00428 return true;
00429
00430 }
00431
00432
00433
00434
00435 DEFINE_FWK_MODULE(ZDCMonitorModule);