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 flag)
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
00139
00140
00141 template <typename T>
00142 struct fits_in_int64_t
00143 {
00144 int checkArray[sizeof(int64_t) - sizeof(T) + 1];
00145 };
00146
00147 void Fill(long long x) { fits_in_int64_t<long long>(); doFill(static_cast<int64_t>(x)); }
00148 void Fill(unsigned long long x) { fits_in_int64_t<unsigned long long>(); doFill(static_cast<int64_t>(x)); }
00149 void Fill(unsigned long x) { fits_in_int64_t<unsigned long>(); doFill(static_cast<int64_t>(x)); }
00150 void Fill(long x) { fits_in_int64_t<long>(); doFill(static_cast<int64_t>(x)); }
00151 void Fill(unsigned int x) { fits_in_int64_t<unsigned int>(); doFill(static_cast<int64_t>(x)); }
00152 void Fill(int x) { fits_in_int64_t<int>(); doFill(static_cast<int64_t>(x)); }
00153 void Fill(short x) { fits_in_int64_t<short>(); doFill(static_cast<int64_t>(x)); }
00154 void Fill(unsigned short x) { fits_in_int64_t<unsigned short>(); doFill(static_cast<int64_t>(x)); }
00155 void Fill(char x) { fits_in_int64_t<char>(); doFill(static_cast<int64_t>(x)); }
00156 void Fill(unsigned char x) { fits_in_int64_t<unsigned char>(); doFill(static_cast<int64_t>(x)); }
00157
00158 void Fill(float x) { Fill(static_cast<double>(x)); }
00159 void Fill(double x);
00160 void Fill(std::string &value);
00161
00162 void Fill(double x, double yw);
00163 void Fill(double x, double y, double zw);
00164 void Fill(double x, double y, double z, double w);
00165 void ShiftFillLast(double y, double ye = 0., int32_t xscale = 1);
00166 void Reset(void);
00167
00168 std::string valueString(void) const;
00169 std::string tagString(void) const;
00170 std::string tagLabelString(void) const;
00171 std::string qualityTagString(const DQMNet::QValue &qv) const;
00172 void packScalarData(std::string &into, const char *prefix) const;
00173 void packQualityData(std::string &into) const;
00174
00176 bool hasError(void) const
00177 { return data_.flags & DQMNet::DQM_PROP_REPORT_ERROR; }
00178
00180 bool hasWarning(void) const
00181 { return data_.flags & DQMNet::DQM_PROP_REPORT_WARN; }
00182
00184 bool hasOtherReport(void) const
00185 { return data_.flags & DQMNet::DQM_PROP_REPORT_OTHER; }
00186
00188 const QReport *getQReport(const std::string &qtname) const;
00189
00191 std::vector<QReport *> getQReports(void) const;
00192
00194 std::vector<QReport *> getQWarnings(void) const;
00195
00197 std::vector<QReport *> getQErrors(void) const;
00198
00201 std::vector<QReport *> getQOthers(void) const;
00202
00204 void runQTests(void);
00205
00206 private:
00207 void doFill(int64_t x);
00208 void incompatible(const char *func) const;
00209 TH1 *accessRootObject(const char *func, int reqdim) const;
00210
00211 public:
00212 #if DQM_ROOT_METHODS
00213 double getMean(int axis = 1) const;
00214 double getMeanError(int axis = 1) const;
00215 double getRMS(int axis = 1) const;
00216 double getRMSError(int axis = 1) const;
00217 int getNbinsX(void) const;
00218 int getNbinsY(void) const;
00219 int getNbinsZ(void) const;
00220 double getBinContent(int binx) const;
00221 double getBinContent(int binx, int biny) const;
00222 double getBinContent(int binx, int biny, int binz) const;
00223 double getBinError(int binx) const;
00224 double getBinError(int binx, int biny) const;
00225 double getBinError(int binx, int biny, int binz) const;
00226 double getEntries(void) const;
00227 double getBinEntries(int bin) const;
00228
00229 private:
00230 double getYmin(void) const;
00231 double getYmax(void) const;
00232
00233 public:
00234 std::string getAxisTitle(int axis = 1) const;
00235 std::string getTitle(void) const;
00236 void setBinContent(int binx, double content);
00237 void setBinContent(int binx, int biny, double content);
00238 void setBinContent(int binx, int biny, int binz, double content);
00239 void setBinError(int binx, double error);
00240 void setBinError(int binx, int biny, double error);
00241 void setBinError(int binx, int biny, int binz, double error);
00242 void setBinEntries(int bin, double nentries);
00243 void setEntries(double nentries);
00244 void setBinLabel(int bin, const std::string &label, int axis = 1);
00245 void setAxisRange(double xmin, double xmax, int axis = 1);
00246 void setAxisTitle(const std::string &title, int axis = 1);
00247 void setAxisTimeDisplay(int value, int axis = 1);
00248 void setAxisTimeFormat(const char *format = "", int axis = 1);
00249
00250 private:
00251 void setAxisTimeOffset(double toffset, const char *option="local", int axis = 1);
00252
00253 public:
00254 void setTitle(const std::string &title);
00255 #endif // DQM_ROOT_METHODS
00256
00257 private:
00259 bool isSoftResetEnabled(void) const
00260 { return refvalue_ != 0; }
00261
00263 bool isAccumulateEnabled(void) const
00264 { return data_.flags & DQMNet::DQM_PROP_ACCUMULATE; }
00265
00266 private:
00268 void resetUpdate(void)
00269 { data_.flags &= ~DQMNet::DQM_PROP_NEW; }
00270
00272 bool resetMe(void) const
00273 { return data_.flags & DQMNet::DQM_PROP_RESET; }
00274
00277 void setAccumulate(bool flag)
00278 { data_.flags |= DQMNet::DQM_PROP_ACCUMULATE; }
00279
00280 TAxis *getAxis(const char *func, int axis) const;
00281
00282
00283 void softReset(void);
00284 void disableSoftReset(void);
00285 void addProfiles(TProfile *h1, TProfile *h2, TProfile *sum, float c1, float c2);
00286 void addProfiles(TProfile2D *h1, TProfile2D *h2, TProfile2D *sum, float c1, float c2);
00287 void copyFunctions(TH1 *from, TH1 *to);
00288 void copyFrom(TH1 *from);
00289
00290
00291
00292 void getQReport(bool create, const std::string &qtname, QReport *&qr, DQMNet::QValue *&qv);
00293 void addQReport(const DQMNet::QValue &desc, QCriterion *qc);
00294 void addQReport(QCriterion *qc);
00295 void updateQReportStats(void);
00296
00297 public:
00298 TObject *getRootObject(void) const;
00299 TH1 *getTH1(void) const;
00300 TH1F *getTH1F(void) const;
00301 TH1S *getTH1S(void) const;
00302 TH1D *getTH1D(void) const;
00303 TH2F *getTH2F(void) const;
00304 TH2S *getTH2S(void) const;
00305 TH2D *getTH2D(void) const;
00306 TH3F *getTH3F(void) const;
00307 TProfile *getTProfile(void) const;
00308 TProfile2D *getTProfile2D(void) const;
00309
00310 TObject *getRefRootObject(void) const;
00311 TH1 *getRefTH1(void) const;
00312 TH1F *getRefTH1F(void) const;
00313 TH1S *getRefTH1S(void) const;
00314 TH1D *getRefTH1D(void) const;
00315 TH2F *getRefTH2F(void) const;
00316 TH2S *getRefTH2S(void) const;
00317 TH2D *getRefTH2D(void) const;
00318 TH3F *getRefTH3F(void) const;
00319 TProfile *getRefTProfile(void) const;
00320 TProfile2D *getRefTProfile2D(void) const;
00321
00322 int64_t getIntValue(void) const
00323 {
00324 assert(kind() == DQM_KIND_INT);
00325 return scalar_.num;
00326 }
00327
00328 double getFloatValue(void) const
00329 {
00330 assert(kind() == DQM_KIND_REAL);
00331 return scalar_.real;
00332 }
00333
00334 const std::string &getStringValue(void) const
00335 {
00336 assert(kind() == DQM_KIND_STRING);
00337 return scalar_.str;
00338 }
00339
00340 DQMNet::TagList getTags(void) const
00341 {
00342 DQMNet::TagList tags;
00343 if (data_.flags & DQMNet::DQM_PROP_TAGGED)
00344 tags.push_back(data_.tag);
00345 return tags;
00346 }
00347
00348 const uint32_t getTag(void) const
00349 { return data_.tag; }
00350 };
00351
00352 #endif // DQMSERVICES_CORE_MONITOR_ELEMENT_H