CMS 3D CMS Logo

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