CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DQMRootSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FwkIO
4 // Class : DQMRootSource
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones
10 // Created: Tue May 3 11:13:47 CDT 2011
11 //
12 
13 // system include files
14 #include <memory>
15 
16 #include "TFile.h"
17 #include "TString.h"
18 #include "TTree.h"
19 #include <map>
20 #include <string>
21 #include <vector>
22 
26 
32 
35 
41 
44 
47 
51 
52 #include "format.h"
53 
54 // class rather than namespace so we can make this a friend of the
55 // MonitorElement to get access to constructors etc.
56 struct DQMTTreeIO {
59 
60  // TODO: this should probably be moved somewhere else
62  public:
63  // Utility function to check the consistency of the axis labels
64  // Taken from TH1::CheckBinLabels which is not public
65  static bool CheckBinLabels(const TAxis* a1, const TAxis* a2) {
66  // Check that axis have same labels
67  THashList* l1 = (const_cast<TAxis*>(a1))->GetLabels();
68  THashList* l2 = (const_cast<TAxis*>(a2))->GetLabels();
69 
70  if (!l1 && !l2)
71  return true;
72  if (!l1 || !l2) {
73  return false;
74  }
75 
76  // Check now labels sizes are the same
77  if (l1->GetSize() != l2->GetSize()) {
78  return false;
79  }
80 
81  for (int i = 1; i <= a1->GetNbins(); ++i) {
82  std::string_view label1 = a1->GetBinLabel(i);
83  std::string_view label2 = a2->GetBinLabel(i);
84  if (label1 != label2) {
85  return false;
86  }
87  }
88 
89  return true;
90  }
91 
92  // NOTE: the merge logic comes from DataFormats/Histograms/interface/MEtoEDMFormat.h
93  static void mergeTogether(TH1* original, TH1* toAdd) {
94  if (original->CanExtendAllAxes() && toAdd->CanExtendAllAxes()) {
95  TList list;
96  list.Add(toAdd);
97  if (original->Merge(&list) == -1) {
98  edm::LogError("MergeFailure") << "Failed to merge DQM element " << original->GetName();
99  }
100  } else {
101  // TODO: Redo. This is both more strict than what ROOT checks for yet
102  // allows cases where ROOT fails with merging.
103  if (original->GetNbinsX() == toAdd->GetNbinsX() &&
104  original->GetXaxis()->GetXmin() == toAdd->GetXaxis()->GetXmin() &&
105  original->GetXaxis()->GetXmax() == toAdd->GetXaxis()->GetXmax() &&
106  original->GetNbinsY() == toAdd->GetNbinsY() &&
107  original->GetYaxis()->GetXmin() == toAdd->GetYaxis()->GetXmin() &&
108  original->GetYaxis()->GetXmax() == toAdd->GetYaxis()->GetXmax() &&
109  original->GetNbinsZ() == toAdd->GetNbinsZ() &&
110  original->GetZaxis()->GetXmin() == toAdd->GetZaxis()->GetXmin() &&
111  original->GetZaxis()->GetXmax() == toAdd->GetZaxis()->GetXmax() &&
112  CheckBinLabels(original->GetXaxis(), toAdd->GetXaxis()) &&
113  CheckBinLabels(original->GetYaxis(), toAdd->GetYaxis()) &&
114  CheckBinLabels(original->GetZaxis(), toAdd->GetZaxis())) {
115  original->Add(toAdd);
116  } else {
117  edm::LogError("MergeFailure") << "Found histograms with different axis limits or different labels '"
118  << original->GetName() << "' not merged.";
119  }
120  }
121  }
122  };
123 
124  // This struct allows to find all MEs belonging to a run-lumi pair
125  // All files will be open at once so m_file property indicates the file where data is saved.
126  struct FileMetadata {
127  unsigned int m_run;
128  unsigned int m_lumi;
129  ULong64_t m_beginTime;
130  ULong64_t m_endTime;
131  ULong64_t m_firstIndex;
132  ULong64_t m_lastIndex; // Last is inclusive
133  unsigned int m_type;
134  TFile* m_file;
135 
136  // This will be used when sorting a vector
137  bool operator<(const FileMetadata& obj) const {
138  if (m_run == obj.m_run)
139  return m_lumi < obj.m_lumi;
140  else
141  return m_run < obj.m_run;
142  }
143 
144  void describe() {
145  std::cout << "read r:" << m_run << " l:" << m_lumi << " bt:" << m_beginTime << " et:" << m_endTime
146  << " fi:" << m_firstIndex << " li:" << m_lastIndex << " type:" << m_type << " file: " << m_file
147  << std::endl;
148  }
149  };
150 
152  public:
154  : m_kind(kind), m_rescope(rescope) {}
155  virtual ~TreeReaderBase() {}
156 
157  MonitorElementData::Key makeKey(std::string const& fullname, int run, int lumi) {
159  key.kind_ = m_kind;
161  if (m_rescope == MonitorElementData::Scope::LUMI) {
162  // no rescoping
163  key.scope_ = lumi == 0 ? MonitorElementData::Scope::RUN : MonitorElementData::Scope::LUMI;
164  key.id_ = edm::LuminosityBlockID(run, lumi);
165  } else if (m_rescope == MonitorElementData::Scope::RUN) {
166  // everything becomes run, we'll never see Scope::JOB inside DQMIO files.
167  key.scope_ = MonitorElementData::Scope::RUN;
168  key.id_ = edm::LuminosityBlockID(run, 0);
169  } else if (m_rescope == MonitorElementData::Scope::JOB) {
170  // Everything is aggregated over the entire job.
171  key.scope_ = MonitorElementData::Scope::JOB;
172  key.id_ = edm::LuminosityBlockID(0, 0);
173  } else {
174  assert(!"Invalid Scope in rescope option.");
175  }
176  return key;
177  }
178  virtual void read(ULong64_t iIndex, DQMStore* dqmstore, int run, int lumi) = 0;
179  virtual void setTree(TTree* iTree) = 0;
180 
181  protected:
184  };
185 
186  template <class T>
188  public:
193  }
194 
195  void read(ULong64_t iIndex, DQMStore* dqmstore, int run, int lumi) override {
196  // This will populate the fields as defined in setTree method
197  m_tree->GetEntry(iIndex);
198 
199  auto key = makeKey(*m_fullName, run, lumi);
200  auto existing = dqmstore->findOrRecycle(key);
201  if (existing) {
202  // TODO: make sure there is sufficient locking here.
204  } else {
205  // We make our own MEs here, to avoid a round-trip through the booking API.
206  MonitorElementData meData;
207  meData.key_ = key;
208  meData.value_.object_ = std::unique_ptr<T>((T*)(m_buffer->Clone()));
209  auto me = new MonitorElement(std::move(meData));
210  dqmstore->putME(me);
211  }
212  }
213 
214  void setTree(TTree* iTree) override {
215  m_tree = iTree;
216  m_tree->SetBranchAddress(kFullNameBranch, &m_fullName);
217  m_tree->SetBranchAddress(kFlagBranch, &m_tag);
218  m_tree->SetBranchAddress(kValueBranch, &m_buffer);
219  }
220 
221  private:
222  TTree* m_tree = nullptr;
224  T* m_buffer = nullptr;
225  uint32_t m_tag = 0;
226  };
227 
229  public:
232  }
233 
234  void read(ULong64_t iIndex, DQMStore* dqmstore, int run, int lumi) override {
235  // This will populate the fields as defined in setTree method
236  m_tree->GetEntry(iIndex);
237 
238  auto key = makeKey(*m_fullName, run, lumi);
239  auto existing = dqmstore->findOrRecycle(key);
240 
241  if (existing) {
242  existing->Fill(*m_value);
243  } else {
244  // We make our own MEs here, to avoid a round-trip through the booking API.
245  MonitorElementData meData;
246  meData.key_ = key;
247  meData.value_.scalar_.str = *m_value;
248  auto me = new MonitorElement(std::move(meData));
249  dqmstore->putME(me);
250  }
251  }
252 
253  void setTree(TTree* iTree) override {
254  m_tree = iTree;
255  m_tree->SetBranchAddress(kFullNameBranch, &m_fullName);
256  m_tree->SetBranchAddress(kFlagBranch, &m_tag);
257  m_tree->SetBranchAddress(kValueBranch, &m_value);
258  }
259 
260  private:
261  TTree* m_tree = nullptr;
263  std::string* m_value = nullptr;
264  uint32_t m_tag = 0;
265  };
266 
267  template <class T>
269  public:
272  }
273 
274  void read(ULong64_t iIndex, DQMStore* dqmstore, int run, int lumi) override {
275  // This will populate the fields as defined in setTree method
276  m_tree->GetEntry(iIndex);
277 
278  auto key = makeKey(*m_fullName, run, lumi);
279  auto existing = dqmstore->findOrRecycle(key);
280 
281  if (existing) {
282  existing->Fill(m_buffer);
283  } else {
284  // We make our own MEs here, to avoid a round-trip through the booking API.
285  MonitorElementData meData;
286  meData.key_ = key;
288  meData.value_.scalar_.num = m_buffer;
290  meData.value_.scalar_.real = m_buffer;
291  auto me = new MonitorElement(std::move(meData));
292  dqmstore->putME(me);
293  }
294  }
295 
296  void setTree(TTree* iTree) override {
297  m_tree = iTree;
298  m_tree->SetBranchAddress(kFullNameBranch, &m_fullName);
299  m_tree->SetBranchAddress(kFlagBranch, &m_tag);
300  m_tree->SetBranchAddress(kValueBranch, &m_buffer);
301  }
302 
303  private:
304  TTree* m_tree = nullptr;
306  T m_buffer = 0;
307  uint32_t m_tag = 0;
308  };
309 };
310 
312 public:
314  DQMRootSource(const DQMRootSource&) = delete;
315  ~DQMRootSource() override;
316 
317  // ---------- const member functions ---------------------
318 
319  const DQMRootSource& operator=(const DQMRootSource&) = delete; // stop default
320 
321  // ---------- static member functions --------------------
322 
323  // ---------- member functions ---------------------------
324  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
325 
326 private:
328 
329  std::shared_ptr<edm::FileBlock> readFile_() override;
330  std::shared_ptr<edm::RunAuxiliary> readRunAuxiliary_() override;
331  std::shared_ptr<edm::LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_() override;
332  void readRun_(edm::RunPrincipal& rpCache) override;
333  void readLuminosityBlock_(edm::LuminosityBlockPrincipal& lbCache) override;
334  void readEvent_(edm::EventPrincipal&) override;
335 
336  // Read MEs from m_fileMetadatas to DQMStore till run or lumi transition
337  void readElements();
338  // True if m_currentIndex points to an element that has a different
339  // run or lumi than the previous element (a transition needs to happen).
340  // False otherwise.
341  bool isRunOrLumiTransition() const;
342  void readNextItemType();
343 
344  // These methods will be called by the framework.
345  // MEs in DQMStore will be put to products.
346  void beginRun(edm::Run& run) override;
348 
349  // If the run matches the filterOnRun configuration parameter, the run
350  // (and all its lumis) will be kept.
351  // Otherwise, check if a run and a lumi are in the range that needs to be processed.
352  // Range is retrieved from lumisToProcess configuration parameter.
353  // If at least one lumi of a run needs to be kept, per run MEs of that run will also be kept.
355  void logFileAction(char const* msg, char const* fileName) const;
356 
357  // ---------- member data --------------------------------
358 
359  // Properties from python config
361  unsigned int m_filterOnRun;
363  std::vector<edm::LuminosityBlockRange> m_lumisToProcess;
365 
367  // Each ME type gets its own reader
368  std::vector<std::shared_ptr<TreeReaderBase>> m_treeReaders;
369 
370  // Index of currenlty processed row in m_fileMetadatas
371  unsigned int m_currentIndex;
372 
373  // All open DQMIO files
374  struct OpenFileInfo {
375  OpenFileInfo(TFile* file, edm::JobReport::Token jrToken) : m_file(file), m_jrToken(jrToken) {}
379  }
380 
381  OpenFileInfo(OpenFileInfo&&) = default;
382  OpenFileInfo& operator=(OpenFileInfo&&) = default;
383 
384  std::unique_ptr<TFile> m_file;
386  };
387  std::vector<OpenFileInfo> m_openFiles;
388 
389  // An item here is a row read from DQMIO indices (metadata) table
390  std::vector<FileMetadata> m_fileMetadatas;
391 };
392 
393 //
394 // constants, enums and typedefs
395 //
396 
397 //
398 // static data member definitions
399 //
400 
403  desc.addUntracked<std::vector<std::string>>("fileNames")->setComment("Names of files to be processed.");
404  desc.addUntracked<unsigned int>("filterOnRun", 0)->setComment("Just limit the process to the selected run.");
405  desc.addUntracked<std::string>("reScope", "JOB")
406  ->setComment(
407  "Accumulate histograms more coarsely."
408  " Options: \"\": keep unchanged, \"RUN\": turn LUMI histograms into RUN histograms, \"JOB\": turn everything "
409  "into JOB histograms.");
410  desc.addUntracked<bool>("skipBadFiles", false)->setComment("Skip the file if it is not valid");
411  desc.addUntracked<std::string>("overrideCatalog", std::string())
412  ->setComment("An alternate file catalog to use instead of the standard site one.");
413  std::vector<edm::LuminosityBlockRange> defaultLumis;
414  desc.addUntracked<std::vector<edm::LuminosityBlockRange>>("lumisToProcess", defaultLumis)
415  ->setComment("Skip any lumi inside the specified run:lumi range.");
416 
417  descriptions.addDefault(desc);
418 }
419 
420 //
421 // constructors and destructor
422 //
423 
425  : edm::PuttableSourceBase(iPSet, iDesc),
426  m_skipBadFiles(iPSet.getUntrackedParameter<bool>("skipBadFiles", false)),
427  m_filterOnRun(iPSet.getUntrackedParameter<unsigned int>("filterOnRun", 0)),
428  m_catalog(iPSet.getUntrackedParameter<std::vector<std::string>>("fileNames"),
429  iPSet.getUntrackedParameter<std::string>("overrideCatalog")),
430  m_lumisToProcess(iPSet.getUntrackedParameter<std::vector<edm::LuminosityBlockRange>>(
431  "lumisToProcess", std::vector<edm::LuminosityBlockRange>())),
432  m_rescope(std::map<std::string, MonitorElementData::Scope>{
433  {"", MonitorElementData::Scope::LUMI},
434  {"LUMI", MonitorElementData::Scope::LUMI},
435  {"RUN", MonitorElementData::Scope::RUN},
436  {"JOB", MonitorElementData::Scope::JOB}}[iPSet.getUntrackedParameter<std::string>("reScope", "JOB")]),
438  m_treeReaders(kNIndicies, std::shared_ptr<TreeReaderBase>()),
439  m_currentIndex(0),
440  m_openFiles(std::vector<OpenFileInfo>()),
441  m_fileMetadatas(std::vector<FileMetadata>()) {
442  edm::sortAndRemoveOverlaps(m_lumisToProcess);
443 
444  if (m_catalog.fileNames(0).empty()) {
446  } else {
447  m_treeReaders[kIntIndex].reset(new TreeSimpleReader<Long64_t>(MonitorElementData::Kind::INT, m_rescope));
448  m_treeReaders[kFloatIndex].reset(new TreeSimpleReader<double>(MonitorElementData::Kind::REAL, m_rescope));
449  m_treeReaders[kStringIndex].reset(new TreeStringReader(MonitorElementData::Kind::STRING, m_rescope));
450  m_treeReaders[kTH1FIndex].reset(new TreeObjectReader<TH1F>(MonitorElementData::Kind::TH1F, m_rescope));
451  m_treeReaders[kTH1SIndex].reset(new TreeObjectReader<TH1S>(MonitorElementData::Kind::TH1S, m_rescope));
452  m_treeReaders[kTH1DIndex].reset(new TreeObjectReader<TH1D>(MonitorElementData::Kind::TH1D, m_rescope));
453  m_treeReaders[kTH2FIndex].reset(new TreeObjectReader<TH2F>(MonitorElementData::Kind::TH2F, m_rescope));
454  m_treeReaders[kTH2SIndex].reset(new TreeObjectReader<TH2S>(MonitorElementData::Kind::TH2S, m_rescope));
455  m_treeReaders[kTH2DIndex].reset(new TreeObjectReader<TH2D>(MonitorElementData::Kind::TH2D, m_rescope));
456  m_treeReaders[kTH3FIndex].reset(new TreeObjectReader<TH3F>(MonitorElementData::Kind::TH3F, m_rescope));
457  m_treeReaders[kTProfileIndex].reset(new TreeObjectReader<TProfile>(MonitorElementData::Kind::TPROFILE, m_rescope));
459  new TreeObjectReader<TProfile2D>(MonitorElementData::Kind::TPROFILE2D, m_rescope));
460  }
461 
462  produces<DQMToken, edm::Transition::BeginRun>("DQMGenerationRecoRun");
463  produces<DQMToken, edm::Transition::BeginLuminosityBlock>("DQMGenerationRecoLumi");
464 }
465 
467  for (auto& file : m_openFiles) {
468  if (file.m_file && file.m_file->IsOpen()) {
469  logFileAction("Closed file", "");
470  }
471  }
472 }
473 
474 //
475 // member functions
476 //
477 
479 
480 // We will read the metadata of all files and fill m_fileMetadatas vector
481 std::shared_ptr<edm::FileBlock> DQMRootSource::readFile_() {
482  const int numFiles = m_catalog.fileNames(0).size();
483  m_openFiles.reserve(numFiles);
484 
485  for (auto& fileitem : m_catalog.fileCatalogItems()) {
486  TFile* file;
487  std::string pfn;
488  std::string lfn;
489  std::list<std::string> exInfo;
490  //loop over names of a file, each of them corresponds to a data catalog
491  bool isGoodFile(true);
492  //get all names of a file, each of them corresponds to a data catalog
493  const std::vector<std::string>& fNames = fileitem.fileNames();
494  for (std::vector<std::string>::const_iterator it = fNames.begin(); it != fNames.end(); ++it) {
495  // Try to open a file
496  try {
497  file = TFile::Open(it->c_str());
498 
499  // Exception will be trapped so we pull it out ourselves
500  std::exception_ptr e = edm::threadLocalException::getException();
501  if (e != std::exception_ptr()) {
502  edm::threadLocalException::setException(std::exception_ptr());
503  std::rethrow_exception(e);
504  }
505 
506  } catch (cms::Exception const& e) {
507  file = nullptr; // is there anything we need to free?
508  if (std::next(it) == fNames.end()) { //last name corresponding to the last data catalog to try
509  if (!m_skipBadFiles) {
511  ex.addContext("Opening DQM Root file");
512  ex << "\nInput file " << *it << " was not found, could not be opened, or is corrupted.\n";
513  //report previous exceptions when use other names to open file
514  for (auto const& s : exInfo)
515  ex.addAdditionalInfo(s);
516  throw ex;
517  }
518  isGoodFile = false;
519  }
520  // save in case of error when trying next name
521  for (auto const& s : e.additionalInfo())
522  exInfo.push_back(s);
523  }
524 
525  // Check if a file is usable
526  if (file && !file->IsZombie()) {
527  logFileAction("Successfully opened file ", it->c_str());
528  pfn = *it;
529  lfn = fileitem.logicalFileName();
530  break;
531  } else {
532  if (std::next(it) == fNames.end()) {
533  if (!m_skipBadFiles) {
535  ex << "Input file " << *it << " could not be opened.\n";
536  ex.addContext("Opening DQM Root file");
537  //report previous exceptions when use other names to open file
538  for (auto const& s : exInfo)
539  ex.addAdditionalInfo(s);
540  throw ex;
541  }
542  isGoodFile = false;
543  }
544  if (file) {
545  delete file;
546  file = nullptr;
547  }
548  }
549  } //end loop over names of the file
550 
551  if (!isGoodFile && m_skipBadFiles)
552  continue;
553 
554  std::unique_ptr<std::string> guid{file->Get<std::string>(kCmsGuid)};
555  if (not guid) {
556  guid = std::make_unique<std::string>(file->GetUUID().AsString());
557  std::transform(guid->begin(), guid->end(), guid->begin(), (int (*)(int))std::toupper);
558  }
559 
561  auto jrToken = jr->inputFileOpened(
562  pfn, lfn, std::string(), std::string(), "DQMRootSource", "source", *guid, std::vector<std::string>());
563  m_openFiles.emplace_back(file, jrToken);
564 
565  // Check file format version, which is encoded in the Title of the TFile
566  if (strcmp(file->GetTitle(), "1") != 0) {
568  ex << "Input file " << fNames[0] << " does not appear to be a DQM Root file.\n";
569  }
570 
571  // Read metadata from the file
572  TTree* indicesTree = dynamic_cast<TTree*>(file->Get(kIndicesTree));
573  assert(indicesTree != nullptr);
574 
576  // Each line of metadata will be read into the coresponding fields of temp.
577  indicesTree->SetBranchAddress(kRunBranch, &temp.m_run);
578  indicesTree->SetBranchAddress(kLumiBranch, &temp.m_lumi);
579  indicesTree->SetBranchAddress(kBeginTimeBranch, &temp.m_beginTime);
580  indicesTree->SetBranchAddress(kEndTimeBranch, &temp.m_endTime);
581  indicesTree->SetBranchAddress(kTypeBranch, &temp.m_type);
582  indicesTree->SetBranchAddress(kFirstIndex, &temp.m_firstIndex);
583  indicesTree->SetBranchAddress(kLastIndex, &temp.m_lastIndex);
584 
585  for (Long64_t index = 0; index != indicesTree->GetEntries(); ++index) {
586  indicesTree->GetEntry(index);
587  temp.m_file = file;
588 
589  if (keepIt(temp.m_run, temp.m_lumi)) {
590  m_fileMetadatas.push_back(temp);
591  }
592  }
593 
594  } //end loop over files
595 
596  // Sort to make sure runs and lumis appear in sequential order
597  std::stable_sort(m_fileMetadatas.begin(), m_fileMetadatas.end());
598 
599  // If we have lumisections without matching runs, insert dummy runs here.
600  unsigned int run = 0;
601  auto toadd = std::vector<FileMetadata>();
602  for (auto& metadata : m_fileMetadatas) {
603  if (run < metadata.m_run && metadata.m_lumi != 0) {
604  // run transition and lumi transition at the same time!
605  FileMetadata dummy{}; // zero initialize
606  dummy.m_run = metadata.m_run;
607  dummy.m_lumi = 0;
608  dummy.m_type = kNoTypesStored;
609  toadd.push_back(dummy);
610  }
611  run = metadata.m_run;
612  }
613 
614  if (!toadd.empty()) {
615  // rather than trying to insert at the right places, just append and sort again.
616  m_fileMetadatas.insert(m_fileMetadatas.end(), toadd.begin(), toadd.end());
617  std::stable_sort(m_fileMetadatas.begin(), m_fileMetadatas.end());
618  }
619 
620  //for (auto& metadata : m_fileMetadatas)
621  // metadata.describe();
622 
623  // Stop if there's nothing to process. Otherwise start the run.
624  if (m_fileMetadatas.empty())
626  else
628 
629  // We have to return something but not sure why
630  return std::make_shared<edm::FileBlock>();
631 }
632 
633 std::shared_ptr<edm::RunAuxiliary> DQMRootSource::readRunAuxiliary_() {
635  auto runAux =
637  return std::make_shared<edm::RunAuxiliary>(runAux);
638 }
639 
640 std::shared_ptr<edm::LuminosityBlockAuxiliary> DQMRootSource::readLuminosityBlockAuxiliary_() {
642  auto lumiAux = edm::LuminosityBlockAuxiliary(edm::LuminosityBlockID(metadata.m_run, metadata.m_lumi),
643  edm::Timestamp(metadata.m_beginTime),
644  edm::Timestamp(metadata.m_endTime));
645  return std::make_shared<edm::LuminosityBlockAuxiliary>(lumiAux);
646 }
647 
649  // Read elements of a current run.
650  do {
652  if (metadata.m_lumi == 0) {
653  readElements();
654  }
655  m_currentIndex++;
656  } while (!isRunOrLumiTransition());
657 
659 
661  jr->reportInputRunNumber(rpCache.id().run());
663 }
664 
666  // Read elements of a current lumi.
667  do {
668  readElements();
669  m_currentIndex++;
670  } while (!isRunOrLumiTransition());
671 
673 
675  jr->reportInputLumiSection(lbCache.id().run(), lbCache.id().luminosityBlock());
677 }
678 
680 
683 
684  if (metadata.m_type != kNoTypesStored) {
685  std::shared_ptr<TreeReaderBase> reader = m_treeReaders[metadata.m_type];
686  TTree* tree = dynamic_cast<TTree*>(metadata.m_file->Get(kTypeNames[metadata.m_type]));
687  // The Reset() below screws up the tree, so we need to re-read it from file
688  // before use here.
689  tree->Refresh();
690 
691  reader->setTree(tree);
692 
693  ULong64_t index = metadata.m_firstIndex;
694  ULong64_t endIndex = metadata.m_lastIndex + 1;
695 
696  for (; index != endIndex; ++index) {
697  reader->read(index, edm::Service<DQMStore>().operator->(), metadata.m_run, metadata.m_lumi);
698  }
699  // Drop buffers in the TTree. This reduces memory consuption while the tree
700  // just sits there and waits for the next block to be read.
701  tree->Reset();
702  }
703 }
704 
706  if (m_currentIndex == 0) {
707  return false;
708  }
709 
710  if (m_currentIndex > m_fileMetadatas.size() - 1) {
711  // We reached the end
712  return true;
713  }
714 
715  FileMetadata previousMetadata = m_fileMetadatas[m_currentIndex - 1];
717 
718  return previousMetadata.m_run != metadata.m_run || previousMetadata.m_lumi != metadata.m_lumi;
719 }
720 
722  if (m_currentIndex == 0) {
724  } else if (m_currentIndex > m_fileMetadatas.size() - 1) {
725  // We reached the end
727  } else {
728  FileMetadata previousMetadata = m_fileMetadatas[m_currentIndex - 1];
730 
731  if (previousMetadata.m_run != metadata.m_run) {
733  } else if (previousMetadata.m_lumi != metadata.m_lumi) {
735  }
736  }
737 }
738 
740  std::unique_ptr<DQMToken> product = std::make_unique<DQMToken>();
741  run.put(std::move(product), "DQMGenerationRecoRun");
742 }
743 
745  std::unique_ptr<DQMToken> product = std::make_unique<DQMToken>();
746  lumi.put(std::move(product), "DQMGenerationRecoLumi");
747 }
748 
750  if (m_filterOnRun != 0 && run != m_filterOnRun) {
751  return false;
752  }
753 
754  if (m_lumisToProcess.empty()) {
755  return true;
756  }
757 
758  for (edm::LuminosityBlockRange const& lumiToProcess : m_lumisToProcess) {
759  if (run >= lumiToProcess.startRun() && run <= lumiToProcess.endRun()) {
760  if (lumi >= lumiToProcess.startLumi() && lumi <= lumiToProcess.endLumi()) {
761  return true;
762  } else if (lumi == 0) {
763  return true;
764  }
765  }
766  }
767  return false;
768 }
769 
770 void DQMRootSource::logFileAction(char const* msg, char const* fileName) const {
771  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay() << msg << fileName;
773 }
774 
775 //
776 // const member functions
777 //
778 
779 //
780 // static member functions
781 //
m_openFiles(std::vector< OpenFileInfo >())
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:140
edm::InputSource::ItemType m_nextItemType
static const char *const kRunBranch
Definition: format.h:59
std::unique_ptr< TFile > m_file
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
static const char *const kTypeNames[]
Definition: format.h:39
MonitorElementData::Scope m_rescope
void readNextItemType()
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
m_fileMetadatas(std::vector< FileMetadata >())
void logFileAction(char const *msg, char const *fileName) const
RunNumber_t run() const
Definition: RunID.h:36
void FlushMessageLog()
void reportInputRunNumber(unsigned int run)
Definition: JobReport.cc:471
m_nextItemType(edm::InputSource::IsFile)
void fillLuminosityBlockPrincipal(ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
static void mergeTogether(TH1 *original, TH1 *toAdd)
ProcessHistoryID const & processHistoryID() const
static const char *const kIndicesTree
Definition: format.h:58
edm::propagate_const< std::unique_ptr< TH1 > > object_
list original
Definition: definitions.py:57
void setTree(TTree *iTree) override
OpenFileInfo(TFile *file, edm::JobReport::Token jrToken)
void read(ULong64_t iIndex, DQMStore *dqmstore, int run, int lumi) override
static const char *const kFirstIndex
Definition: format.h:65
std::vector< OpenFileInfo > m_openFiles
static bool CheckBinLabels(const TAxis *a1, const TAxis *a2)
MonitorElementData::Key makeKey(std::string const &fullname, int run, int lumi)
static const char *const kLumiBranch
Definition: format.h:60
LuminosityBlockAuxiliary const & aux() const
unsigned int m_filterOnRun
RunNumber_t run() const
Accessor for current run number.
Definition: InputSource.cc:457
void beginLuminosityBlock(edm::LuminosityBlock &lumi) override
static const char *const kFullNameBranch
Definition: format.h:53
Log< level::Error, false > LogError
bool keepIt(edm::RunNumber_t, edm::LuminosityBlockNumber_t) const
assert(be >=bs)
unsigned int LuminosityBlockNumber_t
unsigned int m_currentIndex
std::list< std::string > const & additionalInfo() const
Definition: Exception.cc:149
const DQMRootSource & operator=(const DQMRootSource &)=delete
m_treeReaders(kNIndicies, std::shared_ptr< TreeReaderBase >())
m_currentIndex(0)
Token inputFileOpened(std::string const &physicalFileName, std::string const &logicalFileName, std::string const &catalog, std::string const &inputType, std::string const &inputSourceClassName, std::string const &moduleLabel, std::string const &guid, std::vector< std::string > const &branchNames)
Definition: JobReport.cc:320
~DQMRootSource() override
MonitorElement * findOrRecycle(MonitorElementData::Key const &)
Definition: DQMStore.cc:317
virtual void read(ULong64_t iIndex, DQMStore *dqmstore, int run, int lumi)=0
edm::InputSource::ItemType getNextItemType() override
void addDefault(ParameterSetDescription const &psetDescription)
void set(std::string path, Path::Type type)
#define DEFINE_FWK_INPUT_SOURCE(type)
void setTree(TTree *iTree) override
void beginRun(edm::Run &run) override
void put(std::unique_ptr< PROD > product)
Put a new product.
void reportInputLumiSection(unsigned int run, unsigned int lumiSectId)
Definition: JobReport.cc:465
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
edm::InputFileCatalog m_catalog
def move
Definition: eostools.py:511
tuple key
prepare the HTCondor submission files and eventually submit them
RunNumber_t run() const
static const char *const kFlagBranch
Definition: format.h:54
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:169
static const char *const kTypeBranch
Definition: format.h:64
tuple reader
Definition: DQM.py:105
static const char *const kEndTimeBranch
Definition: format.h:63
bool isRunOrLumiTransition() const
list lumi
Definition: dqmdumpme.py:53
std::size_t Token
Definition: JobReport.h:106
RunID const & id() const
Definition: RunPrincipal.h:65
dqm::harvesting::MonitorElement MonitorElement
void read(ULong64_t iIndex, DQMStore *dqmstore, int run, int lumi) override
static const char *const kCmsGuid
Definition: format.h:69
static const char *const kLastIndex
Definition: format.h:66
std::vector< std::shared_ptr< TreeReaderBase > > m_treeReaders
TreeStringReader(MonitorElementData::Kind kind, MonitorElementData::Scope rescope)
std::vector< edm::LuminosityBlockRange > m_lumisToProcess
LuminosityBlockNumber_t luminosityBlock() const
void put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Run.h:109
OpenFileInfo & operator=(OpenFileInfo &&)=default
void addContext(std::string const &context)
Definition: Exception.cc:165
void readRun_(edm::RunPrincipal &rpCache) override
tuple msg
Definition: mps_check.py:285
TreeObjectReader(MonitorElementData::Kind kind, MonitorElementData::Scope rescope)
virtual void setTree(TTree *iTree)=0
void setException(std::exception_ptr e)
void setTree(TTree *iTree) override
bool operator<(const FileMetadata &obj) const
MonitorElement * putME(MonitorElement *me)
Definition: DQMStore.cc:148
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:331
void read(ULong64_t iIndex, DQMStore *dqmstore, int run, int lumi) override
static const char *const kBeginTimeBranch
Definition: format.h:62
TreeReaderBase(MonitorElementData::Kind kind, MonitorElementData::Scope rescope)
std::vector< std::string > fileNames(unsigned iCatalog) const
std::vector< EventRange > & sortAndRemoveOverlaps(std::vector< EventRange > &eventRange)
Definition: EventRange.cc:98
std::exception_ptr getException()
MonitorElementData::Kind m_kind
Log< level::System, true > LogAbsolute
tuple cout
Definition: gather_cfg.py:144
unsigned int RunNumber_t
dqm::harvesting::DQMStore DQMStore
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
Definition: RunPrincipal.cc:28
DQMRootSource(edm::ParameterSet const &, const edm::InputSourceDescription &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void readEvent_(edm::EventPrincipal &) override
long double T
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lbCache) override
void inputFileClosed(InputType inputType, Token fileToken)
Definition: JobReport.cc:376
edm::JobReport::Token m_jrToken
MonitorElementData::Scope m_rescope
Definition: Run.h:45
static const char *const kValueBranch
Definition: format.h:55
std::vector< FileMetadata > m_fileMetadatas
std::shared_ptr< edm::FileBlock > readFile_() override
std::vector< FileCatalogItem > const & fileCatalogItems() const
TreeSimpleReader(MonitorElementData::Kind kind, MonitorElementData::Scope rescope)
unsigned transform(const HcalDetId &id, unsigned transformCode)