00001 #include <DQM/CastorMonitor/interface/CastorMonitorModule.h>
00002 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/Framework/interface/Event.h"
00006
00007
00008
00009
00010
00011
00016
00017
00018
00019
00020 CastorMonitorModule::CastorMonitorModule(const edm::ParameterSet& ps){
00021
00022
00023
00024
00026 inputLabelRaw_ = ps.getParameter<edm::InputTag>("rawLabel");
00027 inputLabelDigi_ = ps.getParameter<edm::InputTag>("digiLabel");
00028 inputLabelRecHitCASTOR_ = ps.getParameter<edm::InputTag>("CastorRecHitLabel");
00029 fVerbosity = ps.getUntrackedParameter<int>("debug", 0);
00030 showTiming_ = ps.getUntrackedParameter<bool>("showTiming", false);
00031 dump2database_ = ps.getUntrackedParameter<bool>("dump2database",false);
00032 EDMonOn_= ps.getUntrackedParameter<bool>("EDMonitor", false);
00033
00034 if(fVerbosity>0) std::cout << "CastorMonitorModule Constructor (start)" << std::endl;
00035
00037 irun_=0;
00038 ilumisec_=0;
00039 ievent_=0;
00040 itime_=0;
00041 ibunch_=0;
00042 actonLS_=false;
00043
00044 meStatus_=0; meRunType_=0;
00045 meEvtMask_=0; meFEDS_=0;
00046
00047 meQuality_=0;
00048 fedsListed_ = false;
00049
00050 RecHitMon_ = NULL;
00051 DigiMon_ = NULL;
00052 LedMon_ = NULL;
00053 PSMon_ = NULL;
00054 CQMon_ = NULL;
00055 EDMon_ = NULL;
00056 HIMon_ = NULL;
00057
00059 dbe_ = edm::Service<DQMStore>().operator->();
00060
00062 evtSel_ = new CastorMonitorSelector(ps);
00063
00064
00065
00066 if ( ps.getUntrackedParameter<bool>("DigiMonitor", false) ) {
00067 if(fVerbosity>0) std::cout << "CastorMonitorModule: Digi monitor flag is on...." << std::endl;
00068 DigiMon_ = new CastorDigiMonitor();
00069 DigiMon_->setup(ps, dbe_);
00070 }
00071
00072
00074 if ( ps.getUntrackedParameter<bool>("RecHitMonitor", false) ) {
00075 if(fVerbosity>0) std::cout << "CastorMonitorModule: RecHit monitor flag is on...." << std::endl;
00076 RecHitMon_ = new CastorRecHitMonitor();
00077 RecHitMon_->setup(ps, dbe_);
00078 }
00079
00080
00081
00083 if ( ps.getUntrackedParameter<bool>("HIMonitor", false) ) {
00084 if(fVerbosity>0) std::cout << "CastorMonitorModule: HI monitor flag is on...." << std::endl;
00085 HIMon_ = new CastorHIMonitor();
00086 HIMon_->setup(ps, dbe_);
00087 }
00088
00089
00091 if ( ps.getUntrackedParameter<bool>("ChannelQualityMonitor", false) ) {
00092 if(fVerbosity>0) std::cout << "CastorChannelQualityMonitor: CQ monitor flag is on...." << std::endl;
00093 CQMon_ = new CastorChannelQualityMonitor();
00094 CQMon_->setup(ps, dbe_);
00095 }
00096
00097
00099
00100
00101
00102
00103
00104
00105
00106
00107 if ( ps.getUntrackedParameter<bool>("PSMonitor", false) ) {
00108 if(fVerbosity>0) std::cout << "CastorMonitorModule: PS monitor flag is on...." << std::endl;
00109 PSMon_ = new CastorPSMonitor();
00110 PSMon_->setup(ps, dbe_);
00111 }
00112
00113
00114
00115 if ( ps.getUntrackedParameter<bool>("EDMonitor", false) ) {
00116 if(fVerbosity>0) std::cout << "CastorMonitorModule: ED monitor flag is on...." << std::endl;
00117 EDMon_ = new CastorEventDisplay();
00118 EDMon_->setup(ps, dbe_);
00119 }
00120
00121
00122
00123
00124
00125
00127
00129 prescaleEvt_ = ps.getUntrackedParameter<int>("diagnosticPrescaleEvt", -1);
00130 if(fVerbosity>0) std::cout << "===>CastorMonitor event prescale = " << prescaleEvt_ << " event(s)"<< std::endl;
00131
00132 prescaleLS_ = ps.getUntrackedParameter<int>("diagnosticPrescaleLS", -1);
00133 if(fVerbosity>0) std::cout << "===>CastorMonitor lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< std::endl;
00134 if (prescaleLS_>0) actonLS_=true;
00135
00136 prescaleUpdate_ = ps.getUntrackedParameter<int>("diagnosticPrescaleUpdate", -1);
00137 if(fVerbosity>0) std::cout << "===>CastorMonitor update prescale = " << prescaleUpdate_ << " update(s)"<< std::endl;
00138
00139 prescaleTime_ = ps.getUntrackedParameter<int>("diagnosticPrescaleTime", -1);
00140 if(fVerbosity>1) std::cout << "===>CastorMonitor time prescale = " << prescaleTime_ << " minute(s)"<< std::endl;
00141
00143 std::string subsystemname = ps.getUntrackedParameter<std::string>("subSystemFolder", "Castor") ;
00144 if(fVerbosity>0) std::cout << "===>CastorMonitor name = " << subsystemname << std::endl;
00145 rootFolder_ = subsystemname + "/";
00146
00147 if ( dbe_ != NULL ){
00148 dbe_->setCurrentFolder(rootFolder_);
00149 }
00150
00151
00152 gettimeofday(&psTime_.updateTV,NULL);
00154 psTime_.updateTime = (psTime_.updateTV.tv_sec*1000.0+psTime_.updateTV.tv_usec/1000.0);
00155 psTime_.updateTime /= 1000.0;
00156 psTime_.elapsedTime=0;
00157 psTime_.vetoTime=psTime_.updateTime;
00158
00159 if(fVerbosity>0) std::cout << "CastorMonitorModule Constructor (end)" << std::endl;
00160
00161 }
00162
00163
00164
00165
00166
00167 CastorMonitorModule::~CastorMonitorModule(){
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 }
00186
00187
00188
00189
00190
00191 void CastorMonitorModule::beginJob(){
00192 ievt_ = 0;
00193 ievt_pre_=0;
00194
00195 if(fVerbosity>0) std::cout << "CastorMonitorModule::beginJob (start)" << std::endl;
00196
00197 if ( dbe_ != NULL ){
00198
00199
00201 dbe_->setCurrentFolder(rootFolder_+"CastorEventProducts");
00202 meEVT_ = dbe_->bookInt("Event Number");
00203 CastorEventProduct =dbe_->book2D("CastorEventProduct","CastorEventProduct",3,0,3,1,0,1);
00204 TH2F* hCastorEventProduct =CastorEventProduct->getTH2F();
00205 hCastorEventProduct->GetXaxis()->SetBinLabel(1,"RawData");
00206 hCastorEventProduct->GetXaxis()->SetBinLabel(2,"CastorDigi");
00207 hCastorEventProduct->GetXaxis()->SetBinLabel(3,"CastorRecHits");
00208 hCastorEventProduct->GetYaxis()->SetBinLabel(1,"Status");
00209 hCastorEventProduct->SetBinContent(1,1,-1);
00210 hCastorEventProduct->SetBinContent(2,1,-1);
00211 hCastorEventProduct->SetBinContent(3,1,-1);
00212 hCastorEventProduct->SetOption("textcolz");
00213
00214
00215 dbe_->setCurrentFolder(rootFolder_+"DQM Job Status" );
00216 meStatus_ = dbe_->bookInt("STATUS");
00217 meRunType_ = dbe_->bookInt("RUN TYPE");
00218 meEvtMask_ = dbe_->bookInt("EVT MASK");
00219 meFEDS_ = dbe_->book1D("FEDs Unpacked","FEDs Unpacked",100,660,759);
00220 meCASTOR_ = dbe_->bookInt("CASTORpresent");
00222
00223 meQuality_ = dbe_->book1D("Quality Status","Quality Status",100,0,1);
00224 meStatus_->Fill(0);
00225 meRunType_->Fill(-1);
00226 meEvtMask_->Fill(-1);
00228 meCASTOR_->Fill(0);
00229 }
00230 else{
00231 if(fVerbosity>0) std::cout << "CastorMonitorModule::beginJob - NO DQMStore service" << std::endl;
00232 }
00233
00234 if(fVerbosity>0) std::cout << "CastorMonitorModule::beginJob (end)" << std::endl;
00235
00236 return;
00237 }
00238
00239
00240
00241
00242
00243 void CastorMonitorModule::beginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
00244
00245 fedsListed_ = false;
00246 reset();
00247
00249 iSetup.get<CastorDbRecord>().get(conditions_);
00250
00252 iSetup.get<CastorPedestalsRcd>().get(dbPedestals);
00253 if(!dbPedestals.isValid() && fVerbosity>0) std::cout << "CASTOR has no CastorPedestals in the CondDB !!!" << std::endl;
00254
00256 float sigma_averaged;
00257 unsigned int iChannel = 0;
00258 std::vector<DetId> channels = dbPedestals->getAllChannels();
00259
00261 for (std::vector<DetId>::iterator ch=channels.begin(); ch!=channels.end(); ch++) {
00262 const CastorPedestal * pedestals_mean = dbPedestals->getValues(*ch);
00263 sigma_averaged = 0.;
00264
00266 for (short unsigned int iCapId = 0; iCapId < 4; iCapId++){
00267 sigma_averaged += sqrt(pedestals_mean->getWidth(iCapId));
00268 };
00269
00271 fPedestalNSigmaAverage[HcalCastorDetId(*ch).module()-1][HcalCastorDetId(*ch).sector()-1] = sigma_averaged/4;
00272 iChannel++;
00273 };
00274
00275 if(iChannel<224 && fVerbosity>0) std::cout << "There are less that 224 channels in CastorPedestalsRcd record !!!" << std::endl;
00276
00277 return;
00278 }
00279
00280
00281
00282
00283 void CastorMonitorModule::beginLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00284 const edm::EventSetup& context) {
00285
00286 if(actonLS_ && !prescale()){
00288 }
00289 }
00290
00291
00292
00293
00294
00295 void CastorMonitorModule::endLuminosityBlock(const edm::LuminosityBlock& lumiSeg,
00296 const edm::EventSetup& context) {
00297 if(actonLS_ && !prescale()){
00299 }
00300 }
00301
00302
00303
00304
00305 void CastorMonitorModule::endRun(const edm::Run& r, const edm::EventSetup& context)
00306 {
00307 if (fVerbosity>0) std::cout <<"CastorMonitorModule::endRun(...) "<<std::endl;
00309 if (DigiMon_!=NULL)
00310 return;
00311 }
00312
00313
00314
00315
00316 void CastorMonitorModule::endJob(void) {
00317
00318
00319
00320 if(RecHitMon_!=NULL) RecHitMon_->done();
00321 if(DigiMon_!=NULL) DigiMon_->done();
00322 if(LedMon_!=NULL) LedMon_->done();
00323 if(CQMon_!=NULL) CQMon_->done();
00324 if(PSMon_!=NULL) PSMon_->done();
00325 if(EDMon_!=NULL) EDMon_->done();
00326 if(HIMon_!=NULL) RecHitMon_->done();
00327
00328
00329
00330
00331
00332
00333
00334 return;
00335 }
00336
00337
00338
00339
00340
00341 void CastorMonitorModule::reset(){
00342
00343 if(DigiMon_!=NULL) DigiMon_->reset();
00344 if(RecHitMon_!=NULL) RecHitMon_->reset();
00345 if(LedMon_!=NULL) LedMon_->reset();
00346 if(CQMon_!=NULL) CQMon_->reset();
00347 if(PSMon_!=NULL) PSMon_->reset();
00348 if(EDMon_!=NULL) EDMon_->reset();
00349 if(HIMon_!=NULL) HIMon_->reset();
00350
00351 }
00352
00353
00354
00355
00356
00357 void CastorMonitorModule::analyze(const edm::Event& iEvent, const edm::EventSetup& eventSetup){
00358
00359 using namespace edm;
00360
00361
00363 irun_ = iEvent.id().run();
00364 ilumisec_ = iEvent.luminosityBlock();
00365 ievent_ = iEvent.id().event();
00366 itime_ = iEvent.time().value();
00367 ibunch_ = iEvent.bunchCrossing();
00368
00369
00370 if (fVerbosity>0) {
00371 std::cout << "==> CastorMonitorModule: evts: "<< nevt_ << ", run: " << irun_ << ", LS: " << ilumisec_ << std::endl;
00372 std::cout << " evt: " << ievent_ << ", time: " << itime_ <<"\t counter = "<< ievt_pre_<< "\t total count = "<<ievt_<<std::endl;
00373 }
00374
00376 ievt_++;
00377
00379 ievt_pre_++;
00380 if(prescale()) return;
00381
00382
00383
00384
00385
00386 int evtMask=DO_CASTOR_RECHITMON|DO_CASTOR_PED_CALIBMON;
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 if ( dbe_ ){
00397 meStatus_->Fill(1);
00398 meEvtMask_->Fill(evtMask);
00399 }
00400
00402 bool rawOK_ = true;
00403 bool digiOK_ = true;
00404 bool rechitOK_ = true;
00405
00406
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 edm::Handle<CastorDigiCollection> CastorDigi;
00436 iEvent.getByLabel(inputLabelDigi_,CastorDigi);
00437 if (!CastorDigi.isValid()) {
00438 digiOK_=false;
00439 }
00440
00441
00442
00445
00446
00447
00448
00449
00450
00451
00452 edm::Handle<CastorRecHitCollection> CastorHits;
00453 iEvent.getByLabel(inputLabelRecHitCASTOR_,CastorHits);
00454 if (!CastorHits.isValid()) {
00455 rechitOK_ = false;
00456 }
00457
00458
00460 if(ievt_%10 == 0) {
00461
00462 TH2F* hCastorEventProduct=CastorEventProduct->getTH2F();
00463 hCastorEventProduct->SetBinContent(1,1,int(rawOK_));
00464 hCastorEventProduct->SetBinContent(2,1,int(digiOK_));
00465 hCastorEventProduct->SetBinContent(3,1,int(rechitOK_));
00466
00467 if(fVerbosity>0) {
00468 std::cout << " RAW Data ==> " << rawOK_<< std::endl;
00469 std::cout << " Digis ==> " << digiOK_<< std::endl;
00470 std::cout << " RecHits ==> " << rechitOK_<< std::endl;
00471 }
00472
00473 }
00474
00475
00476
00477
00478
00479
00480 if (showTiming_){
00481 cpu_timer.reset(); cpu_timer.start();
00482 }
00483
00484
00485
00486 if(digiOK_) DigiMon_->processEvent(*CastorDigi,*conditions_);
00487 if (showTiming_){
00488 cpu_timer.stop();
00489 if (DigiMon_!=NULL) std::cout <<"TIMER:: DIGI MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
00490 cpu_timer.reset(); cpu_timer.start();
00491 }
00492
00493
00494
00495
00496 if(rechitOK_) RecHitMon_->processEvent(*CastorHits);
00497 if (showTiming_){
00498 cpu_timer.stop();
00499 if (RecHitMon_!=NULL) std::cout <<"TIMER:: RECHIT MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
00500 cpu_timer.reset(); cpu_timer.start();
00501 }
00502
00503
00504 if(rechitOK_) CQMon_->processEvent(*CastorHits);
00505 if (showTiming_){
00506 cpu_timer.stop();
00507 if (CQMon_!=NULL) std::cout <<"TIMER:: CHANNELQUALITY MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
00508 cpu_timer.reset(); cpu_timer.start();
00509 }
00510
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00524
00525 edm::ESHandle<CastorElectronicsMap> refEMap;
00526 eventSetup.get<CastorElectronicsMapRcd>().get(refEMap);
00527 const CastorElectronicsMap* myRefEMap = refEMap.product();
00528 listEMap = myRefEMap->allPrecisionId();
00529 if(digiOK_) PSMon_->processEvent(*CastorDigi,*conditions_, listEMap, ibunch_, fPedestalNSigmaAverage);
00530 if (showTiming_) {
00531 cpu_timer.stop();
00532 if (PSMon_!=NULL) std::cout <<"TIMER:: PULSE SHAPE ->"<<cpu_timer.cpuTime()<<std::endl;
00533 cpu_timer.reset(); cpu_timer.start();
00534 }
00535
00536
00537
00539 edm::ESHandle<CaloGeometry> caloGeometry;
00540 eventSetup.get<CaloGeometryRecord>().get(caloGeometry);
00541
00542 if(rechitOK_ && EDMonOn_) EDMon_->processEvent(*CastorHits, *caloGeometry);
00543 if (showTiming_){
00544 cpu_timer.stop();
00545 if (EDMon_!=NULL) std::cout <<"TIMER:: EVENTDISPLAY MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
00546 cpu_timer.reset(); cpu_timer.start();
00547 }
00548
00549
00550 if(rechitOK_ && digiOK_ ) HIMon_->processEvent(*CastorHits, *CastorDigi, *conditions_);
00551 if (showTiming_){
00552 cpu_timer.stop();
00553 if (HIMon_!=NULL) std::cout <<"TIMER:: HI MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
00554 cpu_timer.reset(); cpu_timer.start();
00555 }
00556
00557
00558 if(fVerbosity>0 && ievt_%100 == 0)
00559 std::cout << "CastorMonitorModule: processed " << ievt_ << " events" << std::endl;
00560
00561
00563 meEVT_->Fill(ievt_);
00564
00565
00566
00567 return;
00568 }
00569
00570
00571
00572
00573
00574
00575
00578 bool CastorMonitorModule::prescale()
00579 {
00580 if (fVerbosity>0) std::cout <<"CastorMonitorModule::prescale"<<std::endl;
00581
00582 gettimeofday(&psTime_.updateTV,NULL);
00583 double time = (psTime_.updateTV.tv_sec*1000.0+psTime_.updateTV.tv_usec/1000.0);
00584 time/= (1000.0);
00585 psTime_.elapsedTime = time - psTime_.updateTime;
00586 psTime_.updateTime = time;
00588 bool evtPS = prescaleEvt_>0;
00589 bool lsPS = prescaleLS_>0;
00590 bool timePS = prescaleTime_>0;
00591 bool updatePS = prescaleUpdate_>0;
00592
00594 if(!evtPS && !lsPS && !timePS && !updatePS)
00595 {
00596 return false;
00597 }
00599 if(lsPS && (ilumisec_%prescaleLS_)!=0) lsPS = false;
00600
00601 if (evtPS && (ievt_pre_%prescaleEvt_)!=0) evtPS = false;
00602 if(timePS)
00603 {
00604 double elapsed = (psTime_.updateTime - psTime_.vetoTime)/60.0;
00605 if(elapsed<prescaleTime_){
00606 timePS = false;
00607 psTime_.vetoTime = psTime_.updateTime;
00608 }
00609 }
00610
00611
00612
00613 if (fVerbosity>0)
00614 {
00615 std::cout<<"CastorMonitorModule::prescale evt: "<<ievent_<<"/"<<evtPS<<", ";
00616 std::cout <<"ls: "<<ilumisec_<<"/"<<lsPS<<",";
00617 std::cout <<"time: "<<psTime_.updateTime - psTime_.vetoTime<<"/"<<timePS<<std::endl;
00618 }
00620 if(evtPS || lsPS || timePS) return false;
00621 return true;
00622 }
00623
00624
00625
00626
00627
00628
00631
00632 void CastorMonitorModule::CheckCastorStatus(const FEDRawDataCollection& RawData,
00633 const HcalUnpackerReport& report,
00634 const CastorElectronicsMap& emap,
00635 const CastorDigiCollection& CastorDigi
00636 )
00637 {
00638
00640
00642
00643
00644
00645
00646
00647
00648
00649
00651
00652
00653
00654
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665 return;
00666 }
00667
00668 #include "FWCore/Framework/interface/MakerMacros.h"
00669 #include <DQM/CastorMonitor/interface/CastorMonitorModule.h>
00670 #include "DQMServices/Core/interface/DQMStore.h"
00671
00672 DEFINE_FWK_MODULE(CastorMonitorModule);