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  try {
198  m_tree->GetEntry(iIndex);
199 
200  auto key = makeKey(*m_fullName, run, lumi);
201  auto existing = dqmstore->findOrRecycle(key);
202  if (existing) {
203  // TODO: make sure there is sufficient locking here.
205  } else {
206  // We make our own MEs here, to avoid a round-trip through the booking API.
207  MonitorElementData meData;
208  meData.key_ = key;
209  meData.value_.object_ = std::unique_ptr<T>((T*)(m_buffer->Clone()));
210  auto me = new MonitorElement(std::move(meData));
211  dqmstore->putME(me);
212  }
213  } catch (cms::Exception& iExcept) {
214  using namespace std::string_literals;
215  iExcept.addContext("failed while reading "s + *m_fullName);
216  throw;
217  }
218  }
219 
220  void setTree(TTree* iTree) override {
221  m_tree = iTree;
222  m_tree->SetBranchAddress(kFullNameBranch, &m_fullName);
223  m_tree->SetBranchAddress(kFlagBranch, &m_tag);
224  m_tree->SetBranchAddress(kValueBranch, &m_buffer);
225  }
226 
227  private:
228  TTree* m_tree = nullptr;
230  T* m_buffer = nullptr;
231  uint32_t m_tag = 0;
232  };
233 
235  public:
238  }
239 
240  void read(ULong64_t iIndex, DQMStore* dqmstore, int run, int lumi) override {
241  // This will populate the fields as defined in setTree method
242  m_tree->GetEntry(iIndex);
243 
244  auto key = makeKey(*m_fullName, run, lumi);
245  auto existing = dqmstore->findOrRecycle(key);
246 
247  if (existing) {
248  existing->Fill(*m_value);
249  } else {
250  // We make our own MEs here, to avoid a round-trip through the booking API.
251  MonitorElementData meData;
252  meData.key_ = key;
253  meData.value_.scalar_.str = *m_value;
254  auto me = new MonitorElement(std::move(meData));
255  dqmstore->putME(me);
256  }
257  }
258 
259  void setTree(TTree* iTree) override {
260  m_tree = iTree;
261  m_tree->SetBranchAddress(kFullNameBranch, &m_fullName);
262  m_tree->SetBranchAddress(kFlagBranch, &m_tag);
263  m_tree->SetBranchAddress(kValueBranch, &m_value);
264  }
265 
266  private:
267  TTree* m_tree = nullptr;
269  std::string* m_value = nullptr;
270  uint32_t m_tag = 0;
271  };
272 
273  template <class T>
275  public:
278  }
279 
280  void read(ULong64_t iIndex, DQMStore* dqmstore, int run, int lumi) override {
281  // This will populate the fields as defined in setTree method
282  m_tree->GetEntry(iIndex);
283 
284  auto key = makeKey(*m_fullName, run, lumi);
285  auto existing = dqmstore->findOrRecycle(key);
286 
287  if (existing) {
288  existing->Fill(m_buffer);
289  } else {
290  // We make our own MEs here, to avoid a round-trip through the booking API.
291  MonitorElementData meData;
292  meData.key_ = key;
294  meData.value_.scalar_.num = m_buffer;
296  meData.value_.scalar_.real = m_buffer;
297  auto me = new MonitorElement(std::move(meData));
298  dqmstore->putME(me);
299  }
300  }
301 
302  void setTree(TTree* iTree) override {
303  m_tree = iTree;
304  m_tree->SetBranchAddress(kFullNameBranch, &m_fullName);
305  m_tree->SetBranchAddress(kFlagBranch, &m_tag);
306  m_tree->SetBranchAddress(kValueBranch, &m_buffer);
307  }
308 
309  private:
310  TTree* m_tree = nullptr;
312  T m_buffer = 0;
313  uint32_t m_tag = 0;
314  };
315 };
316 
318 public:
320  DQMRootSource(const DQMRootSource&) = delete;
321  ~DQMRootSource() override;
322 
323  // ---------- const member functions ---------------------
324 
325  const DQMRootSource& operator=(const DQMRootSource&) = delete; // stop default
326 
327  // ---------- static member functions --------------------
328 
329  // ---------- member functions ---------------------------
330  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
331 
332 private:
333  edm::InputSource::ItemType getNextItemType() override;
334 
335  std::shared_ptr<edm::FileBlock> readFile_() override;
336  std::shared_ptr<edm::RunAuxiliary> readRunAuxiliary_() override;
337  std::shared_ptr<edm::LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_() override;
338  void readRun_(edm::RunPrincipal& rpCache) override;
339  void readLuminosityBlock_(edm::LuminosityBlockPrincipal& lbCache) override;
340  void readEvent_(edm::EventPrincipal&) override;
341 
342  // Read MEs from m_fileMetadatas to DQMStore till run or lumi transition
343  void readElements();
344  // True if m_currentIndex points to an element that has a different
345  // run or lumi than the previous element (a transition needs to happen).
346  // False otherwise.
347  bool isRunOrLumiTransition() const;
348  void readNextItemType();
349 
350  // These methods will be called by the framework.
351  // MEs in DQMStore will be put to products.
352  void beginRun(edm::Run& run) override;
353  void beginLuminosityBlock(edm::LuminosityBlock& lumi) override;
354 
355  // If the run matches the filterOnRun configuration parameter, the run
356  // (and all its lumis) will be kept.
357  // Otherwise, check if a run and a lumi are in the range that needs to be processed.
358  // Range is retrieved from lumisToProcess configuration parameter.
359  // If at least one lumi of a run needs to be kept, per run MEs of that run will also be kept.
361  void logFileAction(char const* msg, char const* fileName) const;
362 
363  // ---------- member data --------------------------------
364 
365  // Properties from python config
367  unsigned int m_filterOnRun;
369  std::vector<edm::LuminosityBlockRange> m_lumisToProcess;
371 
373  // Each ME type gets its own reader
374  std::vector<std::shared_ptr<TreeReaderBase>> m_treeReaders;
375 
376  // Index of currenlty processed row in m_fileMetadatas
377  unsigned int m_currentIndex;
378 
379  // All open DQMIO files
380  struct OpenFileInfo {
381  OpenFileInfo(TFile* file, edm::JobReport::Token jrToken) : m_file(file), m_jrToken(jrToken) {}
385  }
386 
387  OpenFileInfo(OpenFileInfo&&) = default;
388  OpenFileInfo& operator=(OpenFileInfo&&) = default;
389 
390  std::unique_ptr<TFile> m_file;
392  };
393  std::vector<OpenFileInfo> m_openFiles;
394 
395  // An item here is a row read from DQMIO indices (metadata) table
396  std::vector<FileMetadata> m_fileMetadatas;
397 };
398 
399 //
400 // constants, enums and typedefs
401 //
402 
403 //
404 // static data member definitions
405 //
406 
409  desc.addUntracked<std::vector<std::string>>("fileNames")->setComment("Names of files to be processed.");
410  desc.addUntracked<unsigned int>("filterOnRun", 0)->setComment("Just limit the process to the selected run.");
411  desc.addUntracked<std::string>("reScope", "JOB")
412  ->setComment(
413  "Accumulate histograms more coarsely."
414  " Options: \"\": keep unchanged, \"RUN\": turn LUMI histograms into RUN histograms, \"JOB\": turn everything "
415  "into JOB histograms.");
416  desc.addUntracked<bool>("skipBadFiles", false)->setComment("Skip the file if it is not valid");
417  desc.addUntracked<std::string>("overrideCatalog", std::string())
418  ->setComment("An alternate file catalog to use instead of the standard site one.");
419  std::vector<edm::LuminosityBlockRange> defaultLumis;
420  desc.addUntracked<std::vector<edm::LuminosityBlockRange>>("lumisToProcess", defaultLumis)
421  ->setComment("Skip any lumi inside the specified run:lumi range.");
422 
423  descriptions.addDefault(desc);
424 }
425 
426 //
427 // constructors and destructor
428 //
429 
431  : edm::PuttableSourceBase(iPSet, iDesc),
432  m_skipBadFiles(iPSet.getUntrackedParameter<bool>("skipBadFiles", false)),
433  m_filterOnRun(iPSet.getUntrackedParameter<unsigned int>("filterOnRun", 0)),
434  m_catalog(iPSet.getUntrackedParameter<std::vector<std::string>>("fileNames"),
435  iPSet.getUntrackedParameter<std::string>("overrideCatalog")),
436  m_lumisToProcess(iPSet.getUntrackedParameter<std::vector<edm::LuminosityBlockRange>>(
437  "lumisToProcess", std::vector<edm::LuminosityBlockRange>())),
438  m_rescope(std::map<std::string, MonitorElementData::Scope>{
439  {"", MonitorElementData::Scope::LUMI},
440  {"LUMI", MonitorElementData::Scope::LUMI},
441  {"RUN", MonitorElementData::Scope::RUN},
442  {"JOB", MonitorElementData::Scope::JOB}}[iPSet.getUntrackedParameter<std::string>("reScope", "JOB")]),
443  m_nextItemType(edm::InputSource::IsFile),
444  m_treeReaders(kNIndicies, std::shared_ptr<TreeReaderBase>()),
445  m_currentIndex(0),
446  m_openFiles(std::vector<OpenFileInfo>()),
447  m_fileMetadatas(std::vector<FileMetadata>()) {
448  edm::sortAndRemoveOverlaps(m_lumisToProcess);
449 
450  if (m_catalog.fileNames(0).empty()) {
451  m_nextItemType = edm::InputSource::IsStop;
452  } else {
453  m_treeReaders[kIntIndex].reset(new TreeSimpleReader<Long64_t>(MonitorElementData::Kind::INT, m_rescope));
454  m_treeReaders[kFloatIndex].reset(new TreeSimpleReader<double>(MonitorElementData::Kind::REAL, m_rescope));
455  m_treeReaders[kStringIndex].reset(new TreeStringReader(MonitorElementData::Kind::STRING, m_rescope));
456  m_treeReaders[kTH1FIndex].reset(new TreeObjectReader<TH1F>(MonitorElementData::Kind::TH1F, m_rescope));
457  m_treeReaders[kTH1SIndex].reset(new TreeObjectReader<TH1S>(MonitorElementData::Kind::TH1S, m_rescope));
458  m_treeReaders[kTH1DIndex].reset(new TreeObjectReader<TH1D>(MonitorElementData::Kind::TH1D, m_rescope));
459  m_treeReaders[kTH1IIndex].reset(new TreeObjectReader<TH1I>(MonitorElementData::Kind::TH1I, m_rescope));
460  m_treeReaders[kTH2FIndex].reset(new TreeObjectReader<TH2F>(MonitorElementData::Kind::TH2F, m_rescope));
461  m_treeReaders[kTH2SIndex].reset(new TreeObjectReader<TH2S>(MonitorElementData::Kind::TH2S, m_rescope));
462  m_treeReaders[kTH2DIndex].reset(new TreeObjectReader<TH2D>(MonitorElementData::Kind::TH2D, m_rescope));
463  m_treeReaders[kTH2IIndex].reset(new TreeObjectReader<TH2I>(MonitorElementData::Kind::TH2I, m_rescope));
464  m_treeReaders[kTH3FIndex].reset(new TreeObjectReader<TH3F>(MonitorElementData::Kind::TH3F, m_rescope));
465  m_treeReaders[kTProfileIndex].reset(new TreeObjectReader<TProfile>(MonitorElementData::Kind::TPROFILE, m_rescope));
466  m_treeReaders[kTProfile2DIndex].reset(
467  new TreeObjectReader<TProfile2D>(MonitorElementData::Kind::TPROFILE2D, m_rescope));
468  }
469 
470  produces<DQMToken, edm::Transition::BeginRun>("DQMGenerationRecoRun");
471  produces<DQMToken, edm::Transition::BeginLuminosityBlock>("DQMGenerationRecoLumi");
472 }
473 
475  for (auto& file : m_openFiles) {
476  if (file.m_file && file.m_file->IsOpen()) {
477  logFileAction("Closed file", "");
478  }
479  }
480 }
481 
482 //
483 // member functions
484 //
485 
487 
488 // We will read the metadata of all files and fill m_fileMetadatas vector
489 std::shared_ptr<edm::FileBlock> DQMRootSource::readFile_() {
490  const int numFiles = m_catalog.fileNames(0).size();
491  m_openFiles.reserve(numFiles);
492 
493  for (auto& fileitem : m_catalog.fileCatalogItems()) {
494  TFile* file = nullptr;
495  std::string pfn;
496  std::string lfn;
497  std::list<std::string> exInfo;
498  //loop over names of a file, each of them corresponds to a data catalog
499  bool isGoodFile(true);
500  //get all names of a file, each of them corresponds to a data catalog
501  const std::vector<std::string>& fNames = fileitem.fileNames();
502  for (std::vector<std::string>::const_iterator it = fNames.begin(); it != fNames.end(); ++it) {
503  // Try to open a file
504  try {
505  file = TFile::Open(it->c_str());
506 
507  // Exception will be trapped so we pull it out ourselves
508  std::exception_ptr e = edm::threadLocalException::getException();
509  if (e != std::exception_ptr()) {
510  edm::threadLocalException::setException(std::exception_ptr());
511  std::rethrow_exception(e);
512  }
513 
514  } catch (cms::Exception const& e) {
515  file = nullptr; // is there anything we need to free?
516  if (std::next(it) == fNames.end()) { //last name corresponding to the last data catalog to try
517  if (!m_skipBadFiles) {
519  ex.addContext("Opening DQM Root file");
520  ex << "\nInput file " << *it << " was not found, could not be opened, or is corrupted.\n";
521  //report previous exceptions when use other names to open file
522  for (auto const& s : exInfo)
523  ex.addAdditionalInfo(s);
524  throw ex;
525  }
526  isGoodFile = false;
527  }
528  // save in case of error when trying next name
529  for (auto const& s : e.additionalInfo())
530  exInfo.push_back(s);
531  }
532 
533  // Check if a file is usable
534  if (file && !file->IsZombie()) {
535  logFileAction("Successfully opened file ", it->c_str());
536  pfn = *it;
537  lfn = fileitem.logicalFileName();
538  break;
539  } else {
540  if (std::next(it) == fNames.end()) {
541  if (!m_skipBadFiles) {
543  ex << "Input file " << *it << " could not be opened.\n";
544  ex.addContext("Opening DQM Root file");
545  //report previous exceptions when use other names to open file
546  for (auto const& s : exInfo)
547  ex.addAdditionalInfo(s);
548  throw ex;
549  }
550  isGoodFile = false;
551  }
552  if (file) {
553  delete file;
554  file = nullptr;
555  }
556  }
557  } //end loop over names of the file
558 
559  if (!file || (!isGoodFile && m_skipBadFiles))
560  continue;
561 
562  std::unique_ptr<std::string> guid{file->Get<std::string>(kCmsGuid)};
563  if (not guid) {
564  guid = std::make_unique<std::string>(file->GetUUID().AsString());
565  std::transform(guid->begin(), guid->end(), guid->begin(), (int (*)(int))std::toupper);
566  }
567 
569  auto jrToken = jr->inputFileOpened(
570  pfn, lfn, std::string(), std::string(), "DQMRootSource", "source", *guid, std::vector<std::string>());
571  m_openFiles.emplace_back(file, jrToken);
572 
573  // Check file format version, which is encoded in the Title of the TFile
574  if (strcmp(file->GetTitle(), "1") != 0) {
576  ex << "Input file " << fNames[0] << " does not appear to be a DQM Root file.\n";
577  }
578 
579  // Read metadata from the file
580  TTree* indicesTree = dynamic_cast<TTree*>(file->Get(kIndicesTree));
581  assert(indicesTree != nullptr);
582 
584  // Each line of metadata will be read into the coresponding fields of temp.
585  indicesTree->SetBranchAddress(kRunBranch, &temp.m_run);
586  indicesTree->SetBranchAddress(kLumiBranch, &temp.m_lumi);
587  indicesTree->SetBranchAddress(kBeginTimeBranch, &temp.m_beginTime);
588  indicesTree->SetBranchAddress(kEndTimeBranch, &temp.m_endTime);
589  indicesTree->SetBranchAddress(kTypeBranch, &temp.m_type);
590  indicesTree->SetBranchAddress(kFirstIndex, &temp.m_firstIndex);
591  indicesTree->SetBranchAddress(kLastIndex, &temp.m_lastIndex);
592 
593  for (Long64_t index = 0; index != indicesTree->GetEntries(); ++index) {
594  indicesTree->GetEntry(index);
595  temp.m_file = file;
596 
597  if (keepIt(temp.m_run, temp.m_lumi)) {
598  m_fileMetadatas.push_back(temp);
599  }
600  }
601 
602  } //end loop over files
603 
604  // Sort to make sure runs and lumis appear in sequential order
605  std::stable_sort(m_fileMetadatas.begin(), m_fileMetadatas.end());
606 
607  // If we have lumisections without matching runs, insert dummy runs here.
608  unsigned int run = 0;
609  auto toadd = std::vector<FileMetadata>();
610  for (auto& metadata : m_fileMetadatas) {
611  if (run < metadata.m_run && metadata.m_lumi != 0) {
612  // run transition and lumi transition at the same time!
613  FileMetadata dummy{}; // zero initialize
614  dummy.m_run = metadata.m_run;
615  dummy.m_lumi = 0;
616  dummy.m_type = kNoTypesStored;
617  toadd.push_back(dummy);
618  }
619  run = metadata.m_run;
620  }
621 
622  if (!toadd.empty()) {
623  // rather than trying to insert at the right places, just append and sort again.
624  m_fileMetadatas.insert(m_fileMetadatas.end(), toadd.begin(), toadd.end());
625  std::stable_sort(m_fileMetadatas.begin(), m_fileMetadatas.end());
626  }
627 
628  //for (auto& metadata : m_fileMetadatas)
629  // metadata.describe();
630 
631  // Stop if there's nothing to process. Otherwise start the run.
632  if (m_fileMetadatas.empty())
634  else
636 
637  // We have to return something but not sure why
638  return std::make_shared<edm::FileBlock>();
639 }
640 
641 std::shared_ptr<edm::RunAuxiliary> DQMRootSource::readRunAuxiliary_() {
643  auto runAux =
644  edm::RunAuxiliary(metadata.m_run, edm::Timestamp(metadata.m_beginTime), edm::Timestamp(metadata.m_endTime));
645  return std::make_shared<edm::RunAuxiliary>(runAux);
646 }
647 
648 std::shared_ptr<edm::LuminosityBlockAuxiliary> DQMRootSource::readLuminosityBlockAuxiliary_() {
651  edm::Timestamp(metadata.m_beginTime),
652  edm::Timestamp(metadata.m_endTime));
653  return std::make_shared<edm::LuminosityBlockAuxiliary>(lumiAux);
654 }
655 
657  // Read elements of a current run.
658  do {
660  if (metadata.m_lumi == 0) {
661  readElements();
662  }
663  m_currentIndex++;
664  } while (!isRunOrLumiTransition());
665 
667 
669  jr->reportInputRunNumber(rpCache.id().run());
671 }
672 
674  // Read elements of a current lumi.
675  do {
676  readElements();
677  m_currentIndex++;
678  } while (!isRunOrLumiTransition());
679 
681 
683  jr->reportInputLumiSection(lbCache.id().run(), lbCache.id().luminosityBlock());
685 }
686 
688 
691 
692  if (metadata.m_type != kNoTypesStored) {
693  std::shared_ptr<TreeReaderBase> reader = m_treeReaders[metadata.m_type];
694  TTree* tree = dynamic_cast<TTree*>(metadata.m_file->Get(kTypeNames[metadata.m_type]));
695  // The Reset() below screws up the tree, so we need to re-read it from file
696  // before use here.
697  tree->Refresh();
698 
699  reader->setTree(tree);
700 
701  ULong64_t index = metadata.m_firstIndex;
702  ULong64_t endIndex = metadata.m_lastIndex + 1;
703 
704  for (; index != endIndex; ++index) {
705  reader->read(index, edm::Service<DQMStore>().operator->(), metadata.m_run, metadata.m_lumi);
706  }
707  // Drop buffers in the TTree. This reduces memory consuption while the tree
708  // just sits there and waits for the next block to be read.
709  tree->Reset();
710  }
711 }
712 
714  if (m_currentIndex == 0) {
715  return false;
716  }
717 
718  if (m_currentIndex > m_fileMetadatas.size() - 1) {
719  // We reached the end
720  return true;
721  }
722 
723  FileMetadata previousMetadata = m_fileMetadatas[m_currentIndex - 1];
725 
726  return previousMetadata.m_run != metadata.m_run || previousMetadata.m_lumi != metadata.m_lumi;
727 }
728 
730  if (m_currentIndex == 0) {
732  } else if (m_currentIndex > m_fileMetadatas.size() - 1) {
733  // We reached the end
735  } else {
736  FileMetadata previousMetadata = m_fileMetadatas[m_currentIndex - 1];
738 
739  if (previousMetadata.m_run != metadata.m_run) {
741  } else if (previousMetadata.m_lumi != metadata.m_lumi) {
743  }
744  }
745 }
746 
748  std::unique_ptr<DQMToken> product = std::make_unique<DQMToken>();
749  run.put(std::move(product), "DQMGenerationRecoRun");
750 }
751 
753  std::unique_ptr<DQMToken> product = std::make_unique<DQMToken>();
754  lumi.put(std::move(product), "DQMGenerationRecoLumi");
755 }
756 
758  if (m_filterOnRun != 0 && run != m_filterOnRun) {
759  return false;
760  }
761 
762  if (m_lumisToProcess.empty()) {
763  return true;
764  }
765 
766  for (edm::LuminosityBlockRange const& lumiToProcess : m_lumisToProcess) {
767  if (run >= lumiToProcess.startRun() && run <= lumiToProcess.endRun()) {
768  if (lumi >= lumiToProcess.startLumi() && lumi <= lumiToProcess.endLumi()) {
769  return true;
770  } else if (lumi == 0) {
771  return true;
772  }
773  }
774  }
775  return false;
776 }
777 
778 void DQMRootSource::logFileAction(char const* msg, char const* fileName) const {
779  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay() << msg << fileName;
781 }
782 
783 //
784 // const member functions
785 //
786 
787 //
788 // static member functions
789 //
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 void logFileAction(char const *msg, std::string const &fileName)
Definition: LH5Reader.cc:31
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:507
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
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:354
~DQMRootSource() override
MonitorElement * findOrRecycle(MonitorElementData::Key const &)
Definition: DQMStore.cc:349
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:501
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:173
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:139
dqm::harvesting::MonitorElement MonitorElement
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
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
void readRun_(edm::RunPrincipal &rpCache) override
void addContext(std::string const &context)
Definition: Exception.cc:169
tuple msg
Definition: mps_check.py:286
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:180
ProcessHistoryRegistry & processHistoryRegistryForUpdate()
Definition: InputSource.h:331
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:25
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:410
edm::JobReport::Token m_jrToken
MonitorElementData::Scope m_rescope
def move(src, dest)
Definition: eostools.py:511
RunNumber_t run() const
Definition: RunID.h:26
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)