Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
TTreeReaderArray< T > Class Template Referencefinal

template<typename T>
class TTreeReaderArray< T >

An interface for reading collections stored in ROOT columnar datasets.

The TTreeReaderArray is a type-safe tool to be used in association with a TTreeReader to access the collections stored in TTree, TNtuple and TChain datasets. In order to access values which are not collections, the TTreeReaderValue class can be used.

See the documentation of TTreeReader for more details and examples.

Definition at line 104 of file TTreeReaderArray.h.

Classes

class  Iterator_t
 Random access iterator to the elements of a TTreeReaderArray. More...

Public Types

typedef bool(ROOT::Detail::TBranchProxy::* BranchProxyRead_t) ()
using const_iterator = Iterator_t<const TTreeReaderArray<T>>
enum  EReadStatus { kReadSuccess = 0 , kReadNothingYet , kReadError }
enum  ESetupStatus {
  kSetupMatchButEntryBeyondEnd , kSetupMakeClassModeMismatch = -9 , kSetupTreeDestructed = -8 , kSetupNotSetup = -7 ,
  kSetupMissingCounterBranch = -6 , kSetupMissingBranch = -5 , kSetupInternalError = -4 , kSetupMissingDictionary = -3 ,
  kSetupMismatch = -2 , kSetupNotACollection = -1 , kSetupMatch , kSetupNoCheck = 5 ,
  kSetupMatchLeaf = 6 , kSetupMatchBranch
}
 Status flags, 0 is good. More...
using iterator = Iterator_t<TTreeReaderArray<T>>

Public Member Functions

 TTreeReaderArray (TTreeReader &tr, const char *branchname)
 Create an array reader of branch "branchname" for TTreeReader "tr".
T & At (std::size_t idx)
const T & At (std::size_t idx) const
iterator begin ()
const_iterator begin () const
const_iterator cbegin () const
const_iterator cend () const
iterator end ()
const_iterator end () const
void * GetAddress ()
 Returns the memory address of the object being read.
const char * GetBranchName () const
TLeafGetLeaf ()
 If we are reading a leaf, return the corresponding TLeaf.
EReadStatus GetReadStatus () const override
ESetupStatus GetSetupStatus () const
 Return this TTreeReaderValue's setup status.
std::size_t GetSize () const
std::size_t GetValueSize () const
 Returns the sizeof of the collection value type. Returns 0 in case the value size could not be retrieved.
bool IsContiguous () const
bool IsEmpty () const
bool IsValid () const
 Return true if the branch was setup and read correctly.
T & operator[] (std::size_t idx)
const T & operator[] (std::size_t idx) const
EReadStatus ProxyRead ()
EReadStatus ProxyReadDefaultImpl ()
template<BranchProxyRead_t Func>
ROOT::Internal::TTreeReaderValueBase::EReadStatus ProxyReadTemplate ()
 Try to read the value from the TBranchProxy, returns the status of the read.

Protected Types

typedef EReadStatus(TTreeReaderValueBase::* Read_t) ()

Protected Member Functions

void CreateProxy () override
 Create the proxy object for our branch.
void ErrorAboutMissingProxyIfNeeded ()
bool GetBranchAndLeaf (TBranch *&branch, TLeaf *&myLeaf, TDictionary *&branchActualType, bool suppressErrorsForMissingBranch=false)
 Determine the branch / leaf and its type; reset fProxy / fSetupStatus on error.
const char * GetBranchContentDataType (TBranch *branch, TString &contentTypeName, TDictionary *&dict, StreamerElementArrayInfo &arrInfo)
 Access a branch's collection content (not the collection itself) through a proxy.
const char * GetDerivedTypeName () const override
Detail::TBranchProxy * GetProxy () const
void MarkTreeReaderUnavailable ()
void NotifyNewTree (TTree *newTree)
 The TTreeReader has switched to a new TTree. Update the leaf.
void RegisterWithTreeReader ()
 Register with tree reader.
TBranchSearchBranchWithCompositeName (TLeaf *&myleaf, TDictionary *&branchActualType, std::string &err)
 Search a branch the name of which contains a ".".
void SetImpl (TBranch *branch, TLeaf *myLeaf)
 Create the TVirtualCollectionReader object for our branch.
void * UntypedAt (std::size_t idx) const

Static Protected Member Functions

static const char * GetBranchDataType (TBranch *branch, TDictionary *&dict, TDictionary const *curDict)
 Retrieve the type of data stored by branch; put its dictionary into dict, return its type name.
