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

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

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

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

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

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