Public Member Functions | Private Member Functions | Private Attributes | List of all members
gallery::EventNavigator Class Reference

#include <EventNavigator.h>

Public Member Functions

 EventNavigator (std::vector< std::string > const &iFileNames)
 
bool isValid () const
 
bool atEnd () const
 
void toBegin ()
 
void next ()
 
void previous ()
 
void goToEntry (long long entry)
 
void nextFile ()
 
art::EventAuxiliary const & eventAuxiliary () const
 
art::History const & history () const
 
art::ProcessHistoryID const & processHistoryID () const
 
art::ProcessHistory const & processHistory () const
 
TFile * getTFile () const
 
TTree * getTTree () const
 
TBranch * eventAuxiliaryBranch () const
 
long long fileEntry () const
 
long long entriesInCurrentFile () const
 
long long eventEntry () const
 

Private Member Functions

void initializeTTreePointers ()
 
void initializeTBranchPointers ()
 

Private Attributes

std::vector< std::stringfileNames_
 
long long numberOfFiles_
 
long long fileEntry_ {-1}
 
long long firstFileWithEvent_ {}
 
long long entriesInCurrentFile_ {}
 
long long eventEntry_ {}
 
std::unique_ptr< TFile > file_ {nullptr}
 
TTree * eventsTree_ {nullptr}
 
TBranch * eventAuxiliaryBranch_ {nullptr}
 
art::EventAuxiliary eventAuxiliary_ {}
 
art::EventAuxiliarypEventAuxiliary_ {&eventAuxiliary_}
 
long long previousEventAuxiliaryEntry_ {-1}
 
TTree * eventHistoryTree_ {nullptr}
 
TBranch * eventHistoryBranch_ {nullptr}
 
art::History eventHistory_ {}
 
art::HistorypEventHistory_ {&eventHistory_}
 
long long previousEventHistoryEntry_ {-1}
 
art::ProcessHistoryMap historyMap_ {}
 

Detailed Description

Definition at line 26 of file EventNavigator.h.

Constructor & Destructor Documentation

gallery::EventNavigator::EventNavigator ( std::vector< std::string > const &  iFileNames)
explicit

Definition at line 15 of file EventNavigator.cc.

16  : fileNames_{iFileNames}, numberOfFiles_(fileNames_.size())
17  {
18  if (fileNames_.empty()) {
19  fileEntry_ = 0;
20  } else {
23  nextFile();
24  }
26  }
27  if (isValid()) {
28  eventsTree_->LoadTree(eventEntry_);
29  }
30  }
std::vector< std::string > fileNames_

Member Function Documentation

bool gallery::EventNavigator::atEnd ( ) const
inline

Definition at line 43 of file EventNavigator.h.

44  {
45  return fileEntry_ == numberOfFiles_;
46  }
long long gallery::EventNavigator::entriesInCurrentFile ( ) const
inline

Definition at line 73 of file EventNavigator.h.

74  {
75  return entriesInCurrentFile_;
76  }
art::EventAuxiliary const & gallery::EventNavigator::eventAuxiliary ( ) const

Definition at line 136 of file EventNavigator.cc.

137  {
141  }
142  return eventAuxiliary_;
143  }
art::EventAuxiliary eventAuxiliary_
long long previousEventAuxiliaryEntry_
TBranch* gallery::EventNavigator::eventAuxiliaryBranch ( ) const
inline

Definition at line 62 of file EventNavigator.h.

63  {
64  return eventAuxiliaryBranch_;
65  }
long long gallery::EventNavigator::eventEntry ( ) const
inline

Definition at line 78 of file EventNavigator.h.

79  {
80  return eventEntry_;
81  }
long long gallery::EventNavigator::fileEntry ( ) const
inline

Definition at line 68 of file EventNavigator.h.

69  {
70  return fileEntry_;
71  }
TFile * gallery::EventNavigator::getTFile ( ) const

Definition at line 193 of file EventNavigator.cc.

194  {
195  return file_.get();
196  }
std::unique_ptr< TFile > file_
TTree * gallery::EventNavigator::getTTree ( ) const

Definition at line 199 of file EventNavigator.cc.

200  {
201  return eventsTree_;
202  }
void gallery::EventNavigator::goToEntry ( long long  entry)

Definition at line 81 of file EventNavigator.cc.

82  {
84  if (isValid()) {
85  eventsTree_->LoadTree(eventEntry_);
86  }
87  }
QList< Entry > entry
art::History const & gallery::EventNavigator::history ( ) const

