CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 // $Id: DQMRootSource.cc,v 1.32 2013/06/06 07:52:17 deguio Exp $
12 //
13 
14 // system include files
15 #include <vector>
16 #include <string>
17 #include <map>
18 #include <memory>
19 #include <list>
20 #include <set>
21 #include "TFile.h"
22 #include "TTree.h"
23 #include "TString.h"
24 #include "TH1.h"
25 #include "TH2.h"
26 #include "TProfile.h"
27 
28 // user include files
36 //#include "FWCore/Utilities/interface/GlobalIdentifier.h"
38 
41 
44 
47 
50 
53 
58 
60 
61 #include "format.h"
62 
63 namespace {
64  //adapter functions
65  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH1F* iHist) {
66  //std::cout <<"create: hist size "<<iName <<" "<<iHist->GetEffectiveEntries()<<std::endl;
67  return iStore.book1D(iName, iHist);
68  }
69  //NOTE: the merge logic comes from DataFormats/Histograms/interface/MEtoEDMFormat.h
70  void mergeTogether(TH1* iOriginal,TH1* iToAdd) {
71  if(iOriginal->TestBit(TH1::kCanRebin)==true && iToAdd->TestBit(TH1::kCanRebin) ==true) {
72  TList list;
73  list.Add(iToAdd);
74  if( -1 == iOriginal->Merge(&list)) {
75  edm::LogError("MergeFailure")<<"Failed to merge DQM element "<<iOriginal->GetName();
76  }
77  } else {
78  if (iOriginal->GetNbinsX() == iToAdd->GetNbinsX() &&
79  iOriginal->GetXaxis()->GetXmin() == iToAdd->GetXaxis()->GetXmin() &&
80  iOriginal->GetXaxis()->GetXmax() == iToAdd->GetXaxis()->GetXmax() &&
81  iOriginal->GetNbinsY() == iToAdd->GetNbinsY() &&
82  iOriginal->GetYaxis()->GetXmin() == iToAdd->GetYaxis()->GetXmin() &&
83  iOriginal->GetYaxis()->GetXmax() == iToAdd->GetYaxis()->GetXmax() &&
84  iOriginal->GetNbinsZ() == iToAdd->GetNbinsZ() &&
85  iOriginal->GetZaxis()->GetXmin() == iToAdd->GetZaxis()->GetXmin() &&
86  iOriginal->GetZaxis()->GetXmax() == iToAdd->GetZaxis()->GetXmax()) {
87  iOriginal->Add(iToAdd);
88  } else {
89  edm::LogError("MergeFailure")<<"Found histograms with different axis limits '"<<iOriginal->GetName()<<"' not merged.";
90  }
91  }
92  }
93  void mergeWithElement(MonitorElement* iElement, TH1F* iHist) {
94  //std::cout <<"merge: hist size "<<iElement->getName() <<" "<<iHist->GetEffectiveEntries()<<std::endl;
95  mergeTogether(iElement->getTH1F(),iHist);
96  }
97  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH1S* iHist) {
98  return iStore.book1S(iName, iHist);
99  }
100  void mergeWithElement(MonitorElement* iElement, TH1S* iHist) {
101  mergeTogether(iElement->getTH1S(),iHist);
102  }
103  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH1D* iHist) {
104  return iStore.book1DD(iName, iHist);
105  }
106  void mergeWithElement(MonitorElement* iElement, TH1D* iHist) {
107  mergeTogether(iElement->getTH1D(),iHist);
108  }
109  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH2F* iHist) {
110  return iStore.book2D(iName, iHist);
111  }
112  void mergeWithElement(MonitorElement* iElement, TH2F* iHist) {
113  mergeTogether(iElement->getTH2F(),iHist);
114  }
115  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH2S* iHist) {
116  return iStore.book2S(iName, iHist);
117  }
118  void mergeWithElement(MonitorElement* iElement, TH2S* iHist) {
119  mergeTogether(iElement->getTH2S(),iHist);
120  }
121  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH2D* iHist) {
122  return iStore.book2DD(iName, iHist);
123  }
124  void mergeWithElement(MonitorElement* iElement, TH2D* iHist) {
125  mergeTogether(iElement->getTH2D(),iHist);
126  }
127  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH3F* iHist) {
128  return iStore.book3D(iName, iHist);
129  }
130  void mergeWithElement(MonitorElement* iElement, TH3F* iHist) {
131  mergeTogether(iElement->getTH3F(),iHist);
132  }
133  MonitorElement* createElement(DQMStore& iStore, const char* iName, TProfile* iHist) {
134  return iStore.bookProfile(iName, iHist);
135  }
136  void mergeWithElement(MonitorElement* iElement, TProfile* iHist) {
137  mergeTogether(iElement->getTProfile(),iHist);
138  }
139  MonitorElement* createElement(DQMStore& iStore, const char* iName, TProfile2D* iHist) {
140  return iStore.bookProfile2D(iName, iHist);
141  }
142  void mergeWithElement(MonitorElement* iElement, TProfile2D* iHist) {
143  mergeTogether(iElement->getTProfile2D(),iHist);
144  }
145 
146  MonitorElement* createElement(DQMStore& iStore, const char* iName, Long64_t& iValue) {
147  MonitorElement* e = iStore.bookInt(iName);
148  e->Fill(iValue);
149  return e;
150  }
151 
152  //NOTE: the merge logic comes from DataFormats/Histograms/interface/MEtoEDMFormat.h
153  void mergeWithElement(MonitorElement* iElement, Long64_t& iValue) {
154  const std::string& name = iElement->getFullname();
155  if(name.find("EventInfo/processedEvents") != std::string::npos) {
156  iElement->Fill(iValue+iElement->getIntValue());
157  } else {
158  if(name.find("EventInfo/iEvent") != std::string::npos ||
159  name.find("EventInfo/iLumiSection") != std::string::npos) {
160  if(iValue > iElement->getIntValue()) {
161  iElement->Fill(iValue);
162  }
163  }
164  }
165  }
166 
167  MonitorElement* createElement(DQMStore& iStore, const char* iName, double& iValue) {
168  MonitorElement* e = iStore.bookFloat(iName);
169  e->Fill(iValue);
170  return e;
171  }
172  void mergeWithElement(MonitorElement* iElement, double& iValue) {
173  //no merging
174  }
175  MonitorElement* createElement(DQMStore& iStore, const char* iName, std::string* iValue) {
176  return iStore.bookString(iName,*iValue);
177  }
178  void mergeWithElement(MonitorElement* , std::string* ) {
179  //no merging
180  }
181 
182  void splitName(const std::string& iFullName, std::string& oPath,const char*& oName) {
183  oPath = iFullName;
184  size_t index = oPath.find_last_of('/');
185  if(index == std::string::npos) {
186  oPath = std::string();
187  oName = iFullName.c_str();
188  } else {
189  oPath.resize(index);
190  oName = iFullName.c_str()+index+1;
191  }
192  }
193 
194  struct RunLumiToRange {
195  unsigned int m_run, m_lumi,m_historyIDIndex;
196  ULong64_t m_beginTime;
197  ULong64_t m_endTime;
198  ULong64_t m_firstIndex, m_lastIndex; //last is inclusive
199  unsigned int m_type; //A value in TypeIndex
200  };
201 
202  class TreeReaderBase {
203  public:
204  TreeReaderBase() {}
205  virtual ~TreeReaderBase() {}
206 
207  MonitorElement* read(ULong64_t iIndex, DQMStore& iStore, bool iIsLumi){
208  return doRead(iIndex,iStore,iIsLumi);
209  }
210  virtual void setTree(TTree* iTree) =0;
211  protected:
212  TTree* m_tree;
213  private:
214  virtual MonitorElement* doRead(ULong64_t iIndex, DQMStore& iStore, bool iIsLumi)=0;
215  };
216 
217  template<class T>
218  class TreeObjectReader: public TreeReaderBase {
219  public:
220  TreeObjectReader():m_tree(0),m_fullName(0),m_buffer(0),m_tag(0){
221  }
222  virtual MonitorElement* doRead(ULong64_t iIndex, DQMStore& iStore, bool iIsLumi) {
223  m_tree->GetEntry(iIndex);
224  MonitorElement* element = iStore.get(*m_fullName);
225  if(0 == element) {
227  const char* name;
228  splitName(*m_fullName, path,name);
229  iStore.setCurrentFolder(path);
230  element = createElement(iStore,name,m_buffer);
231  if(iIsLumi) { element->setLumiFlag();}
232  } else {
233  mergeWithElement(element,m_buffer);
234  }
235  if(0!= m_tag) {
236  iStore.tag(element,m_tag);
237  }
238  return element;
239  }
240  virtual void setTree(TTree* iTree) {
241  m_tree = iTree;
242  m_tree->SetBranchAddress(kFullNameBranch,&m_fullName);
243  m_tree->SetBranchAddress(kFlagBranch,&m_tag);
244  m_tree->SetBranchAddress(kValueBranch,&m_buffer);
245  }
246  private:
247  TTree* m_tree;
248  std::string* m_fullName;
249  T* m_buffer;
250  uint32_t m_tag;
251  };
252 
253  template<class T>
254  class TreeSimpleReader : public TreeReaderBase {
255  public:
256  TreeSimpleReader():m_tree(0),m_fullName(0),m_buffer(),m_tag(0){
257  }
258  virtual MonitorElement* doRead(ULong64_t iIndex, DQMStore& iStore,bool iIsLumi) {
259  m_tree->GetEntry(iIndex);
260  MonitorElement* element = iStore.get(*m_fullName);
261  if(0 == element) {
263  const char* name;
264  splitName(*m_fullName, path,name);
265  iStore.setCurrentFolder(path);
266  element = createElement(iStore,name,m_buffer);
267  if(iIsLumi) { element->setLumiFlag();}
268  } else {
269  mergeWithElement(element, m_buffer);
270  }
271  if(0!=m_tag) {
272  iStore.tag(element,m_tag);
273  }
274  return element;
275  }
276  virtual void setTree(TTree* iTree) {
277  m_tree = iTree;
278  m_tree->SetBranchAddress(kFullNameBranch,&m_fullName);
279  m_tree->SetBranchAddress(kFlagBranch,&m_tag);
280  m_tree->SetBranchAddress(kValueBranch,&m_buffer);
281  }
282  private:
283  TTree* m_tree;
284  std::string* m_fullName;
285  T m_buffer;
286  uint32_t m_tag;
287  };
288 
289 }
290 
292 {
293 
294  public:
296  virtual ~DQMRootSource();
297 
298  // ---------- const member functions ---------------------
299 
300  // ---------- static member functions --------------------
301 
302  // ---------- member functions ---------------------------
303  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
304 
305  private:
306 
307  DQMRootSource(const DQMRootSource&); // stop default
308 
309  class RunPHIDKey {
310  public:
311  RunPHIDKey(edm::ProcessHistoryID const& phid, unsigned int run) :
312  processHistoryID_(phid), run_(run) { }
314  unsigned int run() const { return run_; }
315  bool operator<(RunPHIDKey const& right) const {
316  if (processHistoryID_ == right.processHistoryID()) {
317  return run_ < right.run();
318  }
319  return processHistoryID_ < right.processHistoryID();
320  }
321  private:
323  unsigned int run_;
324  };
325 
327  public:
328  RunLumiPHIDKey(edm::ProcessHistoryID const& phid, unsigned int run, unsigned int lumi) :
329  processHistoryID_(phid), run_(run), lumi_(lumi) { }
331  unsigned int run() const { return run_; }
332  unsigned int lumi() const { return lumi_; }
333  bool operator<(RunLumiPHIDKey const& right) const {
334  if (processHistoryID_ == right.processHistoryID()) {
335  if (run_ == right.run()) {
336  return lumi_ < right.lumi();
337  }
338  return run_ < right.run();
339  }
340  return processHistoryID_ < right.processHistoryID();
341  }
342  private:
344  unsigned int run_;
345  unsigned int lumi_;
346  };
347 
349  //NOTE: the following is really read next run auxiliary
350  virtual boost::shared_ptr<edm::RunAuxiliary> readRunAuxiliary_() ;
351  virtual boost::shared_ptr<edm::LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_() ;
352  virtual boost::shared_ptr<edm::RunPrincipal> readRun_(boost::shared_ptr<edm::RunPrincipal> rpCache);
353  virtual boost::shared_ptr<edm::LuminosityBlockPrincipal> readLuminosityBlock_( boost::shared_ptr<edm::LuminosityBlockPrincipal> lbCache);
355 
356  virtual std::unique_ptr<edm::FileBlock> readFile_();
357  virtual void closeFile_();
358 
359  void logFileAction(char const* msg, char const* fileName) const;
360 
361  void readNextItemType();
362  void setupFile(unsigned int iIndex);
363  void readElements();
364 
365  const DQMRootSource& operator=(const DQMRootSource&); // stop default
366 
367  // ---------- member data --------------------------------
372 
373  size_t m_fileIndex;
375  std::list<unsigned int>::iterator m_nextIndexItr;
376  std::list<unsigned int>::iterator m_presentIndexItr;
377  std::vector<RunLumiToRange> m_runlumiToRange;
378  std::auto_ptr<TFile> m_file;
379  std::vector<TTree*> m_trees;
380  std::vector<boost::shared_ptr<TreeReaderBase> > m_treeReaders;
381 
382  std::list<unsigned int> m_orderedIndices;
384  unsigned int m_lastSeenRun;
386  unsigned int m_lastSeenRun2;
387  unsigned int m_lastSeenLumi2;
388  unsigned int m_filterOnRun;
391  std::set<MonitorElement*> m_lumiElements;
392  std::set<MonitorElement*> m_runElements;
393  std::vector<edm::ProcessHistoryID> m_historyIDs;
394  std::vector<edm::ProcessHistoryID> m_reducedHistoryIDs;
395 
397 };
398 
399 //
400 // constants, enums and typedefs
401 //
402 
403 //
404 // static data member definitions
405 //
406 
407 void
410  desc.addUntracked<std::vector<std::string> >("fileNames")
411  ->setComment("Names of files to be processed.");
412  desc.addUntracked<unsigned int>("filterOnRun",0)
413  ->setComment("Just limit the process to the selected run.");
414  desc.addUntracked<std::string>("overrideCatalog",std::string())
415  ->setComment("An alternate file catalog to use instead of the standard site one.");
416  descriptions.addDefault(desc);
417 }
418 //
419 // constructors and destructor
420 //
422  edm::InputSource(iPSet,iDesc),
423  m_catalog(iPSet.getUntrackedParameter<std::vector<std::string> >("fileNames"),
424  iPSet.getUntrackedParameter<std::string>("overrideCatalog")),
425  m_nextItemType(edm::InputSource::IsFile),
426  m_fileIndex(0),
427  m_presentlyOpenFileIndex(0),
428  m_trees(kNIndicies,static_cast<TTree*>(0)),
429  m_treeReaders(kNIndicies,boost::shared_ptr<TreeReaderBase>()),
430  m_lastSeenReducedPHID(),
431  m_lastSeenRun(0),
432  m_lastSeenReducedPHID2(),
433  m_lastSeenRun2(0),
434  m_lastSeenLumi2(0),
435  m_filterOnRun(iPSet.getUntrackedParameter<unsigned int>("filterOnRun", 0)),
436  m_justOpenedFileSoNeedToGenerateRunTransition(false),
437  m_shouldReadMEs(true)
438 {
439  if(m_fileIndex ==m_catalog.fileNames().size()) {
441  } else{
442  m_treeReaders[kIntIndex].reset(new TreeSimpleReader<Long64_t>());
443  m_treeReaders[kFloatIndex].reset(new TreeSimpleReader<double>());
444  m_treeReaders[kStringIndex].reset(new TreeObjectReader<std::string>());
445  m_treeReaders[kTH1FIndex].reset(new TreeObjectReader<TH1F>());
446  m_treeReaders[kTH1SIndex].reset(new TreeObjectReader<TH1S>());
447  m_treeReaders[kTH1DIndex].reset(new TreeObjectReader<TH1D>());
448  m_treeReaders[kTH2FIndex].reset(new TreeObjectReader<TH2F>());
449  m_treeReaders[kTH2SIndex].reset(new TreeObjectReader<TH2S>());
450  m_treeReaders[kTH2DIndex].reset(new TreeObjectReader<TH2D>());
451  m_treeReaders[kTH3FIndex].reset(new TreeObjectReader<TH3F>());
452  m_treeReaders[kTProfileIndex].reset(new TreeObjectReader<TProfile>());
453  m_treeReaders[kTProfile2DIndex].reset(new TreeObjectReader<TProfile2D>());
454  }
455 
456 }
457 
458 // DQMRootSource::DQMRootSource(const DQMRootSource& rhs)
459 // {
460 // // do actual copying here;
461 // }
462 
464 {
465  if(m_file.get() != 0 && m_file->IsOpen()) {
466  m_file->Close();
467  logFileAction(" Closed file ", m_catalog.fileNames()[m_presentlyOpenFileIndex].c_str());
468  }
469 }
470 
471 //
472 // assignment operators
473 //
474 // const DQMRootSource& DQMRootSource::operator=(const DQMRootSource& rhs)
475 // {
476 // //An exception safe implementation is
477 // DQMRootSource temp(rhs);
478 // swap(rhs);
479 //
480 // return *this;
481 // }
482 
483 //
484 // member functions
485 //
487 {
488  return 0;
489 }
490 
492 {
493  //std::cout <<"getNextItemType "<<m_nextItemType<<std::endl;
494  return m_nextItemType;
495 }
496 
497 boost::shared_ptr<edm::RunAuxiliary> DQMRootSource::readRunAuxiliary_()
498 {
499  //std::cout <<"readRunAuxiliary_"<<std::endl;
500  assert(m_nextIndexItr != m_orderedIndices.end());
501  RunLumiToRange runLumiRange = m_runlumiToRange[*m_nextIndexItr];
502 
503  //NOTE: the setBeginTime and setEndTime functions of RunAuxiliary only work if the previous value was invalid
504  // therefore we must copy
505  m_runAux = edm::RunAuxiliary(runLumiRange.m_run,edm::Timestamp(runLumiRange.m_beginTime),edm::Timestamp(runLumiRange.m_endTime));
506  assert(m_historyIDs.size() > runLumiRange.m_historyIDIndex);
507  //std::cout <<"readRunAuxiliary_ "<<m_historyIDs[runLumiRange.m_historyIDIndex]<<std::endl;
508  m_runAux.setProcessHistoryID(m_historyIDs[runLumiRange.m_historyIDIndex]);
509  return boost::shared_ptr<edm::RunAuxiliary>( new edm::RunAuxiliary(m_runAux) );
510 }
511 
512 boost::shared_ptr<edm::LuminosityBlockAuxiliary>
514 {
515  //std::cout <<"readLuminosityBlockAuxiliary_"<<std::endl;
516  assert(m_nextIndexItr != m_orderedIndices.end());
517  const RunLumiToRange runLumiRange = m_runlumiToRange[*m_nextIndexItr];
518  m_lumiAux = edm::LuminosityBlockAuxiliary(edm::LuminosityBlockID(runLumiRange.m_run,runLumiRange.m_lumi),
519  edm::Timestamp(runLumiRange.m_beginTime),
520  edm::Timestamp(runLumiRange.m_endTime));
521  assert(m_historyIDs.size() > runLumiRange.m_historyIDIndex);
522  //std::cout <<"lumi "<<m_lumiAux.beginTime().value()<<" "<<runLumiRange.m_beginTime<<std::endl;
523  m_lumiAux.setProcessHistoryID(m_historyIDs[runLumiRange.m_historyIDIndex]);
524 
525  return boost::shared_ptr<edm::LuminosityBlockAuxiliary>(new edm::LuminosityBlockAuxiliary(m_lumiAux));
526 }
527 
528 boost::shared_ptr<edm::RunPrincipal>
529 DQMRootSource::readRun_(boost::shared_ptr<edm::RunPrincipal> rpCache)
530 {
531  assert(m_presentIndexItr != m_orderedIndices.end());
532  RunLumiToRange runLumiRange = m_runlumiToRange[*m_presentIndexItr];
533 
535  unsigned int runID =rpCache->id().run();
536  assert(runID == runLumiRange.m_run);
537 
538  m_shouldReadMEs = (m_filterOnRun == 0 ||
539  (m_filterOnRun != 0 && m_filterOnRun == runID));
540  // std::cout <<"readRun_"<<std::endl;
541  // std::cout <<"m_shouldReadMEs " << m_shouldReadMEs <<std::endl;
542 
553  //NOTE: need to reset all run elements at this point
554  if( m_lastSeenRun != runID ||
555  m_lastSeenReducedPHID != m_reducedHistoryIDs.at(runLumiRange.m_historyIDIndex) ) {
556  if (m_shouldReadMEs) {
558  std::vector<MonitorElement*> allMEs = (*store).getAllContents("");
559  for(auto const& ME : allMEs) {
560  // We do not want to reset here Lumi products, since a dedicated
561  // resetting is done at every lumi transition.
562  if (ME->getLumiFlag()) continue;
563  if ( !(*store).isCollate() )
564  ME->Reset();
565  }
566  }
567  m_lastSeenReducedPHID = m_reducedHistoryIDs.at(runLumiRange.m_historyIDIndex);
568  m_lastSeenRun = runID;
569  }
570 
572 
573  //NOTE: it is possible to have a Run when all we have stored is lumis
574  if(runLumiRange.m_lumi == 0) {
575  readElements();
576  }
577 
579  jr->reportInputRunNumber(rpCache->id().run());
580 
581  rpCache->fillRunPrincipal();
582  return rpCache;
583 }
584 
585 boost::shared_ptr<edm::LuminosityBlockPrincipal>
586 DQMRootSource::readLuminosityBlock_( boost::shared_ptr<edm::LuminosityBlockPrincipal> lbCache)
587 {
588  assert(m_presentIndexItr != m_orderedIndices.end());
589  RunLumiToRange runLumiRange = m_runlumiToRange[*m_presentIndexItr];
590  assert(runLumiRange.m_run == lbCache->id().run());
591  assert(runLumiRange.m_lumi == lbCache->id().luminosityBlock());
592 
593  //NOTE: need to reset all lumi block elements at this point
594  if( ( m_lastSeenLumi2 != runLumiRange.m_lumi ||
595  m_lastSeenRun2 != runLumiRange.m_run ||
596  m_lastSeenReducedPHID2 != m_reducedHistoryIDs.at(runLumiRange.m_historyIDIndex) )
597  && m_shouldReadMEs) {
598 
600  std::vector<MonitorElement*> allMEs = (*store).getAllContents("");
601  for(auto const& ME : allMEs) {
602  // We do not want to reset Run Products here!
603  if (ME->getLumiFlag()) {
604  ME->Reset();
605  }
606  }
607  m_lastSeenReducedPHID2 = m_reducedHistoryIDs.at(runLumiRange.m_historyIDIndex);
608  m_lastSeenRun2 = runLumiRange.m_run;
609  m_lastSeenLumi2 = runLumiRange.m_lumi;
610  }
612  //std::cout <<"readLuminosityBlock_"<<std::endl;
613 
614  readElements();
615 
617  jr->reportInputLumiSection(lbCache->id().run(),lbCache->id().luminosityBlock());
618 
619  lbCache->fillLuminosityBlockPrincipal();
620  return lbCache;
621 }
622 
623 std::unique_ptr<edm::FileBlock>
625  //std::cout <<"readFile_"<<std::endl;
627  ++m_fileIndex;
629 
633  std::string(),
634  std::string(),
635  "DQMRootSource",
636  "source",
637  m_file->GetUUID().AsString(),//edm::createGlobalIdentifier(),
638  std::vector<std::string>()
639  );
640 
641  return std::unique_ptr<edm::FileBlock>(new edm::FileBlock);
642 }
643 
644 void
648 }
649 
652  RunLumiToRange runLumiRange = m_runlumiToRange[*m_presentIndexItr];
653  bool shouldContinue = false;
654  do
655  {
656  shouldContinue = false;
658  if(runLumiRange.m_type == kNoTypesStored) {continue;}
659  boost::shared_ptr<TreeReaderBase> reader = m_treeReaders[runLumiRange.m_type];
660  ULong64_t index = runLumiRange.m_firstIndex;
661  ULong64_t endIndex = runLumiRange.m_lastIndex+1;
662  for (; index != endIndex; ++index)
663  {
664  bool isLumi = runLumiRange.m_lumi !=0;
665  if (m_shouldReadMEs)
666  reader->read(index,*store,isLumi);
667 // if (isLumi)
668 // {
669 // std::cout << runLumiRange.m_run << " " << runLumiRange.m_lumi << " lumi element "<< element->getFullname()<<" "<<index<< " " << runLumiRange.m_type << std::endl;
670 // m_lumiElements.insert(element);
671 // }
672 // else
673 // {
674 // std::cout << runLumiRange.m_run << " " << runLumiRange.m_lumi << " run element "<< element->getFullname()<<" "<<index<< " " << runLumiRange.m_type << std::endl;
675 // m_runElements.insert(element);
676 // }
677  }
678  if (m_presentIndexItr != m_orderedIndices.end())
679  {
680  //are there more parts to this same run/lumi?
681  const RunLumiToRange nextRunLumiRange = m_runlumiToRange[*m_presentIndexItr];
682  //continue to the next item if that item is either
683  if ( (m_reducedHistoryIDs.at(nextRunLumiRange.m_historyIDIndex) == m_reducedHistoryIDs.at(runLumiRange.m_historyIDIndex)) &&
684  (nextRunLumiRange.m_run == runLumiRange.m_run) &&
685  (nextRunLumiRange.m_lumi == runLumiRange.m_lumi) )
686  {
687  shouldContinue= true;
688  runLumiRange = nextRunLumiRange;
689  }
690  }
691  } while(shouldContinue);
692 }
693 
695 {
696  //Do the work of actually figuring out where next to go
697 
698  assert (m_nextIndexItr != m_orderedIndices.end());
699  RunLumiToRange runLumiRange = m_runlumiToRange[*m_nextIndexItr];
700 
702  if (runLumiRange.m_lumi != 0 && m_nextItemType == edm::InputSource::IsRun) {
704  return;
705  }
706  ++m_nextIndexItr;
707  }
708  else
709  {
710  //NOTE: the following makes the iterator not be advanced in the
711  //do while loop below.
712  runLumiRange.m_run=0;
713  }
714 
715  bool shouldContinue = false;
716  do
717  {
718  shouldContinue = false;
719  if (m_nextIndexItr == m_orderedIndices.end())
720  {
721  //go to next file
723  //std::cout <<"going to next file"<<std::endl;
724  if(m_fileIndex == m_catalog.fileNames().size()) {
726  }
727  break;
728  }
729  const RunLumiToRange nextRunLumiRange = m_runlumiToRange[*m_nextIndexItr];
730  //continue to the next item if that item is the same run or lumi as we just did
731  if( (m_reducedHistoryIDs.at(nextRunLumiRange.m_historyIDIndex) == m_reducedHistoryIDs.at(runLumiRange.m_historyIDIndex) ) &&
732  (nextRunLumiRange.m_run == runLumiRange.m_run) &&
733  (nextRunLumiRange.m_lumi == runLumiRange.m_lumi) ) {
734  shouldContinue= true;
735  ++m_nextIndexItr;
736  //std::cout <<" advancing " <<nextRunLumiRange.m_run<<" "<<nextRunLumiRange.m_lumi<<std::endl;
737  }
738  } while(shouldContinue);
739 
740  if(m_nextIndexItr != m_orderedIndices.end()) {
745  } else {
747  }
748  }
749 }
750 
751 void
752 DQMRootSource::setupFile(unsigned int iIndex)
753 {
754  if(m_file.get() != 0 && iIndex > 0) {
755  m_file->Close();
756  logFileAction(" Closed file ", m_catalog.fileNames()[iIndex-1].c_str());
757  }
758  logFileAction(" Initiating request to open file ", m_catalog.fileNames()[iIndex].c_str());
759  m_presentlyOpenFileIndex = iIndex;
760  try {
761  m_file = std::auto_ptr<TFile>(TFile::Open(m_catalog.fileNames()[iIndex].c_str()));
762  } catch(cms::Exception const& e) {
764  ex.addContext("Opening DQM Root file");
765  ex <<"\nInput file " << m_catalog.fileNames()[iIndex] << " was not found, could not be opened, or is corrupted.\n";
766  throw ex;
767  }
768  if(not m_file->IsZombie()) {
769  logFileAction(" Successfully opened file ", m_catalog.fileNames()[iIndex].c_str());
770  } else {
772  ex<<"Input file "<<m_catalog.fileNames()[iIndex].c_str() <<" could not be opened.\n";
773  ex.addContext("Opening DQM Root file");
774  throw ex;
775  }
776  //Check file format version, which is encoded in the Title of the TFile
777  if(0 != strcmp(m_file->GetTitle(),"1")) {
779  ex<<"Input file "<<m_catalog.fileNames()[iIndex].c_str() <<" does not appear to be a DQM Root file.\n";
780  }
781 
782  //Get meta Data
783  TDirectory* metaDir = m_file->GetDirectory(kMetaDataDirectoryAbsolute);
784  if(0==metaDir) {
786  ex<<"Input file "<<m_catalog.fileNames()[iIndex].c_str() <<" appears to be corrupted since it does not have the proper internal structure.\n"
787  " Check to see if the file was closed properly.\n";
788  ex.addContext("Opening DQM Root file");
789  throw ex;
790  }
791  TTree* parameterSetTree = dynamic_cast<TTree*>(metaDir->Get(kParameterSetTree));
792  assert(0!=parameterSetTree);
793 
795  assert(0!=psr);
796  {
797  std::string blob;
798  std::string* pBlob = &blob;
799  parameterSetTree->SetBranchAddress(kParameterSetBranch,&pBlob);
800  for(unsigned int index = 0; index != parameterSetTree->GetEntries();++index)
801  {
802  parameterSetTree->GetEntry(index);
803  cms::Digest dg(blob);
804  edm::ParameterSetID psID(dg.digest().toString());
805  edm::ParameterSet temp(blob,psID);
806  }
807  }
808 
809  {
810  TTree* processHistoryTree = dynamic_cast<TTree*>(metaDir->Get(kProcessHistoryTree));
811  assert(0!=processHistoryTree);
812  unsigned int phIndex = 0;
813  processHistoryTree->SetBranchAddress(kPHIndexBranch,&phIndex);
814  std::string processName;
815  std::string* pProcessName = &processName;
816  processHistoryTree->SetBranchAddress(kProcessConfigurationProcessNameBranch,&pProcessName);
817  std::string parameterSetIDBlob;
818  std::string* pParameterSetIDBlob = &parameterSetIDBlob;
819  processHistoryTree->SetBranchAddress(kProcessConfigurationParameterSetIDBranch,&pParameterSetIDBlob);
820  std::string releaseVersion;
821  std::string* pReleaseVersion = &releaseVersion;
822  processHistoryTree->SetBranchAddress(kProcessConfigurationReleaseVersion,&pReleaseVersion);
823  std::string passID;
824  std::string* pPassID = &passID;
825  processHistoryTree->SetBranchAddress(kProcessConfigurationPassID,&pPassID);
826 
828  assert(0!=pcr);
830  assert(0!=phr);
831  std::vector<edm::ProcessConfiguration> configs;
832  configs.reserve(5);
833  m_historyIDs.clear();
834  m_reducedHistoryIDs.clear();
835  for(unsigned int i=0; i != processHistoryTree->GetEntries(); ++i) {
836  processHistoryTree->GetEntry(i);
837  if(phIndex==0) {
838  if(not configs.empty()) {
839  edm::ProcessHistory ph(configs);
840  m_historyIDs.push_back(ph.id());
841  phr->insertMapped(ph);
842  m_reducedHistoryIDs.push_back(phr->extra().reduceProcessHistoryID(ph.id()));
843  }
844  configs.clear();
845  }
846  edm::ParameterSetID psetID(parameterSetIDBlob);
847  edm::ProcessConfiguration pc(processName, psetID,releaseVersion,passID);
848  pcr->insertMapped(pc);
849  configs.push_back(pc);
850  }
851  if(not configs.empty()) {
852  edm::ProcessHistory ph(configs);
853  m_historyIDs.push_back(ph.id());
854  phr->insertMapped( ph);
855  m_reducedHistoryIDs.push_back(phr->extra().reduceProcessHistoryID(ph.id()));
856  //std::cout <<"inserted "<<ph.id()<<std::endl;
857  }
858  }
859 
860  //Setup the indices
861  TTree* indicesTree = dynamic_cast<TTree*>(m_file->Get(kIndicesTree));
862  assert(0!=indicesTree);
863 
864  m_runlumiToRange.clear();
865  m_runlumiToRange.reserve(indicesTree->GetEntries());
866  m_orderedIndices.clear();
867 
868  RunLumiToRange temp;
869  indicesTree->SetBranchAddress(kRunBranch,&temp.m_run);
870  indicesTree->SetBranchAddress(kLumiBranch,&temp.m_lumi);
871  indicesTree->SetBranchAddress(kBeginTimeBranch,&temp.m_beginTime);
872  indicesTree->SetBranchAddress(kEndTimeBranch,&temp.m_endTime);
873  indicesTree->SetBranchAddress(kProcessHistoryIndexBranch,&temp.m_historyIDIndex);
874  indicesTree->SetBranchAddress(kTypeBranch,&temp.m_type);
875  indicesTree->SetBranchAddress(kFirstIndex,&temp.m_firstIndex);
876  indicesTree->SetBranchAddress(kLastIndex,&temp.m_lastIndex);
877 
878  //Need to reorder items since if there was a merge done the same Run
879  //and/or Lumi can appear multiple times but we want to process them
880  //all at once
881 
882  //We use a std::list for m_orderedIndices since inserting into the
883  //middle of a std::list does not disrupt the iterators to already
884  //existing entries
885 
886  //The Map is used to see if a Run/Lumi pair has appeared before
887  typedef std::map<RunLumiPHIDKey, std::list<unsigned int>::iterator > RunLumiToLastEntryMap;
888  RunLumiToLastEntryMap runLumiToLastEntryMap;
889 
890  //Need to group all lumis for the same run together and move the run
891  //entry to the beginning
892  typedef std::map<RunPHIDKey, std::pair< std::list<unsigned int>::iterator, std::list<unsigned int>::iterator> > RunToFirstLastEntryMap;
893  RunToFirstLastEntryMap runToFirstLastEntryMap;
894 
895  for (Long64_t index = 0; index != indicesTree->GetEntries(); ++index)
896  {
897  indicesTree->GetEntry(index);
898 // std::cout <<"read r:"<<temp.m_run
899 // <<" l:"<<temp.m_lumi
900 // <<" b:"<<temp.m_beginTime
901 // <<" e:"<<temp.m_endTime
902 // <<" fi:" << temp.m_firstIndex
903 // <<" li:" << temp.m_lastIndex
904 // <<" type:" << temp.m_type << std::endl;
905  m_runlumiToRange.push_back(temp);
906 
907  RunLumiPHIDKey runLumi(m_reducedHistoryIDs.at(temp.m_historyIDIndex), temp.m_run, temp.m_lumi);
908  RunPHIDKey runKey(m_reducedHistoryIDs.at(temp.m_historyIDIndex), temp.m_run);
909 
910  RunLumiToLastEntryMap::iterator itFind = runLumiToLastEntryMap.find(runLumi);
911  if (itFind == runLumiToLastEntryMap.end())
912  {
913  //does not already exist
914  //does the run for this already exist?
915  std::list<unsigned int>::iterator itLastOfRun = m_orderedIndices.end();
916 
917  RunToFirstLastEntryMap::iterator itRunFirstLastEntryFind = runToFirstLastEntryMap.find(runKey);
918  bool needNewEntryInRunFirstLastEntryMap = true;
919  if (itRunFirstLastEntryFind != runToFirstLastEntryMap.end())
920  {
921  needNewEntryInRunFirstLastEntryMap=false;
922  if (temp.m_lumi!=0)
923  {
924  //lumis go to the end
925  itLastOfRun = itRunFirstLastEntryFind->second.second;
926  //we want to insert after this one so must advance the iterator
927  ++itLastOfRun;
928  }
929  else
930  {
931  //runs go at the beginning
932  itLastOfRun = itRunFirstLastEntryFind->second.first;
933  }
934  }
935  std::list<unsigned int>::iterator iter = m_orderedIndices.insert(itLastOfRun,index);
936  runLumiToLastEntryMap[runLumi]=iter;
937  if (needNewEntryInRunFirstLastEntryMap)
938  runToFirstLastEntryMap[runKey]=std::make_pair(iter,iter);
939  else
940  {
941  if(temp.m_lumi!=0)
942  {
943  //lumis go at end
944  runToFirstLastEntryMap[runKey].second = iter;
945  }
946  else
947  {
948  //since we haven't yet seen this run/lumi combination it means we haven't yet seen
949  // a run so we can put this first
950  runToFirstLastEntryMap[runKey].first = iter;
951  }
952  }
953  }
954  else
955  {
956  //We need to do a merge since the run/lumi already appeared. Put it after the existing entry
957  //std::cout <<" found a second instance of "<<runLumi.first<<" "<<runLumi.second<<" at "<<index<<std::endl;
958  std::list<unsigned int>::iterator itNext = itFind->second;
959  ++itNext;
960  std::list<unsigned int>::iterator iter = m_orderedIndices.insert(itNext,index);
961  RunToFirstLastEntryMap::iterator itRunFirstLastEntryFind = runToFirstLastEntryMap.find(runKey);
962  if (itRunFirstLastEntryFind->second.second == itFind->second)
963  {
964  //if the previous one was the last in the run, we need to update to make this one the last
965  itRunFirstLastEntryFind->second.second = iter;
966  }
967  itFind->second = iter;
968  }
969  }
972 
973  if(m_nextIndexItr != m_orderedIndices.end()) {
974  for( size_t index = 0; index < kNIndicies; ++index) {
975  m_trees[index] = dynamic_cast<TTree*>(m_file->Get(kTypeNames[index]));
976  assert(0!=m_trees[index]);
977  m_treeReaders[index]->setTree(m_trees[index]);
978  }
979  }
980  //After a file open, the framework expects to see a new 'IsRun'
982 }
983 
984 void
985 DQMRootSource::logFileAction(char const* msg, char const* fileName) const {
986  edm::LogAbsolute("fileAction") << std::setprecision(0) << edm::TimeOfDay() << msg << fileName;
988 }
989 
990 //
991 // const member functions
992 //
993 
994 //
995 // static member functions
996 //
const DQMRootSource & operator=(const DQMRootSource &)
virtual boost::shared_ptr< edm::LuminosityBlockAuxiliary > readLuminosityBlockAuxiliary_()
TH2S * getTH2S(void) const
TH1S * getTH1S(void) const
edm::InputSource::ItemType m_nextItemType
unsigned int m_lastSeenRun2
int i
Definition: DBlmapReader.cc:9
static const char *const kProcessHistoryTree
Definition: format.h:55
static const char *const kRunBranch
Definition: format.h:42
unsigned int lumi() const
MonitorElement * book2S(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2S histogram.
Definition: DQMStore.cc:872
virtual boost::shared_ptr< edm::RunPrincipal > readRun_(boost::shared_ptr< edm::RunPrincipal > rpCache)
virtual boost::shared_ptr< edm::LuminosityBlockPrincipal > readLuminosityBlock_(boost::shared_ptr< edm::LuminosityBlockPrincipal > lbCache)
static const char *const kTypeNames[]
Definition: format.h:29
edm::JobReport::Token m_jrToken
void readNextItemType()
virtual void closeFile_()
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
TProfile2D * getTProfile2D(void) const
void logFileAction(char const *msg, char const *fileName) const
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:722
edm::RunAuxiliary m_runAux
void FlushMessageLog()
std::vector< boost::shared_ptr< TreeReaderBase > > m_treeReaders
edm::ProcessHistoryID const & processHistoryID() const
MonitorElement * book3D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ)
Book 3D histogram.
Definition: DQMStore.cc:984
static ThreadSafeRegistry * instance()
MonitorElement * book2DD(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D double histogram.
Definition: DQMStore.cc:894
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:502
static const char *const kIndicesTree
Definition: format.h:41
std::set< MonitorElement * > m_lumiElements
virtual boost::shared_ptr< edm::RunAuxiliary > readRunAuxiliary_()
static const char *const kFirstIndex
Definition: format.h:48
TH3F * getTH3F(void) const
TH1D * getTH1D(void) const
static const char *const kLumiBranch
Definition: format.h:43
size_t m_presentlyOpenFileIndex
std::list< unsigned int >::iterator m_presentIndexItr
unsigned int m_filterOnRun
bool operator<(RunPHIDKey const &right) const
std::set< MonitorElement * > m_runElements
TH2D * getTH2D(void) const
static const char *const kFullNameBranch
Definition: format.h:35
MonitorElement * book1DD(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1S histogram.
Definition: DQMStore.cc:754
MD5Result digest() const
Definition: Digest.cc:194
bool insertMapped(value_type const &v)
std::vector< edm::ProcessHistoryID > m_reducedHistoryIDs
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:659
unsigned int run() const
void Fill(long long x)
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1359
Definition: ME.h:11
static const char *const kPHIndexBranch
Definition: format.h:56
static const char *const kParameterSetBranch
Definition: format.h:63
virtual edm::InputSource::ItemType getNextItemType()
std::vector< RunLumiToRange > m_runlumiToRange
void addDefault(ParameterSetDescription const &psetDescription)
edm::LuminosityBlockAuxiliary m_lumiAux
#define DEFINE_FWK_INPUT_SOURCE(type)
std::vector< edm::ProcessHistoryID > m_historyIDs
edm::ProcessHistoryID const & processHistoryID() const
void inputFileClosed(Token fileToken)
Definition: JobReport.cc:550
MonitorElement * bookString(const char *name, const char *value)
Book string.
Definition: DQMStore.cc:688
edm::ProcessHistoryID processHistoryID_
bool m_justOpenedFileSoNeedToGenerateRunTransition
virtual ~DQMRootSource()
edm::InputFileCatalog m_catalog
edm::ProcessHistoryID m_lastSeenReducedPHID2
static const char *const kParameterSetTree
Definition: format.h:62
std::list< unsigned int > m_orderedIndices
static const char *const kFlagBranch
Definition: format.h:36
static const char *const kTypeBranch
Definition: format.h:47
std::auto_ptr< TFile > m_file
static const char *const kProcessHistoryIndexBranch
Definition: format.h:44
MonitorElement * bookProfile(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, const char *option="s")
Definition: DQMStore.cc:1036
void setProcessHistoryID(ProcessHistoryID const &phid)
static const char *const kEndTimeBranch
Definition: format.h:46
std::vector< std::string > const & logicalFileNames() const
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1473
const std::string getFullname(void) const
get full name of ME including Pathname
void reportInputRunNumber(unsigned int run)
Definition: JobReport.cc:667
std::vector< TTree * > m_trees
unsigned int run() const
std::size_t Token
Definition: JobReport.h:43
static const char *const kProcessConfigurationPassID
Definition: format.h:60
virtual edm::EventPrincipal * readEvent_(edm::EventPrincipal &)
static const char *const kMetaDataDirectoryAbsolute
Definition: format.h:52
std::vector< std::string > const & fileNames() const
unsigned int m_lastSeenLumi2
static const char *const kLastIndex
Definition: format.h:49
int64_t getIntValue(void) const
std::string toString() const
Definition: Digest.cc:87
bool operator<(RunLumiPHIDKey const &right) const
TH1F * getTH1F(void) const
static const char *const kProcessConfigurationReleaseVersion
Definition: format.h:59
void addContext(std::string const &context)
Definition: Exception.cc:227
static const char *const kProcessConfigurationProcessNameBranch
Definition: format.h:57
edm::ProcessHistoryID m_lastSeenReducedPHID
virtual std::unique_ptr< edm::FileBlock > readFile_()
static const char *const kBeginTimeBranch
Definition: format.h:45
TProfile * getTProfile(void) const
void reportInputLumiSection(unsigned int run, unsigned int lumiSectId)
Definition: JobReport.cc:658
RunPHIDKey(edm::ProcessHistoryID const &phid, unsigned int run)
void setupFile(unsigned int iIndex)
RunLumiPHIDKey(edm::ProcessHistoryID const &phid, unsigned int run, unsigned int lumi)
std::list< unsigned int >::iterator m_nextIndexItr
void setProcessHistoryID(ProcessHistoryID const &phid)
Definition: RunAuxiliary.h:36
DQMRootSource(edm::ParameterSet const &, const edm::InputSourceDescription &)
void setLumiFlag(void)
this ME is meant to be stored for each luminosity section
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
TH2F * getTH2F(void) const
MonitorElement * bookInt(const char *name)
Book int.
Definition: DQMStore.cc:629
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:850
long double T
ProcessHistoryID id() const
unsigned int m_lastSeenRun
edm::ProcessHistoryID processHistoryID_
MonitorElement * book1S(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1S histogram.
Definition: DQMStore.cc:738
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:434
Helper class to handle FWLite file input sources.
static const char *const kValueBranch
Definition: format.h:37
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
static const char *const kProcessConfigurationParameterSetIDBranch
Definition: format.h:58
MonitorElement * bookProfile2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, int nchZ, double lowZ, double highZ, const char *option="s")
Definition: DQMStore.cc:1180