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

template<typename T>
class TTreeReaderValue< T >

An interface for reading values stored in ROOT columnar datasets.

The TTreeReaderValue is a type-safe tool to be used in association with a TTreeReader to access the values stored in TTree, TNtuple and TChain datasets. TTreeReaderValue can be also used to access collections such as std::vectors or TClonesArray stored in columnar datasets but it is recommended to use TTreeReaderArray instead as it offers several advantages.

See the documentation of TTreeReader for more details and examples.

Definition at line 174 of file TTreeReaderValue.h.

Public Types

using NonConstT_t = typename std::remove_const< T >::type
 
- Public Types inherited from ROOT::Internal::TTreeReaderValueBase
typedef bool(ROOT::Detail::TBranchProxy::* BranchProxyRead_t) ()
 
enum  EReadStatus { kReadSuccess = 0 , kReadNothingYet , kReadError }
 
enum  ESetupStatus {
  kSetupNotSetup = -7 , kSetupTreeDestructed = -8 , kSetupMakeClassModeMismatch = -9 , kSetupMissingCounterBranch = -6 ,
  kSetupMissingBranch = -5 , kSetupInternalError = -4 , kSetupMissingDictionary = -3 , kSetupMismatch = -2 ,
  kSetupNotACollection = -1 , kSetupMatch = 0 , kSetupMatchBranch = 7 , kSetupNoCheck = 5 ,
  kSetupMatchLeaf = 6
}
 Status flags, 0 is good. More...
 

Public Member Functions

 TTreeReaderValue ()=delete
 
 TTreeReaderValue (TTreeReader &tr, const char *branchname)
 
T * Get ()
 Return a pointer to the value of the current entry.
 
T & operator* ()
 Return a reference to the value of the current entry.
 
T * operator-> ()
 Return a pointer to the value of the current entry.
 
- Public Member Functions inherited from ROOT::Internal::TTreeReaderValueBase
virtual ~TTreeReaderValueBase ()
 Unregister from tree reader, cleanup.
 
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.
 
virtual EReadStatus GetReadStatus () const
 
ESetupStatus GetSetupStatus () const
 Return this TTreeReaderValue's setup status.
 
bool IsValid () const
 Return true if the branch was setup and read correctly.
 
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 Member Functions

const char * GetDerivedTypeName () const override
 Get the template argument as a string.
 
- Protected Member Functions inherited from ROOT::Internal::TTreeReaderValueBase
 TTreeReaderValueBase (const TTreeReaderValueBase &)
 Copy-construct.
 
 TTreeReaderValueBase (TTreeReader *reader, const char *branchname, TDictionary *dict, bool opaqueRead=false)
 Construct a tree value reader and register it with the reader object.
 
virtual void CreateProxy ()
 Create the proxy object for our branch.
 
void ErrorAboutMissingProxyIfNeeded ()
 
Detail::TBranchProxyGetProxy () const
 
void MarkTreeReaderUnavailable ()
 
void NotifyNewTree (TTree *newTree)
 The TTreeReader has switched to a new TTree. Update the leaf.
 
TTreeReaderValueBaseoperator= (const TTreeReaderValueBase &)
 Copy-assign.
 
void RegisterWithTreeReader ()
 Register with tree reader.
 
TBranchSearchBranchWithCompositeName (TLeaf *&myleaf, TDictionary *&branchActualType, std::string &err)
 Search a branch the name of which contains a ".".
 

Additional Inherited Members

- Protected Types inherited from ROOT::Internal::TTreeReaderValueBase
typedef EReadStatus(TTreeReaderValueBase::* Read_t) ()
 
- Static Protected Member Functions inherited from ROOT::Internal::TTreeReaderValueBase
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 inherited from ROOT::Internal::TTreeReaderValueBase
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()
 
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::TBranchProxyfProxy = 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.
 

#include <TTreeReaderValue.h>

Inheritance diagram for TTreeReaderValue< T >:
[legend]

Member Typedef Documentation

◆ NonConstT_t

template<typename T >
using TTreeReaderValue< T >::NonConstT_t = typename std::remove_const<T>::type

Definition at line 178 of file TTreeReaderValue.h.

Constructor & Destructor Documentation

◆ TTreeReaderValue() [1/2]

template<typename T >
TTreeReaderValue< T >::TTreeReaderValue ( )
delete

◆ TTreeReaderValue() [2/2]

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

Definition at line 180 of file TTreeReaderValue.h.

Member Function Documentation

◆ Get()

template<typename T >
T * TTreeReaderValue< T >::Get ( )
inline

Return a pointer to the value of the current entry.

Return a nullptr and print an error if no entry has been loaded yet. The returned address is guaranteed to stay constant while a given TTree is being read from a given file, unless the branch addresses are manipulated directly (e.g. through TTree::SetBranchAddress()). The address might also change when the underlying TTree/TFile is switched, e.g. when a TChain switches files.

Definition at line 189 of file TTreeReaderValue.h.

◆ GetDerivedTypeName()

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

Get the template argument as a string.

Implements ROOT::Internal::TTreeReaderValueBase.

Definition at line 211 of file TTreeReaderValue.h.

◆ operator*()

template<typename T >
T & TTreeReaderValue< T >::operator* ( )
inline

Return a reference to the value of the current entry.

Equivalent to dereferencing the pointer returned by Get(). Behavior is undefined if no entry has been loaded yet. Most likely a crash will occur.

Definition at line 206 of file TTreeReaderValue.h.

◆ operator->()

template<typename T >
T * TTreeReaderValue< T >::operator-> ( )
inline

Return a pointer to the value of the current entry.

Equivalent to Get().

Definition at line 201 of file TTreeReaderValue.h.

  • tree/treeplayer/inc/TTreeReaderValue.h