CMS 3D CMS Logo

MESet.cc
Go to the documentation of this file.
2 
6 
9 
10 #include "TString.h"
11 #include "TPRegexp.h"
12 
13 namespace ecaldqm
14 {
16  mes_(0),
17  path_(""),
18  otype_(binning::nObjType),
19  btype_(binning::nBinType),
20  kind_(MonitorElement::DQM_KIND_INVALID),
21  lumiFlag_(false),
22  batchMode_(false),
23  active_(false)
24  {
25  }
26 
28  mes_(0),
29  path_(_path),
30  otype_(_otype),
31  btype_(_btype),
32  kind_(_kind),
35  active_(false)
36  {
37  if(path_.empty() || path_.find("/") == std::string::npos ||
38  (otype_ != binning::kChannel && path_.find("/") == path_.size() - 1))
39  throw_(_path + " cannot be used for ME path name");
40 
41  switch(kind_){
47  break;
48  default:
49  throw_("Unsupported MonitorElement kind");
50  }
51  }
52 
53  MESet::MESet(MESet const& _orig) :
54  mes_(_orig.mes_),
55  path_(_orig.path_),
56  otype_(_orig.otype_),
57  btype_(_orig.btype_),
58  kind_(_orig.kind_),
59  lumiFlag_(_orig.lumiFlag_),
60  batchMode_(_orig.batchMode_),
61  active_(_orig.active_)
62  {
63  }
64 
66  {
67  }
68 
69  MESet&
70  MESet::operator=(MESet const& _rhs)
71  {
72  mes_ = _rhs.mes_;
73  path_ = _rhs.path_;
74  otype_ = _rhs.otype_;
75  btype_ = _rhs.btype_;
76  kind_ = _rhs.kind_;
77  active_ = _rhs.active_;
78 
79  return *this;
80  }
81 
82  MESet*
83  MESet::clone(std::string const& _path/* = ""*/) const
84  {
86  if(_path != "") path_ = _path;
87  MESet* copy(new MESet(*this));
88  path_ = path;
89  return copy;
90  }
91 
92  void
93  MESet::clear() const
94  {
95  active_ = false;
96  mes_.clear();
97  }
98 
99  void
100  MESet::setAxisTitle(std::string const& _title, int _axis/* = 1*/)
101  {
102  if(!active_) return;
103 
104  unsigned nME(mes_.size());
105  for(unsigned iME(0); iME < nME; iME++)
106  mes_[iME]->setAxisTitle(_title, _axis);
107  }
108 
109  void
110  MESet::reset(double _content/* = 0.*/, double _err/* = 0.*/, double _entries/* = 0.*/)
111  {
112  if(!active_) return;
113 
114  resetAll(_content, _err, _entries);
115  }
116 
117  void
118  MESet::resetAll(double _content/* = 0.*/, double _err/* = 0.*/, double _entries/* = 0.*/)
119  {
120  if(!active_) return;
121 
122  unsigned nME(mes_.size());
123 
125  for(unsigned iME(0); iME < nME; iME++)
126  mes_[iME]->Fill(_content);
127  return;
128  }
129 
130  bool simple(true);
131  if(_content != 0. || _err != 0. || _entries != 0.) simple = false;
132 
133  for(unsigned iME(0); iME < nME; iME++){
134  TH1* h(mes_[iME]->getTH1());
135  h->Reset();
136  if(simple) continue;
137 
138  int nbinsX(h->GetNbinsX());
139  int nbinsY(h->GetNbinsY());
140  double entries(0.);
141  for(int ix(1); ix <= nbinsX; ix++){
142  for(int iy(1); iy <= nbinsY; iy++){
143  int bin(h->GetBin(ix, iy));
144  h->SetBinContent(bin, _content);
145  h->SetBinError(bin, _err);
147  static_cast<TProfile*>(h)->SetBinEntries(bin, _entries);
148  entries += _entries;
149  }
151  static_cast<TProfile2D*>(h)->SetBinEntries(bin, _entries);
152  entries += _entries;
153  }
154  }
155  }
156  if(entries == 0.) entries = _entries;
157  h->SetEntries(_entries);
158  }
159  }
160 
161 
163  MESet::formPath(std::map<std::string, std::string> const& _replacements) const
164  {
165  TString path(path_);
166 
167  for(typename MESet::PathReplacements::const_iterator repItr(_replacements.begin()); repItr != _replacements.end(); ++repItr){
168  TString pattern("\\%\\(");
169  pattern += repItr->first;
170  pattern += "\\)s";
171 
172  TPRegexp re(pattern);
173 
174  re.Substitute(path, repItr->second, "g");
175  }
176 
177  return path.Data();
178  }
179 
180  bool
181  MESet::maskMatches(DetId const& _id, uint32_t _mask, StatusManager const* _statusManager) const
182  {
183  if(!_statusManager) return false;
184 
185  if((_statusManager->getStatus(_id.rawId()) & _mask) != 0) return true;
186 
187  int subdet(_id.subdetId());
188 
189  bool searchNeighborsInTower(btype_ == binning::kTriggerTower || btype_ == binning::kSuperCrystal);
190 
191  // turn off masking for good channel for the time being
192  // update the RenderPlugin then enable again
193 
194  switch(subdet){
195  case EcalBarrel: // this is a DetId for single crystal in barrel
196  {
197  EBDetId ebId(_id);
198  EcalTrigTowerDetId ttId(ebId.tower());
199  if((_statusManager->getStatus(ttId.rawId()) & _mask) != 0) return true;
200 
201  if(searchNeighborsInTower){
202  std::vector<DetId> ids(getTrigTowerMap()->constituentsOf(ttId));
203  for(std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr)
204  if((_statusManager->getStatus(idItr->rawId()) & _mask) != 0) return true;
205  }
206  }
207  break;
208 
209  case EcalEndcap:
210  if(isEcalScDetId(_id)){
211  EcalScDetId scId(_id);
212  for(int ix(1); ix <= 5; ix++){
213  for(int iy(1); iy <= 5; iy++){
214  int iix((scId.ix() - 1) * 5 + ix);
215  int iiy((scId.iy() - 1) * 5 + iy);
216  if(!EEDetId::validDetId(iix, iiy, scId.zside())) continue;
217  if((_statusManager->getStatus(EEDetId(iix, iiy, scId.zside()).rawId()) & _mask) != 0) return true;
218  }
219  }
220  }
221  else{
222  EEDetId eeId(_id);
223  EcalScDetId scId(eeId.sc());
224  if((_statusManager->getStatus(scId.rawId()) & _mask) != 0) return true;
225 
226  if(searchNeighborsInTower){
227  for(int ix(1); ix <= 5; ix++){
228  for(int iy(1); iy <= 5; iy++){
229  int iix((scId.ix() - 1) * 5 + ix);
230  int iiy((scId.iy() - 1) * 5 + iy);
231  if(!EEDetId::validDetId(iix, iiy, scId.zside())) continue;
232  if((_statusManager->getStatus(EEDetId(iix, iiy, scId.zside()).rawId()) & _mask) != 0) return true;
233  }
234  }
235  }
236  }
237  break;
238 
239  case EcalTriggerTower:
240  {
242  std::vector<DetId> ids(getTrigTowerMap()->constituentsOf(ttId));
243  for(std::vector<DetId>::iterator idItr(ids.begin()); idItr != ids.end(); ++idItr)
244  if((_statusManager->getStatus(idItr->rawId()) & _mask) != 0) return true;
245  }
246  break;
247 
248  default:
249  break;
250  }
251 
252  return false;
253  }
254 
255  void
257  {
258  if(!active_) return;
259 
260  DQMStore& store(*edm::Service<DQMStore>());
261 
262  for(unsigned iME(0); iME < mes_.size(); ++iME)
263  store.softReset(mes_[iME]);
264  }
265 
266  void
268  {
269  if(!active_) return;
270 
271  DQMStore& store(*edm::Service<DQMStore>());
272 
273  for(unsigned iME(0); iME < mes_.size(); ++iME)
274  store.disableSoftReset(mes_[iME]);
275  }
276 
277  void
278  MESet::fill_(unsigned _iME, int _bin, double _w)
279  {
280  if(kind_ == MonitorElement::DQM_KIND_REAL) return;
281 
282  MonitorElement* me(mes_[_iME]);
283  if(!me) return;
284 
285  TH1* h(me->getTH1());
286 
287  int nbinsX(h->GetNbinsX());
288 
289  double x(h->GetXaxis()->GetBinCenter(_bin % (nbinsX + 2)));
290 
292  me->Fill(x, _w);
293  else{
294  double y(h->GetYaxis()->GetBinCenter(_bin / (nbinsX + 2)));
295  me->Fill(x, y, _w);
296  }
297  }
298 
299  void
300  MESet::fill_(unsigned _iME, int _bin, double _y, double _w)
301  {
303 
304  MonitorElement* me(mes_[_iME]);
305  if(!me) return;
306 
307  TH1* h(me->getTH1());
308 
309  int nbinsX(h->GetNbinsX());
310 
311  double x(h->GetXaxis()->GetBinCenter(_bin % (nbinsX + 2)));
312  me->Fill(x, _y, _w);
313  }
314 
315  void
316  MESet::fill_(unsigned _iME, double _x, double _wy, double _w)
317  {
318  MonitorElement* me(mes_[_iME]);
319  if(!me) return;
320 
322  me->Fill(_x);
324  me->Fill(_x, _wy);
325  else
326  me->Fill(_x, _wy, _w);
327  }
328 
329 
330 
331  MESet::ConstBin::ConstBin(MESet const& _meSet, unsigned _iME/* = 0*/, int _iBin/* = 1*/) :
332  meSet_(&_meSet),
333  iME(_iME),
334  iBin(_iBin),
335  otype(binning::nObjType)
336  {
337  if(iME == unsigned(-1)) return;
338 
339  // current internal bin numbering scheme does not allow 1D histograms (overflow & underflow in each y)
341  // if(kind != MonitorElement::DQM_KIND_TH1F && kind != MonitorElement::DQM_KIND_TPROFILE &&
343  throw cms::Exception("InvalidOperation") << "MESet::ConstBin::Ctor: const_iterator only available for MESet of 2D histograms";
344 
345  MonitorElement const* me(meSet_->getME(iME));
346 
347  if(!me)
348  throw cms::Exception("InvalidOperation") << "MESet::ConstBin::Ctor: ME " << iME << " does not exist for MESet " << meSet_->getPath();
349 
351  iBin = me->getNbinsX() + 3;
352 
354  }
355 
358  {
359  if(meSet_->getObjType() != _rhs.meSet_->getObjType() ||
360  meSet_->getBinType() != _rhs.meSet_->getBinType())
361  throw cms::Exception("IncompatibleAssignment")
362  << "Iterator of otype " << _rhs.meSet_->getObjType() << " and btype " << _rhs.meSet_->getBinType()
363  << " to otype " << meSet_->getObjType() << " and btype " << meSet_->getBinType()
364  << " (" << _rhs.meSet_->getPath() << " to " << meSet_->getPath() << ")";
365 
366  iME = _rhs.iME;
367  iBin = _rhs.iBin;
368  otype = _rhs.otype;
369 
370  return *this;
371  }
372 
373 
374 
376  bin_()
377  {
378  binning::ObjectType otype(_meSet.getObjType());
379  unsigned iME(binning::findPlotIndex(otype, _id));
380  if(iME == unsigned(-1)) return;
381 
382  binning::BinningType btype(_meSet.getBinType());
383  int bin(binning::findBin2D(otype, btype, _id));
384  if(bin == 0) return;
385 
386  bin_.setMESet(_meSet);
387  bin_.iME = iME;
388  bin_.iBin = bin;
389  bin_.otype = otype;
390  }
391 
394  {
395  unsigned& iME(bin_.iME);
396  MESet const* meSet(bin_.getMESet());
397 
398  if(iME == unsigned(-1)) return *this;
399 
400  int& bin(bin_.iBin);
402 
403  MonitorElement::Kind kind(meSet->getKind());
404  MonitorElement const* me(meSet->getME(iME));
405 
406  int nbinsX(me->getNbinsX());
407 
408  ++bin;
409  if(bin == 1){
410  iME = 0;
411  me = meSet->getME(iME);
412  nbinsX = me->getNbinsX();
414  bin = nbinsX + 3;
415  otype = binning::getObject(meSet->getObjType(), iME);
416  }
417 
418  if(bin % (nbinsX + 2) == nbinsX + 1){
420  bin / (nbinsX + 2) == me->getNbinsY()){
421  iME += 1;
422  me = meSet->getME(iME);
423  if(!me){
424  iME = unsigned(-1);
425  bin = -1;
426  otype = binning::nObjType;
427  }
428  else{
429  nbinsX = me->getNbinsX();
431  bin = nbinsX + 3;
432  else
433  bin = 1;
434 
435  otype = binning::getObject(meSet->getObjType(), iME);
436  }
437  }
438  else
439  bin += 2;
440  }
441 
442  return *this;
443  }
444 
447  {
448  if(!bin_.getMESet()) return *this;
449  do operator++();
450  while(bin_.iME != unsigned(-1) && !bin_.isChannel());
451 
452  return *this;
453  }
454 
455  bool
457  {
458  MESet const* meSet(bin_.getMESet());
459  if(bin_.iME == unsigned(-1) || bin_.iBin < 1) return false;
460 
461  MonitorElement::Kind kind(meSet->getKind());
463 
464  MonitorElement const* me(meSet->getME(bin_.iME));
465 
466  if(bin_.iBin / (me->getNbinsX() + 2) >= me->getNbinsY()) return false;
467 
468  bin_.iBin += me->getNbinsX() + 2;
469 
470  return true;
471  }
472 
473  bool
475  {
476  MESet const* meSet(bin_.getMESet());
477  if(bin_.iME == unsigned(-1) || bin_.iBin < 1) return false;
478 
479  MonitorElement::Kind kind(meSet->getKind());
481 
482  MonitorElement const* me(meSet->getME(bin_.iME));
483 
484  if(bin_.iBin / (me->getNbinsX() + 2) <= 1) return false;
485 
486  bin_.iBin -= me->getNbinsX() + 2;
487 
488  return true;
489  }
490 
491  bool
493  {
494  MESet const* meSet(bin_.getMESet());
495  if(bin_.iME == unsigned(-1) || bin_.iBin < 1) return false;
496 
497  MonitorElement::Kind kind(meSet->getKind());
499 
500  MonitorElement const* me(meSet->getME(bin_.iME));
501 
502  if(bin_.iBin % (me->getNbinsX() + 2) <= 1) return false;
503 
504  bin_.iBin -= 1;
505 
506  return true;
507  }
508 
509  bool
511  {
512  MESet const* meSet(bin_.getMESet());
513  if(bin_.iME == unsigned(-1) || bin_.iBin < 1) return false;
514 
515  MonitorElement::Kind kind(meSet->getKind());
517 
518  MonitorElement const* me(meSet->getME(bin_.iME));
519 
520  if(bin_.iBin % (me->getNbinsX() + 2) >= me->getNbinsX()) return false;
521 
522  bin_.iBin += 1;
523 
524  return true;
525  }
526 }
527 
528 namespace boost
529 {
530  template<> inline ecaldqm::MESet* new_clone<ecaldqm::MESet>(ecaldqm::MESet const& _s){ return _s.clone(); }
531  template<> void delete_clone<ecaldqm::MESet>(ecaldqm::MESet const* _s){ checked_delete(_s); }
532 }
virtual std::string const & getPath() const
Definition: MESet.h:92
MonitorElement::Kind kind_
Definition: MESet.h:134
virtual MonitorElement const * getME(unsigned _iME) const
Definition: MESet.h:98
MonitorElement::Kind getKind() const
Definition: MESet.h:95
virtual void setAxisTitle(std::string const &, int=1)
Definition: MESet.cc:100
const_iterator & operator++()
Definition: MESet.cc:393
Definition: CLHEP.h:16
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
def copy(args, dbName)
virtual void clear() const
Definition: MESet.cc:93
uint32_t getStatus(uint32_t) const
bool isChannel() const
Definition: MESet.h:159
MESet const * meSet_
Definition: MESet.h:144
binning::ObjectType otype
Definition: MESet.h:149
TH1 * getTH1() const
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:83
bool batchMode_
Definition: MESet.h:136
ObjectType getObject(ObjectType, unsigned)
virtual bool maskMatches(DetId const &, uint32_t, StatusManager const *) const
Definition: MESet.cc:181
unsigned ttId(DetId const &)
virtual ~MESet()
Definition: MESet.cc:65
void Fill(long long x)
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
void disableSoftReset(MonitorElement *me)
Definition: DQMStore.cc:3409
std::vector< MonitorElement * > mes_
Definition: MESet.h:129
binning::ObjectType getObjType() const
Definition: MESet.h:93
int ix() const
Definition: EcalScDetId.h:71
void throw_(std::string const &_message) const
Definition: MESet.h:124
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
EcalTrigTowerConstituentsMap const * getTrigTowerMap()
virtual void reset(double=0., double=0., double=0.)
Definition: MESet.cc:110
EcalTrigTowerDetId tower() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.h:59
void softReset(MonitorElement *me)
Definition: DQMStore.cc:3401
bool lumiFlag_
Definition: MESet.h:135
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
int iy() const
Definition: EcalScDetId.h:77
ConstBin & operator=(ConstBin const &)
Definition: MESet.cc:357
virtual void fill_(unsigned, int, double)
Definition: MESet.cc:278
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:163
bin
set the eta bin as selection string.
bool isEcalScDetId(DetId const &)
Definition: DetId.h:18
MESet const * getMESet() const
Definition: MESet.h:190
int findBin2D(ObjectType, BinningType, DetId const &)
virtual void softReset()
Definition: MESet.cc:256
unsigned findPlotIndex(ObjectType, DetId const &)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
std::string & path_
EcalScDetId sc() const
Definition: EEDetId.h:88
int zside() const
Definition: EcalScDetId.h:65
binning::BinningType getBinType() const
Definition: MESet.h:94
virtual void resetAll(double=0., double=0., double=0.)
Definition: MESet.cc:118
bool active_
Definition: MESet.h:138
virtual void recoverStats()
Definition: MESet.cc:267
void setMESet(MESet const &_meSet)
Definition: MESet.h:189
binning::ObjectType otype_
Definition: MESet.h:132
const_iterator & toNextChannel()
Definition: MESet.cc:446
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:70
binning::BinningType btype_
Definition: MESet.h:133
std::string path_
Definition: MESet.h:131