CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ZDCMonitorModule.cc
Go to the documentation of this file.
3 
6 
11 
20 
24 
26 
27 #include <memory>
28 #include <iostream>
29 #include <fstream>
30 #include <vector>
31 #include <string>
32 #include <sys/time.h>
33 
34 //--------------------------------------------------------
36 
37  irun_=0; ilumisec=0; ievent_=0; itime_=0;
38 
39  meStatus_=0;
40  meFEDS_=0;
42  fedsListed_ = false;
43  zdcMon_ = 0;
44 
45  // Assumed ZDC is out of the run by default
46  ZDCpresent_=0;
47 
48  inputLabelDigi_ = ps.getParameter<edm::InputTag>("digiLabel");
49  inputLabelRecHitZDC_ = ps.getParameter<edm::InputTag>("zdcRecHitLabel");
50 
51  tok_hcal_ = consumes<HcalUnpackerReport>(inputLabelDigi_);
52  tok_zdc_ = consumes<ZDCDigiCollection>(inputLabelDigi_);
53  tok_zdcrh_ = consumes<ZDCRecHitCollection>(inputLabelRecHitZDC_);
54 
55  showTiming_ = ps.getUntrackedParameter<bool>("showTiming", false); //-- show CPU time
56  dump2database_ = ps.getUntrackedParameter<bool>("dump2database",false); //-- dumps output to database file
57  // Check Online running
58  Online_ = ps.getUntrackedParameter<bool>("Online",false);
59  checkZDC_=ps.getUntrackedParameter<bool>("checkZDC", true);
61  debug_ = ps.getUntrackedParameter<int>("debug", 0);
62  //FEDRawDataCollection_ = ps.getUntrackedParameter<edm::InputTag>("FEDRawDataCollection",edm::InputTag("source",""));
63 
64  if (checkZDC_)
65  {
66  zdcMon_ = new HcalZDCMonitor();
67  zdcMon_->setup(ps, dbe_);
68  }
69 
70  // set parameters
71  prescaleEvt_ = ps.getUntrackedParameter<int>("diagnosticPrescaleEvt", -1);
72  if(debug_>1) std::cout << "===>ZDCMonitor event prescale = " << prescaleEvt_ << " event(s)"<< std::endl;
73 
74  prescaleLS_ = ps.getUntrackedParameter<int>("diagnosticPrescaleLS", -1);
75  if(debug_>1) std::cout << "===>ZDCMonitor lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< std::endl;
76 
77  // Base folder for the contents of this job
78  std::string subsystemname = ps.getUntrackedParameter<std::string>("subSystemFolder", "ZDC") ;
79  if(debug_>0) std::cout << "===>ZDCMonitor name = " << subsystemname << std::endl;
80  rootFolder_ = subsystemname + "/";
81 
82  gettimeofday(&psTime_.updateTV,NULL);
84  psTime_.updateTime = (psTime_.updateTV.tv_sec*1000.0+psTime_.updateTV.tv_usec/1000.0);
85  psTime_.updateTime /= 1000.0;
86  psTime_.elapsedTime=0;
87  psTime_.vetoTime=psTime_.updateTime;
88 }
89 
90 //--------------------------------------------------------
92 {
93  if (!checkZDC_) return;
94  if (dbe_!=0)
95  {
96  if (zdcMon_!=0) zdcMon_->clearME();
99  }
100 
101 if (zdcMon_!=0)
102  {
103  delete zdcMon_; zdcMon_=0;
104  }
105 }
106 
107 //--------------------------------------------------------
108 // beginJob no longer needed; trying setup within beginJob won't work !! -- IOV's not loaded
110 {
111  if (!checkZDC_) return;
112  // should we reset these counters at the start of each run?
113  ievt_ = 0;
114  ievt_pre_=0;
115 
116  // Counters for rawdata, digi, and rechit
117  ievt_rawdata_=0;
118  ievt_digi_=0;
119  ievt_rechit_=0;
120  return;
121 }
122 
123 //--------------------------------------------------------
125 {
126  if (!checkZDC_) return;
127  fedsListed_ = false;
128  ZDCpresent_ = 0;
129 
130  reset();
131 
132  if ( dbe_ != NULL ){
133  dbe_->setCurrentFolder(rootFolder_+"DQM Job Status" );
134 
135  meIEVTALL_ = dbe_->bookInt("Events Processed");
136  meIEVTRAW_ = dbe_->bookInt("Events with Raw Data");
137  meIEVTDIGI_= dbe_->bookInt("Events with Digis");
138  meIEVTRECHIT_ = dbe_->bookInt("Events with RecHits");
143  meStatus_ = dbe_->bookInt("STATUS");
144 
146  // process latency was (200,0,1), but that gave overflows
147  meLatency_ = dbe_->book1D("Process Latency","Process Latency",200,0,10);
148  meQuality_ = dbe_->book1D("Quality Status","Quality Status",100,0,1);
149  // Store whether or not subdetectors are present
150  meZDC_ = dbe_->bookInt("ZDCpresent");
151 
152  meStatus_->Fill(0);
153  // Should fill with 0 to start
155 
156  }
157  // Create histograms for individual Tasks
158  if (zdcMon_) zdcMon_->beginRun();
159 
161  c.get<HcalDbRecord>().get( pSetup );
162 
163  // Not checking ZDC raw data? In that case, no readoutMap, hcaldetid_, etc. info needed
164 
165 
166  //get conditions
167  c.get<HcalDbRecord>().get(conditions_);
168 
169  // get channel quality -- not yet used for ZDC
170  /*
171  edm::ESHandle<HcalChannelQuality> p;
172  c.get<HcalChannelQualityRcd>().get(p);
173  chanquality_= new HcalChannelQuality(*p.product());
174  */
175  return;
176 }
177 
178 //--------------------------------------------------------
180  const edm::EventSetup& context)
181 {
182  /* Don't start a new luminosity block if it is less than the current value
183  when running online. This avoids the problem of getting events
184  from mis-ordered lumi blocks, which screws up our lumi block
185  monitoring.
186  */
187  if (!checkZDC_) return;
188  if (Online_ && lumiSeg.luminosityBlock()<ilumisec)
189  return;
190 
191  // Otherwise, run normal startups
192  ilumisec = lumiSeg.luminosityBlock();
194 }
195 
196 
197 //--------------------------------------------------------
199  const edm::EventSetup& context)
200 {
201  if (!checkZDC_) return;
202  // In online running, don't process events that occur before current luminosity block
203  if (Online_ && lumiSeg.luminosityBlock()<ilumisec)
204  return;
205 
206  // Call these every luminosity block
207  if (zdcMon_!=0) { zdcMon_->endLuminosityBlock();}
208  // Call these only if prescale set
209  if (prescaleLS_>-1 && !prescale())
210  {
211  }
212  return;
213 }
214 
215 //--------------------------------------------------------
217 {
218  if (!checkZDC_) return;
219  if (debug_>0)
220  std::cout <<"ZDCMonitorModule::endRun(...) ievt = "<<ievt_<<std::endl;
221 
222  // These should be unnecessary; call them just in case, so that
223  // we're sure we get at least one fill per run
224  if (zdcMon_!=0) { zdcMon_->endLuminosityBlock();}
225 
226  return;
227 }
228 
229 
230 //--------------------------------------------------------
232 {
233  if (!checkZDC_) return;
234  if ( dbe_ != NULL ){
235  meStatus_ = dbe_->get(rootFolder_+"DQM Job Status/STATUS");
236  }
237 
238  if ( meStatus_ ) meStatus_->Fill(2);
239 
240  return; // All of the rest of the endjob stuff (filling db, etc.) should be done in the client, right?
241 
242  if (zdcMon_!=NULL) zdcMon_->done();
243 
244  return;
245 }
246 
247 //--------------------------------------------------------
249  if (!checkZDC_) return;
250  if (zdcMon_!=NULL) zdcMon_->reset();
251 
252 }
253 
254 //--------------------------------------------------------
255 void ZDCMonitorModule::analyze(const edm::Event& e, const edm::EventSetup& eventSetup)
256 {
257  if (!checkZDC_) return;
258  // environment datamembers
259  irun_ = e.id().run();
260  ievent_ = e.id().event();
261  itime_ = e.time().value();
262 
263  if (Online_ && e.luminosityBlock()<ilumisec)
264  return;
265 
266  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;
267 
268  if ( meStatus_ ) meStatus_->Fill(1);
269  meLatency_->Fill(psTime_.elapsedTime);
270 
271 
273  bool rawOK_ = true;
274  bool digiOK_ = true;
275  bool zdchitOK_ = true;
276 
278  e.getByToken(tok_hcal_,report);
279  if (!report.isValid())
280  {
281  rawOK_=false;
282  edm::LogWarning("ZDCMonitorModule")<<" Unpacker Report Digi Collection "<<inputLabelDigi_<<" not available";
283  }
284  if (rawOK_)
285  {
286  if(!fedsListed_){
287  const std::vector<int> feds = (*report).getFedsUnpacked();
288  for(unsigned int f=0; f<feds.size(); f++){
289  meFEDS_->Fill(feds[f]);
290  }
291  fedsListed_ = true;
292  fedss = feds; //Assign to a non-const holder
293  }
294  }
295  if (rawOK_==true) ++ievt_rawdata_;
296 
297  // copy of Bryan Dahmes' calibration filter
298  /*
299  // need to get raw data first before running filter!
300  int calibType=-1;
301  int dccBCN=-1;
302 
303  if (rawOK_==true)
304  {
305  // checking FEDs for calibration information
306  int numEmptyFEDs = 0 ;
307  std::vector<int> calibTypeCounter(8,0) ;
308  for( int i = FEDNumbering::MINHCALFEDID; i <= FEDNumbering::MAXHCALFEDID; i++) {
309  const FEDRawData& fedData = rawraw->FEDData(i) ;
310 
311  if ( fedData.size() < 24 ) numEmptyFEDs++ ;
312  if ( fedData.size() < 24 ) continue;
313  int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
314  calibTypeCounter.at(value)++ ; // increment the counter for this calib type
315  // Temporary for Pawel -- get BCN #101
316  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fedData.data());
317  dccBCN = dccHeader->getBunchId();
318  }
319  int maxCount = 0;
320  int numberOfFEDIds = FEDNumbering::MAXHCALFEDID - FEDNumbering::MINHCALFEDID + 1 ;
321  for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
322  if ( calibTypeCounter.at(i) > maxCount )
323  { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
324  if ( maxCount == numberOfFEDIds ) break ;
325  }
326 
327  if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
328  edm::LogWarning("HcalCalibTypeFilter") << "Conflicting calibration types found. Assigning type "
329  << calibType ;
330  LogDebug("HcalCalibTypeFilter") << "Calibration type is: " << calibType ;
331  } // if (rawOK_==true) // calibration loop
332  */
333 
334  // skip this event if we're prescaling...
335  ++ievt_;
336  if(prescaleEvt_>0 && prescale()) return;
337 
339  // try to get digis
341  e.getByToken(tok_zdc_,zdc_digi);
342  if (!zdc_digi.isValid())
343  {
344  digiOK_=false;
345  if (debug_>1) std::cout <<"<ZDCMonitorModule> COULDN'T GET ZDC DIGI"<<std::endl;
346  //edm::LogWarning("ZDCMonitorModule")<< inputLabelDigi_<<" zdc_digi not available";
347  }
348  if (digiOK_) ++ievt_digi_;
349 
351 
352  // try to get rechits
354  e.getByToken(tok_zdcrh_,zdc_hits);
355  if (!zdc_hits.isValid())
356  {
357  zdchitOK_=false;
358  // ZDC Warnings should be suppressed unless debugging is on (since we don't yet normally run zdcreco)
359  if (debug_>0)
360  edm::LogWarning("ZDCMonitorModule")<< inputLabelRecHitZDC_<<" not available";
361  }
362  if (zdchitOK_) ++ievt_rechit_;
363 
364 
366 
367  // Run the configured tasks, protect against missing products
372 
373  if (ZDCpresent_==0 && (digiOK_ || zdchitOK_))
374  {
375  ZDCpresent_=1;
377  }
378 
379  // Data Format monitor task
380  if (showTiming_)
381  {
383  }
384 
385  if (zdcMon_!=NULL && zdchitOK_ && digiOK_)
386  zdcMon_->processEvent(*zdc_digi,*zdc_hits);
387 
388  if (showTiming_)
389  {
390  cpu_timer.stop();
391  if (zdcMon_ !=NULL) std::cout <<"TIMER:: ZDC MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
393  }
394 
395  // Empty Event/Unsuppressed monitor plots
396 
397  if(debug_>0 && ievt_%1000 == 0)
398  std::cout << "ZDCMonitorModule: processed " << ievt_ << " events" << std::endl;
399 
400  if(debug_>1)
401  {
402  std::cout << "ZDCMonitorModule: processed " << ievt_ << " events" << std::endl;
403  std::cout << " ZDC RAW Data ==> " << rawOK_<< std::endl;
404  std::cout << " ZDC Digis ==> " << digiOK_<< std::endl;
405  std::cout << " ZDC RecHits ==> " << zdchitOK_<< std::endl;
406  }
407 
408  return;
409 }
410 
411 //--------------------------------------------------------
413 {
414  if (!checkZDC_) return true;
415 
418  if (debug_>1) std::cout <<"ZDCMonitorModule::prescale: ievt = "<<ievt_<<std::endl;
419  // If no prescales are set, return 'false'. (This means that we should process the event.)
420  if(prescaleEvt_<=0 && prescaleLS_<=0) return false;
421 
422  // Now check whether event should be kept. Assume that it should not by default
423  bool keepEvent=false;
424 
425  // Keep event if prescaleLS test is met or if prescaleEvt test is met
426  if(prescaleLS_>0 && (ilumisec%prescaleLS_)==0) keepEvent = true; // check on ls prescale;
427  if (prescaleEvt_>0 && (ievt_%prescaleEvt_)==0) keepEvent = true; //
428 
429  // if any criteria wants to keep the event, do so
430  if (keepEvent) return false; // event should be kept; don't apply prescale
431  return true; // apply prescale by default
432 
433 } // ZDCMonitorModule::prescale(...)
434 
435 
436 // -------------------------------------------------
437 
RunNumber_t run() const
Definition: EventID.h:42
void beginRun(const edm::Run &run, const edm::EventSetup &c)
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:44
T getUntrackedParameter(std::string const &, T const &) const
std::vector< int > fedss
struct ZDCMonitorModule::@281 psTime_
edm::EDGetTokenT< HcalUnpackerReport > tok_hcal_
void start()
Definition: CPUTimer.cc:74
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:954
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:434
edm::InputTag inputLabelDigi_
virtual void beginRun()
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
MonitorElement * meIEVTRECHIT_
edm::EDGetTokenT< ZDCRecHitCollection > tok_zdcrh_
edm::ESHandle< HcalDbService > conditions_
ZDCMonitorModule(const edm::ParameterSet &ps)
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:59
void reset()
Definition: CPUTimer.cc:107
#define NULL
Definition: scimark2.h:8
edm::CPUTimer cpu_timer
MonitorElement * meIEVTALL_
void analyze(const edm::Event &e, const edm::EventSetup &c)
int prescaleLS_
units of events
void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
void Fill(long long x)
LuminosityBlockNumber_t luminosityBlock() const
tuple report
Definition: zeeHLT_cff.py:9
MonitorElement * meQuality_
edm::InputTag inputLabelRecHitZDC_
void removeContents(void)
erase all monitoring elements in current directory (not including subfolders);
Definition: DQMStore.cc:3135
virtual void clearME()
int debug_
Verbosity switch used for debugging or informational output.
void setup(const edm::ParameterSet &ps, DQMStore *dbe)
MonitorElement * meIEVTRAW_
void endRun(const edm::Run &run, const edm::EventSetup &c)
MonitorElement * meZDC_
double f[11][100]
HcalZDCMonitor * zdcMon_
Times stop()
Definition: CPUTimer.cc:94
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1708
bool isValid() const
Definition: HandleBase.h:76
std::string rootFolder_
edm::EDGetTokenT< ZDCDigiCollection > tok_zdc_
void endLuminosityBlock(void)
double cpuTime() const
Definition: CPUTimer.cc:158
void beginLuminosityBlock(int lb)
const T & get() const
Definition: EventSetup.h:55
unsigned int ilumisec
void processEvent(const ZDCDigiCollection &digi, const ZDCRecHitCollection &rechit)
virtual void done()
MonitorElement * meIEVTDIGI_
edm::EventID id() const
Definition: EventBase.h:56
MonitorElement * meStatus_
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
DQMStore * dbe_
Connection to the DQM backend.
tuple cout
Definition: gather_cfg.py:121
MonitorElement * meLatency_
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:861
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:667
MonitorElement * meFEDS_
Definition: Run.h:41
bool prescale()
Boolean prescale test for this event.