ATLAS Offline Software
Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
SG::WriteDecorHandle< T, D > Class Template Reference

Handle class for adding a decoration to an object. More...

#include <WriteDecorHandle.h>

Inheritance diagram for SG::WriteDecorHandle< T, D >:
Collaboration diagram for SG::WriteDecorHandle< T, D >:

Public Types

using Base = ReadHandle< T >
 Base class. More...
 
using accessor_t = SG::AuxElement::Decorator< D >
 Accessor type for aux data. More...
 
using reference_type = typename accessor_t::reference_type
 Type referencing an aux data item. More...
 
using container_pointer_type = typename accessor_t::container_pointer_type
 Pointer into the vector holding an aux data item. More...
 
using span = typename accessor_t::span
 Span of aux data items. More...
 

Public Member Functions

 WriteDecorHandle (const WriteDecorHandleKey< T > &key)
 Constructor from a WriteDecorHandleKey. More...
 
 WriteDecorHandle (const WriteDecorHandleKey< T > &key, const EventContext &ctx)
 Constructor from a ReadDecorHandleKey and an explicit event context. More...
 
 WriteDecorHandle (const WriteDecorHandle &rhs)
 Copy constructor. More...
 
 WriteDecorHandle (WriteDecorHandle &&rhs)
 Move constructor. More...
 
 ~WriteDecorHandle ()
 Destructor. More...
 
WriteDecorHandleoperator= (const WriteDecorHandle &rhs)
 Assignment operator. More...
 
WriteDecorHandleoperator= (WriteDecorHandle &&rhs)
 Move operator. More...
 
bool isPresent () const
 Is the referenced container present in SG? More...
 
virtual StatusCode setProxyDict (IProxyDict *store) override
 Explicitly set the event store. More...
 
reference_type operator() (const AuxElement &e)
 Fetch the variable for one element, as a reference. More...
 
reference_type operator() (size_t index)
 Fetch the variable for one element, as a reference. More...
 
template<class POINTER_TYPE = container_pointer_type, typename = std::enable_if_t<!std::is_void_v<POINTER_TYPE> >>
POINTER_TYPE getDecorationArray ()
 Get a pointer to the start of the auxiliary data array, for the referenced object. More...
 
span getDecorationSpan ()
 Get a span over the auxilary data array, for the referenced object. More...
 
bool isAvailable ()
 Test to see if this variable exists in the store, for the referenced object. More...
 
SG::auxid_t auxid () const
 Return the aux id for this variable. More...
 
Gaudi::DataHandle::Mode mode () const
 Return the mode (read/write/update) for this handle. More...
 
std::string decorKey () const
 Return the name of the decoration alias (CONT.DECOR). More...
 

Private Types

enum  { NO_ALIAS, MADE_ALIAS, RENOUNCED }
 Set no NO_ALIAS when the handle is created, changed to MADE_ALIAS after the alias has been made. More...
 

Private Member Functions

virtual void * typeless_dataPointer_impl (bool quiet) override
 Retrieve an object from StoreGate. More...
 
bool isAvailable (std::true_type)
 Test to see if this variable exists in the store, for the referenced object. More...
 
bool isAvailable (std::false_type)
 Test to see if this variable exists in the store, for the referenced object. More...
 
const SG::AuxVectorDatavectorData (std::true_type)
 Return the referenced object as a SG::AuxVectorData. More...
 
const SG::AuxVectorDatavectorData (std::false_type)
 Return the referenced object as a SG::AuxVectorData. More...
 
const SG::AuxVectorDatavectorData ()
 Return the referenced object as a SG::AuxVectorData. More...
 

Private Attributes

std::string m_decorKey
 Name of the decoration alias: CONT.DECOR. More...
 
accessor_t m_acc
 Accessor for the aux data item. More...
 
enum SG::WriteDecorHandle:: { ... }  m_state
 Set no NO_ALIAS when the handle is created, changed to MADE_ALIAS after the alias has been made. More...
 

Detailed Description

template<class T, class D>
class SG::WriteDecorHandle< T, D >

