60 fHaveStaticClassOffsets(false),
61 fReadStatus(kReadNothingYet),
62 fBranchName(branchname),
65 fOpaqueRead(opaqueRead)
67 auto * cl =
dynamic_cast<TClass *
>(dict);
69 if (cl && HasEmulatedProxy(cl)) {
70 PrintWriteStlWithoutProxyMsg(
"TTreeReaderValueBase", cl->GetName(), branchname);
79 : fHaveLeaf(rhs.fHaveLeaf),
80 fHaveStaticClassOffsets(rhs.fHaveStaticClassOffsets),
81 fReadStatus(rhs.fReadStatus),
82 fSetupStatus(rhs.fSetupStatus),
83 fBranchName(rhs.fBranchName),
84 fLeafName(rhs.fLeafName),
85 fTreeReader(rhs.fTreeReader),
89 fStaticClassOffsets(rhs.fStaticClassOffsets)
106 fTreeReader->DeregisterValueReader(
this);
108 RegisterWithTreeReader();
126 fTreeReader->DeregisterValueReader(
this);
127 R__ASSERT((fLeafName.Length() == 0) == !fHaveLeaf &&
"leafness disagreement");
128 R__ASSERT(fStaticClassOffsets.empty() == !fHaveStaticClassOffsets &&
"static class offset disagreement");
137 if (!fTreeReader->RegisterValueReader(
this)) {
138 fTreeReader =
nullptr;
147template <ROOT::Internal::TTreeReaderValueBase::BranchProxyRead_t Func>
150 if ((fProxy->*Func)()) {
151 fReadStatus = kReadSuccess;
153 fReadStatus = kReadError;
161 return kReadNothingYet;
162 if (fProxy->IsInitialized() || fProxy->Setup()) {
167 EReadType readtype = EReadType::kNoDirector;
172 case EReadType::kNoDirector:
173 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoDirector>;
175 case EReadType::kReadParentNoCollection:
176 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentNoCollection>;
178 case EReadType::kReadParentCollectionNoPointer:
179 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentCollectionNoPointer>;
181 case EReadType::kReadParentCollectionPointer:
182 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentCollectionPointer>;
184 case EReadType::kReadNoParentNoBranchCountCollectionPointer:
186 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionPointer>;
188 case EReadType::kReadNoParentNoBranchCountCollectionNoPointer:
190 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionNoPointer>;
192 case EReadType::kReadNoParentNoBranchCountNoCollection:
193 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountNoCollection>;
195 case EReadType::kReadNoParentBranchCountCollectionPointer:
197 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionPointer>;
199 case EReadType::kReadNoParentBranchCountCollectionNoPointer:
201 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionNoPointer>;
203 case EReadType::kReadNoParentBranchCountNoCollection:
204 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountNoCollection>;
206 case EReadType::kDefault:
210 return (this->*fProxyReadFunc)();
216 if (fProxy->Read()) {
217 fReadStatus = kReadSuccess;
219 fReadStatus = kReadError;
230 std::string ret = buf;
244 if (!fHaveLeaf || !newTree) {
252 fReadStatus = kReadError;
253 Error(
"TTreeReaderValueBase::GetLeaf()",
"Unable to get the branch from the tree");
257 fLeaf = myBranch->
GetLeaf(fLeafName);
259 Error(
"TTreeReaderValueBase::GetLeaf()",
"Failed to get the leaf from the branch");
273 fProxy->fDirector->GetReadEntry() == -1)
276 if (ProxyRead() != kReadSuccess)
281 return fLeaf->GetValuePointer();
283 fReadStatus = kReadError;
284 Error(
"TTreeReaderValueBase::GetAddress()",
"Unable to get the leaf");
288 if (fHaveStaticClassOffsets) {
291 for (
unsigned int i = 0; i < fStaticClassOffsets.size() - 1; ++i) {
292 address = *(
Byte_t **)(address + fStaticClassOffsets[i]);
295 return address + fStaticClassOffsets.back();
297 return (
Byte_t *)fProxy->GetWhere();
319 TRegexp leafNameExpression(
"\\.[a-zA-Z0-9_]+$");
320 TString leafName(fBranchName(leafNameExpression));
321 TString branchName = fBranchName(0, fBranchName.Length() - leafName.
Length());
322 auto branch = fTreeReader->GetTree()->GetBranch(branchName);
324 std::vector<TString> nameStack;
325 nameStack.push_back(
TString());
327 leafName = branchName(leafNameExpression);
328 branchName = branchName(0, branchName.
Length() - leafName.
Length());
330 branch = fTreeReader->GetTree()->GetBranch(branchName);
332 branch = fTreeReader->GetTree()->GetBranch(branchName +
".");
336 while (!branch && branchName.
Contains(
".")) {
337 leafName = branchName(leafNameExpression);
338 branchName = branchName(0, branchName.
Length() - leafName.
Length());
339 branch = fTreeReader->GetTree()->GetBranch(branchName);
341 branch = fTreeReader->GetTree()->GetBranch(branchName +
".");
348 TString traversingBranch = nameStack.back();
349 nameStack.pop_back();
355 std::vector<Long64_t> offsets;
357 TClass *elementClass =
nullptr;
362 while (!nameStack.empty() && found) {
365 for (
int i = 0; i < myObjArray->
GetEntries(); ++i) {
369 if (!strcmp(tempStreamerElement->
GetName(), traversingBranch.
Data())) {
372 traversingBranch = nameStack.back();
373 nameStack.pop_back();
375 elementClass = tempStreamerElement->
GetClass();
382 if (!finalDataType) {
391 offsets.push_back(
offset);
401 offsets.push_back(
offset);
404 fStaticClassOffsets = offsets;
405 fHaveStaticClassOffsets =
true;
407 if (fDict != finalDataType && fDict != elementClass) {
408 errMsg =
"Wrong data type ";
409 errMsg += finalDataType ? finalDataType->
GetName() : elementClass ? elementClass->
GetName() :
"UNKNOWN";
410 fSetupStatus = kSetupMismatch;
417 if (!fHaveStaticClassOffsets) {
418 errMsg =
"The tree does not have a branch called ";
419 errMsg += fBranchName;
420 errMsg +=
". You could check with TTree::Print() for available branches.";
421 fSetupStatus = kSetupMissingBranch;
426 myLeaf = branch->GetLeaf(
TString(leafName(1, leafName.
Length())));
428 errMsg =
"The tree does not have a branch, nor a sub-branch called ";
429 errMsg += fBranchName;
430 errMsg +=
". You could check with TTree::Print() for available branches.";
431 fSetupStatus = kSetupMissingBranch;
438 branchActualType = fDict;
440 fBranchName = branchName;
441 fLeafName = leafName(1, leafName.
Length());
442 fHaveLeaf = fLeafName.Length() > 0;
443 fSetupStatus = kSetupMatchLeaf;
445 errMsg =
"Leaf of type ";
447 errMsg +=
" cannot be read by TTreeReaderValue<";
450 fSetupStatus = kSetupMismatch;
465 constexpr const char *errPrefix =
"TTreeReaderValueBase::CreateProxy()";
471 fSetupStatus = kSetupInternalError;
473 Error(errPrefix,
"TTreeReader object not set / available for branch %s!", fBranchName.Data());
474 fSetupStatus = kSetupTreeDestructed;
478 auto branchFromFullName = fTreeReader->GetTree()->GetBranch(fBranchName);
479 if (branchFromFullName ==
nullptr)
480 branchFromFullName = fTreeReader->GetTree()->FindBranch(fBranchName);
484 const char *brDataType =
"{UNDETERMINED}";
485 if (branchFromFullName) {
487 brDataType = GetBranchDataType(branchFromFullName, brDictUnused, fDict);
490 "The template argument type T of %s accessing branch %s (which contains data of type %s) is not known "
491 "to ROOT. You will need to create a dictionary for it.",
492 GetDerivedTypeName(), fBranchName.Data(), brDataType);
493 fSetupStatus = kSetupMissingDictionary;
498 if (branchFromFullName) {
499 GetBranchDataType(branchFromFullName, fDict,
nullptr);
508 if (namedProxy && namedProxy->
GetDict() == fDict) {
513 const std::string originalBranchName = fBranchName.Data();
515 TLeaf *myLeaf =
nullptr;
526 if (fBranchName.Contains(
".")) {
527 branch = SearchBranchWithCompositeName(myLeaf, branchActualType, errMsg);
536 branch = branchFromFullName;
537 fStaticClassOffsets = {};
538 fHaveStaticClassOffsets =
false;
550 const auto &suppressErrorsForMissingBranches = fTreeReader->fSuppressErrorsForMissingBranches;
551 const bool suppressErrorsForThisBranch =
552 (suppressErrorsForMissingBranches.find(originalBranchName) != suppressErrorsForMissingBranches.cend());
557 branch = branchFromFullName;
561 fSetupStatus = kSetupMissingBranch;
563 if (suppressErrorsForThisBranch)
569 if (errMsg.empty()) {
570 errMsg =
"The tree does not have a branch called ";
571 errMsg += fBranchName.Data();
572 errMsg +=
". You could check with TTree::Print() for available branches.";
574#if !defined(_MSC_VER)
575#pragma GCC diagnostic push
576#pragma GCC diagnostic ignored "-Wformat-security"
578 Error(errPrefix, errMsg.c_str());
579#if !defined(_MSC_VER)
580#pragma GCC diagnostic pop
586 fSetupStatus = kSetupInternalError;
587 fStaticClassOffsets = {};
588 fHaveStaticClassOffsets =
false;
591 if (!myLeaf && !fHaveStaticClassOffsets) {
594 const char *branchActualTypeName = GetBranchDataType(branch, branchActualType, fDict);
595 if (!branchActualType) {
596 Error(errPrefix,
"The branch %s contains data of type %s, which does not have a dictionary.",
597 fBranchName.Data(), branchActualTypeName ? branchActualTypeName :
"{UNDETERMINED TYPE}");
604 auto dictAsClass =
dynamic_cast<TClass *
>(fDict);
605 auto branchActualTypeAsClass =
dynamic_cast<TClass *
>(branchActualType);
606 auto inheritance = dictAsClass && branchActualTypeAsClass && branchActualTypeAsClass->
InheritsFrom(dictAsClass);
607 bool typeinfoMatch = dictAsClass && dictAsClass->GetTypeInfo() &&
608 dictAsClass->GetTypeInfo() == branchActualTypeAsClass->GetTypeInfo();
610 if (!inheritance && !typeinfoMatch && fDict != branchActualType) {
613 TEnum *dictenum =
dynamic_cast<TEnum *
>(fDict);
614 TEnum *actualenum =
dynamic_cast<TEnum *
>(branchActualType);
615 bool complainAboutMismatch =
true;
616 if (dictdt && actualdt) {
619 complainAboutMismatch =
false;
624 complainAboutMismatch =
false;
626 }
else if ((dictdt || dictenum) && (actualdt || actualenum)) {
629 complainAboutMismatch =
false;
632 complainAboutMismatch =
false;
634 if (complainAboutMismatch) {
635 Error(errPrefix,
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
636 fBranchName.Data(), branchActualType->
GetName(), fDict->GetName());
650 bool isTopLevel = branch->
GetMother() == branch;
652 membername = strrchr(branch->
GetName(),
'.');
653 if (membername.
IsNull()) {
654 membername = branch->
GetName();
657 auto director = fTreeReader->fDirector.get();
661 std::optional<std::size_t>
index;
662 std::size_t current{};
663 auto &&friends = fTreeReader->GetTree()->GetTree()->GetListOfFriends();
671 if (!
index.has_value()) {
673 "The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
674 "This is not yet supported by TTreeReader.",
678 auto &&friendProxy = fTreeReader->AddFriendProxy(
index.value());
679 fTreeReader->AddProxy(std::make_unique<TNamedBranchProxy>(friendProxy.GetDirector(), branch,
680 originalBranchName.c_str(), branch->
GetName(),
681 membername, suppressErrorsForThisBranch));
683 fTreeReader->AddProxy(std::make_unique<TNamedBranchProxy>(director, branch, originalBranchName.c_str(),
684 membername, suppressErrorsForThisBranch));
686 namedProxy = fTreeReader->FindProxy(originalBranchName.c_str());
699 fSetupStatus = kSetupMatchButEntryBeyondEnd;
701 fSetupStatus = kSetupMatch;
703 fSetupStatus = kSetupMismatch;
719 auto ResolveTypedef = [&]() ->
void {
726 if (dict != curDict) {
729 if (dict != curDict) {
766 return "TClonesArray";
767 }
else if (brElement->
GetType() == 31 || brElement->
GetType() == 41) {
769 Error(
"TTreeReaderValueBase::GetBranchDataType()",
770 "Must use TTreeReaderArray to access a member of an object that is stored in a collection.");
776 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Unknown type and class combination: %i, %s",
799 Error(
"TTreeReaderValueBase::GetBranchDataType()",
800 "Must use TTreeReaderArray to read branch %s: it contains an array or a collection.",
810 Error(
"TTreeReaderValueBase::GetBranchDataType()",
811 "The branch %s was created using a leaf list and cannot be represented as a C++ type. Please access one "
812 "of its siblings using a TTreeReaderArray:",
815 TLeaf *leaf =
nullptr;
816 while ((leaf = (
TLeaf *)iLeaves())) {
817 Error(
"TTreeReaderValueBase::GetBranchDataType()",
" %s.%s", branch->
GetName(), leaf->
GetName());
826 return "TClonesArray";
829 Error(
"TTreeReaderValueBase::GetBranchDataType()",
830 "The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
833 Error(
"TTreeReaderValueBase::GetBranchDataType()",
834 "The branch %s is of type %s - something that is not handled yet.", branch->
GetName(),
846 if (!fTreeReader || fTreeReader->fMissingProxies.count(fBranchName.Data()) == 0)
847 Error(
"TTreeReaderValue::Get()",
848 "Value reader for branch %s not properly initialized, did you call "
849 "TTreeReader::Set(Next)Entry() or TTreeReader::Next()?",
862 std::string str = cl->GetName();
863 str +=
" instance associated to column ";
unsigned char Byte_t
Byte (8 bits) (unsigned char)
long long Long64_t
Portable signed long integer 8 bytes.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Base class for all the proxy object.
void SetDict(TDictionary *dict)
const Detail::TBranchProxy * GetProxy() const
TDictionary * GetDict() const
Base class of TTreeReaderValue.
void RegisterWithTreeReader()
Register with tree reader.
void NotifyNewTree(TTree *newTree)
The TTreeReader has switched to a new TTree. Update the leaf.
bool fHaveLeaf
Whether the data is in a leaf.
bool fHaveStaticClassOffsets
Whether !fStaticClassOffsets.empty()
void * GetAddress()
Returns the memory address of the object being read.
static std::string GetElementTypeName(const std::type_info &ti)
Stringify the template argument.
ESetupStatus fSetupStatus
Setup status of this data access.
TString fBranchName
Name of the branch to read data from.
ROOT::Internal::TTreeReaderValueBase::EReadStatus ProxyReadTemplate()
Try to read the value from the TBranchProxy, returns the status of the read.
TTreeReader * fTreeReader
Tree reader we belong to.
TDictionary * fDict
Type that the branch should contain.
TTreeReaderValueBase & operator=(const TTreeReaderValueBase &)
Copy-assign.
EReadStatus fReadStatus
Read status of this data access.
const char * GetBranchName() const
void ErrorAboutMissingProxyIfNeeded()
virtual ~TTreeReaderValueBase()
Unregister from tree reader, cleanup.
TTreeReaderValueBase(TTreeReader *reader, const char *branchname, TDictionary *dict, bool opaqueRead=false)
Construct a tree value reader and register it with the reader object.
EReadStatus ProxyReadDefaultImpl()
virtual void CreateProxy()
Create the proxy object for our branch.
Detail::TBranchProxy * fProxy
Proxy for this branch, owned by TTreeReader.
std::vector< Long64_t > fStaticClassOffsets
TBranch * SearchBranchWithCompositeName(TLeaf *&myleaf, TDictionary *&branchActualType, std::string &err)
Search a branch the name of which contains a ".".
static const char * GetBranchDataType(TBranch *branch, TDictionary *&dict, TDictionary const *curDict)
Retrieve the type of data stored by branch; put its dictionary into dict, return its type name.
A Branch for the case of an object.
const char * GetClassName() const override
Return the name of the user class whose content is stored in this branch, if any.
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
TClass * GetCurrentClass()
Return a pointer to the current type of the data member corresponding to branch element.
virtual const char * GetTypeName() const
Return type name of element in the branch.
A TTree is a list of TBranches.
virtual TLeaf * GetLeaf(const char *name) const
Return pointer to the 1st Leaf named name in thisBranch.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
TClass * IsA() const override
virtual TLeaf * FindLeaf(const char *name)
Find the leaf corresponding to the name 'searchname'.
TObjArray * GetListOfLeaves()
TBranch * GetMother() const
Get our top-level parent branch in the tree.
TClass instances represent classes, structs and namespaces in the ROOT type system.
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
Basic data type descriptor (datatype information is obtained from CINT).
static TDataType * GetDataType(EDataType type)
Given a EDataType type, get the TDataType* that represents it.
TClass * IsA() const override
This class defines an abstract interface that must be implemented by all classes that contain diction...
TClass * IsA() const override
static TDictionary * GetDictionary(const char *name)
Retrieve the type (class, fundamental type, typedef etc) named "name".
The TEnum class implements the enum type.
EDataType GetUnderlyingType() const
Get the underlying integer type of the enum: enum E { kOne }; // ==> int enum F: long; // ==> long Re...
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual const char * GetTypeName() const
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
virtual Int_t GetLenStatic() const
Return the fixed length of this leaf.
const char * GetName() const override
Returns name of object.
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
TObject * UncheckedAt(Int_t i) const
Regular expression class.
Describe one element (data member) to be Streamed.
virtual Bool_t IsaPointer() const
const char * GetTypeName() const
TClass * GetClass() const
TClass * IsA() const override
Describes a persistent version of a class.
TObjArray * GetElements() const override
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
const char * Data() const
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
@ kIndexedFriendNoMatch
A friend with TTreeIndex doesn't have an entry for this index.
@ kEntryBeyondEnd
last entry loop has reached its end
A TTree represents a columnar dataset.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
virtual TTree * GetTree() const
TClass * IsA() const override
Abstract Interface class describing Streamer information for one class.
virtual TObjArray * GetElements() const =0
virtual Int_t GetElementOffset(Int_t id) const =0
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.