20 #include "TClassEdit.h" 41 const
char* branchname ,
43 fBranchName(branchname),
48 fSetupStatus(kSetupNotSetup),
49 fReadStatus(kReadNothingYet)
51 RegisterWithTreeReader();
58 fBranchName(rhs.fBranchName),
59 fLeafName(rhs.fLeafName),
60 fTreeReader(rhs.fTreeReader),
64 fSetupStatus(rhs.fSetupStatus),
65 fReadStatus(rhs.fReadStatus),
66 fStaticClassOffsets(rhs.fStaticClassOffsets)
133 char* buf = TClassEdit::DemangleTypeIdName(ti, err);
134 std::string ret = buf;
150 Error(
"TTreeReaderValueBase::GetLeaf()",
"Unable to get the branch from the tree");
156 Error(
"TTreeReaderValueBase::GetLeaf()",
"Failed to get the leaf from the branch");
172 Error(
"TTreeReaderValueBase::GetAddress()",
"Unable to get the leaf");
198 Error(
"TTreeReaderValueBase::CreateProxy()",
"TTreeReader object not set / available for branch %s!",
205 const char* brDataType =
"{UNDETERMINED}";
210 Error(
"TTreeReaderValueBase::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.",
239 TRegexp leafNameExpression (
"\\.[a-zA-Z0-9_]+$");
244 std::vector<TString> nameStack;
245 nameStack.push_back(
TString());
254 while (!branch && branchName.
Contains(
".")){
265 TString traversingBranch = nameStack.back();
266 nameStack.pop_back();
272 std::vector<Long64_t> offsets;
279 while (nameStack.size() && found){
282 for (
int i = 0; i < myObjArray->
GetEntries(); ++i){
286 if (!strcmp(tempStreamerElement->
GetName(), traversingBranch.
Data())){
289 traversingBranch = nameStack.back();
290 nameStack.pop_back();
292 elementClass = tempStreamerElement->
GetClass();
300 if (!finalDataType) {
309 offsets.push_back(offset);
319 offsets.push_back(offset);
324 if (
fDict != finalDataType &&
fDict != elementClass){
325 Error(
"TTreeReaderValueBase::CreateProxy",
"Wrong data type %s", finalDataType ? finalDataType->
GetName() : elementClass ? elementClass->
GetName() :
"UNKNOWN");
335 Error(
"TTreeReaderValueBase::CreateProxy()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.",
fBranchName.
Data());
342 myLeaf = branch->GetLeaf(
TString(leafName(1, leafName.
Length())));
344 Error(
"TTreeReaderValueBase::CreateProxy()",
345 "The tree does not have a branch, nor a sub-branch called %s. You could check with TTree::Print() for available branches.",
fBranchName.
Data());
354 branchActualType =
fDict;
361 Error(
"TTreeReaderValueBase::CreateProxy()",
369 Error(
"TTreeReaderValueBase::CreateProxy()",
"The tree does not have a branch called %s. You could check with TTree::Print() for available branches.",
fBranchName.
Data());
378 if (!branchActualType) {
379 Error(
"TTreeReaderValueBase::CreateProxy()",
"The branch %s contains data of type %s, which does not have a dictionary.",
380 fBranchName.
Data(), branchActualTypeName ? branchActualTypeName :
"{UNDETERMINED TYPE}");
385 if (
fDict != branchActualType) {
388 bool complainAboutMismatch =
true;
389 if (dictdt && actualdt) {
392 complainAboutMismatch =
false;
397 complainAboutMismatch =
false;
400 if (complainAboutMismatch) {
401 Error(
"TTreeReaderValueBase::CreateProxy()",
402 "The branch %s contains data of type %s. It cannot be accessed by a TTreeReaderValue<%s>",
412 if (namedProxy && !namedProxy->
GetDict()) {
427 bool isTopLevel = branch->
GetMother() == branch;
429 membername = strrchr(branch->
GetName(),
'.');
430 if (membername.
IsNull()) {
431 membername = branch->
GetName();
456 auto ResolveTypedef = [&]() ->
void {
504 return "TClonesArray";
505 }
else if (brElement->
GetType() == 31
506 || brElement->
GetType() == 41) {
508 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Must use TTreeReaderArray to access a member of an object that is stored in a collection.");
514 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"Unknown type and class combination: %i, %s", brElement->
GetType(), brElement->
GetClassName());
525 if ((!dataTypeName || !dataTypeName[0])
538 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"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());
541 while ((leaf = (
TLeaf*) iLeaves())) {
542 Error(
"TTreeReaderValueBase::GetBranchDataType()",
" %s.%s", branch->
GetName(), leaf->GetName());
550 return "TClonesArray";
553 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"The branch %s is a TBranchRef and cannot be represented as a C++ type.", branch->
GetName());
556 Error(
"TTreeReaderValueBase::GetBranchDataType()",
"The branch %s is of type %s - something that is not handled yet.", branch->
GetName(), branch->IsA()->
GetName());
ROOT::Internal::TNamedBranchProxy * FindProxy(const char *branchname) const
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.
To read this branch, we need a dictionary.
TTreeReader is a simple, robust and fast interface to read values from a TTree, TChain or TNtuple...
Namespace for new ROOT classes and functions.
The branch class type is not a collection.
virtual const char * GetTypeName() const
TVirtualStreamerInfo * GetStreamerInfo(Int_t version=0) const
returns a pointer to the TVirtualStreamerInfo object for version If the object does not exist...
virtual ~TTreeReaderValueBase()
Unregister from tree reader, cleanup.
Regular expression class.
static TDictionary * GetDictionary(const char *name)
TStreamerInfo * GetInfo() const
Get streamer info for the branch class.
EReadStatus ProxyRead()
Try to read the value from the TBranchProxy, returns the status of the read.
std::vector< Long64_t > fStaticClassOffsets
Type GetType(const std::string &Name)
The array cannot find its counter branch: Array[CounterBranch].
TObject * At(Int_t idx) const
Bool_t RegisterValueReader(ROOT::Internal::TTreeReaderValueBase *reader)
const Detail::TBranchProxy * GetProxy() const
TDictionary * GetDict() const
virtual TLeaf * GetLeaf(const char *name) const
Return pointer to the 1st Leaf named name in thisBranch.
ESetupStatus fSetupStatus
TTreeReaderValueBase & operator=(const TTreeReaderValueBase &)
Copy-assign.
The specified branch cannot be found.
virtual TBranch * GetBranch(const char *name)
Return pointer to the branch with the given name in this tree or its friends.
virtual const char * GetTypeName() const
Return type name of element in the branch.
void SetDict(TDictionary *dict)
void RegisterWithTreeReader()
Register with tree reader.
ROOT::Internal::TBranchProxyDirector * fDirector
proxying director, owned
TTreeReader * fTreeReader
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...
void AddProxy(ROOT::Internal::TNamedBranchProxy *p)
virtual void CreateProxy()
Create the proxy object for our branch.
Some other error - hopefully the error message helps.
TClass * GetCurrentClass()
Return a pointer to the current type of the data member corresponding to branch element.
virtual void * GetValuePointer() const
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
void * GetAddress()
Returns the memory address of the object being read.
The ROOT global object gROOT contains a list of all defined classes.
No initialization has happened yet.
A Branch for the case of an object.
static std::string GetElementTypeName(const std::type_info &ti)
Stringify the template argument.
virtual TObjArray * GetElements() const =0
virtual Bool_t IsaPointer() const
virtual const char * GetClassName() const
Return the name of the user class whose content is stored in this branch, if any. ...
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
void DeregisterValueReader(ROOT::Internal::TTreeReaderValueBase *reader)
TObjArray * GetListOfLeaves()
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
TLeaf * GetLeaf()
If we are reading a leaf, return the corresponding TLeaf.
TObjArray * GetElements() const
const char * GetTypeName() const
Detail::TBranchProxy * fProxy
virtual const char * GetDerivedTypeName() const =0
TTreeReaderValueBase(TTreeReader *reader=0, const char *branchname=0, TDictionary *dict=0)
Construct a tree value reader and register it with the reader object.
void NotifyNewTree(TTree *newTree)
The TTreeReader has switched to a new TTree. Update the leaf.
Int_t GetEntries() const
Return the number of objects in array (i.e.
A TTree object has a header with a name and a title.
A TTree is a list of TBranches.
Abstract Interface class describing Streamer information for one class.
const char * GetBranchDataType(TBranch *branch, TDictionary *&dict) const
Retrieve the type of data stored by branch; put its dictionary into dict, return its type name...
TBranch * GetMother() const
Get our top-level parent branch in the tree.
virtual Int_t GetElementOffset(Int_t id) const =0
void Error(ErrorHandler_t func, int code, const char *va_(fmt),...)
Write error message and call a handler, if required.
TClass * GetClass() const
const char * Data() const