41 Error(
"TClonesReader::GetCA()",
"Read error in TBranchProxy.");
70 Error(
"TSTLReader::GetCP()",
"Read error in TBranchProxy.");
74 Error(
"TSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
83 if (!myCollectionProxy)
return 0;
84 return myCollectionProxy->
Size();
89 if (!myCollectionProxy)
return 0;
91 return *(
void**)myCollectionProxy->
At(idx);
94 return myCollectionProxy->
At(idx);
106 if (!proxy->
Read()) {
108 Error(
"TCollectionLessSTLReader::GetCP()",
"Read error in TBranchProxy.");
112 Error(
"TCollectionLessSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
116 return fLocalCollection;
121 if (!myCollectionProxy)
return 0;
123 return myCollectionProxy->
Size();
128 if (!myCollectionProxy)
return 0;
131 return *(
void**)myCollectionProxy->
At(idx);
133 return myCollectionProxy->
At(idx);
143 Int_t fBasicTypeSize;
145 TObjectArrayReader() : fBasicTypeSize(-1) { }
146 ~TObjectArrayReader() {}
150 Error(
"TObjectArrayReader::GetCP()",
"Read error in TBranchProxy.");
158 if (!myCollectionProxy)
return 0;
159 return myCollectionProxy->
Size();
162 if (!proxy->
Read())
return 0;
165 void *array = (
void*)proxy->
GetStart();
167 if (fBasicTypeSize == -1){
170 Error(
"TObjectArrayReader::At()",
"Cannot get class info from branch proxy.");
176 objectSize = fBasicTypeSize;
178 return (
void*)((
Byte_t*)array + (objectSize * idx));
181 void SetBasicTypeSize(
Int_t size){
182 fBasicTypeSize = size;
186 class TArrayParameterSizeReader :
public TObjectArrayReader {
190 bool fIsUnsigned =
false;
199 if (
TLeaf* sizeLeaf = treeReader->
GetTree()->FindLeaf(branchName)) {
200 fIsUnsigned = sizeLeaf->IsUnsigned();
211 return *GetIndexReader<UInt_t>();
212 return *GetIndexReader<Int_t>();
217 class TArrayFixedSizeReader :
public TObjectArrayReader {
222 TArrayFixedSizeReader(
Int_t sizeArg) : fSize(sizeArg) {}
229 ~TBasicTypeArrayReader() {}
234 Error(
"TBasicTypeArrayReader::GetCP()",
"Read error in TBranchProxy.");
243 if (!myCollectionProxy)
return 0;
244 return myCollectionProxy->
Size();
249 if (!myCollectionProxy)
return 0;
254 class TBasicTypeClonesReader :
public TClonesReader {
258 TBasicTypeClonesReader(
Int_t offsetArg) : fOffset(offsetArg) {}
262 if (!myClonesArray)
return 0;
263 return (
Byte_t*)myClonesArray->
At(idx) + fOffset;
272 TLeafReader(
TTreeReaderValueBase *valueReaderArg) : fValueReader(valueReaderArg), fElementSize(-1) {}
276 return myLeaf ? myLeaf->
GetLen() : 0;
282 if (fElementSize == -1){
284 if (!myLeaf)
return 0;
287 return (
Byte_t*)address + (fElementSize * idx);
296 class TLeafParameterSizeReader :
public TLeafReader {
301 TLeafReader(valueReaderArg), fSizeReader(*treeReader, leafName) {}
326 fSetupStatus = kSetupInternalError;
328 Error(
"TTreeReaderArrayBase::CreateProxy()",
"TTreeReader object not set / available for branch %s!",
330 fSetupStatus = kSetupTreeDestructed;
335 const char* brDataType =
"{UNDETERMINED}";
338 brDataType = GetBranchDataType(br, dictUnused);
340 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.",
341 GetDerivedTypeName(), fBranchName.Data(), brDataType);
342 fSetupStatus = kSetupMissingDictionary;
353 TLeaf *myLeaf =
nullptr;
354 if (!GetBranchAndLeaf(branch, myLeaf, branchActualType))
358 Error(
"TTreeReaderArrayBase::CreateProxy()",
359 "No dictionary for branch %s.", fBranchName.Data());
366 fSetupStatus = kSetupMatch;
368 SetImpl(branch, myLeaf);
377 fSetupStatus = kSetupMatch;
379 Error(
"TTreeReaderArrayBase::CreateProxy()",
380 "Type ambiguity (want %s, have %s) for branch %s.",
387 bool isTopLevel = branch->
GetMother() == branch;
389 membername = strrchr(branch->
GetName(),
'.');
390 if (membername.IsNull()) {
391 membername = branch->
GetName();
395 fTreeReader->GetProxies()->Add(namedProxy);
398 fSetupStatus = kSetupMatch;
400 fSetupStatus = kSetupMismatch;
404 TString branchActualTypeName;
405 const char* nonCollTypeName = GetBranchContentDataType(branch, branchActualTypeName, branchActualType);
406 if (nonCollTypeName) {
407 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which should be accessed through a TTreeReaderValue< %s >.",
408 fBranchName.Data(), nonCollTypeName, nonCollTypeName);
409 if (fSetupStatus == kSetupInternalError)
410 fSetupStatus = kSetupNotACollection;
414 if (!branchActualType) {
415 if (branchActualTypeName.IsNull()) {
416 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"Cannot determine the type contained in the collection of branch %s. That's weird - please report!",
419 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which does not have a dictionary.",
420 fBranchName.Data(), branchActualTypeName.Data());
421 if (fSetupStatus == kSetupInternalError)
422 fSetupStatus = kSetupMissingDictionary;
428 if (fDict != branchActualType) {
429 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
430 fBranchName.Data(), branchActualType->
GetName(), fDict->GetName());
431 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
432 fSetupStatus = kSetupMismatch;
444 SetImpl(branch, myLeaf);
453 branch = fTreeReader->
GetTree()->GetBranch(fBranchName);
457 if (!fBranchName.Contains(
".")) {
458 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
459 fSetupStatus = kSetupMissingBranch;
464 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
465 TString leafName (fBranchName(leafNameExpression));
466 TString
branchName = fBranchName(0, fBranchName.Length() - leafName.Length());
467 branch = fTreeReader->
GetTree()->GetBranch(branchName);
469 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
470 fSetupStatus = kSetupMissingBranch;
475 myLeaf = branch->GetLeaf(TString(leafName(1, leafName.Length())));
477 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());
478 fSetupStatus = kSetupMissingBranch;
485 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Failed to get the dictionary for %s.", myLeaf->
GetTypeName());
486 fSetupStatus = kSetupMissingDictionary;
493 branchActualType = fDict;
496 fLeafName = leafName(1, leafName.Length());
497 fSetupStatus = kSetupMatchLeaf;
500 Error(
"TTreeReaderArrayBase::GetBranchAndLeaf()",
"Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->
GetTypeName(), fDict->GetName());
502 fSetupStatus = kSetupMismatch;
528 fImpl =
new TLeafReader(
this);
534 fImpl =
new TLeafParameterSizeReader(fTreeReader, leafFullName.Data(),
this);
536 fSetupStatus = kSetupMatchLeaf;
550 if (fSetupStatus == kSetupInternalError)
551 fSetupStatus = kSetupMatch;
553 fImpl =
new TSTLReader();
559 fImpl =
new TClonesReader();
570 fImpl =
new TBasicTypeArrayReader();
573 fImpl =
new TBasicTypeClonesReader(element->
GetOffset());
577 ((TObjectArrayReader*)fImpl)->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
582 ((TArrayParameterSizeReader*)fImpl)->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
585 fImpl =
new TClonesReader();
587 Error(
"TTreeReaderArrayBase::SetImpl()",
588 "Cannot read branch %s: unhandled streamer element type %s",
589 fBranchName.Data(), element->IsA()->
GetName());
590 fSetupStatus = kSetupInternalError;
601 Error(
"TTreeReaderArrayBase::SetImpl",
"Failed to get the top leaf from the branch");
602 fSetupStatus = kSetupMissingBranch;
607 if (fSetupStatus == kSetupInternalError)
608 fSetupStatus = kSetupMatch;
610 fImpl =
new TArrayFixedSizeReader(size);
613 fImpl =
new TArrayParameterSizeReader(fTreeReader, sizeLeaf->
GetName());
615 ((TObjectArrayReader*)fImpl)->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
617 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchClones not implemented");
618 fSetupStatus = kSetupInternalError;
620 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchObject not implemented");
621 fSetupStatus = kSetupInternalError;
623 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchSTL not implemented");
624 fImpl =
new TSTLReader();
625 fSetupStatus = kSetupInternalError;
627 Error(
"TTreeReaderArrayBase::SetImpl",
"Support for branches of type TBranchRef not implemented");
628 fSetupStatus = kSetupInternalError;
643 TString& contentTypeName,
647 contentTypeName =
"";
651 || brElement->
GetType() == 3) {
656 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Could not get value class.");
665 if (brElement->
GetType() == 3) {
674 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Cannot determine STL collection type of %s stored in branch %s", brElement->
GetClassName(), branch->
GetName());
679 if (isMap) contentTypeName =
"std::pair< ";
680 contentTypeName += splitType.fElements[1];
682 contentTypeName += splitType.fElements[2];
683 contentTypeName +=
" >";
688 }
else if (brElement->
GetType() == 31
689 || brElement->
GetType() == 41) {
694 if (ExpectedTypeRet == 0) {
700 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
701 branch->
GetName(), (int)dtData);
706 }
else if (ExpectedTypeRet == 1) {
707 int brID = brElement->
GetID();
710 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
725 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
737 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get class from branch element.");
741 if (!myCollectionProxy){
742 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get collection proxy from STL class");
750 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get valueClass from collectionProxy.");
753 contentTypeName = dict->
GetName();
757 if (!fProxy->Setup() || !fProxy->Read()){
758 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Failed to get type from proxy, unable to check type");
759 contentTypeName =
"UNKNOWN";
761 return contentTypeName;
765 contentTypeName = dict->
GetName();
779 contentTypeName =
"TClonesArray";
780 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
782 fSetupStatus = kSetupNoCheck;
789 if (dict) contentTypeName = dict->
GetName();
794 contentTypeName = dict->
GetName();
805 if ((!dataTypeName || !dataTypeName[0])
818 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());
821 while ((leaf = (
TLeaf*) iLeaves())) {
822 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
" %s.%s", branch->
GetName(), leaf->GetName());
828 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
830 fSetupStatus = kSetupNoCheck;
836 return "TClonesArray";
839 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
842 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is of type %s - something that is not handled yet.", branch->
GetName(), branch->IsA()->
GetName());
Describe Streamer information for one class version.
virtual const char * GetName() const
Returns name of object.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any. ...
A TLeaf describes individual elements of a TBranch See TBranch structure in TTree.
static TDataType * GetDataType(EDataType type)
Given a EDataType type, get the TDataType* that represents it.
TVirtualCollectionProxy * GetCollectionProxy()
Return the collection proxy describing the branch content, if any.
const char * GetBranchContentDataType(TBranch *branch, TString &contentTypeName, TDictionary *&dict)
Access a branch's collection content (not the collection itself) through a proxy. ...
TString GetTypeName()
Get basic type of typedef, e,g.
Int_t GetSplitLevel() const
virtual Int_t GetExpectedType(TClass *&clptr, EDataType &type)
Fill expectedClass and expectedType with information on the data type of the object/values contained ...
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
virtual TClass * GetValueClass() const =0
TStreamerElement * GetElement(Int_t id) const
virtual const char * GetTypeName() const
virtual TLeaf * GetLeafCounter(Int_t &countval) const
Return a pointer to the counter of this leaf.
Regular expression class.
static TDictionary * GetDictionary(const char *name)
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
virtual void * GetStart(UInt_t=0)
Int_t GetArrayLength() const
EReadStatus ProxyRead()
Try to read the value from the TBranchProxy, returns the status of the read.
Type GetType(const std::string &Name)
TObject * At(Int_t idx) const
virtual EDataType GetType() const =0
void SetContentDict(TDictionary *dict)
TBranchElement * GetBranchCount() const
const Detail::TBranchProxy * GetProxy() const
virtual TLeaf * GetLeaf(const char *name) const
Return pointer to the 1st Leaf named name in thisBranch.
int IsSTLCont(int testAlloc=0) const
type : type name: vector<list<classA,allocator>,allocator> testAlloc: if true, we test allocator...
virtual Int_t GetLenType() const
TDictionary * GetContentDict() const
virtual const char * GetClonesName() const
TTreeReaderValueBase::EReadStatus fReadStatus
bool GetBranchAndLeaf(TBranch *&branch, TLeaf *&myLeaf, TDictionary *&branchActualType)
Determine the branch / leaf and its type; reset fProxy / fSetupStatus on error.
virtual Int_t GetLen() const
Return the number of effective elements of this leaf.
virtual const char * GetTypeName() const
Return type name of element in the branch.
Basic data type descriptor (datatype information is obtained from CINT).
This class defines an abstract interface that must be implemented by all classes that contain diction...
virtual Bool_t HasPointers() const =0
virtual TLeaf * GetLeafCount() const
TClass * GetCurrentClass()
Return a pointer to the current type of the data member corresponding to branch element.
void * GetAddress()
Returns the memory address of the object being read.
The ROOT global object gROOT contains a list of all defined classes.
void Warning(const char *location, const char *msgfmt,...)
A Branch for the case of an object.
TObject * UncheckedAt(Int_t i) const
TVirtualCollectionProxy * GetCollection()
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any. ...
virtual void * At(UInt_t idx)=0
TObjArray * GetListOfLeaves()
TClass * GetClass() const
TLeaf * GetLeaf()
If we are reading a leaf, return the corresponding TLeaf.
Int_t GetClassSize() const
TObjArray * GetElements() const
virtual UInt_t Size() const =0
typedef void((*Func_t)())
An array of clone (identical) objects.
const char * GetTypeName() const
virtual ~TVirtualCollectionReader()
virtual TClass * GetClass() const
Int_t GetEntries() const
Return the number of objects in array (i.e.
virtual void * At(Detail::TBranchProxy *, size_t)=0
Base class for all the proxy object.
TBranch * GetBranch() const
A TTree is a list of TBranches.
TBranch * GetMother() const
Get our top-level parent branch in the tree.
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.
TClass * GetClass() const
void SetImpl(TBranch *branch, TLeaf *myLeaf)
Create the TVirtualCollectionReader object for our branch.
virtual size_t GetSize(Detail::TBranchProxy *)=0