Skip to content

Commit

Permalink
code-format & code-check & clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
mmusich authored and sroychow committed Aug 24, 2021
1 parent 34b2f98 commit fe63c1e
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 99 deletions.
4 changes: 2 additions & 2 deletions DQM/SiStripMonitorClient/plugins/SiStripOfflineDQM.cc
Expand Up @@ -200,13 +200,13 @@ void SiStripOfflineDQM::endJob() {
}

bool SiStripOfflineDQM::openInputFile(DQMStore& dqm_store) {
if (inputFileName_.empty())
if (inputFileName_.empty()) {
return false;
}
edm::LogInfo("OpenFile") << "SiStripOfflineDQM::openInputFile: Accessing root File" << inputFileName_;
dqm::harvesting::DQMStore* temp = dynamic_cast<dqm::harvesting::DQMStore*>(&dqm_store);
LegacyIOHelper leo(temp);
return leo.open(inputFileName_);
//return true;
}

#include "FWCore/Framework/interface/MakerMacros.h"
Expand Down
29 changes: 13 additions & 16 deletions DQMServices/Core/interface/LegacyIOHelper.h
Expand Up @@ -2,17 +2,17 @@
#define DQMSERVICES_CORE_LEGACYIOHELPER_H

#include "DQMServices/Core/interface/DQMStore.h"
#include<iostream>
#include<string>
#include <iostream>
#include <string>
#include "TFile.h"
#include "TROOT.h"
#include "TKey.h"
#include "TClass.h"
#include "TSystem.h"
#include "TBufferFile.h"
#include<sstream>
#include<utility>
#include<set>
#include <sstream>
#include <utility>
#include <set>
// This class encapsulates the TDirectory based file format used for DQMGUI
// uploads and many other use cases.
// This should be part of `DQMFileSaver`, however since DQMServices/Components
Expand All @@ -27,13 +27,13 @@ class LegacyIOHelper {
typedef dqm::implementation::DQMStore DQMStore;
typedef dqm::legacy::MonitorElement MonitorElement;

typedef dqm::harvesting::DQMStore HDQMStore;
typedef dqm::harvesting::MonitorElement HMonitorElement;
typedef dqm::harvesting::DQMStore HarvestedDQMStore;
typedef dqm::harvesting::MonitorElement HarvestedMonitorElement;

using MEMap = std::set<HMonitorElement*>;
using MEMap = std::set<HarvestedMonitorElement*>;

LegacyIOHelper(DQMStore* dqmstore) : dbe_(dqmstore){};
LegacyIOHelper(HDQMStore* hdqmstore) : dbe_(hdqmstore){};
LegacyIOHelper(HarvestedDQMStore* hdqmstore) : dbe_(hdqmstore){};
// Replace or append to `filename`, a TDirectory ROOT file. If a run number
// is passed, the paths are rewritten to the "Run Summary" format used by
// DQMGUI. The run number does not affect which MEs are saved; this code only
Expand All @@ -48,13 +48,11 @@ class LegacyIOHelper {
bool saveall = true,
std::string const& fileupdate = "RECREATE");

bool open(std::string const& filename,
std::string const& path = "",
uint32_t const run = 0);
bool open(std::string const& filename, std::string const& path = "", uint32_t const run = 0);

private:
template<class T>
void getMEName(T* h, const std::string& toppath, std::string& meName){
template <class T>
void getMEName(T* h, const std::string& toppath, std::string& meName) {
std::ostringstream fullpath;
fullpath << gDirectory->GetPath() << "/" << h->GetName();
std::string dirpath = fullpath.str();
Expand All @@ -68,10 +66,9 @@ class LegacyIOHelper {
if (pos != std::string::npos) {
dirpath.erase(pos, rsummary.length());
}
//std::cout << dirpath << std::endl;
meName = dirpath;
}
bool readdir(TDirectory *dir, const std::string& toppath);
bool readdir(TDirectory* dir, const std::string& toppath);
bool createDirectoryIfNeededAndCd(const std::string& path);
DQMStore* dbe_;
MEMap data_;
Expand Down
156 changes: 75 additions & 81 deletions DQMServices/Core/src/LegacyIOHelper.cc
@@ -1,4 +1,5 @@
#include "DQMServices/Core/interface/LegacyIOHelper.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

#include <cstdio>
#include <cfloat>
Expand Down Expand Up @@ -165,14 +166,14 @@ bool LegacyIOHelper::createDirectoryIfNeededAndCd(const std::string &path) {
return true;
}

bool LegacyIOHelper::readdir(TDirectory *dir, const std::string& toppath) {
bool LegacyIOHelper::readdir(TDirectory *dir, const std::string &toppath) {
TDirectory *dirsav = gDirectory;
//cout << "Inside:" << gDirectory->GetPath() << std::endl;
LogDebug("LegacyIOHelper") << "Inside:" << gDirectory->GetPath() << std::endl;
TIter next(dir->GetListOfKeys());
TKey *key;
while ((key = (TKey*)next())) {
while ((key = (TKey *)next())) {
if (key->IsFolder()) {
//cout << key->GetName() << std::endl;
LogDebug("LegacyIOHelper") << key->GetName() << std::endl;
dir->cd(key->GetName());
TDirectory *subdir = gDirectory;
readdir(subdir, toppath);
Expand All @@ -181,92 +182,85 @@ bool LegacyIOHelper::readdir(TDirectory *dir, const std::string& toppath) {
} else {
TClass *cl = gROOT->GetClass(key->GetClassName());
std::string meName;
if(cl->InheritsFrom("TProfile")) {
TProfile *h = dynamic_cast<TProfile*>(key->ReadObject<TProfile>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TProfile>(h, toppath, meName);
data_.insert(dbe_->bookProfile(meName, h));
}
if (cl->InheritsFrom("TProfile")) {
TProfile *h = dynamic_cast<TProfile *>(key->ReadObject<TProfile>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TProfile>(h, toppath, meName);
data_.insert(dbe_->bookProfile(meName, h));
}
} else if (cl->InheritsFrom("TProfile2D")) {
TProfile2D *h = dynamic_cast<TProfile2D *>(key->ReadObject<TProfile2D>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TProfile2D>(h, toppath, meName);
data_.insert(dbe_->bookProfile2D(meName, h));
}
} else if (cl->InheritsFrom("TH1F")) {
TH1F *h = dynamic_cast<TH1F *>(key->ReadObject<TH1F>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH1F>(h, toppath, meName);
data_.insert(dbe_->book1D(meName, h));
}
} else if (cl->InheritsFrom("TH1S")) {
TH1S *h = dynamic_cast<TH1S *>(key->ReadObject<TH1S>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH1S>(h, toppath, meName);
data_.insert(dbe_->book1S(meName, h));
}
} else if (cl->InheritsFrom("TH1D")) {
TH1D *h = dynamic_cast<TH1D *>(key->ReadObject<TH1D>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH1D>(h, toppath, meName);
data_.insert(dbe_->book1DD(meName, h));
}
} else if (cl->InheritsFrom("TH2F")) {
TH2F *h = dynamic_cast<TH2F *>(key->ReadObject<TH2F>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH2F>(h, toppath, meName);
data_.insert(dbe_->book2D(meName, h));
}
} else if (cl->InheritsFrom("TH2S")) {
TH2S *h = dynamic_cast<TH2S *>(key->ReadObject<TH2S>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH2S>(h, toppath, meName);
data_.insert(dbe_->book2S(meName, h));
}
} else if (cl->InheritsFrom("TH2D")) {
TH2D *h = dynamic_cast<TH2D *>(key->ReadObject<TH2D>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH2D>(h, toppath, meName);
data_.insert(dbe_->book2DD(meName, h));
}
} else if (cl->InheritsFrom("TH3F")) {
TH3F *h = dynamic_cast<TH3F *>(key->ReadObject<TH3F>()->Clone());
h->SetDirectory(nullptr);
if (h) {
getMEName<TH3F>(h, toppath, meName);
data_.insert(dbe_->book3D(meName, h));
}
}
else if(cl->InheritsFrom("TProfile2D")) {
TProfile2D *h = dynamic_cast<TProfile2D*>(key->ReadObject<TProfile2D>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TProfile2D>(h, toppath, meName);
data_.insert(dbe_->bookProfile2D(meName, h));
}
}
else if(cl->InheritsFrom("TH1F")) {
TH1F *h = dynamic_cast<TH1F*>(key->ReadObject<TH1F>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TH1F>(h, toppath, meName);
data_.insert(dbe_->book1D(meName, h));
}
}
else if(cl->InheritsFrom("TH1S")) {
TH1S *h = dynamic_cast<TH1S*>(key->ReadObject<TH1S>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TH1S>(h, toppath, meName);
data_.insert(dbe_->book1S(meName, h));
}
}
else if(cl->InheritsFrom("TH1D")) {
TH1D *h = dynamic_cast<TH1D*>(key->ReadObject<TH1D>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TH1D>(h, toppath, meName);
data_.insert(dbe_->book1DD(meName, h));
}
}
else if(cl->InheritsFrom("TH2F")) {
TH2F *h = dynamic_cast<TH2F*>(key->ReadObject<TH2F>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TH2F>(h, toppath, meName);
data_.insert(dbe_->book2D(meName, h));
}
}
else if(cl->InheritsFrom("TH2S")) {
TH2S *h =dynamic_cast<TH2S*>(key->ReadObject<TH2S>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TH2S>(h, toppath, meName);
data_.insert(dbe_->book2S(meName, h));
}
}
else if(cl->InheritsFrom("TH2D")) {
TH2D *h = dynamic_cast<TH2D*>(key->ReadObject<TH2D>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TH2D>(h, toppath, meName);
data_.insert(dbe_->book2DD(meName, h));
}
}
else if(cl->InheritsFrom("TH3F")) {
TH3F *h = dynamic_cast<TH3F*>(key->ReadObject<TH3F>()->Clone());
h->SetDirectory(0);
if(h) {
getMEName<TH3F>(h, toppath, meName);
data_.insert(dbe_->book3D(meName, h));
}
}

}
}
if(!data_.empty()) return true;
if (!data_.empty())
return true;
return false;
}

bool LegacyIOHelper::open(std::string const& filename, std::string const& path, uint32_t const run){
TFile* f1 = TFile::Open(filename.c_str());
if(!f1) return false;
bool LegacyIOHelper::open(std::string const &filename, std::string const &path, uint32_t const run) {
TFile *f1 = TFile::Open(filename.c_str());
if (!f1)
return false;
std::ostringstream toppath;
toppath << filename << ":/DQMData/Run " << run << "/";
std::string dirpath = toppath.str();
std::cout << dirpath << std::endl;
edm::LogPrint("LegacyIOHelper") << dirpath << std::endl;
bool flag = readdir(f1, dirpath);
f1->Close();
return flag;
Expand Down

0 comments on commit fe63c1e

Please sign in to comment.