ATLAS Offline Software
Loading...
Searching...
No Matches
SG::WriteHandle< T > Class Template Reference

#include <WriteHandle.h>

Inheritance diagram for SG::WriteHandle< T >:
Collaboration diagram for SG::WriteHandle< T >:

Public Types

typedef T * pointer_type
typedef const T * const_pointer_type
typedef T & reference_type
typedef const T & const_reference_type

Public Member Functions

 WriteHandle ()
 Default constructor.
 WriteHandle (const std::string &sgkey, const std::string &storename=StoreID::storeName(StoreID::EVENT_STORE))
 Constructor specifying the key as a string.
 WriteHandle (const std::string &sgkey, const EventContext &ctx)
 Constructor specifying the key as a string, with context.
 WriteHandle (const std::string &sgkey, const std::string &storename, const EventContext &ctx)
 Constructor specifying the key as a string, with context.
 WriteHandle (const WriteHandleKey< T > &key)
 Constructor from a WriteHandleKey.
 WriteHandle (const WriteHandleKey< T > &key, const EventContext &ctx)
 Constructor from a WriteHandleKey and an explicit event context.
 WriteHandle (SG::WriteHandleKey< T > &&key)=delete
 WriteHandle (SG::WriteHandleKey< T > &&key, const EventContext &ctx)=delete
 WriteHandle (const WriteHandle &rhs)
 Copy constructor.
 WriteHandle (WriteHandle &&rhs) noexcept
 Move constructor.
WriteHandle & operator= (const WriteHandle &rhs)
 Assignment operator.
WriteHandle & operator= (WriteHandle &&rhs) noexcept
 Move operator.
 ~WriteHandle ()
 Destructor.
pointer_type operator-> ()
 Dereference the pointer.
reference_type operator* ()
 Dereference the pointer.
const_pointer_type cptr () const
 Dereference the pointer.
pointer_type ptr ()
 Dereference the pointer.
pointer_type cachedPtr ()
 Return the cached pointer directly; no lookup.
virtual bool isValid () override final
 Can the handle be successfully dereferenced?
StatusCode record (std::unique_ptr< T > data)
 Record a const object to the store.
StatusCode recordNonConst (std::unique_ptr< T > data)
 Record a non-const object to the store.
template<class AUXSTORE>
StatusCode record (std::unique_ptr< T > data, std::unique_ptr< AUXSTORE > store)
 Record a const object and its auxiliary store to the store.
template<class AUXSTORE>
StatusCode recordNonConst (std::unique_ptr< T > data, std::unique_ptr< AUXSTORE > store)
 Record a non-const object and its auxiliary store to the store.
template<std::derived_from< DataObject > DOBJ>
requires std::convertible_to<DOBJ*, T*>
StatusCode record (SG::DataObjectSharedPtr< DOBJ > data)
 Record a const shared DataObject to the store.
template<std::derived_from< DataObject > DOBJ>
requires std::convertible_to<DOBJ*, T*>
StatusCode recordNonConst (SG::DataObjectSharedPtr< DOBJ > data)
 Record a non-const shared DataObject to the store.
const_pointer_type put (std::unique_ptr< T > data, bool returnExisting=false) const
 Record an object to the store.
const_pointer_type put (std::unique_ptr< const T > data, bool returnExisting=false) const
 Record an object to the store.
const_pointer_type put (std::unique_ptr< const ConstDataVector< T > > data, bool returnExisting=false) const
 Record an object to the store.
const_pointer_type put (const EventContext &ctx, std::unique_ptr< const ConstDataVector< T > > data, bool returnExisting=false) const
 Record an object to the store.
const_pointer_type put (const EventContext &ctx, std::unique_ptr< T > data, bool returnExisting=false) const
 Record an object to the store.
const_pointer_type put (const EventContext &ctx, std::unique_ptr< const T > data, bool returnExisting=false) const
 Record an object to the store.
template<std::derived_from< DataObject > DOBJ>
requires std::convertible_to<DOBJ*, T*>
const_pointer_type put (SG::DataObjectSharedPtr< DOBJ > data) const
 Record an object to the store.
template<std::derived_from< DataObject > DOBJ>
requires std::convertible_to<DOBJ*, T*>
const_pointer_type put (const EventContext &ctx, SG::DataObjectSharedPtr< DOBJ > data) const
 Record an object to the store.
template<class AUXSTORE>
const_pointer_type put (std::unique_ptr< T > data, std::unique_ptr< AUXSTORE > auxstore) const
 Record an object and its auxiliary store to the store.
template<class AUXSTORE>
const_pointer_type put (std::unique_ptr< const T > data, std::unique_ptr< const AUXSTORE > auxstore) const
 Record an object and its auxiliary store to the store.
template<class AUXSTORE>
const_pointer_type put (const EventContext &ctx, std::unique_ptr< T > data, std::unique_ptr< AUXSTORE > auxstore) const
 Record an object and its auxiliary store to the store.
template<class AUXSTORE>
const_pointer_type put (const EventContext &ctx, std::unique_ptr< const T > data, std::unique_ptr< const AUXSTORE > auxstore) const
 Record an object and its auxiliary store to the store.
WriteHandle & operator= (std::unique_ptr< T > data)
 Alternate notation for record.
StatusCode alias (const WriteHandleKey< T > &key)
 Make an alias.
template<class U>
StatusCode symLink (const WriteHandleKey< U > &key)
 Make an explicit link.
virtual const std::string & key () const override final
 Return the StoreGate ID for the referenced object.
const std::string & name () const
 Return the StoreGate ID for the referenced object.
std::string store () const
 Return the name of the store holding the object we are proxying.
bool isPresent () const
 Is the referenced object present in SG?
bool isInitialized () const
 Has a proxy been retrieved from SG?
virtual bool isSet () const override final
 Has a proxy been retrieved from SG?
bool isConst () const
 True if this handle has a proxy, and the proxy is const.
StatusCode initialize (bool used=true)
 Verify that the handle has been configured properly.
StatusCode setState ()
 Retrieve and cache all information managed by a handle.
virtual StatusCode setProxyDict (IProxyDict *store)
 Explicitly set the event store.
virtual void reset (bool hard) override
 Reset this handle.
virtual void finalReset () override final
 Reset this handle at the end of processing.
StatusCode setConst ()
 Set the 'const' bit for the bound proxy in the store.
CLID clid () const
 Return the class ID for the referenced object.
const ServiceHandle< IProxyDict > & storeHandle () const
 Return handle to the referenced store.
Gaudi::DataHandle::Mode mode () const
 Return the mode (read/write/update) for this handle.
const std::string & objKey () const
 Return the key string of the underlying DataObjID.
const DataObjID & fullKey () const
 Return the key as a DataObjID.
SG::VarHandleKey & vhKey ()
 Return a non-const reference to the HandleKey.
StatusCode assign (const std::string &sgkey)
 Update the underlying key from a string.
std::string toString () const
 Convert to a string representation.

Protected Member Functions

StatusCode setState (SG::DataProxy *proxy)
 Set the state of the handle to a given proxy.
StatusCode setState (IProxyDict *store, const std::string &name)
 Set the state of a handle from a store and a key name.
StatusCode record_impl (std::unique_ptr< DataObject > dobj, void *dataPtr, bool allowMods, bool returnExisting)
 Helper to record an object in the event store.
