ATLAS Offline Software
Loading...
Searching...
No Matches
xAOD::ContainerDecorator< Cont_t, dType > Class Template Reference

Auxiliary class to instantiate WriteDecorHandles.The handles can be created in an empty state. More...

#include <ContainerDecorator.h>

Collaboration diagram for xAOD::ContainerDecorator< Cont_t, dType >:

Public Types

using Handle_t = SG::WriteDecorHandle<Cont_t, dType>

Public Member Functions

 ContainerDecorator ()=default
 Empty default constructor.
 ContainerDecorator (const SG::WriteDecorHandleKey< Cont_t > &key, const EventContext &ctx, dType defValue={})
 Construct the decorator with an initialized decorHandleKey, and the current EventContext.
 ~ContainerDecorator ()
 Destructor.
 ContainerDecorator (ContainerDecorator &&other)=default
 Default move constructor.
ContainerDecoratoroperator= (ContainerDecorator &&other)=default
 Default move assignment operator.
void initialize (const SG::WriteDecorHandleKey< Cont_t > &key, const EventContext &ctx, dType defValue={})
 Instantiate the handle.
dType & operator() (const SG::AuxElement &auxElem)
 Access the decoration value.
constexpr bool isValid () const
 Returns whether the handle is instantiated.
constexpr operator bool () const
 Returns whether the handle is instantiated.
const Cont_t * container () const
 Returns the underlying container.
const Cont_t * operator-> () const
 Returns the pointer to the underlying container.

Private Member Functions

void initDefault ()
 Decorate the default value to all elements in the container.

Private Attributes

std::unique_ptr< Handle_tm_decorHandle {}
std::unordered_set< const SG::AuxElement * > m_seenAux {}
dType m_defValue {}

Detailed Description

template<detail::PrimaryContainerConcept Cont_t, typename dType>
class xAOD::ContainerDecorator< Cont_t, dType >

Auxiliary class to instantiate WriteDecorHandles.The handles can be created in an empty state.

Once initialized, a default value is decorated to all objects in the container to ensure that the decoration is always set.

Definition at line 18 of file ContainerDecorator.h.

Member Typedef Documentation

◆ Handle_t

template<detail::PrimaryContainerConcept Cont_t, typename dType>
using xAOD::ContainerDecorator< Cont_t, dType >::Handle_t = SG::WriteDecorHandle<Cont_t, dType>

Definition at line 20 of file ContainerDecorator.h.

Constructor & Destructor Documentation

◆ ContainerDecorator() [1/3]

template<detail::PrimaryContainerConcept Cont_t, typename dType>
xAOD::ContainerDecorator< Cont_t, dType >::ContainerDecorator ( )
explicitdefault

Empty default constructor.

◆ ContainerDecorator() [2/3]

template<detail::PrimaryContainerConcept Cont_t, typename dType>
xAOD::ContainerDecorator< Cont_t, dType >::ContainerDecorator ( const SG::WriteDecorHandleKey< Cont_t > & key,
const EventContext & ctx,
dType defValue = {} )
inlineexplicit

Construct the decorator with an initialized decorHandleKey, and the current EventContext.

Parameters
keyThe initialized decorHandleKey with which the decorator is instantitated
ctxEventContext to gain access to the underlying continer
defValueDefault value to be decorated onto the entire container at instantiation

Definition at line 30 of file ContainerDecorator.h.

32 {}) {
34 }
Auxiliary class to instantiate WriteDecorHandles.The handles can be created in an empty state.
void initialize()

◆ ~ContainerDecorator()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
xAOD::ContainerDecorator< Cont_t, dType >::~ContainerDecorator ( )
inline

Destructor.

Definition at line 36 of file ContainerDecorator.h.

36 {
38 }
void initDefault()
Decorate the default value to all elements in the container.

◆ ContainerDecorator() [3/3]

template<detail::PrimaryContainerConcept Cont_t, typename dType>
xAOD::ContainerDecorator< Cont_t, dType >::ContainerDecorator ( ContainerDecorator< Cont_t, dType > && other)
default

Default move constructor.

Member Function Documentation

◆ container()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
const Cont_t * xAOD::ContainerDecorator< Cont_t, dType >::container ( ) const
inline

