#ifndef ROOT_TTreeReaderValue
#define ROOT_TTreeReaderValue
#ifndef ROOT_TString
#include "TString.h"
#endif
#ifndef ROOT_TDictionary
#include "TDictionary.h"
#endif
#ifndef ROOT_TBranchProxy
#include "TBranchProxy.h"
#endif
class TBranch;
class TBranchElement;
class TLeaf;
class TTreeReader;
namespace ROOT {
class TTreeReaderValueBase {
public:
enum ESetupStatus {
kSetupNotSetup = -7,
kSetupTreeDestructed = -8,
kSetupMakeClassModeMismatch = -7,
kSetupMissingCounterBranch = -6,
kSetupMissingBranch = -5,
kSetupInternalError = -4,
kSetupMissingCompiledCollectionProxy = -3,
kSetupMismatch = -2,
kSetupClassMismatch = -1,
kSetupMatch = 0,
kSetupMatchBranch = 0,
kSetupMatchConversion,
kSetupMatchConversionCollection,
kSetupMakeClass,
kSetupVoidPtr,
kSetupNoCheck,
kSetupMatchLeaf
};
enum EReadStatus {
kReadSuccess = 0,
kReadNothingYet,
kReadError
};
EReadStatus ProxyRead();
Bool_t IsValid() const { return fProxy && 0 == (int)fSetupStatus && 0 == (int)fReadStatus; }
ESetupStatus GetSetupStatus() const { return fSetupStatus; }
virtual EReadStatus GetReadStatus() const { return fReadStatus; }
TLeaf* GetLeaf();
void* GetAddress();
const char* GetBranchName() const { return fBranchName; }
protected:
TTreeReaderValueBase(TTreeReader* reader = 0, const char* branchname = 0, TDictionary* dict = 0);
virtual ~TTreeReaderValueBase();
virtual void CreateProxy();
const char* GetBranchDataType(TBranch* branch,
TDictionary* &dict) const;
virtual const char* GetDerivedTypeName() const = 0;
ROOT::TBranchProxy* GetProxy() const { return fProxy; }
void MarkTreeReaderUnavailable() { fTreeReader = 0; }
TString fBranchName;
TString fLeafName;
TTreeReader* fTreeReader;
TDictionary* fDict;
ROOT::TBranchProxy* fProxy;
TLeaf* fLeaf;
Long64_t fTreeLastOffset;
ESetupStatus fSetupStatus;
EReadStatus fReadStatus;
std::vector<Long64_t> fStaticClassOffsets;
friend class ::TTreeReader;
};
}
template <typename T>
class TTreeReaderValue: public ROOT::TTreeReaderValueBase {
public:
TTreeReaderValue() {}
TTreeReaderValue(TTreeReader& tr, const char* branchname):
TTreeReaderValueBase(&tr, branchname, TDictionary::GetDictionary(typeid(T))) {}
T* Get() {
if (!fProxy){
Error("Get()", "Value reader not properly initialized, did you remember to call TTreeReader.Set(Next)Entry()?");
return 0;
}
void *address = GetAddress();
return fProxy->IsaPointer() ? *(T**)address : (T*)address; }
T* operator->() { return Get(); }
T& operator*() { return *Get(); }
protected:
#define R__TTreeReaderValue_TypeString(T) #T
virtual const char* GetDerivedTypeName() const { return R__TTreeReaderValue_TypeString(T); }
#undef R__TTreeReaderValue_TypeString
};
#endif // ROOT_TTreeReaderValue