CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MESetNonObject.cc
Go to the documentation of this file.
2 
3 namespace ecaldqm
4 {
5  MESetNonObject::MESetNonObject(std::string const& _fullPath, binning::ObjectType _otype, binning::BinningType _btype, MonitorElement::Kind _kind, binning::AxisSpecs const* _xaxis/* = 0*/, binning::AxisSpecs const* _yaxis/* = 0*/, binning::AxisSpecs const* _zaxis/* = 0*/) :
6  MESet(_fullPath, _otype, _btype, _kind),
7  xaxis_(_xaxis ? new binning::AxisSpecs(*_xaxis) : 0),
8  yaxis_(_yaxis ? new binning::AxisSpecs(*_yaxis) : 0),
9  zaxis_(_zaxis ? new binning::AxisSpecs(*_zaxis) : 0)
10  {
11  }
12 
14  MESet(_orig),
15  xaxis_(_orig.xaxis_ ? new binning::AxisSpecs(*_orig.xaxis_) : 0),
16  yaxis_(_orig.yaxis_ ? new binning::AxisSpecs(*_orig.yaxis_) : 0),
17  zaxis_(_orig.zaxis_ ? new binning::AxisSpecs(*_orig.zaxis_) : 0)
18  {
19  }
20 
22  {
23  delete xaxis_;
24  delete yaxis_;
25  delete zaxis_;
26  }
27 
28  MESet&
30  {
31  delete xaxis_;
32  delete yaxis_;
33  delete zaxis_;
34  xaxis_ = 0;
35  yaxis_ = 0;
36  zaxis_ = 0;
37 
38  MESetNonObject const* pRhs(dynamic_cast<MESetNonObject const*>(&_rhs));
39  if(pRhs){
40  if(pRhs->xaxis_) xaxis_ = new binning::AxisSpecs(*pRhs->xaxis_);
41  if(pRhs->yaxis_) yaxis_ = new binning::AxisSpecs(*pRhs->yaxis_);
42  if(pRhs->zaxis_) zaxis_ = new binning::AxisSpecs(*pRhs->zaxis_);
43  }
44  return MESet::operator=(_rhs);
45  }
46 
47  MESet*
48  MESetNonObject::clone(std::string const& _path/* = ""*/) const
49  {
51  if(_path != "") path_ = _path;
52  MESet* copy(new MESetNonObject(*this));
53  path_ = path;
54  return copy;
55  }
56 
57  void
59  {
60  doBook_(_dqmStore);
61  }
62 
63  void
65  {
66  doBook_(_ibooker);
67  }
68 
69  bool
70  MESetNonObject::retrieve(DQMStore const& _store, std::string* _failedPath/* = 0*/) const
71  {
72  mes_.clear();
73 
74  MonitorElement* me(_store.get(path_));
75  if(!me){
76  if(_failedPath) *_failedPath = path_;
77  return false;
78  }
79 
80  mes_.push_back(me);
81 
82  active_ = true;
83  return true;
84  }
85 
86  void
87  MESetNonObject::fill(double _x, double _wy/* = 1.*/, double _w/* = 1.*/)
88  {
89  if(!active_) return;
90 
91  if(mes_.size() == 0 || !mes_[0]) return;
92 
93  switch(kind_) {
95  mes_[0]->Fill(_x);
96  break;
99  mes_[0]->Fill(_x, _wy);
100  break;
103  mes_[0]->Fill(_x, _wy, _w);
104  break;
105  default :
106  break;
107  }
108  }
109 
110  void
111  MESetNonObject::setBinContent(int _bin, double _content)
112  {
113  if(!active_) return;
114  if(kind_ == MonitorElement::DQM_KIND_REAL) return;
115 
116  if(mes_.size() == 0 || !mes_[0]) return;
117 
118  mes_[0]->setBinContent(_bin, _content);
119  }
120 
121  void
122  MESetNonObject::setBinError(int _bin, double _error)
123  {
124  if(!active_) return;
125  if(kind_ == MonitorElement::DQM_KIND_REAL) return;
126 
127  if(mes_.size() == 0 || !mes_[0]) return;
128 
129  mes_[0]->setBinError(_bin, _error);
130  }
131 
132  void
133  MESetNonObject::setBinEntries(int _bin, double _entries)
134  {
135  if(!active_) return;
137 
138  if(mes_.size() == 0 || !mes_[0]) return;
139 
140  mes_[0]->setBinEntries(_bin, _entries);
141  }
142 
143  double
144  MESetNonObject::getBinContent(int _bin, int) const
145  {
146  if(!active_) return 0.;
147  if(kind_ == MonitorElement::DQM_KIND_REAL) return 0.;
148 
149  if(mes_.size() == 0 || !mes_[0]) return 0.;
150 
151  return mes_[0]->getBinContent(_bin);
152  }
153 
154  double
155  MESetNonObject::getBinError(int _bin, int) const
156  {
157  if(!active_) return 0.;
158  if(kind_ == MonitorElement::DQM_KIND_REAL) return 0.;
159 
160  if(mes_.size() == 0 || !mes_[0]) return 0.;
161 
162  return mes_[0]->getBinError(_bin);
163  }
164 
165  double
166  MESetNonObject::getBinEntries(int _bin, int) const
167  {
168  if(!active_) return 0.;
170 
171  if(mes_.size() == 0 || !mes_[0]) return 0.;
172 
173  return mes_[0]->getBinEntries(_bin);
174  }
175 
176  int
177  MESetNonObject::findBin(double _x, double _y/* = 0.*/) const
178  {
179  if(!active_) return 0;
180 
181  if(mes_.size() == 0 || !mes_[0]) return 0;
182 
184  return mes_[0]->getTH1()->FindBin(_x);
186  return mes_[0]->getTH1()->FindBin(_x, _y);
187  else
188  return 0;
189  }
190 
191  bool
193  {
194  return (xaxis_ && xaxis_->edges) || (yaxis_ && yaxis_->edges) || (zaxis_ && zaxis_->edges);
195  }
196 
197  template<class Bookable>
198  void
199  MESetNonObject::doBook_(Bookable& _booker)
200  {
201  using namespace std;
202 
203  clear();
204 
205  if(path_.find('%') != string::npos)
206  throw_("book() called with incompletely formed path");
207 
208  size_t slashPos(path_.find_last_of('/'));
209  string name(path_.substr(slashPos + 1));
210  _booker.setCurrentFolder(path_.substr(0, slashPos));
211 
212  MonitorElement* me(0);
213 
214  switch(kind_) {
216  me = _booker.bookFloat(name);
217  break;
218 
220  {
221  if(!xaxis_)
222  throw_("No xaxis found for MESetNonObject");
223 
224  if(!xaxis_->edges)
225  me = _booker.book1D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high);
226  else{
227  float* edges(new float[xaxis_->nbins + 1]);
228  for(int i(0); i < xaxis_->nbins + 1; i++)
229  edges[i] = xaxis_->edges[i];
230  me = _booker.book1D(name, name, xaxis_->nbins, edges);
231  delete [] edges;
232  }
233  }
234  break;
235 
237  {
238  if(!xaxis_)
239  throw_("No xaxis found for MESetNonObject");
240 
241  double ylow, yhigh;
242  if(!yaxis_){
243  ylow = -numeric_limits<double>::max();
244  yhigh = numeric_limits<double>::max();
245  }
246  else{
247  ylow = yaxis_->low;
248  yhigh = yaxis_->high;
249  }
250  if(xaxis_->edges)
251  me = _booker.bookProfile(name, name, xaxis_->nbins, xaxis_->edges, ylow, yhigh, "");
252  else
253  me = _booker.bookProfile(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, ylow, yhigh, "");
254 
255  }
256  break;
257 
259  {
260  if(!xaxis_ || !yaxis_)
261  throw_("No x/yaxis found for MESetNonObject");
262 
263  if(!xaxis_->edges || !yaxis_->edges)
264  me = _booker.book2D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, yaxis_->nbins, yaxis_->low, yaxis_->high);
265  else{
266  float* xedges(new float[xaxis_->nbins + 1]);
267  for(int i(0); i < xaxis_->nbins + 1; i++)
268  xedges[i] = xaxis_->edges[i];
269  float* yedges(new float[yaxis_->nbins + 1]);
270  for(int i(0); i < yaxis_->nbins + 1; i++)
271  yedges[i] = yaxis_->edges[i];
272  me = _booker.book2D(name, name, xaxis_->nbins, xedges, yaxis_->nbins, yedges);
273  delete [] xedges;
274  delete [] yedges;
275  }
276  }
277  break;
278 
280  {
281  if(!xaxis_ || !yaxis_)
282  throw_("No x/yaxis found for MESetNonObject");
283  double high(0.), low(0.);
284  if(zaxis_){
285  low = zaxis_->low;
286  high = zaxis_->high;
287  }
288  else{
291  }
292 
293  me = _booker.bookProfile2D(name, name, xaxis_->nbins, xaxis_->low, xaxis_->high, yaxis_->nbins, yaxis_->low, yaxis_->high, low, high, "");
294  }
295  break;
296 
297  default :
298  throw_("Unsupported MonitorElement kind");
299  }
300 
301  if(xaxis_){
302  me->setAxisTitle(xaxis_->title, 1);
303  if(xaxis_->labels){
304  for(int iBin(1); iBin <= xaxis_->nbins; ++iBin)
305  me->setBinLabel(iBin, xaxis_->labels[iBin - 1], 1);
306  }
307  }
308  if(yaxis_){
309  me->setAxisTitle(yaxis_->title, 2);
310  if(yaxis_->labels){
311  for(int iBin(1); iBin <= yaxis_->nbins; ++iBin)
312  me->setBinLabel(iBin, yaxis_->labels[iBin - 1], 2);
313  }
314  }
315  if(zaxis_){
316  me->setAxisTitle(zaxis_->title, 3);
317  if(zaxis_->labels){
318  for(int iBin(1); iBin <= zaxis_->nbins; ++iBin)
319  me->setBinLabel(iBin, zaxis_->labels[iBin - 1], 3);
320  }
321  }
322 
323  if(lumiFlag_) me->setLumiFlag();
324 
325  mes_.push_back(me);
326 
327  active_ = true;
328  }
329 }
binning::AxisSpecs const * zaxis_
MonitorElement::Kind kind_
Definition: MESet.h:135
int i
Definition: DBlmapReader.cc:9
MESet & operator=(MESet const &) override
void setBinEntries(int, double) override
double getBinError(int, int=0) const override
double getBinEntries(int, int=0) const override
virtual void clear() const
Definition: MESet.cc:93
binning::AxisSpecs const * xaxis_
void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
binning::AxisSpecs const * yaxis_
void setBinError(int, double) override
dictionary edges
std::vector< MonitorElement * > mes_
Definition: MESet.h:130
tuple path
else: Piece not in the list, fine.
void setBinContent(int, double) override
const T & max(const T &a, const T &b)
void throw_(std::string const &_message) const
Definition: MESet.h:125
void doBook_(Bookable &)
int findBin(double, double=0.) const
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1696
bool lumiFlag_
Definition: MESet.h:136
bool retrieve(DQMStore const &, std::string *=0) const override
bool active_
Definition: MESet.h:139
MESetNonObject(std::string const &, binning::ObjectType, binning::BinningType, MonitorElement::Kind, binning::AxisSpecs const *=0, binning::AxisSpecs const *=0, binning::AxisSpecs const *=0)
void fill(double, double=1., double=1.) override
virtual MESet & operator=(MESet const &)
Definition: MESet.cc:70
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
MESet * clone(std::string const &="") const override
std::string path_
Definition: MESet.h:132
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
double getBinContent(int, int=0) const override
bool isVariableBinning() const override
void book(DQMStore &) override