CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/DQMServices/Core/interface/DQMStore.h

Go to the documentation of this file.
00001 #ifndef DQMSERVICES_CORE_DQM_STORE_H
00002 # define DQMSERVICES_CORE_DQM_STORE_H
00003 
00004 # if __GNUC__ && ! defined DQM_DEPRECATED
00005 #  define DQM_DEPRECATED __attribute__((deprecated))
00006 # endif
00007 
00008 # include "DQMServices/Core/interface/DQMDefinitions.h"
00009 # include "classlib/utils/Regexp.h"
00010 # include <vector>
00011 # include <string>
00012 # include <list>
00013 # include <map>
00014 # include <set>
00015 # include <execinfo.h>
00016 # include <stdio.h>
00017 # include <stdlib.h>
00018 # include <cxxabi.h>
00019 
00020 namespace edm { class DQMHttpSource; class ParameterSet; class ActivityRegistry;}
00021 namespace lat { class Regexp; }
00022 
00023 class MonitorElement;
00024 class QCriterion;
00025 class TFile;
00026 class TObject;
00027 class TH1;
00028 class TObjString;
00029 class TH1F;
00030 class TH1S;
00031 class TH1D;
00032 class TH2F;
00033 class TH2S;
00034 class TH2D;
00035 class TH3F;
00036 class TProfile;
00037 class TProfile2D;
00038 
00043 class fastmatch
00044 {
00045 private:
00046   enum MatchingHeuristicEnum { UseFull, OneStarStart, OneStarEnd, TwoStar };
00047 
00048 public:
00049   fastmatch (std::string const& _fastString);
00050   ~fastmatch();
00051 
00052   bool match (std::string const& s) const;
00053 
00054 private:
00055   // checks if two strings are equal, starting at the back of the strings
00056   bool compare_strings_reverse (std::string const& pattern,
00057                                 std::string const& input) const;
00058   // checks if two strings are equal, starting at the front of the strings
00059   bool compare_strings (std::string const& pattern,
00060                         std::string const& input) const;
00061 
00062   lat::Regexp * regexp_;
00063   std::string fastString_;
00064   MatchingHeuristicEnum matching_;
00065 };
00066 
00067 class DQMStore
00068 {
00069 public:
00070   enum SaveReferenceTag
00071   {
00072     SaveWithoutReference,
00073     SaveWithReference,
00074     SaveWithReferenceForQTest
00075   };
00076   enum OpenRunDirs
00077   {
00078     KeepRunDirs,
00079     StripRunDirs
00080   };
00081 
00082   //-------------------------------------------------------------------------
00083   // ---------------------- Constructors ------------------------------------
00084   DQMStore(const edm::ParameterSet &pset, edm::ActivityRegistry&);
00085   DQMStore(const edm::ParameterSet &pset);
00086   ~DQMStore(void);
00087 
00088   //-------------------------------------------------------------------------
00089   void                          setVerbose(unsigned level);
00090 
00091   // ---------------------- public navigation -------------------------------
00092   const std::string &           pwd(void) const;
00093   void                          cd(void);
00094   void                          cd(const std::string &subdir);
00095   void                          setCurrentFolder(const std::string &fullpath);
00096   void                          goUp(void);
00097 
00098   bool                          dirExists(const std::string &path) const;
00099 
00100   //-------------------------------------------------------------------------
00101   // ---------------------- public ME booking -------------------------------
00102 
00103   MonitorElement *              bookInt      (const char *name);
00104   MonitorElement *              bookInt      (const std::string &name);
00105 
00106   MonitorElement *              bookFloat    (const char *name);
00107   MonitorElement *              bookFloat    (const std::string &name);
00108 
00109   MonitorElement *              bookString   (const char *name,
00110                                               const char *value);
00111   MonitorElement *              bookString   (const std::string &name,
00112                                               const std::string &value);
00113 
00114   MonitorElement *              book1D       (const char *name,
00115                                               const char *title,
00116                                               int nchX, double lowX, double highX);
00117   MonitorElement *              book1D       (const std::string &name,
00118                                               const std::string &title,
00119                                               int nchX, double lowX, double highX);
00120   MonitorElement *              book1D       (const char *name,
00121                                               const char *title,
00122                                               int nchX, float *xbinsize);
00123   MonitorElement *              book1D       (const std::string &name,
00124                                               const std::string &title,
00125                                               int nchX, float *xbinsize);
00126   MonitorElement *              book1D       (const char *name, TH1F *h);
00127   MonitorElement *              book1D       (const std::string &name, TH1F *h);
00128 
00129   MonitorElement *              book1S       (const char *name,
00130                                               const char *title,
00131                                               int nchX, double lowX, double highX);
00132   MonitorElement *              book1S       (const std::string &name,
00133                                               const std::string &title,
00134                                               int nchX, double lowX, double highX);
00135   MonitorElement *              book1S       (const char *name,
00136                                               const char *title,
00137                                               int nchX, float *xbinsize);
00138   MonitorElement *              book1S       (const std::string &name,
00139                                               const std::string &title,
00140                                               int nchX, float *xbinsize);
00141   MonitorElement *              book1S       (const char *name, TH1S *h);
00142   MonitorElement *              book1S       (const std::string &name, TH1S *h);
00143 
00144   MonitorElement *              book1DD       (const char *name,
00145                                                const char *title,
00146                                                int nchX, double lowX, double highX);
00147   MonitorElement *              book1DD       (const std::string &name,
00148                                                const std::string &title,
00149                                                int nchX, double lowX, double highX);
00150   MonitorElement *              book1DD       (const char *name,
00151                                                const char *title,
00152                                                int nchX, float *xbinsize);
00153   MonitorElement *              book1DD       (const std::string &name,
00154                                                const std::string &title,
00155                                                int nchX, float *xbinsize);
00156   MonitorElement *              book1DD       (const char *name, TH1D *h);
00157   MonitorElement *              book1DD       (const std::string &name, TH1D *h);
00158 
00159   MonitorElement *              book2D       (const char *name,
00160                                               const char *title,
00161                                               int nchX, double lowX, double highX,
00162                                               int nchY, double lowY, double highY);
00163   MonitorElement *              book2D       (const std::string &name,
00164                                               const std::string &title,
00165                                               int nchX, double lowX, double highX,
00166                                               int nchY, double lowY, double highY);
00167   MonitorElement *              book2D       (const char *name,
00168                                               const char *title,
00169                                               int nchX, float *xbinsize,
00170                                               int nchY, float *ybinsize);
00171   MonitorElement *              book2D       (const std::string &name,
00172                                               const std::string &title,
00173                                               int nchX, float *xbinsize,
00174                                               int nchY, float *ybinsize);
00175   MonitorElement *              book2D       (const char *name, TH2F *h);
00176   MonitorElement *              book2D       (const std::string &name, TH2F *h);
00177 
00178   MonitorElement *              book2S       (const char *name,
00179                                               const char *title,
00180                                               int nchX, double lowX, double highX,
00181                                               int nchY, double lowY, double highY);
00182   MonitorElement *              book2S       (const std::string &name,
00183                                               const std::string &title,
00184                                               int nchX, double lowX, double highX,
00185                                               int nchY, double lowY, double highY);
00186   MonitorElement *              book2S       (const char *name,
00187                                               const char *title,
00188                                               int nchX, float *xbinsize,
00189                                               int nchY, float *ybinsize);
00190   MonitorElement *              book2S       (const std::string &name,
00191                                               const std::string &title,
00192                                               int nchX, float *xbinsize,
00193                                               int nchY, float *ybinsize);
00194   MonitorElement *              book2S       (const char *name, TH2S *h);
00195   MonitorElement *              book2S       (const std::string &name, TH2S *h);
00196 
00197   MonitorElement *              book2DD       (const char *name,
00198                                                const char *title,
00199                                                int nchX, double lowX, double highX,
00200                                                int nchY, double lowY, double highY);
00201   MonitorElement *              book2DD       (const std::string &name,
00202                                                const std::string &title,
00203                                                int nchX, double lowX, double highX,
00204                                                int nchY, double lowY, double highY);
00205   MonitorElement *              book2DD       (const char *name,
00206                                                const char *title,
00207                                                int nchX, float *xbinsize,
00208                                                int nchY, float *ybinsize);
00209   MonitorElement *              book2DD       (const std::string &name,
00210                                                const std::string &title,
00211                                                int nchX, float *xbinsize,
00212                                                int nchY, float *ybinsize);
00213   MonitorElement *              book2DD       (const char *name, TH2D *h);
00214   MonitorElement *              book2DD       (const std::string &name, TH2D *h);
00215 
00216   MonitorElement *              book3D       (const char *name,
00217                                               const char *title,
00218                                               int nchX, double lowX, double highX,
00219                                               int nchY, double lowY, double highY,
00220                                               int nchZ, double lowZ, double highZ);
00221   MonitorElement *              book3D       (const std::string &name,
00222                                               const std::string &title,
00223                                               int nchX, double lowX, double highX,
00224                                               int nchY, double lowY, double highY,
00225                                               int nchZ, double lowZ, double highZ);
00226   MonitorElement *              book3D       (const char *name, TH3F *h);
00227   MonitorElement *              book3D       (const std::string &name, TH3F *h);
00228 
00229   MonitorElement *              bookProfile  (const char *name,
00230                                               const char *title,
00231                                               int nchX, double lowX, double highX,
00232                                               int nchY, double lowY, double highY,
00233                                               const char *option = "s");
00234   MonitorElement *              bookProfile  (const std::string &name,
00235                                               const std::string &title,
00236                                               int nchX, double lowX, double highX,
00237                                               int nchY, double lowY, double highY,
00238                                               const char *option = "s");
00239   MonitorElement *              bookProfile  (const char *name,
00240                                               const char *title,
00241                                               int nchX, double lowX, double highX,
00242                                               double lowY, double highY,
00243                                               const char *option = "s");
00244   MonitorElement *              bookProfile  (const std::string &name,
00245                                               const std::string &title,
00246                                               int nchX, double lowX, double highX,
00247                                               double lowY, double highY,
00248                                               const char *option = "s");
00249   MonitorElement *              bookProfile  (const char *name,
00250                                               const char *title,
00251                                               int nchX, double *xbinsize,
00252                                               int nchY, double lowY, double highY,
00253                                               const char *option = "s");
00254   MonitorElement *              bookProfile  (const std::string &name,
00255                                               const std::string &title,
00256                                               int nchX, double *xbinsize,
00257                                               int nchY, double lowY, double highY,
00258                                               const char *option = "s");
00259   MonitorElement *              bookProfile  (const char *name,
00260                                               const char *title,
00261                                               int nchX, double *xbinsize,
00262                                               double lowY, double highY,
00263                                               const char *option = "s");
00264   MonitorElement *              bookProfile  (const std::string &name,
00265                                               const std::string &title,
00266                                               int nchX, double *xbinsize,
00267                                               double lowY, double highY,
00268                                               const char *option = "s");
00269   MonitorElement *              bookProfile  (const char *name, TProfile *h);
00270   MonitorElement *              bookProfile  (const std::string &name, TProfile *h);
00271 
00272   MonitorElement *              bookProfile2D(const char *name,
00273                                               const char *title,
00274                                               int nchX, double lowX, double highX,
00275                                               int nchY, double lowY, double highY,
00276                                               int nchZ, double lowZ, double highZ,
00277                                               const char *option = "s");
00278   MonitorElement *              bookProfile2D(const std::string &name,
00279                                               const std::string &title,
00280                                               int nchX, double lowX, double highX,
00281                                               int nchY, double lowY, double highY,
00282                                               int nchZ, double lowZ, double highZ,
00283                                               const char *option = "s");
00284   MonitorElement *              bookProfile2D(const char *name,
00285                                               const char *title,
00286                                               int nchX, double lowX, double highX,
00287                                               int nchY, double lowY, double highY,
00288                                               double lowZ, double highZ,
00289                                               const char *option = "s");
00290   MonitorElement *              bookProfile2D(const std::string &name,
00291                                               const std::string &title,
00292                                               int nchX, double lowX, double highX,
00293                                               int nchY, double lowY, double highY,
00294                                               double lowZ, double highZ,
00295                                               const char *option = "s");
00296   MonitorElement *              bookProfile2D(const char *name, TProfile2D *h);
00297   MonitorElement *              bookProfile2D(const std::string &name, TProfile2D *h);
00298 
00299   //-------------------------------------------------------------------------
00300   // ---------------------- public tagging ----------------------------------
00301   void                          tag(MonitorElement *me, unsigned int myTag);
00302   void                          tag(const std::string &path, unsigned int myTag);
00303   void                          tagContents(const std::string &path, unsigned int myTag);
00304   void                          tagAllContents(const std::string &path, unsigned int myTag);
00305 
00306   //-------------------------------------------------------------------------
00307   // ---------------------- public ME getters -------------------------------
00308   std::vector<std::string>      getSubdirs(void) const;
00309   std::vector<std::string>      getMEs(void) const;
00310   bool                          containsAnyMonitorable(const std::string &path) const;
00311 
00312   MonitorElement *              get(const std::string &path) const;
00313   std::vector<MonitorElement *> get(unsigned int tag) const;
00314   std::vector<MonitorElement *> getContents(const std::string &path) const;
00315   std::vector<MonitorElement *> getContents(const std::string &path, unsigned int tag) const;
00316   void                          getContents(std::vector<std::string> &into, bool showContents = true) const;
00317 
00318   // ---------------------- softReset methods -------------------------------
00319   void                          softReset(MonitorElement *me);
00320   void                          disableSoftReset(MonitorElement *me);
00321 
00322   // ---------------------- Public deleting ---------------------------------
00323   void                          rmdir(const std::string &fullpath);
00324   void                          removeContents(void);
00325   void                          removeContents(const std::string &dir);
00326   void                          removeElement(const std::string &name);
00327   void                          removeElement(const std::string &dir, const std::string &name, bool warning = true);
00328 
00329   //-------------------------------------------------------------------------
00330   // ---------------------- public I/O --------------------------------------
00331   void                          save(const std::string &filename,
00332                                      const std::string &path = "",
00333                                      const std::string &pattern = "",
00334                                      const std::string &rewrite = "",
00335                                      SaveReferenceTag ref = SaveWithReference,
00336                                      int minStatus = dqm::qstatus::STATUS_OK,
00337                                      const std::string &fileupdate = "RECREATE");
00338   bool                          open(const std::string &filename,
00339                                      bool overwrite = false,
00340                                      const std::string &path ="",
00341                                      const std::string &prepend = "",
00342                                      OpenRunDirs stripdirs = KeepRunDirs,
00343                                      bool fileMustExist = true);
00344   bool                          load(const std::string &filename,
00345                                      OpenRunDirs stripdirs = StripRunDirs,
00346                                      bool fileMustExist = true);
00347 
00348   //-------------------------------------------------------------------------
00349   // ---------------------- Public print methods -----------------------------
00350   void                          showDirStructure(void) const;
00351 
00352   // ---------------------- Public check options -----------------------------                                                                                        
00353   bool                         isCollate(void) const;
00354 
00355   //-------------------------------------------------------------------------
00356   // ---------------------- Quality Test methods -----------------------------
00357   QCriterion *                  getQCriterion(const std::string &qtname) const;
00358   QCriterion *                  createQTest(const std::string &algoname, const std::string &qtname);
00359   void                          useQTest(const std::string &dir, const std::string &qtname);
00360   int                           useQTestByMatch(const std::string &pattern, const std::string &qtname);
00361   void                          runQTests(void);
00362   int                           getStatus(const std::string &path = "") const;
00363   void        scaleElements(void);
00364 
00365 private:
00366   // ---------------- Navigation -----------------------
00367   bool                          cdInto(const std::string &path) const;
00368 
00369   // ------------------- Reference ME -------------------------------
00370   bool                          isCollateME(MonitorElement *me) const;
00371 
00372   // ------------------- Private "getters" ------------------------------
00373   bool                          readFile(const std::string &filename,
00374                                          bool overwrite = false,
00375                                          const std::string &path ="",
00376                                          const std::string &prepend = "",
00377                                          OpenRunDirs stripdirs = StripRunDirs,
00378                                          bool fileMustExist = true);
00379   void                          makeDirectory(const std::string &path);
00380   unsigned int                  readDirectory(TFile *file,
00381                                               bool overwrite,
00382                                               const std::string &path,
00383                                               const std::string &prepend,
00384                                               const std::string &curdir,
00385                                               OpenRunDirs stripdirs);
00386 
00387   MonitorElement *              findObject(const std::string &dir, const std::string &name) const;
00388 
00389 public:
00390   void                          getAllTags(std::vector<std::string> &into) const;
00391   std::vector<MonitorElement*>  getAllContents(const std::string &path) const;
00392   std::vector<MonitorElement*>  getMatchingContents(const std::string &pattern, lat::Regexp::Syntax syntaxType = lat::Regexp::Wildcard) const;
00393 private:
00394 
00395   // ---------------- Miscellaneous -----------------------------
00396   void        initializeFrom(const edm::ParameterSet&);
00397   void                          reset(void);
00398   void        forceReset(void);
00399 
00400   bool                          extract(TObject *obj, const std::string &dir, bool overwrite);
00401 
00402   // ---------------------- Booking ------------------------------------
00403   MonitorElement *              initialise(MonitorElement *me, const std::string &path);
00404   MonitorElement *              book(const std::string &dir,
00405                                      const std::string &name,
00406                                      const char *context);
00407   template <class HISTO, class COLLATE>
00408   MonitorElement *              book(const std::string &dir, const std::string &name,
00409                                      const char *context, int kind,
00410                                      HISTO *h, COLLATE collate);
00411 
00412   MonitorElement *              bookInt(const std::string &dir, const std::string &name);
00413   MonitorElement *              bookFloat(const std::string &dir, const std::string &name);
00414   MonitorElement *              bookString(const std::string &dir, const std::string &name, const std::string &value);
00415   MonitorElement *              book1D(const std::string &dir, const std::string &name, TH1F *h);
00416   MonitorElement *              book1S(const std::string &dir, const std::string &name, TH1S *h);
00417   MonitorElement *              book1DD(const std::string &dir, const std::string &name, TH1D *h);
00418   MonitorElement *              book2D(const std::string &dir, const std::string &name, TH2F *h);
00419   MonitorElement *              book2S(const std::string &dir, const std::string &name, TH2S *h);
00420   MonitorElement *              book2DD(const std::string &dir, const std::string &name, TH2D *h);
00421   MonitorElement *              book3D(const std::string &dir, const std::string &name, TH3F *h);
00422   MonitorElement *              bookProfile(const std::string &dir, const std::string &name, TProfile *h);
00423   MonitorElement *              bookProfile2D(const std::string &folder, const std::string &name, TProfile2D *h);
00424 
00425   static bool                   checkBinningMatches(MonitorElement *me, TH1 *h);
00426 
00427   static void                   collate1D(MonitorElement *me, TH1F *h);
00428   static void                   collate1S(MonitorElement *me, TH1S *h);
00429   static void                   collate1DD(MonitorElement *me, TH1D *h);
00430   static void                   collate2D(MonitorElement *me, TH2F *h);
00431   static void                   collate2S(MonitorElement *me, TH2S *h);
00432   static void                   collate2DD(MonitorElement *me, TH2D *h);
00433   static void                   collate3D(MonitorElement *me, TH3F *h);
00434   static void                   collateProfile(MonitorElement *me, TProfile *h);
00435   static void                   collateProfile2D(MonitorElement *me, TProfile2D *h);
00436 
00437   // --- Operations on MEs that are normally reset at end of monitoring cycle ---
00438   void                          setAccumulate(MonitorElement *me, bool flag);
00439 
00440   void print_trace(const std::string &dir, const std::string &name);
00441 
00442   // ----------------------- Unavailable ---------------------------------------
00443   DQMStore(const DQMStore&);
00444   const DQMStore& operator=(const DQMStore&);
00445 
00446   //-------------------------------------------------------------------------------
00447   //-------------------------------------------------------------------------------
00448   typedef std::pair<fastmatch *, QCriterion *>                  QTestSpec;
00449   typedef std::list<QTestSpec>                                          QTestSpecs;
00450   typedef std::set<MonitorElement>                                      MEMap;
00451   typedef std::map<std::string, QCriterion *>                           QCMap;
00452   typedef std::map<std::string, QCriterion *(*)(const std::string &)>   QAMap;
00453  
00454   unsigned                      verbose_;
00455   unsigned                      verboseQT_;
00456   bool                          reset_;
00457   double                                scaleFlag_;
00458   bool                          collateHistograms_;
00459   std::string                   readSelectedDirectory_;
00460 
00461   std::string                   pwd_;
00462   MEMap                         data_;
00463   std::set<std::string>         dirs_;
00464 
00465   QCMap                         qtests_;
00466   QAMap                         qalgos_;
00467   QTestSpecs                    qtestspecs_;
00468 
00469   friend class edm::DQMHttpSource;
00470   friend class DQMService;
00471   friend class DQMNet;
00472   friend class DQMArchiver;
00473   friend class DQMStoreExample; // for get{All,Matching}Contents -- sole user of this method!
00474 };
00475 
00476 #endif // DQMSERVICES_CORE_DQM_STORE_H