ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
xAOD::TAuxStore::TBranchHandle Class Reference

Class used internally to implement just-in-time reading. More...

Collaboration diagram for xAOD::TAuxStore::TBranchHandle:

Public Member Functions

 TBranchHandle (::Bool_t staticBranch, ::Bool_t primitiveBranch, const std::type_info *ti, void *obj, SG::auxid_t auxid, const std::string *prefix)
 Constructor. More...
 
::Int_t getEntry ()
 Get entry from the branch that was loaded with TTree::LoadTree() More...
 
::TBranch ** branchPtr ()
 Get a pointer to the branch being held. More...
 
void * objectPtr ()
 Get a pointer to the object. More...
 
void * inputObjectPtr ()
 Get a pointer to the object (or its pointer) in memory for reading. More...
 
void * outputObjectPtr ()
 Get a pointer to the object (or its pointer) in memory for writing. More...
 
const std::type_info * typeInfo () const
 Get the type of the variable in memory. More...
 
void reset ()
 Tell the object that the branch contents need to be re-read. More...
 

Private Attributes

::TBranch * m_branch
 The branch that this object is handling. More...
 
::Long64_t m_entry
 The last entry that was loaded for this branch. More...
 
void * m_object
 The pointer to the object in memory. More...
 
::Bool_t m_static
 Is this a static variable in question? More...
 
::Bool_t m_primitive
 Is this a primitive variable? More...
 
const std::type_info * m_typeInfo
 Type info for the variable. More...
 
::Bool_t m_needsRead
 Read status flag. More...
 
SG::auxid_t m_auxid
 The auxiliary ID of the branch. More...
 
const std::string * m_prefix
 Pointer to the m_prefix string of the parent object. More...
 

Detailed Description

Class used internally to implement just-in-time reading.

This is a much simplified version of the code that we used in the D3PDReader code to read variables just in time for the users.

Definition at line 260 of file TAuxStore.h.

Constructor & Destructor Documentation

◆ TBranchHandle()

xAOD::TAuxStore::TBranchHandle::TBranchHandle ( ::Bool_t  staticBranch,
::Bool_t  primitiveBranch,
const std::type_info *  ti,
void *  obj,
SG::auxid_t  auxid,
const std::string *  prefix 
)

Constructor.

Definition at line 1942 of file TAuxStore.cxx.

1947  : m_branch( 0 ), m_entry( 0 ) , m_object( obj ), m_static( staticBranch ),
1948  m_primitive( primitiveBranch ),
1949  m_typeInfo( ti ), m_needsRead( kTRUE ), m_auxid( auxid ),
1950  m_prefix( prefix ) {
1951  }

Member Function Documentation

◆ branchPtr()

TBranch ** xAOD::TAuxStore::TBranchHandle::branchPtr ( )

Get a pointer to the branch being held.

No magic here.

TTree::SetBranchAddress needs a pointer to a TBranch pointer. This function just makes sure that we can give it such a pointer, which will stay valid during the job.

Returns
A pointer to the branch object handled by this object

Definition at line 2039 of file TAuxStore.cxx.

2039  {
2040  return &m_branch;
2041  }

◆ getEntry()

Int_t xAOD::TAuxStore::TBranchHandle::getEntry ( )

Get entry from the branch that was loaded with TTree::LoadTree()

This function takes care of implementing just-in-time reading of branches for us.

Returns
The number of bytes read. A negative number in case of error.

Definition at line 1958 of file TAuxStore.cxx.

