60 fHaveStaticClassOffsets(
false),
61 fReadStatus(kReadNothingYet),
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)
100 fHaveLeaf =
rhs.fHaveLeaf;
101 fHaveStaticClassOffsets =
rhs.fHaveStaticClassOffsets;
102 fBranchName =
rhs.fBranchName;
103 fLeafName =
rhs.fLeafName;
104 if (fTreeReader !=
rhs.fTreeReader) {
106 fTreeReader->DeregisterValueReader(
this);
107 fTreeReader =
rhs.fTreeReader;
108 RegisterWithTreeReader();
113 fSetupStatus =
rhs.fSetupStatus;
114 fReadStatus =
rhs.fReadStatus;
115 fStaticClassOffsets =
rhs.fStaticClassOffsets;
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;
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();
321 TString branchName = fBranchName(0, fBranchName.Length() -
leafName.Length());
322 auto branch = fTreeReader->GetTree()->GetBranch(branchName);
328 branchName = branchName(0, branchName.
Length() -
leafName.Length());
330 branch = fTreeReader->GetTree()->GetBranch(branchName);
332 branch = fTreeReader->GetTree()->GetBranch(branchName +
".");
338 branchName = branchName(0, branchName.
Length() -
leafName.Length());
339 branch = fTreeReader->GetTree()->GetBranch(branchName);
341 branch = fTreeReader->GetTree()->GetBranch(branchName +
".");
355 std::vector<Long64_t> offsets;
365 for (
int i = 0; i <
myObjArray->GetEntries(); ++i) {
391 offsets.push_back(
offset);
401 offsets.push_back(
offset);
404 fStaticClassOffsets = offsets;
405 fHaveStaticClassOffsets =
true;
408 errMsg =
"Wrong data type ";
410 fSetupStatus = kSetupMismatch;
417 if (!fHaveStaticClassOffsets) {
418 errMsg =
"The tree does not have a branch called ";
420 errMsg +=
". You could check with TTree::Print() for available branches.";
421 fSetupStatus = kSetupMissingBranch;
428 errMsg =
"The tree does not have a branch, nor a sub-branch called ";
430 errMsg +=
". You could check with TTree::Print() for available branches.";
431 fSetupStatus = kSetupMissingBranch;
440 fBranchName = branchName;
442 fHaveLeaf = fLeafName.Length() > 0;
443 fSetupStatus = kSetupMatchLeaf;
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;
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;
526 if (fBranchName.Contains(
".")) {
537 fStaticClassOffsets = {};
538 fHaveStaticClassOffsets =
false;
561 fSetupStatus = kSetupMissingBranch;
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"
579#if !defined(_MSC_VER)
580#pragma GCC diagnostic pop
586 fSetupStatus = kSetupInternalError;
587 fStaticClassOffsets = {};
588 fHaveStaticClassOffsets =
false;
591 if (!
myLeaf && !fHaveStaticClassOffsets) {
596 Error(
errPrefix,
"The branch %s contains data of type %s, which does not have a dictionary.",
635 Error(
errPrefix,
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
657 auto director = fTreeReader->fDirector.get();
659 if (
branch->GetTree() != fTreeReader->GetTree()->GetTree()) {
661 std::optional<std::size_t>
index;
662 std::size_t current{};
663 auto &&
friends = fTreeReader->GetTree()->GetTree()->GetListOfFriends();
665 if (
branch->GetTree() ==
fe->GetTree()) {
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.",
679 fTreeReader->AddProxy(std::make_unique<TNamedBranchProxy>(
friendProxy.GetDirector(),
branch,
699 fSetupStatus = kSetupMatchButEntryBeyondEnd;
701 fSetupStatus = kSetupMatch;
703 fSetupStatus = kSetupMismatch;
719 auto ResolveTypedef = [&]() ->
void {
745 dict =
myStl->GetClass();
766 return "TClonesArray";
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",
792 if (!
myLeaf &&
branch->GetListOfLeaves()->GetEntries() == 1) {
798 if (
myLeaf->GetLeafCount() !=
nullptr ||
myLeaf->GetLenStatic() > 1) {
799 Error(
"TTreeReaderValueBase::GetBranchDataType()",
800 "Must use TTreeReaderArray to read branch %s: it contains an array or a collection.",
805 return myLeaf->GetTypeName();
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:",
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(),
835 branch->IsA()->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 ";
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.
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.
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.