static std::string GetElementTypeName (const std::type_info &ti)
 Stringify the template argument.

Protected Attributes

TString fBranchName
 Name of the branch to read data from.
TDictionaryfDict
 Type that the branch should contain.
bool fHaveLeaf: 1
 Whether the data is in a leaf.
bool fHaveStaticClassOffsets: 1
 Whether !fStaticClassOffsets.empty().
std::unique_ptr< TVirtualCollectionReader > fImpl
TLeaffLeaf = nullptr
TString fLeafName
bool fOpaqueRead {false}
 If true, the reader will not do any type-checking against the actual type held by the branch.
Detail::TBranchProxy * fProxy = nullptr
 Proxy for this branch, owned by TTreeReader.
Read_t fProxyReadFunc = &TTreeReaderValueBase::ProxyReadDefaultImpl
 ! Pointer to the Read implementation to use.
EReadStatus fReadStatus: 2
 Read status of this data access.
ESetupStatus fSetupStatus = kSetupNotSetup
 Setup status of this data access.
std::vector< Long64_tfStaticClassOffsets
TTreeReaderfTreeReader
 Tree reader we belong to.

Private Member Functions

StreamerElementArrayInfo FillStreamerElementArrayInfo (TStreamerElement *elem)

#include <TTreeReaderArray.h>

Inheritance diagram for TTreeReaderArray< T >:
ROOT::Internal::TTreeReaderArrayBase ROOT::Internal::TTreeReaderValueBase

Member Typedef Documentation

◆ BranchProxyRead_t

typedef bool(ROOT::Detail::TBranchProxy::* ROOT::Internal::TTreeReaderValueBase::BranchProxyRead_t) ()
inherited

Definition at line 84 of file TTreeReaderValue.h.

◆ const_iterator

template<typename T>
using TTreeReaderArray< T >::const_iterator = Iterator_t<const TTreeReaderArray<T>>

Definition at line 230 of file TTreeReaderArray.h.

◆ iterator

template<typename T>
using TTreeReaderArray< T >::iterator = Iterator_t<TTreeReaderArray<T>>

Definition at line 229 of file TTreeReaderArray.h.

◆ Read_t

typedef EReadStatus(TTreeReaderValueBase::* ROOT::Internal::TTreeReaderValueBase::Read_t) ()
protectedinherited

Definition at line 143 of file TTreeReaderValue.h.

Member Enumeration Documentation

◆ EReadStatus

Enumerator
kReadSuccess 

Data read okay.

kReadNothingYet 

Data now yet accessed.

kReadError 

Problem reading data.

Definition at line 74 of file TTreeReaderValue.h.

◆ ESetupStatus

Status flags, 0 is good.

Enumerator
kSetupMatchButEntryBeyondEnd 

This branch has been setup, branch data type and reader template type match, but nothing can be read because we have already reached the end of the tree.

kSetupMakeClassModeMismatch 

readers disagree on whether TTree::SetMakeBranch() should be on

kSetupTreeDestructed 

The TTreeReader has been destructed / not set.

kSetupNotSetup 

No initialization has happened yet.

kSetupMissingCounterBranch 

The array cannot find its counter branch: Array[CounterBranch].

kSetupMissingBranch 

The specified branch cannot be found.

kSetupInternalError 

Some other error - hopefully the error message helps.

kSetupMissingDictionary 

To read this branch, we need a dictionary.

kSetupMismatch 

Mismatch of branch type and reader template type.

kSetupNotACollection 

The branch class type is not a collection.

kSetupMatch 

This branch has been set up, branch data type and reader template type match, reading should succeed.

kSetupNoCheck 
kSetupMatchLeaf 

This branch (or TLeaf, really) has been set up, reading should succeed.

kSetupMatchBranch 

This branch has been set up, branch data type and reader template type match, reading should succeed.

Definition at line 48 of file TTreeReaderValue.h.

Constructor & Destructor Documentation

◆ TTreeReaderArray()

template<typename T>
TTreeReaderArray< T >::TTreeReaderArray ( TTreeReader & tr,
const char * branchname )
inline

Create an array reader of branch "branchname" for TTreeReader "tr".

Definition at line 233 of file TTreeReaderArray.h.

Member Function Documentation

◆ At() [1/2]

template<typename T>
T & TTreeReaderArray< T >::At ( std::size_t idx)
inline

Definition at line 238 of file TTreeReaderArray.h.

◆ At() [2/2]

template<typename T>
const T & TTreeReaderArray< T >::At ( std::size_t idx) const
inline

