CMS 3D CMS Logo

MonitorElement.h
Go to the documentation of this file.
1 #ifndef DQMSERVICES_CORE_MONITOR_ELEMENT_H
2 # define DQMSERVICES_CORE_MONITOR_ELEMENT_H
3 
6 # include "TF1.h"
7 # include "TH1F.h"
8 # include "TH1S.h"
9 # include "TH1D.h"
10 # include "TH2F.h"
11 # include "TH2S.h"
12 # include "TH2D.h"
13 # include "TH3F.h"
14 # include "TProfile.h"
15 # include "TProfile2D.h"
16 # include "TObjString.h"
17 # include "TAxis.h"
18 # include <sys/time.h>
19 # include <string>
20 # include <set>
21 # include <map>
22 # include <sstream>
23 # include <iomanip>
24 # include <cassert>
25 # include <cstdint>
26 
27 # ifndef DQM_ROOT_METHODS
28 # define DQM_ROOT_METHODS 1
29 # endif
30 
31 class QCriterion;
32 
33 // tag for a special constructor, see below
35 
38 {
39  friend class DQMStore;
40  friend class DQMService;
41 public:
42  struct Scalar
43  {
44  int64_t num;
45  double real;
47  };
48 
49  enum Kind
50  {
51  DQM_KIND_INVALID = DQMNet::DQM_PROP_TYPE_INVALID,
52  DQM_KIND_INT = DQMNet::DQM_PROP_TYPE_INT,
53  DQM_KIND_REAL = DQMNet::DQM_PROP_TYPE_REAL,
54  DQM_KIND_STRING = DQMNet::DQM_PROP_TYPE_STRING,
55  DQM_KIND_TH1F = DQMNet::DQM_PROP_TYPE_TH1F,
56  DQM_KIND_TH1S = DQMNet::DQM_PROP_TYPE_TH1S,
57  DQM_KIND_TH1D = DQMNet::DQM_PROP_TYPE_TH1D,
58  DQM_KIND_TH2F = DQMNet::DQM_PROP_TYPE_TH2F,
59  DQM_KIND_TH2S = DQMNet::DQM_PROP_TYPE_TH2S,
60  DQM_KIND_TH2D = DQMNet::DQM_PROP_TYPE_TH2D,
61  DQM_KIND_TH3F = DQMNet::DQM_PROP_TYPE_TH3F,
62  DQM_KIND_TPROFILE = DQMNet::DQM_PROP_TYPE_TPROF,
63  DQM_KIND_TPROFILE2D = DQMNet::DQM_PROP_TYPE_TPROF2D
64  };
65 
66 private:
67  DQMNet::CoreObject data_; //< Core object information.
68  Scalar scalar_; //< Current scalar value.
69  TH1 *object_; //< Current ROOT object value.
70  TH1 *reference_; //< Current ROOT reference object.
71  TH1 *refvalue_; //< Soft reference if any.
72  std::vector<QReport> qreports_; //< QReports associated to this object.
73 
74  MonitorElement *initialise(Kind kind);
75  MonitorElement *initialise(Kind kind, TH1 *rootobj);
76  MonitorElement *initialise(Kind kind, const std::string &value);
77  void globalize() {
78  data_.streamId = 0;
79  data_.moduleId = 0;
80  }
81  void setLumi(uint32_t ls) {data_.lumi = ls;}
82 
83 public:
86  const std::string &name,
87  uint32_t run = 0,
88  uint32_t streamId = 0,
89  uint32_t moduleId = 0);
93  MonitorElement &operator=(const MonitorElement &) = delete;
94  MonitorElement &operator=(MonitorElement &&) = delete;
95  ~MonitorElement();
96 
98  bool operator<(const MonitorElement &x) const
99  {
100  return DQMNet::setOrder(data_, x.data_);
101  }
102 
104  static bool CheckBinLabels(const TAxis* a1, const TAxis * a2);
105 
107  Kind kind() const
108  { return Kind(data_.flags & DQMNet::DQM_PROP_TYPE_MASK); }
109 
111  uint32_t flags() const
112  { return data_.flags; }
113 
115  const std::string &getName() const
116  { return data_.objname; }
117 
119  const std::string &getPathname() const
120  { return *data_.dirname; }
121 
123  const std::string getFullname() const
124  {
126  path.reserve(data_.dirname->size() + data_.objname.size() + 2);
127  path += *data_.dirname;
128  if (! data_.dirname->empty())
129  path += '/';
130  path += data_.objname;
131  return path;
132  }
133 
135  bool wasUpdated() const
136  { return data_.flags & DQMNet::DQM_PROP_NEW; }
137 
139  void update()
140  { data_.flags |= DQMNet::DQM_PROP_NEW; }
141 
144  void setResetMe(bool /* flag */)
145  { data_.flags |= DQMNet::DQM_PROP_RESET; }
146 
148  bool getLumiFlag() const
149  { return data_.flags & DQMNet::DQM_PROP_LUMI; }
150 
152  void setLumiFlag()
153  { data_.flags |= DQMNet::DQM_PROP_LUMI; }
154 
159 
160  // A static assert to check that T actually fits in
161  // int64_t.
162  template <typename T>
164  {
165  int checkArray[sizeof(int64_t) - sizeof(T) + 1];
166  };
167 
168  void Fill(long long x) { fits_in_int64_t<long long>(); doFill(static_cast<int64_t>(x)); }
169  void Fill(unsigned long long x) { fits_in_int64_t<unsigned long long>(); doFill(static_cast<int64_t>(x)); }
170  void Fill(unsigned long x) { fits_in_int64_t<unsigned long>(); doFill(static_cast<int64_t>(x)); }
171  void Fill(long x) { fits_in_int64_t<long>(); doFill(static_cast<int64_t>(x)); }
172  void Fill(unsigned int x) { fits_in_int64_t<unsigned int>(); doFill(static_cast<int64_t>(x)); }
173  void Fill(int x) { fits_in_int64_t<int>(); doFill(static_cast<int64_t>(x)); }
174  void Fill(short x) { fits_in_int64_t<short>(); doFill(static_cast<int64_t>(x)); }
175  void Fill(unsigned short x) { fits_in_int64_t<unsigned short>(); doFill(static_cast<int64_t>(x)); }
176  void Fill(char x) { fits_in_int64_t<char>(); doFill(static_cast<int64_t>(x)); }
177  void Fill(unsigned char x) { fits_in_int64_t<unsigned char>(); doFill(static_cast<int64_t>(x)); }
178 
179  void Fill(float x) { Fill(static_cast<double>(x)); }
180  void Fill(double x);
181  void Fill(std::string &value);
182 
183  void Fill(double x, double yw);
184  void Fill(double x, double y, double zw);
185  void Fill(double x, double y, double z, double w);
186  void ShiftFillLast(double y, double ye = 0., int32_t xscale = 1);
187  void Reset();
188 
189  std::string valueString() const;
190  std::string tagString() const;
191  std::string tagLabelString() const;
192  std::string effLabelString() const;
193  std::string qualityTagString(const DQMNet::QValue &qv) const;
194  void packScalarData(std::string &into, const char *prefix) const;
195  void packQualityData(std::string &into) const;
196 
198  bool hasError() const
199  { return data_.flags & DQMNet::DQM_PROP_REPORT_ERROR; }
200 
202  bool hasWarning() const
203  { return data_.flags & DQMNet::DQM_PROP_REPORT_WARN; }
204 
206  bool hasOtherReport() const
207  { return data_.flags & DQMNet::DQM_PROP_REPORT_OTHER; }
208 
211  bool isEfficiency() const
212  { return data_.flags & DQMNet::DQM_PROP_EFFICIENCY_PLOT; }
213 
215  const QReport *getQReport(const std::string &qtname) const;
216 
218  std::vector<QReport *> getQReports() const;
219 
221  std::vector<QReport *> getQWarnings() const;
222 
224  std::vector<QReport *> getQErrors() const;
225 
228  std::vector<QReport *> getQOthers() const;
229 
231  void runQTests();
232 
233 private:
234  void doFill(int64_t x);
235  void incompatible(const char *func) const;
236  TH1 *accessRootObject(const char *func, int reqdim) const;
237 
238 public:
239 #if DQM_ROOT_METHODS
240  double getMean(int axis = 1) const;
241  double getMeanError(int axis = 1) const;
242  double getRMS(int axis = 1) const;
243  double getRMSError(int axis = 1) const;
244  int getNbinsX() const;
245  int getNbinsY() const;
246  int getNbinsZ() const;
247  double getBinContent(int binx) const;
248  double getBinContent(int binx, int biny) const;
249  double getBinContent(int binx, int biny, int binz) const;
250  double getBinError(int binx) const;
251  double getBinError(int binx, int biny) const;
252  double getBinError(int binx, int biny, int binz) const;
253  double getEntries() const;
254  double getBinEntries(int bin) const;
255 
256 private:
257  double getYmin() const;
258  double getYmax() const;
259 
260 public:
261  std::string getAxisTitle(int axis = 1) const;
262  std::string getTitle() const;
263  void setBinContent(int binx, double content);
264  void setBinContent(int binx, int biny, double content);
265  void setBinContent(int binx, int biny, int binz, double content);
266  void setBinError(int binx, double error);
267  void setBinError(int binx, int biny, double error);
268  void setBinError(int binx, int biny, int binz, double error);
269  void setBinEntries(int bin, double nentries);
270  void setEntries(double nentries);
271  void setBinLabel(int bin, const std::string &label, int axis = 1);
272  void setAxisRange(double xmin, double xmax, int axis = 1);
273  void setAxisTitle(const std::string &title, int axis = 1);
274  void setAxisTimeDisplay(int value, int axis = 1);
275  void setAxisTimeFormat(const char *format = "", int axis = 1);
276 
277 private:
278  void setAxisTimeOffset(double toffset, const char *option="local", int axis = 1);
279 
280 public:
281  void setTitle(const std::string &title);
282 #endif // DQM_ROOT_METHODS
283 
284 private:
286  bool isSoftResetEnabled() const
287  { return refvalue_ != nullptr; }
288 
290  bool isAccumulateEnabled() const
291  { return data_.flags & DQMNet::DQM_PROP_ACCUMULATE; }
292 
294  bool markedToDelete() const
295  { return data_.flags & DQMNet::DQM_PROP_MARKTODELETE; }
296 
301 
302 private:
304  void resetUpdate()
305  { data_.flags &= ~DQMNet::DQM_PROP_NEW; }
306 
308  bool resetMe() const
309  { return data_.flags & DQMNet::DQM_PROP_RESET; }
310 
313  void setAccumulate(bool /* flag */)
314  { data_.flags |= DQMNet::DQM_PROP_ACCUMULATE; }
315 
316  TAxis *getAxis(const char *func, int axis) const;
317 
318  // ------------ Operations for MEs that are normally never reset ---------
319 public:
320  void softReset();
321 private:
322  void disableSoftReset();
323  void addProfiles(TProfile *h1, TProfile *h2, TProfile *sum, float c1, float c2);
324  void addProfiles(TProfile2D *h1, TProfile2D *h2, TProfile2D *sum, float c1, float c2);
325  void copyFunctions(TH1 *from, TH1 *to);
326  void copyFrom(TH1 *from);
327 
328 
329  // --- Operations on MEs that are normally reset at end of monitoring cycle ---
330  void getQReport(bool create, const std::string &qtname, QReport *&qr, DQMNet::QValue *&qv);
331  void addQReport(const DQMNet::QValue &desc, QCriterion *qc);
332  void addQReport(QCriterion *qc);
333  void updateQReportStats();
334 
335 public:
336  TObject *getRootObject() const;
337  TH1 *getTH1() const;
338  TH1F *getTH1F() const;
339  TH1S *getTH1S() const;
340  TH1D *getTH1D() const;
341  TH2F *getTH2F() const;
342  TH2S *getTH2S() const;
343  TH2D *getTH2D() const;
344  TH3F *getTH3F() const;
345  TProfile *getTProfile() const;
346  TProfile2D *getTProfile2D() const;
347 
348  TObject *getRefRootObject() const;
349  TH1 *getRefTH1() const;
350  TH1F *getRefTH1F() const;
351  TH1S *getRefTH1S() const;
352  TH1D *getRefTH1D() const;
353  TH2F *getRefTH2F() const;
354  TH2S *getRefTH2S() const;
355  TH2D *getRefTH2D() const;
356  TH3F *getRefTH3F() const;
357  TProfile *getRefTProfile() const;
358  TProfile2D *getRefTProfile2D() const;
359 
360  int64_t getIntValue() const
361  {
362  assert(kind() == DQM_KIND_INT);
363  return scalar_.num;
364  }
365 
366  double getFloatValue() const
367  {
368  assert(kind() == DQM_KIND_REAL);
369  return scalar_.real;
370  }
371 
373  {
374  assert(kind() == DQM_KIND_STRING);
375  return scalar_.str;
376  }
377 
378  DQMNet::TagList getTags() const // DEPRECATED
379  {
380  DQMNet::TagList tags;
381  if (data_.flags & DQMNet::DQM_PROP_TAGGED)
382  tags.push_back(data_.tag);
383  return tags;
384  }
385 
386  const uint32_t getTag() const
387  { return data_.tag; }
388 
389  const uint32_t run() const {return data_.run;}
390  const uint32_t lumi() const {return data_.lumi;}
391  const uint32_t streamId() const {return data_.streamId;}
392  const uint32_t moduleId() const {return data_.moduleId;}
393 };
394 
395 #endif // DQMSERVICES_CORE_MONITOR_ELEMENT_H
static const uint32_t DQM_PROP_REPORT_WARN
Definition: DQMNet.h:48
uint32_t moduleId
Definition: DQMNet.h:105
int64_t getIntValue() const
static const uint32_t DQM_PROP_TYPE_TH1S
Definition: DQMNet.h:33
static const uint32_t DQM_PROP_TYPE_TPROF
Definition: DQMNet.h:41
const double w
Definition: UKUtility.cc:23
def create(alignables, pedeDump, additionalData, outputFile, config)
static const uint32_t DQM_PROP_TYPE_TH2D
Definition: DQMNet.h:37
std::vector< QReport > qreports_
void Fill(unsigned short x)
const std::string & getPathname() const
get pathname of parent folder
double getFloatValue() const
Definition: DQMNet.h:23
uint32_t flags() const
Get the object flags.
void setLumi(uint32_t ls)
bool isSoftResetEnabled() const
whether soft-reset is enabled; default is false
uint32_t flags
Definition: DQMNet.h:99
bool hasError() const
true if at least of one of the quality tests returned an error
static const uint32_t DQM_PROP_TAGGED
Definition: DQMNet.h:55
const std::string & getName() const
get name of ME
void Fill(float x)
static const uint32_t DQM_PROP_EFFICIENCY_PLOT
Definition: DQMNet.h:64
bool hasOtherReport() const
true if at least of one of the tests returned some other (non-ok) status
static const uint32_t DQM_PROP_TYPE_TH3F
Definition: DQMNet.h:38
static const uint32_t DQM_PROP_RESET
Definition: DQMNet.h:57
uint32_t tag
Definition: DQMNet.h:100
const std::string * dirname
Definition: DQMNet.h:106
static const uint32_t DQM_PROP_TYPE_TH1F
Definition: DQMNet.h:32
void Fill(short x)
static const uint32_t DQM_PROP_MARKTODELETE
Definition: DQMNet.h:65
bool operator<(const MonitorElement &x) const
Compare monitor elements, for ordering in sets.
uint32_t run
Definition: DQMNet.h:102
void Fill(unsigned long long x)
bool wasUpdated() const
true if ME was updated in last monitoring cycle
void Fill(long long x)
static const uint32_t DQM_PROP_ACCUMULATE
Definition: DQMNet.h:56
void update()
Mark the object updated.
void Fill(int x)
const uint32_t getTag() const
void setEfficiencyFlag()
void setLumiFlag()
this ME is meant to be stored for each luminosity section
static const uint32_t DQM_PROP_TYPE_INT
Definition: DQMNet.h:29
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
bool hasWarning() const
true if at least of one of the quality tests returned a warning
void setAccumulate(bool)
uint32_t lumi
Definition: DQMNet.h:103
bool resetMe() const
true if ME should be reset at end of monitoring cycle
void resetUpdate()
reset "was updated" flag
bool markedToDelete() const
true if ME is marked for deletion
static const uint32_t DQM_PROP_REPORT_ERROR
Definition: DQMNet.h:47
Definition: value.py:1
static const uint32_t DQM_PROP_REPORT_OTHER
Definition: DQMNet.h:49
static const uint32_t DQM_PROP_TYPE_TH1D
Definition: DQMNet.h:34
void Fill(unsigned int x)
void Fill(char x)
std::string objname
Definition: DQMNet.h:107
const std::string & getStringValue() const
DQMNet::CoreObject data_
bin
set the eta bin as selection string.
const std::string getFullname() const
get full name of ME including Pathname
doFill
Definition: cuy.py:574
const uint32_t lumi() const
void Fill(long x)
def ls(path, rec=False)
Definition: eostools.py:348
void Fill(unsigned long x)
void setResetMe(bool)
bool isEfficiency() const
static bool setOrder(const CoreObject &a, const CoreObject &b)
Definition: DQMNet.h:180
const uint32_t moduleId() const
DQMNet::TagList getTags() const
static const uint32_t DQM_PROP_TYPE_TH2S
Definition: DQMNet.h:36
void Fill(unsigned char x)
std::vector< uint32_t > TagList
Definition: DQMNet.h:85
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:75
bool getLumiFlag() const
true if ME is meant to be stored for each luminosity section
static const uint32_t DQM_PROP_TYPE_STRING
Definition: DQMNet.h:31
void Reset(std::vector< TH2F > &depth)
const uint32_t streamId() const
static const uint32_t DQM_PROP_NEW
Definition: DQMNet.h:59
static const uint32_t DQM_PROP_TYPE_MASK
Definition: DQMNet.h:26
long double T
uint32_t streamId
Definition: DQMNet.h:104
static const uint32_t DQM_PROP_LUMI
Definition: DQMNet.h:61
static const uint32_t DQM_PROP_TYPE_REAL
Definition: DQMNet.h:30
Kind kind() const
Get the type of the monitor element.
static const uint32_t DQM_PROP_TYPE_INVALID
Definition: DQMNet.h:28
static const uint32_t DQM_PROP_TYPE_TPROF2D
Definition: DQMNet.h:42
static const uint32_t DQM_PROP_TYPE_TH2F
Definition: DQMNet.h:35
bool isAccumulateEnabled() const
whether ME contents should be accumulated over multiple monitoring periods; default: false ...
const uint32_t run() const