59 fHaveStaticClassOffsets(
false),
60 fReadStatus(kReadNothingYet),
72 fHaveLeaf(
rhs.fHaveLeaf),
73 fHaveStaticClassOffsets(
rhs.fHaveStaticClassOffsets),
74 fReadStatus(
rhs.fReadStatus),
75 fSetupStatus(
rhs.fSetupStatus),
76 fBranchName(
rhs.fBranchName),
77 fLeafName(
rhs.fLeafName),
78 fTreeReader(
rhs.fTreeReader),
82 fStaticClassOffsets(
rhs.fStaticClassOffsets)
93 fHaveLeaf =
rhs.fHaveLeaf;
94 fHaveStaticClassOffsets =
rhs.fHaveStaticClassOffsets;
95 fBranchName =
rhs.fBranchName;
96 fLeafName =
rhs.fLeafName;
97 if (fTreeReader !=
rhs.fTreeReader) {
99 fTreeReader->DeregisterValueReader(
this);
100 fTreeReader =
rhs.fTreeReader;
101 RegisterWithTreeReader();
106 fSetupStatus =
rhs.fSetupStatus;
107 fReadStatus =
rhs.fReadStatus;
108 fStaticClassOffsets =
rhs.fStaticClassOffsets;
118 if (fTreeReader) fTreeReader->DeregisterValueReader(
this);
119 R__ASSERT((fLeafName.Length() == 0 ) == !fHaveLeaf
120 &&
"leafness disagreement");
121 R__ASSERT(fStaticClassOffsets.empty() == !fHaveStaticClassOffsets
122 &&
"static class offset disagreement");
130 if (!fTreeReader->RegisterValueReader(
this)) {
131 fTreeReader =
nullptr;
142template <ROOT::Internal::TTreeReaderValueBase::BranchProxyRead_t Func>
145 if ((fProxy->*Func)()) {
146 fReadStatus = kReadSuccess;
148 fReadStatus = kReadError;
155 if (!fProxy)
return kReadNothingYet;
156 if (fProxy->IsInitialized() || fProxy->Setup()) {
161 EReadType
readtype = EReadType::kNoDirector;
162 if (fProxy)
readtype = fProxy->GetReadType();
165 case EReadType::kNoDirector:
166 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoDirector>;
168 case EReadType::kReadParentNoCollection:
169 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentNoCollection>;
171 case EReadType::kReadParentCollectionNoPointer:
172 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentCollectionNoPointer>;
174 case EReadType::kReadParentCollectionPointer:
175 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadParentCollectionPointer>;
177 case EReadType::kReadNoParentNoBranchCountCollectionPointer:
178 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionPointer>;
180 case EReadType::kReadNoParentNoBranchCountCollectionNoPointer:
181 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionNoPointer>;
183 case EReadType::kReadNoParentNoBranchCountNoCollection:
184 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountNoCollection>;
186 case EReadType::kReadNoParentBranchCountCollectionPointer:
187 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionPointer>;
189 case EReadType::kReadNoParentBranchCountCollectionNoPointer:
190 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionNoPointer>;
192 case EReadType::kReadNoParentBranchCountNoCollection:
193 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountNoCollection>;
195 case EReadType::kDefault:
199 return (this->*fProxyReadFunc)();
205 if (fProxy->Read()) {
206 fReadStatus = kReadSuccess;
208 fReadStatus = kReadError;
218 std::string
ret = buf;
239 fReadStatus = kReadError;
240 Error(
"TTreeReaderValueBase::GetLeaf()",
"Unable to get the branch from the tree");
244 fLeaf =
myBranch->GetLeaf(fLeafName);
246 Error(
"TTreeReaderValueBase::GetLeaf()",
"Failed to get the leaf from the branch");
254 if (ProxyRead() != kReadSuccess)
return nullptr;
258 return fLeaf->GetValuePointer();
261 fReadStatus = kReadError;
262 Error(
"TTreeReaderValueBase::GetAddress()",
"Unable to get the leaf");
266 if (fHaveStaticClassOffsets){
269 for (
unsigned int i = 0; i < fStaticClassOffsets.size() - 1; ++i){
270 address = *(
Byte_t**)(address + fStaticClassOffsets[i]);
273 return address + fStaticClassOffsets.back();
275 return (
Byte_t*)fProxy->GetWhere();
328 std::vector<Long64_t> offsets;
338 for (
int i = 0; i <
myObjArray->GetEntries(); ++i){
365 offsets.push_back(
offset);
375 offsets.push_back(
offset);
378 fStaticClassOffsets = offsets;
379 fHaveStaticClassOffsets =
true;
382 errMsg =
"Wrong data type ";
384 fSetupStatus = kSetupMismatch;
392 if (!fHaveStaticClassOffsets) {
393 errMsg =
"The tree does not have a branch called ";
395 errMsg +=
". You could check with TTree::Print() for available branches.";
396 fSetupStatus = kSetupMissingBranch;
404 errMsg =
"The tree does not have a branch, nor a sub-branch called ";
406 errMsg +=
". You could check with TTree::Print() for available branches.";
407 fSetupStatus = kSetupMissingBranch;
419 fHaveLeaf = fLeafName.Length() > 0;
420 fSetupStatus = kSetupMatchLeaf;
425 errMsg +=
" cannot be read by TTreeReaderValue<";
428 fSetupStatus = kSetupMismatch;
442 constexpr const char*
errPrefix =
"TTreeReaderValueBase::CreateProxy()";
448 fSetupStatus = kSetupInternalError;
450 Error(
errPrefix,
"TTreeReader object not set / available for branch %s!",
452 fSetupStatus = kSetupTreeDestructed;
466 Error(
errPrefix,
"The template argument type T of %s accessing branch %s (which contains data of type %s) is not known to ROOT. You will need to create a dictionary for it.",
467 GetDerivedTypeName(), fBranchName.Data(),
brDataType);
468 fSetupStatus = kSetupMissingDictionary;
494 if (fBranchName.Contains(
".")) {
505 fStaticClassOffsets = {};
506 fHaveStaticClassOffsets =
false;
519 errMsg =
"The tree does not have a branch called ";
520 errMsg += fBranchName.Data();
521 errMsg +=
". You could check with TTree::Print() for available branches.";
523#if !defined(_MSC_VER)
524#pragma GCC diagnostic push
525#pragma GCC diagnostic ignored "-Wformat-security"
528#if !defined(_MSC_VER)
529#pragma GCC diagnostic pop
535 fSetupStatus = kSetupInternalError;
536 fStaticClassOffsets = {};
537 fHaveStaticClassOffsets =
false;
541 if (!
myLeaf && !fHaveStaticClassOffsets) {
546 Error(
errPrefix,
"The branch %s contains data of type %s, which does not have a dictionary.",
581 "The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
604 auto director = fTreeReader->fDirector;
606 if (
branch->GetTree() != fTreeReader->GetTree()->GetTree()) {
612 if (
branch->GetTree() ==
fe->GetTree()) {
620 Error(
errPrefix,
"The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
621 "This is not yet supported by TTreeReader.",
648 fTreeReader->fFriendProxies.resize(
index+1);
664 fSetupStatus = kSetupMatch;
666 fSetupStatus = kSetupMismatch;
683 auto ResolveTypedef = [&]() ->
void {
710 dict =
myStl->GetClass();
731 return "TClonesArray";
735 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Must use TTreeReaderArray to access a member of an object that is stored in a collection.");
741 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Unknown type and class combination: %i, %s",
brElement->GetType(),
brElement->GetClassName());
758 if (!
myLeaf &&
branch->GetListOfLeaves()->GetEntries() == 1) {
764 if (
myLeaf->GetLeafCount() !=
nullptr ||
myLeaf->GetLenStatic() > 1) {
765 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Must use TTreeReaderArray to read branch %s: it contains an array or a collection.",
branch->GetName());
769 return myLeaf->GetTypeName();
774 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"The branch %s was created using a leaf list and cannot be represented as a C++ type. Please access one of its siblings using a TTreeReaderArray:",
branch->GetName());
778 Error(
"TTreeReaderValueBase::GetBranchDataType()",
" %s.%s",
branch->GetName(),
leaf->GetName());
786 return "TClonesArray";
789 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.",
branch->GetName());
792 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"The branch %s is of type %s - something that is not handled yet.",
branch->GetName(),
branch->IsA()->GetName());
808 std::string str = cl->GetName();
809 str +=
" instance associated to column ";
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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
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 Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
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.
TTreeReaderValueBase(TTreeReader *reader, const char *branchname, TDictionary *dict)
Construct a tree value reader and register it with the reader object.
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
virtual ~TTreeReaderValueBase()
Unregister from tree reader, cleanup.
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 TFriendElement TF describes a TTree object TF in a file.
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,...
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.