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

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

796 {
797
798 // A security check.
799 if( ! m_data ) {
800 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
801 return StatusCode::FAILURE;
802 }
803
804 // Do the deed.
805 m_data->resize( 0 );
806 m_data->resize( size );
807
808 // Return gracefully.
809 return StatusCode::SUCCESS;
810 }
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 833 of file TreeBranchHelpers.cxx.

834 {
835 msg << MSG::ERROR << "ContainerBranchProcessor::setup for RNTuple should not be called" << endmsg;
836 return StatusCode::FAILURE;
837 }

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

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