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;
120 if (fTreeReader) fTreeReader->DeregisterValueReader(
this);
121 R__ASSERT((fLeafName.Length() == 0 ) == !fHaveLeaf
122 &&
"leafness disagreement");
123 R__ASSERT(fStaticClassOffsets.empty() == !fHaveStaticClassOffsets
124 &&
"static class offset disagreement");
132 if (!fTreeReader->RegisterValueReader(
this)) {
133 fTreeReader =
nullptr;
144template <ROOT::Internal::TTreeReaderValueBase::BranchProxyRead_t Func>
147 if ((fProxy->*Func)()) {
148 fReadStatus = kReadSuccess;
150 fReadStatus = kReadError;
157 if (!fProxy)
return kReadNothingYet;
158 if (fProxy->IsInitialized() || fProxy->Setup()) {
163 EReadType
readtype = EReadType::kNoDirector;
164 if (fProxy)
readtype = fProxy->GetReadType();
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:
180 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionPointer>;
182 case EReadType::kReadNoParentNoBranchCountCollectionNoPointer:
183 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountCollectionNoPointer>;
185 case EReadType::kReadNoParentNoBranchCountNoCollection:
186 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentNoBranchCountNoCollection>;
188 case EReadType::kReadNoParentBranchCountCollectionPointer:
189 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionPointer>;
191 case EReadType::kReadNoParentBranchCountCollectionNoPointer:
192 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountCollectionNoPointer>;
194 case EReadType::kReadNoParentBranchCountNoCollection:
195 fProxyReadFunc = &TTreeReaderValueBase::ProxyReadTemplate<&TBranchPoxy::ReadNoParentBranchCountNoCollection>;
197 case EReadType::kDefault:
201 return (this->*fProxyReadFunc)();
207 if (fProxy->Read()) {
208 fReadStatus = kReadSuccess;
210 fReadStatus = kReadError;
220 std::string
ret = buf;
241 fReadStatus = kReadError;
242 Error(
"TTreeReaderValueBase::GetLeaf()",
"Unable to get the branch from the tree");
246 fLeaf =
myBranch->GetLeaf(fLeafName);
248 Error(
"TTreeReaderValueBase::GetLeaf()",
"Failed to get the leaf from the branch");
261 fProxy->fDirector->GetReadEntry() == -1)
264 if (ProxyRead() != kReadSuccess)
return nullptr;
268 return fLeaf->GetValuePointer();
271 fReadStatus = kReadError;
272 Error(
"TTreeReaderValueBase::GetAddress()",
"Unable to get the leaf");
276 if (fHaveStaticClassOffsets){
279 for (
unsigned int i = 0; i < fStaticClassOffsets.size() - 1; ++i){
280 address = *(
Byte_t**)(address + fStaticClassOffsets[i]);
283 return address + fStaticClassOffsets.back();
285 return (
Byte_t*)fProxy->GetWhere();
338 std::vector<Long64_t> offsets;
348 for (
int i = 0; i <
myObjArray->GetEntries(); ++i){
375 offsets.push_back(
offset);
385 offsets.push_back(
offset);
388 fStaticClassOffsets = offsets;
389 fHaveStaticClassOffsets =
true;
392 errMsg =
"Wrong data type ";
394 fSetupStatus = kSetupMismatch;
402 if (!fHaveStaticClassOffsets) {
403 errMsg =
"The tree does not have a branch called ";
405 errMsg +=
". You could check with TTree::Print() for available branches.";
406 fSetupStatus = kSetupMissingBranch;
414 errMsg =
"The tree does not have a branch, nor a sub-branch called ";
416 errMsg +=
". You could check with TTree::Print() for available branches.";
417 fSetupStatus = kSetupMissingBranch;
429 fHaveLeaf = fLeafName.Length() > 0;
430 fSetupStatus = kSetupMatchLeaf;
435 errMsg +=
" cannot be read by TTreeReaderValue<";
438 fSetupStatus = kSetupMismatch;
452 constexpr const char*
errPrefix =
"TTreeReaderValueBase::CreateProxy()";
458 fSetupStatus = kSetupInternalError;
460 Error(
errPrefix,
"TTreeReader object not set / available for branch %s!",
462 fSetupStatus = kSetupTreeDestructed;
478 "The template argument type T of %s accessing branch %s (which contains data of type %s) is not known "
479 "to ROOT. You will need to create a dictionary for it.",
480 GetDerivedTypeName(), fBranchName.Data(),
brDataType);
481 fSetupStatus = kSetupMissingDictionary;
514 if (fBranchName.Contains(
".")) {
525 fStaticClassOffsets = {};
526 fHaveStaticClassOffsets =
false;
550 fSetupStatus = kSetupMissingBranch;
559 errMsg =
"The tree does not have a branch called ";
560 errMsg += fBranchName.Data();
561 errMsg +=
". You could check with TTree::Print() for available branches.";
563#if !defined(_MSC_VER)
564#pragma GCC diagnostic push
565#pragma GCC diagnostic ignored "-Wformat-security"
568#if !defined(_MSC_VER)
569#pragma GCC diagnostic pop
575 fSetupStatus = kSetupInternalError;
576 fStaticClassOffsets = {};
577 fHaveStaticClassOffsets =
false;
580 if (!
myLeaf && !fHaveStaticClassOffsets) {
585 Error(
errPrefix,
"The branch %s contains data of type %s, which does not have a dictionary.",
621 "The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
644 auto director = fTreeReader->fDirector.get();
646 if (
branch->GetTree() != fTreeReader->GetTree()->GetTree()) {
648 std::optional<std::size_t>
index;
649 std::size_t current{};
650 auto &&
friends = fTreeReader->GetTree()->GetTree()->GetListOfFriends();
652 if (
branch->GetTree() ==
fe->GetTree()) {
658 if (!
index.has_value()) {
660 "The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
661 "This is not yet supported by TTreeReader.",
666 fTreeReader->AddProxy(std::make_unique<TNamedBranchProxy>(
friendProxy.GetDirector(),
branch,
682 fSetupStatus = kSetupMatch;
684 fSetupStatus = kSetupMismatch;
701 auto ResolveTypedef = [&]() ->
void {
728 dict =
myStl->GetClass();
749 return "TClonesArray";
753 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Must use TTreeReaderArray to access a member of an object that is stored in a collection.");
759 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Unknown type and class combination: %i, %s",
brElement->GetType(),
brElement->GetClassName());
776 if (!
myLeaf &&
branch->GetListOfLeaves()->GetEntries() == 1) {
782 if (
myLeaf->GetLeafCount() !=
nullptr ||
myLeaf->GetLenStatic() > 1) {
783 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Must use TTreeReaderArray to read branch %s: it contains an array or a collection.",
branch->GetName());
787 return myLeaf->GetTypeName();
792 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());
796 Error(
"TTreeReaderValueBase::GetBranchDataType()",
" %s.%s",
branch->GetName(),
leaf->GetName());
804 return "TClonesArray";
807 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.",
branch->GetName());
810 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"The branch %s is of type %s - something that is not handled yet.",
branch->GetName(),
branch->IsA()->GetName());
821 if (std::find(fTreeReader->fMissingProxies.cbegin(), fTreeReader->fMissingProxies.cend(), fBranchName.Data()) ==
822 fTreeReader->fMissingProxies.cend())
823 Error(
"TTreeReaderValue::Get()",
"Value reader not properly initialized, did you call "
824 "TTreeReader::Set(Next)Entry() or TTreeReader::Next()?");
836 std::string str = cl->GetName();
837 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.