const void * put_impl (const EventContext *ctx, std::unique_ptr< DataObject > dobj, const void *dataPtr, bool allowMods, bool returnExisting, IProxyDict *&store) const
 Helper to record an object in the event store.
void * typeless_dataPointer_impl (bool quiet)
 Retrieve an object from StoreGate.
void * typeless_dataPointer (bool quiet=defaultQuiet)
 Retrieve an object from StoreGate.
const void * typeless_cptr ()
 Retrieve an object from StoreGate as a const pointer.
void * typeless_ptr (bool quiet=defaultQuiet)
 Retrieve an object from StoreGate as non-const pointer.
const void * get_impl (const EventContext *ctx, bool quiet=defaultQuiet) const
StatusCode symLink_impl (CLID newClid, const std::string &newKey)
 Make a symlink or alias to the object currently referenced by this handle.
bool isPresent_impl (const std::string &key) const
 Is the referenced object present in SG?

Protected Attributes

void * m_ptr
 The object to which we are bound.
SG::DataProxy * m_proxy
 Proxy holding the object to which we are bound.
IProxyDict * m_store
 Pointer to the store that owns the object.
bool m_storeWasSet
 True if the store was set explicitly via setProxyDict.

Private Member Functions

pointer_type checkedCachedPtr ()
 Return the cached pointer directly.
template<class U>
StatusCode doRecord (U data, bool isConst, bool returnExisting)
 Helper for record.
template<class U>
const_pointer_type doPut (const EventContext *ctx, U data, bool returnExisting, IProxyDict *&store) const
 Helper for put.
template<class AUXSTORE>
WriteHandle< T >::const_pointer_type doPut (const EventContext *ctx, std::unique_ptr< T > data, std::unique_ptr< AUXSTORE > auxstore) const
 Helper for recording an object and its auxiliary store to the store.
template<class AUXSTORE>
WriteHandle< T >::const_pointer_type doPut (const EventContext *ctx, std::unique_ptr< const T > data, std::unique_ptr< const AUXSTORE > auxstore) const
 Helper for recording an object and its auxiliary store to the store.
template<class AUXSTORE>
StatusCode record (std::unique_ptr< T > data, std::unique_ptr< AUXSTORE > auxstore, bool isConst)
 Record an object and its auxiliary store to the store.
IProxyDict * storeFromHandle (const EventContext *ctx) const
 Return the store instance to use.
bool setStoreFromHandle (const EventContext *ctx)
 Initialize the store pointer from the store handle.
void resetProxy ()
 Clear the m_proxy field and release the old proxy.
void setProxy (SG::DataProxy *proxy)
 Set a new proxy.
void * typeless_dataPointer_fromProxy (SG::DataProxy *proxy, bool quiet) const
 Retrieve a pointer from a proxy.

Private Attributes

SG::DataProxy * m_lockAuxPending = nullptr
 If non-null, then we need to lock the associated aux store object when we're deleted.
std::unique_ptr< VarHandleKey > m_ownedKey
 An owned VarHandleKey.
const VarHandleKey * m_key
 The associated key object.

Detailed Description

template<class T>
class SG::WriteHandle< T >

Definition at line 69 of file StoreGate/StoreGate/WriteHandle.h.

Member Typedef Documentation

◆ const_pointer_type

template<class T>
typedef const T* SG::WriteHandle< T >::const_pointer_type

Definition at line 74 of file StoreGate/StoreGate/WriteHandle.h.

◆ const_reference_type

template<class T>
typedef const T& SG::WriteHandle< T >::const_reference_type

Definition at line 76 of file StoreGate/StoreGate/WriteHandle.h.

◆ pointer_type

template<class T>
typedef T* SG::WriteHandle< T >::pointer_type

Definition at line 73 of file StoreGate/StoreGate/WriteHandle.h.

◆ reference_type

template<class T>
typedef T& SG::WriteHandle< T >::reference_type

Definition at line 75 of file StoreGate/StoreGate/WriteHandle.h.

Constructor & Destructor Documentation