Definition at line 239 of file TTreeReaderArray.h.

◆ begin() [1/2]

template<typename T>
iterator TTreeReaderArray< T >::begin ( )
inline

Definition at line 243 of file TTreeReaderArray.h.

◆ begin() [2/2]

template<typename T>
const_iterator TTreeReaderArray< T >::begin ( ) const
inline

Definition at line 245 of file TTreeReaderArray.h.

◆ cbegin()

template<typename T>
const_iterator TTreeReaderArray< T >::cbegin ( ) const
inline

Definition at line 247 of file TTreeReaderArray.h.

◆ cend()

template<typename T>
const_iterator TTreeReaderArray< T >::cend ( ) const
inline

Definition at line 248 of file TTreeReaderArray.h.

◆ CreateProxy()

void ROOT::Internal::TTreeReaderArrayBase::CreateProxy ( )
overrideprotectedvirtualinherited

Create the proxy object for our branch.

Reimplemented from ROOT::Internal::TTreeReaderValueBase.

Definition at line 534 of file TTreeReaderArray.cxx.

◆ end() [1/2]

template<typename T>
iterator TTreeReaderArray< T >::end ( )
inline

Definition at line 244 of file TTreeReaderArray.h.

◆ end() [2/2]

template<typename T>
const_iterator TTreeReaderArray< T >::end ( ) const
inline

Definition at line 246 of file TTreeReaderArray.h.

◆ ErrorAboutMissingProxyIfNeeded()

void ROOT::Internal::TTreeReaderValueBase::ErrorAboutMissingProxyIfNeeded ( )
protectedinherited

Definition at line 842 of file TTreeReaderValue.cxx.

◆ FillStreamerElementArrayInfo()

ROOT::Internal::TTreeReaderArrayBase::StreamerElementArrayInfo ROOT::Internal::TTreeReaderArrayBase::FillStreamerElementArrayInfo ( TStreamerElement * elem)
privateinherited

Definition at line 989 of file TTreeReaderArray.cxx.

◆ GetAddress()

void * ROOT::Internal::TTreeReaderValueBase::GetAddress ( )
inherited

Returns the memory address of the object being read.

Definition at line 266 of file TTreeReaderValue.cxx.

◆ GetBranchAndLeaf()

bool ROOT::Internal::TTreeReaderArrayBase::GetBranchAndLeaf ( TBranch *& branch,
TLeaf *& myLeaf,
TDictionary *& branchActualType,
bool suppressErrorsForMissingBranch = false )
protectedinherited

Determine the branch / leaf and its type; reset fProxy / fSetupStatus on error.

Definition at line 790 of file TTreeReaderArray.cxx.

◆ GetBranchContentDataType()

const char * ROOT::Internal::TTreeReaderArrayBase::GetBranchContentDataType ( TBranch * branch,
TString & contentTypeName,
TDictionary *& dict,
StreamerElementArrayInfo & arrInfo )
protectedinherited

Access a branch's collection content (not the collection itself) through a proxy.

Retrieve the type of data contained in the collection stored by branch; put its dictionary into dict, If there is no dictionary, put its type name into contentTypeName. The contentTypeName is set to NULL if the branch does not contain a collection; in that case, the type of the branch is returned. In all other cases, NULL is returned.

Definition at line 1016 of file TTreeReaderArray.cxx.

◆ GetBranchDataType()

const char * ROOT::Internal::TTreeReaderValueBase::GetBranchDataType ( TBranch * branch,
TDictionary *& dict,
TDictionary const * curDict )
staticprotectedinherited

Retrieve the type of data stored by branch; put its dictionary into dict, return its type name.

If no dictionary is available, at least its type name should be returned.

Definition at line 713 of file TTreeReaderValue.cxx.

◆ GetBranchName()

const char * ROOT::Internal::TTreeReaderValueBase::GetBranchName ( ) const
inlineinherited

Definition at line 101 of file TTreeReaderValue.h.

◆ GetDerivedTypeName()

template<typename T>
const char * TTreeReaderArray< T >::GetDerivedTypeName ( ) const
inlineoverrideprotectedvirtual

Implements ROOT::Internal::TTreeReaderValueBase.

Definition at line 252 of file TTreeReaderArray.h.

◆ GetElementTypeName()

std::string ROOT::Internal::TTreeReaderValueBase::GetElementTypeName ( const std::type_info & ti)
staticprotectedinherited

Stringify the template argument.

Definition at line 226 of file TTreeReaderValue.cxx.

◆ GetLeaf()

