NAIA  1.0.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
Public Member Functions | Private Attributes | List of all members
NAIA::OnDemandContainer< T > Class Template Reference

Mixin class to add "read-on-demand" behavior to an existing container class. More...

#include <OnDemandContainer.h>

Public Member Functions

 OnDemandContainer ()=default
 
void LoadEvent ()
 Wrapper to call GetEntry on the underlying TBranch. More...
 
void SetTreeEntry (unsigned long long treeEntry)
 Set the TTree entry number. More...
 
void Branch (TTree *tree)
 Create the TBranch associated with this container. More...
 
void MirrorBranch (TTree *targetTree, const T *sourceContainer)
 Create a TBranch associated with this container mirroring from an existing container. More...
 
void SetBranchAddress (TTree *tree)
 Setup reading of the data container. More...
 
void DisableIO () const
 Disables I/O for this container. It won't be written on disk and trying to read it will cause an exception. More...
 
T * operator-> ()
 Access operator. Use this to access container data More...
 

Private Attributes

T * myPtrAddress
 
TBranch * m_branch = nullptr
 
unsigned long long m_treeEntry = std::numeric_limits<unsigned long long>::max()
 
bool m_cacheIsValid = false
 
bool m_ioEnabled = true
 

Detailed Description

template<class T>
class NAIA::OnDemandContainer< T >

Mixin class to add "read-on-demand" behavior to an existing container class.

This class is designed as a mixin so that every "data container" class can inherit from this using the CRTP pattern and have automatically enabled branch handling and cached reading from a TTree object.

Example of container definition (for production only): ```cpp class TofBaseData : public TObject; // the data-container class class TofBase : public OnDemandContainer<TofBase>, public TofBaseData; // CRTP mixin in action! ```

Exampe usage during analysis ```cpp for(size_t iEv=0; iEv < chain->GetEntries(); iEv++){ auto event = chain->GetEvent(iEv); // this calls SetTreeEntry betaHist->Fill( event.tofBase->Beta ); // this triggers "read-on-demand" due to use of operator-> } ```

NOTE: T class must have a static std::string BranchName. This is because multiple std::map insertion in the T "Data" corresponding class might write into private members of OnDemandContainer while writing, so BranchName can't be a non-static member or data layout might be screwed up. This shouldn't happen in read mode but it should be tested.

Template Parameters
T- the data container class

Definition at line 44 of file OnDemandContainer.h.

Constructor & Destructor Documentation

template<class T>
NAIA::OnDemandContainer< T >::OnDemandContainer ( )
default

Member Function Documentation

template<class T>
void NAIA::OnDemandContainer< T >::Branch ( TTree *  tree)
inline

Create the TBranch associated with this container.

Parameters
treeThe TTree hosting the TBranch

Definition at line 80 of file OnDemandContainer.h.

Referenced by NAIA::Event::BranchAll().

template<class T>
void NAIA::OnDemandContainer< T >::DisableIO ( ) const
inline

Disables I/O for this container. It won't be written on disk and trying to read it will cause an exception.

Definition at line 116 of file OnDemandContainer.h.

template<class T>
void NAIA::OnDemandContainer< T >::LoadEvent ( )
inline

Wrapper to call GetEntry on the underlying TBranch.

Check if event changed before calling GetEntry, otherwise return same event

Definition at line 54 of file OnDemandContainer.h.

Referenced by NAIA::Event::ForceReadAllBranches(), and NAIA::OnDemandContainer< RichBase >::operator->().

template<class T>
void NAIA::OnDemandContainer< T >::MirrorBranch ( TTree *  targetTree,
const T *  sourceContainer 
)
inline

Create a TBranch associated with this container mirroring from an existing container.

Parameters
treeThe TTree hosting the TBranch
sourceContainerThe container from which to read the data

Definition at line 91 of file OnDemandContainer.h.

Referenced by NAIA::Event::MirrorBranches().

template<class T>
T* NAIA::OnDemandContainer< T >::operator-> ( )
inline

Access operator. Use this to access container data

We overload the -> operator to wrap the data access and insert the "read-on-demand" behavior before the data access.

Returns
T* pointer to this, as it should be
Exceptions
std::runtime_errorif this container I/O capabilities have been disabled previously

Definition at line 127 of file OnDemandContainer.h.

template<class T>
void NAIA::OnDemandContainer< T >::SetBranchAddress ( TTree *  tree)
inline

Setup reading of the data container.

Parameters
treeThe input TTree

Definition at line 103 of file OnDemandContainer.h.

Referenced by NAIA::Event::SetAllBranchAddress().

template<class T>
void NAIA::OnDemandContainer< T >::SetTreeEntry ( unsigned long long  treeEntry)
inline

Set the TTree entry number.

Parameters
treeEntrythe TTree entry to be loaded

Definition at line 68 of file OnDemandContainer.h.

Referenced by NAIA::Event::SetEventNumber().

Member Data Documentation

template<class T>
TBranch* NAIA::OnDemandContainer< T >::m_branch = nullptr
private
template<class T>
bool NAIA::OnDemandContainer< T >::m_cacheIsValid = false
mutableprivate
template<class T>
bool NAIA::OnDemandContainer< T >::m_ioEnabled = true
mutableprivate
template<class T>
unsigned long long NAIA::OnDemandContainer< T >::m_treeEntry = std::numeric_limits<unsigned long long>::max()
private
template<class T>
T* NAIA::OnDemandContainer< T >::myPtrAddress
private

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