67 auto * cl =
dynamic_cast<TClass *
>(dict);
147template <ROOT::Internal::TTreeReaderValueBase::BranchProxyRead_t Func>
167 EReadType readtype = EReadType::kNoDirector;
169 readtype =
fProxy->GetReadType();
172 case EReadType::kNoDirector:
175 case EReadType::kReadParentNoCollection:
178 case EReadType::kReadParentCollectionNoPointer:
181 case EReadType::kReadParentCollectionPointer:
184 case EReadType::kReadNoParentNoBranchCountCollectionPointer:
188 case EReadType::kReadNoParentNoBranchCountCollectionNoPointer:
192 case EReadType::kReadNoParentNoBranchCountNoCollection:
195 case EReadType::kReadNoParentBranchCountCollectionPointer:
199 case EReadType::kReadNoParentBranchCountCollectionNoPointer:
203 case EReadType::kReadNoParentBranchCountNoCollection:
206 case EReadType::kDefault:
230 std::string
ret = buf;
253 Error(
"TTreeReaderValueBase::GetLeaf()",
"Unable to get the branch from the tree");
259 Error(
"TTreeReaderValueBase::GetLeaf()",
"Failed to get the leaf from the branch");
273 fProxy->fDirector->GetReadEntry() == -1)
281 return fLeaf->GetValuePointer();
284 Error(
"TTreeReaderValueBase::GetAddress()",
"Unable to get the leaf");
319 TRegexp leafNameExpression(
"\\.[a-zA-Z0-9_]+$");
324 std::vector<TString> nameStack;
325 nameStack.push_back(
TString());
348 TString traversingBranch = nameStack.back();
349 nameStack.pop_back();
355 std::vector<Long64_t> offsets;
357 TClass *elementClass =
nullptr;
362 while (!nameStack.empty() && found) {
365 for (
int i = 0; i < myObjArray->
GetEntries(); ++i) {
369 if (!strcmp(tempStreamerElement->
GetName(), traversingBranch.
Data())) {
372 traversingBranch = nameStack.back();
373 nameStack.pop_back();
375 elementClass = tempStreamerElement->
GetClass();
382 if (!finalDataType) {
391 offsets.push_back(offset);
401 offsets.push_back(offset);
407 if (
fDict != finalDataType &&
fDict != elementClass) {
408 errMsg =
"Wrong data type ";
409 errMsg += finalDataType ? finalDataType->
GetName() : elementClass ? elementClass->
GetName() :
"UNKNOWN";
418 errMsg =
"The tree does not have a branch called ";
420 errMsg +=
". You could check with TTree::Print() for available branches.";
426 myLeaf = branch->GetLeaf(
TString(leafName(1, leafName.
Length())));
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.";
438 branchActualType =
fDict;
445 errMsg =
"Leaf of type ";
447 errMsg +=
" cannot be read by TTreeReaderValue<";
448 errMsg +=
fDict->GetName();
465 constexpr const char *errPrefix =
"TTreeReaderValueBase::CreateProxy()";
473 Error(errPrefix,
"TTreeReader object not set / available for branch %s!",
fBranchName.Data());
479 if (branchFromFullName ==
nullptr)
484 const char *brDataType =
"{UNDETERMINED}";
485 if (branchFromFullName) {
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.",
498 if (branchFromFullName) {
513 const std::string originalBranchName =
fBranchName.Data();
515 TLeaf *myLeaf =
nullptr;
536 branch = branchFromFullName;
550 const auto &suppressErrorsForMissingBranches =
fTreeReader->fSuppressErrorsForMissingBranches;
551 const bool suppressErrorsForThisBranch =
552 (suppressErrorsForMissingBranches.find(originalBranchName) != suppressErrorsForMissingBranches.cend());
557 branch = branchFromFullName;
563 if (suppressErrorsForThisBranch)
569 if (errMsg.empty()) {
570 errMsg =
"The tree does not have a branch called ";
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"
578 Error(errPrefix, errMsg.c_str());
579#if !defined(_MSC_VER)
580#pragma GCC diagnostic pop
595 if (!branchActualType) {
596 Error(errPrefix,
"The branch %s contains data of type %s, which does not have a dictionary.",
597 fBranchName.Data(), branchActualTypeName ? branchActualTypeName :
"{UNDETERMINED TYPE}");
605 auto branchActualTypeAsClass =
dynamic_cast<TClass *
>(branchActualType);
606 auto inheritance = dictAsClass && branchActualTypeAsClass && branchActualTypeAsClass->
InheritsFrom(dictAsClass);
607 bool typeinfoMatch = dictAsClass && dictAsClass->GetTypeInfo() &&
608 dictAsClass->GetTypeInfo() == branchActualTypeAsClass->GetTypeInfo();
610 if (!inheritance && !typeinfoMatch &&
fDict != branchActualType) {
614 TEnum *actualenum =
dynamic_cast<TEnum *
>(branchActualType);
615 bool complainAboutMismatch =
true;
616 if (dictdt && actualdt) {
619 complainAboutMismatch =
false;
624 complainAboutMismatch =
false;
626 }
else if ((dictdt || dictenum) && (actualdt || actualenum)) {
629 complainAboutMismatch =
false;
632 complainAboutMismatch =
false;
634 if (complainAboutMismatch) {
635 Error(errPrefix,
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
650 bool isTopLevel = branch->
GetMother() == branch;
652 membername = strrchr(branch->
GetName(),
'.');
653 if (membername.
IsNull()) {
654 membername = branch->
GetName();
661 std::optional<std::size_t> index;
662 std::size_t current{};
663 auto &&friends =
fTreeReader->GetTree()->GetTree()->GetListOfFriends();
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.",
678 auto &&friendProxy =
fTreeReader->AddFriendProxy(index.value());
679 fTreeReader->AddProxy(std::make_unique<TNamedBranchProxy>(friendProxy.GetDirector(), branch,
680 originalBranchName.c_str(), branch->
GetName(),
681 membername, suppressErrorsForThisBranch));
683 fTreeReader->AddProxy(std::make_unique<TNamedBranchProxy>(director, branch, originalBranchName.c_str(),
684 membername, suppressErrorsForThisBranch));
686 namedProxy =
fTreeReader->FindProxy(originalBranchName.c_str());
719 auto ResolveTypedef = [&]() ->
void {
726 if (dict != curDict) {
729 if (dict != curDict) {
766 return "TClonesArray";
767 }
else if (brElement->
GetType() == 31 || brElement->
GetType() == 41) {
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",
799 Error(
"TTreeReaderValueBase::GetBranchDataType()",
800 "Must use TTreeReaderArray to read branch %s: it contains an array or a collection.",
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:",
815 TLeaf *leaf =
nullptr;
816 while ((leaf = (
TLeaf *)iLeaves())) {
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(),
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 ";
unsigned char Byte_t
Byte (8 bits) (unsigned char).
int Int_t
Signed integer 4 bytes (int).
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.
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Base class for all the proxy object.
void SetDict(TDictionary *dict)
const Detail::TBranchProxy * GetProxy() const
TDictionary * GetDict() const
Base class of TTreeReaderValue.
void RegisterWithTreeReader()
Register with tree reader.
@ kSetupInternalError
Some other error - hopefully the error message helps.
@ kSetupMissingBranch
The specified branch cannot be found.
@ kSetupMatchButEntryBeyondEnd
This branch has been setup, branch data type and reader template type match, but nothing can be read ...
@ kSetupMissingDictionary
To read this branch, we need a dictionary.
@ kSetupMismatch
Mismatch of branch type and reader template type.
@ kSetupTreeDestructed
The TTreeReader has been destructed / not set.
@ kSetupMatchLeaf
This branch (or TLeaf, really) has been set up, reading should succeed.
@ kSetupMatch
This branch has been set up, branch data type and reader template type match, reading should succeed.
Read_t fProxyReadFunc
! Pointer to the Read implementation to use.
bool fOpaqueRead
If true, the reader will not do any type-checking against the actual type held by the branch.
void NotifyNewTree(TTree *newTree)
The TTreeReader has switched to a new TTree. Update the leaf.
bool fHaveLeaf
Whether the data is in a leaf.
friend class ::TTreeReader
bool fHaveStaticClassOffsets
Whether !fStaticClassOffsets.empty().
void * GetAddress()
Returns the memory address of the object being read.
@ kReadError
Problem reading data.
@ kReadSuccess
Data read okay.
@ kReadNothingYet
Data now yet accessed.
static std::string GetElementTypeName(const std::type_info &ti)
Stringify the template argument.
ESetupStatus fSetupStatus
virtual const char * GetDerivedTypeName() const =0
TString fBranchName
Name of the branch to read data from.
ROOT::Internal::TTreeReaderValueBase::EReadStatus ProxyReadTemplate()
Try to read the value from the TBranchProxy, returns the status of the read.
TTreeReader * fTreeReader
Tree reader we belong to.
TDictionary * fDict
Type that the branch should contain.
TTreeReaderValueBase & operator=(const TTreeReaderValueBase &)
Copy-assign.
EReadStatus fReadStatus
Read status of this data access.
const char * GetBranchName() const
void ErrorAboutMissingProxyIfNeeded()
TLeaf * GetLeaf()
If we are reading a leaf, return the corresponding TLeaf.
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.
Detail::TBranchProxy * fProxy
std::vector< Long64_t > fStaticClassOffsets
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.
const char * GetClassName() const override
Return the name of the user class whose content is stored in this branch, if any.
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
TClass * GetCurrentClass()
Return a pointer to the current type of the data member corresponding to branch element.
virtual const char * GetTypeName() const
Return type name of element in the branch.
A TTree is a list of TBranches.
virtual TLeaf * GetLeaf(const char *name) const
Return pointer to the 1st Leaf named name in thisBranch.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
TClass * IsA() const override
virtual TLeaf * FindLeaf(const char *name)
Find the leaf corresponding to the name 'searchname'.
TObjArray * GetListOfLeaves()
TBranch * GetMother() const
Get our top-level parent branch in the tree.
TClass instances represent classes, structs and namespaces in the ROOT type system.
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0, Bool_t isTransient=kFALSE) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist,...
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
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.
EDataType GetUnderlyingType() const
Get the underlying integer type of the enum: enum E { kOne }; // ==> int enum F: long; // ==> long Re...
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual const char * GetTypeName() const
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
virtual Int_t GetLenStatic() const
Return the fixed length of this leaf.
const char * GetName() const override
Returns name of object.
Int_t GetEntries() const override
Return the number of objects in array (i.e.
TObject * At(Int_t idx) const override
Regular expression class.
Describe one element (data member) to be Streamed.
virtual Bool_t IsaPointer() const
const char * GetTypeName() const
TClass * GetClass() const
TClass * IsA() const override
Describes a persistent version of a class.
TObjArray * GetElements() const override
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
const char * Data() const
@ 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.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
virtual TTree * GetTree() const
TClass * IsA() const override
Abstract Interface class describing Streamer information for one class.
virtual TObjArray * GetElements() const =0
virtual Int_t GetElementOffset(Int_t id) const =0
bool HasEmulatedProxy(TClass *cl)
void PrintWriteStlWithoutProxyMsg(const char *where, const char *clName, const char *BranchName)
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.