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 TDynamicArrayReader :
public BASE {
203 class TVirtualSizeReaderImpl {
205 virtual ~TVirtualSizeReaderImpl() =
default;
206 virtual size_t GetSize() = 0;
209 template <
typename T>
210 class TSizeReaderImpl final :
public TVirtualSizeReaderImpl {
214 TSizeReaderImpl(
TTreeReader &
r,
const char *leafName) : fSizeReader(
r, leafName) {}
215 size_t GetSize() final {
return *fSizeReader; }
218 std::unique_ptr<TVirtualSizeReaderImpl> fSizeReader;
221 template <
class...
ARGS>
222 TDynamicArrayReader(
TTreeReader *treeReader,
const char *leafName,
ARGS &&...args)
225 std::string foundLeafName = leafName;
231 std::string leafNameNoParent = leafName;
233 auto posLastDot = leafNameNoParent.rfind(
'.');
234 if (posLastDot != leafNameNoParent.npos) {
235 parent = leafNameNoParent.substr(0, posLastDot);
236 leafNameNoParent.erase(0, posLastDot + 1);
240 if (!sizeLeaf && !parent.empty()) {
241 auto posLastDotParent = parent.rfind(
'.');
242 if (posLastDotParent != parent.npos)
243 parent = parent.substr(0, posLastDot);
248 foundLeafName = parent;
250 foundLeafName +=
".";
251 foundLeafName += leafNameNoParent;
253 }
while (!sizeLeaf && !parent.empty());
257 Error(
"TDynamicArrayReader ",
"Cannot find leaf count for %s or any parent branch!", leafName);
261 const std::string leafType = sizeLeaf->
GetTypeName();
262 if (leafType ==
"Int_t") {
263 fSizeReader.reset(
new TSizeReaderImpl<Int_t>(*treeReader, foundLeafName.c_str()));
264 }
else if (leafType ==
"UInt_t") {
265 fSizeReader.reset(
new TSizeReaderImpl<UInt_t>(*treeReader, foundLeafName.c_str()));
266 }
else if (leafType ==
"Short_t") {
267 fSizeReader.reset(
new TSizeReaderImpl<Short_t>(*treeReader, foundLeafName.c_str()));
268 }
else if (leafType ==
"UShort_t") {
269 fSizeReader.reset(
new TSizeReaderImpl<UShort_t>(*treeReader, foundLeafName.c_str()));
270 }
else if (leafType ==
"Long_t") {
271 fSizeReader.reset(
new TSizeReaderImpl<Long_t>(*treeReader, foundLeafName.c_str()));
272 }
else if (leafType ==
"ULong_t") {
273 fSizeReader.reset(
new TSizeReaderImpl<ULong_t>(*treeReader, foundLeafName.c_str()));
274 }
else if (leafType ==
"Long64_t") {
275 fSizeReader.reset(
new TSizeReaderImpl<Long64_t>(*treeReader, foundLeafName.c_str()));
276 }
else if (leafType ==
"ULong64_t") {
277 fSizeReader.reset(
new TSizeReaderImpl<ULong64_t>(*treeReader, foundLeafName.c_str()));
279 Error(
"TDynamicArrayReader ",
280 "Unsupported size type for leaf %s. Supported types are int, short int, long int, long long int and "
281 "their unsigned counterparts.",
289 class TArrayParameterSizeReader :
public TDynamicArrayReader<TObjectArrayReader> {
291 TArrayParameterSizeReader(
TTreeReader *treeReader,
const char *branchName)
292 : TDynamicArrayReader<TObjectArrayReader>(treeReader, branchName)
298 class TArrayFixedSizeReader :
public TObjectArrayReader {
303 TArrayFixedSizeReader(
Int_t sizeArg) :
fSize(sizeArg) {}
310 ~TBasicTypeArrayReader() {}
315 Error(
"TBasicTypeArrayReader::GetCP()",
"Read error in TBranchProxy.");
324 if (!myCollectionProxy)
return 0;
325 return myCollectionProxy->
Size();
330 if (!myCollectionProxy)
return 0;
335 class TBasicTypeClonesReader final:
public TClonesReader {
339 TBasicTypeClonesReader(
Int_t offsetArg) : fOffset(offsetArg) {}
343 if (!myClonesArray)
return 0;
344 return (
Byte_t*)myClonesArray->
At(idx) + fOffset;
353 TLeafReader(
TTreeReaderValueBase *valueReaderArg) : fValueReader(valueReaderArg), fElementSize(-1) {}
357 return myLeaf ? myLeaf->
GetLen() : 0;
363 if (fElementSize == -1){
365 if (!myLeaf)
return 0;
368 return (
Byte_t*)address + (fElementSize * idx);
377 class TLeafParameterSizeReader :
public TDynamicArrayReader<TLeafReader> {
380 : TDynamicArrayReader<TLeafReader>(treeReader, leafName, valueReaderArg)
386 return TDynamicArrayReader<TLeafReader>::GetSize(proxy);
404 fSetupStatus = kSetupInternalError;
406 Error(
"TTreeReaderArrayBase::CreateProxy()",
"TTreeReader object not set / available for branch %s!",
408 fSetupStatus = kSetupTreeDestructed;
413 const char* brDataType =
"{UNDETERMINED}";
416 brDataType = GetBranchDataType(br, dictUnused, fDict);
418 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.",
419 GetDerivedTypeName(), fBranchName.Data(), brDataType);
420 fSetupStatus = kSetupMissingDictionary;
431 TLeaf *myLeaf =
nullptr;
432 if (!GetBranchAndLeaf(branch, myLeaf, branchActualType))
436 Error(
"TTreeReaderArrayBase::CreateProxy()",
437 "No dictionary for branch %s.", fBranchName.Data());
444 fSetupStatus = kSetupMatch;
446 SetImpl(branch, myLeaf);
455 fSetupStatus = kSetupMatch;
457 Error(
"TTreeReaderArrayBase::CreateProxy()",
458 "Type ambiguity (want %s, have %s) for branch %s.",
465 bool isTopLevel = branch->
GetMother() == branch;
467 membername = strrchr(branch->
GetName(),
'.');
468 if (membername.
IsNull()) {
469 membername = branch->
GetName();
472 auto director = fTreeReader->fDirector;
485 Error(
"TTreeReaderArrayBase::CreateProxy()",
"The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
486 "This is not yet supported by TTreeReader.",
491 if ((
size_t)index < fTreeReader->fFriendProxies.size()) {
492 feproxy = fTreeReader->fFriendProxies.at(
index);
496 fTreeReader->fFriendProxies.resize(
index+1);
497 fTreeReader->fFriendProxies.at(
index) = feproxy;
502 fTreeReader->AddProxy(namedProxy);
505 fSetupStatus = kSetupMatch;
507 fSetupStatus = kSetupMismatch;
512 const char* nonCollTypeName = GetBranchContentDataType(branch, branchActualTypeName, branchActualType);
513 if (nonCollTypeName) {
514 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which should be accessed through a TTreeReaderValue< %s >.",
515 fBranchName.Data(), nonCollTypeName, nonCollTypeName);
516 if (fSetupStatus == kSetupInternalError)
517 fSetupStatus = kSetupNotACollection;
521 if (!branchActualType) {
522 if (branchActualTypeName.
IsNull()) {
523 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"Cannot determine the type contained in the collection of branch %s. That's weird - please report!",
526 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which does not have a dictionary.",
527 fBranchName.Data(), branchActualTypeName.
Data());
528 if (fSetupStatus == kSetupInternalError)
529 fSetupStatus = kSetupMissingDictionary;
540 auto left_datatype =
dynamic_cast<TDataType *
>(left);
541 auto right_datatype =
dynamic_cast<TDataType *
>(right);
542 if (!left_datatype || !right_datatype)
544 auto l = left_datatype->GetType();
545 auto r = right_datatype->GetType();
546 if (
l > 0 &&
l ==
r)
555 if (! matchingDataType(fDict, branchActualType)) {
556 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
557 fBranchName.Data(), branchActualType->
GetName(), fDict->GetName());
558 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
559 fSetupStatus = kSetupMismatch;
571 SetImpl(branch, myLeaf);
584 if (!fBranchName.Contains(
".")) {
585 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
586 fSetupStatus = kSetupMissingBranch;
591 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
592 TString leafName (fBranchName(leafNameExpression));
593 TString branchName = fBranchName(0, fBranchName.Length() - leafName.
Length());
596 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
597 fSetupStatus = kSetupMissingBranch;
604 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());
605 fSetupStatus = kSetupMissingBranch;
612 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Failed to get the dictionary for %s.", myLeaf->
GetTypeName());
613 fSetupStatus = kSetupMissingDictionary;
620 branchActualType = fDict;
622 fBranchName = branchName;
623 fLeafName = leafName(1, leafName.
Length());
624 fHaveLeaf = (fLeafName.Length() > 0);
625 fSetupStatus = kSetupMatchLeaf;
628 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->
GetTypeName(), fDict->GetName());
630 fSetupStatus = kSetupMismatch;
656 fImpl = std::make_unique<TLeafReader>(
this);
662 fImpl = std::make_unique<TLeafParameterSizeReader>(fTreeReader, leafFullName.
Data(),
this);
664 fSetupStatus = kSetupMatchLeaf;
678 if (fSetupStatus == kSetupInternalError)
679 fSetupStatus = kSetupMatch;
681 if (branchElement->
GetType() == 31) {
682 Error(
"TTreeReaderArrayBase::SetImpl",
683 "STL Collection nested in a TClonesArray not yet supported");
684 fSetupStatus = kSetupInternalError;
687 fImpl = std::make_unique<TSTLReader>();
693 fImpl = std::make_unique<TClonesReader>();
696 fImpl = std::make_unique<TBasicTypeArrayReader>();
700 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
703 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
707 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
711 fImpl = std::make_unique<TBasicTypeArrayReader>();
714 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
717 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
718 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
722 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
723 ((TArrayParameterSizeReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
726 fImpl = std::make_unique<TClonesReader>();
728 Error(
"TTreeReaderArrayBase::SetImpl()",
729 "Cannot read branch %s: unhandled streamer element type %s",
730 fBranchName.Data(), element->
IsA()->
GetName());
731 fSetupStatus = kSetupInternalError;
742 Error(
"TTreeReaderArrayBase::SetImpl",
"Failed to get the top leaf from the branch");
743 fSetupStatus = kSetupMissingBranch;
748 if (fSetupStatus == kSetupInternalError)
749 fSetupStatus = kSetupMatch;
751 fImpl = std::make_unique<TArrayFixedSizeReader>(topLeaf->GetLenStatic());
754 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, sizeLeaf->
GetName());
756 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->Size());
758 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchClones not implemented");
759 fSetupStatus = kSetupInternalError;
761 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchObject not implemented");
762 fSetupStatus = kSetupInternalError;
764 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchSTL not implemented");
765 fImpl = std::make_unique<TSTLReader>();
766 fSetupStatus = kSetupInternalError;
768 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchRef not implemented");
769 fSetupStatus = kSetupInternalError;
788 contentTypeName =
"";
792 || brElement->
GetType() == 3) {
797 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Could not get value class.");
806 if (brElement->
GetType() == 3) {
815 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Cannot determine STL collection type of %s stored in branch %s", brElement->
GetClassName(), branch->
GetName());
820 if (isMap) contentTypeName =
"std::pair< ";
821 contentTypeName += splitType.
fElements[1];
823 contentTypeName += splitType.
fElements[2];
824 contentTypeName +=
" >";
829 }
else if (brElement->
GetType() == 31
830 || brElement->
GetType() == 41) {
835 if (ExpectedTypeRet == 0) {
847 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
848 branch->
GetName(), (
int)dtData);
853 }
else if (ExpectedTypeRet == 1) {
854 int brID = brElement->
GetID();
857 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
872 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
884 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get class from branch element.");
888 if (!myCollectionProxy){
889 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get collection proxy from STL class");
897 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get valueClass from collectionProxy.");
900 contentTypeName = dict->
GetName();
904 if (!fProxy->Setup() || !fProxy->Read()){
905 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Failed to get type from proxy, unable to check type");
906 contentTypeName =
"UNKNOWN";
908 return contentTypeName;
912 contentTypeName = dict->
GetName();
926 contentTypeName =
"TClonesArray";
927 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
929 fSetupStatus = kSetupNoCheck;
936 if (dict) contentTypeName = dict->
GetName();
941 contentTypeName = dict->
GetName();
952 if ((!dataTypeName || !dataTypeName[0])
970 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());
973 while ((leaf = (
TLeaf*) iLeaves())) {
974 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
" %s.%s", branch->
GetName(), leaf->
GetName());
980 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
982 fSetupStatus = kSetupNoCheck;
988 return "TClonesArray";
991 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
994 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.
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 r
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
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
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.
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
Int_t GetExpectedType(TClass *&clptr, EDataType &type) override
Fill expectedClass and expectedType with information on the data type of the object/values contained ...
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
TClass * IsA() const override
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...
TClass * IsA() const override
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
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
TObject * UncheckedAt(Int_t i) const
Regular expression class.
Int_t GetArrayLength() const
const char * GetTypeName() const
TClass * GetClass() const
TClass * IsA() const override
Describes a persistent version of a class.
TStreamerElement * GetElement(Int_t id) const override
TObjArray * GetElements() const override
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