CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZDCMonitorClient.cc
Go to the documentation of this file.
6 
7 #include "TROOT.h"
8 #include "TTree.h"
9 #include "TGaxis.h"
10 #include "TH1F.h"
11 #include "TH2F.h"
12 #include "TFile.h"
13 
14 #include <memory>
15 #include <iostream>
16 #include <fstream>
17 #include <vector>
18 #include <string>
19 #include <sys/time.h>
20 
23 
25 // Use to hold/get channel status
30 
34 
35 
36 //--------------------------------------------------------
38  initialize(ps);
39 }
40 
42 
43 //--------------------------------------------------------
45 
46  if (debug_>0) std::cout << "ZDCMonitorClient: Exit ..." << std::endl;
47 }
48 
49 //--------------------------------------------------------
51 
52  irun_=0; ilumisec_=0; ievent_=0; itime_=0;
53 
55 
56 
57  debug_ = ps.getUntrackedParameter<int>("debug", 0);
58  if (debug_>0)
59  std::cout << std::endl<<" *** ZDC Monitor Client ***" << std::endl<<std::endl;
60 
61  if(debug_>1) std::cout << "ZDCMonitorClient: constructor...." << std::endl;
62 
63  Online_ = ps.getUntrackedParameter<bool>("Online",false);
64  // timing switch
65  showTiming_ = ps.getUntrackedParameter<bool>("showTiming",false);
66 
67  // MonitorDaemon switch
68  enableMonitorDaemon_ = ps.getUntrackedParameter<bool>("enableMonitorDaemon", true);
69  if (debug_>0)
70  {
71  if ( enableMonitorDaemon_ ) std::cout << "-->enableMonitorDaemon switch is ON" << std::endl;
72  else std::cout << "-->enableMonitorDaemon switch is OFF" << std::endl;
73  }
74 
75  // get hold of back-end interface
77  if (debug_>1) dbe_->showDirStructure();
78 
79  // DQM ROOT input
80  inputFile_ = ps.getUntrackedParameter<std::string>("inputFile", "");
81  if(inputFile_.size()!=0 && debug_>0) std::cout << "-->reading DQM input from " << inputFile_ << std::endl;
82 
83  if( ! enableMonitorDaemon_ ) {
84  if( inputFile_.size() != 0 && dbe_!=NULL){
87  }
88  }
89 
90  //histogram reset freqency, update frequency, timeout
91  resetEvents_ = ps.getUntrackedParameter<int>("resetFreqEvents",-1); //number of real events
92  if(resetEvents_!=-1 && debug_>0) std::cout << "-->Will reset histograms every " << resetEvents_ <<" events." << std::endl;
93  resetLS_ = ps.getUntrackedParameter<int>("resetFreqLS",-1); //number of lumisections
94  if(resetLS_!=-1 && debug_>0) std::cout << "-->Will reset histograms every " << resetLS_ <<" lumi sections." << std::endl;
95 
96  // base Html output directory
97  baseHtmlDir_ = ps.getUntrackedParameter<std::string>("baseHtmlDir", "");
98  if (debug_>0)
99  {
100  if( baseHtmlDir_.size() != 0)
101  std::cout << "-->HTML output will go to baseHtmlDir = '" << baseHtmlDir_ << "'" << std::endl;
102  else std::cout << "-->HTML output is disabled" << std::endl;
103  }
104 
105  runningStandalone_ = ps.getUntrackedParameter<bool>("runningStandalone", false); // unnecessary? Or use for offline client processing?
106  if (debug_>1)
107  {
108  if( runningStandalone_ ) std::cout << "-->standAlone switch is ON" << std::endl;
109  else std::cout << "-->standAlone switch is OFF" << std::endl;
110  }
111 
112  // set parameters
113  prescaleEvt_ = ps.getUntrackedParameter<int>("diagnosticPrescaleEvt", -1);
114  if (debug_>0)
115  std::cout << "===>DQM event prescale = " << prescaleEvt_ << " event(s)"<< std::endl;
116 
117  prescaleLS_ = ps.getUntrackedParameter<int>("diagnosticPrescaleLS", -1);
118  if (debug_>0) std::cout << "===>DQM lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< std::endl;
119 
120  // Base folder for the contents of this job
121  std::string subsystemname = ps.getUntrackedParameter<std::string>("subSystemFolder", "ZDC") ;
122  if (debug_>0) std::cout << "===>ZDCMonitor name = " << subsystemname << std::endl;
123  rootFolder_ = subsystemname + "/";
124 
125  return;
126 }
127 
128 //--------------------------------------------------------
129 // remove all MonitorElements and directories
131  if (debug_>0) std::cout <<"<ZDCMonitorClient>removeAllME()"<<std::endl;
132  if(dbe_==NULL) return;
133 
134  // go to top directory
135  dbe_->cd();
136  // remove MEs at top directory
137  dbe_->removeContents();
138  // remove directory (including subdirectories recursively)
139  if(dbe_->dirExists("Collector"))
140  dbe_->rmdir("Collector");
141  if(dbe_->dirExists("Summary"))
142  dbe_->rmdir("Summary");
143  return;
144 }
145 
146 //--------------------------------------------------------
149  if (debug_>0) std::cout <<"<ZDCMonitorClient> resetAllME()"<<std::endl;
150  return;
151 }
152 
153 //--------------------------------------------------------
155 
156  if( debug_>0 ) std::cout << "ZDCMonitorClient: beginJob" << std::endl;
157 
158  ievt_ = 0;
159 
160  return;
161 }
162 
163 //--------------------------------------------------------
165 
166  if (debug_>0)
167  std::cout << std::endl<<"ZDCMonitorClient: Standard beginRun() for run " << r.id().run() << std::endl<<std::endl;
168 
169  // Get current channel quality
170  /*
171  edm::ESHandle<HcalChannelQuality> p;
172  c.get<HcalChannelQualityRcd>().get(p);
173  chanquality_= new HcalChannelQuality(*p.product());
174  */
175 
176  std::string eventinfo="EventInfo";
177  if (rootFolder_!="ZDC")
178  eventinfo+="DUMMY";
179 
180  // Setup histograms -- this is all we will do for ZDC Monitor at the moment!
181  MonitorElement* me; //JEFF
182  dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str()+"/");
183  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary");
184  if (me)
185  dbe_->removeElement(me->getName());
186  me = dbe_->bookFloat("reportSummary");
187  me->Fill(-1); // set status to unknown at startup
188  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummaryMap");
189  if (me)
190  dbe_->removeElement(me->getName());
191  me = dbe_->book2D("reportSummaryMap","ZDC Report Summary Map",4,0,4,1,0,1);
192  TH2F* myhist=me->getTH2F();
193  myhist->GetXaxis()->SetBinLabel(1,"HAD-");
194  myhist->GetXaxis()->SetBinLabel(2,"EM-");
195  myhist->GetXaxis()->SetBinLabel(3,"EM+");
196  myhist->GetXaxis()->SetBinLabel(4,"HAD+");
197  // Set all values to -1
198  myhist->SetBinContent(1,1,-1);
199  myhist->SetBinContent(2,1,-1);
200  myhist->SetBinContent(3,1,-1);
201  myhist->SetBinContent(4,1,-1);
202 
203 
204  dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str()+"/reportSummaryContents/");
205  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary/reportSummaryContents/ZDC_HADMinus");
206  if (me)
207  dbe_->removeElement(me->getName());
208  me = dbe_->bookFloat("ZDC_HADMinus");
209  me->Fill(-1); // set status to unknown at startup
210  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary/reportSummaryContents/ZDC_EMMinus");
211  if (me)
212  dbe_->removeElement(me->getName());
213  me = dbe_->bookFloat("ZDC_EMMinus");
214  me->Fill(-1); // set status to unknown at startup
215  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary/reportSummaryContents/ZDC_EMPlus");
216  if (me)
217  dbe_->removeElement(me->getName());
218  me = dbe_->bookFloat("ZDC_EMPlus");
219  me->Fill(-1); // set status to unknown at startup
220  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/reportSummary/reportSummaryContents/ZDC_HADPlus");
221  if (me)
222  dbe_->removeElement(me->getName());
223  me = dbe_->bookFloat("ZDC_HADPlus");
224  me->Fill(-1); // set status to unknown at startup
225 
226  // Add dummy DAQ Summary, DCS Summary
227  dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str());
228  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary");
229  if (me)
230  dbe_->removeElement(me->getName());
231  me = dbe_->bookFloat("DAQSummary");
232  me->Fill(-1); // set status to unknown at startup
233 
234  dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str()+"/DAQContents");
235  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary/DAQContents/ZDC_HADPlus");
236  if (me)
237  dbe_->removeElement(me->getName());
238  me = dbe_->bookFloat("ZDC_HADPlus");
239  me->Fill(-1); // set status to unknown at startup
240 
241  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary/DAQContents/ZDC_HADMinus");
242  if (me)
243  dbe_->removeElement(me->getName());
244  me = dbe_->bookFloat("ZDC_HADMinus");
245  me->Fill(-1); // set status to unknown at startup
246 
247  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary/DAQContents/ZDC_EMPlus");
248  if (me)
249  dbe_->removeElement(me->getName());
250  me = dbe_->bookFloat("ZDC_EMPlus");
251  me->Fill(-1); // set status to unknown at startup
252 
253  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DAQSummary/DAQContents/ZDC_EMMinus");
254  if (me)
255  dbe_->removeElement(me->getName());
256  me = dbe_->bookFloat("ZDC_EMMinus");
257  me->Fill(-1); // set status to unknown at startup
258 
259  // DCS Summary
260  dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str());
261  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary");
262  if (me)
263  dbe_->removeElement(me->getName());
264  me = dbe_->bookFloat("DCSSummary");
265  me->Fill(-1); // set status to unknown at startup
266 
267  dbe_->setCurrentFolder(rootFolder_+eventinfo.c_str()+"/DCSContents");
268  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary/DCSContents/ZDC_HADPlus");
269  if (me)
270  dbe_->removeElement(me->getName());
271  me = dbe_->bookFloat("ZDC_HADPlus");
272  me->Fill(-1); // set status to unknown at startup
273 
274  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary/DCSContents/ZDC_HADMinus");
275  if (me)
276  dbe_->removeElement(me->getName());
277  me = dbe_->bookFloat("ZDC_HADMinus");
278  me->Fill(-1); // set status to unknown at startup
279 
280  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary/DCSContents/ZDC_EMPlus");
281  if (me)
282  dbe_->removeElement(me->getName());
283  me = dbe_->bookFloat("ZDC_EMPlus");
284  me->Fill(-1); // set status to unknown at startup
285 
286  me=dbe_->get(rootFolder_+eventinfo.c_str()+"/DCSSummary/DCSContents/ZDC_EMMinus");
287  if (me)
288  dbe_->removeElement(me->getName());
289  me = dbe_->bookFloat("ZDC_EMMinus");
290  me->Fill(-1); // set status to unknown at startup
291 
292 }
293 
294 
295 //--------------------------------------------------------
297 
298  if( debug_>0 )
299  std::cout << "ZDCMonitorClient: endJob, ievt = " << ievt_ << std::endl;
300 
301  return;
302 }
303 
304 //--------------------------------------------------------
306 
307  if (debug_>0)
308  std::cout << std::endl<<"<ZDCMonitorClient> Standard endRun() for run " << r.id().run() << std::endl<<std::endl;
309 
310  if (!Online_)
311  analyze();
312 
313  if( debug_ >0) std::cout <<"ZDCMonitorClient: processed events: "<<ievt_<<std::endl;
314 
315  if (debug_>0) std::cout <<"==>Creating report after run end condition"<<std::endl;
316  if(irun_>1){
317  if(inputFile_.size()!=0) report(true);
318  else report(false);
319  }
320 
321  // dumping to database
322 
323  // need to add separate function to do this!!!
324 
325  return;
326 }
327 
329 
330 {
331  return; // not used for ZDC
332 
333 } // ZDCMonitorClient::writeDBfile()
334 
335 //--------------------------------------------------------
337 {
338  // don't allow 'backsliding' across lumi blocks in online running
339  // This still won't prevent some lumi blocks from being evaluated multiple times. Need to think about this.
340  //if (Online_ && (int)l.luminosityBlock()<ilumisec_) return;
341  if (debug_>0) std::cout <<"Entered Monitor Client beginLuminosityBlock for LS = "<<l.luminosityBlock()<<std::endl;
343  if( debug_>0 ) std::cout << "ZDCMonitorClient: beginLuminosityBlock" << std::endl;
344 }
345 
346 //--------------------------------------------------------
348 
349  // don't allow backsliding in online running
350  //if (Online_ && (int)l.luminosityBlock()<ilumisec_) return;
351  if( debug_>0 ) std::cout << "ZDCMonitorClient: std::endluminosityBlock" << std::endl;
352  if(prescaleLS_>0 && !prescale()){
353  // do scheduled tasks...
354  if (Online_)
355  analyze();
356  }
357 
358  return;
359 }
360 
361 //--------------------------------------------------------
362 void ZDCMonitorClient::analyze(const edm::Event& e, const edm::EventSetup& eventSetup){
363 
364  if (debug_>1)
365  std::cout <<"Entered ZDCMonitorClient::analyze(const Evt...)"<<std::endl;
366 
367  if(resetEvents_>0 && (ievt_%resetEvents_)==0) resetAllME(); // use ievt_ here, not ievent_, since ievent is the event #, not the # of events processed
368  if(resetLS_>0 && (ilumisec_%resetLS_)==0) resetAllME();
369 
370  // environment datamembers
371 
372  // Don't process out-of-order lumi block information in online running
373  //if (Online_ && (int)e.luminosityBlock()<ilumisec_) return;
374  irun_ = e.id().run();
376  ievent_ = e.id().event();
377  itime_ = e.time().value();
378  mytime_ = (e.time().value())>>32;
379 
380  if (minlumisec_==0)
384 
385  if (debug_>1)
386  std::cout << "ZDCMonitorClient: evts: "<< ievt_ << ", run: " << irun_ << ", LS: " << ilumisec_ << ", evt: " << ievent_ << ", time: " << itime_ << std::endl;
387 
388  ievt_++;
389 
390  if ( runningStandalone_) return;
391 
392  // run if we want to check individual events, and if this event isn't prescaled
393  if (prescaleEvt_>0 && !prescale())
394  analyze();
395 }
396 
397 
398 //--------------------------------------------------------
400  if (debug_>0)
401  std::cout <<"<ZDCMonitorClient> Entered ZDCMonitorClient::analyze()"<<std::endl;
402  if(debug_>1) std::cout<<"\nZDC Monitor Client heartbeat...."<<std::endl;
403 
404  createTests();
405  //mui_->doMonitoring();
406  dbe_->runQTests();
407  errorSummary();
408 
409 
410  return;
411  }
412 
413 //--------------------------------------------------------
415 
416  if( debug_>0 ) std::cout << "ZDCMonitorClient: creating all tests" << std::endl;
417  return;
418 }
419 
420 //--------------------------------------------------------
421 void ZDCMonitorClient::report(bool doUpdate) {
422 
423  if( debug_>0 )
424  std::cout << "ZDCMonitorClient: creating report, ievt = " << ievt_ << std::endl;
425 
426  if(doUpdate){
427  createTests();
428  dbe_->runQTests();
429  }
430  errorSummary();
431 
432  //create html output if specified...
433  if( baseHtmlDir_.size() != 0 && ievt_>0)
434  htmlOutput();
435  return;
436 }
437 
439 
440 
441  float errorSummary = 1.0;
442 
443  char meTitle[256];
444  sprintf(meTitle,"%sEventInfo/errorSummary",rootFolder_.c_str() );
445  MonitorElement* me = dbe_->get(meTitle);
446  if(me) me->Fill(errorSummary);
447 
448  return;
449 }
450 
451 
453  return;
454 }
455 
457  // std::cout << std::endl;
458  // std::cout << " *** Hcal Generic Monitor Client, for offline operation***" << std::endl;
459  // std::cout << std::endl;
460  return;
461 }
462 
464 {
465  if(!infile){
466  throw cms::Exception("Incomplete configuration") <<
467  "ZDCMonitorClient: this histogram file is bad! " <<std::endl;
468  return;
469  }
470  return;
471 }
472 
473 
474 void ZDCMonitorClient::dumpHistograms(int& runNum, std::vector<TH1F*> &hist1d,std::vector<TH2F*> &hist2d)
475 {
476  hist1d.clear();
477  hist2d.clear();
478  return;
479 }
480 
481 //--------------------------------------------------------
484 
486  if (debug_>1) std::cout <<"ZDCMonitorClient::prescale"<<std::endl;
487 
488  // If no prescales are set, return 'false'. (This means that we should process the event.)
489  if(prescaleEvt_<=0 && prescaleLS_<=0) return false;
490 
491  // Now check whether event should be kept. Assume that it should not by default
492 
493  bool keepEvent=false;
494 
495  // Keep event if prescaleLS test is met or if prescaleEvt test is met
496  if(prescaleLS_>0 && (ilumisec_%prescaleLS_)==0) keepEvent = true; // check on ls prescale;
497  if (prescaleEvt_>0 && (ievt_%prescaleEvt_)==0) keepEvent = true; //
498 
499  // if any criteria wants to keep the event, do so
500  if (keepEvent) return false; // event should be kept; don't apply prescale
501  return true; // apply prescale by default
502 }
503 
504 
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
const std::string & getName(void) const
get name of ME
RunID const & id() const
Definition: RunBase.h:41
bool prescale()
Boolean prescale test for this event.
RunNumber_t run() const
Definition: RunID.h:43
std::string inputFile_
void rmdir(const std::string &fullpath)
Definition: DQMStore.cc:3046
void endJob(void)
EndJob.
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:632
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void endRun(const edm::Run &r, const edm::EventSetup &c)
EndRun.
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
#define NULL
Definition: scimark2.h:8
int prescaleLS_
units of events
void beginLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &c)
BeginLumiBlock.
int debug_
Verbosity switch used for debugging or informational output.
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:879
std::string rootFolder_
void errorSummary()
Generate error summary.
void Fill(long long x)
LuminosityBlockNumber_t luminosityBlock() const
void dumpHistograms(int &runNum, std::vector< TH1F * > &hist1d, std::vector< TH2F * > &hist2d)
void initialize(const edm::ParameterSet &ps)
void removeContents(void)
erase all monitoring elements in current directory (not including subfolders);
Definition: DQMStore.cc:3080
const T & max(const T &a, const T &b)
DQMStore * dbe_
Connection to the DQM backend.
void removeElement(const std::string &name)
Definition: DQMStore.cc:3088
void analyze(void)
Analyze.
void runQTests(void)
Definition: DQMStore.cc:3198
void beginJob()
BeginJob.
void report(bool update)
Create reports.
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1693
void resetAllME(void)
reset all monitor elements
~ZDCMonitorClient()
Destructor.
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:720
std::string baseHtmlDir_
void createTests(void)
Create tests.
string fname
main script
void endLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &c)
EndLumiBlock.
edm::EventID id() const
Definition: EventBase.h:56
ZDCMonitorClient()
Constructors.
void beginRun(const edm::Run &r, const edm::EventSetup &c)
BeginRun.
bool open(const std::string &filename, bool overwrite=false, const std::string &path="", const std::string &prepend="", OpenRunDirs stripdirs=KeepRunDirs, bool fileMustExist=true)
Definition: DQMStore.cc:2840
tuple cout
Definition: gather_cfg.py:121
void showDirStructure(void) const
Definition: DQMStore.cc:3277
TH2F * getTH2F(void) const
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:1070
void htmlOutput(void)
HtmlOutput.
TimeValue_t value() const
Definition: Timestamp.h:56
edm::Timestamp time() const
Definition: EventBase.h:57
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:655
Definition: Run.h:41
void loadHistograms(TFile *infile, const char *fname)