CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
LegacyIOHelper Class Reference

#include <LegacyIOHelper.h>

Public Types

typedef
dqm::implementation::DQMStore 
DQMStore
 
typedef dqm::harvesting::DQMStore HarvestedDQMStore
 
typedef
dqm::harvesting::MonitorElement 
HarvestedMonitorElement
 
using MEMap = std::set< HarvestedMonitorElement * >
 
typedef dqm::legacy::MonitorElement MonitorElement
 

Public Member Functions

 LegacyIOHelper (DQMStore *dqmstore)
 
 LegacyIOHelper (HarvestedDQMStore *hdqmstore)
 
bool open (std::string const &filename, std::string const &path="", uint32_t const run=0)
 
void save (std::string const &filename, std::string const &path="", uint32_t const run=0, bool saveall=true, std::string const &fileupdate="RECREATE")
 

Private Member Functions

bool createDirectoryIfNeededAndCd (const std::string &path)
 
template<class T >
void getMEName (T *h, const std::string &toppath, std::string &meName)
 
bool readdir (TDirectory *dir, const std::string &toppath)
 

Private Attributes

MEMap data_
 
DQMStoredbe_
 

Detailed Description

Definition at line 15 of file LegacyIOHelper.h.

Member Typedef Documentation

Definition at line 18 of file LegacyIOHelper.h.

Definition at line 21 of file LegacyIOHelper.h.

Definition at line 22 of file LegacyIOHelper.h.

Definition at line 24 of file LegacyIOHelper.h.

Definition at line 19 of file LegacyIOHelper.h.

Constructor & Destructor Documentation

LegacyIOHelper::LegacyIOHelper ( DQMStore dqmstore)
inline

Definition at line 26 of file LegacyIOHelper.h.

26 : dbe_(dqmstore){};
DQMStore * dbe_
LegacyIOHelper::LegacyIOHelper ( HarvestedDQMStore hdqmstore)
inline

Definition at line 27 of file LegacyIOHelper.h.

27 : dbe_(hdqmstore){};
DQMStore * dbe_

Member Function Documentation

bool LegacyIOHelper::createDirectoryIfNeededAndCd ( const std::string &  path)
private

Definition at line 126 of file LegacyIOHelper.cc.

References cms::cuda::assert(), dataset::end, Exception, class-composition::o, command_line::start, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by save().

126  {
127  assert(!path.empty());
128 
129  // Find the first path component.
130  size_t start = 0;
131  size_t end = path.find('/', start);
132  if (end == std::string::npos)
133  end = path.size();
134 
135  while (true) {
136  // Check if this subdirectory component exists. If yes, make sure
137  // it is actually a subdirectory. Otherwise create or cd into it.
138  std::string part(path, start, end - start);
139  TObject *o = gDirectory->Get(part.c_str());
140  if (o && !dynamic_cast<TDirectory *>(o))
141  throw cms::Exception("DQMFileSaver") << "Attempt to create directory '" << path
142  << "' in a file"
143  " fails because the part '"
144  << part
145  << "' already exists and is not"
146  " directory";
147  else if (!o)
148  gDirectory->mkdir(part.c_str());
149 
150  if (!gDirectory->cd(part.c_str()))
151  throw cms::Exception("DQMFileSaver") << "Attempt to create directory '" << path
152  << "' in a file"
153  " fails because could not cd into subdirectory '"
154  << part << "'";
155 
156  // Stop if we reached the end, ignoring any trailing '/'.
157  if (end + 1 >= path.size())
158  break;
159 
160  // Find the next path component.
161  start = end + 1;
162  end = path.find('/', start);
163  if (end == std::string::npos)
164  end = path.size();
165  }
166 
167  return true;
168 }
assert(be >=bs)
part
Definition: HCALResponse.h:20
string end
Definition: dataset.py:937
template<class T >
void LegacyIOHelper::getMEName ( T h,
const std::string &  toppath,
std::string &  meName 
)
inlineprivate

Definition at line 46 of file LegacyIOHelper.h.

References das_client::fullpath(), and AlCaHLTBitMon_QueryRunRegistry::string.

