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