TLeaf * ROOT::Internal::TTreeReaderValueBase::GetLeaf ( )
inlineinherited

If we are reading a leaf, return the corresponding TLeaf.

Definition at line 97 of file TTreeReaderValue.h.

◆ GetProxy()

Detail::TBranchProxy * ROOT::Internal::TTreeReaderValueBase::GetProxy ( ) const
inlineprotectedinherited

Definition at line 119 of file TTreeReaderValue.h.

◆ GetReadStatus()

EReadStatus ROOT::Internal::TTreeReaderArrayBase::GetReadStatus ( ) const
inlineoverridevirtualinherited

Reimplemented from ROOT::Internal::TTreeReaderValueBase.

Definition at line 47 of file TTreeReaderArray.h.

◆ GetSetupStatus()

ESetupStatus ROOT::Internal::TTreeReaderValueBase::GetSetupStatus ( ) const
inlineinherited

Return this TTreeReaderValue's setup status.

Use this method to check e.g. whether the TTreeReaderValue is correctly setup and ready for reading.

Definition at line 93 of file TTreeReaderValue.h.

◆ GetSize()

std::size_t ROOT::Internal::TTreeReaderArrayBase::GetSize ( ) const
inlineinherited

Definition at line 44 of file TTreeReaderArray.h.

◆ GetValueSize()

std::size_t ROOT::Internal::TTreeReaderArrayBase::GetValueSize ( ) const
inlineinherited

Returns the sizeof of the collection value type. Returns 0 in case the value size could not be retrieved.

Definition at line 52 of file TTreeReaderArray.h.

◆ IsContiguous()

bool ROOT::Internal::TTreeReaderArrayBase::IsContiguous ( ) const
inlineinherited

Definition at line 49 of file TTreeReaderArray.h.

◆ IsEmpty()

bool ROOT::Internal::TTreeReaderArrayBase::IsEmpty ( ) const
inlineinherited

Definition at line 45 of file TTreeReaderArray.h.

◆ IsValid()

bool ROOT::Internal::TTreeReaderValueBase::IsValid ( ) const
inlineinherited

Return true if the branch was setup and read correctly.

Use GetSetupStatus() to only check the setup status.

Definition at line 90 of file TTreeReaderValue.h.

◆ MarkTreeReaderUnavailable()

void ROOT::Internal::TTreeReaderValueBase::MarkTreeReaderUnavailable ( )
inlineprotectedinherited

Definition at line 121 of file TTreeReaderValue.h.

◆ NotifyNewTree()

void ROOT::Internal::TTreeReaderValueBase::NotifyNewTree ( TTree * newTree)
protectedinherited

The TTreeReader has switched to a new TTree. Update the leaf.

Definition at line 238 of file TTreeReaderValue.cxx.

◆ operator[]() [1/2]

template<typename T>
T & TTreeReaderArray< T >::operator[] ( std::size_t idx)
inline

Definition at line 240 of file TTreeReaderArray.h.

◆ operator[]() [2/2]

template<typename T>
const T & TTreeReaderArray< T >::operator[] ( std::size_t idx) const
inline

Definition at line 241 of file TTreeReaderArray.h.

◆ ProxyRead()

EReadStatus ROOT::Internal::TTreeReaderValueBase::ProxyRead ( )
inlineinherited

Definition at line 80 of file TTreeReaderValue.h.

◆ ProxyReadDefaultImpl()

ROOT::Internal::TTreeReaderValueBase::EReadStatus ROOT::Internal::TTreeReaderValueBase::ProxyReadDefaultImpl ( )
inherited

Definition at line 158 of file TTreeReaderValue.cxx.

◆ ProxyReadTemplate()

ROOT::Internal::TTreeReaderValueBase::EReadStatus ROOT::Internal::TTreeReaderValueBase::ProxyReadTemplate ( )
inherited

Try to read the value from the TBranchProxy, returns the status of the read.

Definition at line 148 of file TTreeReaderValue.cxx.

◆ RegisterWithTreeReader()

void ROOT::Internal::TTreeReaderValueBase::RegisterWithTreeReader ( )
protectedinherited

Register with tree reader.

Definition at line 134 of file TTreeReaderValue.cxx.

◆ SearchBranchWithCompositeName()

TBranch * ROOT::Internal::TTreeReaderValueBase::SearchBranchWithCompositeName ( TLeaf *& myLeaf,
TDictionary *& branchActualType,
std::string & errMsg )
protectedinherited

Search a branch the name of which contains a ".".

