00001 #ifndef DQMSERVICES_CORE_MONITOR_ELEMENT_H
00002 # define DQMSERVICES_CORE_MONITOR_ELEMENT_H
00003
00004 # include "DQMServices/Core/interface/DQMNet.h"
00005 # include "DQMServices/Core/interface/QReport.h"
00006 # include "TF1.h"
00007 # include "TH1F.h"
00008 # include "TH1S.h"
00009 # include "TH1D.h"
00010 # include "TH2F.h"
00011 # include "TH2S.h"
00012 # include "TH2D.h"
00013 # include "TH3F.h"
00014 # include "TProfile.h"
00015 # include "TProfile2D.h"
00016 # include "TObjString.h"
00017 # include "TAxis.h"
00018 # include <sys/time.h>
00019 # include <string>
00020 # include <set>
00021 # include <map>
00022 # include <sstream>
00023 # include <iomanip>
00024 # include <cassert>
00025 # include <stdint.h>
00026
00027 # ifndef DQM_ROOT_METHODS
00028 # define DQM_ROOT_METHODS 1
00029 # endif
00030
00031 class QCriterion;
00032
00034 class MonitorElement
00035 {
00036 friend class DQMStore;
00037 friend class DQMService;
00038 public:
00039 struct Scalar
00040 {
00041 int64_t num;
00042 double real;
00043 std::string str;
00044 };
00045
00046 enum Kind
00047 {
00048 DQM_KIND_INVALID = DQMNet::DQM_PROP_TYPE_INVALID,
00049 DQM_KIND_INT = DQMNet::DQM_PROP_TYPE_INT,
00050 DQM_KIND_REAL = DQMNet::DQM_PROP_TYPE_REAL,
00051 DQM_KIND_STRING = DQMNet::DQM_PROP_TYPE_STRING,
00052 DQM_KIND_TH1F = DQMNet::DQM_PROP_TYPE_TH1F,
00053 DQM_KIND_TH1S = DQMNet::DQM_PROP_TYPE_TH1S,
00054 DQM_KIND_TH1D = DQMNet::DQM_PROP_TYPE_TH1D,
00055 DQM_KIND_TH2F = DQMNet::DQM_PROP_TYPE_TH2F,
00056 DQM_KIND_TH2S = DQMNet::DQM_PROP_TYPE_TH2S,
00057 DQM_KIND_TH2D = DQMNet::DQM_PROP_TYPE_TH2D,
00058 DQM_KIND_TH3F = DQMNet::DQM_PROP_TYPE_TH3F,
00059 DQM_KIND_TPROFILE = DQMNet::DQM_PROP_TYPE_TPROF,
00060 DQM_KIND_TPROFILE2D = DQMNet::DQM_PROP_TYPE_TPROF2D
00061 };
00062
00063 typedef std::vector<QReport>::const_iterator QReportIterator;
00064
00065 private:
00066 DQMNet::CoreObject data_;
00067 Scalar scalar_;
00068 TH1 *object_;
00069 TH1 *reference_;
00070 TH1 *refvalue_;
00071 std::vector<QReport> qreports_;
00072
00073 MonitorElement *initialise(Kind kind);
00074 MonitorElement *initialise(Kind kind, TH1 *rootobj);
00075 MonitorElement *initialise(Kind kind, const std::string &value);
00076
00077 public:
00078 MonitorElement(void);
00079 MonitorElement(const std::string *path, const std::string &name);
00080 MonitorElement(const MonitorElement &);
00081 MonitorElement &operator=(const MonitorElement &);
00082 ~MonitorElement(void);
00083
00085 bool operator<(const MonitorElement &x) const
00086 {
00087 return DQMNet::setOrder(data_, x.data_);
00088 }
00089
00091 Kind kind(void) const
00092 { return Kind(data_.flags & DQMNet::DQM_PROP_TYPE_MASK); }
00093
00095 uint32_t flags(void) const
00096 { return data_.flags; }
00097
00099 const std::string &getName(void) const
00100 { return data_.objname; }
00101
00103 const std::string &getPathname(void) const
00104 { return *data_.dirname; }
00105
00107 const std::string getFullname(void) const
00108 {
00109 std::string path;
00110 path.reserve(data_.dirname->size() + data_.objname.size() + 2);
00111 path += *data_.dirname;
00112 if (! data_.dirname->empty())
00113 path += '/';
00114 path += data_.objname;
00115 return path;
00116 }
00117
00119 bool wasUpdated(void) const
00120 { return data_.flags & DQMNet::DQM_PROP_NEW; }
00121
00123 void update(void)
00124 { data_.flags |= DQMNet::DQM_PROP_NEW; }
00125
00128 void setResetMe(bool )
00129 { data_.flags |= DQMNet::DQM_PROP_RESET; }
00130
00132 bool getLumiFlag(void) const
00133 { return data_.flags & DQMNet::DQM_PROP_LUMI; }
00134
00136 void setLumiFlag(void)
00137 { data_.flags |= DQMNet::DQM_PROP_LUMI; }
00138
00141 void setEfficiencyFlag(void)
00142 { data_.flags |= DQMNet::DQM_PROP_EFFICIENCY_PLOT; }
00143
00144
00145
00146 template <typename T>
00147 struct fits_in_int64_t
00148 {
00149 int checkArray[sizeof(int64_t) - sizeof(T) + 1];
00150 };
00151
00152 void Fill(long long x) { fits_in_int64_t<long long>(); doFill(static_cast<int64_t>(x)); }
00153 void Fill(unsigned long long x) { fits_in_int64_t<unsigned long long>(); doFill(static_cast<int64_t>(x)); }
00154 void Fill(unsigned long x) { fits_in_int64_t<unsigned long>(); doFill(static_cast<int64_t>(x)); }
00155 void Fill(long x) { fits_in_int64_t<long>(); doFill(static_cast<int64_t>(x)); }
00156 void Fill(unsigned int x) { fits_in_int64_t<unsigned int>(); doFill(static_cast<int64_t>(x)); }
00157 void Fill(int x) { fits_in_int64_t<int>(); doFill(static_cast<int64_t>(x)); }
00158 void Fill(short x) { fits_in_int64_t<short>(); doFill(static_cast<int64_t>(x)); }
00159 void Fill(unsigned short x) { fits_in_int64_t<unsigned short>(); doFill(static_cast<int64_t>(x)); }
00160 void Fill(char x) { fits_in_int64_t<char>(); doFill(static_cast<int64_t>(x)); }
00161 void Fill(unsigned char x) { fits_in_int64_t<unsigned char>(); doFill(static_cast<int64_t>(x)); }
00162
00163 void Fill(float x) { Fill(static_cast<double>(x)); }
00164 void Fill(double x);
00165 void Fill(std::string &value);
00166
00167 void Fill(double x, double yw);
00168 void Fill(double x, double y, double zw);
00169 void Fill(double x, double y, double z, double w);
00170 void ShiftFillLast(double y, double ye = 0., int32_t xscale = 1);
00171 void Reset(void);
00172
00173 std::string valueString(void) const;
00174 std::string tagString(void) const;
00175 std::string tagLabelString(void) const;
00176 std::string effLabelString(void) const;
00177 std::string qualityTagString(const DQMNet::QValue &qv) const;
00178 void packScalarData(std::string &into, const char *prefix) const;
00179 void packQualityData(std::string &into) const;
00180
00182 bool hasError(void) const
00183 { return data_.flags & DQMNet::DQM_PROP_REPORT_ERROR; }
00184
00186 bool hasWarning(void) const
00187 { return data_.flags & DQMNet::DQM_PROP_REPORT_WARN; }
00188
00190 bool hasOtherReport(void) const
00191 { return data_.flags & DQMNet::DQM_PROP_REPORT_OTHER; }
00192
00195 bool isEfficiency(void) const
00196 { return data_.flags & DQMNet::DQM_PROP_EFFICIENCY_PLOT; }
00197
00199 const QReport *getQReport(const std::string &qtname) const;
00200
00202 std::vector<QReport *> getQReports(void) const;
00203
00205 std::vector<QReport *> getQWarnings(void) const;
00206
00208 std::vector<QReport *> getQErrors(void) const;
00209
00212 std::vector<QReport *> getQOthers(void) const;
00213
00215 void runQTests(void);
00216
00217 private:
00218 void doFill(int64_t x);
00219 void incompatible(const char *func) const;
00220 TH1 *accessRootObject(const char *func, int reqdim) const;
00221
00222 public:
00223 #if DQM_ROOT_METHODS
00224 double getMean(int axis = 1) const;
00225 double getMeanError(int axis = 1) const;
00226 double getRMS(int axis = 1) const;
00227 double getRMSError(int axis = 1) const;
00228 int getNbinsX(void) const;
00229 int getNbinsY(void) const;
00230 int getNbinsZ(void) const;
00231 double getBinContent(int binx) const;
00232 double getBinContent(int binx, int biny) const;
00233 double getBinContent(int binx, int biny, int binz) const;
00234 double getBinError(int binx) const;
00235 double getBinError(int binx, int biny) const;
00236 double getBinError(int binx, int biny, int binz) const;
00237 double getEntries(void) const;
00238 double getBinEntries(int bin) const;
00239
00240 private:
00241 double getYmin(void) const;
00242 double getYmax(void) const;
00243
00244 public:
00245 std::string getAxisTitle(int axis = 1) const;
00246 std::string getTitle(void) const;
00247 void setBinContent(int binx, double content);
00248 void setBinContent(int binx, int biny, double content);
00249 void setBinContent(int binx, int biny, int binz, double content);
00250 void setBinError(int binx, double error);
00251 void setBinError(int binx, int biny, double error);
00252 void setBinError(int binx, int biny, int binz, double error);
00253 void setBinEntries(int bin, double nentries);
00254 void setEntries(double nentries);
00255 void setBinLabel(int bin, const std::string &label, int axis = 1);
00256 void setAxisRange(double xmin, double xmax, int axis = 1);
00257 void setAxisTitle(const std::string &title, int axis = 1);
00258 void setAxisTimeDisplay(int value, int axis = 1);
00259 void setAxisTimeFormat(const char *format = "", int axis = 1);
00260
00261 private:
00262 void setAxisTimeOffset(double toffset, const char *option="local", int axis = 1);
00263
00264 public:
00265 void setTitle(const std::string &title);
00266 #endif // DQM_ROOT_METHODS
00267
00268 private:
00270 bool isSoftResetEnabled(void) const
00271 { return refvalue_ != 0; }
00272
00274 bool isAccumulateEnabled(void) const
00275 { return data_.flags & DQMNet::DQM_PROP_ACCUMULATE; }
00276
00277 private:
00279 void resetUpdate(void)
00280 { data_.flags &= ~DQMNet::DQM_PROP_NEW; }
00281
00283 bool resetMe(void) const
00284 { return data_.flags & DQMNet::DQM_PROP_RESET; }
00285
00288 void setAccumulate(bool )
00289 { data_.flags |= DQMNet::DQM_PROP_ACCUMULATE; }
00290
00291 TAxis *getAxis(const char *func, int axis) const;
00292
00293
00294 void softReset(void);
00295 void disableSoftReset(void);
00296 void addProfiles(TProfile *h1, TProfile *h2, TProfile *sum, float c1, float c2);
00297 void addProfiles(TProfile2D *h1, TProfile2D *h2, TProfile2D *sum, float c1, float c2);
00298 void copyFunctions(TH1 *from, TH1 *to);
00299 void copyFrom(TH1 *from);
00300
00301
00302
00303 void getQReport(bool create, const std::string &qtname, QReport *&qr, DQMNet::QValue *&qv);
00304 void addQReport(const DQMNet::QValue &desc, QCriterion *qc);
00305 void addQReport(QCriterion *qc);
00306 void updateQReportStats(void);
00307
00308 public:
00309 TObject *getRootObject(void) const;
00310 TH1 *getTH1(void) const;
00311 TH1F *getTH1F(void) const;
00312 TH1S *getTH1S(void) const;
00313 TH1D *getTH1D(void) const;
00314 TH2F *getTH2F(void) const;
00315 TH2S *getTH2S(void) const;
00316 TH2D *getTH2D(void) const;
00317 TH3F *getTH3F(void) const;
00318 TProfile *getTProfile(void) const;
00319 TProfile2D *getTProfile2D(void) const;
00320
00321 TObject *getRefRootObject(void) const;
00322 TH1 *getRefTH1(void) const;
00323 TH1F *getRefTH1F(void) const;
00324 TH1S *getRefTH1S(void) const;
00325 TH1D *getRefTH1D(void) const;
00326 TH2F *getRefTH2F(void) const;
00327 TH2S *getRefTH2S(void) const;
00328 TH2D *getRefTH2D(void) const;
00329 TH3F *getRefTH3F(void) const;
00330 TProfile *getRefTProfile(void) const;
00331 TProfile2D *getRefTProfile2D(void) const;
00332
00333 int64_t getIntValue(void) const
00334 {
00335 assert(kind() == DQM_KIND_INT);
00336 return scalar_.num;
00337 }
00338
00339 double getFloatValue(void) const
00340 {
00341 assert(kind() == DQM_KIND_REAL);
00342 return scalar_.real;
00343 }
00344
00345 const std::string &getStringValue(void) const
00346 {
00347 assert(kind() == DQM_KIND_STRING);
00348 return scalar_.str;
00349 }
00350
00351 DQMNet::TagList getTags(void) const
00352 {
00353 DQMNet::TagList tags;
00354 if (data_.flags & DQMNet::DQM_PROP_TAGGED)
00355 tags.push_back(data_.tag);
00356 return tags;
00357 }
00358
00359 const uint32_t getTag(void) const
00360 { return data_.tag; }
00361 };
00362
00363 #endif // DQMSERVICES_CORE_MONITOR_ELEMENT_H