ATLAS Offline Software
Loading...
Searching...
No Matches
CP::TreeBranchHelpers::ElementBranchProcessor Class Reference

Class writing one variable from an xAOD object into a branch. More...

#include <TreeBranchHelpers.h>

Inheritance diagram for CP::TreeBranchHelpers::ElementBranchProcessor:
Collaboration diagram for CP::TreeBranchHelpers::ElementBranchProcessor:

Public Member Functions

 ElementBranchProcessor ()=default
virtual ~ElementBranchProcessor ()=default
 ElementBranchProcessor (const ElementBranchProcessor &)=delete
ElementBranchProcessor & operator= (const ElementBranchProcessor &)=delete
virtual StatusCode setup (TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData, MsgStream &msg) override
 Function setting up the object, and the branch.
virtual StatusCode setup (ROOT::RNTupleModel &, const BranchConfig &, OutputBranchData &, MsgStream &msg) override
StatusCode process (const SG::AuxElement &element, 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::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.

Definition at line 226 of file TreeBranchHelpers.h.

Constructor & Destructor Documentation

◆ ElementBranchProcessor() [1/2]

CP::TreeBranchHelpers::ElementBranchProcessor::ElementBranchProcessor ( )
default

◆ ~ElementBranchProcessor()

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

◆ ElementBranchProcessor() [2/2]

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

Member Function Documentation

◆ operator=()

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

◆ process()

StatusCode CP::TreeBranchHelpers::ElementBranchProcessor::process ( const SG::AuxElement & element,
MsgStream & msg )

Function processing the object, filling the variable.

This function is called by ElementProcessorRegular, to extract one variable from the standalone object, and move its payload into the memory address from which the output tree is writing its branch.

Parameters
elementThe standalone object to get the auxiliary variable from
msgReference to the parent's MsgStream object
Returns
The usual StatusCode values

Definition at line 729 of file TreeBranchHelpers.cxx.

730 {
731
732 // A security check.
733 if( ( ! m_acc ) || ( ! m_factory ) || ( ! m_data ) ) {
734 msg << MSG::FATAL << "Internal logic error detected" << endmsg;
735 return StatusCode::FAILURE;
736 }
737
738 // Copy it into the output variable.
739 TempInterface dstiface (m_data->size(), m_acc->auxid(), m_data->toPtr());
740 m_factory->copy( m_acc->auxid(), dstiface, 0,
741 *element.container(), element.index(), 1 );
742
743 // Return gracefully.
744 return StatusCode::SUCCESS;
745 }
#define endmsg
std::unique_ptr< SG::IAuxTypeVector > m_data
The object managing the memory of the written variable.
const SG::IAuxTypeVectorFactory * m_factory
Pointer to the helper object that handles this variable.
std::unique_ptr< SG::TypelessConstAccessor > m_acc
Object accessing the variable in question.
MsgStream & msg
Definition testRead.cxx:32

◆ setup() [1/2]

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

Implements CP::TreeBranchHelpers::IComponentProcessor.

Definition at line 747 of file TreeBranchHelpers.cxx.

748 {
749 msg << MSG::ERROR << "ElementBranchProcessor::setup for RNTuple should not be called" << endmsg;
750 return StatusCode::FAILURE;
751 }

◆ setup() [2/2]

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

Function setting up the object, and the branch.

This is pretty much the constructor of the class. I just decided to implement it as a regular function and not a "real" constructor, to be able to return a StatusCode value from the call. Since the setup of the object may very well fail.

Parameters
treeThe tree to set up the new branch in
auxNameThe name of the auxiliary variable to create a branch from
branchNameName of the branch to create in the tree
msgReference to the parent's MsgStream object
Returns
The usual StatusCode values

Implements CP::TreeBranchHelpers::IComponentProcessor.

Definition at line 638 of file TreeBranchHelpers.cxx.

639 {
640
641 // Remember the branch name.
642 m_branchName = outputData.branchName;
643
644 // Create the accessor.
645 m_acc = std::make_unique<SG::TypelessConstAccessor>( *branchConfig.auxType, outputData.auxName );
646
647 // Get a pointer to the vector factory.
648 m_factory = branchConfig.auxFactory;
649
650 // Create the data object.
651 m_data = m_factory->create( m_acc->auxid(), 1, 1, false );
652
653 // Pointer to the branch, to be created.
654 TBranch* br = nullptr;
655
656 // Decide whether we're dealing with a "primitive" or an "object" branch.
657 if( strlen( branchConfig.auxType->name() ) == 1 ) {
658
659 // This is a "primitive" variable...
660
661 // Get the type identifier for it that ROOT will understand.
662 const char rType = rootType( branchConfig.auxType->name()[ 0 ], msg );
663 if( rType == '\0' ) {
664 msg << MSG::ERROR << "Type not recognised for variable: "
665 << outputData.branchName << endmsg;
666 return StatusCode::FAILURE;
667 }
668
669 // Construct the type description.
670 std::ostringstream typeDesc;
671 typeDesc << outputData.branchName << "/" << rType;
672
673 // Create the primitive branch.
674 br = tree.Branch( outputData.branchName.c_str(), m_data->toPtr(),
675 typeDesc.str().c_str() );
676 // Check that the branch creation succeeded.
677 if( ! br ) {
678 msg << MSG::ERROR << "Failed to create branch: " << outputData.branchName
679 << endmsg;
680 return StatusCode::FAILURE;
681 }
682
683 if (branchConfig.basketSize.has_value())
684 br->SetBasketSize(branchConfig.basketSize.value());
685
686 } else {
687
688 // This is an "object" variable...
689
690 // Get a proper type name for the variable.
691 const std::string typeName = SG::normalizedTypeinfoName( *branchConfig.auxType );
692
693 // Access the dictionary for the type.
694 TClass* cl = TClass::GetClass( *branchConfig.auxType );
695 if( ! cl ) {
696 cl = TClass::GetClass( typeName.c_str() );
697 }
698 if( ! cl ) {
699 msg << MSG::ERROR << "Couldn't find dictionary for type: "
700 << typeName << endmsg;
701 return StatusCode::FAILURE;
702 }
703 if( ! cl->GetStreamerInfo() ) {
704 msg << MSG::ERROR << "No streamer info available for type: "
705 << cl->GetName() << endmsg;
706 return StatusCode::FAILURE;
707 }
708
709 // Create the object branch.
710 m_dataPtr = m_data->toPtr();
711 br = tree.Branch( outputData.branchName.c_str(), cl->GetName(), &m_dataPtr );
712 // Check that the branch creation succeeded.
713 if( ! br ) {
714 msg << MSG::ERROR << "Failed to create branch: " << outputData.branchName
715 << endmsg;
716 return StatusCode::FAILURE;
717 }
718
719 if (branchConfig.basketSize.has_value())
720 br->SetBasketSize(branchConfig.basketSize.value());
721
722 }
723
724 // Return gracefully.
725 return StatusCode::SUCCESS;
726 }
void * m_dataPtr
Helper variable, pointing at the object to be written.
std::string m_branchName
Name of the branch being 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()) ]
char rootType(char typeidType)
This function is used internally in the code when creating primitive dynamic auxiliary branches.
TChain * tree

Member Data Documentation

◆ m_acc

std::unique_ptr< SG::TypelessConstAccessor > CP::TreeBranchHelpers::ElementBranchProcessor::m_acc

Object accessing the variable in question.

Definition at line 271 of file TreeBranchHelpers.h.

◆ m_branchName

std::string CP::TreeBranchHelpers::ElementBranchProcessor::m_branchName

Name of the branch being written.

Definition at line 269 of file TreeBranchHelpers.h.

◆ m_data

std::unique_ptr< SG::IAuxTypeVector > CP::TreeBranchHelpers::ElementBranchProcessor::m_data

The object managing the memory of the written variable.

Definition at line 275 of file TreeBranchHelpers.h.

◆ m_dataPtr

void* CP::TreeBranchHelpers::ElementBranchProcessor::m_dataPtr = nullptr

Helper variable, pointing at the object to be written.

Definition at line 277 of file TreeBranchHelpers.h.

◆ m_factory

const SG::IAuxTypeVectorFactory* CP::TreeBranchHelpers::ElementBranchProcessor::m_factory = nullptr

Pointer to the helper object that handles this variable.

Definition at line 273 of file TreeBranchHelpers.h.


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