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

Class writing all variables from one DataVector container. More...

#include <TreeBranchHelpers.h>

Inheritance diagram for CP::TreeBranchHelpers::ContainerProcessorRegular:
Collaboration diagram for CP::TreeBranchHelpers::ContainerProcessorRegular:

Public Member Functions

 ContainerProcessorRegular (const std::string &sgName)
 Default constructor.
virtual ~ContainerProcessorRegular ()=default
 ContainerProcessorRegular (const ContainerProcessorRegular &)=delete
ContainerProcessorRegularoperator= (const ContainerProcessorRegular &)=delete
virtual StatusCode retrieveProcess (StoreType &evtStore) override
 retrieve and process the object
virtual StatusCode addBranch (TTree &tree, const BranchConfig &branchConfig, OutputBranchData &outputData) override
 Add one branch to the output tree.
virtual StatusCode addBranch (ROOT::RNTupleModel &model, const BranchConfig &branchConfig, OutputBranchData &outputData) override
void setLevel (MSG::Level lvl)
 Change the current logging level.
Functions providing the same interface as AthMessaging
bool msgLvl (const MSG::Level lvl) const
 Test the output level of the object.
MsgStream & msg () const
 The standard message stream.
MsgStream & msg (const MSG::Level lvl) const
 The standard message stream.

Private Member Functions

void initMessaging () const
 Initialize our message level and MessageSvc.

Private Attributes

std::vector< std::unique_ptr< ContainerBranchProcessor > > m_branches
 List of branch processors set up for this xAOD object.
TVirtualCollectionProxy * m_collProxy = nullptr
 Collection proxy used for iterating over the container.
int m_auxElementOffset = -1
 Offset of the element type to SG::AuxElement.
std::string m_sgName
 Name of the object in the event store.
std::string m_nm
 Message source name.
boost::thread_specific_ptr< MsgStream > m_msg_tls
 MsgStream instance (a std::cout like with print-out levels).
std::atomic< IMessageSvc * > m_imsg { nullptr }
 MessageSvc pointer.
std::atomic< MSG::Level > m_lvl { MSG::NIL }
 Current logging level.
std::atomic_flag m_initialized ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
 Messaging initialized (initMessaging).

Detailed Description

Class writing all variables from one DataVector container.

It is designed to work with any DataVector<SG::AuxElement> type, it doesn't have to be an xAOD::IParticleContainer. But of course that is the main use case for it...

It expects an SG::AuxVectorBase object from the caller, iterates over the elements of that container using the ROOT dictionary of the type, and writes individual variables from the elements of the container using the same machinery that ElementProcessorRegular employs.

Definition at line 408 of file TreeBranchHelpers.h.

Constructor & Destructor Documentation

◆ ContainerProcessorRegular() [1/2]

CP::TreeBranchHelpers::ContainerProcessorRegular::ContainerProcessorRegular ( const std::string & sgName)

Default constructor.

We have to have a default constructor to initialise the asg::AsgMessaging base class correctly. Members of this class would not need an explicit constructor themselves.

Definition at line 880 of file TreeBranchHelpers.cxx.

881 : asg::AsgMessaging( ("CP::TreeBranchHelpers::ContainerProcessorRegular/" + sgName).c_str() ),
882 m_sgName(sgName) {
883
884 }
std::string m_sgName
Name of the object in the event store.

◆ ~ContainerProcessorRegular()

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

◆ ContainerProcessorRegular() [2/2]

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

Member Function Documentation

◆ addBranch() [1/2]

StatusCode CP::TreeBranchHelpers::ContainerProcessorRegular::addBranch ( ROOT::RNTupleModel & model,
const BranchConfig & branchConfig,
OutputBranchData & outputData )
overridevirtual

Implements CP::TreeBranchHelpers::IObjectProcessor.

Definition at line 974 of file TreeBranchHelpers.cxx.

975 {
976 ATH_MSG_ERROR("ContainerProcessorRegular::addBranch for RNTuple should not be called");
977 return StatusCode::FAILURE;
978 }
#define ATH_MSG_ERROR(x)

◆ addBranch() [2/2]

StatusCode CP::TreeBranchHelpers::ContainerProcessorRegular::addBranch ( TTree & tree,
const BranchConfig & branchConfig,
OutputBranchData & outputData )
overridevirtual

Add one branch to the output tree.

This function is used during the setup of the output tree to create one branch in it, from one specific auxiliary variable. The type of the variable is figured out at runtime using the auxiliary store infrastructure.

Parameters
treeThe tree to create the branch in
auxNameName of the auxiliary variable to create the branch from
branchNameThe name of the branch to create in the tree
allowMissingSet to true to print an error message in case of a failure
createdUsed to store if the branch was actually created
Returns
The usual StatusCode values

Implements CP::TreeBranchHelpers::IObjectProcessor.

Definition at line 963 of file TreeBranchHelpers.cxx.

964 {
965
966 // Set up the new branch.
967 m_branches.emplace_back(std::make_unique<ContainerBranchProcessor>());
968 ATH_CHECK( m_branches.back()->setup( tree, branchConfig, outputData, msg() ) );
969
970 // Return gracefully.
971 return StatusCode::SUCCESS;
972 }
#define ATH_CHECK
Evaluate an expression and check for errors.
MsgStream & msg() const
The standard message stream.
std::vector< std::unique_ptr< ContainerBranchProcessor > > m_branches
List of branch processors set up for this xAOD object.
TChain * tree

◆ initMessaging()

void AthMessaging::initMessaging ( ) const
privateinherited

Initialize our message level and MessageSvc.

This method should only be called once.

Definition at line 39 of file AthMessaging.cxx.

40{
42 // If user did not set an explicit level, set a default
43 if (m_lvl == MSG::NIL) {
44 m_lvl = m_imsg ?
45 static_cast<MSG::Level>( m_imsg.load()->outputLevel(m_nm) ) :
46 MSG::INFO;
47 }
48}
std::string m_nm
Message source name.
std::atomic< IMessageSvc * > m_imsg
MessageSvc pointer.
std::atomic< MSG::Level > m_lvl
Current logging level.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ msg() [1/2]

MsgStream & asg::AsgMessaging::msg ( ) const
inherited

The standard message stream.

Returns
A reference to the default message stream of this object.

Definition at line 49 of file AsgMessaging.cxx.

49 {
50#ifndef XAOD_STANDALONE
51 return ::AthMessaging::msg();
52#else // not XAOD_STANDALONE
53 return m_msg;
54#endif // not XAOD_STANDALONE
55 }

◆ msg() [2/2]

MsgStream & asg::AsgMessaging::msg ( const MSG::Level lvl) const
inherited

The standard message stream.

Parameters
lvlThe message level to set the stream to
Returns
A reference to the default message stream, set to level "lvl"

Definition at line 57 of file AsgMessaging.cxx.

57 {
58#ifndef XAOD_STANDALONE
59 return ::AthMessaging::msg( lvl );
60#else // not XAOD_STANDALONE
61 m_msg << lvl;
62 return m_msg;
63#endif // not XAOD_STANDALONE
64 }

◆ msgLvl()

bool asg::AsgMessaging::msgLvl ( const MSG::Level lvl) const
inherited

Test the output level of the object.

Parameters
lvlThe message level to test against
Returns
boolean Indicting if messages at given level will be printed
true If messages at level "lvl" will be printed

Definition at line 41 of file AsgMessaging.cxx.

41 {
42#ifndef XAOD_STANDALONE
43 return ::AthMessaging::msgLvl( lvl );
44#else // not XAOD_STANDALONE
45 return m_msg.msgLevel( lvl );
46#endif // not XAOD_STANDALONE
47 }

◆ operator=()

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

◆ retrieveProcess()

StatusCode CP::TreeBranchHelpers::ContainerProcessorRegular::retrieveProcess ( StoreType & evtStore)
overridevirtual

retrieve and process the object

Implements CP::TreeBranchHelpers::IObjectProcessor.

Definition at line 886 of file TreeBranchHelpers.cxx.

887 {
888
889 // Retrieve the container:
890 static const bool ALLOW_MISSING = false;
891 const TClass* cl = nullptr;
892 const SG::AuxVectorBase* vec = getVector( m_sgName,
893 evtStore,
894 ALLOW_MISSING, cl, msg() );
895 if( ! vec ) {
896 ATH_MSG_ERROR( "Failed to retrieve container \""
897 << m_sgName << "\"" );
898 return StatusCode::FAILURE;
899 }
900 const SG::AuxVectorBase& container = *vec;
901
902 // Get the collection proxy for the type if it's not available yet.
903 if( ! m_collProxy ) {
904
905 // Get the collection proxy from the dictionary.
906 m_collProxy = cl->GetCollectionProxy();
907 if( ! m_collProxy ) {
908 ATH_MSG_ERROR( "No collection proxy provided by type: "
909 << cl->GetName() );
910 return StatusCode::FAILURE;
911 }
912
913 // Get the offset that one needs to use to get from the element
914 // pointers to SG::AuxElement pointers.
915 static const TClass* const auxElementClass =
916 TClass::GetClass( typeid( SG::AuxElement ) );
918 m_collProxy->GetValueClass()->GetBaseClassOffset( auxElementClass );
919 if( m_auxElementOffset < 0 ) {
920 ATH_MSG_ERROR( "Vector element type \""
921 << m_collProxy->GetValueClass()->GetName()
922 << "\" doesn't seem to inherit from \""
923 << auxElementClass->GetName() << "\"" );
924 return StatusCode::FAILURE;
925 }
926 }
927
928 // Set up the iteration over the elements of the container. In a really
929 // low level / ugly way...
930 void* cPtr =
931 const_cast< void* >( static_cast< const void* >( &container ) );
932 TVirtualCollectionProxy::TPushPop helper( m_collProxy, cPtr );
933 const UInt_t cSize = m_collProxy->Size();
934
935 // Tell all branch processors to resize their variables.
936 for( auto& p : m_branches ) {
937 ATH_CHECK( p->resize( cSize, msg() ) );
938 }
939
940 // Now iterate over the container.
941 for( UInt_t i = 0; i < cSize; ++i ) {
942
943 // Get the element.
944 char* elPtr = static_cast< char* >( m_collProxy->At( i ) );
945 if( ! elPtr ) {
946 ATH_MSG_ERROR( "Failed to get element " << i << " from container" );
947 return StatusCode::FAILURE;
948 }
949 const SG::AuxElement* element =
950 reinterpret_cast< const SG::AuxElement* >( elPtr +
952
953 // Execute all branch processors on this element.
954 for( auto& p : m_branches ) {
955 ATH_CHECK( p->process( *element, i, msg() ) );
956 }
957 }
958
959 // Return gracefully.
960 return StatusCode::SUCCESS;
961 }
std::vector< size_t > vec
TVirtualCollectionProxy * m_collProxy
Collection proxy used for iterating over the container.
int m_auxElementOffset
Offset of the element type to SG::AuxElement.
MsgStream & msg() const
The standard message stream.
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
const SG::AuxVectorData * container() const
Return the container holding this element.
virtual const IAuxTypeVector * getVector(SG::auxid_t auxid) const override
Return vector interface for one aux data item.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ setLevel()

void AthMessaging::setLevel ( MSG::Level lvl)
inherited

Change the current logging level.

Use this rather than msg().setLevel() for proper operation with MT.

Definition at line 28 of file AthMessaging.cxx.

29{
30 m_lvl = lvl;
31}

Member Data Documentation

◆ ATLAS_THREAD_SAFE

std::atomic_flag m_initialized AthMessaging::ATLAS_THREAD_SAFE = ATOMIC_FLAG_INIT
mutableprivateinherited

Messaging initialized (initMessaging).

Definition at line 141 of file AthMessaging.h.

◆ m_auxElementOffset

int CP::TreeBranchHelpers::ContainerProcessorRegular::m_auxElementOffset = -1
private

Offset of the element type to SG::AuxElement.

Definition at line 459 of file TreeBranchHelpers.h.

◆ m_branches

std::vector<std::unique_ptr<ContainerBranchProcessor> > CP::TreeBranchHelpers::ContainerProcessorRegular::m_branches
private

List of branch processors set up for this xAOD object.

Note that when we set up a branch, we tell TTree to remember a physical address in memory. To make sure that the address of the object held by the branch processors are not moved in memory after their construction, we have to use an std::list container here. std::vector would not work. (As it can relocate objects when increasing the size of the container.)

Definition at line 455 of file TreeBranchHelpers.h.

◆ m_collProxy

TVirtualCollectionProxy* CP::TreeBranchHelpers::ContainerProcessorRegular::m_collProxy = nullptr
private

Collection proxy used for iterating over the container.

Definition at line 457 of file TreeBranchHelpers.h.

◆ m_imsg

std::atomic<IMessageSvc*> AthMessaging::m_imsg { nullptr }
mutableprivateinherited

MessageSvc pointer.

Definition at line 135 of file AthMessaging.h.

135{ nullptr };

◆ m_lvl

std::atomic<MSG::Level> AthMessaging::m_lvl { MSG::NIL }
mutableprivateinherited

Current logging level.

Definition at line 138 of file AthMessaging.h.

138{ MSG::NIL };

◆ m_msg_tls

boost::thread_specific_ptr<MsgStream> AthMessaging::m_msg_tls
mutableprivateinherited

MsgStream instance (a std::cout like with print-out levels).

Definition at line 132 of file AthMessaging.h.

◆ m_nm

std::string AthMessaging::m_nm
privateinherited

Message source name.

Definition at line 129 of file AthMessaging.h.

◆ m_sgName

std::string CP::TreeBranchHelpers::ContainerProcessorRegular::m_sgName
private

Name of the object in the event store.

Definition at line 462 of file TreeBranchHelpers.h.


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