// // Created by Gabriele Gaetano Fronzé on 30/05/2017. // #ifndef ALICE_MTR_UTILS_TSMARTTREE_H #define ALICE_MTR_UTILS_TSMARTTREE_H #include "TTree.h" #include "TBranch.h" #include "TTreeIndex.h" class TSmartTree : public TTree{ private: Bool_t fIsSorted; Long64_t *fTreeIndex; Long64_t fPosition; public: TSmartTree() : TTree(){ fIsSorted = kFALSE; fPosition = 0; } TSmartTree(const char* name, const char* title, Int_t splitlevel = 99) : TTree(name,title,splitlevel){ fIsSorted = kFALSE; fPosition = 0; } void Sort(const char* majorname, const char* minorname = "0"){ if (fIsSorted) return; this->BuildIndex(majorname,minorname); fTreeIndex = ((TTreeIndex*)this->GetTreeIndex())->GetIndex(); fIsSorted = kTRUE; }; Int_t Fill(){ fIsSorted = kFALSE; return TTree::Fill(); } int GetSortedEntry(Long64_t i){ if(fIsSorted) return this->GetEntry(fTreeIndex[i]); else return this->GetEntry(i); } int operator[](Long64_t i){ return this->GetSortedEntry(i); } int Next(){ return this->GetSortedEntry(fPosition++); } inline Bool_t GetIsSorted(){ return fIsSorted; } inline Long64_t GetPosition(){ return fPosition; } ClassDef(TSmartTree,1); }; #endif //ALICE_MTR_UTILS_TSMARTTREE_H