32 using namespace ROOT::Internal;
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.");
90 if (!myCollectionProxy)
return 0;
91 return myCollectionProxy->
Size();
96 if (!myCollectionProxy)
return 0;
98 return *(
void**)myCollectionProxy->
At(idx);
101 return myCollectionProxy->
At(idx);
113 if (!proxy->
Read()) {
115 Error(
"TCollectionLessSTLReader::GetCP()",
"Read error in TBranchProxy.");
119 Error(
"TCollectionLessSTLReader::GetCP()",
"Logic error, proxy object not set in TBranchProxy.");
123 return localCollection;
128 if (!myCollectionProxy)
return 0;
130 return myCollectionProxy->
Size();
135 if (!myCollectionProxy)
return 0;
138 return *(
void**)myCollectionProxy->
At(idx);
140 return myCollectionProxy->
At(idx);
152 TObjectArrayReader() : basicTypeSize(-1) { }
153 ~TObjectArrayReader() {}
157 Error(
"TObjectArrayReader::GetCP()",
"Read error in TBranchProxy.");
165 if (!myCollectionProxy)
return 0;
166 return myCollectionProxy->
Size();
169 if (!proxy->
Read())
return 0;
172 void *array = (
void*)proxy->
GetStart();
174 if (basicTypeSize == -1){
177 Error(
"TObjectArrayReader::At()",
"Cannot get class info from branch proxy.");
183 objectSize = basicTypeSize;
185 return (
void*)((
Byte_t*)array + (objectSize * idx));
188 void SetBasicTypeSize(
Int_t size){
189 basicTypeSize = size;
193 class TArrayParameterSizeReader :
public TObjectArrayReader {
197 bool fIsUnsigned =
false;
206 if (
TLeaf* sizeLeaf = treeReader->
GetTree()->FindLeaf(branchName)) {
207 fIsUnsigned = sizeLeaf->IsUnsigned();
218 return *GetIndexReader<UInt_t>();
219 return *GetIndexReader<Int_t>();
224 class TArrayFixedSizeReader :
public TObjectArrayReader {
229 TArrayFixedSizeReader(
Int_t sizeArg) : size(sizeArg) {}
236 ~TBasicTypeArrayReader() {}
241 Error(
"TBasicTypeArrayReader::GetCP()",
"Read error in TBranchProxy.");
250 if (!myCollectionProxy)
return 0;
251 return myCollectionProxy->
Size();
256 if (!myCollectionProxy)
return 0;
261 class TBasicTypeClonesReader :
public TClonesReader {
265 TBasicTypeClonesReader(
Int_t offsetArg) : offset(offsetArg) {}
269 if (!myClonesArray)
return 0;
270 return (
Byte_t*)myClonesArray->
At(idx) + offset;
279 TLeafReader(
TTreeReaderValueBase *valueReaderArg) : valueReader(valueReaderArg), elementSize(-1) {}
282 TLeaf *myLeaf = valueReader->GetLeaf();
283 return myLeaf ? myLeaf->
GetLen() : 0;
288 void *address = valueReader->GetAddress();
289 if (elementSize == -1){
290 TLeaf *myLeaf = valueReader->GetLeaf();
291 if (!myLeaf)
return 0;
294 return (
Byte_t*)address + (elementSize * idx);
299 valueReader->ProxyRead();
303 class TLeafParameterSizeReader :
public TLeafReader {
307 TLeafParameterSizeReader(
TTreeReader *treeReader,
const char *leafName,
TTreeReaderValueBase *valueReaderArg) : TLeafReader(valueReaderArg), sizeReader(*treeReader, leafName) {}
332 fSetupStatus = kSetupInternalError;
334 Error(
"TTreeReaderArrayBase::CreateProxy()",
"TTreeReader object not set / available for branch %s!",
336 fSetupStatus = kSetupTreeDestructed;
341 const char* brDataType =
"{UNDETERMINED}";
344 brDataType = GetBranchDataType(br, dictUnused);
346 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.",
347 GetDerivedTypeName(), fBranchName.Data(), brDataType);
348 fSetupStatus = kSetupMissingDictionary;
359 fSetupStatus = kSetupMatch;
362 Fatal(
"TTreeReaderArrayBase::CreateProxy()",
"No fImpl set!");
363 fSetupStatus = kSetupMissingDictionary;
373 if (fBranchName.Contains(
".")){
374 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
375 TString leafName (fBranchName(leafNameExpression));
376 TString branchName = fBranchName(0, fBranchName.Length() - leafName.Length());
377 branch = fTreeReader->
GetTree()->GetBranch(branchName);
379 Error(
"TTreeReaderArrayBase::CreateProxy()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
380 fSetupStatus = kSetupMissingBranch;
385 myLeaf = branch->GetLeaf(TString(leafName(1, leafName.Length())));
387 Error(
"TTreeReaderArrayBase::CreateProxy()",
"The tree does not have a branch, nor a sub-branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
388 fSetupStatus = kSetupMissingBranch;
395 Error(
"TTreeReaderArrayBase::CreateProxy()",
"Failed to get the dictionary for %s.", myLeaf->
GetTypeName());
396 fSetupStatus = kSetupMissingDictionary;
402 branchActualType = fDict;
405 fLeafName = leafName(1, leafName.Length());
406 fSetupStatus = kSetupMatchLeaf;
409 Error(
"TTreeReaderArrayBase::CreateProxy()",
"Leaf of type %s cannot be read by TTreeReaderValue<%s>.", myLeaf->
GetTypeName(), fDict->GetName());
411 fSetupStatus = kSetupMismatch;
418 Error(
"TTreeReaderArrayBase::CreateProxy()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.", fBranchName.Data());
419 fSetupStatus = kSetupMissingBranch;
430 fSetupStatus = kSetupMatch;
435 bool isTopLevel = branch->
GetMother() == branch;
437 membername = strrchr(branch->
GetName(),
'.');
438 if (membername.IsNull()) {
439 membername = branch->
GetName();
443 fTreeReader->GetProxies()->Add(namedProxy);
446 fSetupStatus = kSetupMatch;
448 fSetupStatus = kSetupMismatch;
452 TString branchActualTypeName;
453 const char* nonCollTypeName = GetBranchContentDataType(branch, branchActualTypeName, branchActualType);
454 if (nonCollTypeName) {
455 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which should be accessed through a TTreeReaderValue< %s >.",
456 fBranchName.Data(), nonCollTypeName, nonCollTypeName);
457 if (fSetupStatus == kSetupInternalError)
458 fSetupStatus = kSetupNotACollection;
462 if (!branchActualType) {
463 if (branchActualTypeName.IsNull()) {
464 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"Cannot determine the type contained in the collection of branch %s. That's weird - please report!",
467 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s, which does not have a dictionary.",
468 fBranchName.Data(), branchActualTypeName.Data());
469 if (fSetupStatus == kSetupInternalError)
470 fSetupStatus = kSetupMissingDictionary;
476 if (fDict != branchActualType) {
477 Error(
"TTreeReaderArrayBase::CreateContentProxy()",
"The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderArray<%s>",
478 fBranchName.Data(), branchActualType->
GetName(), fDict->GetName());
479 if (fSetupStatus == kSetupInternalError || fSetupStatus >= 0)
480 fSetupStatus = kSetupMismatch;
503 fImpl =
new TLeafReader(
this);
509 fImpl =
new TLeafParameterSizeReader(fTreeReader, leafFullName.Data(),
this);
511 fSetupStatus = kSetupMatchLeaf;
525 if (fSetupStatus == kSetupInternalError)
526 fSetupStatus = kSetupMatch;
528 fImpl =
new TSTLReader();
534 fImpl =
new TClonesReader();
545 fImpl =
new TBasicTypeArrayReader();
548 fImpl =
new TBasicTypeClonesReader(element->
GetOffset());
552 ((TObjectArrayReader*)fImpl)->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
557 ((TArrayParameterSizeReader*)fImpl)->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
560 fImpl =
new TClonesReader();
562 Error(
"TTreeReaderArrayBase::CreateProxy()",
563 "Cannot read branch %s: unhandled streamer element type %s",
564 fBranchName.Data(), element->IsA()->
GetName());
565 fSetupStatus = kSetupInternalError;
576 Error(
"TTreeReaderArrayBase::CreateProxy",
"Failed to get the top leaf from the branch");
577 fSetupStatus = kSetupMissingBranch;
582 if (fSetupStatus == kSetupInternalError)
583 fSetupStatus = kSetupMatch;
585 fImpl =
new TArrayFixedSizeReader(size);
588 fImpl =
new TArrayParameterSizeReader(fTreeReader, sizeLeaf->
GetName());
590 ((TObjectArrayReader*)fImpl)->SetBasicTypeSize(((
TDataType*)fDict)->
Size());
592 Error(
"TTreeReaderArrayBase::CreateProxy",
"Support for branches of type TBranchClones not implemented");
593 fSetupStatus = kSetupInternalError;
595 Error(
"TTreeReaderArrayBase::CreateProxy",
"Support for branches of type TBranchObject not implemented");
596 fSetupStatus = kSetupInternalError;
598 Error(
"TTreeReaderArrayBase::CreateProxy",
"Support for branches of type TBranchSTL not implemented");
599 fImpl =
new TSTLReader();
600 fSetupStatus = kSetupInternalError;
602 Error(
"TTreeReaderArrayBase::CreateProxy",
"Support for branches of type TBranchRef not implemented");
603 fSetupStatus = kSetupInternalError;
618 TString& contentTypeName,
622 contentTypeName =
"";
626 || brElement->
GetType() == 3) {
631 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Could not get value class.");
640 if (brElement->
GetType() == 3) {
649 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Cannot determine STL collection type of %s stored in branch %s", brElement->
GetClassName(), branch->
GetName());
654 if (isMap) contentTypeName =
"std::pair< ";
655 contentTypeName += splitType.fElements[1];
657 contentTypeName += splitType.fElements[2];
658 contentTypeName +=
" >";
663 }
else if (brElement->
GetType() == 31
664 || brElement->
GetType() == 41) {
669 if (ExpectedTypeRet == 0) {
675 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains a data type %d for which the dictionary cannot be retrieved.",
676 branch->
GetName(), (int)dtData);
681 }
else if (ExpectedTypeRet == 1) {
682 int brID = brElement->
GetID();
685 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s contains data of type %s for which the dictionary does not exist. It's needed.",
700 return "{CANNOT DETERMINE TBranchElement DATA TYPE}";
712 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get class from branch element.");
716 if (!myCollectionProxy){
717 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get collection proxy from STL class");
725 Error(
"TTreeReaderArrayBase::GetBranchDataType()",
"Could not get valueClass from collectionProxy.");
728 contentTypeName = dict->
GetName();
732 if (!fProxy->Setup() || !fProxy->Read()){
733 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Failed to get type from proxy, unable to check type");
734 contentTypeName =
"UNKNOWN";
736 return contentTypeName;
740 contentTypeName = dict->
GetName();
754 contentTypeName =
"TClonesArray";
755 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
757 fSetupStatus = kSetupNoCheck;
764 if (dict) contentTypeName = dict->
GetName();
769 contentTypeName = dict->
GetName();
780 if ((!dataTypeName || !dataTypeName[0])
793 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());
796 while ((leaf = (
TLeaf*) iLeaves())) {
797 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
" %s.%s", branch->
GetName(), leaf->GetName());
803 Warning(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"Not able to check type correctness, ignoring check");
805 fSetupStatus = kSetupNoCheck;
811 return "TClonesArray";
814 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
817 Error(
"TTreeReaderArrayBase::GetBranchContentDataType()",
"The branch %s is of type %s - something that is not handled yet.", branch->
GetName(), branch->IsA()->
GetName());
virtual Int_t GetLen() const
Return the number of effective elements of this leaf.
Describe Streamer information for one class version.
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 IsSTLCont(int testAlloc=0) const
type : type name: vector<list<classA,allocator>,allocator> testAlloc: if true, we test allocator...
virtual TLeaf * GetLeaf(const char *name) const
Return pointer to the 1st Leaf named name in thisBranch.
virtual Int_t GetExpectedType(TClass *&clptr, EDataType &type)
Fill expectedClass and expectedType with information on the data type of the object/values contained ...
const char * GetTypeName() const
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
void Fatal(const char *location, const char *msgfmt,...)
virtual TClass * GetValueClass() const =0
Regular expression class.
static TDictionary * GetDictionary(const char *name)
virtual void * GetStart(UInt_t=0)
TBranch * GetBranch() const
Type GetType(const std::string &Name)
Int_t GetSplitLevel() const
virtual EDataType GetType() const =0
Int_t GetClassSize() const
const Detail::TBranchProxy * GetProxy() const
void SetContentDict(TDictionary *dict)
virtual const char * GetClonesName() const
TBranchElement * GetBranchCount() const
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
virtual TLeaf * GetLeafCounter(Int_t &countval) const
Return a pointer to the counter of this leaf.
TObject * UncheckedAt(Int_t i) const
virtual const char * GetTypeName() const
TObjArray * GetElements() const
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
TBranch * GetMother() const
Get our top-level parent branch in the tree.
TClass * GetCurrentClass()
Return a pointer to the current type of the data member corresponding to branch element.
virtual const char * GetName() const
Returns name of object.
The ROOT global object gROOT contains a list of all defined classes.
void Warning(const char *location, const char *msgfmt,...)
virtual TClass * GetClass() const
virtual TLeaf * GetLeafCount() const
A Branch for the case of an object.
virtual const char * GetTypeName() const
Return type name of element in the branch.
TVirtualCollectionProxy * GetCollection()
virtual Int_t GetLenType() const
TClass * GetClass() const
Bool_t IsaPointer() const
virtual void * At(UInt_t idx)=0
TObjArray * GetListOfLeaves()
Int_t GetEntries() const
Return the number of objects in array (i.e.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any. ...
TVirtualCollectionProxy * GetCollectionProxy() const
Return the proxy describing the collection (if any).
TClass * GetClass() const
virtual UInt_t Size() const =0
typedef void((*Func_t)())
An array of clone (identical) objects.
virtual ~TVirtualCollectionReader()
Proxy around an arbitrary container, which implements basic functionality and iteration.
TStreamerElement * GetElement(Int_t id) const
TObject * At(Int_t idx) const
Base class for all the proxy object.
TDictionary * GetContentDict() const
A TTree is a list of TBranches.
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any. ...
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.
Int_t GetArrayLength() const