Parameters
[out]myLeafThe leaf identified by the name if found (can be untouched).
[out]branchActualTypeDictionary associated to the type of the leaf (can be untouched).
[out]errMsgThe error message (can be untouched).
Returns
The address of the branch if found, nullptr otherwise This method allows to efficiently search for branches which have names which contain "dots", for example "w.v.a" or "v.a". Therefore, it allows to support names such as v.a where the branch was created with this syntax:
myTree->Branch("v", &v, "a/I:b:/I")
The method has some side effects, namely it can modify fSetupStatus, fProxy and fStaticClassOffsets/fHaveStaticClassOffsets.

Definition at line 315 of file TTreeReaderValue.cxx.

◆ SetImpl()

void ROOT::Internal::TTreeReaderArrayBase::SetImpl ( TBranch * branch,
TLeaf * myLeaf )
protectedinherited

Create the TVirtualCollectionReader object for our branch.

Definition at line 868 of file TTreeReaderArray.cxx.

◆ UntypedAt()

void * ROOT::Internal::TTreeReaderArrayBase::UntypedAt ( std::size_t idx) const
inlineprotectedinherited

Definition at line 55 of file TTreeReaderArray.h.

Member Data Documentation

◆ fBranchName

TString ROOT::Internal::TTreeReaderValueBase::fBranchName
protectedinherited

Name of the branch to read data from.

Definition at line 136 of file TTreeReaderValue.h.

◆ fDict

TDictionary* ROOT::Internal::TTreeReaderValueBase::fDict
protectedinherited

Type that the branch should contain.

Definition at line 139 of file TTreeReaderValue.h.

◆ fHaveLeaf

bool ROOT::Internal::TTreeReaderValueBase::fHaveLeaf
protectedinherited

Whether the data is in a leaf.

Definition at line 132 of file TTreeReaderValue.h.

◆ fHaveStaticClassOffsets

bool ROOT::Internal::TTreeReaderValueBase::fHaveStaticClassOffsets
protectedinherited

Whether !fStaticClassOffsets.empty().

Definition at line 133 of file TTreeReaderValue.h.

◆ fImpl

std::unique_ptr<TVirtualCollectionReader> ROOT::Internal::TTreeReaderArrayBase::fImpl
protectedinherited

Definition at line 63 of file TTreeReaderArray.h.

◆ fLeaf

TLeaf* ROOT::Internal::TTreeReaderValueBase::fLeaf = nullptr
protectedinherited

Definition at line 141 of file TTreeReaderValue.h.

◆ fLeafName

TString ROOT::Internal::TTreeReaderValueBase::fLeafName
protectedinherited

Definition at line 137 of file TTreeReaderValue.h.

◆ fOpaqueRead

bool ROOT::Internal::TTreeReaderValueBase::fOpaqueRead {false}
protectedinherited

If true, the reader will not do any type-checking against the actual type held by the branch.

Useful to just check if the current entry can be read or not without caring about its value.

Note
Only used by TTreeReaderOpaqueValue.

Definition at line 151 of file TTreeReaderValue.h.

◆ fProxy

Detail::TBranchProxy* ROOT::Internal::TTreeReaderValueBase::fProxy = nullptr
protectedinherited

Proxy for this branch, owned by TTreeReader.

Definition at line 140 of file TTreeReaderValue.h.

◆ fProxyReadFunc

Read_t ROOT::Internal::TTreeReaderValueBase::fProxyReadFunc = &TTreeReaderValueBase::ProxyReadDefaultImpl
protectedinherited

! Pointer to the Read implementation to use.

Definition at line 144 of file TTreeReaderValue.h.

◆ fReadStatus

EReadStatus ROOT::Internal::TTreeReaderValueBase::fReadStatus
protectedinherited

Read status of this data access.

Definition at line 134 of file TTreeReaderValue.h.

◆ fSetupStatus

ESetupStatus ROOT::Internal::TTreeReaderValueBase::fSetupStatus = kSetupNotSetup
protectedinherited

Setup status of this data access.

Definition at line 135 of file TTreeReaderValue.h.

◆ fStaticClassOffsets

std::vector<Long64_t> ROOT::Internal::TTreeReaderValueBase::fStaticClassOffsets
protectedinherited

Definition at line 142 of file TTreeReaderValue.h.

◆ fTreeReader

TTreeReader* ROOT::Internal::TTreeReaderValueBase::fTreeReader
protectedinherited

Tree reader we belong to.

Definition at line 138 of file TTreeReaderValue.h.


The documentation for this class was generated from the following file: