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  // All open DQMIO files
373  std::vector<TFile*> m_openFiles;
374  // An item here is a row read from DQMIO indices (metadata) table
375  std::vector<FileMetadata> m_fileMetadatas;
376 };
377 
378 //
379 // constants, enums and typedefs
380 //
381 
382 //
383 // static data member definitions
384 //
385 
388  desc.addUntracked<std::vector<std::string>>("fileNames")->setComment("Names of files to be processed.");
389  desc.addUntracked<unsigned int>("filterOnRun", 0)->setComment("Just limit the process to the selected run.");
390  desc.addUntracked<std::string>("reScope", "JOB")
391  ->setComment(
392  "Accumulate histograms more coarsely."
393  " Options: \"\": keep unchanged, \"RUN\": turn LUMI histograms into RUN histograms, \"JOB\": turn everything "
394  "into JOB histograms.");
395  desc.addUntracked<bool>("skipBadFiles", false)->setComment("Skip the file if it is not valid");
396  desc.addUntracked<std::string>("overrideCatalog", std::string())
397  ->setComment("An alternate file catalog to use instead of the standard site one.");
398  std::vector<edm::LuminosityBlockRange> defaultLumis;
399  desc.addUntracked<std::vector<edm::LuminosityBlockRange>>("lumisToProcess", defaultLumis)
400  ->setComment("Skip any lumi inside the specified run:lumi range.");
401 
402  descriptions.addDefault(desc);
403 }
404 
405 //
406 // constructors and destructor
407 //
408 
410  : edm::PuttableSourceBase(iPSet, iDesc),
411  m_skipBadFiles(iPSet.getUntrackedParameter<bool>("skipBadFiles", false)),
412  m_filterOnRun(iPSet.getUntrackedParameter<unsigned int>("filterOnRun", 0)),
413  m_catalog(iPSet.getUntrackedParameter<std::vector<std::string>>("fileNames"),
414  iPSet.getUntrackedParameter<std::string>("overrideCatalog")),
415  m_lumisToProcess(iPSet.getUntrackedParameter<std::vector<edm::LuminosityBlockRange>>(
416  "lumisToProcess", std::vector<edm::LuminosityBlockRange>())),
417  m_rescope(std::map<std::string, MonitorElementData::Scope>{
418  {"", MonitorElementData::Scope::LUMI},
419  {"LUMI", MonitorElementData::Scope::LUMI},
420  {"RUN", MonitorElementData::Scope::RUN},
421  {"JOB", MonitorElementData::Scope::JOB}}[iPSet.getUntrackedParameter<std::string>("reScope", "JOB")]),
423  m_treeReaders(kNIndicies, std::shared_ptr<TreeReaderBase>()),
424  m_currentIndex(0),
425  m_openFiles(std::vector<TFile*>()),
426  m_fileMetadatas(std::vector<FileMetadata>()) {
427  edm::sortAndRemoveOverlaps(m_lumisToProcess);
428 
429  if (m_catalog.fileNames(0).empty()) {
431  } else {
432  m_treeReaders[kIntIndex].reset(new TreeSimpleReader<Long64_t>(MonitorElementData::Kind::INT, m_rescope));
433  m_treeReaders[kFloatIndex].reset(new TreeSimpleReader<double>(MonitorElementData::Kind::REAL, m_rescope));
434  m_treeReaders[kStringIndex].reset(new TreeStringReader(MonitorElementData::Kind::STRING, m_rescope));
435  m_treeReaders[kTH1FIndex].reset(new TreeObjectReader<TH1F>(MonitorElementData::Kind::TH1F, m_rescope));
436  m_treeReaders[kTH1SIndex].reset(new TreeObjectReader<TH1S>(MonitorElementData::Kind::TH1S, m_rescope));
437  m_treeReaders[kTH1DIndex].reset(new TreeObjectReader<TH1D>(MonitorElementData::Kind::TH1D, m_rescope));
438  m_treeReaders[kTH2FIndex].reset(new TreeObjectReader<TH2F>(MonitorElementData::Kind::TH2F, m_rescope));
439  m_treeReaders[kTH2SIndex].reset(new TreeObjectReader<TH2S>(MonitorElementData::Kind::TH2S, m_rescope));
440  m_treeReaders[kTH2DIndex].reset(new TreeObjectReader<TH2D>(MonitorElementData::Kind::TH2D, m_rescope));
441  m_treeReaders[kTH3FIndex].reset(new TreeObjectReader<TH3F>(MonitorElementData::Kind::TH3F, m_rescope));
442  m_treeReaders[kTProfileIndex].reset(new TreeObjectReader<TProfile>(MonitorElementData::Kind::TPROFILE, m_rescope));
444  new TreeObjectReader<TProfile2D>(MonitorElementData::Kind::TPROFILE2D, m_rescope));
445  }
446 
447  produces<DQMToken, edm::Transition::BeginRun>("DQMGenerationRecoRun");
448  produces<DQMToken, edm::Transition::BeginLuminosityBlock>("DQMGenerationRecoLumi");
449 }
450 
452  for (auto& file : m_openFiles) {
453  if (file != nullptr && file->IsOpen()) {
454  file->Close();
455  logFileAction("Closed file", "");
456  }
457  }
458 }
459 
460 //
461 // member functions
462 //
463 
465 
466 // We will read the metadata of all files and fill m_fileMetadatas vector
467 std::shared_ptr<edm::FileBlock> DQMRootSource::readFile_() {
468  const int numFiles = m_catalog.fileNames(0).size();
469  m_openFiles.reserve(numFiles);
470 
471  for (auto& fileitem : m_catalog.fileCatalogItems()) {
472  TFile* file;
473  std::list<std::string> exInfo;
474  //loop over names of a file, each of them corresponds to a data catalog
475  bool isGoodFile(true);
476  //get all names of a file, each of them corresponds to a data catalog
477  const std::vector<std::string>& fNames = fileitem.fileNames();
478  for (std::vector<std::string>::const_iterator it = fNames.begin(); it != fNames.end(); ++it) {
479  // Try to open a file
480  try {
481  file = TFile::Open(it->c_str());
482 
483  // Exception will be trapped so we pull it out ourselves
484  std::exception_ptr e = edm::threadLocalException::getException();
485  if (e != std::exception_ptr()) {
486  edm::threadLocalException::setException(std::exception_ptr());
487  std::rethrow_exception(e);
488  }
489 
490  } catch (cms::Exception const& e) {
491  file = nullptr; // is there anything we need to free?
492  if (std::next(it) == fNames.end()) { //last name corresponding to the last data catalog to try
493  if (!m_skipBadFiles) {
495  ex.addContext("Opening DQM Root file");
496  ex << "\nInput file " << it->c_str() << " was not found, could not be opened, or is corrupted.\n";
497  //report previous exceptions when use other names to open file
498  for (auto const& s : exInfo)
499  ex.addAdditionalInfo(s);
500  throw ex;
501  }
502  isGoodFile = false;
503  }
504  // save in case of error when trying next name
505  for (auto const& s : e.additionalInfo())
506  exInfo.push_back(s);
507  }
508 
509  // Check if a file is usable
510  if (file && !file->IsZombie()) {
511  logFileAction("Successfully opened file ", it->c_str());
512  break;
513  } else {
514  if (std::next(it) == fNames.end()) {
515  if (!m_skipBadFiles) {
517  ex << "Input file " << it->c_str() << " could not be opened.\n";
518  ex.addContext("Opening DQM Root file");
519  //report previous exceptions when use other names to open file
520  for (auto const& s : exInfo)
521  ex.addAdditionalInfo(s);
522  throw ex;
523  }
524  isGoodFile = false;
525  }
526  if (file) {
527  delete file;
528  file = nullptr;
529  }
530  }
531  } //end loop over names of the file
532 
533  if (!isGoodFile && m_skipBadFiles)
534  continue;
535 
536  m_openFiles.insert(m_openFiles.begin(), file);
537 
538  // Check file format version, which is encoded in the Title of the TFile
539  if (strcmp(file->GetTitle(), "1") != 0) {
541  ex << "Input file " << fNames[0].c_str() << " does not appear to be a DQM Root file.\n";
542  }
543 
544  // Read metadata from the file
545  TTree* indicesTree = dynamic_cast<TTree*>(file->Get(kIndicesTree));
546  assert(indicesTree != nullptr);
547 
549  // Each line of metadata will be read into the coresponding fields of temp.
550  indicesTree->SetBranchAddress(kRunBranch, &temp.m_run);
551  indicesTree->SetBranchAddress(kLumiBranch, &temp.m_lumi);
552  indicesTree->SetBranchAddress(kBeginTimeBranch, &temp.m_beginTime);
553  indicesTree->SetBranchAddress(kEndTimeBranch, &temp.m_endTime);
554  indicesTree->SetBranchAddress(kTypeBranch, &temp.m_type);
555  indicesTree->SetBranchAddress(kFirstIndex, &temp.m_firstIndex);
556  indicesTree->SetBranchAddress(kLastIndex, &temp.m_lastIndex);
557 
558  for (Long64_t index = 0; index != indicesTree->GetEntries(); ++index) {
559  indicesTree->GetEntry(index);
560  temp.m_file = file;
561 
562  if (keepIt(temp.m_run, temp.m_lumi)) {
563  m_fileMetadatas.push_back(temp);
564  }
565  }
566 
567  } //end loop over files
568 
569  // Sort to make sure runs and lumis appear in sequential order
570  std::stable_sort(m_fileMetadatas.begin(), m_fileMetadatas.end());
571 
572  // If we have lumisections without matching runs, insert dummy runs here.
573  unsigned int run = 0;
574  auto toadd = std::vector<FileMetadata>();
575  for (auto& metadata : m_fileMetadatas) {
576  if (run < metadata.m_run && metadata.m_lumi != 0) {
577  // run transition and lumi transition at the same time!
578  FileMetadata dummy{}; // zero initialize
579  dummy.m_run = metadata.m_run;
580  dummy.m_lumi = 0;
581  dummy.m_type = kNoTypesStored;
582  toadd.push_back(dummy);
583  }
584  run = metadata.m_run;
585  }
586 
587  if (!toadd.empty()) {
588  // rather than trying to insert at the right places, just append and sort again.
589  m_fileMetadatas.insert(m_fileMetadatas.end(), toadd.begin(), toadd.end());
590  std::stable_sort(m_fileMetadatas.begin(), m_fileMetadatas.end());
591  }
592 
593  //for (auto& metadata : m_fileMetadatas)
594  // metadata.describe();
595 
596  // Stop if there's nothing to process. Otherwise start the run.
597  if (m_fileMetadatas.empty())
599  else
601 
602  // We have to return something but not sure why
603  return std::make_shared<edm::FileBlock>();
604 }
605 
606 std::shared_ptr<edm::RunAuxiliary> DQMRootSource::readRunAuxiliary_() {
608  auto runAux =
610  return std::make_shared<edm::RunAuxiliary>(runAux);
611 }
612 
613 std::shared_ptr<edm::LuminosityBlockAuxiliary> DQMRootSource::readLuminosityBlockAuxiliary_() {
615  auto lumiAux = edm::LuminosityBlockAuxiliary(edm::LuminosityBlockID(metadata.m_run, metadata.m_lumi),
616  edm::Timestamp(metadata.m_beginTime),
617  edm::Timestamp(metadata.m_endTime));
618  return std::make_shared<edm::LuminosityBlockAuxiliary>(lumiAux);
619 }
620 
622  // Read elements of a current run.
623  do {
625  if (metadata.m_lumi == 0) {
626  readElements();
627  }
628  m_currentIndex++;
629  } while (!isRunOrLumiTransition());
630 
632 
634  jr->reportInputRunNumber(rpCache.id().run());
636 }
637 
639  // Read elements of a current lumi.
640  do {
641  readElements();
642  m_currentIndex++;
643  } while (!isRunOrLumiTransition());
644 
646 
648  jr->reportInputLumiSection(lbCache.id().run(), lbCache.id().luminosityBlock());
650 }
651 
653 
656 
657  if (metadata.m_type != kNoTypesStored) {
658  std::shared_ptr<TreeReaderBase> reader = m_treeReaders[metadata.m_type];
659  TTree* tree = dynamic_cast<TTree*>(metadata.m_file->Get(kTypeNames[metadata.m_type]));
660  // The Reset() below screws up the tree, so we need to re-read it from file
661  // before use here.
662  tree->Refresh();
663 
664  reader->setTree(tree);
665 
666  ULong64_t index = metadata.m_firstIndex;
667  ULong64_t endIndex = metadata.m_lastIndex + 1;
668 
669  for (; index != endIndex; ++index) {
670  reader->read(index, edm::Service<DQMStore>().operator->(), metadata.m_run, metadata.m_lumi);
671  }
672  // Drop buffers in the TTree. This reduces memory consuption while the tree
673  // just sits there and waits for the next block to be read.
674  tree->Reset();
675  }
676 }
677 
679  if (m_currentIndex == 0) {
680  return false;
681  }
682 
683  if (m_currentIndex > m_fileMetadatas.size() - 1) {
684  // We reached the end
685  return true;
686  }
687 
688  FileMetadata previousMetadata = m_fileMetadatas[m_currentIndex - 1];
690 
691  return previousMetadata.m_run != metadata.m_run || previousMetadata.m_lumi != metadata.m_lumi;
692 }
693 
695  if (m_currentIndex == 0) {
697  } else if (m_currentIndex > m_fileMetadatas.size() - 1) {
698  // We reached the end
700  } else {
701  FileMetadata previousMetadata = m_fileMetadatas[m_currentIndex - 1];
703 
704  if (previousMetadata.m_run != metadata.m_run) {
706  } else if (previousMetadata.m_lumi != metadata.m_lumi) {
708  }
709  }
710 }
711 
713  std::unique_ptr<DQMToken> product = std::make_unique<DQMToken>();
714  run.put(std::move(product), "DQMGenerationRecoRun");
715 }
716 
718  std::unique_ptr<DQMToken> product = std::make_unique<DQMToken>();
719  lumi.put(std::move(product), "DQMGenerationRecoLumi");
720 }
721 
723  if (m_filterOnRun != 0 && run != m_filterOnRun) {
724  return false;
725  }
726 
727  if (m_lumisToProcess.empty()) {
728  return true;
729  }
730 
731  for (edm::LuminosityBlockRange const& lumiToProcess : m_lumisToProcess) {
732  if (run >= lumiToProcess.startRun() && run <= lumiToProcess.endRun()) {
733  if (lumi >= lumiToProcess.startLumi() && lumi <= lumiToProcess.endLumi()) {
734  return true;
735  } else if (lumi == 0) {
736  return true;
737  }
738  }
739  }
740  return false;
741 }
742 
743 void DQMRootSource::logFileAction(char const* msg, char const* fileName) const {
744  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay() << msg << fileName;
746 }
747 
748 //
749 // const member functions
750 //
751 
752 //
753 // static member functions
754 //
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::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
std::vector< TFile * > m_openFiles
void read(ULong64_t iIndex, DQMStore *dqmstore, int run, int lumi) override
static const char *const kFirstIndex
Definition: format.h:65
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)
~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
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 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
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 &)
m_openFiles(std::vector< TFile * >())
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void readEvent_(edm::EventPrincipal &) override
long double T
void readLuminosityBlock_(edm::LuminosityBlockPrincipal &lbCache) override
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)