ATLAS Offline Software
Loading...
Searching...
No Matches
CP::TreeBranchHelpers::ContainerBranchProcessor Class Reference

Class writing one variable from an xAOD object into a branch. More...

#include <TreeBranchHelpers.h>

Inheritance diagram for CP::TreeBranchHelpers::ContainerBranchProcessor:
Collaboration diagram for CP::TreeBranchHelpers::ContainerBranchProcessor:

Public Member Functions

StatusCode setup (TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg)
 Function setting up the object, and the branch.
StatusCode resize (size_t size, MsgStream &msg)
 Function (re)sizing the variable for a new event.
StatusCode process (const SG::AuxElement &element, size_t index, MsgStream &msg)
 Function processing the object, filling the variable.

Public Attributes

std::string m_branchName
 Name of the branch being written.
std::unique_ptr< SG::TypelessConstAccessorm_acc
 Object accessing the variable in question.
const SG::IAuxTypeVectorFactorym_factory = nullptr
 Pointer to the helper object that handles this variable.
std::unique_ptr< SG::IAuxTypeVectorm_data
 The object managing the memory of the written variable.
void * m_dataPtr = nullptr
 Helper variable, pointing at the object to be written.

Detailed Description

Class writing one variable from an xAOD object into a branch.

It is used for both setting up the branch in the outut TTree during the setup of the tree, and then to fill the "output variable" with the right payload during the event processing.

Note that since we may have a lot of such objects, I didn't want to make it inherit from asg::AsgMessaging. Which means that all of the class's functions need to receive its parent's message stream object to be able to log error messages "nicely".

Also note that since this is very much an internal class, all of its members are public. Since the owner of such objects should know perfectly well how they behave.

Finally, note that it is more complicated than the ElementBranchProcessor class. Since in this case we need to explicitly deal with std::vector types, which we need to fill explicitly when extracting the variables from the xAOD objects.

Definition at line 285 of file TreeBranchHelpers.h.

Member Function Documentation

◆ process()

StatusCode CP::TreeBranchHelpers::ContainerBranchProcessor::process ( const SG::AuxElement & element,
size_t index,
MsgStream & msg )

Function processing the object, filling the variable.

Definition at line 733 of file TreeBranchHelpers.cxx.

734 {
735
736 // A security check.
737 if( ( ! m_acc ) || ( ! m_factory ) || ( ! m_data ) ) {
738 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
739 return StatusCode::FAILURE;
740 }
741
742 // Get the data out of the xAOD object.
743 //const void* auxData = ( *m_acc )( element );
744
745 // Copy it into the output variable.
746 TempInterface dstiface (m_data->size(), m_acc->auxid(), m_data->toPtr());
747 m_factory->copy( m_acc->auxid(), dstiface, index,
748 *element.container(), element.index(), 1 );
749
750 // Return gracefully.
751 return StatusCode::SUCCESS;
752 }
#define endmsg
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
std::unique_ptr< SG::TypelessConstAccessor > m_acc
Object accessing the variable in question.
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
const SG::AuxVectorData * container() const
Return the container holding this element.
size_t index() const
Return the index of this element within its container.
MsgStream & msg
Definition testRead.cxx:32

◆ resize()

StatusCode CP::TreeBranchHelpers::ContainerBranchProcessor::resize ( size_t size,
MsgStream & msg )

Function (re)sizing the variable for a new event.

Definition at line 716 of file TreeBranchHelpers.cxx.

717 {
718
719 // A security check.
720 if( ! m_data ) {
721 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
722 return StatusCode::FAILURE;
723 }
724
725 // Do the deed.
726 m_data->resize( 0 );
727 m_data->resize( size );
728
729 // Return gracefully.
730 return StatusCode::SUCCESS;
731 }

◆ setup()

StatusCode CP::TreeBranchHelpers::ContainerBranchProcessor::setup ( TTree & tree,
const BranchConfig & branchConfig,
OutputBranchData & outputData,
MsgStream & msg )

Function setting up the object, and the branch.

Definition at line 668 of file TreeBranchHelpers.cxx.

669 {
670
671 // Remember the branch name.
672 m_branchName = outputData.branchName;
673
674 // Create the accessor.
675 m_acc.reset( new SG::TypelessConstAccessor( *branchConfig.auxType, outputData.auxName ) );
676
677 // Get a pointer to the vector factory.
678 m_factory = branchConfig.auxFactory;
679
680 // Create the data object.
681 m_data = m_factory->create( m_acc->auxid(), 0, 0, false );
682
683 // Get a proper type name for the variable.
684 const std::string typeName = SG::normalizedTypeinfoName( *branchConfig.auxVecType );
685
686 // Access the dictionary for the type.
687 TClass* cl = TClass::GetClass( *branchConfig.auxVecType );
688 if( ! cl ) {
689 cl = TClass::GetClass( typeName.c_str() );
690 }
691 if( ! cl ) {
692 msg << MSG::ERROR << "Couldn't find dictionary for type: "
693 << typeName << endmsg;
694 return StatusCode::FAILURE;
695 }
696 if( ! cl->GetStreamerInfo() ) {
697 msg << MSG::ERROR << "No streamer info available for type: "
698 << cl->GetName() << endmsg;
699 return StatusCode::FAILURE;
700 }
701
702 // Create the branch.
703 m_dataPtr = m_data->toVector();
704 TBranch* br = tree.Branch( outputData.branchName.c_str(), cl->GetName(),
705 &m_dataPtr );
706 if( ! br ) {
707 msg << MSG::ERROR << "Failed to create branch: " << outputData.branchName
708 << endmsg;
709 return StatusCode::FAILURE;
710 }
711
712 // Return gracefully.
713 return StatusCode::SUCCESS;
714 }
std::string m_branchName
Name of the branch being written.
void * m_dataPtr
Helper variable, pointing at the object to be written.
std::string normalizedTypeinfoName(const std::type_info &info)
Convert a type_info to a normalized string representation (matching the names used in the root dictio...
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
TChain * tree

Member Data Documentation

◆ m_acc

std::unique_ptr< SG::TypelessConstAccessor > CP::TreeBranchHelpers::ContainerBranchProcessor::m_acc

Object accessing the variable in question.

Definition at line 299 of file TreeBranchHelpers.h.

◆ m_branchName

std::string CP::TreeBranchHelpers::ContainerBranchProcessor::m_branchName

Name of the branch being written.

Definition at line 297 of file TreeBranchHelpers.h.

◆ m_data

std::unique_ptr< SG::IAuxTypeVector > CP::TreeBranchHelpers::ContainerBranchProcessor::m_data

The object managing the memory of the written variable.

Definition at line 303 of file TreeBranchHelpers.h.

◆ m_dataPtr

void* CP::TreeBranchHelpers::ContainerBranchProcessor::m_dataPtr = nullptr

Helper variable, pointing at the object to be written.

Definition at line 305 of file TreeBranchHelpers.h.

◆ m_factory

const SG::IAuxTypeVectorFactory* CP::TreeBranchHelpers::ContainerBranchProcessor::m_factory = nullptr

Pointer to the helper object that handles this variable.

Definition at line 301 of file TreeBranchHelpers.h.


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