Definition at line 146 of file EventNavigator.cc.

147  {
149  eventHistoryBranch_->GetEntry(eventEntry_);
151  }
152  return eventHistory_;
153  }
long long previousEventHistoryEntry_
void gallery::EventNavigator::initializeTBranchPointers ( )
private

Definition at line 224 of file EventNavigator.cc.

225  {
226  eventAuxiliaryBranch_ = eventsTree_->GetBranch(
228 
229  if (eventAuxiliaryBranch_ == nullptr) {
231  }
233 
236 
237  if (eventHistoryBranch_ == nullptr) {
239  }
240  eventHistoryBranch_->SetAddress(&pEventHistory_);
241  }
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const bt)
Definition: BranchType.cc:83
art::History * pEventHistory_
void throwBranchNotFound(std::string const &branchName)
art::EventAuxiliary * pEventAuxiliary_
std::string const & eventHistoryBranchName()
Definition: rootNames.cc:63
void gallery::EventNavigator::initializeTTreePointers ( )
private

Definition at line 205 of file EventNavigator.cc.

206  {
207  eventsTree_ = file_->Get<TTree>(art::rootNames::eventTreeName().c_str());
208  if (eventsTree_ == nullptr) {
210  }
211  if (eventsTree_->GetEntries() < 0) {
213  << "Unable to get the number of entries in events TTree.\n"
214  "This might be a corrupted file.\n";
215  }
217  file_->Get<TTree>(art::rootNames::eventHistoryTreeName().c_str());
218  if (eventHistoryTree_ == nullptr) {
220  }
221  }
std::unique_ptr< TFile > file_
std::string const & eventHistoryTreeName()
Definition: rootNames.cc:56
void throwTreeNotFound(std::string const &treeName)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::string const & eventTreeName()
Definition: rootNames.cc:69
bool gallery::EventNavigator::isValid ( ) const
inline

Definition at line 36 of file EventNavigator.h.

37  {
38  return fileEntry_ != numberOfFiles_ &&
40  }
void gallery::EventNavigator::next ( )

Definition at line 47 of file EventNavigator.cc.

48  {
50  // normal case, go to next event in same file
51  ++eventEntry_;
52  } else {
53  // handle odd cases, calling next when already at the end
54  // or after a call to nextFile() left us on a file with
55  // no events. (Neither of these cases should occur in a
56  // normal loop over events)
57  nextFile();
58  }
59  // if we hit the end of the file go to the next file
60  // also skip empty files
63  nextFile();
64  }
65  if (isValid()) {
66  eventsTree_->LoadTree(eventEntry_);
67  }
68  }
void gallery::EventNavigator::nextFile ( )

Definition at line 90 of file EventNavigator.cc.

91  {
92  // Be careful with this function. If the next file is empty this
93  // will leave it not pointing at a valid event.
94  if (atEnd()) {
96  << "Illegal call to EventNavigator::nextFile() when atEnd() is true";
97  }
98 
99  if (file_) {
100  std::cout << "Closing file, read " << file_->GetBytesRead()
101  << " bytes in " << file_->GetReadCalls() << " transactions\n";
102  }
103 
104  ++fileEntry_;
105  if (atEnd()) {
107  eventEntry_ = 0;
108  file_ = nullptr;
109  eventsTree_ = nullptr;
110  eventAuxiliaryBranch_ = nullptr;
111  eventHistoryTree_ = nullptr;
112  eventHistoryBranch_ = nullptr;
115  historyMap_.clear();
116  return;
117  }
118  file_.reset(TFile::Open(fileNames_[fileEntry_].c_str()));
119  if (!file_ || file_->IsZombie()) {
121  << "Failed opening file \'" << fileNames_[fileEntry_] << "\'";
122  }
123  std::cout << "Successfully opened file " << fileNames_[fileEntry_]
124  << std::endl;
127  entriesInCurrentFile_ = eventsTree_->GetEntries();
128  eventEntry_ = 0;
131  historyMap_.clear();
132  return;
133  }
art::ProcessHistoryMap historyMap_
std::unique_ptr< TFile > file_
std::vector< std::string > fileNames_
long long previousEventHistoryEntry_
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
long long previousEventAuxiliaryEntry_
QTextStream & endl(QTextStream &s)
void gallery::EventNavigator::previous ( )

Definition at line 71 of file EventNavigator.cc.

72  {
73  // We will never get here is we're dealing with more than one file.
74  --eventEntry_;
75  if (isValid()) {
76  eventsTree_->LoadTree(eventEntry_);
77  }
78  }
art::ProcessHistory const & gallery::EventNavigator::processHistory ( ) const

