CMS 3D CMS Logo

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;
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")]),
437  m_nextItemType(edm::InputSource::IsFile),
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()) {
445  m_nextItemType = edm::InputSource::IsStop;
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[kTH1IIndex].reset(new TreeObjectReader<TH1I>(MonitorElementData::Kind::TH1I, m_rescope));
454  m_treeReaders[kTH2FIndex].reset(new TreeObjectReader<TH2F>(MonitorElementData::Kind::TH2F, m_rescope));
455  m_treeReaders[kTH2SIndex].reset(new TreeObjectReader<TH2S>(MonitorElementData::Kind::TH2S, m_rescope));
456  m_treeReaders[kTH2DIndex].reset(new TreeObjectReader<TH2D>(MonitorElementData::Kind::TH2D, m_rescope));
457  m_treeReaders[kTH2IIndex].reset(new TreeObjectReader<TH2I>(MonitorElementData::Kind::TH2I, m_rescope));
458  m_treeReaders[kTH3FIndex].reset(new TreeObjectReader<TH3F>(MonitorElementData::Kind::TH3F, m_rescope));
459  m_treeReaders[kTProfileIndex].reset(new TreeObjectReader<TProfile>(MonitorElementData::Kind::TPROFILE, m_rescope));
460  m_treeReaders[kTProfile2DIndex].reset(
461  new TreeObjectReader<TProfile2D>(MonitorElementData::Kind::TPROFILE2D, m_rescope));
462  }
463 
464  produces<DQMToken, edm::Transition::BeginRun>("DQMGenerationRecoRun");
465  produces<DQMToken, edm::Transition::BeginLuminosityBlock>("DQMGenerationRecoLumi");
466 }
467 
469  for (auto& file : m_openFiles) {
470  if (file.m_file && file.m_file->IsOpen()) {
471  logFileAction("Closed file", "");
472  }
473  }
474 }
475 
476 //
477 // member functions
478 //
479 
481 
482 // We will read the metadata of all files and fill m_fileMetadatas vector
483 std::shared_ptr<edm::FileBlock> DQMRootSource::readFile_() {
484  const int numFiles = m_catalog.fileNames(0).size();
485  m_openFiles.reserve(numFiles);
486 
487  for (auto& fileitem : m_catalog.fileCatalogItems()) {
488  TFile* file;
489  std::string pfn;
490  std::string lfn;
491  std::list<std::string> exInfo;
492  //loop over names of a file, each of them corresponds to a data catalog
493  bool isGoodFile(true);
494  //get all names of a file, each of them corresponds to a data catalog
495  const std::vector<std::string>& fNames = fileitem.fileNames();
496  for (std::vector<std::string>::const_iterator it = fNames.begin(); it != fNames.end(); ++it) {
497  // Try to open a file
498  try {
499  file = TFile::Open(it->c_str());
500 
501  // Exception will be trapped so we pull it out ourselves
502  std::exception_ptr e = edm::threadLocalException::getException();
503  if (e != std::exception_ptr()) {
504  edm::threadLocalException::setException(std::exception_ptr());
505  std::rethrow_exception(e);
506  }
507 
508  } catch (cms::Exception const& e) {
509  file = nullptr; // is there anything we need to free?
510  if (std::next(it) == fNames.end()) { //last name corresponding to the last data catalog to try
511  if (!m_skipBadFiles) {
513  ex.addContext("Opening DQM Root file");
514  ex << "\nInput file " << *it << " was not found, could not be opened, or is corrupted.\n";
515  //report previous exceptions when use other names to open file
516  for (auto const& s : exInfo)
517  ex.addAdditionalInfo(s);
518  throw ex;
519  }
520  isGoodFile = false;
521  }
522  // save in case of error when trying next name
523  for (auto const& s : e.additionalInfo())
524  exInfo.push_back(s);
525  }
526 
527  // Check if a file is usable
528  if (file && !file->IsZombie()) {
529  logFileAction("Successfully opened file ", it->c_str());
530  pfn = *it;
531  lfn = fileitem.logicalFileName();
532  break;
533  } else {
534  if (std::next(it) == fNames.end()) {
535  if (!m_skipBadFiles) {
537  ex << "Input file " << *it << " could not be opened.\n";
538  ex.addContext("Opening DQM Root file");
539  //report previous exceptions when use other names to open file
540  for (auto const& s : exInfo)
541  ex.addAdditionalInfo(s);
542  throw ex;
543  }
544  isGoodFile = false;
545  }
546  if (file) {
547  delete file;
548  file = nullptr;
549  }
550  }
551  } //end loop over names of the file
552 
553  if (!isGoodFile && m_skipBadFiles)
554  continue;
555 
556  std::unique_ptr<std::string> guid{file->Get<std::string>(kCmsGuid)};
557  if (not guid) {
558  guid = std::make_unique<std::string>(file->GetUUID().AsString());
559  std::transform(guid->begin(), guid->end(), guid->begin(), (int (*)(int))std::toupper);
560  }
561 
563  auto jrToken = jr->inputFileOpened(
564  pfn, lfn, std::string(), std::string(), "DQMRootSource", "source", *guid, std::vector<std::string>());
565  m_openFiles.emplace_back(file, jrToken);
566 
567  // Check file format version, which is encoded in the Title of the TFile
568  if (strcmp(file->GetTitle(), "1") != 0) {
570  ex << "Input file " << fNames[0] << " does not appear to be a DQM Root file.\n";
571  }
572 
573  // Read metadata from the file
574  TTree* indicesTree = dynamic_cast<TTree*>(file->Get(kIndicesTree));
575  assert(indicesTree != nullptr);
576 
577  FileMetadata temp;
578  // Each line of metadata will be read into the coresponding fields of temp.
579  indicesTree->SetBranchAddress(kRunBranch, &temp.m_run);
580  indicesTree->SetBranchAddress(kLumiBranch, &temp.m_lumi);
581  indicesTree->SetBranchAddress(kBeginTimeBranch, &temp.m_beginTime);
582  indicesTree->SetBranchAddress(kEndTimeBranch, &temp.m_endTime);
583  indicesTree->SetBranchAddress(kTypeBranch, &temp.m_type);
584  indicesTree->SetBranchAddress(kFirstIndex, &temp.m_firstIndex);
585  indicesTree->SetBranchAddress(kLastIndex, &temp.m_lastIndex);
586 
587  for (Long64_t index = 0; index != indicesTree->GetEntries(); ++index) {
588  indicesTree->GetEntry(index);
589  temp.m_file = file;
590 
591  if (keepIt(temp.m_run, temp.m_lumi)) {
592  m_fileMetadatas.push_back(temp);
593  }
594  }
595 
596  } //end loop over files
597 
598  // Sort to make sure runs and lumis appear in sequential order
599  std::stable_sort(m_fileMetadatas.begin(), m_fileMetadatas.end());
600 
601  // If we have lumisections without matching runs, insert dummy runs here.
602  unsigned int run = 0;
603  auto toadd = std::vector<FileMetadata>();
604  for (auto& metadata : m_fileMetadatas) {
605  if (run < metadata.m_run && metadata.m_lumi != 0) {
606  // run transition and lumi transition at the same time!
607  FileMetadata dummy{}; // zero initialize
608  dummy.m_run = metadata.m_run;
609  dummy.m_lumi = 0;
610  dummy.m_type = kNoTypesStored;
611  toadd.push_back(dummy);
612  }
613  run = metadata.m_run;
614  }
615 
616  if (!toadd.empty()) {
617  // rather than trying to insert at the right places, just append and sort again.
618  m_fileMetadatas.insert(m_fileMetadatas.end(), toadd.begin(), toadd.end());
619  std::stable_sort(m_fileMetadatas.begin(), m_fileMetadatas.end());
620  }
621 
622  //for (auto& metadata : m_fileMetadatas)
623  // metadata.describe();
624 
625  // Stop if there's nothing to process. Otherwise start the run.
626  if (m_fileMetadatas.empty())
628  else
630 
631  // We have to return something but not sure why
632  return std::make_shared<edm::FileBlock>();
633 }
634 
635 std::shared_ptr<edm::RunAuxiliary> DQMRootSource::readRunAuxiliary_() {
636  FileMetadata metadata = m_fileMetadatas[m_currentIndex];
637  auto runAux =
638  edm::RunAuxiliary(metadata.m_run, edm::Timestamp(metadata.m_beginTime), edm::Timestamp(metadata.m_endTime));
639  return std::make_shared<edm::RunAuxiliary>(runAux);
640 }
641 
642 std::shared_ptr<edm::LuminosityBlockAuxiliary> DQMRootSource::readLuminosityBlockAuxiliary_() {
643  FileMetadata metadata = m_fileMetadatas[m_currentIndex];
645  edm::Timestamp(metadata.m_beginTime),
646  edm::Timestamp(metadata.m_endTime));
647  return std::make_shared<edm::LuminosityBlockAuxiliary>(lumiAux);
648 }
649 
651  // Read elements of a current run.
652  do {
653  FileMetadata metadata = m_fileMetadatas[m_currentIndex];
654  if (metadata.m_lumi == 0) {
655  readElements();
656  }
657  m_currentIndex++;
658  } while (!isRunOrLumiTransition());
659 
661 
663  jr->reportInputRunNumber(rpCache.id().run());
665 }
666 
668  // Read elements of a current lumi.
669  do {
670  readElements();
671  m_currentIndex++;
672  } while (!isRunOrLumiTransition());
673 
675 
677  jr->reportInputLumiSection(lbCache.id().run(), lbCache.id().luminosityBlock());
679 }
680 
682 
684  FileMetadata metadata = m_fileMetadatas[m_currentIndex];
685 
686  if (metadata.m_type != kNoTypesStored) {
687  std::shared_ptr<TreeReaderBase> reader = m_treeReaders[metadata.m_type];
688  TTree* tree = dynamic_cast<TTree*>(metadata.m_file->Get(kTypeNames[metadata.m_type]));
689  // The Reset() below screws up the tree, so we need to re-read it from file
690  // before use here.
691  tree->Refresh();
692 
693  reader->setTree(tree);
694 
695  ULong64_t index = metadata.m_firstIndex;
696  ULong64_t endIndex = metadata.m_lastIndex + 1;
697 
698  for (; index != endIndex; ++index) {
699  reader->read(index, edm::Service<DQMStore>().operator->(), metadata.m_run, metadata.m_lumi);
700  }
701  // Drop buffers in the TTree. This reduces memory consuption while the tree
702  // just sits there and waits for the next block to be read.
703  tree->Reset();
704  }
705 }
706 
708  if (m_currentIndex == 0) {
709  return false;
710  }
711 
712  if (m_currentIndex > m_fileMetadatas.size() - 1) {
713  // We reached the end
714  return true;
715  }
716 
717  FileMetadata previousMetadata = m_fileMetadatas[m_currentIndex - 1];
718  FileMetadata metadata = m_fileMetadatas[m_currentIndex];
719 
720  return previousMetadata.m_run != metadata.m_run || previousMetadata.m_lumi != metadata.m_lumi;
721 }
722 
724  if (m_currentIndex == 0) {
726  } else if (m_currentIndex > m_fileMetadatas.size() - 1) {
727  // We reached the end
729  } else {
730  FileMetadata previousMetadata = m_fileMetadatas[m_currentIndex - 1];
731  FileMetadata metadata = m_fileMetadatas[m_currentIndex];
732 
733  if (previousMetadata.m_run != metadata.m_run) {
735  } else if (previousMetadata.m_lumi != metadata.m_lumi) {
737  }
738  }
739 }
740 
742  std::unique_ptr<DQMToken> product = std::make_unique<DQMToken>();
743  run.put(std::move(product), "DQMGenerationRecoRun");
744 }
745 
747  std::unique_ptr<DQMToken> product = std::make_unique<DQMToken>();
748  lumi.put(std::move(product), "DQMGenerationRecoLumi");
749 }
750 
752  if (m_filterOnRun != 0 && run != m_filterOnRun) {
753  return false;
754  }
755 
756  if (m_lumisToProcess.empty()) {
757  return true;
758  }
759 
760  for (edm::LuminosityBlockRange const& lumiToProcess : m_lumisToProcess) {
761  if (run >= lumiToProcess.startRun() && run <= lumiToProcess.endRun()) {
762  if (lumi >= lumiToProcess.startLumi() && lumi <= lumiToProcess.endLumi()) {
763  return true;
764  } else if (lumi == 0) {
765  return true;
766  }
767  }
768  }
769  return false;
770 }
771 
772 void DQMRootSource::logFileAction(char const* msg, char const* fileName) const {
773  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay() << msg << fileName;
775 }
776 
777 //
778 // const member functions
779 //
780 
781 //
782 // static member functions
783 //
edm::InputSource::ItemType m_nextItemType
static const char *const kRunBranch
Definition: format.h:63
LuminosityBlockNumber_t luminosityBlock() const
std::vector< std::string > fileNames(unsigned iCatalog) const
std::unique_ptr< TFile > m_file
std::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_() override
static const char *const kTypeNames[]
Definition: format.h:41
MonitorElementData::Scope m_rescope
void readNextItemType()
void FlushMessageLog()
void reportInputRunNumber(unsigned int run)
Definition: JobReport.cc:471
void fillLuminosityBlockPrincipal(ProcessHistory const *processHistory, DelayedReader *reader=nullptr)
RunID const & id() const
Definition: RunPrincipal.h:65
static void mergeTogether(TH1 *original, TH1 *toAdd)
ProcessHistoryID const & processHistoryID() const
static const char *const kIndicesTree
Definition: format.h:62
edm::propagate_const< std::unique_ptr< TH1 > > object_
void setTree(TTree *iTree) override
RunNumber_t run() const
Accessor for current run number.
Definition: InputSource.cc:457
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:69
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:64
unsigned int m_filterOnRun
void beginLuminosityBlock(edm::LuminosityBlock &lumi) override
reader
Definition: DQM.py:105
static const char *const kFullNameBranch
Definition: format.h:57
Log< level::Error, false > LogError
assert(be >=bs)
unsigned int LuminosityBlockNumber_t
unsigned int m_currentIndex
const DQMRootSource & operator=(const DQMRootSource &)=delete
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)
#define DEFINE_FWK_INPUT_SOURCE(type)
void setTree(TTree *iTree) override
void beginRun(edm::Run &run) override
void reportInputLumiSection(unsigned int run, unsigned int lumiSectId)
Definition: JobReport.cc:465
std::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_() override
edm::InputFileCatalog m_catalog
static const char *const kFlagBranch
Definition: format.h:58
void addAdditionalInfo(std::string const &info)
Definition: Exception.cc:169
static const char *const kTypeBranch
Definition: format.h:68
static const char *const kEndTimeBranch
Definition: format.h:67
RunNumber_t run() const
std::size_t Token
Definition: JobReport.h:106
bool isRunOrLumiTransition() const
ProcessHistoryRegistry const & processHistoryRegistry() const
Accessors for process history registry.
Definition: InputSource.h:140
dqm::harvesting::MonitorElement MonitorElement
void read(ULong64_t iIndex, DQMStore *dqmstore, int run, int lumi) override
static const char *const kCmsGuid
Definition: format.h:73
static const char *const kLastIndex
Definition: format.h:70
std::vector< std::shared_ptr< TreeReaderBase > > m_treeReaders
TreeStringReader(MonitorElementData::Kind kind, MonitorElementData::Scope rescope)
std::vector< edm::LuminosityBlockRange > m_lumisToProcess
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
MonitorElement * putME(MonitorElement *me)
Definition: DQMStore.cc:148
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:329
void read(ULong64_t iIndex, DQMStore *dqmstore, int run, int lumi) override
void logFileAction(char const *msg, char const *fileName) const
HLT enums.
static const char *const kBeginTimeBranch
Definition: format.h:66
TreeReaderBase(MonitorElementData::Kind kind, MonitorElementData::Scope rescope)
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
bool keepIt(edm::RunNumber_t, edm::LuminosityBlockNumber_t) const
unsigned int RunNumber_t
dqm::harvesting::DQMStore DQMStore
LuminosityBlockAuxiliary const & aux() const
void fillRunPrincipal(ProcessHistoryRegistry const &processHistoryRegistry, DelayedReader *reader=nullptr)
Definition: RunPrincipal.cc:28
DQMRootSource(edm::ParameterSet const &, const edm::InputSourceDescription &)
Definition: tree.py:1
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
def move(src, dest)
Definition: eostools.py:511
RunNumber_t run() const
Definition: RunID.h:36
bool operator<(const FileMetadata &obj) const
Definition: Run.h:45
static const char *const kValueBranch
Definition: format.h:59
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)