46  {
47  std::ostringstream fullpath;
48  fullpath << gDirectory->GetPath() << "/" << h->GetName();
49  std::string dirpath = fullpath.str();
50  // Search for the substring in string
51  size_t pos = dirpath.find(toppath);
52  if (pos != std::string::npos) {
53  dirpath.erase(pos, toppath.length());
54  }
55  std::string rsummary = "/Run summary";
56  pos = dirpath.find(rsummary);
57  if (pos != std::string::npos) {
58  dirpath.erase(pos, rsummary.length());
59  }
60  meName = dirpath;
61  }
def fullpath
Definition: das_client.py:267
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
bool LegacyIOHelper::open ( std::string const &  filename,
std::string const &  path = "",
uint32_t const  run = 0 
)

Definition at line 257 of file LegacyIOHelper.cc.

References validate-o2o-wbm::f1, readdir(), and AlCaHLTBitMon_QueryRunRegistry::string.

257  {
258  TFile *f1 = TFile::Open(filename.c_str());
259  if (!f1)
260  return false;
261  std::ostringstream toppath;
262  toppath << filename << ":/DQMData/Run " << run << "/";
263  std::string dirpath = toppath.str();
264  edm::LogPrint("LegacyIOHelper") << dirpath << std::endl;
265  bool flag = readdir(f1, dirpath);
266  f1->Close();
267  return flag;
268 }
bool readdir(TDirectory *dir, const std::string &toppath)
Log< level::Warning, true > LogPrint
tuple filename
Definition: lut2db_cfg.py:20
bool LegacyIOHelper::readdir ( TDirectory *  dir,
const std::string &  toppath 
)
private

Definition at line 170 of file LegacyIOHelper.cc.

References dqm::implementation::IBooker::book1D(), dqm::implementation::IBooker::book1DD(), dqm::implementation::IBooker::book1S(), dqm::implementation::IBooker::book2D(), dqm::implementation::IBooker::book2DD(), dqm::implementation::IBooker::book2S(), dqm::implementation::IBooker::book3D(), dqm::implementation::IBooker::bookProfile(), dqm::implementation::IBooker::bookProfile2D(), haddnano::cl, data_, dbe_, h, submitPVResolutionJobs::key, LogDebug, GetRecoTauVFromDQM_MC_cff::next, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by open().

