CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/DQM/HcalMonitorClient/src/ZDCMonitorClient.cc

Go to the documentation of this file.
00001 #include <DQM/HcalMonitorClient/interface/ZDCMonitorClient.h>
00002 #include "FWCore/ServiceRegistry/interface/Service.h"
00003 #include "FWCore/Framework/interface/MakerMacros.h"
00004 #include "DQMServices/Core/interface/MonitorElement.h"
00005 #include "DataFormats/DetId/interface/DetId.h"
00006 
00007 #include "TROOT.h"
00008 #include "TTree.h"
00009 #include "TGaxis.h"
00010 #include "TH1F.h"
00011 #include "TH2F.h"
00012 #include "TFile.h"
00013 
00014 #include <memory>
00015 #include <iostream>
00016 #include <fstream>
00017 #include <vector>
00018 #include <string>
00019 #include <sys/time.h>
00020 
00021 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00022 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00023 
00024 #include <DQM/HcalMonitorClient/interface/HcalDQMDbInterface.h>
00025 // Use to hold/get channel status
00026 #include "CondFormats/HcalObjects/interface/HcalChannelQuality.h"
00027 #include "CondFormats/HcalObjects/interface/HcalCondObjectContainer.h"
00028 #include "CalibCalorimetry/HcalAlgos/interface/HcalDbASCIIIO.h"
00029 #include "CondFormats/HcalObjects/interface/HcalChannelStatus.h"
00030 
00031 #include <DQM/HcalMonitorClient/interface/HcalClientUtils.h>
00032 #include "DQM/HcalMonitorClient/interface/HcalHistoUtils.h"
00033 #include "DQM/HcalMonitorTasks/interface/HcalEtaPhiHists.h"
00034 
00035 
00036 //--------------------------------------------------------
00037 ZDCMonitorClient::ZDCMonitorClient(const edm::ParameterSet& ps){
00038   initialize(ps);
00039 }
00040 
00041 ZDCMonitorClient::ZDCMonitorClient(){}
00042 
00043 //--------------------------------------------------------
00044 ZDCMonitorClient::~ZDCMonitorClient(){
00045 
00046   if (debug_>0) std::cout << "ZDCMonitorClient: Exit ..." << std::endl;
00047 }
00048 
00049 //--------------------------------------------------------
00050 void ZDCMonitorClient::initialize(const edm::ParameterSet& ps){
00051 
00052   irun_=0; ilumisec_=0; ievent_=0; itime_=0;
00053 
00054   maxlumisec_=0; minlumisec_=0;
00055 
00056 
00057   debug_ = ps.getUntrackedParameter<int>("debug", 0);
00058   if (debug_>0)
00059     std::cout << std::endl<<" *** ZDC Monitor Client ***" << std::endl<<std::endl;
00060 
00061   if(debug_>1) std::cout << "ZDCMonitorClient: constructor...." << std::endl;
00062 
00063   Online_ = ps.getUntrackedParameter<bool>("Online",false);
00064   // timing switch 
00065   showTiming_ = ps.getUntrackedParameter<bool>("showTiming",false);  
00066 
00067   // MonitorDaemon switch
00068   enableMonitorDaemon_ = ps.getUntrackedParameter<bool>("enableMonitorDaemon", true);
00069   if (debug_>0)
00070     {
00071       if ( enableMonitorDaemon_ ) std::cout << "-->enableMonitorDaemon switch is ON" << std::endl;
00072       else std::cout << "-->enableMonitorDaemon switch is OFF" << std::endl;
00073     }
00074 
00075   // get hold of back-end interface
00076   dbe_ = edm::Service<DQMStore>().operator->();
00077   if (debug_>1) dbe_->showDirStructure();   
00078 
00079   // DQM ROOT input
00080   inputFile_ = ps.getUntrackedParameter<std::string>("inputFile", "");
00081   if(inputFile_.size()!=0 && debug_>0) std::cout << "-->reading DQM input from " << inputFile_ << std::endl;
00082   
00083   if( ! enableMonitorDaemon_ ) {  
00084     if( inputFile_.size() != 0 && dbe_!=NULL){
00085       dbe_->open(inputFile_);
00086       dbe_->showDirStructure();     
00087     }
00088   }
00089 
00090   //histogram reset freqency, update frequency, timeout
00091   resetEvents_ = ps.getUntrackedParameter<int>("resetFreqEvents",-1);   //number of real events
00092   if(resetEvents_!=-1 && debug_>0) std::cout << "-->Will reset histograms every " << resetEvents_ <<" events." << std::endl;
00093   resetLS_ = ps.getUntrackedParameter<int>("resetFreqLS",-1);       //number of lumisections
00094   if(resetLS_!=-1 && debug_>0) std::cout << "-->Will reset histograms every " << resetLS_ <<" lumi sections." << std::endl;
00095 
00096   // base Html output directory
00097   baseHtmlDir_ = ps.getUntrackedParameter<std::string>("baseHtmlDir", "");
00098   if (debug_>0)
00099     {
00100       if( baseHtmlDir_.size() != 0) 
00101         std::cout << "-->HTML output will go to baseHtmlDir = '" << baseHtmlDir_ << "'" << std::endl;
00102       else std::cout << "-->HTML output is disabled" << std::endl;
00103     }
00104   
00105   runningStandalone_ = ps.getUntrackedParameter<bool>("runningStandalone", false); // unnecessary? Or use for offline client processing?
00106   if (debug_>1)
00107     {
00108       if( runningStandalone_ ) std::cout << "-->standAlone switch is ON" << std::endl;
00109       else std::cout << "-->standAlone switch is OFF" << std::endl;
00110     }
00111 
00112   // set parameters   
00113   prescaleEvt_ = ps.getUntrackedParameter<int>("diagnosticPrescaleEvt", -1);
00114   if (debug_>0) 
00115     std::cout << "===>DQM event prescale = " << prescaleEvt_ << " event(s)"<< std::endl;
00116 
00117   prescaleLS_ = ps.getUntrackedParameter<int>("diagnosticPrescaleLS", -1);
00118   if (debug_>0) std::cout << "===>DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< std::endl;
00119 
00120   // Base folder for the contents of this job
00121   std::string subsystemname = ps.getUntrackedParameter<std::string>("subSystemFolder", "ZDC") ;
00122   if (debug_>0) std::cout << "===>ZDCMonitor name = " << subsystemname << std::endl;
00123   rootFolder_ = subsystemname + "/";
00124 
00125   return;
00126 }
00127 
00128 //--------------------------------------------------------
00129 // remove all MonitorElements and directories
00130 void ZDCMonitorClient::removeAllME(){
00131   if (debug_>0) std::cout <<"<ZDCMonitorClient>removeAllME()"<<std::endl;
00132   if(dbe_==NULL) return;
00133 
00134   // go to top directory
00135   dbe_->cd();
00136   // remove MEs at top directory
00137   dbe_->removeContents(); 
00138   // remove directory (including subdirectories recursively)
00139   if(dbe_->dirExists("Collector"))
00140     dbe_->rmdir("Collector");
00141   if(dbe_->dirExists("Summary"))
00142     dbe_->rmdir("Summary");
00143   return;
00144 }
00145 
00146 //--------------------------------------------------------
00148 void ZDCMonitorClient::resetAllME() {
00149   if (debug_>0) std::cout <<"<ZDCMonitorClient> resetAllME()"<<std::endl;
00150    return;
00151 }
00152 
00153 //--------------------------------------------------------
00154 void ZDCMonitorClient::beginJob(){
00155 
00156   if( debug_>0 ) std::cout << "ZDCMonitorClient: beginJob" << std::endl;
00157   
00158   ievt_ = 0;
00159  
00160   return;
00161 }
00162 
00163 //--------------------------------------------------------
00164 void ZDCMonitorClient::beginRun(const edm::Run& r, const edm::EventSetup& c) {
00165 
00166   if (debug_>0)
00167     std::cout << std::endl<<"ZDCMonitorClient: Standard beginRun() for run " << r.id().run() << std::endl<<std::endl;
00168  
00169   // Get current channel quality 
00170   /*
00171  edm::ESHandle<HcalChannelQuality> p;
00172   c.get<HcalChannelQualityRcd>().get(p);
00173   chanquality_= new HcalChannelQuality(*p.product());
00174   */
00175 
00176   std::string eventinfo="EventInfo";
00177   if (rootFolder_!="ZDC")
00178     eventinfo+="DUMMY";
00179 
00180   // Setup histograms -- this is all we will do for ZDC Monitor at the moment!
00181   MonitorElement* me; //JEFF
00182   dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str()+"/");
00183   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary");
00184   if (me)
00185      dbe_->removeElement(me->getName());
00186   me = dbe_->bookFloat("reportSummary");
00187   me->Fill(-1); // set status to unknown at startup
00188   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummaryMap");
00189   if (me)
00190     dbe_->removeElement(me->getName());
00191   me = dbe_->book2D("reportSummaryMap","ZDC Report Summary Map",4,0,4,1,0,1);
00192   TH2F* myhist=me->getTH2F();
00193   myhist->GetXaxis()->SetBinLabel(1,"HAD-");
00194   myhist->GetXaxis()->SetBinLabel(2,"EM-");
00195   myhist->GetXaxis()->SetBinLabel(3,"EM+");
00196   myhist->GetXaxis()->SetBinLabel(4,"HAD+");
00197   // Set all values to -1
00198   myhist->SetBinContent(1,1,-1);
00199   myhist->SetBinContent(2,1,-1);
00200   myhist->SetBinContent(3,1,-1);
00201   myhist->SetBinContent(4,1,-1);
00202   
00203 
00204   dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str()+"/reportSummaryContents/");
00205   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary/reportSummaryContents/ZDC_HADMinus");
00206   if (me)
00207      dbe_->removeElement(me->getName());
00208   me = dbe_->bookFloat("ZDC_HADMinus");
00209   me->Fill(-1); // set status to unknown at startup
00210   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary/reportSummaryContents/ZDC_EMMinus");
00211   if (me)
00212      dbe_->removeElement(me->getName());
00213   me = dbe_->bookFloat("ZDC_EMMinus");
00214   me->Fill(-1); // set status to unknown at startup
00215   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary/reportSummaryContents/ZDC_EMPlus");
00216   if (me)
00217      dbe_->removeElement(me->getName());
00218   me = dbe_->bookFloat("ZDC_EMPlus");
00219   me->Fill(-1); // set status to unknown at startup
00220   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary/reportSummaryContents/ZDC_HADPlus");
00221   if (me)
00222      dbe_->removeElement(me->getName());
00223   me = dbe_->bookFloat("ZDC_HADPlus");
00224   me->Fill(-1); // set status to unknown at startup
00225 
00226   // Add dummy DAQ Summary, DCS Summary
00227   dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str());
00228   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary");
00229   if (me)
00230     dbe_->removeElement(me->getName());
00231   me = dbe_->bookFloat("DAQSummary");
00232   me->Fill(-1); // set status to unknown at startup
00233 
00234   dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str()+"/DAQContents");
00235   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary/DAQContents/ZDC_HADPlus");
00236   if (me)
00237     dbe_->removeElement(me->getName());
00238   me = dbe_->bookFloat("ZDC_HADPlus");
00239   me->Fill(-1); // set status to unknown at startup
00240 
00241   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary/DAQContents/ZDC_HADMinus");
00242   if (me)
00243     dbe_->removeElement(me->getName());
00244   me = dbe_->bookFloat("ZDC_HADMinus");
00245   me->Fill(-1); // set status to unknown at startup
00246 
00247   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary/DAQContents/ZDC_EMPlus");
00248   if (me)
00249     dbe_->removeElement(me->getName());
00250   me = dbe_->bookFloat("ZDC_EMPlus");
00251   me->Fill(-1); // set status to unknown at startup
00252 
00253   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary/DAQContents/ZDC_EMMinus");
00254   if (me)
00255     dbe_->removeElement(me->getName());
00256   me = dbe_->bookFloat("ZDC_EMMinus");
00257   me->Fill(-1); // set status to unknown at startup
00258 
00259   // DCS Summary 
00260   dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str());
00261   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary");
00262   if (me)
00263     dbe_->removeElement(me->getName());
00264   me = dbe_->bookFloat("DCSSummary");
00265   me->Fill(-1); // set status to unknown at startup
00266 
00267   dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str()+"/DCSContents");
00268   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary/DCSContents/ZDC_HADPlus");
00269   if (me)
00270     dbe_->removeElement(me->getName());
00271   me = dbe_->bookFloat("ZDC_HADPlus");
00272   me->Fill(-1); // set status to unknown at startup
00273 
00274   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary/DCSContents/ZDC_HADMinus");
00275   if (me)
00276     dbe_->removeElement(me->getName());
00277   me = dbe_->bookFloat("ZDC_HADMinus");
00278   me->Fill(-1); // set status to unknown at startup
00279 
00280   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary/DCSContents/ZDC_EMPlus");
00281   if (me)
00282     dbe_->removeElement(me->getName());
00283   me = dbe_->bookFloat("ZDC_EMPlus");
00284   me->Fill(-1); // set status to unknown at startup
00285 
00286   me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary/DCSContents/ZDC_EMMinus");
00287   if (me)
00288     dbe_->removeElement(me->getName());
00289   me = dbe_->bookFloat("ZDC_EMMinus");
00290   me->Fill(-1); // set status to unknown at startup
00291 
00292 }
00293 
00294 
00295 //--------------------------------------------------------
00296 void ZDCMonitorClient::endJob(void) {
00297 
00298   if( debug_>0 ) 
00299     std::cout << "ZDCMonitorClient: endJob, ievt = " << ievt_ << std::endl;
00300 
00301   return;
00302 }
00303 
00304 //--------------------------------------------------------
00305 void ZDCMonitorClient::endRun(const edm::Run& r, const edm::EventSetup& c) {
00306 
00307   if (debug_>0)
00308     std::cout << std::endl<<"<ZDCMonitorClient> Standard endRun() for run " << r.id().run() << std::endl<<std::endl;
00309 
00310   if (!Online_)
00311     analyze();
00312 
00313   if( debug_ >0) std::cout <<"ZDCMonitorClient: processed events: "<<ievt_<<std::endl;
00314 
00315   if (debug_>0) std::cout <<"==>Creating report after run end condition"<<std::endl;
00316   if(irun_>1){
00317     if(inputFile_.size()!=0) report(true);
00318     else report(false);
00319   }
00320 
00321   // dumping to database
00322 
00323   // need to add separate function to do this!!!
00324 
00325   return;
00326 }
00327 
00328 void ZDCMonitorClient::writeDBfile()
00329 
00330 {
00331   return; // not used for ZDC
00332 
00333 } // ZDCMonitorClient::writeDBfile()
00334 
00335 //--------------------------------------------------------
00336 void ZDCMonitorClient::beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &c) 
00337 {
00338   // don't allow 'backsliding' across lumi blocks in online running
00339   // This still won't prevent some lumi blocks from being evaluated multiple times.  Need to think about this.
00340   //if (Online_ && (int)l.luminosityBlock()<ilumisec_) return;
00341   if (debug_>0) std::cout <<"Entered Monitor Client beginLuminosityBlock for LS = "<<l.luminosityBlock()<<std::endl;
00342   ilumisec_ = l.luminosityBlock();
00343   if( debug_>0 ) std::cout << "ZDCMonitorClient: beginLuminosityBlock" << std::endl;
00344 }
00345 
00346 //--------------------------------------------------------
00347 void ZDCMonitorClient::endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &c) {
00348 
00349   // don't allow backsliding in online running
00350   //if (Online_ && (int)l.luminosityBlock()<ilumisec_) return;
00351   if( debug_>0 ) std::cout << "ZDCMonitorClient: std::endluminosityBlock" << std::endl;
00352   if(prescaleLS_>0 && !prescale()){
00353     // do scheduled tasks...
00354     if (Online_)
00355       analyze();
00356   }
00357 
00358   return;
00359 }
00360 
00361 //--------------------------------------------------------
00362 void ZDCMonitorClient::analyze(const edm::Event& e, const edm::EventSetup& eventSetup){
00363 
00364   if (debug_>1)
00365     std::cout <<"Entered ZDCMonitorClient::analyze(const Evt...)"<<std::endl;
00366   
00367   if(resetEvents_>0 && (ievt_%resetEvents_)==0) resetAllME(); // use ievt_ here, not ievent_, since ievent is the event #, not the # of events processed
00368   if(resetLS_>0 && (ilumisec_%resetLS_)==0) resetAllME();
00369 
00370   // environment datamembers
00371 
00372   // Don't process out-of-order lumi block information in online running
00373   //if (Online_ && (int)e.luminosityBlock()<ilumisec_) return;
00374   irun_     = e.id().run();
00375   ilumisec_ = e.luminosityBlock();
00376   ievent_   = e.id().event();
00377   itime_    = e.time().value();
00378   mytime_   = (e.time().value())>>32;
00379 
00380   if (minlumisec_==0)
00381     minlumisec_=ilumisec_;
00382   minlumisec_=std::min(minlumisec_,ilumisec_);
00383   maxlumisec_=std::max(maxlumisec_,ilumisec_);
00384 
00385   if (debug_>1) 
00386     std::cout << "ZDCMonitorClient: evts: "<< ievt_ << ", run: " << irun_ << ", LS: " << ilumisec_ << ", evt: " << ievent_ << ", time: " << itime_ << std::endl; 
00387   
00388   ievt_++; 
00389 
00390   if ( runningStandalone_) return;
00391 
00392   // run if we want to check individual events, and if this event isn't prescaled
00393   if (prescaleEvt_>0 && !prescale()) 
00394     analyze();
00395 }
00396 
00397 
00398 //--------------------------------------------------------
00399 void ZDCMonitorClient::analyze(){
00400   if (debug_>0) 
00401     std::cout <<"<ZDCMonitorClient> Entered ZDCMonitorClient::analyze()"<<std::endl;
00402   if(debug_>1) std::cout<<"\nZDC Monitor Client heartbeat...."<<std::endl;
00403   
00404   createTests();  
00405   //mui_->doMonitoring();
00406   dbe_->runQTests();
00407   errorSummary();
00408 
00409 
00410   return;
00411   }
00412 
00413 //--------------------------------------------------------
00414 void ZDCMonitorClient::createTests(void){
00415   
00416   if( debug_>0 ) std::cout << "ZDCMonitorClient: creating all tests" << std::endl;
00417   return;
00418 }
00419 
00420 //--------------------------------------------------------
00421 void ZDCMonitorClient::report(bool doUpdate) {
00422   
00423   if( debug_>0 ) 
00424     std::cout << "ZDCMonitorClient: creating report, ievt = " << ievt_ << std::endl;
00425   
00426   if(doUpdate){
00427     createTests();  
00428     dbe_->runQTests();
00429   }
00430   errorSummary();
00431 
00432   //create html output if specified...
00433   if( baseHtmlDir_.size() != 0 && ievt_>0) 
00434     htmlOutput();
00435   return;
00436 }
00437 
00438 void ZDCMonitorClient::errorSummary(){
00439   
00440 
00441   float errorSummary = 1.0;
00442   
00443   char meTitle[256];
00444   sprintf(meTitle,"%sEventInfo/errorSummary",rootFolder_.c_str() );
00445   MonitorElement* me = dbe_->get(meTitle);
00446   if(me) me->Fill(errorSummary);
00447   
00448   return;
00449 }
00450 
00451 
00452 void ZDCMonitorClient::htmlOutput(void){
00453   return;
00454 }
00455 
00456 void ZDCMonitorClient::offlineSetup(){
00457   //  std::cout << std::endl;
00458   //  std::cout << " *** Hcal Generic Monitor Client, for offline operation***" << std::endl;
00459   //  std::cout << std::endl;
00460   return;
00461 }
00462 
00463 void ZDCMonitorClient::loadHistograms(TFile* infile, const char* fname)
00464 {
00465   if(!infile){
00466     throw cms::Exception("Incomplete configuration") << 
00467       "ZDCMonitorClient: this histogram file is bad! " <<std::endl;
00468     return;
00469   }
00470   return;
00471 }
00472 
00473 
00474 void ZDCMonitorClient::dumpHistograms(int& runNum, std::vector<TH1F*> &hist1d,std::vector<TH2F*> &hist2d)
00475 {
00476   hist1d.clear(); 
00477   hist2d.clear(); 
00478   return;
00479 }
00480 
00481 //--------------------------------------------------------
00482 bool ZDCMonitorClient::prescale(){
00484 
00486   if (debug_>1) std::cout <<"ZDCMonitorClient::prescale"<<std::endl;
00487   
00488   // If no prescales are set, return 'false'.  (This means that we should process the event.)
00489   if(prescaleEvt_<=0 && prescaleLS_<=0) return false;
00490 
00491   // Now check whether event should be kept.  Assume that it should not by default
00492 
00493   bool keepEvent=false;
00494   
00495   // Keep event if prescaleLS test is met or if prescaleEvt test is met
00496   if(prescaleLS_>0 && (ilumisec_%prescaleLS_)==0) keepEvent = true; // check on ls prescale; 
00497   if (prescaleEvt_>0 && (ievt_%prescaleEvt_)==0) keepEvent = true; // 
00498   
00499   // if any criteria wants to keep the event, do so
00500   if (keepEvent) return false;  // event should be kept; don't apply prescale
00501   return true; // apply prescale by default
00502 }
00503 
00504 
00505 DEFINE_FWK_MODULE(ZDCMonitorClient);