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

 ContainerBranchProcessor ()=default
virtual ~ContainerBranchProcessor ()=default
 ContainerBranchProcessor (const ContainerBranchProcessor &)=delete
ContainerBranchProcessoroperator= (const ContainerBranchProcessor &)=delete
virtual StatusCode setup (TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg) override
 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.
virtual StatusCode setup (ROOT::RNTupleModel &, const BranchConfig &, OutputBranchData &, MsgStream &msg) override

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 303 of file TreeBranchHelpers.h.

Constructor & Destructor Documentation

◆ ContainerBranchProcessor() [1/2]

CP::TreeBranchHelpers::ContainerBranchProcessor::ContainerBranchProcessor ( )
default

◆ ~ContainerBranchProcessor()

virtual CP::TreeBranchHelpers::ContainerBranchProcessor::~ContainerBranchProcessor ( )
virtualdefault

◆ ContainerBranchProcessor() [2/2]

CP::TreeBranchHelpers::ContainerBranchProcessor::ContainerBranchProcessor ( const ContainerBranchProcessor & )
delete

Member Function Documentation

◆ operator=()

ContainerBranchProcessor & CP::TreeBranchHelpers::ContainerBranchProcessor::operator= ( const ContainerBranchProcessor & )
delete

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

805 {
806
807 // A security check.
808 if( ( ! m_acc ) || ( ! m_factory ) || ( ! m_data ) ) {
809 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
810 return StatusCode::FAILURE;
811 }
812
813 // Get the data out of the xAOD object.
814 //const void* auxData = ( *m_acc )( element );
815
816 // Copy it into the output variable.
817 TempInterface dstiface (m_data->size(), m_acc->auxid(), m_data->toPtr());
818 m_factory->copy( m_acc->auxid(), dstiface, index,
819 *element.container(), element.index(), 1 );
820
821 // Return gracefully.
822 return StatusCode::SUCCESS;
823 }
#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.
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 787 of file TreeBranchHelpers.cxx.

788 {
789
790 // A security check.
791 if( ! m_data ) {
792 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
793 return StatusCode::FAILURE;
794 }
795
796 // Do the deed.
797 m_data->resize( 0 );
798 m_data->resize( size );
799
800 // Return gracefully.
801 return StatusCode::SUCCESS;
802 }
size_t size() const
Number of registered mappings.

◆ setup() [1/2]

StatusCode CP::TreeBranchHelpers::ContainerBranchProcessor::setup ( ROOT::RNTupleModel & ,
const BranchConfig & ,
OutputBranchData & ,
MsgStream & msg )
overridevirtual

Implements CP::TreeBranchHelpers::IComponentProcessor.

Definition at line 825 of file TreeBranchHelpers.cxx.

826 {
827 msg << MSG::ERROR << "ContainerBranchProcessor::setup for RNTuple should not be called" << endmsg;
828 return StatusCode::FAILURE;
829 }

◆ setup() [2/2]

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

Function setting up the object, and the branch.

Implements CP::TreeBranchHelpers::IComponentProcessor.

Definition at line 737 of file TreeBranchHelpers.cxx.

738 {
739
740 // Remember the branch name.
741 m_branchName = outputData.branchName;
742
743 // Create the accessor.
744 m_acc.reset( new SG::TypelessConstAccessor( *branchConfig.auxType, outputData.auxName ) );
745
746 // Get a pointer to the vector factory.
747 m_factory = branchConfig.auxFactory;
748
749 // Create the data object.
750 m_data = m_factory->create( m_acc->auxid(), 0, 0, false );
751
752 // Get a proper type name for the variable.
753 const std::string typeName = SG::normalizedTypeinfoName( *branchConfig.auxVecType );
754
755 // Access the dictionary for the type.
756 TClass* cl = TClass::GetClass( *branchConfig.auxVecType );
757 if( ! cl ) {
758 cl = TClass::GetClass( typeName.c_str() );
759 }
760 if( ! cl ) {
761 msg << MSG::ERROR << "Couldn't find dictionary for type: "
762 << typeName << endmsg;
763 return StatusCode::FAILURE;
764 }
765 if( ! cl->GetStreamerInfo() ) {
766 msg << MSG::ERROR << "No streamer info available for type: "
767 << cl->GetName() << endmsg;
768 return StatusCode::FAILURE;
769 }
770
771 // Create the branch.
772 m_dataPtr = m_data->toVector();
773 TBranch* br = tree.Branch( outputData.branchName.c_str(), cl->GetName(),
774 &m_dataPtr );
775 if( ! br ) {
776 msg << MSG::ERROR << "Failed to create branch: " << outputData.branchName
777 << endmsg;
778 return StatusCode::FAILURE;
779 }
780 if (branchConfig.basketSize.has_value())
781 br->SetBasketSize(branchConfig.basketSize.value());
782
783 // Return gracefully.
784 return StatusCode::SUCCESS;
785 }
std::string m_branchName
Name of the branch being written.
void * m_dataPtr
Helper variable, pointing at the object to be written.
ConstAuxElement::TypelessConstAccessor TypelessConstAccessor
Definition AuxElement.h:567
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 322 of file TreeBranchHelpers.h.

◆ m_branchName

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

Name of the branch being written.

Definition at line 320 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 326 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 328 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 324 of file TreeBranchHelpers.h.


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