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));
194 void SetBasicTypeSize(
Int_t size){
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;
512 if (fDict != branchActualType) {
513 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
514 fBranchName.Data(), branchActualType->
GetName(), fDict->GetName());
515 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
516 fSetupStatus = kSetupMismatch;
528 SetImpl(branch, myLeaf);
541 if (!fBranchName.Contains(
".")) {
542 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
543 fSetupStatus = kSetupMissingBranch;
548 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
549 TString leafName (fBranchName(leafNameExpression));
550 TString branchName = fBranchName(0, fBranchName.Length() - leafName.
Length());
553 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
554 fSetupStatus = kSetupMissingBranch;
561 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());
562 fSetupStatus = kSetupMissingBranch;
569 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Failed to get the dictionary for %s.", myLeaf->
GetTypeName());
570 fSetupStatus = kSetupMissingDictionary;
577 branchActualType = fDict;
579 fBranchName = branchName;
580 fLeafName = leafName(1, leafName.
Length());
581 fHaveLeaf = (fLeafName.Length() > 0);
582 fSetupStatus = kSetupMatchLeaf;
585 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->
GetTypeName(), fDict->GetName());
587 fSetupStatus = kSetupMismatch;
613 fImpl = std::make_unique<TLeafReader>(
this);
619 fImpl = std::make_unique<TLeafParameterSizeReader>(fTreeReader, leafFullName.
Data(),
this);
621 fSetupStatus = kSetupMatchLeaf;
635 if (fSetupStatus == kSetupInternalError)
636 fSetupStatus = kSetupMatch;
638 fImpl = std::make_unique<TSTLReader>();
644 fImpl = std::make_unique<TClonesReader>();
647 fImpl = std::make_unique<TBasicTypeArrayReader>();
651 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
654 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
658 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
662 fImpl = std::make_unique<TBasicTypeArrayReader>();
665 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
668 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
669 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
673 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
674 ((TArrayParameterSizeReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
677 fImpl = std::make_unique<TClonesReader>();
679 Error(
"TTreeReaderArrayBase::SetImpl()",
680 "Cannot read branch %s: unhandled streamer element type %s",
681 fBranchName.Data(), element->IsA()->
GetName());
682 fSetupStatus = kSetupInternalError;
693 Error(
"TTreeReaderArrayBase::SetImpl",
"Failed to get the top leaf from the branch");
694 fSetupStatus = kSetupMissingBranch;
699 if (fSetupStatus == kSetupInternalError)
700 fSetupStatus = kSetupMatch;
702 fImpl = std::make_unique<TArrayFixedSizeReader>(topLeaf->GetLenStatic());
705 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, sizeLeaf->
GetName());
707 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
709 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchClones not implemented");
710 fSetupStatus = kSetupInternalError;
712 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchObject not implemented");
713 fSetupStatus = kSetupInternalError;
715 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchSTL not implemented");
716 fImpl = std::make_unique<TSTLReader>();
717 fSetupStatus = kSetupInternalError;
719 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchRef not implemented");
720 fSetupStatus = kSetupInternalError;
739 contentTypeName =
"";
743 || brElement->
GetType() == 3) {
748 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Could not get value class.");
757 if (brElement->
GetType() == 3) {
766 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Cannot determine STL collection type of %s stored in branch %s", brElement->
GetClassName(), branch->
GetName());
771 if (isMap) contentTypeName =
"std::pair< ";
772 contentTypeName += splitType.
fElements[1];
774 contentTypeName += splitType.
fElements[2];
775 contentTypeName +=
" >";
780 }
else if (brElement->
GetType() == 31
781 || brElement->
GetType() == 41) {
786 if (ExpectedTypeRet == 0) {
792 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
793 branch->
GetName(), (
int)dtData);
798 }
else if (ExpectedTypeRet == 1) {
799 int brID = brElement->
GetID();
802 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
817 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
829 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get class from branch element.");
833 if (!myCollectionProxy){
834 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get collection proxy from STL class");
842 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get valueClass from collectionProxy.");
845 contentTypeName = dict->
GetName();
849 if (!fProxy->Setup() || !fProxy->Read()){
850 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Failed to get type from proxy, unable to check type");
851 contentTypeName =
"UNKNOWN";
853 return contentTypeName;
857 contentTypeName = dict->
GetName();
871 contentTypeName =
"TClonesArray";
872 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
874 fSetupStatus = kSetupNoCheck;
881 if (dict) contentTypeName = dict->
GetName();
886 contentTypeName = dict->
GetName();
897 if ((!dataTypeName || !dataTypeName[0])
915 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());
918 while ((leaf = (
TLeaf*) iLeaves())) {
919 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
" %s.%s", branch->
GetName(), leaf->
GetName());
925 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
927 fSetupStatus = kSetupNoCheck;
933 return "TClonesArray";
936 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
939 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,...)
void Warning(const char *location, const char *msgfmt,...)
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.
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)
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
Type GetType(const std::string &Name)
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