60 fHaveStaticClassOffsets(
false),
61 fReadStatus(kReadNothingYet),
74 : fHaveLeaf(
rhs.fHaveLeaf),
75 fHaveStaticClassOffsets(
rhs.fHaveStaticClassOffsets),
76 fReadStatus(
rhs.fReadStatus),
77 fSetupStatus(
rhs.fSetupStatus),
78 fBranchName(
rhs.fBranchName),
79 fLeafName(
rhs.fLeafName),
80 fTreeReader(
rhs.fTreeReader),
84 fStaticClassOffsets(
rhs.fStaticClassOffsets)
95 fHaveLeaf =
rhs.fHaveLeaf;
96 fHaveStaticClassOffsets =
rhs.fHaveStaticClassOffsets;
97 fBranchName =
rhs.fBranchName;
98 fLeafName =
rhs.fLeafName;
99 if (fTreeReader !=
rhs.fTreeReader) {
101 fTreeReader->DeregisterValueReader(
this);
102 fTreeReader =
rhs.fTreeReader;
103 RegisterWithTreeReader();
108 fSetupStatus =
rhs.fSetupStatus;
109 fReadStatus =
rhs.fReadStatus;
110 fStaticClassOffsets =
rhs.fStaticClassOffsets;
121 fTreeReader->DeregisterValueReader(
this);
122 R__ASSERT((fLeafName.Length() == 0) == !fHaveLeaf &&
"leafness disagreement");
123 R__ASSERT(fStaticClassOffsets.empty() == !fHaveStaticClassOffsets &&
"static class offset disagreement");
132 if (!fTreeReader->RegisterValueReader(
this)) {
133 fTreeReader =
nullptr;
142template <ROOT::Internal::TTreeReaderValueBase::BranchProxyRead_t Func>
145 if ((fProxy->*Func)()) {
146 fReadStatus = kReadSuccess;
148 fReadStatus = kReadError;
156 return kReadNothingYet;
157 if (fProxy->IsInitialized() || fProxy->Setup()) {
162 EReadType
readtype = EReadType::kNoDirector;
167 case EReadType::kNoDirector:
168 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoDirector>;
170 case EReadType::kReadParentNoCollection:
171 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentNoCollection>;
173 case EReadType::kReadParentCollectionNoPointer:
174 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentCollectionNoPointer>;
176 case EReadType::kReadParentCollectionPointer:
177 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentCollectionPointer>;
179 case EReadType::kReadNoParentNoBranchCountCollectionPointer:
181 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionPointer>;
183 case EReadType::kReadNoParentNoBranchCountCollectionNoPointer:
185 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionNoPointer>;
187 case EReadType::kReadNoParentNoBranchCountNoCollection:
188 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountNoCollection>;
190 case EReadType::kReadNoParentBranchCountCollectionPointer:
192 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionPointer>;
194 case EReadType::kReadNoParentBranchCountCollectionNoPointer:
196 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionNoPointer>;
198 case EReadType::kReadNoParentBranchCountNoCollection:
199 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountNoCollection>;
201 case EReadType::kDefault:
205 return (this->*fProxyReadFunc)();
211 if (fProxy->Read()) {
212 fReadStatus = kReadSuccess;
214 fReadStatus = kReadError;
225 std::string
ret = buf;
247 fReadStatus = kReadError;
248 Error(
"TTreeReaderValueBase::GetLeaf()",
"Unable to get the branch from the tree");
252 fLeaf =
myBranch->GetLeaf(fLeafName);
254 Error(
"TTreeReaderValueBase::GetLeaf()",
"Failed to get the leaf from the branch");
268 fProxy->fDirector->GetReadEntry() == -1)
271 if (ProxyRead() != kReadSuccess)
276 return fLeaf->GetValuePointer();
278 fReadStatus = kReadError;
279 Error(
"TTreeReaderValueBase::GetAddress()",
"Unable to get the leaf");
283 if (fHaveStaticClassOffsets) {
286 for (
unsigned int i = 0; i < fStaticClassOffsets.size() - 1; ++i) {
287 address = *(
Byte_t **)(address + fStaticClassOffsets[i]);
290 return address + fStaticClassOffsets.back();
292 return (
Byte_t *)fProxy->GetWhere();
350 std::vector<Long64_t> offsets;
360 for (
int i = 0; i <
myObjArray->GetEntries(); ++i) {
386 offsets.push_back(
offset);
396 offsets.push_back(
offset);
399 fStaticClassOffsets = offsets;
400 fHaveStaticClassOffsets =
true;
403 errMsg =
"Wrong data type ";
405 fSetupStatus = kSetupMismatch;
412 if (!fHaveStaticClassOffsets) {
413 errMsg =
"The tree does not have a branch called ";
415 errMsg +=
". You could check with TTree::Print() for available branches.";
416 fSetupStatus = kSetupMissingBranch;
423 errMsg =
"The tree does not have a branch, nor a sub-branch called ";
425 errMsg +=
". You could check with TTree::Print() for available branches.";
426 fSetupStatus = kSetupMissingBranch;
437 fHaveLeaf = fLeafName.Length() > 0;
438 fSetupStatus = kSetupMatchLeaf;
442 errMsg +=
" cannot be read by TTreeReaderValue<";
445 fSetupStatus = kSetupMismatch;
460 constexpr const char *
errPrefix =
"TTreeReaderValueBase::CreateProxy()";
466 fSetupStatus = kSetupInternalError;
468 Error(
errPrefix,
"TTreeReader object not set / available for branch %s!", fBranchName.Data());
469 fSetupStatus = kSetupTreeDestructed;
485 "The template argument type T of %s accessing branch %s (which contains data of type %s) is not known "
486 "to ROOT. You will need to create a dictionary for it.",
487 GetDerivedTypeName(), fBranchName.Data(),
brDataType);
488 fSetupStatus = kSetupMissingDictionary;
521 if (fBranchName.Contains(
".")) {
532 fStaticClassOffsets = {};
533 fHaveStaticClassOffsets =
false;
557 fSetupStatus = kSetupMissingBranch;
566 errMsg =
"The tree does not have a branch called ";
567 errMsg += fBranchName.Data();
568 errMsg +=
". You could check with TTree::Print() for available branches.";
570#if !defined(_MSC_VER)
571#pragma GCC diagnostic push
572#pragma GCC diagnostic ignored "-Wformat-security"
575#if !defined(_MSC_VER)
576#pragma GCC diagnostic pop
582 fSetupStatus = kSetupInternalError;
583 fStaticClassOffsets = {};
584 fHaveStaticClassOffsets =
false;
587 if (!
myLeaf && !fHaveStaticClassOffsets) {
592 Error(
errPrefix,
"The branch %s contains data of type %s, which does not have a dictionary.",
631 Error(
errPrefix,
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
653 auto director = fTreeReader->fDirector.get();
655 if (
branch->GetTree() != fTreeReader->GetTree()->GetTree()) {
657 std::optional<std::size_t>
index;
658 std::size_t current{};
659 auto &&
friends = fTreeReader->GetTree()->GetTree()->GetListOfFriends();
661 if (
branch->GetTree() ==
fe->GetTree()) {
667 if (!
index.has_value()) {
669 "The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
670 "This is not yet supported by TTreeReader.",
675 fTreeReader->AddProxy(std::make_unique<TNamedBranchProxy>(
friendProxy.GetDirector(),
branch,
691 fSetupStatus = kSetupMatch;
693 fSetupStatus = kSetupMismatch;
709 auto ResolveTypedef = [&]() ->
void {
735 dict =
myStl->GetClass();
756 return "TClonesArray";
759 Error(
"TTreeReaderValueBase::GetBranchDataType()",
760 "Must use TTreeReaderArray to access a member of an object that is stored in a collection.");
766 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Unknown type and class combination: %i, %s",
782 if (!
myLeaf &&
branch->GetListOfLeaves()->GetEntries() == 1) {
788 if (
myLeaf->GetLeafCount() !=
nullptr ||
myLeaf->GetLenStatic() > 1) {
789 Error(
"TTreeReaderValueBase::GetBranchDataType()",
790 "Must use TTreeReaderArray to read branch %s: it contains an array or a collection.",
795 return myLeaf->GetTypeName();
800 Error(
"TTreeReaderValueBase::GetBranchDataType()",
801 "The branch %s was created using a leaf list and cannot be represented as a C++ type. Please access one "
802 "of its siblings using a TTreeReaderArray:",
807 Error(
"TTreeReaderValueBase::GetBranchDataType()",
" %s.%s",
branch->GetName(),
leaf->GetName());
816 return "TClonesArray";
819 Error(
"TTreeReaderValueBase::GetBranchDataType()",
820 "The branch %s is a TBranchRef and cannot be represented as a C++ type.",
branch->GetName());
823 Error(
"TTreeReaderValueBase::GetBranchDataType()",
824 "The branch %s is of type %s - something that is not handled yet.",
branch->GetName(),
825 branch->IsA()->GetName());
836 if (std::find(fTreeReader->fMissingProxies.cbegin(), fTreeReader->fMissingProxies.cend(), fBranchName.Data()) ==
837 fTreeReader->fMissingProxies.cend())
838 Error(
"TTreeReaderValue::Get()",
"Value reader not properly initialized, did you call "
839 "TTreeReader::Set(Next)Entry() or TTreeReader::Next()?");
851 std::string str = cl->GetName();
852 str +=
" instance associated to column ";
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#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.
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.
void * GetAddress()
Returns the memory address of the object being read.
static std::string GetElementTypeName(const std::type_info &ti)
Stringify the template argument.
ROOT::Internal::TTreeReaderValueBase::EReadStatus ProxyReadTemplate()
Try to read the value from the TBranchProxy, returns the status of the read.
TTreeReaderValueBase & operator=(const TTreeReaderValueBase &)
Copy-assign.
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.
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.
A TTree is a list of TBranches.
TClass instances represent classes, structs and namespaces in the ROOT type system.
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.
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
const char * GetName() const override
Returns name of object.
Regular expression class.
Describes a persistent version of a class.
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.
A TTree represents a columnar dataset.
Abstract Interface class describing Streamer information for one class.
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.