◆ WriteHandle() [1/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( )

Default constructor.

The handle will not be usable until a non-blank key is assigned.

◆ WriteHandle() [2/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( const std::string & sgkey,
const std::string & storename = StoreID::storeName(StoreID::EVENT_STORE) )
explicit

Constructor specifying the key as a string.

Parameters
sgkeyStoreGate key of the referenced object.
storenameName of the referenced event store.

◆ WriteHandle() [3/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( const std::string & sgkey,
const EventContext & ctx )
explicit

Constructor specifying the key as a string, with context.

Parameters
sgkeyStoreGate key of the referenced object.
ctxThe event context.

◆ WriteHandle() [4/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( const std::string & sgkey,
const std::string & storename,
const EventContext & ctx )
explicit

Constructor specifying the key as a string, with context.

Parameters
sgkeyStoreGate key of the referenced object.
storenameName of the referenced event store.
ctxThe event context.

◆ WriteHandle() [5/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( const WriteHandleKey< T > & key)
explicit

Constructor from a WriteHandleKey.

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

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

◆ WriteHandle() [6/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( const WriteHandleKey< T > & key,
const EventContext & ctx )
explicit

Constructor from a WriteHandleKey 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.

◆ WriteHandle() [7/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( SG::WriteHandleKey< T > && key)
explicitdelete

◆ WriteHandle() [8/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( SG::WriteHandleKey< T > && key,
const EventContext & ctx )
explicitdelete

◆ WriteHandle() [9/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( const WriteHandle< T > & rhs)

Copy constructor.

◆ WriteHandle() [10/10]

template<class T>
SG::WriteHandle< T >::WriteHandle ( WriteHandle< T > && rhs)
noexcept

Move constructor.

◆ ~WriteHandle()

template<class T>
SG::WriteHandle< T >::~WriteHandle ( )

Destructor.

Lock an aux object if m_lockAuxPending is set.

Member Function Documentation

◆ alias()

template<class T>
StatusCode SG::WriteHandle< T >::alias ( const WriteHandleKey< T > & key)

Make an alias.

Parameters
keyAlternate key by which the referenced object should be known.

The current handle should be valid and referencing an object (i.e., record should have been called on it).

The object will also be known by the name given in key.

◆ assign()

StatusCode SG::VarHandleBase::assign ( const std::string & sgkey)
inherited

Update the underlying key from a string.

If this handle was initialized from a HandleKey, then this doesn't work (since the HandleKey is const). ExcNonConstHandleKey will be thrown in that case.

See VarHandleKey::assign.

Definition at line 649 of file StoreGate/src/VarHandleBase.cxx.

650 {
651 return vhKey().assign (sgkey);
652 }
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
virtual StatusCode assign(const std::string &sgkey)
Change the key of the object to which we're referring.

◆ cachedPtr()

template<class T>
pointer_type SG::WriteHandle< T >::cachedPtr ( )

Return the cached pointer directly; no lookup.

◆ checkedCachedPtr()

template<class T>
pointer_type SG::WriteHandle< T >::checkedCachedPtr ( )
private

Return the cached pointer directly.

If it is null, throw ExcNullWriteHandle.

◆ clid()

CLID SG::VarHandleBase::clid ( ) const
inherited

Return the class ID for the referenced object.

◆ cptr()

template<class T>
const_pointer_type SG::WriteHandle< T >::cptr ( ) const

Dereference the pointer.

Returns the cached pointer.

◆ doPut() [1/3]

template<class T>
template<class AUXSTORE>
WriteHandle< T >::const_pointer_type SG::WriteHandle< T >::doPut ( const EventContext * ctx,
std::unique_ptr< const T > data,
std::unique_ptr< const AUXSTORE > auxstore ) const
private

Helper for recording an object and its auxiliary store to the store.

Parameters
ctxThe event context, or nullptr to use the current context.
dataThe object to record.
auxstoreAuxiliary store object.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, and the objects passed in are destroyed.

◆ doPut() [2/3]

template<class T>
template<class AUXSTORE>
WriteHandle< T >::const_pointer_type SG::WriteHandle< T >::doPut ( const EventContext * ctx,
std::unique_ptr< T > data,
std::unique_ptr< AUXSTORE > auxstore ) const
private

Helper for recording an object and its auxiliary store to the store.

Parameters
ctxThe event context, or nullptr to use the current context.
dataThe object to record.
auxstoreAuxiliary store object.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, and the objects passed in are destroyed.

◆ doPut() [3/3]

template<class T>
template<class U>
const_pointer_type SG::WriteHandle< T >::doPut ( const EventContext * ctx,
U data,
bool returnExisting,
IProxyDict *& store ) const
private

Helper for put.

Parameters
ctxThe event context, or nullptr to use the current context.
dataThe object to record.
returnExistingAllow an existing object.
[out]storeThe store being used.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, unless returnExisting is true, in which case return success. In either case, data is destroyed.

◆ doRecord()

template<class T>
template<class U>
StatusCode SG::WriteHandle< T >::doRecord ( U data,
bool isConst,
bool returnExisting )
private

Helper for record.

Parameters
dataThe object to record.
isConstIf true, record the object as const.
returnExistingAllow an existing object.

◆ finalReset()

void SG::VarHandleBase::finalReset ( )
finaloverridevirtualinherited

Reset this handle at the end of processing.

hard If true, anything depending on the event store is cleared.

Same as reset(true);

Reimplemented from IResetable.

Definition at line 602 of file StoreGate/src/VarHandleBase.cxx.

602 {
603#ifdef DEBUG_VHB
604 dbg::print(stderr, "::VHB::finalReset {} with proxy={}, key={}, store={}\n", dbg::ptr(this), dbg::proxy(m_proxy), this->key(), dbg::store(this->m_store));
605#endif
606 reset (true);
607 }
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
IProxyDict * m_store
Pointer to the store that owns the object.
SG::DataProxy * m_proxy
Proxy holding the object to which we are bound.
virtual void reset() override
Free all allocated elements.
void * ptr(T *p)
Definition SGImplSvc.cxx:75
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition SGImplSvc.cxx:71

◆ fullKey()

const DataObjID & SG::VarHandleBase::fullKey ( ) const
inherited

Return the key as a DataObjID.

◆ get_impl()

const void * SG::VarHandleBase::get_impl ( const EventContext * ctx,
bool quiet = defaultQuiet ) const
protectedinherited

Definition at line 908 of file StoreGate/src/VarHandleBase.cxx.

910 {
911 if (this->mode() != Gaudi::DataHandle::Reader) {
912 if (!quiet)
913 REPORT_ERROR (StatusCode::FAILURE)
914 << "get_impl called for a non-read handle.";
915 return nullptr;
916 }
917
918 if (this->key().empty()) {
919 if (!quiet)
920 REPORT_ERROR (StatusCode::FAILURE)
921 << "Cannot initialize a Read/Write/Update handle with a null key.";
922 return nullptr;
923 }
924
925 IProxyDict* store = storeFromHandle (ctx);
926 if (!store) {
927 if (!quiet)
928 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
929 return nullptr;
930 }
931
932 SG::DataProxy* proxy = store->proxy_exact(m_key->hashedKey());
933 if (!proxy) {
934 proxy = store->proxy(this->clid(), this->key());
935 if (!proxy) {
936 if (!quiet)
937 REPORT_ERROR (StatusCode::FAILURE)
938 << "Cannot find proxy for "
939 << this->clid() << "/" << this->key();
940 return nullptr;
941 }
942 }
943
945 }
#define REPORT_ERROR(SC)
Report an error.
static const Attributes_t empty
IProxyDict * storeFromHandle(const EventContext *ctx) const
Return the store instance to use.
void * typeless_dataPointer_fromProxy(SG::DataProxy *proxy, bool quiet) const
Retrieve a pointer from a proxy.
Gaudi::DataHandle::Mode mode() const
Return the mode (read/write/update) for this handle.
const VarHandleKey * m_key
The associated key object.
std::string store() const
Return the name of the store holding the object we are proxying.
CLID clid() const
Return the class ID for the referenced object.

◆ initialize()

StatusCode SG::VarHandleBase::initialize ( bool used = true)
inherited

Verify that the handle has been configured properly.

Parameters
usedIf false, then this handle is not to be used. Instead of normal initialization, the key will be cleared.

This will return failure if the key is blank or if the event store cannot be found.

Definition at line 459 of file StoreGate/src/VarHandleBase.cxx.

460 {
461 if (!used) {
462 if (m_ownedKey) {
463 CHECK( m_ownedKey->initialize (used) );
464 }
465 return StatusCode::SUCCESS;
466 }
467
468 if (!m_store) {
469 if (m_ownedKey) {
470 CHECK( m_ownedKey->initialize() );
471 }
472 m_store = &*(this->storeHandle());
473 m_storeWasSet = false;
474 }
475
476 if (!m_store) {
477 return StatusCode::FAILURE;
478 }
479
480 return StatusCode::SUCCESS;
481 }
#define CHECK(...)
Evaluate an expression and check for errors.
std::unique_ptr< VarHandleKey > m_ownedKey
An owned VarHandleKey.
bool m_storeWasSet
True if the store was set explicitly via setProxyDict.
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.

◆ isConst()

bool SG::VarHandleBase::isConst ( ) const
inherited

True if this handle has a proxy, and the proxy is const.

Refers to the state of the proxy, not of the handle.

Definition at line 439 of file StoreGate/src/VarHandleBase.cxx.

440 {
441#ifdef DEBUG_VHB
442 dbg::print(stderr, "::VHB::isConst({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
443#endif
444 return 0 != m_proxy
445 ? m_proxy->isConst()
446 : false;
447 }

◆ isInitialized()

bool SG::VarHandleBase::isInitialized ( ) const
inherited

Has a proxy been retrieved from SG?

(Weaker test than isValid, but does not touch the disk.)

Definition at line 413 of file StoreGate/src/VarHandleBase.cxx.

414 {
415#ifdef DEBUG_VHB
416 dbg::print(stderr, "::VHB::isInitialized({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
417#endif
418 return (0 != m_proxy);
419 }

◆ isPresent()

bool SG::VarHandleBase::isPresent ( ) const
inherited

Is the referenced object present in SG?

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

Definition at line 401 of file StoreGate/src/VarHandleBase.cxx.

402 {
403 return isPresent_impl (key());
404 }
bool isPresent_impl(const std::string &key) const
Is the referenced object present in SG?

◆ isPresent_impl()

bool SG::VarHandleBase::isPresent_impl ( const std::string & key) const
protectedinherited

Is the referenced object present in SG?

Parameters
keySG key to test.

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

Definition at line 1132 of file StoreGate/src/VarHandleBase.cxx.

1133 {
1134 const DataProxy* proxy = m_proxy;
1135 if (!proxy) {
1136 const IProxyDict* store = m_store;
1137 if (!store)
1138 store = this->storeHandle().get();
1139 if (store)
1140 proxy = store->proxy(this->clid(), key);
1141 }
1142 if (proxy) {
1143 return proxy->isValid();
1144 }
1145 return false;
1146 }

◆ isSet()

bool SG::VarHandleBase::isSet ( ) const
finaloverridevirtualinherited

Has a proxy been retrieved from SG?

Same as isInitialized; this is an interface required by IResetable.

Implements IResetable.

Definition at line 427 of file StoreGate/src/VarHandleBase.cxx.

428 {
429 return isInitialized();
430 }
bool isInitialized() const
Has a proxy been retrieved from SG?

◆ isValid()

template<class T>
virtual bool SG::WriteHandle< T >::isValid ( )
finaloverridevirtual

Can the handle be successfully dereferenced?

Implements SG::VarHandleBase.

◆ key()

const std::string & SG::VarHandleBase::key ( ) const
finaloverridevirtualinherited

Return the StoreGate ID for the referenced object.

This is defined in VarHandleKey. We need to redefine it here because it's also in IResetable. (Otherwise there would be an ambiguity.)

Implements IResetable.

Definition at line 64 of file AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx.

65 {
66 return m_key->key();
67 }

◆ mode()

Gaudi::DataHandle::Mode SG::VarHandleBase::mode ( ) const
inherited

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

◆ name()

const std::string & SG::VarHandleBase::name ( ) const
inherited

Return the StoreGate ID for the referenced object.

A synonym for key().

Definition at line 75 of file AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx.

76 {
77 return this->key();
78 }

◆ objKey()

const std::string & SG::VarHandleBase::objKey ( ) const
inherited

Return the key string of the underlying DataObjID.

Compared to key(), this will be prefixed with the store name.

◆ operator*()

template<class T>
reference_type SG::WriteHandle< T >::operator* ( )

Dereference the pointer.

Returns the cached pointer. Throws ExcNullWriteHandle if null.

◆ operator->()

template<class T>
pointer_type SG::WriteHandle< T >::operator-> ( )

Dereference the pointer.

Returns the cached pointer. Throws ExcNullWriteHandle if null.

◆ operator=() [1/3]

template<class T>
WriteHandle & SG::WriteHandle< T >::operator= ( const WriteHandle< T > & rhs)

Assignment operator.

◆ operator=() [2/3]

template<class T>
WriteHandle & SG::WriteHandle< T >::operator= ( std::unique_ptr< T > data)

Alternate notation for record.

Records a non-const object.

Parameters
dataObject to record.

Throws an exception on failure.

◆ operator=() [3/3]

template<class T>
WriteHandle & SG::WriteHandle< T >::operator= ( WriteHandle< T > && rhs)
noexcept

Move operator.

◆ ptr()

template<class T>
pointer_type SG::WriteHandle< T >::ptr ( )

Dereference the pointer.

Returns the cached pointer.

◆ put() [1/12]

template<class T>
template<std::derived_from< DataObject > DOBJ>
requires std::convertible_to<DOBJ*, T*>
const_pointer_type SG::WriteHandle< T >::put ( const EventContext & ctx,
SG::DataObjectSharedPtr< DOBJ > data ) const

Record an object to the store.

Parameters
ctxThe event context to use.
dataThe object to record.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error.

The event store takes shared ownership of the object.

◆ put() [2/12]

template<class T>
const_pointer_type SG::WriteHandle< T >::put ( const EventContext & ctx,
std::unique_ptr< const ConstDataVector< T > > data,
bool returnExisting = false ) const

Record an object to the store.

Parameters
ctxThe event context to use.
dataThe object to record.
returnExistingAllow an existing object?

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, unless returnExisting is true, in which case return success. In either case, data is destroyed.

◆ put() [3/12]

template<class T>
const_pointer_type SG::WriteHandle< T >::put ( const EventContext & ctx,
std::unique_ptr< const T > data,
bool returnExisting = false ) const

Record an object to the store.

Parameters
ctxThe event context to use.
dataThe object to record.
returnExistingAllow an existing object?

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, unless returnExisting is true, in which case return success. In either case, data is destroyed.

◆ put() [4/12]

template<class T>
template<class AUXSTORE>
const_pointer_type SG::WriteHandle< T >::put ( const EventContext & ctx,
std::unique_ptr< const T > data,
std::unique_ptr< const AUXSTORE > auxstore ) const

Record an object and its auxiliary store to the store.

Parameters
ctxThe event context to use.
dataThe object to record.
auxstoreAuxiliary store object.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, and the objects passed in are destroyed.

Unlike the version taking unique_ptr<T>, this does not alter the store pointer of data.

◆ put() [5/12]

template<class T>
const_pointer_type SG::WriteHandle< T >::put ( const EventContext & ctx,
std::unique_ptr< T > data,
bool returnExisting = false ) const

Record an object to the store.

Parameters
ctxThe event context to use.
dataThe object to record.
returnExistingAllow an existing object?

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, unless returnExisting is true, in which case return success. In either case, data is destroyed.

◆ put() [6/12]

template<class T>
template<class AUXSTORE>
const_pointer_type SG::WriteHandle< T >::put ( const EventContext & ctx,
std::unique_ptr< T > data,
std::unique_ptr< AUXSTORE > auxstore ) const

Record an object and its auxiliary store to the store.

Parameters
ctxThe event context to use.
dataThe object to record.
auxstoreAuxiliary store object.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, and the objects passed in are destroyed.

◆ put() [7/12]

template<class T>
template<std::derived_from< DataObject > DOBJ>
requires std::convertible_to<DOBJ*, T*>
const_pointer_type SG::WriteHandle< T >::put ( SG::DataObjectSharedPtr< DOBJ > data) const

Record an object to the store.

Parameters
dataThe object to record.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error.

The event store takes shared ownership of the object.

◆ put() [8/12]

template<class T>
const_pointer_type SG::WriteHandle< T >::put ( std::unique_ptr< const ConstDataVector< T > > data,
bool returnExisting = false ) const

Record an object to the store.

Parameters
dataThe object to record.
returnExistingAllow an existing object?

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, unless returnExisting is true, in which case return success. In either case, data is destroyed.

◆ put() [9/12]

template<class T>
const_pointer_type SG::WriteHandle< T >::put ( std::unique_ptr< const T > data,
bool returnExisting = false ) const

Record an object to the store.

Parameters
dataThe object to record.
returnExistingAllow an existing object?

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, unless returnExisting is true, in which case return success. In either case, data is destroyed.

◆ put() [10/12]

template<class T>
template<class AUXSTORE>
const_pointer_type SG::WriteHandle< T >::put ( std::unique_ptr< const T > data,
std::unique_ptr< const AUXSTORE > auxstore ) const

Record an object and its auxiliary store to the store.

Parameters
dataThe object to record.
auxstoreAuxiliary store object.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, and the objects passed in are destroyed.

Unlike the version taking unique_ptr<T>, this does not alter the store pointer of data.

◆ put() [11/12]

template<class T>
const_pointer_type SG::WriteHandle< T >::put ( std::unique_ptr< T > data,
bool returnExisting = false ) const

Record an object to the store.

Parameters
dataThe object to record.
returnExistingAllow an existing object?

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, unless returnExisting is true, in which case return success. In either case, data is destroyed.

◆ put() [12/12]

template<class T>
template<class AUXSTORE>
const_pointer_type SG::WriteHandle< T >::put ( std::unique_ptr< T > data,
std::unique_ptr< AUXSTORE > auxstore ) const

Record an object and its auxiliary store to the store.

Parameters
dataThe object to record.
auxstoreAuxiliary store object.

Unlike record(), this does not change the handle object. That means that one will not be able to get the object back by dereferencing the handle. Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, and the objects passed in are destroyed.

◆ put_impl()

const void * SG::VarHandleBase::put_impl ( const EventContext * ctx,
std::unique_ptr< DataObject > dobj,
const void * dataPtr,
bool allowMods,
bool returnExisting,
IProxyDict *& store ) const
protectedinherited

Helper to record an object in the event store.

Unlike record, put does not change the handle and does not cache the pointer in the handle.

Parameters
ctxThe event context, or nullptr to use the current context.
dobjThe wrapped data object (DataBucket) to record.
dataPtrPointer to the transient object itself.
allowModsIf false, record the object as const.
returnExistingAllow an existing object.
[out]storeThe store being used.

Returns the object placed in the store, or nullptr if there was an error. If there was already an object in the store with the given key, then return null, unless returnExisting is true, in which case return success. In either case, dobj is destroyed.

Definition at line 810 of file StoreGate/src/VarHandleBase.cxx.

816 {
817 if (this->name().empty()) {
818 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
819 return nullptr;
820 }
821
822 store = storeFromHandle (ctx);
823 if (!store) {
824 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
825 return nullptr;
826 }
827 if (!dobj) {
828 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer.";
829 return nullptr;
830 }
831
832 SG::DataObjectSharedPtr<DataObject> sptr (std::move (dobj));
833 unsigned int initRefCount = sptr->refCount();
834 SG::DataProxy* new_proxy =
835 store->recordObject (sptr, this->name(), allowMods, returnExisting);
836 if (!new_proxy) {
837 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
838 return nullptr;
839 }
840
841 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
842 // If the reference count hasn't changed, then we've returned an existing
843 // object rather than recording a new one. Retrieve the pointer.
844 dataPtr = typeless_dataPointer_fromProxy (new_proxy, true);
845 }
846
847 return dataPtr;
848 }
bool isValid() const
called by destructor
const std::string & name() const
Return the StoreGate ID for the referenced object.
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr

◆ record() [1/4]

template<class T>
template<std::derived_from< DataObject > DOBJ>
requires std::convertible_to<DOBJ*, T*>
StatusCode SG::WriteHandle< T >::record ( SG::DataObjectSharedPtr< DOBJ > data)

Record a const shared DataObject to the store.

Parameters
dataThe object to record.

The event store takes shared ownership of the object.

◆ record() [2/4]

template<class T>
StatusCode SG::WriteHandle< T >::record ( std::unique_ptr< T > data)

Record a const object to the store.

Parameters
dataThe object to record.

◆ record() [3/4]

template<class T>
template<class AUXSTORE>
StatusCode SG::WriteHandle< T >::record ( std::unique_ptr< T > data,
std::unique_ptr< AUXSTORE > auxstore,
bool isConst )
private

Record an object and its auxiliary store to the store.

Parameters
dataThe object to record.
auxstoreAuxiliary store object.
isConstIf true, record the objects as const.

◆ record() [4/4]

template<class T>
template<class AUXSTORE>
StatusCode SG::WriteHandle< T >::record ( std::unique_ptr< T > data,
std::unique_ptr< AUXSTORE > store )

Record a const object and its auxiliary store to the store.

Parameters
dataThe object to record.
auxstoreAuxiliary store object.

◆ record_impl()

StatusCode SG::VarHandleBase::record_impl ( std::unique_ptr< DataObject > dobj,
void * dataPtr,
bool allowMods,
bool returnExisting )
protectedinherited

Helper to record an object in the event store.

Parameters
Thewrapped data object (DataBucket) to record.
dataPtrPointer to the transient object itself.
allowModsIf false, record the object as const.
returnExistingAllow an existing object.

If there is already an existing object with our key, then return failure, unless returnExisting is true, in which case return success. In either case, dobj is destroyed.

Definition at line 737 of file StoreGate/src/VarHandleBase.cxx.

741 {
742 if (!m_store) {
743 if (m_ownedKey) {
744 CHECK (m_ownedKey->initialize());
745 }
746 m_store = &*(this->storeHandle());
747 m_storeWasSet = false;
748 }
749
750 if (this->name().empty()) {
751 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
752 return StatusCode::FAILURE;
753 }
754 if (!dobj) {
755 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer";
756 return StatusCode::FAILURE;
757 }
758
759 SG::DataObjectSharedPtr<DataObject> sptr (dobj.release());
760 unsigned int initRefCount = sptr->refCount();
761 SG::DataProxy* new_proxy =
762 m_store->recordObject (sptr, this->name(), allowMods, returnExisting);
763 if (!new_proxy) {
764 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
765 resetProxy();
766 return StatusCode::FAILURE;
767 }
768 if (m_proxy != new_proxy) {
769 CHECK (this->setState (new_proxy));
770 }
771
772 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
773 // If the reference count hasn't changed, then we've returned an existing
774 // object rather than recording a new one. Retrieve the pointer, making
775 // sure that it isn't const.
776 if (m_proxy->isConst()) {
777 REPORT_ERROR (StatusCode::FAILURE)
778 << "Found an existing const object from recordOrRetrieve.";
779 return StatusCode::FAILURE;
780 }
782 if (!allowMods)
783 CHECK( setConst() );
784 }
785 else
786 m_ptr=(void*)dataPtr;
787
788 return StatusCode::SUCCESS;
789 }
StatusCode setState()
Retrieve and cache all information managed by a handle.
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
void * m_ptr
The object to which we are bound.
void * typeless_dataPointer_impl(bool quiet)
Retrieve an object from StoreGate.
void resetProxy()
Clear the m_proxy field and release the old proxy.

◆ recordNonConst() [1/3]

template<class T>
template<std::derived_from< DataObject > DOBJ>
requires std::convertible_to<DOBJ*, T*>
StatusCode SG::WriteHandle< T >::recordNonConst ( SG::DataObjectSharedPtr< DOBJ > data)

Record a non-const shared DataObject to the store.

Parameters
dataThe object to record.

The event store takes shared ownership of the object.

◆ recordNonConst() [2/3]

template<class T>
StatusCode SG::WriteHandle< T >::recordNonConst ( std::unique_ptr< T > data)

Record a non-const object to the store.

Parameters
dataThe object to record.

◆ recordNonConst() [3/3]

template<class T>
template<class AUXSTORE>
StatusCode SG::WriteHandle< T >::recordNonConst ( std::unique_ptr< T > data,
std::unique_ptr< AUXSTORE > store )

Record a non-const object and its auxiliary store to the store.

Parameters
dataThe object to record.
auxstoreAuxiliary store object.

◆ reset()

void SG::VarHandleBase::reset ( bool hard)
overridevirtualinherited

Reset this handle.

Parameters
hardIf true, anything depending on the event store is cleared.

If the handle stays associated with a given event store, then hard=false. In that case, we clear the cached pointer; the proxy is also dropped if it is reset only. If hard=true, then we always drop the proxy and in addition clear the cached pointer to the event store.

Implements IResetable.

Reimplemented in SG::UpdateHandle< T >, and SG::UpdateHandle< IDCBackend >.

Definition at line 577 of file StoreGate/src/VarHandleBase.cxx.

577 {
578#ifdef DEBUG_VHB
579 dbg::print(stderr, "::VHB::reset {} with proxy={}, key={}, store={} (hard={})\n", dbg::ptr(this), dbg::proxy(m_proxy), this->key(), dbg::store(this->m_store), hard);
580#endif
581 m_ptr = 0;
582
583 if (hard) {
584 m_store = 0;
585 m_storeWasSet = false;
586 }
587
588 //if the proxy is not resetOnly then release it as it will become invalid
589 // Also release on a hard reset.
590 if (0 != m_proxy && (!m_proxy->isResetOnly() || hard)) {
591 resetProxy();
592 }
593 }

◆ resetProxy()

void SG::VarHandleBase::resetProxy ( )
privateinherited

Clear the m_proxy field and release the old proxy.

Definition at line 1035 of file StoreGate/src/VarHandleBase.cxx.

1036 {
1037 if (m_proxy) {
1038 if (m_ownedKey) {
1039 m_proxy->unbindHandle(this);
1040 m_proxy->release();
1041 }
1042 m_proxy = nullptr;
1043 }
1044 }

◆ setConst()

StatusCode SG::VarHandleBase::setConst ( )
inherited

Set the 'const' bit for the bound proxy in the store.

Definition at line 613 of file StoreGate/src/VarHandleBase.cxx.

614 {
615 if (typeless_dataPointer()) {
616 m_proxy->setConst();
617 return StatusCode::SUCCESS;
618 }
619 return StatusCode::FAILURE;
620 }
void * typeless_dataPointer(bool quiet=defaultQuiet)
Retrieve an object from StoreGate.

◆ setProxy()

void SG::VarHandleBase::setProxy ( SG::DataProxy * proxy)
privateinherited

Set a new proxy.

Release any old one first.

Parameters
proxyThe new proxy.

Definition at line 1051 of file StoreGate/src/VarHandleBase.cxx.

1052 {
1053 resetProxy();
1054 if (proxy) {
1055 if (m_ownedKey) {
1056 proxy->addRef();
1057 proxy->bindHandle (this);
1058 }
1059 m_proxy = proxy;
1060 }
1061 }

◆ setProxyDict()

StatusCode SG::VarHandleBase::setProxyDict ( IProxyDict * store)
virtualinherited

Explicitly set the event store.

Parameters
storeThe new event store.

This implicitly does a reset().

Reimplemented in SG::WriteDecorHandle< Cont_t, dType >, SG::WriteDecorHandle< Cont_t, float >, SG::WriteDecorHandle< Cont_t, SegCov_t >, SG::WriteDecorHandle< Cont_t, SegPars_t >, SG::WriteDecorHandle< Cont_t, std::vector< char > >, SG::WriteDecorHandle< Cont_t, std::vector< ElementLink< xAOD::UncalibratedMeasurementContainer > > >, SG::WriteDecorHandle< container_t, xAOD::CaloRingsLinks >, SG::WriteDecorHandle< DataVector< IParticle >, float >, SG::WriteDecorHandle< DataVector< IParticle >, uint32_t >, SG::WriteDecorHandle< DataVector< xAOD::Electron_v1 >, float >, SG::WriteDecorHandle< DataVector< xAOD::Electron_v1 >, int >, SG::WriteDecorHandle< DataVector< xAOD::Jet_v1 >, float >, SG::WriteDecorHandle< DataVector< xAOD::Jet_v1 >, std::vector< float > >, SG::WriteDecorHandle< DataVector< xAOD::Jet_v1 >, std::vector< int > >, SG::WriteDecorHandle< DataVector< xAOD::TrackParticle_v1 >, float >, SG::WriteDecorHandle< DataVector< xAOD::TrackParticle_v1 >, std::vector< char > >, SG::WriteDecorHandle< DataVector< xAOD::TrackParticle_v1 >, std::vector< float > >, SG::WriteDecorHandle< DataVector< xAOD::TrackParticle_v1 >, std::vector< int > >, SG::WriteDecorHandle< xAOD::CaloClusterContainer, std::vector< ElementLink< xAOD::CaloClusterContainer > > >, SG::WriteDecorHandle< xAOD::IParticleContainer, float >, SG::WriteDecorHandle< xAOD::IParticleContainer, short >, SG::WriteDecorHandle< xAOD::JetContainer, ElementLink< xAOD::JetContainer > >, SG::WriteDecorHandle< xAOD::JetContainer, float >, and SG::WriteDecorHandle< xAOD::JetContainer, int >.

Definition at line 558 of file StoreGate/src/VarHandleBase.cxx.

559 {
560 reset(true);
561 m_store = store;
562 m_storeWasSet = true;
563 return StatusCode::SUCCESS;
564 }

◆ setState() [1/3]

StatusCode SG::VarHandleBase::setState ( )
inherited

Retrieve and cache all information managed by a handle.

This will retrieve and cache the associated DataProxy.

Note for the case of a WriteHandle that has not yet been written to, the proxy may not exist. We return Success in that case; however, isInitialized will still return false.

Definition at line 494 of file StoreGate/src/VarHandleBase.cxx.

495 {
496 CHECK( initialize() );
497 if (!m_storeWasSet) {
498 IProxyDict* store = storeFromHandle (nullptr);
499 if (store) m_store = store;
500 }
501
502#ifdef DEBUG_VHB
503 dbg::print(stderr, "::VHB:: setState() on {} with key={} ({}) and store={} (CLID: {})\n", dbg::ptr(this), this->key(), m_key->hashedKey(), dbg::store(m_store), this->clid());
504#endif
505
506 SG::DataProxy* proxy = m_store->proxy_exact (m_key->hashedKey());
507 if (!proxy) {
508#ifdef DEBUG_VHB
509 dbg::print(stderr, "::VHB:: setState() on {} ==> null proxy!\n", dbg::ptr(this));
510#endif
511 proxy = m_store->proxy(this->clid(), this->key());
512 }
513
514 if (!proxy) {
515#ifdef DEBUG_VHB
516 dbg::print(stderr, "::VHB:: setState() on {} ==> STILL null proxy!\n", dbg::ptr(this));
517#endif
518 }
519 else if (!proxy->isValid()) {
520#ifdef DEBUG_VHB
521 dbg::print(stderr, "::VHB:: setState() on {} ==> proxy not valid! Dumping Store\n", dbg::ptr(this));
522 if (!m_store) {
523 dbg::print(stderr, "::VHB:: setState() on {} ==> m_store is a nullptr\n", dbg::ptr(this));
524 }
525 else {
526 SGImplSvc* stor = dynamic_cast<SGImplSvc*>(m_store);
527 if (!stor) {
528 dbg::print(stderr, "::VHB:: setState() on {} ==> m_store points not to an SGImplSvc but to a {}\n", dbg::ptr(this), boost::core::demangle(typeid(*m_store).name()));
529 }
530 else {
531 dbg::print(stderr, "\n{}\n", stor->dump());
532 }
533 }
534#endif
535 }
536 StatusCode sc = this->setState(proxy);
537
538 // Failure to find the proxy is ok in the case of a @c WriteHandle
539 // that has not yet been written to.
540 if (sc.isFailure() && mode() == Gaudi::DataHandle::Writer && m_ptr == nullptr)
541 return StatusCode::SUCCESS;
542
543 return sc;
544 }
static Double_t sc
std::string dump() const
dump objects in store.
::StatusCode StatusCode
StatusCode definition for legacy code.
void initialize()

◆ setState() [2/3]

StatusCode SG::VarHandleBase::setState ( IProxyDict * store,
const std::string & key )
protectedinherited

Set the state of a handle from a store and a key name.

Parameters
storeThe event store to access.
nameThe StoreGate key to search for.

Fails if no such object is recorded.

Parameters
storeThe event store to access.
nameThe StoreGate key to search for.

Definition at line 711 of file StoreGate/src/VarHandleBase.cxx.

712 {
713 if (0 == store) {
714 return StatusCode::FAILURE;
715 }
716#ifdef DEBUG_VHB
717 dbg::print(stderr, "::VHB::setState({}, store={}, key={}) const\n", dbg::ptr(this), dbg::store(store), key);
718#endif
719 CLID cid = this->clid();
720 SG::DataProxy* proxy = store->proxy(cid, key);
721 return this->setState(proxy);
722 }
uint32_t CLID
The Class ID type.

◆ setState() [3/3]

StatusCode SG::VarHandleBase::setState ( SG::DataProxy * proxy)
protectedinherited

Set the state of the handle to a given proxy.

Parameters
proxyThe proxy to set.

The proxy must be valid; otherwise FAILURE will be returned.

Definition at line 685 of file StoreGate/src/VarHandleBase.cxx.

686 {
687#ifdef DEBUG_VHB
688 dbg::print(stderr, "::VHB::setState({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(proxy));
689#endif
690 if (0 == proxy || !proxy->isValid()) {
691 return StatusCode::FAILURE;
692 }
693
694 if (m_proxy != proxy) {
695 // We're changing proxies. Release the old and bind to the new.
696 setProxy (proxy);
697 // Clear cached pointer.
698 m_ptr=0;
699 }
700
701 return StatusCode::SUCCESS;
702 }
void setProxy(SG::DataProxy *proxy)
Set a new proxy.

◆ setStoreFromHandle()

bool SG::VarHandleBase::setStoreFromHandle ( const EventContext * ctx)
privateinherited

Initialize the store pointer from the store handle.

Also checks that the key is valid.

Parameters
ctxThe current event context, or nullptr.

Returns true on success.

Definition at line 1018 of file StoreGate/src/VarHandleBase.cxx.

1019 {
1020 if (m_ownedKey) {
1021 if (m_ownedKey->initialize().isFailure()) {
1022 return false;
1023 }
1024 }
1025 m_store = storeFromHandle (ctx);
1026 m_storeWasSet = (ctx && m_store ==
1027 Atlas::getExtendedEventContext(*ctx).proxy());
1028 return true;
1029 }
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.

◆ store()

std::string SG::VarHandleBase::store ( ) const
inherited

Return the name of the store holding the object we are proxying.

Definition at line 383 of file StoreGate/src/VarHandleBase.cxx.

384 {
385 if (m_store)
386 return m_store->name();
387 return this->storeHandle().name();
388 }

◆ storeFromHandle()

IProxyDict * SG::VarHandleBase::storeFromHandle ( const EventContext * ctx) const
privateinherited

Return the store instance to use.

Parameters
ctxThe current event context, or nullptr.
ctxThe current event context, or nullptr.

If we're referencing the default event store, pick the specific store to use in this order:

  • Store associated with an explicitly-provided context.
  • A store explicitly set via setProxyDict.
  • Store associated with the current context.

For another store:

  • A store explicitly set via setProxyDict.
  • The store retrieved from the handle, resolved to the current slot if it's a hive store.

Definition at line 989 of file StoreGate/src/VarHandleBase.cxx.

990 {
991 if (m_key->isEventStore()) {
992 if (ctx)
993 return Atlas::getExtendedEventContext(*ctx).proxy();
994 if (m_storeWasSet && m_store) return m_store;
995
996 const Atlas::ExtendedEventContext* ectx =
997 Atlas::tryGetExtendedEventContext (Gaudi::Hive::currentContext());
998
999 return (ectx ? ectx->proxy() : nullptr);
1000 }
1001
1002 if (m_storeWasSet && m_store) return m_store;
1003 IProxyDict* store = m_store;
1004 if (!store)
1005 store = &*this->storeHandle();
1006
1007 return store->hiveProxyDict();
1008 }
const ExtendedEventContext * tryGetExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.

◆ storeHandle()

const ServiceHandle< IProxyDict > & SG::VarHandleBase::storeHandle ( ) const
inherited

Return handle to the referenced store.

◆ symLink()

template<class T>
template<class U>
StatusCode SG::WriteHandle< T >::symLink ( const WriteHandleKey< U > & key)

Make an explicit link.

Parameters
keyAlternate clid by which the referenced object should be known. The SG key must match the key of the current handle.

You should generally not be using this!

The current handle should be valid and referencing an object (i.e., record should have been called on it).

This makes a symlink: the object will be retrievable as a different type.

Note that if T and @U are related via SG_BASE and/or DATAVECTOR_BASE, then you shouldn't need to explicitly make a symlink; that should happen automatically.

If a U* is not convertable to a T* via C++ rules, then you likely will be, at best, relying on undefined behavior. You will probably get warnings from the undefined behavior sanitizer when if you try to dereference the U*.

This usage is here mainly to assist in migrating some existing patterns to MT. You should think several times before using in new code.

◆ symLink_impl()

StatusCode SG::VarHandleBase::symLink_impl ( CLID newClid,
const std::string & newKey )
protectedinherited

Make a symlink or alias to the object currently referenced by this handle.

Parameters
newClidCLID of link.
newKeySG key of link.

If newClid matches the existing clid, then make an alias. If newKey matches the existing key, then make a symlink. If neither match, it's an error.

Definition at line 958 of file StoreGate/src/VarHandleBase.cxx.

960 {
961 if (!m_ptr || !m_store) {
962 REPORT_ERROR (StatusCode::FAILURE) << "symlink: Handle not valid.";
963 return StatusCode::FAILURE;
964 }
965
966 SG::DataObjectSharedPtr<DataObject> obj (new SymlinkDataObject (newClid, m_ptr));
967 SG::DataProxy* prox = m_store->recordObject (obj, newKey, false, true);
968 if (!prox)
969 return StatusCode::FAILURE;
970 return StatusCode::SUCCESS;
971 }

◆ toString()

std::string SG::VarHandleBase::toString ( ) const
inherited

Convert to a string representation.

Definition at line 658 of file StoreGate/src/VarHandleBase.cxx.

659 {
660 std::string s =
661 std::format ("VarHandleBase @{} store={}, clid={}, key{}----------- ptr@{}, proxy@{}",
662 static_cast<const void*>(this),
663 store(), clid(), key(),
665 static_cast<const void*>(m_proxy));
666 if (m_proxy)
667 s += std::format (", DataObject@{}",
668 static_cast<const void*>(m_proxy->object()));
669 return s;
670 }
const T * as_const_ptr(const T *p)
Helper for getting a const version of a pointer.

◆ typeless_cptr()

const void * SG::VarHandleBase::typeless_cptr ( )
protectedinherited

Retrieve an object from StoreGate as a const pointer.

Same as typeless_dataPointer with the return value converted to const.

◆ typeless_dataPointer()

void * SG::VarHandleBase::typeless_dataPointer ( bool quiet = defaultQuiet)
protectedinherited

Retrieve an object from StoreGate.

Parameters
quietIf true, suppress failure messages.

Inline method: first check cached pointer, then call the _impl method.

◆ typeless_dataPointer_fromProxy()

void * SG::VarHandleBase::typeless_dataPointer_fromProxy ( SG::DataProxy * proxy,
bool quiet ) const
privateinherited

Retrieve a pointer from a proxy.

Parameters
proxyThe proxy object.
quietIf true, suppress failure messages.

Warning — doesn't enforce const rules; the caller must do that.

Definition at line 1072 of file StoreGate/src/VarHandleBase.cxx.

1074 {
1075 if (!proxy || !proxy->isValid()) {
1076 // invalid proxy
1077 if (!quiet) {
1078 REPORT_MESSAGE(MSG::WARNING)
1079 << "Proxy "
1080 << " [" << (proxy != 0 ? proxy->clID() : 0)
1081 << "/" << (proxy != 0
1082 ? proxy->name()
1083 : std::string("<N/A>"))
1084 << "] is in an invalid state";
1085 } //quiet
1086 return nullptr;
1087 }
1088
1089 DataObject* dobj = proxy->accessData();
1090 if (!dobj) {
1091 // invalid dobj
1092 if (!quiet) {
1093 REPORT_MESSAGE(MSG::WARNING)
1094 << "this proxy " << MSG::hex << proxy
1095 << MSG::dec << " has a NULL data object ptr";
1096 }
1097 return nullptr;
1098 }
1099
1100 const CLID clid = this->clid();
1101 void* ptr = SG::Storable_cast(dobj, clid, nullptr, true, proxy);
1102 if (ptr)
1103 return ptr;
1104
1105 // If ptr is null, probably the clid we gave wasn't the clid
1106 // the object was stored with, nor it inherits from it.
1107 // before giving up, let's check its transient CLIDs
1108 DataBucketBase *dbb = 0;
1109 if (proxy->transientID(clid) &&
1110 0 != (dbb = dynamic_cast<DataBucketBase*>(dobj))) {
1111 // it is a symlink after all.
1112 // Let's hard cast (and keep our fingers Xed)
1113 ptr = static_cast<void*>(dbb->object());
1114 } else {
1115 if (!quiet) {
1116 REPORT_MESSAGE(MSG::WARNING)
1117 << "Request for an invalid object; requested CLID = "
1118 << clid
1119 << ", proxy primary ID is " << proxy->clID();
1120 }
1121 } // try symlink -- endif
1122 return ptr;
1123 }
#define REPORT_MESSAGE(LVL)
Report a message.
virtual void * object()=0
T * Storable_cast(DataObject *pDObj, bool quiet=true, IRegisterTransient *irt=0, bool isConst=true)

◆ typeless_dataPointer_impl()

void * SG::VarHandleBase::typeless_dataPointer_impl ( bool quiet)
protectedinherited

Retrieve an object from StoreGate.

Parameters
quietIf true, suppress failure messages.

Definition at line 856 of file StoreGate/src/VarHandleBase.cxx.

857 {
858#ifdef DEBUG_VHB
859 dbg::print(stderr, "::VHB::typeless_dataPointer_impl({}, ptr={}, proxy={}, key={}, store={})\n", dbg::ptr(this), dbg::ptr(this->m_ptr), dbg::proxy(this->m_proxy), this->key(), dbg::store(this->m_store));
860#endif
861
862 // First check for cached pointer.
863 if (0 != m_ptr)
864 return m_ptr;
865
866 if (0 == m_proxy) {
867 // No proxy, need to look it up.
868 if (this->setState().isFailure() || !m_proxy) {
869 if (!quiet) {
870 REPORT_MESSAGE(MSG::WARNING)
871 << "could not get proxy for key " << key();
872 if (this->mode() != Gaudi::DataHandle::Reader) {
873 REPORT_MESSAGE(MSG::WARNING)<< " try using a ReadHandle";
874 }
875 } //quiet
876 return 0;
877 } //setstate
878 } //m_proxy
879
881 return m_ptr;
882 }

◆ typeless_ptr()

void * SG::VarHandleBase::typeless_ptr ( bool quiet = defaultQuiet)
protectedinherited

Retrieve an object from StoreGate as non-const pointer.

Calls typeless_dataPointer, then raises an exception if the proxy is marked as const.

Definition at line 891 of file StoreGate/src/VarHandleBase.cxx.

892 {
894 if (p != nullptr && isConst())
895 throw SG::ExcConstObject (clid(), key(), store());
896 return p;
897 }
bool isConst() const
True if this handle has a proxy, and the proxy is const.

◆ vhKey()

SG::VarHandleKey & SG::VarHandleBase::vhKey ( )
inherited

Return a non-const reference to the HandleKey.

If this handle was initialized from a HandleKey, then this doesn't work (since the HandleKey is const). ExcNonConstHandleKey will be thrown in that case.

Definition at line 630 of file StoreGate/src/VarHandleBase.cxx.

631 {
632 if (!m_ownedKey) {
633 throwExcNonConstHandleKey (m_key->clid(), m_key->key(),
634 m_key->storeHandle().name());
635 }
636 return *m_ownedKey;
637 }
void throwExcNonConstHandleKey(CLID clid, const std::string &sgkey, const std::string &storename)
Throw a SG::ExcNonConstHandleKey exception.

Member Data Documentation

◆ m_key

const VarHandleKey* SG::VarHandleBase::m_key
privateinherited

The associated key object.

If we were initialized from a key object, then this points at that. Otherwise, it points at the same object as m_ownedKey.

Definition at line 530 of file StoreGate/StoreGate/VarHandleBase.h.

◆ m_lockAuxPending

template<class T>
SG::DataProxy* SG::WriteHandle< T >::m_lockAuxPending = nullptr
private

If non-null, then we need to lock the associated aux store object when we're deleted.

This is set when we record an object along with the associated aux const with the const flag set (the default). Recall that for a const record, we want to support the semantics that you can get a non-const pointer back from the handle as long as it exists, to finish initialization of the object. For an aux store, though, just getting back a non-const pointer is not sufficient, since the store will have been locked at the time of the record, preventing changes to the store.

So if we're meant to record a const aux store object, we don't actually set it const on the record, but instead set this and do the setConst in the destructor.

Definition at line 691 of file StoreGate/StoreGate/WriteHandle.h.

◆ m_ownedKey

std::unique_ptr<VarHandleKey> SG::VarHandleBase::m_ownedKey
privateinherited

An owned VarHandleKey.

This is set in the case where a VarHandle is not initialized from a key object.

Definition at line 525 of file StoreGate/StoreGate/VarHandleBase.h.

◆ m_proxy

SG::DataProxy* SG::VarHandleBase::m_proxy
protectedinherited

Proxy holding the object to which we are bound.

Definition at line 512 of file StoreGate/StoreGate/VarHandleBase.h.

◆ m_ptr

void* SG::VarHandleBase::m_ptr
protectedinherited

The object to which we are bound.

Definition at line 509 of file StoreGate/StoreGate/VarHandleBase.h.

◆ m_store

IProxyDict* SG::VarHandleBase::m_store
protectedinherited

Pointer to the store that owns the object.

Definition at line 515 of file StoreGate/StoreGate/VarHandleBase.h.

◆ m_storeWasSet

bool SG::VarHandleBase::m_storeWasSet
protectedinherited

True if the store was set explicitly via setProxyDict.

Definition at line 518 of file StoreGate/StoreGate/VarHandleBase.h.


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