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  , inputLabelDigi_(ps.getParameter<edm::InputTag>("digiLabel"))
37  , inputLabelRecHitZDC_(ps.getParameter<edm::InputTag>("zdcRecHitLabel"))
38 {
39 
40  irun_=0; ilumisec=0; ievent_=0; itime_=0;
41 
42  meStatus_=0;
43  meFEDS_=0;
45  fedsListed_ = false;
46  zdcMon_ = 0;
47 
48  // Assumed ZDC is out of the run by default
49  ZDCpresent_=0;
50 
51 
52  tok_hcal_ = consumes<HcalUnpackerReport>(inputLabelDigi_);
53  tok_zdc_ = consumes<ZDCDigiCollection>(inputLabelDigi_);
54  tok_zdcrh_ = consumes<ZDCRecHitCollection>(inputLabelRecHitZDC_);
55 
56  showTiming_ = ps.getUntrackedParameter<bool>("showTiming", false); //-- show CPU time
57  dump2database_ = ps.getUntrackedParameter<bool>("dump2database",false); //-- dumps output to database file
58  // Check Online running
59  Online_ = ps.getUntrackedParameter<bool>("Online",false);
60  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  // set parameters
65  prescaleEvt_ = ps.getUntrackedParameter<int>("diagnosticPrescaleEvt", -1);
66  if(debug_>1) std::cout << "===>ZDCMonitor event prescale = " << prescaleEvt_ << " event(s)"<< std::endl;
67 
68  prescaleLS_ = ps.getUntrackedParameter<int>("diagnosticPrescaleLS", -1);
69  if(debug_>1) std::cout << "===>ZDCMonitor lumi section prescale = " << prescaleLS_ << " lumi section(s)"<< std::endl;
70 
71  // Base folder for the contents of this job
72  std::string subsystemname = ps.getUntrackedParameter<std::string>("subSystemFolder", "ZDC") ;
73  if(debug_>0) std::cout << "===>ZDCMonitor name = " << subsystemname << std::endl;
74  rootFolder_ = subsystemname + "/";
75 
76  gettimeofday(&psTime_.updateTV,NULL);
78  psTime_.updateTime = (psTime_.updateTV.tv_sec*1000.0+psTime_.updateTV.tv_usec/1000.0);
79  psTime_.updateTime /= 1000.0;
80  psTime_.elapsedTime=0;
81  psTime_.vetoTime=psTime_.updateTime;
82 
83  // beginJob contents has been moved to the constructor for the MT migration
84  if (checkZDC_) {
85  // should we reset these counters at the start of each run?
86  ievt_ = 0;
87  ievt_pre_=0;
88 
89  // Counters for rawdata, digi, and rechit
90  ievt_rawdata_=0;
91  ievt_digi_=0;
92  ievt_rechit_=0;
93  }
94 }
95 
96 //--------------------------------------------------------
98 {
99  if (!checkZDC_) return;
100 
101  if (zdcMon_!=0)
102  {
103  delete zdcMon_; zdcMon_=0;
104  }
105 }
106 
107 
108 //--------------------------------------------------------
110 {
111  if (!checkZDC_) return;
112 
113  zdcMon_ = new HcalZDCMonitor();
114  zdcMon_->setup(ps_, ib);
115 
116  fedsListed_ = false;
117  ZDCpresent_ = 0;
118 
119  reset();
120 
121  ib.setCurrentFolder(rootFolder_+"DQM Job Status" );
122 
123  meIEVTALL_ = ib.bookInt("Events Processed");
124  meIEVTRAW_ = ib.bookInt("Events with Raw Data");
125  meIEVTDIGI_= ib.bookInt("Events with Digis");
126  meIEVTRECHIT_ = ib.bookInt("Events with RecHits");
131  meStatus_ = ib.bookInt("STATUS");
132 
134  // process latency was (200,0,1), but that gave overflows
135  meLatency_ = ib.book1D("Process Latency","Process Latency",200,0,10);
136  meQuality_ = ib.book1D("Quality Status","Quality Status",100,0,1);
137  // Store whether or not subdetectors are present
138  meZDC_ = ib.bookInt("ZDCpresent");
139 
140  meStatus_->Fill(0);
141  // Should fill with 0 to start
143 
144  // Create histograms for individual Tasks
145  if (zdcMon_) zdcMon_->beginRun();
146 
148  c.get<HcalDbRecord>().get( pSetup );
149 
150  // Not checking ZDC raw data? In that case, no readoutMap, hcaldetid_, etc. info needed
151 
152 
153  //get conditions
154  c.get<HcalDbRecord>().get(conditions_);
155 
156  // get channel quality -- not yet used for ZDC
157  /*
158  edm::ESHandle<HcalChannelQuality> p;
159  c.get<HcalChannelQualityRcd>().get(p);
160  chanquality_= new HcalChannelQuality(*p.product());
161  */
162  return;
163 }
164 
165 //--------------------------------------------------------
167  const edm::EventSetup& context)
168 {
169  /* Don't start a new luminosity block if it is less than the current value
170  when running online. This avoids the problem of getting events
171  from mis-ordered lumi blocks, which screws up our lumi block
172  monitoring.
173  */
174  if (!checkZDC_) return;
175  if (Online_ && lumiSeg.luminosityBlock()<ilumisec)
176  return;
177 
178  // Otherwise, run normal startups
179  ilumisec = lumiSeg.luminosityBlock();
181 }
182 
183 
184 //--------------------------------------------------------
186  const edm::EventSetup& context)
187 {
188  if (!checkZDC_) return;
189  // In online running, don't process events that occur before current luminosity block
190  if (Online_ && lumiSeg.luminosityBlock()<ilumisec)
191  return;
192 
193  // Call these every luminosity block
194  if (zdcMon_!=0) { zdcMon_->endLuminosityBlock();}
195  // Call these only if prescale set
196  if (prescaleLS_>-1 && !prescale())
197  {
198  }
199  return;
200 }
201 
202 //--------------------------------------------------------
204 {
205  if (!checkZDC_) return;
206  if (debug_>0)
207  std::cout <<"ZDCMonitorModule::endRun(...) ievt = "<<ievt_<<std::endl;
208 
209  // These should be unnecessary; call them just in case, so that
210  // we're sure we get at least one fill per run
211 // if (zdcMon_!=0) { zdcMon_->endLuminosityBlock();}
212 
213  return;
214 }
215 
216 
217 //--------------------------------------------------------
219  if (!checkZDC_) return;
220  if (zdcMon_!=NULL) zdcMon_->reset();
221 
222 }
223 
224 //--------------------------------------------------------
225 void ZDCMonitorModule::analyze(const edm::Event& e, const edm::EventSetup& eventSetup)
226 {
227  if (!checkZDC_) return;
228  // environment datamembers
229  irun_ = e.id().run();
230  ievent_ = e.id().event();
231  itime_ = e.time().value();
232 
233  if (Online_ && e.luminosityBlock()<ilumisec)
234  return;
235 
236  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;
237 
238  if ( meStatus_ ) meStatus_->Fill(1);
239  meLatency_->Fill(psTime_.elapsedTime);
240 
241 
243  bool rawOK_ = true;
244  bool digiOK_ = true;
245  bool zdchitOK_ = true;
246 
248  e.getByToken(tok_hcal_,report);
249  if (!report.isValid())
250  {
251  rawOK_=false;
252  edm::LogWarning("ZDCMonitorModule")<<" Unpacker Report Digi Collection "<<inputLabelDigi_<<" not available";
253  }
254  if (rawOK_)
255  {
256  if(!fedsListed_){
257  const std::vector<int> feds = (*report).getFedsUnpacked();
258  for(unsigned int f=0; f<feds.size(); f++){
259  meFEDS_->Fill(feds[f]);
260  }
261  fedsListed_ = true;
262  fedss = feds; //Assign to a non-const holder
263  }
264  }
265  if (rawOK_==true) ++ievt_rawdata_;
266 
267  // copy of Bryan Dahmes' calibration filter
268  /*
269  // need to get raw data first before running filter!
270  int calibType=-1;
271  int dccBCN=-1;
272 
273  if (rawOK_==true)
274  {
275  // checking FEDs for calibration information
276  int numEmptyFEDs = 0 ;
277  std::vector<int> calibTypeCounter(8,0) ;
278  for( int i = FEDNumbering::MINHCALFEDID; i <= FEDNumbering::MAXHCALFEDID; i++) {
279  const FEDRawData& fedData = rawraw->FEDData(i) ;
280 
281  if ( fedData.size() < 24 ) numEmptyFEDs++ ;
282  if ( fedData.size() < 24 ) continue;
283  int value = ((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
284  calibTypeCounter.at(value)++ ; // increment the counter for this calib type
285  // Temporary for Pawel -- get BCN #101
286  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fedData.data());
287  dccBCN = dccHeader->getBunchId();
288  }
289  int maxCount = 0;
290  int numberOfFEDIds = FEDNumbering::MAXHCALFEDID - FEDNumbering::MINHCALFEDID + 1 ;
291  for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
292  if ( calibTypeCounter.at(i) > maxCount )
293  { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
294  if ( maxCount == numberOfFEDIds ) break ;
295  }
296 
297  if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
298  edm::LogWarning("HcalCalibTypeFilter") << "Conflicting calibration types found. Assigning type "
299  << calibType ;
300  LogDebug("HcalCalibTypeFilter") << "Calibration type is: " << calibType ;
301  } // if (rawOK_==true) // calibration loop
302  */
303 
304  // skip this event if we're prescaling...
305  ++ievt_;
306  if(prescaleEvt_>0 && prescale()) return;
307 
309  // try to get digis
311  e.getByToken(tok_zdc_,zdc_digi);
312  if (!zdc_digi.isValid())
313  {
314  digiOK_=false;
315  if (debug_>1) std::cout <<"<ZDCMonitorModule> COULDN'T GET ZDC DIGI"<<std::endl;
316  //edm::LogWarning("ZDCMonitorModule")<< inputLabelDigi_<<" zdc_digi not available";
317  }
318  if (digiOK_) ++ievt_digi_;
319 
321 
322  // try to get rechits
324  e.getByToken(tok_zdcrh_,zdc_hits);
325  if (!zdc_hits.isValid())
326  {
327  zdchitOK_=false;
328  // ZDC Warnings should be suppressed unless debugging is on (since we don't yet normally run zdcreco)
329  if (debug_>0)
330  edm::LogWarning("ZDCMonitorModule")<< inputLabelRecHitZDC_<<" not available";
331  }
332  if (zdchitOK_) ++ievt_rechit_;
333 
334 
336 
337  // Run the configured tasks, protect against missing products
342 
343  if (ZDCpresent_==0 && (digiOK_ || zdchitOK_))
344  {
345  ZDCpresent_=1;
347  }
348 
349  // Data Format monitor task
350  if (showTiming_)
351  {
353  }
354 
355  if (zdcMon_!=NULL && zdchitOK_ && digiOK_)
356  zdcMon_->processEvent(*zdc_digi,*zdc_hits, *report);
357 
358  if (showTiming_)
359  {
360  cpu_timer.stop();
361  if (zdcMon_ !=NULL) std::cout <<"TIMER:: ZDC MONITOR ->"<<cpu_timer.cpuTime()<<std::endl;
363  }
364 
365  // Empty Event/Unsuppressed monitor plots
366 
367  if(debug_>0 && ievt_%1000 == 0)
368  std::cout << "ZDCMonitorModule: processed " << ievt_ << " events" << std::endl;
369 
370  if(debug_>1)
371  {
372  std::cout << "ZDCMonitorModule: processed " << ievt_ << " events" << std::endl;
373  std::cout << " ZDC RAW Data ==> " << rawOK_<< std::endl;
374  std::cout << " ZDC Digis ==> " << digiOK_<< std::endl;
375  std::cout << " ZDC RecHits ==> " << zdchitOK_<< std::endl;
376  }
377 
378  return;
379 }
380 
381 //--------------------------------------------------------
383 {
384  if (!checkZDC_) return true;
385 
388  if (debug_>1) std::cout <<"ZDCMonitorModule::prescale: ievt = "<<ievt_<<std::endl;
389  // If no prescales are set, return 'false'. (This means that we should process the event.)
390  if(prescaleEvt_<=0 && prescaleLS_<=0) return false;
391 
392  // Now check whether event should be kept. Assume that it should not by default
393  bool keepEvent=false;
394 
395  // Keep event if prescaleLS test is met or if prescaleEvt test is met
396  if(prescaleLS_>0 && (ilumisec%prescaleLS_)==0) keepEvent = true; // check on ls prescale;
397  if (prescaleEvt_>0 && (ievt_%prescaleEvt_)==0) keepEvent = true; //
398 
399  // if any criteria wants to keep the event, do so
400  if (keepEvent) return false; // event should be kept; don't apply prescale
401  return true; // apply prescale by default
402 
403 } // ZDCMonitorModule::prescale(...)
404 
405 
406 // -------------------------------------------------
407 
RunNumber_t run() const
Definition: EventID.h:39
EventNumber_t event() const
Definition: EventID.h:41
T getUntrackedParameter(std::string const &, T const &) const
std::vector< int > fedss
int ib
Definition: cuy.py:660
edm::EDGetTokenT< HcalUnpackerReport > tok_hcal_
void start()
Definition: CPUTimer.cc:74
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
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)
MonitorElement * bookInt(Args &&...args)
Definition: DQMStore.h:103
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
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 setup(const edm::ParameterSet &ps, DQMStore::IBooker &ib)
void Fill(long long x)
LuminosityBlockNumber_t luminosityBlock() const
tuple report
Definition: zeeHLT_cff.py:9
MonitorElement * meQuality_
edm::InputTag inputLabelRecHitZDC_
int debug_
Verbosity switch used for debugging or informational output.
void processEvent(const ZDCDigiCollection &digi, const ZDCRecHitCollection &rechit, const HcalUnpackerReport &report)
MonitorElement * meIEVTRAW_
void endRun(const edm::Run &run, const edm::EventSetup &c)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
MonitorElement * meZDC_
double f[11][100]
struct ZDCMonitorModule::@278 psTime_
HcalZDCMonitor * zdcMon_
Times stop()
Definition: CPUTimer.cc:94
bool isValid() const
Definition: HandleBase.h:75
std::string rootFolder_
edm::EDGetTokenT< ZDCDigiCollection > tok_zdc_
void endLuminosityBlock(void)
const edm::ParameterSet & ps_
units of &quot;updates&quot;, TBD
double cpuTime() const
Definition: CPUTimer.cc:158
void beginLuminosityBlock(int lb)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
const T & get() const
Definition: EventSetup.h:55
unsigned int ilumisec
MonitorElement * meIEVTDIGI_
edm::EventID id() const
Definition: EventBase.h:60
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
MonitorElement * meStatus_
void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
edm::RunNumber_t irun_
tuple cout
Definition: gather_cfg.py:121
edm::EventNumber_t ievent_
MonitorElement * meLatency_
TimeValue_t value() const
Definition: Timestamp.h:56
edm::Timestamp time() const
Definition: EventBase.h:61
MonitorElement * meFEDS_
Definition: Run.h:41
bool prescale()
Boolean prescale test for this event.