EventNavigator.h
Go to the documentation of this file.
1 #ifndef gallery_EventNavigator_h
2 #define gallery_EventNavigator_h
3 
4 // Manages iteration over the events in a vector of
5 // input files. It handles the iteration, opening
6 // the files, opening TTrees, reading EventAuxilliary
7 // objects and reading History objects from the input
8 // files.
9 
14 
15 #include "TFile.h"
16 
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 class TBranch;
22 class TTree;
23 
24 namespace gallery {
25 
27  public:
28  explicit EventNavigator(std::vector<std::string> const& iFileNames);
29 
30  // In a normal iteration using the next function, isValid and
31  // atEnd will always return opposite values. If nextFile was
32  // called directly and there was an empty file, they might
33  // return different values.
34 
35  bool
36  isValid() const
37  {
38  return fileEntry_ != numberOfFiles_ &&
40  }
41 
42  bool
43  atEnd() const
44  {
45  return fileEntry_ == numberOfFiles_;
46  }
47 
48  void toBegin();
49  void next();
50  void previous();
51  void goToEntry(long long entry);
52  void nextFile();
53 
54  art::EventAuxiliary const& eventAuxiliary() const;
55  art::History const& history() const;
57  art::ProcessHistory const& processHistory() const;
58 
59  TFile* getTFile() const;
60  TTree* getTTree() const;
61  TBranch*
63  {
64  return eventAuxiliaryBranch_;
65  }
66 
67  long long
68  fileEntry() const
69  {
70  return fileEntry_;
71  }
72  long long
74  {
75  return entriesInCurrentFile_;
76  }
77  long long
78  eventEntry() const
79  {
80  return eventEntry_;
81  }
82 
83  private:
86 
87  std::vector<std::string> fileNames_;
88  long long numberOfFiles_;
89  long long fileEntry_{-1};
90  long long firstFileWithEvent_{};
91 
92  long long entriesInCurrentFile_{};
93  long long eventEntry_{};
94 
95  std::unique_ptr<TFile> file_{nullptr};
96 
97  TTree* eventsTree_{nullptr};
98  TBranch* eventAuxiliaryBranch_{nullptr};
101  mutable long long previousEventAuxiliaryEntry_{-1};
102 
103  TTree* eventHistoryTree_{nullptr};
104  TBranch* eventHistoryBranch_{nullptr};
107  mutable long long previousEventHistoryEntry_{-1};
108 
110  };
111 } // namespace gallery
112 
113 #endif /* gallery_EventNavigator_h */
114 
115 // Local Variables:
116 // mode: c++
117 // End:
long long fileEntry() const
art::ProcessHistoryMap historyMap_
std::unique_ptr< TFile > file_
std::vector< std::string > fileNames_
QList< Entry > entry
TFile * getTFile() const
TTree * getTTree() const
art::ProcessHistory const & processHistory() const
void goToEntry(long long entry)
std::map< ProcessHistoryID const, ProcessHistory > ProcessHistoryMap
art::ProcessHistoryID const & processHistoryID() const
TBranch * eventAuxiliaryBranch() const
art::History * pEventHistory_
long long entriesInCurrentFile() const
long long previousEventHistoryEntry_
art::EventAuxiliary eventAuxiliary_
EventNavigator(std::vector< std::string > const &iFileNames)
art::EventAuxiliary * pEventAuxiliary_
long long previousEventAuxiliaryEntry_
long long eventEntry() const
art::History const & history() const
art::EventAuxiliary const & eventAuxiliary() const