Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-31 00:08:46

0001 #ifndef DQMSERVICES_CORE_LEGACYIOHELPER_H
0002 #define DQMSERVICES_CORE_LEGACYIOHELPER_H
0003 
0004 #include "DQMServices/Core/interface/DQMStore.h"
0005 #include "TROOT.h"
0006 
0007 // This class encapsulates the TDirectory based file format used for DQMGUI
0008 // uploads and many other use cases.
0009 // This should be part of `DQMFileSaver`, however since DQMServices/Components
0010 // DQMFileSaver and DQMServices/FileIO DQMFileSaverOnline both write this
0011 // format, the code is shared here (evnetually, these modules should become one
0012 // again).
0013 // This code is in DQMServices/Core to also allow the legacy DQMStore::save
0014 // interface to use this without adding another dependency.
0015 class LegacyIOHelper {
0016 public:
0017   // use internal type here since we call this from the DQMStore itself.
0018   typedef dqm::implementation::DQMStore DQMStore;
0019   typedef dqm::legacy::MonitorElement MonitorElement;
0020 
0021   typedef dqm::harvesting::DQMStore HarvestedDQMStore;
0022   typedef dqm::harvesting::MonitorElement HarvestedMonitorElement;
0023 
0024   using MEMap = std::set<HarvestedMonitorElement*>;
0025 
0026   LegacyIOHelper(DQMStore* dqmstore) : dbe_(dqmstore){};
0027   LegacyIOHelper(HarvestedDQMStore* hdqmstore) : dbe_(hdqmstore){};
0028   // Replace or append to `filename`, a TDirectory ROOT file. If a run number
0029   // is passed, the paths are rewritten to the "Run Summary" format used by
0030   // DQMGUI. The run number does not affect which MEs are saved; this code only
0031   // supports non-threaded mode. `fileupdate` is passed to ROOT unchanged.
0032   // The run number passed in is added to the Directory structure inside the
0033   // file ("Run xxxxxx/.../Run Summary/...") if not 0. It is only used to
0034   // select only MEs for that run iff saveall is false, else all MEs (RUN, LUMI
0035   // and JOB) are saved.
0036   void save(std::string const& filename,
0037             std::string const& path = "",
0038             uint32_t const run = 0,
0039             bool saveall = true,
0040             std::string const& fileupdate = "RECREATE");
0041 
0042   bool open(std::string const& filename, std::string const& path = "", uint32_t const run = 0);
0043 
0044 private:
0045   template <class T>
0046   void getMEName(T* h, const std::string& toppath, std::string& meName) {
0047     std::ostringstream fullpath;
0048     fullpath << gDirectory->GetPath() << "/" << h->GetName();
0049     std::string dirpath = fullpath.str();
0050     // Search for the substring in string
0051     size_t pos = dirpath.find(toppath);
0052     if (pos != std::string::npos) {
0053       dirpath.erase(pos, toppath.length());
0054     }
0055     std::string rsummary = "/Run summary";
0056     pos = dirpath.find(rsummary);
0057     if (pos != std::string::npos) {
0058       dirpath.erase(pos, rsummary.length());
0059     }
0060     meName = dirpath;
0061   }
0062   bool readdir(TDirectory* dir, const std::string& toppath);
0063   bool createDirectoryIfNeededAndCd(const std::string& path);
0064   DQMStore* dbe_;
0065   MEMap data_;
0066 };
0067 
0068 #endif