Handle class for adding a decoration to an object.

This (and the corresponding ReadDecorHandle class) allow the scheduler to track dependencies on decorations on objects, in addition to the objects themselves. For example, one algorithm could produce a container C, a second could read C and add a decoration to it C.d, and a third algorithm could read the decoration C.d. This allows the scheduler to know that the third algorithm must be executed after the second completes.

A WriteDecorHandle<T, D> works just like a ReadHandle<T> (except that using it as a property directly is not supported). When the object is first accessed, the decoration is actually created (and a SG alias is made for the object under the C.d name). The handle also has functionality for accessing a decoration of type D, similarly to the interface provided by Decorator objects. You can either write the decoration from for SG::AuxElement object:

handle(o) = x;

or reference the element by its index in the container:

handle(i) = x;

Example:

class MyAlgorithm : public AthReentrantAlgorithm {
...
};
...
MyAlgorithm::MyAlgorithm (const std::string& name, ISvcLocator* svcloc)
: AthReentrantAlgorithm (name, svcloc), ...
{
declareProperty ("Key", m_key = "container.decor");
...
}
{
ATH_CHECK( m_key.initialize() );
...
}
StatusCode MyAlgorithm::execute (const EventContext& ctx) const
{
for (const MyObj& o : *h) { // Access the container.
h (o) = calculate (o); // Add the decoration.
...

When the decoration handle is destroyed, the decoration will be locked (i.e., converted to an ordinary variable).

Implementation note: we keep track of decorations using aliases. For a container C with decoration d, the WriteDecorHandle will make an alias C.d for C. The ReadDecorHandle will then retrieve C.d from StoreGate. The alias C.d is also what enters into scheduling decisions.

The key() method will return the key of the container. Use decorKey() to get the name used for the decoration alias.

Definition at line 97 of file StoreGate/StoreGate/WriteDecorHandle.h.

Member Typedef Documentation

◆ accessor_t

template<class T , class D >
using SG::WriteDecorHandle< T, D >::accessor_t = SG::AuxElement::Decorator<D>

Accessor type for aux data.

Definition at line 105 of file StoreGate/StoreGate/WriteDecorHandle.h.

◆ Base

template<class T , class D >
using SG::WriteDecorHandle< T, D >::Base = ReadHandle<T>

Base class.

Definition at line 102 of file StoreGate/StoreGate/WriteDecorHandle.h.

◆ container_pointer_type

template<class T , class D >
using SG::WriteDecorHandle< T, D >::container_pointer_type = typename accessor_t::container_pointer_type

Pointer into the vector holding an aux data item.

Definition at line 111 of file StoreGate/StoreGate/WriteDecorHandle.h.

◆ reference_type

template<class T , class D >
using SG::WriteDecorHandle< T, D >::reference_type = typename accessor_t::reference_type

Type referencing an aux data item.

Definition at line 108 of file StoreGate/StoreGate/WriteDecorHandle.h.

◆ span

template<class T , class D >
using SG::WriteDecorHandle< T, D >::span = typename accessor_t::span

Span of aux data items.

Definition at line 114 of file StoreGate/StoreGate/WriteDecorHandle.h.

Member Enumeration Documentation

◆ anonymous enum

template<class T , class D >
anonymous enum
private

Set no NO_ALIAS when the handle is created, changed to MADE_ALIAS after the alias has been made.

But if renounce() has been called on the parent key, then we set this to RENOUNCED to indicate that we shouldn't make an alias.

Enumerator
NO_ALIAS 
MADE_ALIAS 
RENOUNCED 

Definition at line 319 of file StoreGate/StoreGate/WriteDecorHandle.h.

319  { NO_ALIAS,
320  MADE_ALIAS,
321  RENOUNCED }

Constructor & Destructor Documentation

◆ WriteDecorHandle() [1/4]

template<class T , class D >
SG::WriteDecorHandle< T, D >::WriteDecorHandle ( const WriteDecorHandleKey< T > &  key)
explicit

Constructor from a WriteDecorHandleKey.

Parameters
keyThe key object holding the clid/key/store/attr.

This will raise an exception if the StoreGate key is blank, or if the event store cannot be found.

◆ WriteDecorHandle() [2/4]

template<class T , class D >
SG::WriteDecorHandle< T, D >::WriteDecorHandle ( const WriteDecorHandleKey< T > &  key,
const EventContext &  ctx 
)
explicit

Constructor from a ReadDecorHandleKey and an explicit event context.

Parameters
keyThe key object holding the clid/key.
ctxThe event context.

This will raise an exception if the StoreGate key is blank, or if the event store cannot be found.

If the default event store has been requested, then the thread-specific store from the event context will be used.

◆ WriteDecorHandle() [3/4]

template<class T , class D >
SG::WriteDecorHandle< T, D >::WriteDecorHandle ( const WriteDecorHandle< T, D > &  rhs)

Copy constructor.

◆ WriteDecorHandle() [4/4]

template<class T , class D >
SG::WriteDecorHandle< T, D >::WriteDecorHandle ( WriteDecorHandle< T, D > &&  rhs)

Move constructor.

◆ ~WriteDecorHandle()

template<class T , class D >
SG::WriteDecorHandle< T, D >::~WriteDecorHandle ( )

Destructor.

This will lock the decoration.

Member Function Documentation

◆ auxid()

template<class T , class D >
SG::auxid_t SG::WriteDecorHandle< T, D >::auxid ( ) const

Return the aux id for this variable.

◆ decorKey()

template<class T , class D >
std::string SG::WriteDecorHandle< T, D >::decorKey ( ) const

Return the name of the decoration alias (CONT.DECOR).

◆ getDecorationArray()

template<class T , class D >
template<class POINTER_TYPE = container_pointer_type, typename = std::enable_if_t<!std::is_void_v<POINTER_TYPE> >>
POINTER_TYPE SG::WriteDecorHandle< T, D >::getDecorationArray ( )

Get a pointer to the start of the auxiliary data array, for the referenced object.

◆ getDecorationSpan()

template<class T , class D >
span SG::WriteDecorHandle< T, D >::getDecorationSpan ( )

Get a span over the auxilary data array, for the referenced object.

◆ isAvailable() [1/3]

template<class T , class D >
bool SG::WriteDecorHandle< T, D >::isAvailable ( )

Test to see if this variable exists in the store, for the referenced object.

◆ isAvailable() [2/3]

template<class T , class D >
bool SG::WriteDecorHandle< T, D >::isAvailable ( std::false_type  )
private

Test to see if this variable exists in the store, for the referenced object.

Specialization for the case of a container (T does not derive from SG::AuxElement).

◆ isAvailable() [3/3]

template<class T , class D >
bool SG::WriteDecorHandle< T, D >::isAvailable ( std::true_type  )
private

Test to see if this variable exists in the store, for the referenced object.

Specialization for the case of a standalone object (T derives from SG::AuxElement).

◆ isPresent()

template<class T , class D >
bool SG::WriteDecorHandle< T, D >::isPresent ( ) const

Is the referenced container present in SG?

Note that this tests for the presence of the container, not for the decoration.

Const method; the handle does not change as a result of this.

◆ mode()

template<class T , class D >
Gaudi::DataHandle::Mode SG::WriteDecorHandle< T, D >::mode ( ) const

Return the mode (read/write/update) for this handle.

◆ operator()() [1/2]

template<class T , class D >
reference_type SG::WriteDecorHandle< T, D >::operator() ( const AuxElement e)

Fetch the variable for one element, as a reference.

Parameters
eThe element for which to fetch the variable.

◆ operator()() [2/2]

template<class T , class D >
reference_type SG::WriteDecorHandle< T, D >::operator() ( size_t  index)

Fetch the variable for one element, as a reference.

Parameters
indexThe index of the desired element.

This looks up the variable in the object referenced by this handle. For a standalone object, pass an index of 0.

◆ operator=() [1/2]

template<class T , class D >
WriteDecorHandle& SG::WriteDecorHandle< T, D >::operator= ( const WriteDecorHandle< T, D > &  rhs)

Assignment operator.

◆ operator=() [2/2]

template<class T , class D >
WriteDecorHandle& SG::WriteDecorHandle< T, D >::operator= ( WriteDecorHandle< T, D > &&  rhs)

Move operator.

◆ setProxyDict()

template<class T , class D >
virtual StatusCode SG::WriteDecorHandle< T, D >::setProxyDict ( IProxyDict store)
overridevirtual

Explicitly set the event store.

Parameters
storeThe new event store.

This implicitly does a reset().

We need to override this so that the setting gets made on the container handle as well.

◆ typeless_dataPointer_impl()

template<class T , class D >
virtual void* SG::WriteDecorHandle< T, D >::typeless_dataPointer_impl ( bool  quiet)
overrideprivatevirtual

Retrieve an object from StoreGate.

Parameters
quietIf true, suppress failure messages.

Extended for decoration handles: when we first retrieve the object, we make an alias for the decoration and also create the decoration itself.

◆ vectorData() [1/3]

template<class T , class D >
const SG::AuxVectorData* SG::WriteDecorHandle< T, D >::vectorData ( )
private

Return the referenced object as a SG::AuxVectorData.

If T is a container object, then this should be the object itself. But if it is a standalone object, deriving from SG::AuxElement, then we need to call container() on the object.

◆ vectorData() [2/3]

template<class T , class D >
const SG::AuxVectorData* SG::WriteDecorHandle< T, D >::vectorData ( std::false_type  )
private

Return the referenced object as a SG::AuxVectorData.

Specialization for the case of a container (T does not derive from SG::AuxElement).

◆ vectorData() [3/3]

template<class T , class D >
const SG::AuxVectorData* SG::WriteDecorHandle< T, D >::vectorData ( std::true_type  )
private

Return the referenced object as a SG::AuxVectorData.

Specialization for the case of a standalone object (T derives from SG::AuxElement).

Member Data Documentation

◆ m_acc

template<class T , class D >
accessor_t SG::WriteDecorHandle< T, D >::m_acc
private

Accessor for the aux data item.

Definition at line 313 of file StoreGate/StoreGate/WriteDecorHandle.h.

◆ m_decorKey

template<class T , class D >
std::string SG::WriteDecorHandle< T, D >::m_decorKey
private

Name of the decoration alias: CONT.DECOR.

Definition at line 310 of file StoreGate/StoreGate/WriteDecorHandle.h.

◆ m_state

enum { ... } SG::WriteDecorHandle< T, D >::m_state

Set no NO_ALIAS when the handle is created, changed to MADE_ALIAS after the alias has been made.

But if renounce() has been called on the parent key, then we set this to RENOUNCED to indicate that we shouldn't make an alias.


The documentation for this class was generated from the following file:
SG::WriteDecorHandleKey
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
Definition: StoreGate/StoreGate/WriteDecorHandleKey.h:89
SG::WriteDecorHandle::MADE_ALIAS
@ MADE_ALIAS
Definition: StoreGate/StoreGate/WriteDecorHandle.h:320
initialize
void initialize()
Definition: run_EoverP.cxx:894
x
#define x
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
LArG4FSStartPointFilterLegacy.execute
execute
Definition: LArG4FSStartPointFilterLegacy.py:20
SG::WriteDecorHandle::RENOUNCED
@ RENOUNCED
Definition: StoreGate/StoreGate/WriteDecorHandle.h:321
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
extractSporadic.h
list h
Definition: extractSporadic.py:97
SG::WriteDecorHandle
Handle class for adding a decoration to an object.
Definition: StoreGate/StoreGate/WriteDecorHandle.h:99
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
EMFourMomBuilder::calculate
void calculate(xAOD::Electron &electron)
Definition: EMFourMomBuilder.cxx:68
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
h
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
SG::WriteDecorHandle::NO_ALIAS
@ NO_ALIAS
Definition: StoreGate/StoreGate/WriteDecorHandle.h:319