#ifndef ROOT_TTreeReader
#define ROOT_TTreeReader
#ifndef ROOT_THashTable
#include "THashTable.h"
#endif
#ifndef ROOT_TTree
#include "TTree.h"
#endif
#ifndef ROOT_TTreeReaderUtils
#include "TTreeReaderUtils.h"
#endif
#include <deque>
#include <iterator>
class TDictionary;
class TDirectory;
class TFileCollection;
namespace ROOT {
class TBranchProxyDirector;
}
class TTreeReader: public TObject {
public:
class Iterator_t:
public std::iterator<std::input_iterator_tag, const Long64_t, Long64_t> {
private:
Long64_t fEntry;
TTreeReader* fReader;
bool IsValid() const { return fEntry >= 0; }
public:
Iterator_t(): fEntry(-1), fReader() {}
Iterator_t(TTreeReader& reader, Long64_t entry):
fEntry(entry), fReader(&reader) {}
bool operator==(const Iterator_t& lhs) const {
if (!IsValid() && !lhs.IsValid()) return true;
return fEntry == lhs.fEntry && fReader == lhs.fReader;
}
bool operator!=(const Iterator_t& lhs) const {
return !(*this == lhs);
}
Iterator_t operator++(int) {
Iterator_t ret = *this;
this->operator++();
return ret;
}
Iterator_t& operator++() {
if (IsValid()) {
++fEntry;
this->operator*();
}
return *this;
}
const Long64_t& operator*() {
if (IsValid()) {
if (fReader->SetEntry(fEntry) != kEntryValid) {
fEntry = -1;
}
}
return fEntry;
}
const Long64_t& operator*() const {
return **const_cast<Iterator_t*>(this);
}
};
typedef Iterator_t iterator;
enum EEntryStatus {
kEntryValid = 0,
kEntryNotLoaded,
kEntryNoTree,
kEntryNotFound,
kEntryChainSetupError,
kEntryChainFileError,
kEntryDictionaryError,
};
TTreeReader():
fDirectory(0),
fEntryStatus(kEntryNoTree),
fDirector(0)
{}
TTreeReader(TTree* tree);
TTreeReader(const char* keyname, TDirectory* dir = NULL );
TTreeReader(const char* , TFileCollection* ) { Error("TTreeReader()", "Not Implemented!");};
~TTreeReader();
void SetTree(TTree* tree);
void SetTree(const char* , TDirectory* ) { Error("SetTree()", "Not Implemented!");};
void SetChain(const char* , TFileCollection* ) { Error("SetChain()", "Not Implemented!");};
Bool_t IsChain() const { return TestBit(kBitIsChain); }
Bool_t Next() { return SetEntry(GetCurrentEntry() + 1) == kEntryValid; }
EEntryStatus SetEntry(Long64_t entry) { return SetEntryBase(entry, kFALSE); }
EEntryStatus SetLocalEntry(Long64_t entry) { return SetEntryBase(entry, kTRUE); }
EEntryStatus GetEntryStatus() const { return fEntryStatus; }
TTree* GetTree() const { return fTree; }
Long64_t GetEntries(Bool_t force) const { return fTree ? (force ? fTree->GetEntries() : fTree->GetEntriesFast() ) : -1; }
Long64_t GetCurrentEntry() const;
Iterator_t begin() {
return Iterator_t(*this, 0);
}
Iterator_t end() const { return Iterator_t(); }
protected:
void Initialize();
ROOT::TNamedBranchProxy* FindProxy(const char* branchname) const {
return (ROOT::TNamedBranchProxy*) fProxies.FindObject(branchname); }
TCollection* GetProxies() { return &fProxies; }
void RegisterValueReader(ROOT::TTreeReaderValueBase* reader);
void DeregisterValueReader(ROOT::TTreeReaderValueBase* reader);
EEntryStatus SetEntryBase(Long64_t entry, Bool_t local);
private:
enum EPropertyBits {
kBitIsChain = BIT(14)
};
TTree* fTree;
TDirectory* fDirectory;
EEntryStatus fEntryStatus;
ROOT::TBranchProxyDirector* fDirector;
std::deque<ROOT::TTreeReaderValueBase*> fValues;
THashTable fProxies;
friend class ROOT::TTreeReaderValueBase;
friend class ROOT::TTreeReaderArrayBase;
ClassDef(TTreeReader, 0);
};
#endif // defined TTreeReader