46 Error(
"TClonesReader::GetCA()",
"Read error in TBranchProxy.");
75 Error(
"TSTLReader::GetCP()",
"Read error in TBranchProxy.");
79 Error(
"TSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
88 if (!myCollectionProxy)
return 0;
89 return myCollectionProxy->
Size();
94 if (!myCollectionProxy)
return 0;
96 return *(
void**)myCollectionProxy->
At(idx);
99 return myCollectionProxy->
At(idx);
111 if (!proxy->
Read()) {
113 Error(
"TCollectionLessSTLReader::GetCP()",
"Read error in TBranchProxy.");
117 Error(
"TCollectionLessSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
121 return fLocalCollection;
126 if (!myCollectionProxy)
return 0;
131 return myCollectionProxy->
Size();
136 if (!myCollectionProxy)
return 0;
143 return *(
void**)myCollectionProxy->
At(idx);
145 return myCollectionProxy->
At(idx);
155 Int_t fBasicTypeSize;
157 TObjectArrayReader() : fBasicTypeSize(-1) { }
158 ~TObjectArrayReader() {}
162 Error(
"TObjectArrayReader::GetCP()",
"Read error in TBranchProxy.");
170 if (!myCollectionProxy)
return 0;
171 return myCollectionProxy->
Size();
174 if (!proxy->
Read())
return 0;
177 void *array = (
void*)proxy->
GetStart();
179 if (fBasicTypeSize == -1){
182 Error(
"TObjectArrayReader::At()",
"Cannot get class info from branch proxy.");
188 objectSize = fBasicTypeSize;
190 return (
void*)((
Byte_t*)array + (objectSize * idx));
193 void SetBasicTypeSize(
Int_t size){
194 fBasicTypeSize = size;
198 template <
class BASE>
199 class TUIntOrIntReader:
public BASE {
202 std::unique_ptr<TTreeReaderValueBase> fSizeReader;
203 bool fIsUnsigned =
false;
212 template <
class...
ARGS>
213 TUIntOrIntReader(
TTreeReader *treeReader,
const char *leafName,
218 fIsUnsigned = sizeLeaf->IsUnsigned();
229 return *GetSizeReader<UInt_t>();
230 return *GetSizeReader<Int_t>();
234 class TArrayParameterSizeReader:
public TUIntOrIntReader<TObjectArrayReader> {
236 TArrayParameterSizeReader(
TTreeReader *treeReader,
const char *branchName):
237 TUIntOrIntReader<TObjectArrayReader>(treeReader, branchName) {}
241 class TArrayFixedSizeReader :
public TObjectArrayReader {
246 TArrayFixedSizeReader(
Int_t sizeArg) : fSize(sizeArg) {}
253 ~TBasicTypeArrayReader() {}
258 Error(
"TBasicTypeArrayReader::GetCP()",
"Read error in TBranchProxy.");
267 if (!myCollectionProxy)
return 0;
268 return myCollectionProxy->
Size();
273 if (!myCollectionProxy)
return 0;
278 class TBasicTypeClonesReader final:
public TClonesReader {
282 TBasicTypeClonesReader(
Int_t offsetArg) : fOffset(offsetArg) {}
286 if (!myClonesArray)
return 0;
287 return (
Byte_t*)myClonesArray->
At(idx) + fOffset;
296 TLeafReader(
TTreeReaderValueBase *valueReaderArg) : fValueReader(valueReaderArg), fElementSize(-1) {}
300 return myLeaf ? myLeaf->
GetLen() : 0;
306 if (fElementSize == -1){
308 if (!myLeaf)
return 0;
311 return (
Byte_t*)address + (fElementSize * idx);
320 class TLeafParameterSizeReader:
public TUIntOrIntReader<TLeafReader> {
322 TLeafParameterSizeReader(
TTreeReader *treeReader,
const char *leafName,
324 TUIntOrIntReader<TLeafReader>(treeReader, leafName, valueReaderArg) {}
328 return TUIntOrIntReader<TLeafReader>::GetSize(proxy);
346 fSetupStatus = kSetupInternalError;
348 Error(
"TTreeReaderArrayBase::CreateProxy()",
"TTreeReader object not set / available for branch %s!",
350 fSetupStatus = kSetupTreeDestructed;
355 const char* brDataType =
"{UNDETERMINED}";
358 brDataType = GetBranchDataType(br, dictUnused, fDict);
360 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.",
361 GetDerivedTypeName(), fBranchName.Data(), brDataType);
362 fSetupStatus = kSetupMissingDictionary;
373 TLeaf *myLeaf =
nullptr;
374 if (!GetBranchAndLeaf(branch, myLeaf, branchActualType))
378 Error(
"TTreeReaderArrayBase::CreateProxy()",
379 "No dictionary for branch %s.", fBranchName.Data());
386 fSetupStatus = kSetupMatch;
388 SetImpl(branch, myLeaf);
397 fSetupStatus = kSetupMatch;
399 Error(
"TTreeReaderArrayBase::CreateProxy()",
400 "Type ambiguity (want %s, have %s) for branch %s.",
407 bool isTopLevel = branch->
GetMother() == branch;
409 membername = strrchr(branch->
GetName(),
'.');
410 if (membername.
IsNull()) {
411 membername = branch->
GetName();
414 auto director = fTreeReader->fDirector;
427 Error(
"TTreeReaderArrayBase::CreateProxy()",
"The branch %s is contained in a Friend TTree that is not directly attached to the main.\n"
428 "This is not yet supported by TTreeReader.",
433 if ((
size_t)index < fTreeReader->fFriendProxies.size()) {
434 feproxy = fTreeReader->fFriendProxies.at(index);
438 fTreeReader->fFriendProxies.resize(index+1);
439 fTreeReader->fFriendProxies.at(index) = feproxy;
444 fTreeReader->AddProxy(namedProxy);
447 fSetupStatus = kSetupMatch;
449 fSetupStatus = kSetupMismatch;
454 const char* nonCollTypeName = GetBranchContentDataType(branch, branchActualTypeName, branchActualType);
455 if (nonCollTypeName) {
456 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which should be accessed through a TTreeReaderValue< %s >.",
457 fBranchName.Data(), nonCollTypeName, nonCollTypeName);
458 if (fSetupStatus == kSetupInternalError)
459 fSetupStatus = kSetupNotACollection;
463 if (!branchActualType) {
464 if (branchActualTypeName.
IsNull()) {
465 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"Cannot determine the type contained in the collection of branch %s. That's weird - please report!",
468 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which does not have a dictionary.",
469 fBranchName.Data(), branchActualTypeName.
Data());
470 if (fSetupStatus == kSetupInternalError)
471 fSetupStatus = kSetupMissingDictionary;
477 if (fDict != branchActualType) {
478 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
479 fBranchName.Data(), branchActualType->
GetName(), fDict->GetName());
480 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
481 fSetupStatus = kSetupMismatch;
493 SetImpl(branch, myLeaf);
506 if (!fBranchName.Contains(
".")) {
507 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
508 fSetupStatus = kSetupMissingBranch;
513 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
514 TString leafName (fBranchName(leafNameExpression));
515 TString branchName = fBranchName(0, fBranchName.Length() - leafName.
Length());
518 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
519 fSetupStatus = kSetupMissingBranch;
526 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());
527 fSetupStatus = kSetupMissingBranch;
534 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Failed to get the dictionary for %s.", myLeaf->
GetTypeName());
535 fSetupStatus = kSetupMissingDictionary;
542 branchActualType = fDict;
544 fBranchName = branchName;
545 fLeafName = leafName(1, leafName.
Length());
546 fHaveLeaf = (fLeafName.Length() > 0);
547 fSetupStatus = kSetupMatchLeaf;
550 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->
GetTypeName(), fDict->GetName());
552 fSetupStatus = kSetupMismatch;
578 fImpl = std::make_unique<TLeafReader>(
this);
584 fImpl = std::make_unique<TLeafParameterSizeReader>(fTreeReader, leafFullName.
Data(),
this);
586 fSetupStatus = kSetupMatchLeaf;
600 if (fSetupStatus == kSetupInternalError)
601 fSetupStatus = kSetupMatch;
603 fImpl = std::make_unique<TSTLReader>();
609 fImpl = std::make_unique<TClonesReader>();
612 fImpl = std::make_unique<TBasicTypeArrayReader>();
616 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
619 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
623 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
627 fImpl = std::make_unique<TBasicTypeArrayReader>();
630 fImpl = std::make_unique<TBasicTypeClonesReader>(element->
GetOffset());
633 fImpl = std::make_unique<TArrayFixedSizeReader>(element->
GetArrayLength());
634 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
638 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, branchElement->
GetBranchCount()->
GetName());
639 ((TArrayParameterSizeReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
642 fImpl = std::make_unique<TClonesReader>();
644 Error(
"TTreeReaderArrayBase::SetImpl()",
645 "Cannot read branch %s: unhandled streamer element type %s",
646 fBranchName.Data(), element->IsA()->
GetName());
647 fSetupStatus = kSetupInternalError;
658 Error(
"TTreeReaderArrayBase::SetImpl",
"Failed to get the top leaf from the branch");
659 fSetupStatus = kSetupMissingBranch;
663 auto sizeLeaf = topLeaf->GetLeafCount();
664 if (fSetupStatus == kSetupInternalError)
665 fSetupStatus = kSetupMatch;
667 fImpl = std::make_unique<TArrayFixedSizeReader>(topLeaf->GetLenStatic());
670 fImpl = std::make_unique<TArrayParameterSizeReader>(fTreeReader, sizeLeaf->GetName());
672 ((TObjectArrayReader*)fImpl.get())->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
674 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchClones not implemented");
675 fSetupStatus = kSetupInternalError;
677 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchObject not implemented");
678 fSetupStatus = kSetupInternalError;
680 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchSTL not implemented");
681 fImpl = std::make_unique<TSTLReader>();
682 fSetupStatus = kSetupInternalError;
684 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchRef not implemented");
685 fSetupStatus = kSetupInternalError;
704 contentTypeName =
"";
708 || brElement->
GetType() == 3) {
713 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Could not get value class.");
722 if (brElement->
GetType() == 3) {
731 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Cannot determine STL collection type of %s stored in branch %s", brElement->
GetClassName(), branch->
GetName());
736 if (isMap) contentTypeName =
"std::pair< ";
737 contentTypeName += splitType.
fElements[1];
739 contentTypeName += splitType.
fElements[2];
740 contentTypeName +=
" >";
745 }
else if (brElement->
GetType() == 31
746 || brElement->
GetType() == 41) {
751 if (ExpectedTypeRet == 0) {
757 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
758 branch->
GetName(), (
int)dtData);
763 }
else if (ExpectedTypeRet == 1) {
764 int brID = brElement->
GetID();
767 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
782 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
794 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get class from branch element.");
798 if (!myCollectionProxy){
799 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get collection proxy from STL class");
807 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get valueClass from collectionProxy.");
810 contentTypeName = dict->
GetName();
814 if (!fProxy->Setup() || !fProxy->Read()){
815 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Failed to get type from proxy, unable to check type");
816 contentTypeName =
"UNKNOWN";
818 return contentTypeName;
822 contentTypeName = dict->
GetName();
836 contentTypeName =
"TClonesArray";
837 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
839 fSetupStatus = kSetupNoCheck;
846 if (dict) contentTypeName = dict->
GetName();
851 contentTypeName = dict->
GetName();
862 if ((!dataTypeName || !dataTypeName[0])
880 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());
883 while ((leaf = (
TLeaf*) iLeaves())) {
884 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
" %s.%s", branch->
GetName(), leaf->
GetName());
890 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
892 fSetupStatus = kSetupNoCheck;
898 return "TClonesArray";
901 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
904 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 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