59 fHaveStaticClassOffsets(
false),
60 fReadStatus(kReadNothingYet),
73 : fHaveLeaf(
rhs.fHaveLeaf),
74 fHaveStaticClassOffsets(
rhs.fHaveStaticClassOffsets),
75 fReadStatus(
rhs.fReadStatus),
76 fSetupStatus(
rhs.fSetupStatus),
77 fBranchName(
rhs.fBranchName),
78 fLeafName(
rhs.fLeafName),
79 fTreeReader(
rhs.fTreeReader),
83 fStaticClassOffsets(
rhs.fStaticClassOffsets)
94 fHaveLeaf =
rhs.fHaveLeaf;
95 fHaveStaticClassOffsets =
rhs.fHaveStaticClassOffsets;
96 fBranchName =
rhs.fBranchName;
97 fLeafName =
rhs.fLeafName;
98 if (fTreeReader !=
rhs.fTreeReader) {
100 fTreeReader->DeregisterValueReader(
this);
101 fTreeReader =
rhs.fTreeReader;
102 RegisterWithTreeReader();
107 fSetupStatus =
rhs.fSetupStatus;
108 fReadStatus =
rhs.fReadStatus;
109 fStaticClassOffsets =
rhs.fStaticClassOffsets;
120 fTreeReader->DeregisterValueReader(
this);
121 R__ASSERT((fLeafName.Length() == 0) == !fHaveLeaf &&
"leafness disagreement");
122 R__ASSERT(fStaticClassOffsets.empty() == !fHaveStaticClassOffsets &&
"static class offset disagreement");
131 if (!fTreeReader->RegisterValueReader(
this)) {
132 fTreeReader =
nullptr;
141template <ROOT::Internal::TTreeReaderValueBase::BranchProxyRead_t Func>
144 if ((fProxy->*Func)()) {
145 fReadStatus = kReadSuccess;
147 fReadStatus = kReadError;
155 return kReadNothingYet;
156 if (fProxy->IsInitialized() || fProxy->Setup()) {
161 EReadType
readtype = EReadType::kNoDirector;
166 case EReadType::kNoDirector:
167 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoDirector>;
169 case EReadType::kReadParentNoCollection:
170 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentNoCollection>;
172 case EReadType::kReadParentCollectionNoPointer:
173 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentCollectionNoPointer>;
175 case EReadType::kReadParentCollectionPointer:
176 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentCollectionPointer>;
178 case EReadType::kReadNoParentNoBranchCountCollectionPointer:
180 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionPointer>;
182 case EReadType::kReadNoParentNoBranchCountCollectionNoPointer:
184 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionNoPointer>;
186 case EReadType::kReadNoParentNoBranchCountNoCollection:
187 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountNoCollection>;
189 case EReadType::kReadNoParentBranchCountCollectionPointer:
191 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionPointer>;
193 case EReadType::kReadNoParentBranchCountCollectionNoPointer:
195 &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionNoPointer>;
197 case EReadType::kReadNoParentBranchCountNoCollection:
198 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountNoCollection>;
200 case EReadType::kDefault:
204 return (this->*fProxyReadFunc)();
210 if (fProxy->Read()) {
211 fReadStatus = kReadSuccess;
213 fReadStatus = kReadError;
224 std::string
ret = buf;
246 fReadStatus = kReadError;
247 Error(
"TTreeReaderValueBase::GetLeaf()",
"Unable to get the branch from the tree");
251 fLeaf =
myBranch->GetLeaf(fLeafName);
253 Error(
"TTreeReaderValueBase::GetLeaf()",
"Failed to get the leaf from the branch");
267 fProxy->fDirector->GetReadEntry() == -1)
270 if (ProxyRead() != kReadSuccess)
275 return fLeaf->GetValuePointer();
277 fReadStatus = kReadError;
278 Error(
"TTreeReaderValueBase::GetAddress()",
"Unable to get the leaf");
282 if (fHaveStaticClassOffsets) {
285 for (
unsigned int i = 0; i < fStaticClassOffsets.size() - 1; ++i) {
286 address = *(
Byte_t **)(address + fStaticClassOffsets[i]);
289 return address + fStaticClassOffsets.back();
291 return (
Byte_t *)fProxy->GetWhere();
349 std::vector<Long64_t> offsets;
359 for (
int i = 0; i <
myObjArray->GetEntries(); ++i) {
385 offsets.push_back(
offset);
395 offsets.push_back(
offset);
398 fStaticClassOffsets = offsets;
399 fHaveStaticClassOffsets =
true;
402 errMsg =
"Wrong data type ";
404 fSetupStatus = kSetupMismatch;
411 if (!fHaveStaticClassOffsets) {
412 errMsg =
"The tree does not have a branch called ";
414 errMsg +=
". You could check with TTree::Print() for available branches.";
415 fSetupStatus = kSetupMissingBranch;
422 errMsg =
"The tree does not have a branch, nor a sub-branch called ";
424 errMsg +=
". You could check with TTree::Print() for available branches.";
425 fSetupStatus = kSetupMissingBranch;
436 fHaveLeaf = fLeafName.Length() > 0;
437 fSetupStatus = kSetupMatchLeaf;
441 errMsg +=
" cannot be read by TTreeReaderValue<";
444 fSetupStatus = kSetupMismatch;
459 constexpr const char *
errPrefix =
"TTreeReaderValueBase::CreateProxy()";
465 fSetupStatus = kSetupInternalError;
467 Error(
errPrefix,
"TTreeReader object not set / available for branch %s!", fBranchName.Data());
468 fSetupStatus = kSetupTreeDestructed;
484 "The template argument type T of %s accessing branch %s (which contains data of type %s) is not known "
485 "to ROOT. You will need to create a dictionary for it.",
486 GetDerivedTypeName(), fBranchName.Data(),
brDataType);
487 fSetupStatus = kSetupMissingDictionary;
520 if (fBranchName.Contains(
".")) {
531 fStaticClassOffsets = {};
532 fHaveStaticClassOffsets =
false;
555 fSetupStatus = kSetupMissingBranch;
564 errMsg =
"The tree does not have a branch called ";
565 errMsg += fBranchName.Data();
566 errMsg +=
". You could check with TTree::Print() for available branches.";
568#if !defined(_MSC_VER)
569#pragma GCC diagnostic push
570#pragma GCC diagnostic ignored "-Wformat-security"
573#if !defined(_MSC_VER)
574#pragma GCC diagnostic pop
580 fSetupStatus = kSetupInternalError;
581 fStaticClassOffsets = {};
582 fHaveStaticClassOffsets =
false;
585 if (!
myLeaf && !fHaveStaticClassOffsets) {
590 Error(
errPrefix,
"The branch %s contains data of type %s, which does not have a dictionary.",
629 Error(
errPrefix,
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
651 auto director = fTreeReader->fDirector.get();
653 if (
branch->GetTree() != fTreeReader->GetTree()->GetTree()) {
655 std::optional<std::size_t>
index;
656 std::size_t current{};
657 auto &&
friends = fTreeReader->GetTree()->GetTree()->GetListOfFriends();
659 if (
branch->GetTree() ==
fe->GetTree()) {
665 if (!
index.has_value()) {
667 "The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
668 "This is not yet supported by TTreeReader.",
673 fTreeReader->AddProxy(std::make_unique<TNamedBranchProxy>(
friendProxy.GetDirector(),
branch,
693 fSetupStatus = kSetupMatchButEntryBeyondEnd;
695 fSetupStatus = kSetupMatch;
697 fSetupStatus = kSetupMismatch;
713 auto ResolveTypedef = [&]() ->
void {
739 dict =
myStl->GetClass();
760 return "TClonesArray";
763 Error(
"TTreeReaderValueBase::GetBranchDataType()",
764 "Must use TTreeReaderArray to access a member of an object that is stored in a collection.");
770 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Unknown type and class combination: %i, %s",
786 if (!
myLeaf &&
branch->GetListOfLeaves()->GetEntries() == 1) {
792 if (
myLeaf->GetLeafCount() !=
nullptr ||
myLeaf->GetLenStatic() > 1) {
793 Error(
"TTreeReaderValueBase::GetBranchDataType()",
794 "Must use TTreeReaderArray to read branch %s: it contains an array or a collection.",
799 return myLeaf->GetTypeName();
804 Error(
"TTreeReaderValueBase::GetBranchDataType()",
805 "The branch %s was created using a leaf list and cannot be represented as a C++ type. Please access one "
806 "of its siblings using a TTreeReaderArray:",
811 Error(
"TTreeReaderValueBase::GetBranchDataType()",
" %s.%s",
branch->GetName(),
leaf->GetName());
820 return "TClonesArray";
823 Error(
"TTreeReaderValueBase::GetBranchDataType()",
824 "The branch %s is a TBranchRef and cannot be represented as a C++ type.",
branch->GetName());
827 Error(
"TTreeReaderValueBase::GetBranchDataType()",
828 "The branch %s is of type %s - something that is not handled yet.",
branch->GetName(),
829 branch->IsA()->GetName());
840 if (!fTreeReader || fTreeReader->fMissingProxies.count(fBranchName.Data()) == 0)
841 Error(
"TTreeReaderValue::Get()",
842 "Value reader for branch %s not properly initialized, did you call "
843 "TTreeReader::Set(Next)Entry() or TTreeReader::Next()?",
856 std::string str = cl->GetName();
857 str +=
" instance associated to column ";
long long Long64_t
Portable signed long integer 8 bytes.
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.
Describe one element (data member) to be Streamed.
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.
@ kEntryBeyondEnd
last entry loop has reached its end
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.