48 Error(
"TClonesReader::GetCA()",
"Read error in TBranchProxy.");
77 Error(
"TSTLReader::GetCP()",
"Read error in TBranchProxy.");
81 Error(
"TSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
90 if (!myCollectionProxy)
return 0;
91 return myCollectionProxy->
Size();
96 if (!myCollectionProxy)
return 0;
98 return *(
void**)myCollectionProxy->
At(idx);
101 return myCollectionProxy->
At(idx);
113 if (!proxy->
Read()) {
115 Error(
"TCollectionLessSTLReader::GetCP()",
"Read error in TBranchProxy.");
119 Error(
"TCollectionLessSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
123 return fLocalCollection;
128 if (!myCollectionProxy)
return 0;
133 return myCollectionProxy->
Size();
138 if (!myCollectionProxy)
return 0;
145 return *(
void**)myCollectionProxy->
At(idx);
147 return myCollectionProxy->
At(idx);
157 Int_t fBasicTypeSize;
159 TObjectArrayReader() : fBasicTypeSize(-1) { }
160 ~TObjectArrayReader() {}
164 Error(
"TObjectArrayReader::GetCP()",
"Read error in TBranchProxy.");
172 if (!myCollectionProxy)
return 0;
173 return myCollectionProxy->
Size();
176 if (!proxy->
Read())
return 0;
179 void *array = (
void*)proxy->
GetStart();
181 if (fBasicTypeSize == -1){
184 Error(
"TObjectArrayReader::At()",
"Cannot get class info from branch proxy.");
190 objectSize = fBasicTypeSize;
192 return (
void*)((
Byte_t*)array + (objectSize * idx));
195 void SetBasicTypeSize(
Int_t size){
196 fBasicTypeSize = size;
200 template <
class BASE>
201 class TUIntOrIntReader:
public BASE {
204 std::unique_ptr<TTreeReaderValueBase> fSizeReader;
205 bool fIsUnsigned =
false;
214 template <
class...
ARGS>
215 TUIntOrIntReader(
TTreeReader *treeReader,
const char *leafName,
219 std::string foundLeafName = leafName;
225 std::string leafNameNoParent = leafName;
227 auto posLastDot = leafNameNoParent.rfind(
'.');
228 if (posLastDot != leafNameNoParent.npos) {
229 parent = leafNameNoParent.substr(0, posLastDot);
230 leafNameNoParent.erase(0, posLastDot + 1);
234 if (!sizeLeaf && !parent.empty()) {
235 auto posLastDotParent = parent.rfind(
'.');
236 if (posLastDotParent != parent.npos)
237 parent = parent.substr(0, posLastDot);
242 foundLeafName = parent;
244 foundLeafName +=
".";
245 foundLeafName += leafNameNoParent;
247 }
while (!sizeLeaf && !parent.empty());
251 Error(
"TUIntOrIntReader",
"Cannot find leaf count for %s or any parent branch!", leafName);
265 return *GetSizeReader<UInt_t>();
266 return *GetSizeReader<Int_t>();
270 class TArrayParameterSizeReader:
public TUIntOrIntReader<TObjectArrayReader> {
272 TArrayParameterSizeReader(
TTreeReader *treeReader,
const char *branchName):
273 TUIntOrIntReader<TObjectArrayReader>(treeReader, branchName) {}
277 class TArrayFixedSizeReader :
public TObjectArrayReader {
282 TArrayFixedSizeReader(
Int_t sizeArg) :
fSize(sizeArg) {}
289 ~TBasicTypeArrayReader() {}
294 Error(
"TBasicTypeArrayReader::GetCP()",
"Read error in TBranchProxy.");
303 if (!myCollectionProxy)
return 0;
304 return myCollectionProxy->
Size();
309 if (!myCollectionProxy)
return 0;
314 class TBasicTypeClonesReader final:
public TClonesReader {
318 TBasicTypeClonesReader(
Int_t offsetArg) : fOffset(offsetArg) {}
322 if (!myClonesArray)
return 0;
323 return (
Byte_t*)myClonesArray->
At(idx) + fOffset;
332 TLeafReader(
TTreeReaderValueBase *valueReaderArg) : fValueReader(valueReaderArg), fElementSize(-1) {}
336 return myLeaf ? myLeaf->
GetLen() : 0;
342 if (fElementSize == -1){
344 if (!myLeaf)
return 0;
347 return (
Byte_t*)address + (fElementSize * idx);
356 class TLeafParameterSizeReader:
public TUIntOrIntReader<TLeafReader> {
358 TLeafParameterSizeReader(
TTreeReader *treeReader,
const char *leafName,
360 TUIntOrIntReader<TLeafReader>(treeReader, leafName, valueReaderArg) {}
364 return TUIntOrIntReader<TLeafReader>::GetSize(proxy);
382 fSetupStatus = kSetupInternalError;
384 Error(
"TTreeReaderArrayBase::CreateProxy()",
"TTreeReader object not set / available for branch %s!",
386 fSetupStatus = kSetupTreeDestructed;
391 const char* brDataType =
"{UNDETERMINED}";
394 brDataType = GetBranchDataType(br, dictUnused, fDict);
396 Error(
"TTreeReaderArrayBase::CreateProxy()",
"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.",
397 GetDerivedTypeName(), fBranchName.Data(), brDataType);
398 fSetupStatus = kSetupMissingDictionary;
409 TLeaf *myLeaf =
nullptr;
410 if (!GetBranchAndLeaf(branch, myLeaf, branchActualType))
414 Error(
"TTreeReaderArrayBase::CreateProxy()",
415 "No dictionary for branch %s.", fBranchName.Data());
422 fSetupStatus = kSetupMatch;
424 SetImpl(branch, myLeaf);
433 fSetupStatus = kSetupMatch;
435 Error(
"TTreeReaderArrayBase::CreateProxy()",
436 "Type ambiguity (want %s, have %s) for branch %s.",
443 bool isTopLevel = branch->
GetMother() == branch;
445 membername = strrchr(branch->
GetName(),
'.');
446 if (membername.
IsNull()) {
447 membername = branch->
GetName();
450 auto director = fTreeReader->fDirector;
463 Error(
"TTreeReaderArrayBase::CreateProxy()",
"The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
464 "This is not yet supported by TTreeReader.",
469 if ((
size_t)index < fTreeReader->fFriendProxies.size()) {
470 feproxy = fTreeReader->fFriendProxies.at(index);
474 fTreeReader->fFriendProxies.resize(index+1);
475 fTreeReader->fFriendProxies.at(index) = feproxy;
480 fTreeReader->AddProxy(namedProxy);
483 fSetupStatus = kSetupMatch;
485 fSetupStatus = kSetupMismatch;
490 const char* nonCollTypeName = GetBranchContentDataType(branch, branchActualTypeName, branchActualType);
491 if (nonCollTypeName) {
492 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which should be accessed through a TTreeReaderValue< %s >.",
493 fBranchName.Data(), nonCollTypeName, nonCollTypeName);
494 if (fSetupStatus == kSetupInternalError)
495 fSetupStatus = kSetupNotACollection;
499 if (!branchActualType) {
500 if (branchActualTypeName.
IsNull()) {
501 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"Cannot determine the type contained in the collection of branch %s. That's weird - please report!",
504 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which does not have a dictionary.",
505 fBranchName.Data(), branchActualTypeName.
Data());
506 if (fSetupStatus == kSetupInternalError)
507 fSetupStatus = kSetupMissingDictionary;
518 auto left_datatype =
dynamic_cast<TDataType *
>(left);
519 auto right_datatype =
dynamic_cast<TDataType *
>(right);
520 if (!left_datatype || !right_datatype)
523 auto r = right_datatype->GetType();
524 if (
l > 0 &&
l ==
r)
533 if (! matchingDataType(fDict, branchActualType)) {
534 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
535 fBranchName.Data(), branchActualType->
GetName(), fDict->GetName());
536 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
537 fSetupStatus = kSetupMismatch;
549 SetImpl(branch, myLeaf);
562 if (!fBranchName.Contains(
".")) {
563 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
564 fSetupStatus = kSetupMissingBranch;
569 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
570 TString leafName (fBranchName(leafNameExpression));
571 TString branchName = fBranchName(0, fBranchName.Length() - leafName.
Length());
574 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
575 fSetupStatus = kSetupMissingBranch;
582 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch, nor a sub-branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
583 fSetupStatus = kSetupMissingBranch;
590 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Failed to get the dictionary for %s.", myLeaf->
GetTypeName());
591 fSetupStatus = kSetupMissingDictionary;
598 branchActualType = fDict;
600 fBranchName = branchName;
601 fLeafName = leafName(1, leafName.
Length());
602 fHaveLeaf = (fLeafName.Length() > 0);
603 fSetupStatus = kSetupMatchLeaf;
606 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->
GetTypeName(), fDict->GetName());
608 fSetupStatus = kSetupMismatch;
634 fImpl = std::make_unique<TLeafReader>(
this);
640 fImpl = std::make_unique<TLeafParameterSizeReader>(fTreeReader, leafFullName.
Data(),
this);
642 fSetupStatus = kSetupMatchLeaf;
644 else if (branch->IsA() == TBranchElement::Class()) {
656 if (fSetupStatus == kSetupInternalError)
657 fSetupStatus = kSetupMatch;
658 if (element->IsA() == TStreamerSTL::Class()){
659 fImpl = std::make_unique<TSTLReader>();
661 else if (element->IsA() == TStreamerObject::Class()){
664 if (element->
GetClass() == TClonesArray::Class()){
665 fImpl = std::make_unique<TClonesReader>();
668 fImpl = std::make_unique<TBasicTypeArrayReader>();
672 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
675 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
678 else if (element->IsA() == TStreamerLoop::Class()) {
679 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
681 else if (element->IsA() == TStreamerBasicType::Class()){
683 fImpl = std::make_unique<TBasicTypeArrayReader>();
686 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
689 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
690 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
693 else if (element->IsA() == TStreamerBasicPointer::Class()) {
694 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
695 ((TArrayParameterSizeReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
697 else if (element->IsA() == TStreamerBase::Class()){
698 fImpl = std::make_unique<TClonesReader>();
700 Error(
"TTreeReaderArrayBase::SetImpl()",
701 "Cannot read branch %s: unhandled streamer element type %s",
702 fBranchName.Data(), element->IsA()->
GetName());
703 fSetupStatus = kSetupInternalError;
711 }
else if (branch->IsA() == TBranch::Class()) {
714 Error(
"TTreeReaderArrayBase::SetImpl",
"Failed to get the top leaf from the branch");
715 fSetupStatus = kSetupMissingBranch;
720 if (fSetupStatus == kSetupInternalError)
721 fSetupStatus = kSetupMatch;
723 fImpl = std::make_unique<TArrayFixedSizeReader>(topLeaf->GetLenStatic());
726 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, sizeLeaf->
GetName());
728 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
729 }
else if (branch->IsA() == TBranchClones::Class()) {
730 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchClones not implemented");
731 fSetupStatus = kSetupInternalError;
732 }
else if (branch->IsA() == TBranchObject::Class()) {
733 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchObject not implemented");
734 fSetupStatus = kSetupInternalError;
735 }
else if (branch->IsA() == TBranchSTL::Class()) {
736 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchSTL not implemented");
737 fImpl = std::make_unique<TSTLReader>();
738 fSetupStatus = kSetupInternalError;
739 }
else if (branch->IsA() == TBranchRef::Class()) {
740 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchRef not implemented");
741 fSetupStatus = kSetupInternalError;
760 contentTypeName =
"";
761 if (branch->IsA() == TBranchElement::Class()) {
764 || brElement->
GetType() == 3) {
769 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Could not get value class.");
778 if (brElement->
GetType() == 3) {
787 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Cannot determine STL collection type of %s stored in branch %s", brElement->
GetClassName(), branch->
GetName());
792 if (isMap) contentTypeName =
"std::pair< ";
793 contentTypeName += splitType.
fElements[1];
795 contentTypeName += splitType.
fElements[2];
796 contentTypeName +=
" >";
801 }
else if (brElement->
GetType() == 31
802 || brElement->
GetType() == 41) {
807 if (ExpectedTypeRet == 0) {
819 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
820 branch->
GetName(), (
int)dtData);
825 }
else if (ExpectedTypeRet == 1) {
826 int brID = brElement->
GetID();
829 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
844 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
853 if (element->IsA() == TStreamerSTL::Class()){
856 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get class from branch element.");
860 if (!myCollectionProxy){
861 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get collection proxy from STL class");
869 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get valueClass from collectionProxy.");
872 contentTypeName = dict->
GetName();
875 else if (element->IsA() == TStreamerObject::Class() && !strcmp(element->
GetTypeName(),
"TClonesArray")){
876 if (!fProxy->Setup() || !fProxy->Read()){
877 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Failed to get type from proxy, unable to check type");
878 contentTypeName =
"UNKNOWN";
880 return contentTypeName;
884 contentTypeName = dict->
GetName();
898 contentTypeName =
"TClonesArray";
899 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
901 fSetupStatus = kSetupNoCheck;
908 if (dict) contentTypeName = dict->
GetName();
913 contentTypeName = dict->
GetName();
920 }
else if (branch->IsA() == TBranch::Class()
921 || branch->IsA() == TBranchObject::Class()
922 || branch->IsA() == TBranchSTL::Class()) {
924 if ((!dataTypeName || !dataTypeName[0])
925 && branch->IsA() == TBranch::Class()) {
929 if (myDataType && myDataType->IsA() == TDataType::Class()){
942 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"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());
945 while ((leaf = (
TLeaf*) iLeaves())) {
946 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
" %s.%s", branch->
GetName(), leaf->
GetName());
951 if (branch->IsA() == TBranchSTL::Class()){
952 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
954 fSetupStatus = kSetupNoCheck;
958 }
else if (branch->IsA() == TBranchClones::Class()) {
959 dict = TClonesArray::Class();
960 return "TClonesArray";
961 }
else if (branch->IsA() == TBranchRef::Class()) {
963 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
966 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is of type %s - something that is not handled yet.", branch->
GetName(), branch->IsA()->
GetName());
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Base class for all the proxy object.
virtual void * GetStart(UInt_t=0)
TVirtualCollectionProxy * GetCollection()
TBranchProxyDirector * GetDirector()
const Detail::TBranchProxy * GetProxy() const
TDictionary * GetContentDict() const
void SetContentDict(TDictionary *dict)
Base class of TTreeReaderArray.
bool GetBranchAndLeaf(TBranch *&branch, TLeaf *&myLeaf, TDictionary *&branchActualType)
Determine the branch / leaf and its type; reset fProxy / fSetupStatus on error.
virtual void CreateProxy()
Create the proxy object for our branch.
void SetImpl(TBranch *branch, TLeaf *myLeaf)
Create the TVirtualCollectionReader object for our branch.
const char * GetBranchContentDataType(TBranch *branch, TString &contentTypeName, TDictionary *&dict)
Access a branch's collection content (not the collection itself) through a proxy.
Base class of TTreeReaderValue.
void * GetAddress()
Returns the memory address of the object being read.
TLeaf * GetLeaf()
If we are reading a leaf, return the corresponding TLeaf.
virtual ~TVirtualCollectionReader()
A Branch for the case of an object.
TBranchElement * GetBranchCount() const
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any.
virtual Int_t GetExpectedType(TClass *&clptr, EDataType &type)
Fill expectedClass and expectedType with information on the data type of the object/values contained ...
TVirtualCollectionProxy * GetCollectionProxy()
Return the collection proxy describing the branch content, if any.
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.
virtual const char * GetClonesName() const
virtual TClass * GetClass() const
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.
Int_t GetSplitLevel() const
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.
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
Int_t GetClassSize() const
An array of clone (identical) objects.
TClass * GetClass() const
Basic data type descriptor (datatype information is obtained from CINT).
TString GetTypeName()
Get basic type of typedef, e,g.: "class TDirectory*" -> "TDirectory".
static TDataType * GetDataType(EDataType type)
Given a EDataType type, get the TDataType* that represents it.
This class defines an abstract interface that must be implemented by all classes that contain diction...
static TDictionary * GetDictionary(const char *name)
Retrieve the type (class, fundamental type, typedef etc) named "name".
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
virtual Int_t GetLenType() const
virtual const char * GetTypeName() const
virtual Int_t GetLen() const
Return the number of effective elements of this leaf, for the current entry.
virtual TLeaf * GetLeafCount() const
If this leaf stores a variable-sized array or a multi-dimensional array whose last dimension has vari...
TBranch * GetBranch() const
virtual Bool_t IsUnsigned() const
virtual const char * GetName() const
Returns name of object.
Int_t GetEntries() const
Return the number of objects in array (i.e.
TObject * UncheckedAt(Int_t i) const
TObject * At(Int_t idx) const
TRangeDynCast is an adaptater class that allows the typed iteration through a TCollection.
Regular expression class.
Int_t GetArrayLength() const
const char * GetTypeName() const
TClass * GetClass() const
Describe Streamer information for one class version.
TObjArray * GetElements() const
TStreamerElement * GetElement(Int_t id) const
const char * Data() const
An interface for reading values stored in ROOT columnar datasets.
A simple, robust and fast interface to read values from ROOT columnar datasets such as TTree,...
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
virtual TLeaf * FindLeaf(const char *name)
Find leaf..
virtual void PushProxy(void *objectstart)=0
virtual EDataType GetType() const =0
virtual void PopProxy()=0
virtual TClass * GetValueClass() const =0
virtual void * At(UInt_t idx)=0
virtual UInt_t Size() const =0
virtual Bool_t HasPointers() const =0
void forward(const LAYERDATA &prevLayerData, LAYERDATA &currLayerData)
apply the weights (and functions) in forward direction of the DNN
int IsSTLCont(int testAlloc=0) const
type : type name: vector<list<classA,allocator>,allocator> testAlloc: if true, we test allocator,...
std::vector< std::string > fElements