12 #ifndef ROOT_TTreeReaderValue
13 #define ROOT_TTreeReaderValue
28 #include <type_traits>
42 class TTreeReaderValueBase {
48 kSetupTreeDestructed = -8,
49 kSetupMakeClassModeMismatch = -7,
50 kSetupMissingCounterBranch = -6,
51 kSetupMissingBranch = -5,
52 kSetupInternalError = -4,
53 kSetupMissingDictionary = -3,
55 kSetupNotACollection = -1,
57 kSetupMatchBranch = 0,
71 EReadStatus ProxyRead() {
return (this->*fProxyReadFunc)(); }
73 EReadStatus ProxyReadDefaultImpl();
75 typedef Bool_t (ROOT::Detail::TBranchProxy::*BranchProxyRead_t)();
76 template <BranchProxyRead_t Func>
77 ROOT::Internal::TTreeReaderValueBase::EReadStatus ProxyReadTemplate();
79 Bool_t IsValid()
const {
return fProxy && 0 == (int)fSetupStatus && 0 == (
int)fReadStatus; }
80 ESetupStatus GetSetupStatus()
const {
return fSetupStatus; }
81 virtual EReadStatus GetReadStatus()
const {
return fReadStatus; }
84 TLeaf* GetLeaf() {
return fLeaf; }
88 const char* GetBranchName()
const {
return fBranchName; }
90 virtual ~TTreeReaderValueBase();
93 TTreeReaderValueBase(TTreeReader* reader,
const char* branchname, TDictionary* dict);
94 TTreeReaderValueBase(
const TTreeReaderValueBase&);
95 TTreeReaderValueBase& operator=(
const TTreeReaderValueBase&);
97 void RegisterWithTreeReader();
98 void NotifyNewTree(TTree* newTree);
100 TBranch* SearchBranchWithCompositeName(TLeaf *&myleaf, TDictionary *&branchActualType, std::string &err);
101 virtual void CreateProxy();
102 static const char* GetBranchDataType(TBranch* branch,
104 TDictionary
const *curDict);
106 virtual const char* GetDerivedTypeName()
const = 0;
108 Detail::TBranchProxy* GetProxy()
const {
return fProxy; }
110 void MarkTreeReaderUnavailable() { fTreeReader = 0; fSetupStatus = kSetupTreeDestructed; }
113 static std::string GetElementTypeName(
const std::type_info& ti);
116 int fHaveStaticClassOffsets : 1;
117 EReadStatus fReadStatus : 2;
118 ESetupStatus fSetupStatus = kSetupNotSetup;
121 TTreeReader* fTreeReader;
123 Detail::TBranchProxy* fProxy =
nullptr;
124 TLeaf* fLeaf =
nullptr;
125 std::vector<Long64_t> fStaticClassOffsets;
126 typedef EReadStatus (TTreeReaderValueBase::*Read_t)();
127 Read_t fProxyReadFunc = &TTreeReaderValueBase::ProxyReadDefaultImpl;
132 friend class ::TTreeReader;
139 template <
typename T>
140 class R__CLING_PTRCHECK(off) TTreeReaderValue final:
public ROOT::Internal::TTreeReaderValueBase {
144 using NonConstT_t =
typename std::remove_const<T>::type;
145 TTreeReaderValue() =
delete;
146 TTreeReaderValue(TTreeReader& tr,
const char* branchname):
147 TTreeReaderValueBase(&tr, branchname,
148 TDictionary::GetDictionary(typeid(NonConstT_t))) {}
157 Error(
"TTreeReaderValue::Get()",
"Value reader not properly initialized, did you remember to call TTreeReader.Set(Next)Entry()?");
160 void *address = GetAddress();
161 return fProxy->IsaPointer() ? *(T**)address : (T*)address; }
164 T* operator->() {
return Get(); }
168 T& operator*() {
return *Get(); }
173 virtual const char* GetDerivedTypeName()
const {
174 static const std::string sElementTypeName = GetElementTypeName(
typeid(T));
175 return sElementTypeName.data();
182 #endif // ROOT_TTreeReaderValue