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 <stdint.h>
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  typedef std::vector<QReport>::const_iterator QReportIterator;
67 
68 private:
69  DQMNet::CoreObject data_; //< Core object information.
70  Scalar scalar_; //< Current scalar value.
71  TH1 *object_; //< Current ROOT object value.
72  TH1 *reference_; //< Current ROOT reference object.
73  TH1 *refvalue_; //< Soft reference if any.
74  std::vector<QReport> qreports_; //< QReports associated to this object.
75 
76  MonitorElement *initialise(Kind kind);
77  MonitorElement *initialise(Kind kind, TH1 *rootobj);
78  MonitorElement *initialise(Kind kind, const std::string &value);
79  void globalize() {
80  data_.streamId = 0;
81  data_.moduleId = 0;
82  }
83  void setLumi(uint32_t ls) {data_.lumi = ls;}
84 
85 public:
86  MonitorElement(void);
88  const std::string &name,
89  uint32_t run = 0,
90  uint32_t streamId = 0,
91  uint32_t moduleId = 0);
95  MonitorElement &operator=(const MonitorElement &) = delete;
96  MonitorElement &operator=(MonitorElement &&) = delete;
97  ~MonitorElement(void);
98 
100  bool operator<(const MonitorElement &x) const
101  {
102  return DQMNet::setOrder(data_, x.data_);
103  }
104 
106  static bool CheckBinLabels(const TAxis* a1, const TAxis * a2);
107 
109  Kind kind(void) const
110  { return Kind(data_.flags & DQMNet::DQM_PROP_TYPE_MASK); }
111 
113  uint32_t flags(void) const
114  { return data_.flags; }
115 
117  const std::string &getName(void) const
118  { return data_.objname; }
119 
121  const std::string &getPathname(void) const
122  { return *data_.dirname; }
123 
125  const std::string getFullname(void) const
126  {
128  path.reserve(data_.dirname->size() + data_.objname.size() + 2);
129  path += *data_.dirname;
130  if (! data_.dirname->empty())
131  path += '/';
132  path += data_.objname;
133  return path;
134  }
135 
137  bool wasUpdated(void) const
138  { return data_.flags & DQMNet::DQM_PROP_NEW; }
139 
141  void update(void)
142  { data_.flags |= DQMNet::DQM_PROP_NEW; }
143 
146  void setResetMe(bool /* flag */)
147  { data_.flags |= DQMNet::DQM_PROP_RESET; }
148 
150  bool getLumiFlag(void) const
151  { return data_.flags & DQMNet::DQM_PROP_LUMI; }
152 
154  void setLumiFlag(void)
155  { data_.flags |= DQMNet::DQM_PROP_LUMI; }
156 
159  void setEfficiencyFlag(void)
161 
162  // A static assert to check that T actually fits in
163  // int64_t.
164  template <typename T>
166  {
167  int checkArray[sizeof(int64_t) - sizeof(T) + 1];
168  };
169 
170  void Fill(long long x) { fits_in_int64_t<long long>(); doFill(static_cast<int64_t>(x)); }
171  void Fill(unsigned long long x) { fits_in_int64_t<unsigned long long>(); doFill(static_cast<int64_t>(x)); }
172  void Fill(unsigned long x) { fits_in_int64_t<unsigned long>(); doFill(static_cast<int64_t>(x)); }
173  void Fill(long x) { fits_in_int64_t<long>(); doFill(static_cast<int64_t>(x)); }
174  void Fill(unsigned int x) { fits_in_int64_t<unsigned int>(); doFill(static_cast<int64_t>(x)); }
175  void Fill(int x) { fits_in_int64_t<int>(); doFill(static_cast<int64_t>(x)); }
176  void Fill(short x) { fits_in_int64_t<short>(); doFill(static_cast<int64_t>(x)); }
177  void Fill(unsigned short x) { fits_in_int64_t<unsigned short>(); doFill(static_cast<int64_t>(x)); }
178  void Fill(char x) { fits_in_int64_t<char>(); doFill(static_cast<int64_t>(x)); }
179  void Fill(unsigned char x) { fits_in_int64_t<unsigned char>(); doFill(static_cast<int64_t>(x)); }
180 
181  void Fill(float x) { Fill(static_cast<double>(x)); }
182  void Fill(double x);
183  void Fill(std::string &value);
184 
185  void Fill(double x, double yw);
186  void Fill(double x, double y, double zw);
187  void Fill(double x, double y, double z, double w);
188  void ShiftFillLast(double y, double ye = 0., int32_t xscale = 1);
189  void Reset(void);
190 
191  std::string valueString(void) const;
192  std::string tagString(void) const;
193  std::string tagLabelString(void) const;
194  std::string effLabelString(void) const;
195  std::string qualityTagString(const DQMNet::QValue &qv) const;
196  void packScalarData(std::string &into, const char *prefix) const;
197  void packQualityData(std::string &into) const;
198 
200  bool hasError(void) const
201  { return data_.flags & DQMNet::DQM_PROP_REPORT_ERROR; }
202 
204  bool hasWarning(void) const
205  { return data_.flags & DQMNet::DQM_PROP_REPORT_WARN; }
206 
208  bool hasOtherReport(void) const
209  { return data_.flags & DQMNet::DQM_PROP_REPORT_OTHER; }
210 
213  bool isEfficiency(void) const
214  { return data_.flags & DQMNet::DQM_PROP_EFFICIENCY_PLOT; }
215 
217  const QReport *getQReport(const std::string &qtname) const;
218 
220  std::vector<QReport *> getQReports(void) const;
221 
223  std::vector<QReport *> getQWarnings(void) const;
224 
226  std::vector<QReport *> getQErrors(void) const;
227 
230  std::vector<QReport *> getQOthers(void) const;
231 
233  void runQTests(void);
234 
235 private:
236  void doFill(int64_t x);
237  void incompatible(const char *func) const;
238  TH1 *accessRootObject(const char *func, int reqdim) const;
239 
240 public:
241 #if DQM_ROOT_METHODS
242  double getMean(int axis = 1) const;
243  double getMeanError(int axis = 1) const;
244  double getRMS(int axis = 1) const;
245  double getRMSError(int axis = 1) const;
246  int getNbinsX(void) const;
247  int getNbinsY(void) const;
248  int getNbinsZ(void) const;
249  double getBinContent(int binx) const;
250  double getBinContent(int binx, int biny) const;
251  double getBinContent(int binx, int biny, int binz) const;
252  double getBinError(int binx) const;
253  double getBinError(int binx, int biny) const;
254  double getBinError(int binx, int biny, int binz) const;
255  double getEntries(void) const;
256  double getBinEntries(int bin) const;
257 
258 private:
259  double getYmin(void) const;
260  double getYmax(void) const;
261 
262 public:
263  std::string getAxisTitle(int axis = 1) const;
264  std::string getTitle(void) const;
265  void setBinContent(int binx, double content);
266  void setBinContent(int binx, int biny, double content);
267  void setBinContent(int binx, int biny, int binz, double content);
268  void setBinError(int binx, double error);
269  void setBinError(int binx, int biny, double error);
270  void setBinError(int binx, int biny, int binz, double error);
271  void setBinEntries(int bin, double nentries);
272  void setEntries(double nentries);
273  void setBinLabel(int bin, const std::string &label, int axis = 1);
274  void setAxisRange(double xmin, double xmax, int axis = 1);
275  void setAxisTitle(const std::string &title, int axis = 1);
276  void setAxisTimeDisplay(int value, int axis = 1);
277  void setAxisTimeFormat(const char *format = "", int axis = 1);
278 
279 private:
280  void setAxisTimeOffset(double toffset, const char *option="local", int axis = 1);
281 
282 public:
283  void setTitle(const std::string &title);
284 #endif // DQM_ROOT_METHODS
285 
286 private:
288  bool isSoftResetEnabled(void) const
289  { return refvalue_ != 0; }
290 
292  bool isAccumulateEnabled(void) const
293  { return data_.flags & DQMNet::DQM_PROP_ACCUMULATE; }
294 
296  bool markedToDelete(void) const
297  { return data_.flags & DQMNet::DQM_PROP_MARKTODELETE; }
298 
301  void markToDelete(void)
303 
304 private:
306  void resetUpdate(void)
307  { data_.flags &= ~DQMNet::DQM_PROP_NEW; }
308 
310  bool resetMe(void) const
311  { return data_.flags & DQMNet::DQM_PROP_RESET; }
312 
315  void setAccumulate(bool /* flag */)
316  { data_.flags |= DQMNet::DQM_PROP_ACCUMULATE; }
317 
318  TAxis *getAxis(const char *func, int axis) const;
319 
320  // ------------ Operations for MEs that are normally never reset ---------
321 public:
322  void softReset(void);
323 private:
324  void disableSoftReset(void);
325  void addProfiles(TProfile *h1, TProfile *h2, TProfile *sum, float c1, float c2);
326  void addProfiles(TProfile2D *h1, TProfile2D *h2, TProfile2D *sum, float c1, float c2);
327  void copyFunctions(TH1 *from, TH1 *to);
328  void copyFrom(TH1 *from);
329 
330 
331  // --- Operations on MEs that are normally reset at end of monitoring cycle ---
332  void getQReport(bool create, const std::string &qtname, QReport *&qr, DQMNet::QValue *&qv);
333  void addQReport(const DQMNet::QValue &desc, QCriterion *qc);
334  void addQReport(QCriterion *qc);
335  void updateQReportStats(void);
336 
337 public:
338  TObject *getRootObject(void) const;
339  TH1 *getTH1(void) const;
340  TH1F *getTH1F(void) const;
341  TH1S *getTH1S(void) const;
342  TH1D *getTH1D(void) const;
343  TH2F *getTH2F(void) const;
344  TH2S *getTH2S(void) const;
345  TH2D *getTH2D(void) const;
346  TH3F *getTH3F(void) const;
347  TProfile *getTProfile(void) const;
348  TProfile2D *getTProfile2D(void) const;
349 
350  TObject *getRefRootObject(void) const;
351  TH1 *getRefTH1(void) const;
352  TH1F *getRefTH1F(void) const;
353  TH1S *getRefTH1S(void) const;
354  TH1D *getRefTH1D(void) const;
355  TH2F *getRefTH2F(void) const;
356  TH2S *getRefTH2S(void) const;
357  TH2D *getRefTH2D(void) const;
358  TH3F *getRefTH3F(void) const;
359  TProfile *getRefTProfile(void) const;
360  TProfile2D *getRefTProfile2D(void) const;
361 
362  int64_t getIntValue(void) const
363  {
364  assert(kind() == DQM_KIND_INT);
365  return scalar_.num;
366  }
367 
368  double getFloatValue(void) const
369  {
370  assert(kind() == DQM_KIND_REAL);
371  return scalar_.real;
372  }
373 
374  const std::string &getStringValue(void) const
375  {
376  assert(kind() == DQM_KIND_STRING);
377  return scalar_.str;
378  }
379 
380  DQMNet::TagList getTags(void) const // DEPRECATED
381  {
382  DQMNet::TagList tags;
383  if (data_.flags & DQMNet::DQM_PROP_TAGGED)
384  tags.push_back(data_.tag);
385  return tags;
386  }
387 
388  const uint32_t getTag(void) const
389  { return data_.tag; }
390 
391  const uint32_t run(void) const {return data_.run;}
392  const uint32_t lumi(void) const {return data_.lumi;}
393  const uint32_t streamId(void) const {return data_.streamId;}
394  const uint32_t moduleId(void) const {return data_.moduleId;}
395 };
396 
397 #endif // DQMSERVICES_CORE_MONITOR_ELEMENT_H
static const uint32_t DQM_PROP_REPORT_WARN
Definition: DQMNet.h:48
const std::string & getName(void) const
get name of ME
uint32_t moduleId
Definition: DQMNet.h:105
void resetUpdate(void)
reset "was updated" flag
static const uint32_t DQM_PROP_TYPE_TH1S
Definition: DQMNet.h:33
bool markedToDelete(void) const
true if ME is marked for deletion
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)
Definition: DQMNet.h:23
void setLumi(uint32_t ls)
uint32_t flags
Definition: DQMNet.h:99
bool hasError(void) 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
void Fill(float x)
static const uint32_t DQM_PROP_EFFICIENCY_PLOT
Definition: DQMNet.h:64
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 update(void)
Mark the object updated.
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)
const uint32_t getTag(void) const
void Fill(long long x)
bool wasUpdated(void) const
true if ME was updated in last monitoring cycle
static const uint32_t DQM_PROP_ACCUMULATE
Definition: DQMNet.h:56
bool getLumiFlag(void) const
true if ME is meant to be stored for each luminosity section
const uint32_t lumi(void) const
void Fill(int x)
const std::string & getPathname(void) const
get pathname of parent folder
bool hasWarning(void) const
true if at least of one of the quality tests returned a warning
static const uint32_t DQM_PROP_TYPE_INT
Definition: DQMNet.h:29
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
DQMNet::TagList getTags(void) const
void setAccumulate(bool)
uint32_t lumi
Definition: DQMNet.h:103
double getFloatValue(void) const
static const uint32_t DQM_PROP_REPORT_ERROR
Definition: DQMNet.h:47
std::vector< QReport >::const_iterator QReportIterator
Definition: value.py:1
static const uint32_t DQM_PROP_REPORT_OTHER
Definition: DQMNet.h:49
Kind kind(void) const
Get the type of the monitor element.
static const uint32_t DQM_PROP_TYPE_TH1D
Definition: DQMNet.h:34
uint32_t flags(void) const
Get the object flags.
const std::string getFullname(void) const
get full name of ME including Pathname
const std::string & getStringValue(void) const
bool isAccumulateEnabled(void) const
whether ME contents should be accumulated over multiple monitoring periods; default: false ...
const uint32_t streamId(void) const
void Fill(unsigned int x)
void Fill(char x)
std::string objname
Definition: DQMNet.h:107
DQMNet::CoreObject data_
bin
set the eta bin as selection string.
void markToDelete(void)
doFill
Definition: cuy.py:574
void Fill(long x)
def ls(path, rec=False)
Definition: eostools.py:348
std::vector< uint32_t > TagList
Definition: DQMNet.h:85
void Fill(unsigned long x)
bool isEfficiency(void) const
int64_t getIntValue(void) const
void setResetMe(bool)
bool hasOtherReport(void) const
true if at least of one of the tests returned some other (non-ok) status
bool resetMe(void) const
true if ME should be reset at end of monitoring cycle
const uint32_t moduleId(void) const
static bool setOrder(const CoreObject &a, const CoreObject &b)
Definition: DQMNet.h:180
bool isSoftResetEnabled(void) const
whether soft-reset is enabled; default is false
static const uint32_t DQM_PROP_TYPE_TH2S
Definition: DQMNet.h:36
void Fill(unsigned char x)
const uint32_t run(void) const
auto zw(V v) -> Vec2< typename std::remove_reference< decltype(v[0])>::type >
Definition: ExtVec.h:75
void setEfficiencyFlag(void)
static const uint32_t DQM_PROP_TYPE_STRING
Definition: DQMNet.h:31
void Reset(std::vector< TH2F > &depth)
static const uint32_t DQM_PROP_NEW
Definition: DQMNet.h:59
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
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
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