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
ContainerBranchProcessor & operator= (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::TypelessConstAccessor > m_acc
 Object accessing the variable in question.
const SG::IAuxTypeVectorFactory * m_factory = nullptr
 Pointer to the helper object that handles this variable.
std::unique_ptr< SG::IAuxTypeVector > m_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 304 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 820 of file TreeBranchHelpers.cxx.

821 {
822
823 // A security check.
824 if( ( ! m_acc ) || ( ! m_factory ) || ( ! m_data ) ) {
825 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
826 return StatusCode::FAILURE;
827 }
828
829 // Copy it into the output variable.
830 TempInterface dstiface (m_data->size(), m_acc->auxid(), m_data->toPtr());
831 m_factory->copy( m_acc->auxid(), dstiface, index,
832 *element.container(), element.index(), 1 );
833
834 // Return gracefully.
835 return StatusCode::SUCCESS;
836 }
#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 803 of file TreeBranchHelpers.cxx.

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

839 {
840 msg << MSG::ERROR << "ContainerBranchProcessor::setup for RNTuple should not be called" << endmsg;
841 return StatusCode::FAILURE;
842 }

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

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

◆ m_branchName

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

Name of the branch being written.

Definition at line 321 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 327 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 329 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 325 of file TreeBranchHelpers.h.


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