CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalBaseDQMonitor.cc
Go to the documentation of this file.
12 
13 #include <iostream>
14 #include <vector>
15 
16 /*
17  * \file HcalBaseDQMonitor.cc
18  *
19  * \author J Temple
20  *
21  * Base class for all Hcal DQM analyzers
22  *
23 
24 */
25 
26 // constructor
27 
29 {
30  Online_ = ps.getUntrackedParameter<bool>("online",false);
31  mergeRuns_ = ps.getUntrackedParameter<bool>("mergeRuns",false);
32  enableCleanup_ = ps.getUntrackedParameter<bool>("enableCleanup",false);
33  debug_ = ps.getUntrackedParameter<int>("debug",0);
34  prefixME_ = ps.getUntrackedParameter<std::string>("subSystemFolder","Hcal/");
35  if (prefixME_.substr(prefixME_.size()-1,prefixME_.size())!="/")
36  prefixME_.append("/");
37  subdir_ = ps.getUntrackedParameter<std::string>("TaskFolder","Test/");
38  if (subdir_.size()>0 && subdir_.substr(subdir_.size()-1,subdir_.size())!="/")
39  subdir_.append("/");
40  subdir_=prefixME_+subdir_;
41  AllowedCalibTypes_ = ps.getUntrackedParameter<std::vector<int> > ("AllowedCalibTypes");
42  skipOutOfOrderLS_ = ps.getUntrackedParameter<bool>("skipOutOfOrderLS",false);
43  NLumiBlocks_ = ps.getUntrackedParameter<int>("NLumiBlocks",4000);
44  makeDiagnostics_ = ps.getUntrackedParameter<bool>("makeDiagnostics",false);
45 
46 
47  FEDRawDataCollection_ = ps.getUntrackedParameter<edm::InputTag>("FEDRawDataCollection");
48  tok_braw_ = consumes<FEDRawDataCollection>(FEDRawDataCollection_);
49 
50  setupDone_ = false;
51  logicalMap_= 0;
52  needLogicalMap_=false;
53  meIevt_=0;
54  meLevt_=0;
55  meTevtHist_=0;
56  ProblemsVsLB=0;
63 
64  eMap_ = 0;
65 
66  ievt_=0;
67  levt_=0;
68  tevt_=0;
69  currenttype_=-1;
70  HBpresent_=false;
71  HEpresent_=false;
72  HOpresent_=false;
73  HFpresent_=false;
74 
75 
76 } //HcalBaseDQMonitor::HcalBaseDQMonitor(const ParameterSet& ps)
77 
78 
79 
80 
81 // destructor
82 
84 {
85  if (logicalMap_) delete logicalMap_;
86 }
87 
88 
89 //dqmBeginRun
91 {
92 
93  if (eMap_==0) //eMap_ not created yet
94  {
95  if (debug_>1) std::cout <<"\t<HcalBaseDQMonitor::dqmBeginRun> Getting Emap!"<<std::endl;
97  es.get<HcalDbRecord>().get( pSetup );
98  eMap_=pSetup->getHcalMapping();
99  }
100  if (mergeRuns_) return;
101  if( setupDone_ ) this->reset();
102 
103 }
104 
105 
106 
108 {
109  if (debug_>0) std::cout <<"HcalBaseDQMonitor::bookHistograms(): task = '"<<subdir_<<"'"<<std::endl;
110  if (! mergeRuns_)
111  {
112  this->setup(ib);
113  this->reset();
114  }
115  else if (tevt_ == 0)
116  {
117  this->setup(ib);
118  this->reset();
119  }
120 } // beginRun(const edm::Run& run, const edm::EventSetup& c)
121 
123 {
124  if (debug_>0) std::cout <<"HcalBaseDQMonitor::endRun: task = "<<subdir_<<std::endl;
125 } //endRun(...)
126 
128 {
129  if (debug_>0) std::cout <<"HcalBaseDQMonitor::reset(): task = "<<subdir_<<std::endl;
130  if (meIevt_) meIevt_->Fill(-1);
131  ievt_=0;
132  if (meLevt_) meLevt_->Fill(-1);
133  levt_=0;
134  if (meTevt_) meTevt_->Fill(-1);
135  tevt_=0;
136  if (meTevtHist_) meTevtHist_->Reset();
138  HBpresent_=false;
139  HEpresent_=false;
140  HOpresent_=false;
141  HFpresent_=false;
142  currentLS=0;
143  currenttype_=-1;
144 } //reset()
145 
147 {
148 
149 } //cleanup()
150 
152 {
153  if (setupDone_)
154  return;
155  setupDone_ = true;
156  if (debug_>3) std::cout <<"<HcalBaseDQMonitor> setup in progress"<<std::endl;
158  meIevt_ = ib.bookInt("EventsProcessed");
159  if (meIevt_) meIevt_->Fill(-1);
160  meLevt_ = ib.bookInt("EventsProcessed_currentLS");
161  if (meLevt_) meLevt_->Fill(-1);
162  meTevt_ = ib.bookInt("EventsProcessed_Total");
163  if (meTevt_) meTevt_->Fill(-1);
164  meTevtHist_=ib.book1D("Events_Processed_Task_Histogram","Counter of Events Processed By This Task",1,0.5,1.5);
165  if (meTevtHist_) meTevtHist_->Reset();
166  ib.setCurrentFolder(subdir_+"LSvalues");
167  ProblemsCurrentLB=ib.book2D("ProblemsThisLS","Problem Channels in current Lumi Section",
168  7,0,7,1,0,1);
169  if (ProblemsCurrentLB)
170  {
171  (ProblemsCurrentLB->getTH2F())->GetXaxis()->SetBinLabel(1,"HB");
172  (ProblemsCurrentLB->getTH2F())->GetXaxis()->SetBinLabel(2,"HE");
173  (ProblemsCurrentLB->getTH2F())->GetXaxis()->SetBinLabel(3,"HO");
174  (ProblemsCurrentLB->getTH2F())->GetXaxis()->SetBinLabel(4,"HF");
175  (ProblemsCurrentLB->getTH2F())->GetXaxis()->SetBinLabel(5,"HO0");
176  (ProblemsCurrentLB->getTH2F())->GetXaxis()->SetBinLabel(6,"HO12");
177  (ProblemsCurrentLB->getTH2F())->GetXaxis()->SetBinLabel(7,"HFlumi");
178  (ProblemsCurrentLB->getTH2F())->GetYaxis()->SetBinLabel(1,"Status");
180  }
181 } // setup()
182 
183 
185  const edm::EventSetup& c)
186 {
187  if (this->LumiInOrder(lumiSeg.luminosityBlock())==false) return;
188  currentLS=lumiSeg.luminosityBlock();
189  levt_=0;
190  if (meLevt_!=0) meLevt_->Fill(-1);
191  if (ProblemsCurrentLB)
193 }
194 
196  const edm::EventSetup& c)
197 {
198  if (this->LumiInOrder(lumiSeg.luminosityBlock())==false) return;
199  // Inherited classes do end-of-lumi functions here
200 }
201 
202 
204 {
205  if (skipOutOfOrderLS_==false) return true; // don't skip out-of-order lumi sections
206  // check that latest lumi section is >= last processed
207  if (Online_ && lumisec<currentLS)
208  return false;
209  return true;
210 }
211 
213 {
214  if (debug_>9) std::cout <<"<HcalBaseDQMonitor::IsAllowedCalibType>"<<std::endl;
215  if (AllowedCalibTypes_.size()==0)
216  {
217  if (debug_>9) std::cout <<"\tNo calib types specified by user; All events allowed"<<std::endl;
218  return true;
219  }
220 
221  if (debug_>9) std::cout <<"\tHcalBaseDQMonitor::IsAllowedCalibType checking if calibration type = "<<currenttype_<<" is allowed...";
223  {
224  if (AllowedCalibTypes_[i]==currenttype_)
225  {
226  if (debug_>9) std::cout <<"\t Type allowed!"<<std::endl;
227  return true;
228  }
229  }
230  if (debug_>9) std::cout <<"\t Type not allowed!"<<std::endl;
231  return false;
232 
233 } // bool HcalBaseDQMonitor::IsAllowedCalibType()
234 
236  if (needLogicalMap_ && logicalMap_==0) {
238  c.get<IdealGeometryRecord>().get(pT);
240  logicalMap_=new HcalLogicalMap(gen.createMap(&(*pT)));
241  }
242 }
243 
245 {
246  getLogicalMap(c);
247 
248  if (debug_>5) std::cout <<"\t<HcalBaseDQMonitor::analyze> event = "<<ievt_<<std::endl;
249  eventAllowed_=true; // assume event is allowed
250 
251 
252  // Try to get raw data
254  if (!(e.getByToken(tok_braw_,rawraw)))
255  {
256  edm::LogWarning("HcalMonitorModule")<<" raw data with label "<<FEDRawDataCollection_ <<" not available";
257  return;
258  }
259 
260  // fill with total events seen (this differs from ievent, which is total # of good events)
261  ++tevt_;
262  if (meTevt_) meTevt_->Fill(tevt_);
263  if (meTevtHist_) meTevtHist_->Fill(1);
264  // skip out of order lumi events
265  if (this->LumiInOrder(e.luminosityBlock())==false)
266  {
267  eventAllowed_=false;
268  return;
269  }
270 
271  this->CheckCalibType(rawraw);
272  // skip events of wrong calibration type
274  if (!eventAllowed_) return;
275 
276  // Event is good; count it
277  ++ievt_;
278  ++levt_;
279  if (meIevt_) meIevt_->Fill(ievt_);
280  if (meLevt_) meLevt_->Fill(levt_);
281 
282 
283  if (HBpresent_==false)
284  {
286  }
287  if (HEpresent_==false)
288  {
290  }
291  if (HOpresent_==false)
292  {
294  }
295  if (HFpresent_==false)
296  {
298  }
299 
300 
301 } // void HcalBaseDQMonitor::analyze(const edm::Event& e, const edm::EventSetup& c)
302 
303 //
304 // CheckSubdetectorStatus
306 {
307 
308  std::vector<int> fedUnpackList;
309  for (int i=FEDNumbering::MINHCALFEDID;
311  i++)
312  {
314  continue;
315  fedUnpackList.push_back(i);
316  }
317 
318  if (debug_>1) std::cout <<"<HcalMonitorModule::CheckSubdetectorStatus> Checking subdetector "<<subdet<<std::endl;
319  for (std::vector<int>::const_iterator i=fedUnpackList.begin();
320  i!=fedUnpackList.end();
321  ++i)
322  {
323  if (debug_>2) std::cout <<"\t<HcalMonitorModule::CheckSubdetectorStatus> FED = "<<*i<<std::endl;
324  const FEDRawData& fed =(*rawraw).FEDData(*i);
325  if (fed.size()<12) continue; // Was 16. How do such tiny events even get here?
326 
327  // get the DCC header
328  const HcalDCCHeader* dccHeader=(const HcalDCCHeader*)(fed.data());
329  if (!dccHeader) return;
330  int dccid=dccHeader->getSourceId();
331  // check for HF
332  if (subdet == HcalForward && ((dccid>=1118 && dccid<=1122) ||
333  (dccid>=718 && dccid<=723)))
334  {
335  HFpresent_=true;
336  return;
337  }
338  else if (subdet==HcalOuter && dccid>723)
339  {
340  HOpresent_=true;
341  return;
342  }
343  else if (dccid<718 && (subdet==HcalBarrel || subdet==HcalEndcap))
344  {
345  HcalHTRData htr;
346  for (int spigot=0; spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
347  {
348  if (!dccHeader->getSpigotPresent(spigot)) continue;
349 
350  // Load the given decoder with the pointer and length from this spigot.
351  dccHeader->getSpigotData(spigot,htr, fed.size());
352 
353  // check min length, correct wordcount, empty event, or total length if histo event.
354  if (!htr.check()) continue;
355  if (htr.isHistogramEvent()) continue;
356 
357  int firstFED = FEDNumbering::MINHCALFEDID;
358 
359  // Tease out HB and HE, which share HTRs in HBHE
360  for(int fchan=0; fchan<3; ++fchan) //0,1,2 are valid
361  {
362  for(int fib=1; fib<9; ++fib) //1...8 are valid
363  {
364  HcalElectronicsId eid(fchan,fib,spigot,dccid-firstFED);
365  eid.setHTR(htr.readoutVMECrateId(),
366  htr.htrSlot(),htr.htrTopBottom());
367 
368  DetId did=emap.lookup(eid);
369  if (!did.null())
370  {
371 
372  if ((HcalSubdetector)did.subdetId()==subdet)
373  {
374  if (subdet==HcalBarrel)
375  {
376  HBpresent_=true;
377  return;
378  }
379  else if (subdet==HcalEndcap)
380  {
381  HEpresent_=true;
382  return;
383  }
384  } // if ((HcalSubdetector)did.subdetId()==subdet)
385  } // if (!did.null())
386  } // for (int fib=1;fib<9;...)
387  } // for (int fchan=0; fchan<3;...)
388  } // for (int spigot=0;spigot<HcalDCCHeader::SPIGOT_COUNT; spigot++)
389  } //else if (dcc<718 && (subdet...))
390  } // loop over fedUnpackList
391 
392 
393 } // void CheckSubdetectorStatus
394 
395 
396 // Check Calib type
398 {
399  // Get Event Calibration Type -- copy of Bryan Dahmes' filter
400  int calibType=-1;
401  int numEmptyFEDs = 0 ;
402  std::vector<int> calibTypeCounter(8,0) ;
403  for( int i = FEDNumbering::MINHCALFEDID;
405  {
407  continue;
408 
409  const FEDRawData& fedData = rawraw->FEDData(i) ;
410 
411  if ( fedData.size() < 24 ) numEmptyFEDs++ ;
412  if ( fedData.size() < 24 ) continue;
413 
414  int value = (int)((const HcalDCCHeader*)(fedData.data()))->getCalibType() ;
415  if(value>7)
416  {
417  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Unexpected Calibration type: "<< value << " in FED: "<<i<<" (should be 0-7). I am bailing out...";
418  return;
419  }
420 
421  calibTypeCounter.at(value)++ ; // increment the counter for this calib type
422  } // for (int i = FEDNumbering::MINHCALFEDID; ...)
423 
424  int maxCount = 0;
425  int numberOfFEDIds = (FEDNumbering::MAXHCALFEDID-FEDNumbering::MINHCALFEDID+1) +
427  for (unsigned int i=0; i<calibTypeCounter.size(); i++) {
428  if ( calibTypeCounter.at(i) > maxCount )
429  { calibType = i ; maxCount = calibTypeCounter.at(i) ; }
430  if ( maxCount == numberOfFEDIds ) break ;
431  }
432 
433  if ( maxCount != (numberOfFEDIds-numEmptyFEDs) )
434  edm::LogWarning("HcalMonitorModule::CalibTypeFilter") << "Conflicting calibration types found. Assigning type "
435  << calibType ;
436  LogDebug("HcalMonitorModule::CalibTypeFilter") << "Calibration type is: " << calibType ;
437  // Fill histogram of calibration types, as well as integer to keep track of current value
439  //if (meCalibType_) meCalibType_->Fill(calibType);
440  //if (meCurrentCalibType_) meCurrentCalibType_->Fill(calibType);
442 
443  if (debug_>2) std::cout <<"\t<HcalMonitorModule> ievt = "<<ievt_<<" calibration type = "<<calibType<<std::endl;
444 
445 } // check calib type
446 
#define LogDebug(id)
virtual void endLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
virtual void dqmBeginRun(const edm::Run &run, const edm::EventSetup &c)
bool LumiInOrder(int lumisec)
MonitorElement * ProblemsCurrentLB
int ib
Definition: cuy.py:660
bool check() const
Check for a good event Requires a minimum length, matching wordcount and length, not an empty event...
Definition: HcalHTRData.cc:62
edm::EDGetTokenT< FEDRawDataCollection > tok_braw_
virtual void analyze(const edm::Event &e, const edm::EventSetup &c)
void CheckCalibType(const edm::Handle< FEDRawDataCollection > &)
unsigned int htrTopBottom() const
HcalElectronicsId-style HTR top/bottom (1=top/0=bottom)
Definition: HcalHTRData.cc:342
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
MonitorElement * ProblemsVsLB_HF
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
std::vector< int > AllowedCalibTypes_
tuple calibType
Definition: diJetCalib.py:20
virtual void cleanup(void)
virtual void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &)
MonitorElement * bookInt(Args &&...args)
Definition: DQMStore.h:103
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
void getLogicalMap(const edm::EventSetup &c)
MonitorElement * meTevt_
int getSpigotData(int nspigot, HcalHTRData &decodeTool, int validSize) const
uint16_t size_type
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
void Fill(long long x)
const HcalElectronicsMap * eMap_
LuminosityBlockNumber_t luminosityBlock() const
unsigned int htrSlot() const
HcalElectronicsId-style HTR slot.
Definition: HcalHTRData.cc:338
MonitorElement * meTevtHist_
MonitorElement * ProblemsVsLB_HBHEHF
virtual ~HcalBaseDQMonitor()
MonitorElement * ProblemsVsLB_HB
HcalLogicalMap * logicalMap_
edm::InputTag FEDRawDataCollection_
virtual void beginLuminosityBlock(const edm::LuminosityBlock &lumiSeg, const edm::EventSetup &c)
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:115
HcalSubdetector
Definition: HcalAssistant.h:31
MonitorElement * meIevt_
bool getSpigotPresent(unsigned int nspigot) const
Read the &quot;PRESENT&quot; bit for this spigot.
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
HcalLogicalMap createMap(const HcalTopology *topo, unsigned int mapIOV=4)
int getSourceId() const
Definition: HcalDCCHeader.h:32
Definition: DetId.h:18
void setHTR(int crate, int slot, int tb)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:274
void CheckSubdetectorStatus(const edm::Handle< FEDRawDataCollection > &, HcalSubdetector, const HcalElectronicsMap &)
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:133
const T & get() const
Definition: EventSetup.h:55
bool null() const
is this a null id ?
Definition: DetId.h:45
virtual void reset(void)
MonitorElement * ProblemsVsLB_HE
virtual void endRun(const edm::Run &run, const edm::EventSetup &c)
unsigned int readoutVMECrateId() const
HcalElectronicsId-style VME crate number.
Definition: HcalHTRData.cc:346
static const int SPIGOT_COUNT
Definition: HcalDCCHeader.h:19
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
tuple cout
Definition: gather_cfg.py:121
MonitorElement * ProblemsVsLB_HO
MonitorElement * ProblemsVsLB
TH2F * getTH2F(void) const
void Reset(void)
reset ME (ie. contents, errors, etc)
virtual void setup(DQMStore::IBooker &)
Readout chain identification for Hcal.
MonitorElement * meLevt_
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
bool isHistogramEvent() const
Is this event a histogram event? (do not call standard unpack in this case!!!!!)
Definition: HcalHTRData.cc:385
Definition: Run.h:41