CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
58  edm::EventNumber_t const& event) const {
60  if (!indexIntoFile_.empty()) {
63  ret = i.entry();
64  }
65  } else {
67  if (fileIndex_.end() != i) {
68  ret = i->entry_;
69  }
70  }
71  return ret;
72  }
73 
75  edm::LuminosityBlockNumber_t const& lumi) const {
77  if (!indexIntoFile_.empty()) {
80  ret = i.entry();
81  }
82  } else {
84  if (fileIndex_.end() != i) {
85  ret = i->entry_;
86  }
87  }
88  return ret;
89  }
90 
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 
108  if (empty()) {
109  TTree* meta = dynamic_cast<TTree*>(branchMap.getFile()->Get(edm::poolNames::metaDataTreeName().c_str()));
110  if (nullptr == meta) {
111  throw cms::Exception("NoMetaTree")
112  << "The TFile does not contain a TTree named " << edm::poolNames::metaDataTreeName();
113  }
114  if (meta->FindBranch(edm::poolNames::indexIntoFileBranchName().c_str()) != nullptr) {
115  edm::IndexIntoFile* indexPtr = &indexIntoFile_;
116  TBranch* b = meta->GetBranch(edm::poolNames::indexIntoFileBranchName().c_str());
117  b->SetAddress(&indexPtr);
118  b->GetEntry(0);
119  TTree* eventTree = branchMap.getEventTree();
120  TBranch* auxBranch = eventTree->GetBranch(edm::BranchTypeToAuxiliaryBranchName(edm::InEvent).c_str());
121  if (nullptr == auxBranch) {
122  throw cms::Exception("NoEventAuxilliary")
123  << "The TTree " << edm::poolNames::eventTreeName() << " does not contain a branch named 'EventAuxiliary'";
124  }
125 
126  indexIntoFile_.setNumberOfEvents(auxBranch->GetEntries());
128  std::shared_ptr<edm::IndexIntoFile::EventFinder>(std::make_shared<FWLiteEventFinder>(auxBranch)));
129 
130  } else if (meta->FindBranch(edm::poolNames::fileIndexBranchName().c_str()) != nullptr) {
131  edm::FileIndex* findexPtr = &fileIndex_;
132  TBranch* b = meta->GetBranch(edm::poolNames::fileIndexBranchName().c_str());
133  b->SetAddress(&findexPtr);
134  b->GetEntry(0);
135  } else {
136  // TBD: fill the FileIndex for old file formats (prior to CMSSW 2_0_0)
137  throw cms::Exception("NoIndexBranch")
138  << "The TFile does not contain a TBranch named " << edm::poolNames::indexIntoFileBranchName().c_str()
139  << " or " << edm::poolNames::fileIndexBranchName().c_str();
140  }
141  }
142  assert(!empty());
143  }
144 } // namespace fwlite
tuple ret
prodAgent to be discontinued
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:116
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:44
assert(be >=bs)
unsigned int LuminosityBlockNumber_t
IndexIntoFileItr findRunPosition(RunNumber_t run) const
Same as findPosition.
EntryNumber_t findEvent(edm::RunNumber_t const &run, edm::LuminosityBlockNumber_t const &lumi, edm::EventNumber_t const &event) const
Definition: EntryFinder.cc:56
void setNumberOfEvents(EntryNumber_t nevents)
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:49
long long EntryNumber_t
const_iterator findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: FileIndex.cc:91
std::string const & fileIndexBranchName()
Definition: BranchType.cc:195
edm::IndexIntoFile::EntryNumber_t EntryNumber_t
Definition: EntryFinder.h:33
const_iterator findRunPosition(RunNumber_t run) const
Definition: FileIndex.cc:135
std::string const & indexIntoFileBranchName()
Definition: BranchType.cc:198
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
edm::EventNumber_t getEventNumberOfEntry(edm::IndexIntoFile::EntryNumber_t entry) const override
Definition: EntryFinder.cc:39
const_iterator end() const
Definition: FileIndex.h:87
std::string const & metaDataTreeName()
Definition: BranchType.cc:159
TTree const * getEventTree() const
list lumi
Definition: dqmdumpme.py:53
EntryNumber_t findRun(edm::RunNumber_t const &run) const
Definition: EntryFinder.cc:91
void fillIndex(BranchMapReader &branchMap)
Definition: EntryFinder.cc:107
static EntryNumber_t const invalidEntry
Definition: EntryFinder.h:41
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:118
edm::FileIndex fileIndex_
Definition: EntryFinder.h:45
std::string const & eventTreeName()
Definition: BranchType.cc:220
list entry
Definition: mps_splice.py:68
unsigned int RunNumber_t
IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
void setEventFinder(std::shared_ptr< EventFinder > ptr)
EventNumber_t event() const
EntryNumber_t findLumi(edm::RunNumber_t const &run, edm::LuminosityBlockNumber_t const &lumi) const
Definition: EntryFinder.cc:74