1958  {
1959 
1960  // A little sanity check:
1961  if( ! m_branch ) {
1962  // This is no longer an error. We can have such objects for
1963  // decorations, which don't exist on the input.
1964  return 0;
1965  }
1966 
1967  // Update the I/O monitoring:
1969 
1970  // Make sure that the branch is associated to a tree
1971  // as the entry to be read is retrieved from the tree
1972  if (!m_branch->GetTree()){
1973  Error("xAOD::TAuxStore::TBranchHandle::getEntry",
1974  XAOD_MESSAGE("Branch=%s is not associated to any tree while reading of branches within this class relies on that"),
1975  m_branch->GetName());
1976  return -1;
1977  }
1978 
1979  // Get the entry that should be read
1980  // The entry to be read is set with TTree::LoadTree()
1981  // NB: for a branch from a friend tree and if the friend tree has an index built,
1982  // then the entry to read is found when calling the TTree::LoadTree() function
1983  // that matches the major and minor values between the main tree and the friend tree
1984  ::Long64_t entry = m_branch->GetTree()->GetReadEntry();
1985 
1986  if ( entry < 0 ){
1987  // Raise error as it implies
1988  // either that the TTree::LoadTree() function has not been called
1989  // or
1990  // the entry requested to be read by the user
1991  // is not corresponding to any entry for the friend tree
1992  Error("xAOD::TAuxStore::TBranchHandle::getEntry",
1993  XAOD_MESSAGE( "Entry to read is not set for branch=%s from tree=%s. "
1994  "It is either because TTree::LoadTree(entry) was not called "
1995  "beforehand in the TEvent class OR "
1996  "the entry requested to be read for the main tree is not corresponding to an event for the friend tree"),
1997  m_branch->GetName(),
1998  m_branch->GetTree()->GetName());
1999  return -1;
2000  }
2001 
2002  // Check if anything needs to be done:
2003  if( ( entry == m_entry ) && ( ! m_needsRead ) ) {
2004  return 0;
2005  }
2006 
2007  // Switch the branch in the right mode:
2008  if( ! m_primitive ) {
2009  if( ( m_branch->GetMakeClass() != m_static ) &&
2010  ( ! m_branch->SetMakeClass( m_static ) ) ) {
2011  ::Error( "xAOD::TAuxStore::TBranchHandle::getEntry",
2012  XAOD_MESSAGE( "Failed to call SetMakeClass(%i) on "
2013  "branch \"%s\"" ),
2014  static_cast< int >( m_static ), m_branch->GetName() );
2015  return -1;
2016  }
2017  }
2018 
2019  // Load the entry.
2020  const ::Int_t nbytes = m_branch->GetEntry( entry );
2021 
2022  // If the load was successful, remember that we loaded this entry.
2023  if( nbytes >= 0 ) {
2024  m_entry = entry;
2025  // The reading will now be done:
2026  m_needsRead = kFALSE;
2027  }
2028 
2029  // Return the number of bytes read.
2030  return nbytes;
2031  }

◆ inputObjectPtr()

void * xAOD::TAuxStore::TBranchHandle::inputObjectPtr ( )

Get a pointer to the object (or its pointer) in memory for reading.

This is a tricky one.

When reading a single sub-branch of a branch that was written using an auxiliary container with direct ROOT I/O, TTree expects us to give it a simple pointer to the object that it should fill with content. But when reading a top level branch, like the dynamically created branches that we make, TTree needs to receive a pointer to a pointer.

Also, when reading a primitive type, ROOT also expects a simple pointer to the primitive variable in memory.

This function returns the correct kind of pointer for TTree::SetBranchAddress in all situations.

Returns
The pointer to be given to TTree::SetBranchAddress

Definition at line 2069 of file TAuxStore.cxx.

2069  {
2070 
2071  // Return the correct pointer:
2072  if( m_static || m_primitive ) {
2073  return m_object;
2074  } else {
2075  return &m_object;
2076  }
2077  }

◆ objectPtr()

void * xAOD::TAuxStore::TBranchHandle::objectPtr ( )

Get a pointer to the object.

This function is used in the implementation of the IAuxStoreIO interface.

In there we just need a simple pointer to the object, we don't care about ROOT's idiosyncracies.

Returns
A pointer to the object in memory

Definition at line 2049 of file TAuxStore.cxx.

2049  {
2050 
2051  return m_object;
2052  }

◆ outputObjectPtr()

void * xAOD::TAuxStore::TBranchHandle::outputObjectPtr ( )

Get a pointer to the object (or its pointer) in memory for writing.

This is a slightly simplified version of GetInputObjectPtr(), for the case when we need to write a branch, and have to pass a pointer to TTree::Branch.

In this case we don't need to be mindful of whether the variable was read as a static or dynamic variable. The only interesting thing is if the variable is of a primitive or an object type.

Returns
The pointer to be given to TTree::Branch

Definition at line 2088 of file TAuxStore.cxx.

2088  {
2089 
2090  // Return the correct pointer:
2091  if( m_primitive ) {
2092  return m_object;
2093  } else {
2094  return &m_object;
2095  }
2096  }

◆ reset()

void xAOD::TAuxStore::TBranchHandle::reset ( )

Tell the object that the branch contents need to be re-read.

After TEvent::Fill is called, the TAuxStore objects used for data writing are cleared.

Since TEvent doesn't know if the object is also used to read information or not. (If it's just used for writing, then this explicit clearing is mandatory.)

In case the user wants to continue processing the same event after the fill() call (because for instance the code is writing multiple trees), then we need to be aware that the variable needs to be re-read from the input to be in a good shape for the next write operation.

Definition at line 2114 of file TAuxStore.cxx.

