CMS 3D CMS Logo

EntryFinder.cc
Go to the documentation of this file.
1 
2 /*
3 // -*- C++ -*-
4 //
5 // Package: FWLite/DataFormats
6 // Class : Index
7 //
8 
9  Description: <one line class summary>
10 
11  Usage:
12  <usage>
13 
14 */
15 //
16 // Original Author: Bill Tanenbaum
17 //
18 
19 // user include files
24 
25 #include "TBranch.h"
26 #include "TFile.h"
27 #include "TTree.h"
28 
29 // forward declarations
30 
31 namespace fwlite {
32 
33  // This is a helper class for IndexIntoFile.
35  public:
36  explicit FWLiteEventFinder(TBranch* auxBranch) : auxBranch_(auxBranch) {}
37  ~FWLiteEventFinder() override {}
38 
40  void* saveAddress = auxBranch_->GetAddress();
41  edm::EventAuxiliary eventAux;
42  edm::EventAuxiliary *pEvAux = &eventAux;
43  auxBranch_->SetAddress(&pEvAux);
44  auxBranch_->GetEntry(entry);
45  auxBranch_->SetAddress(saveAddress);
46  return eventAux.event();
47  }
48 
49  private:
50  TBranch* auxBranch_;
51  };
52 
53  EntryFinder::EntryFinder() : indexIntoFile_(), fileIndex_() {}
55 
59  if (!indexIntoFile_.empty()) {
62  ret = i.entry();
63  }
64  } else {
66  if (fileIndex_.end() != i) {
67  ret = i->entry_;
68  }
69  }
70  return ret;
71  }
72 
76  if (!indexIntoFile_.empty()) {
79  ret = i.entry();
80  }
81  } else {
83  if (fileIndex_.end() != i) {
84  ret = i->entry_;
85  }
86  }
87  return ret;
88  }
89 
93  if (!indexIntoFile_.empty()) {
96  ret = i.entry();
97  }
98  } else {
100  if (fileIndex_.end() != i) {
101  ret = i->entry_;
102  }
103  }
104  return ret;
105  }
106 
107  void
109  if (empty()) {
110  TTree* meta = dynamic_cast<TTree*>(branchMap.getFile()->Get(edm::poolNames::metaDataTreeName().c_str()));
111  if (nullptr == meta) {
112  throw cms::Exception("NoMetaTree") << "The TFile does not contain a TTree named "
114  }
115  if (meta->FindBranch(edm::poolNames::indexIntoFileBranchName().c_str()) != nullptr) {
116  edm::IndexIntoFile* indexPtr = &indexIntoFile_;
117  TBranch* b = meta->GetBranch(edm::poolNames::indexIntoFileBranchName().c_str());
118  b->SetAddress(&indexPtr);
119  b->GetEntry(0);
120  TTree* eventTree = branchMap.getEventTree();
121  TBranch* auxBranch = eventTree->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InEvent).c_str());
122  if(nullptr == auxBranch) {
123  throw cms::Exception("NoEventAuxilliary") << "The TTree "
125  << " does not contain a branch named 'EventAuxiliary'";
126  }
127 
128  indexIntoFile_.setNumberOfEvents(auxBranch->GetEntries());
129  indexIntoFile_.setEventFinder(std::shared_ptr<edm::IndexIntoFile::EventFinder>(std::make_shared<FWLiteEventFinder>(auxBranch)));
130 
131  } else if (meta->FindBranch(edm::poolNames::fileIndexBranchName().c_str()) != nullptr) {
132  edm::FileIndex* findexPtr = &fileIndex_;
133  TBranch* b = meta->GetBranch(edm::poolNames::fileIndexBranchName().c_str());
134  b->SetAddress(&findexPtr);
135  b->GetEntry(0);
136  } else {
137  // TBD: fill the FileIndex for old file formats (prior to CMSSW 2_0_0)
138  throw cms::Exception("NoIndexBranch") << "The TFile does not contain a TBranch named " <<
140  }
141  }
142  assert(!empty());
143  }
144 }
void setEventFinder(std::shared_ptr< EventFinder > ptr) const
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:115
FWLiteEventFinder(TBranch *auxBranch)
Definition: EntryFinder.cc:36
bool empty() const
True if no runs, lumis, or events are in the file.
TFile const * getFile() const
unsigned long long EventNumber_t
edm::IndexIntoFile indexIntoFile_
Definition: EntryFinder.h:41
unsigned int LuminosityBlockNumber_t
IndexIntoFileItr findRunPosition(RunNumber_t run) const
Same as findPosition.
long long EntryNumber_t
EntryNumber_t findEvent(edm::RunNumber_t const &run, edm::LuminosityBlockNumber_t const &lumi, edm::EventNumber_t const &event) const
Definition: EntryFinder.cc:57
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:53
const_iterator findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: FileIndex.cc:91
std::string const & fileIndexBranchName()
Definition: BranchType.cc:228
edm::IndexIntoFile::EntryNumber_t EntryNumber_t
Definition: EntryFinder.h:33
const_iterator findRunPosition(RunNumber_t run) const
Definition: FileIndex.cc:136
std::string const & indexIntoFileBranchName()
Definition: BranchType.cc:233
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
const_iterator end() const
Definition: FileIndex.h:100
std::string const & metaDataTreeName()
Definition: BranchType.cc:168
TTree const * getEventTree() const
EntryNumber_t findRun(edm::RunNumber_t const &run) const
Definition: EntryFinder.cc:91
void fillIndex(BranchMapReader &branchMap)
Definition: EntryFinder.cc:108
static EntryNumber_t const invalidEntry
Definition: EntryFinder.h:39
const_iterator findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: FileIndex.cc:120
IndexIntoFileItr findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
bool empty() const
Definition: EntryFinder.h:34
double b
Definition: hdecay.h:120
edm::FileIndex fileIndex_
Definition: EntryFinder.h:42
void setNumberOfEvents(EntryNumber_t nevents) const
std::string const & eventTreeName()
Definition: BranchType.cc:260
unsigned int RunNumber_t
IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
EventNumber_t event() const
edm::EventNumber_t getEventNumberOfEntry(edm::IndexIntoFile::EntryNumber_t entry) const override
Definition: EntryFinder.cc:39
Definition: event.py:1
EntryNumber_t findLumi(edm::RunNumber_t const &run, edm::LuminosityBlockNumber_t const &lumi) const
Definition: EntryFinder.cc:74