File indexing completed on 2025-01-18 10:10:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TTreeReaderFast
0013 #define ROOT_TTreeReaderFast
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 #include "TTree.h"
0026 #include "TTreeReader.h"
0027
0028 #include <deque>
0029
0030
0031 namespace ROOT {
0032 namespace Experimental {
0033 namespace Internal {
0034 class TTreeReaderValueFast;
0035 class TTreeReaderValueFastBase;
0036 }
0037
0038 class TTreeReaderFast: public TObject {
0039 public:
0040
0041
0042
0043
0044
0045 class Iterator_t {
0046
0047 Int_t *fIdx{nullptr};
0048 Int_t fCount{0};
0049 Long64_t fEntry{-1};
0050 TTreeReaderFast *fReader{nullptr};
0051
0052
0053 bool IsValid() const { return fEntry >= 0; }
0054
0055 public:
0056 using iterator_category = std::input_iterator_tag;
0057 using value_type = const Long64_t;
0058 using difference_type = Long_t;
0059 using pointer = const Long64_t *;
0060 using const_pointer = const Long64_t *;
0061 using reference = const Long64_t &;
0062
0063
0064 Iterator_t() {}
0065
0066
0067
0068 Iterator_t(TTreeReaderFast& reader, Long64_t first):
0069 fIdx(&(reader.fEvtIndex)), fEntry(first), fReader(&reader)
0070 {
0071
0072 fCount = fReader->GetNextRange(fEntry);
0073 *fIdx = 0;
0074 }
0075
0076
0077 bool operator==(const Iterator_t& lhs) const {
0078
0079 if (R__unlikely(!IsValid() && !lhs.IsValid())) {return true;}
0080 return R__unlikely(fEntry == lhs.fEntry && fReader == lhs.fReader);
0081 }
0082
0083
0084 bool operator!=(const Iterator_t& lhs) const {
0085 return !(*this == lhs);
0086 }
0087
0088
0089 Iterator_t operator++(int) {
0090 Iterator_t ret = *this;
0091 this->operator++();
0092 return ret;
0093 }
0094
0095
0096 Iterator_t& operator++() {
0097 (*fIdx)++;
0098 if (R__unlikely(*fIdx == fCount)) {
0099
0100 fEntry += fCount;
0101 *fIdx = 0;
0102 fCount = fReader->GetNextRange(fEntry);
0103
0104 if (R__unlikely(!fCount || (fCount < 0))) {
0105 fEntry = -1;
0106 fReader->fEntryStatus = TTreeReader::kEntryBadReader;
0107 }
0108 }
0109 return *this;
0110 }
0111
0112
0113 Long64_t operator*() {
0114 return fEntry + *fIdx;
0115 }
0116
0117 Long64_t operator*() const {
0118 return **const_cast<Iterator_t*>(this);
0119 }
0120 };
0121
0122 typedef Iterator_t iterator;
0123
0124 TTreeReaderFast():
0125 fTree(nullptr),
0126 fEntryStatus(TTreeReader::kEntryNoTree),
0127 fLastEntry(-1)
0128 {}
0129
0130 TTreeReaderFast(TTree* tree);
0131 TTreeReaderFast(const char* keyname, TDirectory* dir = nullptr );
0132
0133 ~TTreeReaderFast() override;
0134
0135 TTreeReader::EEntryStatus SetEntriesRange(Long64_t first, Long64_t last);
0136
0137 TTreeReader::EEntryStatus GetEntryStatus() const { return fEntryStatus; }
0138
0139 TTree* GetTree() const { return fTree; }
0140
0141 TTreeReader::EEntryStatus SetEntry(Long64_t);
0142
0143
0144 Iterator_t begin() {
0145 return Iterator_t(*this, 0);
0146 }
0147 Iterator_t end() const { return Iterator_t(); }
0148
0149 protected:
0150
0151
0152 Int_t &GetIndexRef() {return fEvtIndex;}
0153
0154 void RegisterValueReader(ROOT::Experimental::Internal::TTreeReaderValueFastBase* reader);
0155 void DeregisterValueReader(ROOT::Experimental::Internal::TTreeReaderValueFastBase* reader);
0156
0157 private:
0158
0159 Int_t GetNextRange(Int_t);
0160 void Initialize();
0161
0162 TTree* fTree{nullptr};
0163 TDirectory* fDirectory{nullptr};
0164 ROOT::Internal::TBranchProxyDirector* fDirector{nullptr};
0165 TTreeReader::EEntryStatus fEntryStatus{TTreeReader::kEntryNotLoaded};
0166 std::deque<ROOT::Experimental::Internal::TTreeReaderValueFastBase*> fValues;
0167
0168 Int_t fEvtIndex{-1};
0169 Long64_t fBaseEvent{-1};
0170 Long64_t fLastEntry{-1};
0171
0172 friend class ROOT::Experimental::Internal::TTreeReaderValueFastBase;
0173
0174 ClassDefOverride(TTreeReaderFast, 0);
0175 };
0176
0177 }
0178 }
0179 #endif