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.21 2011/07/07 16:46:53 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"
36 
39 
42 
45 
48 
50 
54 
56 
57 #include "format.h"
58 
59 namespace {
60  //adapter functions
61  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH1F* iHist) {
62  //std::cout <<"create: hist size "<<iName <<" "<<iHist->GetEffectiveEntries()<<std::endl;
63  return iStore.book1D(iName, iHist);
64  }
65  //NOTE: the merge logic comes from DataFormats/Histograms/interface/MEtoEDMFormat.h
66  void mergeTogether(TH1* iOriginal,TH1* iToAdd) {
67  if(iOriginal->TestBit(TH1::kCanRebin)==true && iToAdd->TestBit(TH1::kCanRebin) ==true) {
68  TList list;
69  list.Add(iToAdd);
70  if( -1 == iOriginal->Merge(&list)) {
71  edm::LogError("MergeFailure")<<"Failed to merge DQM element "<<iOriginal->GetName();
72  }
73  } else {
74  if (iOriginal->GetNbinsX() == iToAdd->GetNbinsX() &&
75  iOriginal->GetXaxis()->GetXmin() == iToAdd->GetXaxis()->GetXmin() &&
76  iOriginal->GetXaxis()->GetXmax() == iToAdd->GetXaxis()->GetXmax() &&
77  iOriginal->GetNbinsY() == iToAdd->GetNbinsY() &&
78  iOriginal->GetYaxis()->GetXmin() == iToAdd->GetYaxis()->GetXmin() &&
79  iOriginal->GetYaxis()->GetXmax() == iToAdd->GetYaxis()->GetXmax() &&
80  iOriginal->GetNbinsZ() == iToAdd->GetNbinsZ() &&
81  iOriginal->GetZaxis()->GetXmin() == iToAdd->GetZaxis()->GetXmin() &&
82  iOriginal->GetZaxis()->GetXmax() == iToAdd->GetZaxis()->GetXmax()) {
83  iOriginal->Add(iToAdd);
84  } else {
85  edm::LogError("MergeFailure")<<"Found histograms with different axis limitsm '"<<iOriginal->GetName()<<"' not merged.";
86  }
87  }
88  }
89  void mergeWithElement(MonitorElement* iElement, TH1F* iHist) {
90  //std::cout <<"merge: hist size "<<iElement->getName() <<" "<<iHist->GetEffectiveEntries()<<std::endl;
91  mergeTogether(iElement->getTH1F(),iHist);
92  }
93  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH1S* iHist) {
94  return iStore.book1S(iName, iHist);
95  }
96  void mergeWithElement(MonitorElement* iElement, TH1S* iHist) {
97  mergeTogether(iElement->getTH1S(),iHist);
98  }
99  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH1D* iHist) {
100  return iStore.book1DD(iName, iHist);
101  }
102  void mergeWithElement(MonitorElement* iElement, TH1D* iHist) {
103  mergeTogether(iElement->getTH1D(),iHist);
104  }
105  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH2F* iHist) {
106  return iStore.book2D(iName, iHist);
107  }
108  void mergeWithElement(MonitorElement* iElement, TH2F* iHist) {
109  mergeTogether(iElement->getTH2F(),iHist);
110  }
111  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH2S* iHist) {
112  return iStore.book2S(iName, iHist);
113  }
114  void mergeWithElement(MonitorElement* iElement, TH2S* iHist) {
115  mergeTogether(iElement->getTH2S(),iHist);
116  }
117  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH2D* iHist) {
118  return iStore.book2DD(iName, iHist);
119  }
120  void mergeWithElement(MonitorElement* iElement, TH2D* iHist) {
121  mergeTogether(iElement->getTH2D(),iHist);
122  }
123  MonitorElement* createElement(DQMStore& iStore, const char* iName, TH3F* iHist) {
124  return iStore.book3D(iName, iHist);
125  }
126  void mergeWithElement(MonitorElement* iElement, TH3F* iHist) {
127  mergeTogether(iElement->getTH3F(),iHist);
128  }
129  MonitorElement* createElement(DQMStore& iStore, const char* iName, TProfile* iHist) {
130  return iStore.bookProfile(iName, iHist);
131  }
132  void mergeWithElement(MonitorElement* iElement, TProfile* iHist) {
133  mergeTogether(iElement->getTProfile(),iHist);
134  }
135  MonitorElement* createElement(DQMStore& iStore, const char* iName, TProfile2D* iHist) {
136  return iStore.bookProfile2D(iName, iHist);
137  }
138  void mergeWithElement(MonitorElement* iElement, TProfile2D* iHist) {
139  mergeTogether(iElement->getTProfile2D(),iHist);
140  }
141 
142  MonitorElement* createElement(DQMStore& iStore, const char* iName, Long64_t& iValue) {
143  MonitorElement* e = iStore.bookInt(iName);
144  e->Fill(iValue);
145  return e;
146  }
147 
148  //NOTE: the merge logic comes from DataFormats/Histograms/interface/MEtoEDMFormat.h
149  void mergeWithElement(MonitorElement* iElement, Long64_t& iValue) {
150  const std::string& name = iElement->getFullname();
151  if(name.find("EventInfo/processedEvents") != std::string::npos) {
152  iElement->Fill(iValue+iElement->getIntValue());
153  } else {
154  if(name.find("EventInfo/iEvent") != std::string::npos ||
155  name.find("EventInfo/iLumiSection") != std::string::npos) {
156  if(iValue > iElement->getIntValue()) {
157  iElement->Fill(iValue);
158  }
159  }
160  }
161  }
162 
163  MonitorElement* createElement(DQMStore& iStore, const char* iName, double& iValue) {
164  MonitorElement* e = iStore.bookFloat(iName);
165  e->Fill(iValue);
166  return e;
167  }
168  void mergeWithElement(MonitorElement* iElement, double& iValue) {
169  //no merging
170  }
171  MonitorElement* createElement(DQMStore& iStore, const char* iName, std::string* iValue) {
172  return iStore.bookString(iName,*iValue);
173  }
174  void mergeWithElement(MonitorElement* , std::string* ) {
175  //no merging
176  }
177 
178  void splitName(const std::string& iFullName, std::string& oPath,const char*& oName) {
179  oPath = iFullName;
180  size_t index = oPath.find_last_of('/');
181  if(index == std::string::npos) {
182  oPath = std::string();
183  oName = iFullName.c_str();
184  } else {
185  oPath.resize(index);
186  oName = iFullName.c_str()+index+1;
187  }
188  }
189 
190  struct RunLumiToRange {
191  unsigned int m_run, m_lumi,m_historyIDIndex;
192  ULong64_t m_beginTime;
193  ULong64_t m_endTime;
194  ULong64_t m_firstIndex, m_lastIndex; //last is inclusive
195  unsigned int m_type; //A value in TypeIndex
196  };
197 
198  class TreeReaderBase {
199  public:
200  TreeReaderBase() {}
201  virtual ~TreeReaderBase() {}
202 
203  MonitorElement* read(ULong64_t iIndex, DQMStore& iStore, bool iIsLumi){
204  return doRead(iIndex,iStore,iIsLumi);
205  }
206  virtual void setTree(TTree* iTree) =0;
207  protected:
208  TTree* m_tree;
209  private:
210  virtual MonitorElement* doRead(ULong64_t iIndex, DQMStore& iStore, bool iIsLumi)=0;
211  };
212 
213  template<class T>
214  class TreeObjectReader: public TreeReaderBase {
215  public:
216  TreeObjectReader():m_tree(0),m_fullName(0),m_buffer(0),m_tag(0){
217  }
218  virtual MonitorElement* doRead(ULong64_t iIndex, DQMStore& iStore, bool iIsLumi) {
219  m_tree->GetEntry(iIndex);
220  MonitorElement* element = iStore.get(*m_fullName);
221  if(0 == element) {
222  std::string path;
223  const char* name;
224  splitName(*m_fullName, path,name);
225  iStore.setCurrentFolder(path);
226  element = createElement(iStore,name,m_buffer);
227  if(iIsLumi) { element->setLumiFlag();}
228  } else {
229  mergeWithElement(element,m_buffer);
230  }
231  if(0!= m_tag) {
232  iStore.tag(element,m_tag);
233  }
234  return element;
235  }
236  virtual void setTree(TTree* iTree) {
237  m_tree = iTree;
238  m_tree->SetBranchAddress(kFullNameBranch,&m_fullName);
239  m_tree->SetBranchAddress(kFlagBranch,&m_tag);
240  m_tree->SetBranchAddress(kValueBranch,&m_buffer);
241  }
242  private:
243  TTree* m_tree;
244  std::string* m_fullName;
245  T* m_buffer;
246  uint32_t m_tag;
247  };
248 
249  template<class T>
250  class TreeSimpleReader : public TreeReaderBase {
251  public:
252  TreeSimpleReader():m_tree(0),m_fullName(0),m_buffer(),m_tag(0){
253  }
254  virtual MonitorElement* doRead(ULong64_t iIndex, DQMStore& iStore,bool iIsLumi) {
255  m_tree->GetEntry(iIndex);
256  MonitorElement* element = iStore.get(*m_fullName);
257  if(0 == element) {
258  std::string path;
259  const char* name;
260  splitName(*m_fullName, path,name);
261  iStore.setCurrentFolder(path);
262  element = createElement(iStore,name,m_buffer);
263  if(iIsLumi) { element->setLumiFlag();}
264  } else {
265  mergeWithElement(element, m_buffer);
266  }
267  if(0!=m_tag) {
268  iStore.tag(element,m_tag);
269  }
270  return element;
271  }
272  virtual void setTree(TTree* iTree) {
273  m_tree = iTree;
274  m_tree->SetBranchAddress(kFullNameBranch,&m_fullName);
275  m_tree->SetBranchAddress(kFlagBranch,&m_tag);
276  m_tree->SetBranchAddress(kValueBranch,&m_buffer);
277  }
278  private:
279  TTree* m_tree;
280  std::string* m_fullName;
281  T m_buffer;
282  uint32_t m_tag;
283  };
284 
285 }
286 
288 {
289 
290  public:
292  virtual ~DQMRootSource();
293 
294  // ---------- const member functions ---------------------
295 
296  // ---------- static member functions --------------------
297 
298  // ---------- member functions ---------------------------
299  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
300  protected:
302  virtual void endRun(edm::Run&);
303 
304  private:
305  DQMRootSource(const DQMRootSource&); // stop default
306 
308  //NOTE: the following is really read next run auxiliary
309  virtual boost::shared_ptr<edm::RunAuxiliary> readRunAuxiliary_() ;
310  virtual boost::shared_ptr<edm::LuminosityBlockAuxiliary> readLuminosityBlockAuxiliary_() ;
311  virtual boost::shared_ptr<edm::RunPrincipal> readRun_(boost::shared_ptr<edm::RunPrincipal> rpCache);
312  virtual boost::shared_ptr<edm::LuminosityBlockPrincipal> readLuminosityBlock_( boost::shared_ptr<edm::LuminosityBlockPrincipal> lbCache);
313  virtual edm::EventPrincipal* readEvent_() ;
314 
315  virtual boost::shared_ptr<edm::FileBlock> readFile_();
316  virtual void closeFile_();
317 
318  void readNextItemType();
319  void setupFile(unsigned int iIndex);
320  void readElements();
321 
322  const DQMRootSource& operator=(const DQMRootSource&); // stop default
323 
324  // ---------- member data --------------------------------
329 
330  size_t m_fileIndex;
331  std::list<unsigned int>::iterator m_nextIndexItr;
332  std::list<unsigned int>::iterator m_presentIndexItr;
333  std::vector<RunLumiToRange> m_runlumiToRange;
334  std::auto_ptr<TFile> m_file;
335  std::vector<TTree*> m_trees;
336  std::vector<boost::shared_ptr<TreeReaderBase> > m_treeReaders;
337 
338  std::list<unsigned int> m_orderedIndices;
339  unsigned int m_lastSeenRun;
342  std::set<MonitorElement*> m_lumiElements;
343  std::set<MonitorElement*> m_runElements;
344  std::vector<edm::ProcessHistoryID> m_historyIDs;
345 
347 };
348 
349 //
350 // constants, enums and typedefs
351 //
352 
353 //
354 // static data member definitions
355 //
356 
357 void
360  desc.addUntracked<std::vector<std::string> >("fileNames")
361  ->setComment("Names of files to be processed.");
362  desc.addUntracked<std::string>("overrideCatalog",std::string())
363  ->setComment("An alternate file catalog to use instead of the standard site one.");
364  descriptions.addDefault(desc);
365 }
366 //
367 // constructors and destructor
368 //
370 edm::InputSource(iPSet,iDesc),
371 m_catalog(iPSet.getUntrackedParameter<std::vector<std::string> >("fileNames"),
372  iPSet.getUntrackedParameter<std::string>("overrideCatalog")),
373 m_nextItemType(edm::InputSource::IsFile),
374 m_fileIndex(0),
375 m_trees(kNIndicies,static_cast<TTree*>(0)),
376 m_treeReaders(kNIndicies,boost::shared_ptr<TreeReaderBase>()),
377 m_lastSeenRun(0),
378 m_justOpenedFileSoNeedToGenerateRunTransition(false),
379 m_doNotReadRemainingPartsOfFileSinceFrameworkTerminating(false)
380 {
381  if(m_fileIndex ==m_catalog.fileNames().size()) {
383  } else{
384  m_treeReaders[kIntIndex].reset(new TreeSimpleReader<Long64_t>());
385  m_treeReaders[kFloatIndex].reset(new TreeSimpleReader<double>());
386  m_treeReaders[kStringIndex].reset(new TreeObjectReader<std::string>());
387  m_treeReaders[kTH1FIndex].reset(new TreeObjectReader<TH1F>());
388  m_treeReaders[kTH1SIndex].reset(new TreeObjectReader<TH1S>());
389  m_treeReaders[kTH1DIndex].reset(new TreeObjectReader<TH1D>());
390  m_treeReaders[kTH2FIndex].reset(new TreeObjectReader<TH2F>());
391  m_treeReaders[kTH2SIndex].reset(new TreeObjectReader<TH2S>());
392  m_treeReaders[kTH2DIndex].reset(new TreeObjectReader<TH2D>());
393  m_treeReaders[kTH3FIndex].reset(new TreeObjectReader<TH3F>());
394  m_treeReaders[kTProfileIndex].reset(new TreeObjectReader<TProfile>());
395  m_treeReaders[kTProfile2DIndex].reset(new TreeObjectReader<TProfile2D>());
396  }
397 
398 }
399 
400 // DQMRootSource::DQMRootSource(const DQMRootSource& rhs)
401 // {
402 // // do actual copying here;
403 // }
404 
406 {
407 }
408 
409 //
410 // assignment operators
411 //
412 // const DQMRootSource& DQMRootSource::operator=(const DQMRootSource& rhs)
413 // {
414 // //An exception safe implementation is
415 // DQMRootSource temp(rhs);
416 // swap(rhs);
417 //
418 // return *this;
419 // }
420 
421 //
422 // member functions
423 //
424 namespace {
425  struct no_deleter {
426  void operator()(void*) {}
427  };
428 }
429 
432 {
433  return 0;
434 }
435 
438 {
439  //std::cout <<"getNextItemType "<<m_nextItemType<<std::endl;
440  return m_nextItemType;
441 }
442 boost::shared_ptr<edm::RunAuxiliary>
444 {
445  //std::cout <<"readRunAuxiliary_"<<std::endl;
446  assert(m_nextIndexItr != m_orderedIndices.end());
447  unsigned int index = *m_nextIndexItr;
448  RunLumiToRange runLumiRange = m_runlumiToRange[index];
449  //NOTE: this could be a lumi instead of the actual run. We need to find the time for the run
450  // so we will scan forward
451  while(runLumiRange.m_lumi !=0 && ++index<m_runlumiToRange.size()) {
452  const RunLumiToRange& next = m_runlumiToRange[index];
453  if(runLumiRange.m_run == next.m_run) {
454  runLumiRange = next;
455  } else {
456  break;
457  }
458  }
459 
460  //NOTE: the setBeginTime and setEndTime functions of RunAuxiliary only work if the previous value was invalid
461  // therefore we must copy
462  m_runAux = edm::RunAuxiliary(runLumiRange.m_run,edm::Timestamp(runLumiRange.m_beginTime),edm::Timestamp(runLumiRange.m_endTime));
463  assert(m_historyIDs.size() > runLumiRange.m_historyIDIndex);
464  //std::cout <<"readRunAuxiliary_ "<<m_historyIDs[runLumiRange.m_historyIDIndex]<<std::endl;
465  m_runAux.setProcessHistoryID(m_historyIDs[runLumiRange.m_historyIDIndex]);
466  return boost::shared_ptr<edm::RunAuxiliary>( new edm::RunAuxiliary(m_runAux) );
467 }
468 boost::shared_ptr<edm::LuminosityBlockAuxiliary>
470 {
471  //std::cout <<"readLuminosityBlockAuxiliary_"<<std::endl;
472  assert(m_nextIndexItr != m_orderedIndices.end());
473  const RunLumiToRange runLumiRange = m_runlumiToRange[*m_nextIndexItr];
474  m_lumiAux = edm::LuminosityBlockAuxiliary(edm::LuminosityBlockID(runLumiRange.m_run,runLumiRange.m_lumi),
475  edm::Timestamp(runLumiRange.m_beginTime),
476  edm::Timestamp(runLumiRange.m_endTime));
477  assert(m_historyIDs.size() > runLumiRange.m_historyIDIndex);
478  //std::cout <<"lumi "<<m_lumiAux.beginTime().value()<<" "<<runLumiRange.m_beginTime<<std::endl;
479  m_lumiAux.setProcessHistoryID(m_historyIDs[runLumiRange.m_historyIDIndex]);
480 
481  return boost::shared_ptr<edm::LuminosityBlockAuxiliary>(new edm::LuminosityBlockAuxiliary(m_lumiAux));
482 }
483 boost::shared_ptr<edm::RunPrincipal>
484 DQMRootSource::readRun_(boost::shared_ptr<edm::RunPrincipal> rpCache)
485 {
487  unsigned int runID =rpCache->id().run();
488  unsigned int lastRunID = m_lastSeenRun;
489  m_lastSeenRun = runID;
491  //std::cout <<"readRun_"<<std::endl;
492 
493  //NOTE: need to reset all run elements at this point
494  if(lastRunID != runID) {
495  for(std::set<MonitorElement*>::iterator it = m_runElements.begin(), itEnd = m_runElements.end();
496  it != itEnd;
497  ++it) {
498  //std::cout <<"RESETTING "<<(*it)->getName()<<std::endl;
499  (*it)->Reset();
500  }
501  }
502 
503  rpCache->addToProcessHistory();
504 
505  if(m_presentIndexItr != m_orderedIndices.end()) {
506  RunLumiToRange runLumiRange = m_runlumiToRange[*m_presentIndexItr];
507  //NOTE: it is possible to have an Run when all we have stored is lumis
508  if(runLumiRange.m_lumi == 0 &&
509  runLumiRange.m_run == rpCache->id().run()) {
510  readElements();
511  }
512  }
513 
515  jr->reportInputRunNumber(rpCache->id().run());
516  return rpCache;
517 }
518 boost::shared_ptr<edm::LuminosityBlockPrincipal>
519 DQMRootSource::readLuminosityBlock_( boost::shared_ptr<edm::LuminosityBlockPrincipal> lbCache)
520 {
521  //NOTE: need to reset all lumi block elements at this point
522  for(std::set<MonitorElement*>::iterator it = m_lumiElements.begin(), itEnd = m_lumiElements.end();
523  it != itEnd;
524  ++it) {
525  //std::cout <<"RESETTING "<<(*it)->getName()<<std::endl;
526  (*it)->Reset();
527  }
529  //std::cout <<"readLuminosityBlock_"<<std::endl;
530  RunLumiToRange runLumiRange = m_runlumiToRange[*m_presentIndexItr];
531  if(runLumiRange.m_run == lbCache->id().run() &&
532  runLumiRange.m_lumi == lbCache->id().luminosityBlock()) {
533  readElements();
534  }
535 
537  jr->reportInputLumiSection(lbCache->id().run(),lbCache->id().luminosityBlock());
538 
539  return lbCache;
540 }
541 
542 boost::shared_ptr<edm::FileBlock>
544  //std::cout <<"readFile_"<<std::endl;
546  ++m_fileIndex;
548 
552  std::string(),
553  std::string(),
554  "DQMRootSource",
555  "source",
556  m_file->GetUUID().AsString(),//edm::createGlobalIdentifier(),
557  std::vector<std::string>()
558  );
559 
561  return boost::shared_ptr<edm::FileBlock>(new edm::FileBlock);
562 }
563 
564 
565 void
567  //std::cout <<"DQMRootSource::endLumi"<<std::endl;
568 }
569 void
571  //std::cout <<"DQMRootSource::endRun"<<std::endl;
572  //NOTE: the framework will call endRun before closeFile in the case
573  // where the frameworks is terminating
575 }
576 
577 
578 void
580  //std::cout <<"closeFile_"<<std::endl;
581  //when going from one file to the next the framework does not call
582  // 'endRun' or 'endLumi' until it looks to see if the other file contains
583  // a new run or lumi. If the other file doesn't then
585  while(m_presentIndexItr != m_orderedIndices.end()) {
586  readElements();
587  }
588  }
591 }
592 
593 void
596  RunLumiToRange runLumiRange = m_runlumiToRange[*m_presentIndexItr];
597  bool shouldContinue = false;
598  do {
599  shouldContinue = false;
600  if(runLumiRange.m_type == kNoTypesStored) {continue;}
601  boost::shared_ptr<TreeReaderBase> reader = m_treeReaders[runLumiRange.m_type];
602  for(ULong64_t index = runLumiRange.m_firstIndex, endIndex=runLumiRange.m_lastIndex+1;
603  index != endIndex;
604  ++index) {
605  bool isLumi = runLumiRange.m_lumi !=0;
606  MonitorElement* element = reader->read(index,*store,isLumi);
607  if(isLumi) {
608  //std::cout <<" lumi element "<< element->getName()<<" "<<index<<std::endl;
609  m_lumiElements.insert(element);
610  } else {
611  //std::cout <<" run element "<< element->getName()<<" "<<index<<std::endl;
612  m_runElements.insert(element);
613  }
614  }
616  if(m_presentIndexItr != m_orderedIndices.end()) {
617  //are there more parts to this same run/lumi?
618  const RunLumiToRange nextRunLumiRange = m_runlumiToRange[*m_presentIndexItr];
619  //continue to the next item if that item is either
620  if( (nextRunLumiRange.m_run == runLumiRange.m_run) &&
621  (nextRunLumiRange.m_lumi == runLumiRange.m_lumi) ) {
622  shouldContinue= true;
623  runLumiRange = nextRunLumiRange;
624  }
625  }
626  }while(shouldContinue);
627 }
628 
629 
630 void
632 {
633  //Do the work of actually figuring out where next to go
634  RunLumiToRange runLumiRange = m_runlumiToRange[*m_nextIndexItr];
636  assert(m_nextIndexItr != m_orderedIndices.end());
637 
638  if(runLumiRange.m_lumi ==0) {
639  //std::cout <<"reading run "<<runLumiRange.m_run<<std::endl;
640  m_runAux.id() = edm::RunID(runLumiRange.m_run);
641  } else {
643  //std::cout <<" proceeding with dummy run";
645  return;
646  }
647  //std::cout <<"reading lumi "<<runLumiRange.m_run<<","<<runLumiRange.m_lumi<<std::endl;
648  m_lumiAux.id() = edm::LuminosityBlockID(runLumiRange.m_run,runLumiRange.m_lumi);
649  }
650  ++m_nextIndexItr;
651  } else {
652  //NOTE: the following causes the iterator to move to before 'begin' but that is OK
653  // since the first thing in the 'do while' loop is to advance the iterator which puts
654  // us at the first entry in the file
655  runLumiRange.m_run=0;
656  }
657 
658  bool shouldContinue = false;
659  do {
660  shouldContinue = false;
661  if(m_nextIndexItr == m_orderedIndices.end()) {
662  //go to next file
664  //std::cout <<"going to next file"<<std::endl;
665  if(m_fileIndex == m_catalog.fileNames().size()) {
667  }
668  break;
669  }
670  const RunLumiToRange nextRunLumiRange = m_runlumiToRange[*m_nextIndexItr];
671  //continue to the next item if that item is the same run or lumi as we just did
672  if( (nextRunLumiRange.m_run == runLumiRange.m_run) && (
673  nextRunLumiRange.m_lumi == runLumiRange.m_lumi) ) {
674  shouldContinue= true;
675  runLumiRange = nextRunLumiRange;
676  ++m_nextIndexItr;
677  //std::cout <<" advancing " <<nextRunLumiRange.m_run<<" "<<nextRunLumiRange.m_lumi<<std::endl;
678  }
679 
680  } while(shouldContinue);
681 
682  if(m_nextIndexItr != m_orderedIndices.end()) {
685  //std::cout <<" next is run"<<std::endl;
686  } else {
688  //we have to create a dummy Run since we switched to a lumi in a new run
689  //std::cout <<" next is dummy run "<<m_justOpenedFileSoNeedToGenerateRunTransition<<std::endl;
691  } else {
693  }
694  }
695  }
696 }
697 
698 void
699 DQMRootSource::setupFile(unsigned int iIndex)
700 {
701 
702  m_file = std::auto_ptr<TFile>(TFile::Open(m_catalog.fileNames()[iIndex].c_str()));
703 
704  //Check file format version, which is encoded in the Title of the TFile
705  assert(0==strcmp(m_file->GetTitle(),"1"));
706 
707  //Get meta Data
708  TDirectory* metaDir = m_file->GetDirectory(kMetaDataDirectoryAbsolute);
709  assert(0!=metaDir);
710  TTree* parameterSetTree = dynamic_cast<TTree*>(metaDir->Get(kParameterSetTree));
711  assert(0!=parameterSetTree);
712 
714  assert(0!=psr);
715  {
716  std::string blob;
717  std::string* pBlob = &blob;
718  parameterSetTree->SetBranchAddress(kParameterSetBranch,&pBlob);
719  for(unsigned int index = 0; index != parameterSetTree->GetEntries();++index) {
720  parameterSetTree->GetEntry(index);
721  cms::Digest dg(blob);
722  edm::ParameterSetID psID(dg.digest().toString());
723  edm::ParameterSet temp(blob,psID);
724  }
725  }
726 
727  {
728  TTree* processHistoryTree = dynamic_cast<TTree*>(metaDir->Get(kProcessHistoryTree));
729  assert(0!=processHistoryTree);
730  unsigned int phIndex = 0;
731  processHistoryTree->SetBranchAddress(kPHIndexBranch,&phIndex);
732  std::string processName;
733  std::string* pProcessName = &processName;
734  processHistoryTree->SetBranchAddress(kProcessConfigurationProcessNameBranch,&pProcessName);
735  std::string parameterSetIDBlob;
736  std::string* pParameterSetIDBlob = &parameterSetIDBlob;
737  processHistoryTree->SetBranchAddress(kProcessConfigurationParameterSetIDBranch,&pParameterSetIDBlob);
738  std::string releaseVersion;
739  std::string* pReleaseVersion = &releaseVersion;
740  processHistoryTree->SetBranchAddress(kProcessConfigurationReleaseVersion,&pReleaseVersion);
741  std::string passID;
742  std::string* pPassID = &passID;
743  processHistoryTree->SetBranchAddress(kProcessConfigurationPassID,&pPassID);
744 
746  assert(0!=pcr);
748  assert(0!=phr);
749  std::vector<edm::ProcessConfiguration> configs;
750  configs.reserve(5);
751  for(unsigned int i=0; i != processHistoryTree->GetEntries(); ++i) {
752  processHistoryTree->GetEntry();
753  if(phIndex==0) {
754  if(not configs.empty()) {
755  edm::ProcessHistory ph(configs);
756  m_historyIDs.push_back(ph.id());
757  phr->insertMapped(ph);
758  }
759  configs.clear();
760  }
761  edm::ParameterSetID psetID(parameterSetIDBlob);
762  edm::ProcessConfiguration pc(processName, psetID,releaseVersion,passID);
763  pcr->insertMapped(pc);
764  configs.push_back(pc);
765  }
766  if(not configs.empty()) {
767  edm::ProcessHistory ph(configs);
768  m_historyIDs.push_back(ph.id());
769  phr->insertMapped( ph);
770  //std::cout <<"inserted "<<ph.id()<<std::endl;
771  }
772  }
773 
774  //Setup the indices
775  TTree* indicesTree = dynamic_cast<TTree*>(m_file->Get(kIndicesTree));
776  assert(0!=indicesTree);
777 
778  m_runlumiToRange.clear();
779  m_runlumiToRange.reserve(indicesTree->GetEntries());
780  m_orderedIndices.clear();
781 
782  RunLumiToRange temp;
783  indicesTree->SetBranchAddress(kRunBranch,&temp.m_run);
784  indicesTree->SetBranchAddress(kLumiBranch,&temp.m_lumi);
785  indicesTree->SetBranchAddress(kBeginTimeBranch,&temp.m_beginTime);
786  indicesTree->SetBranchAddress(kEndTimeBranch,&temp.m_endTime);
787  indicesTree->SetBranchAddress(kProcessHistoryIndexBranch,&temp.m_historyIDIndex);
788  indicesTree->SetBranchAddress(kTypeBranch,&temp.m_type);
789  indicesTree->SetBranchAddress(kFirstIndex,&temp.m_firstIndex);
790  indicesTree->SetBranchAddress(kLastIndex,&temp.m_lastIndex);
791 
792  //Need to reorder items since if there was a merge done the same Run and/or Lumi can appear multiple times
793  // but we want to process them all at once
794 
795  //We use a std::list for m_orderedIndices since inserting into the middle of a std::list does not
796  // disrupt the iterators to already existing entries
797 
798  //The Map is used to see if a Run/Lumi pair has appeared before
799  typedef std::map<std::pair<unsigned int, unsigned int>, std::list<unsigned int>::iterator > RunLumiToLastEntryMap;
800  RunLumiToLastEntryMap runLumiToLastEntryMap;
801 
802  //Need to group all lumis for the same run together and move the run entry to the beginning
803  typedef std::map<unsigned int, std::pair<std::list<unsigned int>::iterator,std::list<unsigned int>::iterator> > RunToFirstLastEntryMap;
804  RunToFirstLastEntryMap runToFirstLastEntryMap;
805 
806  for(Long64_t index = 0; index != indicesTree->GetEntries();++index) {
807  indicesTree->GetEntry(index);
808  //std::cout <<"read r:"<<temp.m_run<<" l:"<<temp.m_lumi<<" b:"<<temp.m_beginTime<<" e:"<<temp.m_endTime<<std::endl;
809  m_runlumiToRange.push_back(temp);
810 
811  std::pair<unsigned int, unsigned int> runLumi(temp.m_run,temp.m_lumi);
812 
813  RunLumiToLastEntryMap::iterator itFind = runLumiToLastEntryMap.find(runLumi);
814  if(itFind == runLumiToLastEntryMap.end()) {
815  //does not already exist
816 
817  //does the run for this already exist?
818  std::list<unsigned int>::iterator itLastOfRun = m_orderedIndices.end();
819  RunToFirstLastEntryMap::iterator itRunFirstLastEntryFind = runToFirstLastEntryMap.find(temp.m_run);
820  bool needNewEntryInRunFirstLastEntryMap = true;
821  if(itRunFirstLastEntryFind != runToFirstLastEntryMap.end()) {
822  needNewEntryInRunFirstLastEntryMap=false;
823  if(temp.m_lumi!=0) {
824  //lumis go to the end
825  itLastOfRun = itRunFirstLastEntryFind->second.second;
826  //we want to insert after this one so must advanced the iterator
827  ++itLastOfRun;
828  } else {
829  //runs go at the beginning
830  itLastOfRun = itRunFirstLastEntryFind->second.first;
831  }
832  }
833 
834  std::list<unsigned int>::iterator iter = m_orderedIndices.insert(itLastOfRun,index);
835  runLumiToLastEntryMap[runLumi]=iter;
836  if(needNewEntryInRunFirstLastEntryMap) {
837  runToFirstLastEntryMap[temp.m_run]=std::make_pair(iter,iter);
838  } else {
839  if(temp.m_lumi!=0) {
840  //lumis go at end
841  runToFirstLastEntryMap[temp.m_run].second = iter;
842  } else {
843  //since we haven't yet seen this run/lumi combination it means we haven't yet seen
844  // a run so we can put this first
845  runToFirstLastEntryMap[temp.m_run].first = iter;
846  }
847  }
848  } else {
849  //We need to do a merge since the run/lumi already appeared. Put it after the existing entry
850  //std::cout <<" found a second instance of "<<runLumi.first<<" "<<runLumi.second<<" at "<<index<<std::endl;
851  std::list<unsigned int>::iterator itNext = itFind->second;
852  ++itNext;
853  std::list<unsigned int>::iterator iter = m_orderedIndices.insert(itNext,index);
854  RunToFirstLastEntryMap::iterator itRunFirstLastEntryFind = runToFirstLastEntryMap.find(temp.m_run);
855  if(itRunFirstLastEntryFind->second.second == itFind->second) {
856  //if the previous one was the last in the run, we need to update to make this one the last
857  itRunFirstLastEntryFind->second.second = iter;
858  }
859  itFind->second = iter;
860  }
861  }
864 
865  if(m_nextIndexItr != m_orderedIndices.end()) {
866  for( size_t index = 0; index < kNIndicies; ++index) {
867  m_trees[index] = dynamic_cast<TTree*>(m_file->Get(kTypeNames[index]));
868  assert(0!=m_trees[index]);
869  m_treeReaders[index]->setTree(m_trees[index]);
870  }
871  }
872  //After a file open, the framework expects to see a new 'IsRun'
873  //m_lastSeenRun = 0;
875 }
876 
877 //
878 // const member functions
879 //
880 
881 //
882 // static member functions
883 //
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:664
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
MonitorElement * book1D(const char *name, const char *title, int nchX, double lowX, double highX)
Book 1D histogram.
Definition: DQMStore.cc:514
edm::RunAuxiliary m_runAux
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:776
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:686
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:470
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
std::list< unsigned int >::iterator m_presentIndexItr
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:546
MD5Result digest() const
Definition: Digest.cc:188
bool insertMapped(value_type const &v)
MonitorElement * bookFloat(const char *name)
Book float.
Definition: DQMStore.cc:451
void Fill(long long x)
int path() const
Definition: HLTadd.h:3
void tag(MonitorElement *me, unsigned int myTag)
Definition: DQMStore.cc:1151
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()
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:517
MonitorElement * bookString(const char *name, const char *value)
Book string.
Definition: DQMStore.cc:480
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:828
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:1265
const std::string getFullname(void) const
get full name of ME including Pathname
void reportInputRunNumber(unsigned int run)
Definition: JobReport.cc:634
std::vector< TTree * > m_trees
std::size_t Token
Definition: JobReport.h:44
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
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:625
void setupFile(unsigned int iIndex)
std::list< unsigned int >::iterator m_nextIndexItr
void setProcessHistoryID(ProcessHistoryID const &phid)
Definition: RunAuxiliary.h:36
static ThreadSafeRegistry * instance()
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:421
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:642
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:530
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:232
LuminosityBlockID const & id() const
Helper class to handle FWLite file input sources.
Definition: Run.h:32
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:972