170  {
171  TDirectory *dirsav = gDirectory;
172  LogDebug("LegacyIOHelper") << "Inside:" << gDirectory->GetPath() << std::endl;
173  TIter next(dir->GetListOfKeys());
174  TKey *key;
175  while ((key = (TKey *)next())) {
176  if (key->IsFolder()) {
177  LogDebug("LegacyIOHelper") << key->GetName() << std::endl;
178  dir->cd(key->GetName());
179  TDirectory *subdir = gDirectory;
180  readdir(subdir, toppath);
181  dirsav->cd();
182  continue;
183  } else {
184  TClass *cl = gROOT->GetClass(key->GetClassName());
185  std::string meName;
186  if (cl->InheritsFrom("TProfile")) {
187  TProfile *h = dynamic_cast<TProfile *>(key->ReadObject<TProfile>()->Clone());
188  h->SetDirectory(nullptr);
189  if (h) {
190  getMEName<TProfile>(h, toppath, meName);
191  data_.insert(dbe_->bookProfile(meName, h));
192  }
193  } else if (cl->InheritsFrom("TProfile2D")) {
194  TProfile2D *h = dynamic_cast<TProfile2D *>(key->ReadObject<TProfile2D>()->Clone());
195  h->SetDirectory(nullptr);
196  if (h) {
197  getMEName<TProfile2D>(h, toppath, meName);
198  data_.insert(dbe_->bookProfile2D(meName, h));
199  }
200  } else if (cl->InheritsFrom("TH1F")) {
201  TH1F *h = dynamic_cast<TH1F *>(key->ReadObject<TH1F>()->Clone());
202  h->SetDirectory(nullptr);
203  if (h) {
204  getMEName<TH1F>(h, toppath, meName);
205  data_.insert(dbe_->book1D(meName, h));
206  }
207  } else if (cl->InheritsFrom("TH1S")) {
208  TH1S *h = dynamic_cast<TH1S *>(key->ReadObject<TH1S>()->Clone());
209  h->SetDirectory(nullptr);
210  if (h) {
211  getMEName<TH1S>(h, toppath, meName);
212  data_.insert(dbe_->book1S(meName, h));
213  }
214  } else if (cl->InheritsFrom("TH1D")) {
215  TH1D *h = dynamic_cast<TH1D *>(key->ReadObject<TH1D>()->Clone());
216  h->SetDirectory(nullptr);
217  if (h) {
218  getMEName<TH1D>(h, toppath, meName);
219  data_.insert(dbe_->book1DD(meName, h));
220  }
221  } else if (cl->InheritsFrom("TH2F")) {
222  TH2F *h = dynamic_cast<TH2F *>(key->ReadObject<TH2F>()->Clone());
223  h->SetDirectory(nullptr);
224  if (h) {
225  getMEName<TH2F>(h, toppath, meName);
226  data_.insert(dbe_->book2D(meName, h));
227  }
228  } else if (cl->InheritsFrom("TH2S")) {
229  TH2S *h = dynamic_cast<TH2S *>(key->ReadObject<TH2S>()->Clone());
230  h->SetDirectory(nullptr);
231  if (h) {
232  getMEName<TH2S>(h, toppath, meName);
233  data_.insert(dbe_->book2S(meName, h));
234  }
235  } else if (cl->InheritsFrom("TH2D")) {
236  TH2D *h = dynamic_cast<TH2D *>(key->ReadObject<TH2D>()->Clone());
237  h->SetDirectory(nullptr);
238  if (h) {
239  getMEName<TH2D>(h, toppath, meName);
240  data_.insert(dbe_->book2DD(meName, h));
241  }
242  } else if (cl->InheritsFrom("TH3F")) {
243  TH3F *h = dynamic_cast<TH3F *>(key->ReadObject<TH3F>()->Clone());
244  h->SetDirectory(nullptr);
245  if (h) {
246  getMEName<TH3F>(h, toppath, meName);
247  data_.insert(dbe_->book3D(meName, h));
248  }
249  }
250  }
251  }
252  if (!data_.empty())
253  return true;
254  return false;
255 }
MonitorElement * bookProfile2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, double lowZ, double highZ, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:399
MonitorElement * book2S(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:219
tuple cl
Definition: haddnano.py:49
MonitorElement * book1DD(TString const &name, TString const &title, int nchX, double lowX, double highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:155
DQMStore * dbe_
MonitorElement * bookProfile(TString const &name, TString const &title, int nchX, double lowX, double highX, int, double lowY, double highY, char const *option="s", FUNC onbooking=NOOP())
Definition: DQMStore.h:322
bool readdir(TDirectory *dir, const std::string &toppath)
tuple key
prepare the HTCondor submission files and eventually submit them
MonitorElement * book1S(TString const &name, TString const &title, int nchX, double lowX, double highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:133
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:177
MonitorElement * book2DD(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:261
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
MonitorElement * book3D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, FUNC onbooking=NOOP())
Definition: DQMStore.h:290
#define LogDebug(id)
void LegacyIOHelper::save ( std::string const &  filename,
std::string const &  path = "",
uint32_t const  run = 0,
bool  saveall = true,
std::string const &  fileupdate = "RECREATE" 
)

Definition at line 15 of file LegacyIOHelper.cc.

References visDQMUpload::buf, ws_sso_content_reader::content, gather_cfg::cout, createDirectoryIfNeededAndCd(), dbe_, TrackerOfflineValidation_Dqm_cff::dirName, mergeVDriftHistosByStation::file, dqm::implementation::IGetter::getAllContents(), MonitorElementData::INT, hlt_dqm_clientPB-live_cfg::me, summarizeEdmComparisonLogfiles::objectName, runTheMatrix::opt, MonitorElementData::REAL, mps_fire::result, str, MonitorElementData::STRING, AlCaHLTBitMon_QueryRunRegistry::string, createPayload::suffix, and relativeConstraints::value.

Referenced by dqm::DQMFileSaverOnline::makeSnapshot(), dqm::implementation::DQMStore::save(), and DQMFileSaver::saveForOffline().

19  {
20  // TFile flushes to disk with fsync() on every TDirectory written to
21  // the file. This makes DQM file saving painfully slow, and
22  // ironically makes it _more_ likely the file saving gets
23  // interrupted and corrupts the file. The utility class below
24  // simply ignores the flush synchronisation.
25  class TFileNoSync : public TFile {
26  public:
27  TFileNoSync(char const *file, char const *opt) : TFile{file, opt} {}
28  Int_t SysSync(Int_t) override { return 0; }
29  };
30 
31  std::cout << "DQMFileSaver::globalEndRun()" << std::endl;
32 
33  char suffix[64];
34  sprintf(suffix, "R%09d", run);
35  TFileNoSync *file = new TFileNoSync(filename.c_str(), fileupdate.c_str()); // open file
36 
37  // Traverse all MEs
38  std::vector<MonitorElement *> mes;
39  if (saveall) {
40  // this is typically used, at endJob there will only be JOB histos here
41  mes = dbe_->getAllContents(path);
42  } else {
43  // at endRun it might make sense to use this, to not save JOB histos yet.
44  mes = dbe_->getAllContents(path, run, 0);
45  }
46 
47  for (auto me : mes) {
48  // Modify dirname to comply with DQM GUI format. Change:
49  // A/B/C/plot
50  // into:
51  // DQMData/Run X/A/Run summary/B/C/plot
52  std::string dirName = me->getPathname();
53  uint64_t firstSlashPos = dirName.find('/');
54  if (firstSlashPos == std::string::npos) {
55  firstSlashPos = dirName.length();
56  }
57 
58  if (run) {
59  // Rewrite paths to "Run Summary" format when given a run number.
60  // Else, write a simple, flat TDirectory for local usage.
61  dirName = dirName.substr(0, firstSlashPos) + "/Run summary" + dirName.substr(firstSlashPos, dirName.size());
62  dirName = "DQMData/Run " + std::to_string(run) + "/" + dirName;
63  }
64 
65  std::string objectName = me->getName();
66 
67  // Create dir if it doesn't exist and cd into it
69 
70  // INTs are saved as strings in this format: <objectName>i=value</objectName>
71  // REALs are saved as strings in this format: <objectName>f=value</objectName>
72  // STRINGs are saved as strings in this format: <objectName>s="value"</objectName>
73  if (me->kind() == MonitorElement::Kind::INT) {
74  int value = me->getIntValue();
75  std::string content = "<" + objectName + ">i=" + std::to_string(value) + "</" + objectName + ">";
76  TObjString str(content.c_str());
77  str.Write();
78  } else if (me->kind() == MonitorElement::Kind::REAL) {
79  double value = me->getFloatValue();
80  char buf[64];
81  // use printf here to preserve exactly the classic formatting.
82  std::snprintf(buf, sizeof(buf), "%.*g", DBL_DIG + 2, value);
83  std::string content = "<" + objectName + ">f=" + buf + "</" + objectName + ">";
84  TObjString str(content.c_str());
85  str.Write();
86  } else if (me->kind() == MonitorElement::Kind::STRING) {
87  const std::string &value = me->getStringValue();
88  std::string content = "<" + objectName + ">s=" + value + "</" + objectName + ">";
89  TObjString str(content.c_str());
90  str.Write();
91  } else {
92  // Write a histogram
93  TH1 *value = me->getTH1();
94  value->Write();
95 
96  if (me->getEfficiencyFlag()) {
97  std::string content = "<" + objectName + ">e=1</" + objectName + ">";
98  TObjString str(content.c_str());
99  str.Write();
100  }
101 
102  for (QReport *qr : me->getQReports()) {
104  // TODO: 64 is likely too short; memory corruption in the old code?
105  char buf[64];
106  std::snprintf(buf, sizeof(buf), "qr=st:%d:%.*g:", qr->getStatus(), DBL_DIG + 2, qr->getQTresult());
107  result = '<' + objectName + '.' + qr->getQRName() + '>';
108  result += buf;
109  result += qr->getAlgorithm() + ':' + qr->getMessage();
110  result += "</" + objectName + '.' + qr->getQRName() + '>';
111  TObjString str(result.c_str());
112  str.Write();
113  }
114  }
115 
116  // Go back to the root directory
117  gDirectory->cd("/");
118  }
119 
120  file->Close();
121 }
bool createDirectoryIfNeededAndCd(const std::string &path)
virtual std::vector< dqm::harvesting::MonitorElement * > getAllContents(std::string const &path) const
Definition: DQMStore.cc:609
tuple result
Definition: mps_fire.py:311
DQMStore * dbe_
unsigned long long uint64_t
Definition: Time.h:13
tuple filename
Definition: lut2db_cfg.py:20
tuple cout
Definition: gather_cfg.py:144
#define str(s)

Member Data Documentation

MEMap LegacyIOHelper::data_
private

Definition at line 65 of file LegacyIOHelper.h.

Referenced by readdir().

DQMStore* LegacyIOHelper::dbe_
private

Definition at line 64 of file LegacyIOHelper.h.

Referenced by readdir(), and save().