Returns the underlying container.

Definition at line 76 of file ContainerDecorator.h.

76{ return isValid() ? m_decorHandle->cptr() : nullptr; }
constexpr bool isValid() const
Returns whether the handle is instantiated.
std::unique_ptr< Handle_t > m_decorHandle

◆ initDefault()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
void xAOD::ContainerDecorator< Cont_t, dType >::initDefault ( )
inlineprivate

Decorate the default value to all elements in the container.

Definition at line 81 of file ContainerDecorator.h.

81 {
82 if (!m_decorHandle){
83 return;
84 }
85 if(!m_decorHandle->isPresent() ) {
86 return;
87 }
88 for (const SG::AuxElement* auxElem : **m_decorHandle) {
89 if (m_seenAux.insert(auxElem).second) {
90 (*m_decorHandle)(*auxElem) = m_defValue;
91 }
92 }
93 }
std::unordered_set< const SG::AuxElement * > m_seenAux

◆ initialize()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
void xAOD::ContainerDecorator< Cont_t, dType >::initialize ( const SG::WriteDecorHandleKey< Cont_t > & key,
const EventContext & ctx,
dType defValue = {} )
inline

Instantiate the handle.

Parameters
keyWriteDecorationKey to be used
ctxThe current event context
defValueDefault value to be used for all objects

Definition at line 48 of file ContainerDecorator.h.

50 {}) {
51 if (key.empty()) {
52 m_decorHandle.reset();
53 return;
54 }
55 if (m_decorHandle) {
56 THROW_EXCEPTION("The Container decorator is already initialized to "<<m_decorHandle->fullKey()<<"."
57 <<m_decorHandle->decorKey());
58 }
62 }
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10

◆ isValid()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
bool xAOD::ContainerDecorator< Cont_t, dType >::isValid ( ) const
inlineconstexpr

Returns whether the handle is instantiated.

Definition at line 72 of file ContainerDecorator.h.

72{ return m_decorHandle != nullptr; }

◆ operator bool()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
xAOD::ContainerDecorator< Cont_t, dType >::operator bool ( ) const
inlineconstexpr

Returns whether the handle is instantiated.

Definition at line 74 of file ContainerDecorator.h.

74{return isValid(); }

◆ operator()()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
dType & xAOD::ContainerDecorator< Cont_t, dType >::operator() ( const SG::AuxElement & auxElem)
inline

Access the decoration value.

Definition at line 64 of file ContainerDecorator.h.

64 {
66 THROW_EXCEPTION("No decorator has been defined. Please use initialize() beforhand");
67 }
68 m_seenAux.insert(&auxElem);
69 return (*m_decorHandle)(auxElem);
70 }
#define ATH_UNLIKELY(x)

◆ operator->()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
const Cont_t * xAOD::ContainerDecorator< Cont_t, dType >::operator-> ( ) const
inline

Returns the pointer to the underlying container.

Definition at line 78 of file ContainerDecorator.h.

78{ return container(); }
const Cont_t * container() const
Returns the underlying container.

◆ operator=()

template<detail::PrimaryContainerConcept Cont_t, typename dType>
ContainerDecorator & xAOD::ContainerDecorator< Cont_t, dType >::operator= ( ContainerDecorator< Cont_t, dType > && other)
default

Default move assignment operator.

Member Data Documentation

◆ m_decorHandle

template<detail::PrimaryContainerConcept Cont_t, typename dType>
std::unique_ptr<Handle_t> xAOD::ContainerDecorator< Cont_t, dType >::m_decorHandle {}
private

Definition at line 94 of file ContainerDecorator.h.

94{};

◆ m_defValue

template<detail::PrimaryContainerConcept Cont_t, typename dType>
dType xAOD::ContainerDecorator< Cont_t, dType >::m_defValue {}
private

Definition at line 96 of file ContainerDecorator.h.

96{};

◆ m_seenAux

template<detail::PrimaryContainerConcept Cont_t, typename dType>
std::unordered_set<const SG::AuxElement*> xAOD::ContainerDecorator< Cont_t, dType >::m_seenAux {}
private

Definition at line 95 of file ContainerDecorator.h.

95{};

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