CMS 3D CMS Logo

MESet.h
Go to the documentation of this file.
1 #ifndef MESet_H
2 #define MESet_H
3 
5 
8 
11 
13 
14 #include <string>
15 #include <vector>
16 
17 #include "boost/ptr_container/ptr_map.hpp"
18 
19 namespace ecaldqm {
20  /*
21  class MESet
22  Base class for MonitorElement wrappers
23  Interface between ME bins and DetId
24 */
25 
26  class StatusManager;
27 
28  class MESet {
29  public:
30  typedef std::map<std::string, std::string> PathReplacements;
31 
32  MESet();
34  MESet(MESet const &);
35  virtual ~MESet();
36 
37  virtual MESet &operator=(MESet const &);
38 
39  virtual MESet *clone(std::string const & = "") const;
40 
41  virtual void book(DQMStore::IBooker &) {}
42  virtual bool retrieve(DQMStore::IGetter &, std::string * = nullptr) const { return false; }
43  virtual void clear() const;
44 
45  virtual void fill(DetId const &, double = 1., double = 1., double = 1.) {}
46  virtual void fill(EcalElectronicsId const &, double = 1., double = 1., double = 1.) {}
47  virtual void fill(int, double = 1., double = 1., double = 1.) {}
48  virtual void fill(double, double = 1., double = 1.) {}
49 
50  virtual void setBinContent(DetId const &, double) {}
51  virtual void setBinContent(EcalElectronicsId const &, double) {}
52  virtual void setBinContent(int, double) {}
53  virtual void setBinContent(DetId const &, int, double) {}
54  virtual void setBinContent(EcalElectronicsId const &, int, double) {}
55  virtual void setBinContent(int, int, double) {}
56 
57  virtual void setBinError(DetId const &, double) {}
58  virtual void setBinError(EcalElectronicsId const &, double) {}
59  virtual void setBinError(int, double) {}
60  virtual void setBinError(DetId const &, int, double) {}
61  virtual void setBinError(EcalElectronicsId const &, int, double) {}
62  virtual void setBinError(int, int, double) {}
63 
64  virtual void setBinEntries(DetId const &, double) {}
65  virtual void setBinEntries(EcalElectronicsId const &, double) {}
66  virtual void setBinEntries(int, double) {}
67  virtual void setBinEntries(DetId const &, int, double) {}
68  virtual void setBinEntries(EcalElectronicsId const &, int, double) {}
69  virtual void setBinEntries(int, int, double) {}
70 
71  virtual double getBinContent(DetId const &, int = 0) const { return 0.; }
72  virtual double getBinContent(EcalElectronicsId const &, int = 0) const { return 0.; }
73  virtual double getBinContent(int, int = 0) const { return 0.; }
74 
75  virtual double getBinError(DetId const &, int = 0) const { return 0.; }
76  virtual double getBinError(EcalElectronicsId const &, int = 0) const { return 0.; }
77  virtual double getBinError(int, int = 0) const { return 0.; }
78 
79  virtual double getBinEntries(DetId const &, int = 0) const { return 0.; }
80  virtual double getBinEntries(EcalElectronicsId const &, int = 0) const { return 0.; }
81  virtual double getBinEntries(int, int = 0) const { return 0.; }
82 
83  // title, axis
84  virtual void setAxisTitle(std::string const &, int = 1);
85 
86  virtual void reset(double = 0., double = 0., double = 0.);
87  virtual void resetAll(double = 0., double = 0., double = 0.);
88 
89  virtual bool maskMatches(DetId const &, uint32_t, StatusManager const *) const;
90 
91  virtual std::string const &getPath() const { return path_; }
94  MonitorElement::Kind getKind() const { return kind_; }
95  bool isActive() const { return active_; } // booked or retrieved
96  virtual bool isVariableBinning() const { return false; }
97  virtual MonitorElement const *getME(unsigned _iME) const { return (_iME < mes_.size() ? mes_[_iME] : nullptr); }
98  virtual MonitorElement *getME(unsigned _iME) { return (_iME < mes_.size() ? mes_[_iME] : nullptr); }
99  virtual void softReset();
100  virtual void recoverStats();
101 
102  std::string formPath(PathReplacements const &) const;
103 
104  void setLumiFlag() { lumiFlag_ = true; };
105  bool getLumiFlag() const { return lumiFlag_; }
106  void setBatchMode() { batchMode_ = true; }
107  bool getBatchMode() const { return batchMode_; }
108 
109  protected:
110  virtual void fill_(unsigned, int, double);
111  virtual void fill_(unsigned, int, double, double);
112  virtual void fill_(unsigned, double, double, double);
113 
114  virtual void checkME_(unsigned _iME) const {
115  if (!getME(_iME)) {
116  std::stringstream ss;
117  ss << "ME does not exist at index " << _iME;
118  throw_(ss.str());
119  }
120  }
121 
122  void throw_(std::string const &_message) const { throw cms::Exception("EcalDQM") << path_ << ": " << _message; }
123 
124  mutable std::vector<MonitorElement *> mes_;
125 
130  bool lumiFlag_; // when true, histograms will be saved every lumi section
131  // (default false)
132  bool batchMode_; // when true, histograms are not GUI-ready (default false)
133 
134  mutable bool active_;
135 
136  public:
137  struct ConstBin {
138  protected:
139  MESet const *meSet_;
140 
141  public:
142  unsigned iME;
143  int iBin;
145 
146  ConstBin() : meSet_(nullptr), iME(-1), iBin(-1), otype(binning::nObjType) {}
147  ConstBin(MESet const &, unsigned = 0, int = 1);
148  ConstBin(ConstBin const &_orig) : meSet_(_orig.meSet_), iME(_orig.iME), iBin(_orig.iBin), otype(_orig.otype) {}
149  ConstBin &operator=(ConstBin const &);
150  bool operator==(ConstBin const &_rhs) const {
151  return meSet_ != nullptr && meSet_ == _rhs.meSet_ && iME == _rhs.iME && iBin == _rhs.iBin;
152  }
153  bool isChannel() const {
154  if (meSet_)
155  return binning::isValidIdBin(otype, meSet_->getBinType(), iME, iBin);
156  else
157  return false;
158  }
159  uint32_t getId() const {
160  if (meSet_)
161  return binning::idFromBin(otype, meSet_->getBinType(), iME, iBin);
162  else
163  return 0;
164  }
165  double getBinContent() const {
166  if (meSet_ && iME != unsigned(-1))
167  return meSet_->getME(iME)->getBinContent(iBin);
168  else
169  return 0.;
170  }
171  double getBinError() const {
172  if (meSet_ && iME != unsigned(-1))
173  return meSet_->getME(iME)->getBinError(iBin);
174  else
175  return 0.;
176  }
177  double getBinEntries() const {
178  if (meSet_ && iME != unsigned(-1))
179  return meSet_->getME(iME)->getBinEntries(iBin);
180  else
181  return 0.;
182  }
183  MonitorElement const *getME() const {
184  if (meSet_ && iME != unsigned(-1))
185  return meSet_->getME(iME);
186  else
187  return nullptr;
188  }
189  void setMESet(MESet const &_meSet) { meSet_ = &_meSet; }
190  MESet const *getMESet() const { return meSet_; }
191  };
192 
193  struct Bin : public ConstBin {
194  protected:
196 
197  public:
198  Bin() : ConstBin(), meSet_(nullptr) {}
199  Bin(MESet &_set, unsigned _iME = 0, int _iBin = 1) : ConstBin(_set, _iME, _iBin), meSet_(&_set) {}
200  Bin(Bin const &_orig) : ConstBin(_orig), meSet_(_orig.meSet_) {}
201  ConstBin &operator=(Bin const &_rhs) {
202  bool wasNull(ConstBin::meSet_ == nullptr);
203  ConstBin::operator=(_rhs);
204  if (wasNull)
205  meSet_ = _rhs.meSet_;
206  return *this;
207  }
208  void fill(double _w = 1.) {
209  if (meSet_)
210  meSet_->fill_(iME, iBin, _w);
211  }
212  void fill(double _y, double _w = 1.) {
213  if (meSet_)
214  meSet_->fill_(iME, iBin, _y, _w);
215  }
216  void setBinContent(double _content) {
217  if (meSet_ && iME != unsigned(-1))
218  meSet_->getME(iME)->setBinContent(iBin, _content);
219  }
220  void setBinError(double _error) {
221  if (meSet_ && iME != unsigned(-1))
222  meSet_->getME(iME)->setBinError(iBin, _error);
223  }
224  void setBinEntries(double _entries) {
225  if (meSet_ && iME != unsigned(-1))
226  meSet_->getME(iME)->setBinEntries(iBin, _entries);
227  }
229  if (meSet_ && iME != unsigned(-1))
230  return meSet_->getME(iME);
231  else
232  return nullptr;
233  }
234  void setMESet(MESet &_meSet) {
235  ConstBin::meSet_ = &_meSet;
236  meSet_ = &_meSet;
237  }
238  MESet *getMESet() const { return meSet_; }
239  };
240 
241  /* const_iterator
242  iterates over bins
243  supports automatic transition between MEs in the same set
244  underflow -> bin == 0 overflow -> bin == -1
245  */
246  struct const_iterator {
247  const_iterator() : bin_() {}
248  const_iterator(MESet const &_meSet, unsigned _iME = 0, int _iBin = 1) : bin_(_meSet, _iME, _iBin) {}
249  const_iterator(MESet const &, DetId const &);
250  const_iterator(const_iterator const &_orig) : bin_(_orig.bin_) {}
252  bin_ = _rhs.bin_;
253  return *this;
254  }
255  bool operator==(const_iterator const &_rhs) const { return bin_ == _rhs.bin_; }
256  bool operator!=(const_iterator const &_rhs) const { return !(bin_ == _rhs.bin_); }
257  ConstBin const *operator->() const { return &bin_; }
258  const_iterator &operator++();
259  const_iterator &toNextChannel();
260  bool up();
261  bool down();
262  bool left();
263  bool right();
264 
265  protected:
267  };
268 
269  struct iterator : public const_iterator {
270  iterator() : const_iterator(), bin_() {}
271  iterator(MESet &_meSet, unsigned _iME = 0, int _iBin = 1) : const_iterator(_meSet, _iME, _iBin), bin_(_meSet) {
272  bin_.ConstBin::operator=(const_iterator::bin_);
273  }
274  iterator(MESet &_meSet, DetId const &_id) : const_iterator(_meSet, _id), bin_(_meSet) {
275  bin_.ConstBin::operator=(const_iterator::bin_);
276  }
277  iterator(iterator const &_orig) : const_iterator(_orig), bin_(_orig.bin_) {}
280  bin_.ConstBin::operator=(const_iterator::bin_);
281  return *this;
282  }
283  Bin *operator->() { return &bin_; }
284  Bin const *operator->() const { return &bin_; }
287  bin_.ConstBin::operator=(const_iterator::bin_);
288  return *this;
289  }
292  bin_.ConstBin::operator=(const_iterator::bin_);
293  return *this;
294  }
295  bool up() {
296  bool res(const_iterator::up());
297  bin_.ConstBin::operator=(const_iterator::bin_);
298  return res;
299  }
300  bool down() {
301  bool res(const_iterator::down());
302  bin_.ConstBin::operator=(const_iterator::bin_);
303  return res;
304  }
305  bool left() {
306  bool res(const_iterator::left());
307  bin_.ConstBin::operator=(const_iterator::bin_);
308  return res;
309  }
310  bool right() {
311  bool res(const_iterator::right());
312  bin_.ConstBin::operator=(const_iterator::bin_);
313  return res;
314  }
315 
316  private:
318  };
319 
320  virtual const_iterator begin() const { return const_iterator(*this); }
321 
322  virtual const_iterator end() const { return const_iterator(*this, -1, -1); }
323 
324  virtual const_iterator beginChannel() const {
325  const_iterator itr(*this, 0, 0);
326  return itr.toNextChannel();
327  }
328 
329  virtual iterator begin() { return iterator(*this); }
330 
331  virtual iterator end() { return iterator(*this, -1, -1); }
332 
333  virtual iterator beginChannel() {
334  iterator itr(*this, 0, 0);
335  itr.toNextChannel();
336  return itr;
337  }
338  };
339 
340 } // namespace ecaldqm
341 
342 namespace boost {
343  template <>
344  inline ecaldqm::MESet *new_clone<ecaldqm::MESet>(ecaldqm::MESet const &);
345  template <>
346  void delete_clone<ecaldqm::MESet>(ecaldqm::MESet const *);
347 } // namespace boost
348 
349 namespace ecaldqm {
350  typedef boost::ptr_map<std::string, MESet> MESetCollection;
351 }
352 
353 #endif
virtual std::string const & getPath() const
Definition: MESet.h:91
Definition: BitonicSort.h:8
MonitorElement::Kind kind_
Definition: MESet.h:129
iterator(MESet &_meSet, unsigned _iME=0, int _iBin=1)
Definition: MESet.h:271
const_iterator & operator=(const_iterator const &_rhs)
Definition: MESet.h:251
virtual MonitorElement const * getME(unsigned _iME) const
Definition: MESet.h:97
MonitorElement::Kind getKind() const
Definition: MESet.h:94
void setBinContent(int binx, double content)
set content of bin (1-D)
virtual void setBinEntries(int, int, double)
Definition: MESet.h:69
virtual void setAxisTitle(std::string const &, int=1)
Definition: MESet.cc:89
const_iterator & operator++()
Definition: MESet.cc:374
virtual void book(DQMStore::IBooker &)
Definition: MESet.h:41
virtual void setBinEntries(EcalElectronicsId const &, double)
Definition: MESet.h:65
Definition: CLHEP.h:16
virtual iterator end()
Definition: MESet.h:331
iterator & operator=(const_iterator const &_rhs)
Definition: MESet.h:278
virtual void clear() const
Definition: MESet.cc:84
const_iterator(MESet const &_meSet, unsigned _iME=0, int _iBin=1)
Definition: MESet.h:248
virtual double getBinError(DetId const &, int=0) const
Definition: MESet.h:75
bool operator==(const_iterator const &_rhs) const
Definition: MESet.h:255
bool isChannel() const
Definition: MESet.h:153
virtual void checkME_(unsigned _iME) const
Definition: MESet.h:114
bool isValidIdBin(ObjectType, BinningType, unsigned, int)
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
void fill(double _y, double _w=1.)
Definition: MESet.h:212
virtual void setBinEntries(int, double)
Definition: MESet.h:66
iterator(iterator const &_orig)
Definition: MESet.h:277
#define nullptr
MESet const * meSet_
Definition: MESet.h:139
double getBinEntries() const
Definition: MESet.h:177
binning::ObjectType otype
Definition: MESet.h:144
MonitorElement const * getME() const
Definition: MESet.h:183
virtual MESet * clone(std::string const &="") const
Definition: MESet.cc:75
virtual void setBinEntries(DetId const &, double)
Definition: MESet.h:64
virtual iterator begin()
Definition: MESet.h:329
bool batchMode_
Definition: MESet.h:132
virtual iterator beginChannel()
Definition: MESet.h:333
virtual double getBinError(EcalElectronicsId const &, int=0) const
Definition: MESet.h:76
virtual void setBinContent(DetId const &, int, double)
Definition: MESet.h:53
const_iterator & toNextChannel()
Definition: MESet.h:290
virtual void setBinContent(DetId const &, double)
Definition: MESet.h:50
virtual bool maskMatches(DetId const &, uint32_t, StatusManager const *) const
Definition: MESet.cc:167
MonitorElement * getME() const
Definition: MESet.h:228
virtual double getBinEntries(int, int=0) const
Definition: MESet.h:81
Definition: Electron.h:6
virtual const_iterator begin() const
Definition: MESet.h:320
virtual ~MESet()
Definition: MESet.cc:62
virtual void fill(int, double=1., double=1., double=1.)
Definition: MESet.h:47
virtual double getBinContent(int, int=0) const
Definition: MESet.h:73
void setMESet(MESet &_meSet)
Definition: MESet.h:234
virtual void setBinError(EcalElectronicsId const &, int, double)
Definition: MESet.h:61
virtual void setBinError(DetId const &, double)
Definition: MESet.h:57
virtual void setBinContent(int, double)
Definition: MESet.h:52
virtual void setBinError(DetId const &, int, double)
Definition: MESet.h:60
virtual double getBinContent(DetId const &, int=0) const
Definition: MESet.h:71
binning::ObjectType getObjType() const
Definition: MESet.h:92
void throw_(std::string const &_message) const
Definition: MESet.h:122
virtual double getBinError(int, int=0) const
Definition: MESet.h:77
ConstBin(ConstBin const &_orig)
Definition: MESet.h:148
virtual void fill(EcalElectronicsId const &, double=1., double=1., double=1.)
Definition: MESet.h:46
Bin const * operator->() const
Definition: MESet.h:284
double getBinError() const
Definition: MESet.h:171
MESet * getMESet() const
Definition: MESet.h:238
virtual const_iterator beginChannel() const
Definition: MESet.h:324
virtual void reset(double=0., double=0., double=0.)
Definition: MESet.cc:98
Bin(Bin const &_orig)
Definition: MESet.h:200
virtual void setBinError(int, double)
Definition: MESet.h:59
iterator(MESet &_meSet, DetId const &_id)
Definition: MESet.h:274
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
virtual bool isVariableBinning() const
Definition: MESet.h:96
bool operator!=(const_iterator const &_rhs) const
Definition: MESet.h:256
virtual void setBinContent(EcalElectronicsId const &, int, double)
Definition: MESet.h:54
bool lumiFlag_
Definition: MESet.h:130
boost::ptr_map< std::string, MESet > MESetCollection
Definition: MESet.h:350
ConstBin & operator=(ConstBin const &)
Definition: MESet.cc:343
void fill(double _w=1.)
Definition: MESet.h:208
virtual void fill_(unsigned, int, double)
Definition: MESet.cc:266
std::string formPath(PathReplacements const &) const
Definition: MESet.cc:150
const_iterator(const_iterator const &_orig)
Definition: MESet.h:250
void setBatchMode()
Definition: MESet.h:106
Definition: DetId.h:18
MESet const * getMESet() const
Definition: MESet.h:190
void setLumiFlag()
Definition: MESet.h:104
MESet * meSet_
Definition: MESet.h:195
bool getBatchMode() const
Definition: MESet.h:107
ConstBin & operator=(Bin const &_rhs)
Definition: MESet.h:201
bool isActive() const
Definition: MESet.h:95
virtual void softReset()
Definition: MESet.cc:246
double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
virtual MonitorElement * getME(unsigned _iME)
Definition: MESet.h:98
bool getLumiFlag() const
Definition: MESet.h:105
virtual void fill(DetId const &, double=1., double=1., double=1.)
Definition: MESet.h:45
Bin(MESet &_set, unsigned _iME=0, int _iBin=1)
Definition: MESet.h:199
binning::BinningType getBinType() const
Definition: MESet.h:93
virtual void resetAll(double=0., double=0., double=0.)
Definition: MESet.cc:105
double getBinContent() const
Definition: MESet.h:165
virtual bool retrieve(DQMStore::IGetter &, std::string *=0) const
Definition: MESet.h:42
bool active_
Definition: MESet.h:134
virtual double getBinContent(EcalElectronicsId const &, int=0) const
Definition: MESet.h:72
virtual void setBinContent(int, int, double)
Definition: MESet.h:55
virtual void recoverStats()
Definition: MESet.cc:256
virtual void setBinEntries(EcalElectronicsId const &, int, double)
Definition: MESet.h:68
virtual void setBinError(EcalElectronicsId const &, double)
Definition: MESet.h:58
double getBinContent(int binx) const
get content of bin (1-D)
virtual double getBinEntries(DetId const &, int=0) const
Definition: MESet.h:79
virtual double getBinEntries(EcalElectronicsId const &, int=0) const
Definition: MESet.h:80
double getBinEntries(int bin) const
get # of bin entries (for profiles)
ConstBin const * operator->() const
Definition: MESet.h:257
virtual void setBinError(int, int, double)
Definition: MESet.h:62
uint32_t getId() const
Definition: MESet.h:159
void setMESet(MESet const &_meSet)
Definition: MESet.h:189
binning::ObjectType otype_
Definition: MESet.h:127
void setBinContent(double _content)
Definition: MESet.h:216
virtual const_iterator end() const
Definition: MESet.h:322
const_iterator & toNextChannel()
Definition: MESet.cc:424
void setBinEntries(double _entries)
Definition: MESet.h:224
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:64
binning::BinningType btype_
Definition: MESet.h:128
void setBinError(double _error)
Definition: MESet.h:220
std::map< std::string, std::string > PathReplacements
Definition: MESet.h:30
bool operator==(ConstBin const &_rhs) const
Definition: MESet.h:150
std::string path_
Definition: MESet.h:126
virtual void setBinContent(EcalElectronicsId const &, double)
Definition: MESet.h:51
void setBinEntries(int bin, double nentries)
set # of bin entries (to be used for profiles)
const_iterator & operator++()
Definition: MESet.h:285
virtual void setBinEntries(DetId const &, int, double)
Definition: MESet.h:67
std::vector< MonitorElement * > mes_
Definition: MESet.h:124
virtual void fill(double, double=1., double=1.)
Definition: MESet.h:48
uint32_t idFromBin(ObjectType, BinningType, unsigned, int)