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