2114  {
2115 
2116  m_needsRead = kTRUE;
2117  return;
2118  }

◆ typeInfo()

const std::type_info * xAOD::TAuxStore::TBranchHandle::typeInfo ( ) const

Get the type of the variable in memory.

Definition at line 2098 of file TAuxStore.cxx.

2098  {
2099 
2100  return m_typeInfo;
2101  }

Member Data Documentation

◆ m_auxid

SG::auxid_t xAOD::TAuxStore::TBranchHandle::m_auxid
private

The auxiliary ID of the branch.

Definition at line 299 of file TAuxStore.h.

◆ m_branch

::TBranch* xAOD::TAuxStore::TBranchHandle::m_branch
private

The branch that this object is handling.

Definition at line 285 of file TAuxStore.h.

◆ m_entry

::Long64_t xAOD::TAuxStore::TBranchHandle::m_entry
private

The last entry that was loaded for this branch.

Definition at line 287 of file TAuxStore.h.

◆ m_needsRead

::Bool_t xAOD::TAuxStore::TBranchHandle::m_needsRead
private

Read status flag.

Definition at line 297 of file TAuxStore.h.

◆ m_object

void* xAOD::TAuxStore::TBranchHandle::m_object
private

The pointer to the object in memory.

Definition at line 289 of file TAuxStore.h.

◆ m_prefix

const std::string* xAOD::TAuxStore::TBranchHandle::m_prefix
private

Pointer to the m_prefix string of the parent object.

Definition at line 301 of file TAuxStore.h.

◆ m_primitive

::Bool_t xAOD::TAuxStore::TBranchHandle::m_primitive
private

Is this a primitive variable?

Definition at line 293 of file TAuxStore.h.

◆ m_static

::Bool_t xAOD::TAuxStore::TBranchHandle::m_static
private

Is this a static variable in question?

Definition at line 291 of file TAuxStore.h.

◆ m_typeInfo

const std::type_info* xAOD::TAuxStore::TBranchHandle::m_typeInfo
private

Type info for the variable.

Definition at line 295 of file TAuxStore.h.


The documentation for this class was generated from the following files:
xAOD::TAuxStore::TBranchHandle::m_entry
::Long64_t m_entry
The last entry that was loaded for this branch.
Definition: TAuxStore.h:287
xAOD::TAuxStore::TBranchHandle::m_prefix
const std::string * m_prefix
Pointer to the m_prefix string of the parent object.
Definition: TAuxStore.h:301
xAOD::IOStats::stats
ReadStats & stats()
Access the object belonging to the current thread.
Definition: IOStats.cxx:17
xAOD::TAuxStore::TBranchHandle::m_primitive
::Bool_t m_primitive
Is this a primitive variable?
Definition: TAuxStore.h:293
xAOD::TAuxStore::TBranchHandle::m_branch
::TBranch * m_branch
The branch that this object is handling.
Definition: TAuxStore.h:285
XAOD_MESSAGE
#define XAOD_MESSAGE(MESSAGE)
Simple macro for printing error/verbose messages.
Definition: Control/xAODRootAccess/xAODRootAccess/tools/Message.h:19
xAOD::TAuxStore::TBranchHandle::m_object
void * m_object
The pointer to the object in memory.
Definition: TAuxStore.h:289
xAOD::IOStats::instance
static IOStats & instance()
Singleton object accessor.
Definition: IOStats.cxx:11
GetAllXsec.entry
list entry
Definition: GetAllXsec.py:132
xAOD::TAuxStore::TBranchHandle::m_auxid
SG::auxid_t m_auxid
The auxiliary ID of the branch.
Definition: TAuxStore.h:299
xAOD::TAuxStore::TBranchHandle::m_needsRead
::Bool_t m_needsRead
Read status flag.
Definition: TAuxStore.h:297
xAOD::TAuxStore::TBranchHandle::m_typeInfo
const std::type_info * m_typeInfo
Type info for the variable.
Definition: TAuxStore.h:295
xAOD::ReadStats::readBranch
void readBranch(const std::string &prefix, SG::auxid_t auxid)
Function incrementing the read counter on a specific branch.
L1Topo::Error
Error
The different types of error that can be flagged in the L1TopoRDO.
Definition: Error.h:16
xAOD::TAuxStore::TBranchHandle::m_static
::Bool_t m_static
Is this a static variable in question?
Definition: TAuxStore.h:291
python.PyAthena.obj
obj
Definition: PyAthena.py:135
xAOD::TAuxStore::prefix
const char * prefix() const
Get the currently configured branch name prefix.
Definition: TAuxStore.cxx:115