Definition at line 166 of file EventNavigator.cc.

167  {
168 
169  if (historyMap_.empty()) {
170 
171  std::unique_ptr<TTree> metaDataTree{
172  file_->Get<TTree>(art::rootNames::metaDataTreeName().c_str())};
173 
174  if (!metaDataTree) {
176  }
177 
178  auto pHistMapPtr = &historyMap_;
179  TBranch* processHistoryBranch = metaDataTree->GetBranch(
180  art::rootNames::metaBranchRootName<art::ProcessHistoryMap>());
181 
182  if (!processHistoryBranch) {
184  art::rootNames::metaBranchRootName<art::ProcessHistoryMap>());
185  }
186  processHistoryBranch->SetAddress(&pHistMapPtr);
187  processHistoryBranch->GetEntry(0);
188  }
189  return historyMap_[processHistoryID()];
190  }
art::ProcessHistoryMap historyMap_
std::unique_ptr< TFile > file_
art::ProcessHistoryID const & processHistoryID() const
void throwTreeNotFound(std::string const &treeName)
std::string const & metaDataTreeName()
Definition: rootNames.cc:42
void throwBranchNotFound(std::string const &branchName)
art::ProcessHistoryID const & gallery::EventNavigator::processHistoryID ( ) const

Definition at line 156 of file EventNavigator.cc.

157  {
159  eventHistoryBranch_->GetEntry(eventEntry_);
161  }
163  }
long long previousEventHistoryEntry_
ProcessHistoryID const & processHistoryID() const noexcept
Definition: History.cc:31
void gallery::EventNavigator::toBegin ( )

Definition at line 33 of file EventNavigator.cc.

34  {
36  eventEntry_ = 0;
37  return;
38  }
40  nextFile();
41  if (isValid()) {
42  eventsTree_->LoadTree(eventEntry_);
43  }
44  }

Member Data Documentation

long long gallery::EventNavigator::entriesInCurrentFile_ {}
private

Definition at line 92 of file EventNavigator.h.

art::EventAuxiliary gallery::EventNavigator::eventAuxiliary_ {}
mutableprivate

Definition at line 99 of file EventNavigator.h.

TBranch* gallery::EventNavigator::eventAuxiliaryBranch_ {nullptr}
private

Definition at line 98 of file EventNavigator.h.

long long gallery::EventNavigator::eventEntry_ {}
private

Definition at line 93 of file EventNavigator.h.

art::History gallery::EventNavigator::eventHistory_ {}
mutableprivate

Definition at line 105 of file EventNavigator.h.

TBranch* gallery::EventNavigator::eventHistoryBranch_ {nullptr}
private

Definition at line 104 of file EventNavigator.h.

TTree* gallery::EventNavigator::eventHistoryTree_ {nullptr}
private

Definition at line 103 of file EventNavigator.h.

TTree* gallery::EventNavigator::eventsTree_ {nullptr}
private

Definition at line 97 of file EventNavigator.h.

std::unique_ptr<TFile> gallery::EventNavigator::file_ {nullptr}
private

Definition at line 95 of file EventNavigator.h.

long long gallery::EventNavigator::fileEntry_ {-1}
private

Definition at line 89 of file EventNavigator.h.

std::vector<std::string> gallery::EventNavigator::fileNames_
private

Definition at line 87 of file EventNavigator.h.

long long gallery::EventNavigator::firstFileWithEvent_ {}
private

Definition at line 90 of file EventNavigator.h.

art::ProcessHistoryMap gallery::EventNavigator::historyMap_ {}
mutableprivate

Definition at line 109 of file EventNavigator.h.

long long gallery::EventNavigator::numberOfFiles_
private

Definition at line 88 of file EventNavigator.h.

art::EventAuxiliary* gallery::EventNavigator::pEventAuxiliary_ {&eventAuxiliary_}
private

Definition at line 100 of file EventNavigator.h.

art::History* gallery::EventNavigator::pEventHistory_ {&eventHistory_}
private

Definition at line 106 of file EventNavigator.h.

long long gallery::EventNavigator::previousEventAuxiliaryEntry_ {-1}
mutableprivate

Definition at line 101 of file EventNavigator.h.

long long gallery::EventNavigator::previousEventHistoryEntry_ {-1}
mutableprivate

Definition at line 107 of file EventNavigator.h.


The documentation for this class was generated from the following files: