CMS 3D CMS Logo

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