56 const char* branchname ,
120 &&
"leafness disagreement");
122 &&
"static class offset disagreement");
142template <ROOT::Internal::TTreeReaderValueBase::BranchProxyRead_t Func>
161 EReadType readtype = EReadType::kNoDirector;
165 case EReadType::kNoDirector:
168 case EReadType::kReadParentNoCollection:
171 case EReadType::kReadParentCollectionNoPointer:
174 case EReadType::kReadParentCollectionPointer:
177 case EReadType::kReadNoParentNoBranchCountCollectionPointer:
180 case EReadType::kReadNoParentNoBranchCountCollectionNoPointer:
183 case EReadType::kReadNoParentNoBranchCountNoCollection:
186 case EReadType::kReadNoParentBranchCountCollectionPointer:
189 case EReadType::kReadNoParentBranchCountCollectionNoPointer:
192 case EReadType::kReadNoParentBranchCountNoCollection:
195 case EReadType::kDefault:
218 std::string ret = buf;
240 Error(
"TTreeReaderValueBase::GetLeaf()",
"Unable to get the branch from the tree");
246 Error(
"TTreeReaderValueBase::GetLeaf()",
"Failed to get the leaf from the branch");
258 return fLeaf->GetValuePointer();
262 Error(
"TTreeReaderValueBase::GetAddress()",
"Unable to get the leaf");
295 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
298 auto branch =
fTreeReader->GetTree()->GetBranch(branchName);
300 std::vector<TString> nameStack;
301 nameStack.push_back(
TString());
303 leafName = branchName(leafNameExpression);
304 branchName = branchName(0, branchName.
Length() - leafName.
Length());
306 branch =
fTreeReader->GetTree()->GetBranch(branchName);
307 if (!branch) branch =
fTreeReader->GetTree()->GetBranch(branchName +
".");
310 while (!branch && branchName.
Contains(
".")){
311 leafName = branchName(leafNameExpression);
312 branchName = branchName(0, branchName.
Length() - leafName.
Length());
313 branch =
fTreeReader->GetTree()->GetBranch(branchName);
314 if (!branch) branch =
fTreeReader->GetTree()->GetBranch(branchName +
".");
321 TString traversingBranch = nameStack.back();
322 nameStack.pop_back();
328 std::vector<Long64_t> offsets;
330 TClass *elementClass =
nullptr;
335 while (!nameStack.empty() && found){
342 if (!strcmp(tempStreamerElement->
GetName(), traversingBranch.
Data())){
345 traversingBranch = nameStack.back();
346 nameStack.pop_back();
348 elementClass = tempStreamerElement->
GetClass();
356 if (!finalDataType) {
365 offsets.push_back(
offset);
375 offsets.push_back(
offset);
381 if (
fDict != finalDataType &&
fDict != elementClass){
382 errMsg =
"Wrong data type ";
383 errMsg += finalDataType ? finalDataType->
GetName() : elementClass ? elementClass->
GetName() :
"UNKNOWN";
393 errMsg =
"The tree does not have a branch called ";
395 errMsg +=
". You could check with TTree::Print() for available branches.";
402 myLeaf = branch->GetLeaf(
TString(leafName(1, leafName.
Length())));
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.";
415 branchActualType =
fDict;
423 errMsg =
"Leaf of type ";
425 errMsg +=
" cannot be read by TTreeReaderValue<";
426 errMsg +=
fDict->GetName();
442 constexpr const char* errPrefix =
"TTreeReaderValueBase::CreateProxy()";
450 Error(errPrefix,
"TTreeReader object not set / available for branch %s!",
457 if (branchFromFullName ==
nullptr)
461 const char* brDataType =
"{UNDETERMINED}";
462 if (branchFromFullName) {
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.",
481 const std::string originalBranchName =
fBranchName.Data();
483 TLeaf *myLeaf =
nullptr;
504 branch = branchFromFullName;
513 branch = branchFromFullName;
518 if (errMsg.empty()) {
519 errMsg =
"The tree does not have a branch called ";
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"
527 Error(errPrefix, errMsg.c_str());
528#if !defined(_MSC_VER)
529#pragma GCC diagnostic pop
545 if (!branchActualType) {
546 Error(errPrefix,
"The branch %s contains data of type %s, which does not have a dictionary.",
547 fBranchName.Data(), branchActualTypeName ? branchActualTypeName :
"{UNDETERMINED TYPE}");
555 auto branchActualTypeAsClass =
dynamic_cast<TClass*
>(branchActualType);
556 auto inheritance = dictAsClass && branchActualTypeAsClass && branchActualTypeAsClass->
InheritsFrom(dictAsClass);
558 if (
fDict != branchActualType && !inheritance) {
562 TEnum *actualenum =
dynamic_cast<TEnum*
>(branchActualType);
563 bool complainAboutMismatch =
true;
564 if (dictdt && actualdt) {
567 complainAboutMismatch =
false;
572 complainAboutMismatch =
false;
574 }
else if ( (dictdt || dictenum) && (actualdt || actualenum) ) {
577 complainAboutMismatch =
false;
579 if (complainAboutMismatch) {
581 "The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
597 bool isTopLevel = branch->
GetMother() == branch;
599 membername = strrchr(branch->
GetName(),
'.');
600 if (membername.
IsNull()) {
601 membername = branch->
GetName();
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.",
625 const char *localBranchName = originalBranchName.c_str();
630 && localBranchName[
len] ==
'.'
632 localBranchName = localBranchName +
len + 1;
635 if (strncmp(localBranchName, fe_found->
GetName(),
len) == 0
636 && localBranchName[
len] ==
'.'
638 localBranchName = localBranchName +
len + 1;
653 namedProxy =
new TNamedBranchProxy(director, branch, originalBranchName.c_str(), membername);
683 auto ResolveTypedef = [&]() ->
void {
690 if (dict != curDict) {
693 if (dict != curDict) {
731 return "TClonesArray";
732 }
else if (brElement->
GetType() == 31
733 || brElement->
GetType() == 41) {
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());
752 if ((!dataTypeName || !dataTypeName[0])
765 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Must use TTreeReaderArray to read branch %s: it contains an array or a collection.", branch->
GetName());
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());
776 TLeaf* leaf =
nullptr;
777 while ((leaf = (
TLeaf*) iLeaves())) {
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.
TBranchProxyDirector * GetDirector()
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.
@ 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.
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
Setup status of this data access.
virtual const char * GetDerivedTypeName() const =0
TTreeReaderValueBase(TTreeReader *reader, const char *branchname, TDictionary *dict)
Construct a tree value reader and register it with the reader object.
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
TLeaf * GetLeaf()
If we are reading a leaf, return the corresponding TLeaf.
virtual ~TTreeReaderValueBase()
Unregister from tree reader, cleanup.
EReadStatus ProxyReadDefaultImpl()
virtual void CreateProxy()
Create the proxy object for our branch.
Detail::TBranchProxy * fProxy
Proxy for this branch, owned by TTreeReader.
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.
A TFriendElement TF describes a TTree object TF in a file.
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.
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
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
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
char * DemangleTypeIdName(const std::type_info &ti, int &errorCode)
Demangle in a portable way the type id name.