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 
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
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:355
edm::FileIndex
Definition: FileIndex.h:21
edm::RunNumber_t
unsigned int RunNumber_t
Definition: RunLumiEventNumber.h:14
edm::EventAuxiliary::event
EventNumber_t event() const
Definition: EventAuxiliary.h:72
edm::FileIndex::findLumiPosition
const_iterator findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: FileIndex.cc:120
mps_fire.i
i
Definition: mps_fire.py:355
edm::poolNames::eventTreeName
std::string const & eventTreeName()
Definition: BranchType.cc:218
fwlite::EntryFinder::invalidEntry
static const EntryNumber_t invalidEntry
Definition: EntryFinder.h:41
edm::IndexIntoFile::findRunPosition
IndexIntoFileItr findRunPosition(RunNumber_t run) const
Same as findPosition.
Definition: IndexIntoFile.cc:692
fwlite
Definition: TFileDirectory.h:16
fwlite::FWLiteEventFinder::getEventNumberOfEntry
edm::EventNumber_t getEventNumberOfEntry(edm::IndexIntoFile::EntryNumber_t entry) const override
Definition: EntryFinder.cc:39
edm::FileIndex::findEventPosition
const_iterator findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: FileIndex.cc:91
edm::IndexIntoFile::setNumberOfEvents
void setNumberOfEvents(EntryNumber_t nevents)
Definition: IndexIntoFile.h:945
edm::IndexIntoFile::numericalOrder
Definition: IndexIntoFile.h:266
mps_splice.entry
entry
Definition: mps_splice.py:68
EntryFinder.h
edm::IndexIntoFile
Definition: IndexIntoFile.h:225
cms::cuda::assert
assert(be >=bs)
fwlite::EntryFinder::findRun
EntryNumber_t findRun(edm::RunNumber_t const &run) const
Definition: EntryFinder.cc:91
edm::poolNames::indexIntoFileBranchName
std::string const & indexIntoFileBranchName()
Definition: BranchType.cc:201
fwlite::EntryFinder::EntryNumber_t
edm::IndexIntoFile::EntryNumber_t EntryNumber_t
Definition: EntryFinder.h:33
fwlite::BranchMapReader::getEventTree
TTree const * getEventTree() const
Definition: BranchMapReader.h:94
edm::LuminosityBlockNumber_t
unsigned int LuminosityBlockNumber_t
Definition: RunLumiEventNumber.h:13
edm::IndexIntoFile::empty
bool empty() const
True if no runs, lumis, or events are in the file.
Definition: IndexIntoFile.cc:487
edm::BranchTypeToAuxiliaryBranchName
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const &branchType)
Definition: BranchType.cc:115
fwlite::EntryFinder::fillIndex
void fillIndex(BranchMapReader &branchMap)
Definition: EntryFinder.cc:107
BranchMapReader.h
fwlite::EntryFinder::findEvent
EntryNumber_t findEvent(edm::RunNumber_t const &run, edm::LuminosityBlockNumber_t const &lumi, edm::EventNumber_t const &event) const
Definition: EntryFinder.cc:56
fwlite::EntryFinder::~EntryFinder
~EntryFinder()
Definition: EntryFinder.cc:54
edm::IndexIntoFile::setEventFinder
void setEventFinder(std::shared_ptr< EventFinder > ptr)
Definition: IndexIntoFile.h:952
edm::EventNumber_t
unsigned long long EventNumber_t
Definition: RunLumiEventNumber.h:12
fwlite::FWLiteEventFinder::FWLiteEventFinder
FWLiteEventFinder(TBranch *auxBranch)
Definition: EntryFinder.cc:36
edm::InEvent
Definition: BranchType.h:11
b
double b
Definition: hdecay.h:118
edm::FileIndex::end
const_iterator end() const
Definition: FileIndex.h:87
edm::EventAuxiliary
Definition: EventAuxiliary.h:14
edm::FileIndex::const_iterator
std::vector< Element >::const_iterator const_iterator
Definition: FileIndex.h:49
edm::IndexIntoFile::IndexIntoFileItr
Definition: IndexIntoFile.h:681
fwlite::EntryFinder::empty
bool empty() const
Definition: EntryFinder.h:34
edm::IndexIntoFile::findLumiPosition
IndexIntoFileItr findLumiPosition(RunNumber_t run, LuminosityBlockNumber_t lumi) const
Definition: IndexIntoFile.cc:685
fwlite::FWLiteEventFinder::~FWLiteEventFinder
~FWLiteEventFinder() override
Definition: EntryFinder.cc:37
fwlite::FWLiteEventFinder::auxBranch_
TBranch * auxBranch_
Definition: EntryFinder.cc:50
edm::IndexIntoFile::end
IndexIntoFileItr end(SortOrder sortOrder) const
Used to end an iteration over the Runs, Lumis, and Events in a file.
Definition: IndexIntoFile.cc:470
edm::IndexIntoFile::findEventPosition
IndexIntoFileItr findEventPosition(RunNumber_t run, LuminosityBlockNumber_t lumi, EventNumber_t event) const
Definition: IndexIntoFile.cc:676
fwlite::FWLiteEventFinder
Definition: EntryFinder.cc:34
fwlite::BranchMapReader::getFile
TFile const * getFile() const
Definition: BranchMapReader.h:92
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::FileIndex::findRunPosition
const_iterator findRunPosition(RunNumber_t run) const
Definition: FileIndex.cc:135
edm::poolNames::metaDataTreeName
std::string const & metaDataTreeName()
Definition: BranchType.cc:162
fwlite::EntryFinder::indexIntoFile_
edm::IndexIntoFile indexIntoFile_
Definition: EntryFinder.h:44
EventAuxiliary.h
Exception
Definition: hltDiff.cc:246
fwlite::BranchMapReader
Definition: BranchMapReader.h:70
fwlite::EntryFinder::EntryFinder
EntryFinder()
Definition: EntryFinder.cc:53
fwlite::EntryFinder::fileIndex_
edm::FileIndex fileIndex_
Definition: EntryFinder.h:45
Exception.h
fwlite::EntryFinder::findLumi
EntryNumber_t findLumi(edm::RunNumber_t const &run, edm::LuminosityBlockNumber_t const &lumi) const
Definition: EntryFinder.cc:74
edm::IndexIntoFile::EntryNumber_t
long long EntryNumber_t
Definition: IndexIntoFile.h:231
edm::poolNames::fileIndexBranchName
std::string const & fileIndexBranchName()
Definition: BranchType.cc:198
event
Definition: event.py:1
lumi
Definition: LumiSectionData.h:20
edm::IndexIntoFile::EventFinder
Definition: IndexIntoFile.h:902