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 288 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 771 of file TreeBranchHelpers.cxx.

772 {
773
774 // A security check.
775 if( ( ! m_acc ) || ( ! m_factory ) || ( ! m_data ) ) {
776 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
777 return StatusCode::FAILURE;
778 }
779
780 // Get the data out of the xAOD object.
781 //const void* auxData = ( *m_acc )( element );
782
783 // Copy it into the output variable.
784 TempInterface dstiface (m_data->size(), m_acc->auxid(), m_data->toPtr());
785 m_factory->copy( m_acc->auxid(), dstiface, index,
786 *element.container(), element.index(), 1 );
787
788 // Return gracefully.
789 return StatusCode::SUCCESS;
790 }
#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 754 of file TreeBranchHelpers.cxx.

755 {
756
757 // A security check.
758 if( ! m_data ) {
759 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
760 return StatusCode::FAILURE;
761 }
762
763 // Do the deed.
764 m_data->resize( 0 );
765 m_data->resize( size );
766
767 // Return gracefully.
768 return StatusCode::SUCCESS;
769 }

◆ 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 704 of file TreeBranchHelpers.cxx.

705 {
706
707 // Remember the branch name.
708 m_branchName = outputData.branchName;
709
710 // Create the accessor.
711 m_acc.reset( new SG::TypelessConstAccessor( *branchConfig.auxType, outputData.auxName ) );
712
713 // Get a pointer to the vector factory.
714 m_factory = branchConfig.auxFactory;
715
716 // Create the data object.
717 m_data = m_factory->create( m_acc->auxid(), 0, 0, false );
718
719 // Get a proper type name for the variable.
720 const std::string typeName = SG::normalizedTypeinfoName( *branchConfig.auxVecType );
721
722 // Access the dictionary for the type.
723 TClass* cl = TClass::GetClass( *branchConfig.auxVecType );
724 if( ! cl ) {
725 cl = TClass::GetClass( typeName.c_str() );
726 }
727 if( ! cl ) {
728 msg << MSG::ERROR << "Couldn't find dictionary for type: "
729 << typeName << endmsg;
730 return StatusCode::FAILURE;
731 }
732 if( ! cl->GetStreamerInfo() ) {
733 msg << MSG::ERROR << "No streamer info available for type: "
734 << cl->GetName() << endmsg;
735 return StatusCode::FAILURE;
736 }
737
738 // Create the branch.
739 m_dataPtr = m_data->toVector();
740 TBranch* br = tree.Branch( outputData.branchName.c_str(), cl->GetName(),
741 &m_dataPtr );
742 if( ! br ) {
743 msg << MSG::ERROR << "Failed to create branch: " << outputData.branchName
744 << endmsg;
745 return StatusCode::FAILURE;
746 }
747 if (branchConfig.basketSize.has_value())
748 br->SetBasketSize(branchConfig.basketSize.value());
749
750 // Return gracefully.
751 return StatusCode::SUCCESS;
752 }
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 302 of file TreeBranchHelpers.h.

◆ m_branchName

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

Name of the branch being written.

Definition at line 300 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 306 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 308 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 304 of file TreeBranchHelpers.h.


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