47 Error(
"TClonesReader::GetCA()",
"Read error in TBranchProxy.");
76 Error(
"TSTLReader::GetCP()",
"Read error in TBranchProxy.");
80 Error(
"TSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
89 if (!myCollectionProxy)
return 0;
90 return myCollectionProxy->
Size();
95 if (!myCollectionProxy)
return 0;
97 return *(
void**)myCollectionProxy->
At(idx);
100 return myCollectionProxy->
At(idx);
112 if (!proxy->
Read()) {
114 Error(
"TCollectionLessSTLReader::GetCP()",
"Read error in TBranchProxy.");
118 Error(
"TCollectionLessSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
122 return fLocalCollection;
127 if (!myCollectionProxy)
return 0;
132 return myCollectionProxy->
Size();
137 if (!myCollectionProxy)
return 0;
144 return *(
void**)myCollectionProxy->
At(idx);
146 return myCollectionProxy->
At(idx);
156 Int_t fBasicTypeSize;
158 TObjectArrayReader() : fBasicTypeSize(-1) { }
159 ~TObjectArrayReader() {}
163 Error(
"TObjectArrayReader::GetCP()",
"Read error in TBranchProxy.");
171 if (!myCollectionProxy)
return 0;
172 return myCollectionProxy->
Size();
175 if (!proxy->
Read())
return 0;
178 void *array = (
void*)proxy->
GetStart();
180 if (fBasicTypeSize == -1){
183 Error(
"TObjectArrayReader::At()",
"Cannot get class info from branch proxy.");
189 objectSize = fBasicTypeSize;
191 return (
void*)((
Byte_t*)array + (objectSize * idx));
195 fBasicTypeSize =
size;
199 template <
class BASE>
200 class TUIntOrIntReader:
public BASE {
203 std::unique_ptr<TTreeReaderValueBase> fSizeReader;
204 bool fIsUnsigned =
false;
213 template <
class...
ARGS>
214 TUIntOrIntReader(
TTreeReader *treeReader,
const char *leafName,
218 std::string foundLeafName = leafName;
224 std::string leafNameNoParent = leafName;
226 auto posLastDot = leafNameNoParent.rfind(
'.');
227 if (posLastDot != leafNameNoParent.npos) {
228 parent = leafNameNoParent.substr(0, posLastDot);
229 leafNameNoParent.erase(0, posLastDot + 1);
233 if (!sizeLeaf && !parent.empty()) {
234 auto posLastDotParent = parent.rfind(
'.');
235 if (posLastDotParent != parent.npos)
236 parent = parent.substr(0, posLastDot);
241 foundLeafName = parent;
243 foundLeafName +=
".";
244 foundLeafName += leafNameNoParent;
246 }
while (!sizeLeaf && !parent.empty());
250 Error(
"TUIntOrIntReader",
"Cannot find leaf count for %s or any parent branch!", leafName);
264 return *GetSizeReader<UInt_t>();
265 return *GetSizeReader<Int_t>();
269 class TArrayParameterSizeReader:
public TUIntOrIntReader<TObjectArrayReader> {
271 TArrayParameterSizeReader(
TTreeReader *treeReader,
const char *branchName):
272 TUIntOrIntReader<TObjectArrayReader>(treeReader, branchName) {}
276 class TArrayFixedSizeReader :
public TObjectArrayReader {
281 TArrayFixedSizeReader(
Int_t sizeArg) :
fSize(sizeArg) {}
288 ~TBasicTypeArrayReader() {}
293 Error(
"TBasicTypeArrayReader::GetCP()",
"Read error in TBranchProxy.");
302 if (!myCollectionProxy)
return 0;
303 return myCollectionProxy->
Size();
308 if (!myCollectionProxy)
return 0;
313 class TBasicTypeClonesReader final:
public TClonesReader {
317 TBasicTypeClonesReader(
Int_t offsetArg) : fOffset(offsetArg) {}
321 if (!myClonesArray)
return 0;
322 return (
Byte_t*)myClonesArray->
At(idx) + fOffset;
331 TLeafReader(
TTreeReaderValueBase *valueReaderArg) : fValueReader(valueReaderArg), fElementSize(-1) {}
335 return myLeaf ? myLeaf->
GetLen() : 0;
341 if (fElementSize == -1){
343 if (!myLeaf)
return 0;
346 return (
Byte_t*)address + (fElementSize * idx);
355 class TLeafParameterSizeReader:
public TUIntOrIntReader<TLeafReader> {
357 TLeafParameterSizeReader(
TTreeReader *treeReader,
const char *leafName,
359 TUIntOrIntReader<TLeafReader>(treeReader, leafName, valueReaderArg) {}
363 return TUIntOrIntReader<TLeafReader>::GetSize(proxy);
381 fSetupStatus = kSetupInternalError;
383 Error(
"TTreeReaderArrayBase::CreateProxy()",
"TTreeReader object not set / available for branch %s!",
385 fSetupStatus = kSetupTreeDestructed;
390 const char* brDataType =
"{UNDETERMINED}";
393 brDataType = GetBranchDataType(br, dictUnused, fDict);
395 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.",
396 GetDerivedTypeName(), fBranchName.Data(), brDataType);
397 fSetupStatus = kSetupMissingDictionary;
408 TLeaf *myLeaf =
nullptr;
409 if (!GetBranchAndLeaf(branch, myLeaf, branchActualType))
413 Error(
"TTreeReaderArrayBase::CreateProxy()",
414 "No dictionary for branch %s.", fBranchName.Data());
421 fSetupStatus = kSetupMatch;
423 SetImpl(branch, myLeaf);
432 fSetupStatus = kSetupMatch;
434 Error(
"TTreeReaderArrayBase::CreateProxy()",
435 "Type ambiguity (want %s, have %s) for branch %s.",
442 bool isTopLevel = branch->
GetMother() == branch;
444 membername = strrchr(branch->
GetName(),
'.');
445 if (membername.
IsNull()) {
446 membername = branch->
GetName();
449 auto director = fTreeReader->fDirector;
462 Error(
"TTreeReaderArrayBase::CreateProxy()",
"The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
463 "This is not yet supported by TTreeReader.",
468 if ((
size_t)index < fTreeReader->fFriendProxies.size()) {
469 feproxy = fTreeReader->fFriendProxies.at(index);
473 fTreeReader->fFriendProxies.resize(index+1);
474 fTreeReader->fFriendProxies.at(index) = feproxy;
479 fTreeReader->AddProxy(namedProxy);
482 fSetupStatus = kSetupMatch;
484 fSetupStatus = kSetupMismatch;
489 const char* nonCollTypeName = GetBranchContentDataType(branch, branchActualTypeName, branchActualType);
490 if (nonCollTypeName) {
491 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which should be accessed through a TTreeReaderValue< %s >.",
492 fBranchName.Data(), nonCollTypeName, nonCollTypeName);
493 if (fSetupStatus == kSetupInternalError)
494 fSetupStatus = kSetupNotACollection;
498 if (!branchActualType) {
499 if (branchActualTypeName.
IsNull()) {
500 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"Cannot determine the type contained in the collection of branch %s. That's weird - please report!",
503 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which does not have a dictionary.",
504 fBranchName.Data(), branchActualTypeName.
Data());
505 if (fSetupStatus == kSetupInternalError)
506 fSetupStatus = kSetupMissingDictionary;
517 auto left_datatype =
dynamic_cast<TDataType *
>(left);
518 auto right_datatype =
dynamic_cast<TDataType *
>(right);
519 if (!left_datatype || !right_datatype)
522 auto r = right_datatype->GetType();
523 if (
l > 0 &&
l ==
r)
532 if (! matchingDataType(fDict, branchActualType)) {
533 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
534 fBranchName.Data(), branchActualType->
GetName(), fDict->GetName());
535 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
536 fSetupStatus = kSetupMismatch;
548 SetImpl(branch, myLeaf);
561 if (!fBranchName.Contains(
".")) {
562 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
563 fSetupStatus = kSetupMissingBranch;
568 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
569 TString leafName (fBranchName(leafNameExpression));
570 TString branchName = fBranchName(0, fBranchName.Length() - leafName.
Length());
573 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
574 fSetupStatus = kSetupMissingBranch;
581 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());
582 fSetupStatus = kSetupMissingBranch;
589 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Failed to get the dictionary for %s.", myLeaf->
GetTypeName());
590 fSetupStatus = kSetupMissingDictionary;
597 branchActualType = fDict;
599 fBranchName = branchName;
600 fLeafName = leafName(1, leafName.
Length());
601 fHaveLeaf = (fLeafName.Length() > 0);
602 fSetupStatus = kSetupMatchLeaf;
605 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->
GetTypeName(), fDict->GetName());
607 fSetupStatus = kSetupMismatch;
633 fImpl = std::make_unique<TLeafReader>(
this);
639 fImpl = std::make_unique<TLeafParameterSizeReader>(fTreeReader, leafFullName.
Data(),
this);
641 fSetupStatus = kSetupMatchLeaf;
643 else if (branch->IsA() == TBranchElement::Class()) {
655 if (fSetupStatus == kSetupInternalError)
656 fSetupStatus = kSetupMatch;
657 if (element->IsA() == TStreamerSTL::Class()){
658 fImpl = std::make_unique<TSTLReader>();
660 else if (element->IsA() == TStreamerObject::Class()){
663 if (element->
GetClass() == TClonesArray::Class()){
664 fImpl = std::make_unique<TClonesReader>();
667 fImpl = std::make_unique<TBasicTypeArrayReader>();
671 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
674 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
677 else if (element->IsA() == TStreamerLoop::Class()) {
678 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
680 else if (element->IsA() == TStreamerBasicType::Class()){
682 fImpl = std::make_unique<TBasicTypeArrayReader>();
685 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
688 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
689 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
692 else if (element->IsA() == TStreamerBasicPointer::Class()) {
693 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
694 ((TArrayParameterSizeReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
696 else if (element->IsA() == TStreamerBase::Class()){
697 fImpl = std::make_unique<TClonesReader>();
699 Error(
"TTreeReaderArrayBase::SetImpl()",
700 "Cannot read branch %s: unhandled streamer element type %s",
701 fBranchName.Data(), element->IsA()->
GetName());
702 fSetupStatus = kSetupInternalError;
710 }
else if (branch->IsA() == TBranch::Class()) {
713 Error(
"TTreeReaderArrayBase::SetImpl",
"Failed to get the top leaf from the branch");
714 fSetupStatus = kSetupMissingBranch;
719 if (fSetupStatus == kSetupInternalError)
720 fSetupStatus = kSetupMatch;
722 fImpl = std::make_unique<TArrayFixedSizeReader>(topLeaf->GetLenStatic());
725 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, sizeLeaf->
GetName());
727 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
728 }
else if (branch->IsA() == TBranchClones::Class()) {
729 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchClones not implemented");
730 fSetupStatus = kSetupInternalError;
731 }
else if (branch->IsA() == TBranchObject::Class()) {
732 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchObject not implemented");
733 fSetupStatus = kSetupInternalError;
734 }
else if (branch->IsA() == TBranchSTL::Class()) {
735 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchSTL not implemented");
736 fImpl = std::make_unique<TSTLReader>();
737 fSetupStatus = kSetupInternalError;
738 }
else if (branch->IsA() == TBranchRef::Class()) {
739 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchRef not implemented");
740 fSetupStatus = kSetupInternalError;
759 contentTypeName =
"";
760 if (branch->IsA() == TBranchElement::Class()) {
763 || brElement->
GetType() == 3) {
768 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Could not get value class.");
777 if (brElement->
GetType() == 3) {
786 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Cannot determine STL collection type of %s stored in branch %s", brElement->
GetClassName(), branch->
GetName());
791 if (isMap) contentTypeName =
"std::pair< ";
792 contentTypeName += splitType.
fElements[1];
794 contentTypeName += splitType.
fElements[2];
795 contentTypeName +=
" >";
800 }
else if (brElement->
GetType() == 31
801 || brElement->
GetType() == 41) {
806 if (ExpectedTypeRet == 0) {
818 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
819 branch->
GetName(), (
int)dtData);
824 }
else if (ExpectedTypeRet == 1) {
825 int brID = brElement->
GetID();
828 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
843 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
852 if (element->IsA() == TStreamerSTL::Class()){
855 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get class from branch element.");
859 if (!myCollectionProxy){
860 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get collection proxy from STL class");
868 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get valueClass from collectionProxy.");
871 contentTypeName = dict->
GetName();
874 else if (element->IsA() == TStreamerObject::Class() && !strcmp(element->
GetTypeName(),
"TClonesArray")){
875 if (!fProxy->Setup() || !fProxy->Read()){
876 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Failed to get type from proxy, unable to check type");
877 contentTypeName =
"UNKNOWN";
879 return contentTypeName;
883 contentTypeName = dict->
GetName();
897 contentTypeName =
"TClonesArray";
898 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
900 fSetupStatus = kSetupNoCheck;
907 if (dict) contentTypeName = dict->
GetName();
912 contentTypeName = dict->
GetName();
919 }
else if (branch->IsA() == TBranch::Class()
920 || branch->IsA() == TBranchObject::Class()
921 || branch->IsA() == TBranchSTL::Class()) {
923 if ((!dataTypeName || !dataTypeName[0])
924 && branch->IsA() == TBranch::Class()) {
928 if (myDataType && myDataType->IsA() == TDataType::Class()){
941 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());
944 while ((leaf = (
TLeaf*) iLeaves())) {
945 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
" %s.%s", branch->
GetName(), leaf->
GetName());
950 if (branch->IsA() == TBranchSTL::Class()){
951 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
953 fSetupStatus = kSetupNoCheck;
957 }
else if (branch->IsA() == TBranchClones::Class()) {
958 dict = TClonesArray::Class();
959 return "TClonesArray";
960 }
else if (branch->IsA() == TBranchRef::Class()) {
962 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
965 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is of type %s - something that is not handled yet.", branch->
GetName(), branch->IsA()->
GetName());
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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.
@ kReadError
Problem reading data.
@ kReadSuccess
Data read okay.
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
Regular expression class.
Int_t GetArrayLength() const
const char * GetTypeName() const
TClass * GetClass() const
Describes a persistent version of a class.
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