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

#include <ReadHandle.h>

Inherits SG::VarHandleBase.

Inherited by SG::WriteDecorHandle< xAOD::MuonSegmentContainer, HitLinkVec_t >, SG::WriteDecorHandle< xAOD::MuonSegmentContainer, float >, SG::WriteDecorHandle< xAOD::MuonSegmentContainer, SegPars_t >, SG::WriteDecorHandle< PrdCont_t, bool >, SG::WriteDecorHandle< PrdCont_t, SegLinkVec_t >, SG::WriteDecorHandle< xAOD::IParticleContainer, float >, SG::WriteDecorHandle< xAOD::IParticleContainer, short >, SG::WriteDecorHandle< xAOD::JetContainer, int >, SG::WriteDecorHandle< xAOD::JetContainer, float >, SG::WriteDecorHandle< xAOD::TrackParticleContainer, bool >, and SG::WriteDecorHandle< container_t, xAOD::CaloRingsLinks >.

Collaboration diagram for SG::ReadHandle< 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

 ReadHandle ()
 Default constructor.
 ReadHandle (const std::string &sgkey, const std::string &storename=StoreID::storeName(StoreID::EVENT_STORE))
 Constructor specifying the key as a string.
 ReadHandle (const std::string &sgkey, const EventContext &ctx)
 Constructor specifying the key as a string, with context.
 ReadHandle (const std::string &sgkey, const std::string &storename, const EventContext &ctx)
 Constructor specifying the key as a string, with context.
 ReadHandle (const ReadHandleKey< T > &key)
 Constructor from a ReadHandleKey.
 ReadHandle (const ReadHandleKey< T > &key, const EventContext &ctx)
 Constructor from a ReadHandleKey and an explicit event context.
 ReadHandle (SG::DataProxy *proxy)
 Constructor from a DataProxy.
 ReadHandle (SG::ReadHandleKey< T > &&key)=delete
 ReadHandle (SG::ReadHandleKey< T > &&key, const EventContext &ctx)=delete
 ReadHandle (const ReadHandle &rhs)
 Copy constructor.
 ReadHandle (ReadHandle &&rhs)
 Move constructor.
ReadHandleoperator= (const ReadHandle &rhs)
 Assignment operator.
ReadHandleoperator= (ReadHandle &&rhs)
 Move operator.
const_pointer_type operator-> ()
 Dereference the pointer.
const_reference_type operator* ()
 Dereference the pointer.
const_pointer_type cptr ()
 Dereference the pointer.
const_pointer_type ptr ()
 Dereference the pointer.
const_pointer_type cachedPtr () const
 Return the cached pointer directly; no lookup.
virtual bool isValid () override final
 Can the handle be successfully dereferenced?
const_pointer_type get () const
 Dereference the pointer, but don't cache anything.
const_pointer_type get (const EventContext &ctx) const
 Dereference the pointer, but don't cache anything.
StatusCode alias (const WriteHandleKey< T > &key)
 Make an alias.
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::VarHandleKeyvhKey ()
 Return a non-const reference to the HandleKey.
StatusCode assign (const std::string &sgkey)
 Update the underlying key from a string.

Protected Member Functions

 ReadHandle (const VarHandleKey &key, const EventContext *ctx)
 Protected constructor used by WriteDecorHandle.
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::DataProxym_proxy
 Proxy holding the object to which we are bound.
IProxyDictm_store
 Pointer to the store that owns the object.
bool m_storeWasSet
 True if the store was set explicitly via setProxyDict.

Private Member Functions

const_pointer_type checkedCPtr ()
 Helper: dereference the pointer.
IProxyDictstoreFromHandle (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

std::unique_ptr< VarHandleKeym_ownedKey
 An owned VarHandleKey.
const VarHandleKeym_key
 The associated key object.

Detailed Description

template<class T>
class SG::ReadHandle< T >

Definition at line 65 of file StoreGate/StoreGate/ReadHandle.h.

Member Typedef Documentation

◆ const_pointer_type

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

Definition at line 70 of file StoreGate/StoreGate/ReadHandle.h.

◆ const_reference_type

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

Definition at line 72 of file StoreGate/StoreGate/ReadHandle.h.

◆ pointer_type

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

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

◆ reference_type

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

Definition at line 71 of file StoreGate/StoreGate/ReadHandle.h.

Constructor & Destructor Documentation

◆ ReadHandle() [1/12]

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

Default constructor.

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

◆ ReadHandle() [2/12]

template<class T>
SG::ReadHandle< T >::ReadHandle ( 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.

◆ ReadHandle() [3/12]

template<class T>
SG::ReadHandle< T >::ReadHandle ( 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.

◆ ReadHandle() [4/12]

template<class T>
SG::ReadHandle< T >::ReadHandle ( 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.

◆ ReadHandle() [5/12]

template<class T>
SG::ReadHandle< T >::ReadHandle ( const ReadHandleKey< T > & key)
explicit

Constructor from a ReadHandleKey.

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.

◆ ReadHandle() [6/12]

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

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

◆ ReadHandle() [7/12]

template<class T>
SG::ReadHandle< T >::ReadHandle ( SG::DataProxy * proxy)
explicit

Constructor from a DataProxy.

Parameters
proxyThe proxy to which to bind.
modeMode of this handle (read/write/update).

This handle will be bound to the given proxy.

◆ ReadHandle() [8/12]

template<class T>
SG::ReadHandle< T >::ReadHandle ( SG::ReadHandleKey< T > && key)
explicitdelete

◆ ReadHandle() [9/12]

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

◆ ReadHandle() [10/12]

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

Copy constructor.

◆ ReadHandle() [11/12]

template<class T>
SG::ReadHandle< T >::ReadHandle ( ReadHandle< T > && rhs)

Move constructor.

◆ ReadHandle() [12/12]

template<class T>
SG::ReadHandle< T >::ReadHandle ( const VarHandleKey & key,
const EventContext * ctx )
explicitprotected

Protected constructor used by WriteDecorHandle.

Parameters
keyThe key object holding the clid/key.
ctxThe event context, or nullptr to use the global default.

Member Function Documentation

◆ alias()

template<class T>
StatusCode SG::ReadHandle< 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.

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 648 of file StoreGate/src/VarHandleBase.cxx.

649 {
650 return vhKey().assign (sgkey);
651 }
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>
const_pointer_type SG::ReadHandle< T >::cachedPtr ( ) const

Return the cached pointer directly; no lookup.

◆ checkedCPtr()

template<class T>
const_pointer_type SG::ReadHandle< T >::checkedCPtr ( )
private

Helper: dereference the pointer.

Throws ExcNullReadHandle on failure.

◆ clid()

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

Return the class ID for the referenced object.

◆ cptr()

template<class T>
const_pointer_type SG::ReadHandle< T >::cptr ( )

Dereference the pointer.

Returns nullptr on failure.

◆ 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 601 of file StoreGate/src/VarHandleBase.cxx.

601 {
602#ifdef DEBUG_VHB
603 dbg::print(stderr, "::VHB::finalReset {} with proxy={}, key={}, store={}\n", dbg::ptr(this), dbg::proxy(m_proxy), this->key(), dbg::store(this->m_store));
604#endif
605 reset (true);
606 }
virtual void reset(bool hard) override
Reset this handle.
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.
void * ptr(T *p)
Definition SGImplSvc.cxx:74
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition SGImplSvc.cxx:70

◆ fullKey()

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

Return the key as a DataObjID.

◆ get() [1/2]

template<class T>
const_pointer_type SG::ReadHandle< T >::get ( ) const

Dereference the pointer, but don't cache anything.

◆ get() [2/2]

template<class T>
const_pointer_type SG::ReadHandle< T >::get ( const EventContext & ctx) const

Dereference the pointer, but don't cache anything.

Parameters
ctxThe event context to use.

◆ get_impl()

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

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

892 {
893 if (this->mode() != Gaudi::DataHandle::Reader) {
894 if (!quiet)
895 REPORT_ERROR (StatusCode::FAILURE)
896 << "get_impl called for a non-read handle.";
897 return nullptr;
898 }
899
900 if (this->key().empty()) {
901 if (!quiet)
902 REPORT_ERROR (StatusCode::FAILURE)
903 << "Cannot initialize a Read/Write/Update handle with a null key.";
904 return nullptr;
905 }
906
907 IProxyDict* store = storeFromHandle (ctx);
908 if (!store) {
909 if (!quiet)
910 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
911 return nullptr;
912 }
913
914 SG::DataProxy* proxy = store->proxy_exact(m_key->hashedKey());
915 if (!proxy) {
916 proxy = store->proxy(this->clid(), this->key());
917 if (!proxy) {
918 if (!quiet)
919 REPORT_ERROR (StatusCode::FAILURE)
920 << "Cannot find proxy for "
921 << this->clid() << "/" << this->key();
922 return nullptr;
923 }
924 }
925
927 }
#define REPORT_ERROR(SC)
Report an error.
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.
bool empty(TH1 *h)

◆ 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 458 of file StoreGate/src/VarHandleBase.cxx.

459 {
460 if (!used) {
461 if (m_ownedKey) {
462 CHECK( m_ownedKey->initialize (used) );
463 }
464 return StatusCode::SUCCESS;
465 }
466
467 if (!m_store) {
468 if (m_ownedKey) {
469 CHECK( m_ownedKey->initialize() );
470 }
471 m_store = &*(this->storeHandle());
472 m_storeWasSet = false;
473 }
474
475 if (!m_store) {
476 return StatusCode::FAILURE;
477 }
478
479 return StatusCode::SUCCESS;
480 }
#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 438 of file StoreGate/src/VarHandleBase.cxx.

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

◆ 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 412 of file StoreGate/src/VarHandleBase.cxx.

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

◆ 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 400 of file StoreGate/src/VarHandleBase.cxx.

401 {
402 return isPresent_impl (key());
403 }
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 1115 of file StoreGate/src/VarHandleBase.cxx.

1116 {
1117 const DataProxy* proxy = m_proxy;
1118 if (!proxy) {
1119 const IProxyDict* store = m_store;
1120 if (!store)
1121 store = this->storeHandle().get();
1122 if (store)
1123 proxy = store->proxy(this->clid(), key);
1124 }
1125 if (proxy) {
1126 return proxy->isValid();
1127 }
1128 return false;
1129 }

◆ 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 426 of file StoreGate/src/VarHandleBase.cxx.

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

◆ isValid()

template<class T>
virtual bool SG::ReadHandle< 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>
const_reference_type SG::ReadHandle< T >::operator* ( )

Dereference the pointer.

Throws ExcNullReadHandle on failure.

◆ operator->()

template<class T>
const_pointer_type SG::ReadHandle< T >::operator-> ( )

Dereference the pointer.

Throws ExcNullReadHandle on failure.

◆ operator=() [1/2]

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

Assignment operator.

◆ operator=() [2/2]

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

Move operator.

◆ ptr()

template<class T>
const_pointer_type SG::ReadHandle< T >::ptr ( )

Dereference the pointer.

Returns nullptr on failure.

◆ 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 792 of file StoreGate/src/VarHandleBase.cxx.

798 {
799 if (this->name().empty()) {
800 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
801 return nullptr;
802 }
803
804 store = storeFromHandle (ctx);
805 if (!store) {
806 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
807 return nullptr;
808 }
809 if (!dobj) {
810 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer.";
811 return nullptr;
812 }
813
814 SG::DataObjectSharedPtr<DataObject> sptr (std::move (dobj));
815 unsigned int initRefCount = sptr->refCount();
816 SG::DataProxy* new_proxy =
817 store->recordObject (sptr, this->name(), allowMods, returnExisting);
818 if (!new_proxy) {
819 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
820 return nullptr;
821 }
822
823 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
824 // If the reference count hasn't changed, then we've returned an existing
825 // object rather than recording a new one. Retrieve the pointer.
826 dataPtr = typeless_dataPointer_fromProxy (new_proxy, true);
827 }
828
829 return dataPtr;
830 }
bool isValid() const
called by destructor
const std::string & name() const
Return the StoreGate ID for the referenced object.
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr

◆ 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 719 of file StoreGate/src/VarHandleBase.cxx.

723 {
724 if (!m_store) {
725 if (m_ownedKey) {
726 CHECK (m_ownedKey->initialize());
727 }
728 m_store = &*(this->storeHandle());
729 m_storeWasSet = false;
730 }
731
732 if (this->name().empty()) {
733 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
734 return StatusCode::FAILURE;
735 }
736 if (!dobj) {
737 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer";
738 return StatusCode::FAILURE;
739 }
740
741 SG::DataObjectSharedPtr<DataObject> sptr (dobj.release());
742 unsigned int initRefCount = sptr->refCount();
743 SG::DataProxy* new_proxy =
744 m_store->recordObject (sptr, this->name(), allowMods, returnExisting);
745 if (!new_proxy) {
746 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
747 resetProxy();
748 return StatusCode::FAILURE;
749 }
750 if (m_proxy != new_proxy) {
751 CHECK (this->setState (new_proxy));
752 }
753
754 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
755 // If the reference count hasn't changed, then we've returned an existing
756 // object rather than recording a new one. Retrieve the pointer, making
757 // sure that it isn't const.
758 if (m_proxy->isConst()) {
759 REPORT_ERROR (StatusCode::FAILURE)
760 << "Found an existing const object from recordOrRetrieve.";
761 return StatusCode::FAILURE;
762 }
764 if (!allowMods)
765 CHECK( setConst() );
766 }
767 else
768 m_ptr=(void*)dataPtr;
769
770 return StatusCode::SUCCESS;
771 }
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.

◆ 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 576 of file StoreGate/src/VarHandleBase.cxx.

576 {
577#ifdef DEBUG_VHB
578 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);
579#endif
580 m_ptr = 0;
581
582 if (hard) {
583 m_store = 0;
584 m_storeWasSet = false;
585 }
586
587 //if the proxy is not resetOnly then release it as it will become invalid
588 // Also release on a hard reset.
589 if (0 != m_proxy && (!m_proxy->isResetOnly() || hard)) {
590 resetProxy();
591 }
592 }

◆ resetProxy()

void SG::VarHandleBase::resetProxy ( )
privateinherited

Clear the m_proxy field and release the old proxy.

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

1019 {
1020 if (m_proxy) {
1021 if (m_ownedKey) {
1022 m_proxy->unbindHandle(this);
1023 m_proxy->release();
1024 }
1025 m_proxy = nullptr;
1026 }
1027 }

◆ setConst()

StatusCode SG::VarHandleBase::setConst ( )
inherited

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

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

613 {
614 if (typeless_dataPointer()) {
615 m_proxy->setConst();
616 return StatusCode::SUCCESS;
617 }
618 return StatusCode::FAILURE;
619 }
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 1034 of file StoreGate/src/VarHandleBase.cxx.

1035 {
1036 resetProxy();
1037 if (proxy) {
1038 if (m_ownedKey) {
1039 proxy->addRef();
1040 proxy->bindHandle (this);
1041 }
1042 m_proxy = proxy;
1043 }
1044 }

◆ 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< 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< bool > >, SG::WriteDecorHandle< DataVector< xAOD::TrackParticle_v1 >, std::vector< float > >, SG::WriteDecorHandle< DataVector< xAOD::TrackParticle_v1 >, std::vector< int > >, SG::WriteDecorHandle< PrdCont_t, bool >, SG::WriteDecorHandle< PrdCont_t, SegLinkVec_t >, SG::WriteDecorHandle< xAOD::CaloClusterContainer, std::vector< ElementLink< xAOD::CaloClusterContainer > > >, SG::WriteDecorHandle< xAOD::IParticleContainer, float >, SG::WriteDecorHandle< xAOD::IParticleContainer, short >, SG::WriteDecorHandle< xAOD::JetContainer, float >, SG::WriteDecorHandle< xAOD::JetContainer, int >, SG::WriteDecorHandle< xAOD::MuonSegmentContainer, float >, SG::WriteDecorHandle< xAOD::MuonSegmentContainer, HitLinkVec_t >, SG::WriteDecorHandle< xAOD::MuonSegmentContainer, SegPars_t >, and SG::WriteDecorHandle< xAOD::TrackParticleContainer, bool >.

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

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

◆ 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 493 of file StoreGate/src/VarHandleBase.cxx.

494 {
495 CHECK( initialize() );
496 if (!m_storeWasSet) {
497 IProxyDict* store = storeFromHandle (nullptr);
498 if (store) m_store = store;
499 }
500
501#ifdef DEBUG_VHB
502 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());
503#endif
504
505 SG::DataProxy* proxy = m_store->proxy_exact (m_key->hashedKey());
506 if (!proxy) {
507#ifdef DEBUG_VHB
508 dbg::print(stderr, "::VHB:: setState() on {} ==> null proxy!\n", dbg::ptr(this));
509#endif
510 proxy = m_store->proxy(this->clid(), this->key());
511 }
512
513 if (!proxy) {
514#ifdef DEBUG_VHB
515 dbg::print(stderr, "::VHB:: setState() on {} ==> STILL null proxy!\n", dbg::ptr(this));
516#endif
517 }
518 else if (!proxy->isValid()) {
519#ifdef DEBUG_VHB
520 dbg::print(stderr, "::VHB:: setState() on {} ==> proxy not valid! Dumping Store\n", dbg::ptr(this));
521 if (!m_store) {
522 dbg::print(stderr, "::VHB:: setState() on {} ==> m_store is a nullptr\n", dbg::ptr(this));
523 }
524 else {
525 SGImplSvc* stor = dynamic_cast<SGImplSvc*>(m_store);
526 if (!stor) {
527 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()));
528 }
529 else {
530 dbg::print(stderr, "\n{}\n", stor->dump());
531 }
532 }
533#endif
534 }
535 StatusCode sc = this->setState(proxy);
536
537 // Failure to find the proxy is ok in the case of a @c WriteHandle
538 // that has not yet been written to.
539 if (sc.isFailure() && mode() == Gaudi::DataHandle::Writer && m_ptr == nullptr)
540 return StatusCode::SUCCESS;
541
542 return sc;
543 }
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 692 of file StoreGate/src/VarHandleBase.cxx.

693 {
694 if (0 == store) {
695 return StatusCode::FAILURE;
696 }
697#ifdef DEBUG_VHB
698 dbg::print(stderr, "::VHB::setState({}, store={}, key={}) const\n", dbg::ptr(this), dbg::store(store), key);
699#endif
700 CLID cid = this->clid();
701 SG::DataProxy* proxy = store->proxy(cid, key);
702 // std::cerr << "::VHB:: -- clid=[" << cid << "] proxy=[" << proxy << "]\n";
703 return this->setState(proxy);
704 }
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 666 of file StoreGate/src/VarHandleBase.cxx.

667 {
668#ifdef DEBUG_VHB
669 dbg::print(stderr, "::VHB::setState({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(proxy));
670#endif
671 if (0 == proxy || !proxy->isValid()) {
672 return StatusCode::FAILURE;
673 }
674
675 if (m_proxy != proxy) {
676 // We're changing proxies. Release the old and bind to the new.
677 setProxy (proxy);
678 // Clear cached pointer.
679 m_ptr=0;
680 }
681
682 return StatusCode::SUCCESS;
683 }
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 1001 of file StoreGate/src/VarHandleBase.cxx.

1002 {
1003 if (m_ownedKey) {
1004 if (m_ownedKey->initialize().isFailure()) {
1005 return false;
1006 }
1007 }
1008 m_store = storeFromHandle (ctx);
1009 m_storeWasSet = (ctx && m_store ==
1010 Atlas::getExtendedEventContext(*ctx).proxy());
1011 return true;
1012 }
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 382 of file StoreGate/src/VarHandleBase.cxx.

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

◆ 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 971 of file StoreGate/src/VarHandleBase.cxx.

972 {
973 if (m_key->isEventStore()) {
974 if (ctx)
975 return Atlas::getExtendedEventContext(*ctx).proxy();
976 if (m_storeWasSet && m_store) return m_store;
977
978 if ( Atlas::hasExtendedEventContext (Gaudi::Hive::currentContext()) ) {
979 return Atlas::getExtendedEventContext (Gaudi::Hive::currentContext()).proxy();
980 } else {
981 return nullptr;
982 }
983 }
984
985 if (m_storeWasSet && m_store) return m_store;
986 IProxyDict* store = m_store;
987 if (!store)
988 store = &*this->storeHandle();
989
990 return store->hiveProxyDict();
991 }
bool hasExtendedEventContext(const EventContext &ctx)
Test whether a context object has an extended context installed.

◆ storeHandle()

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

Return handle to the referenced store.

◆ 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 940 of file StoreGate/src/VarHandleBase.cxx.

942 {
943 if (!m_ptr || !m_store) {
944 REPORT_ERROR (StatusCode::FAILURE) << "symlink: Handle not valid.";
945 return StatusCode::FAILURE;
946 }
947
948 SG::DataObjectSharedPtr<DataObject> obj (new SymlinkDataObject (newClid, m_ptr));
949 SG::DataProxy* prox = m_store->recordObject (obj, newKey, false, true);
950 if (!prox)
951 return StatusCode::FAILURE;
952 return StatusCode::SUCCESS;
953 }

◆ 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 1055 of file StoreGate/src/VarHandleBase.cxx.

1057 {
1058 if (!proxy || !proxy->isValid()) {
1059 // invalid proxy
1060 if (!quiet) {
1061 REPORT_MESSAGE(MSG::WARNING)
1062 << "Proxy "
1063 << " [" << (proxy != 0 ? proxy->clID() : 0)
1064 << "/" << (proxy != 0
1065 ? proxy->name()
1066 : std::string("<N/A>"))
1067 << "] is in an invalid state";
1068 } //quiet
1069 return nullptr;
1070 }
1071
1072 DataObject* dobj = proxy->accessData();
1073 if (!dobj) {
1074 // invalid dobj
1075 if (!quiet) {
1076 REPORT_MESSAGE(MSG::WARNING)
1077 << "this proxy " << MSG::hex << proxy
1078 << MSG::dec << " has a NULL data object ptr";
1079 }
1080 return nullptr;
1081 }
1082
1083 const CLID clid = this->clid();
1084 void* ptr = SG::Storable_cast(dobj, clid, nullptr, true, proxy);
1085 if (ptr)
1086 return ptr;
1087
1088 // If ptr is null, probably the clid we gave wasn't the clid
1089 // the object was stored with, nor it inherits from it.
1090 // before giving up, let's check its transient CLIDs
1091 DataBucketBase *dbb = 0;
1092 if (proxy->transientID(clid) &&
1093 0 != (dbb = dynamic_cast<DataBucketBase*>(dobj))) {
1094 // it is a symlink after all.
1095 // Let's hard cast (and keep our fingers Xed)
1096 ptr = static_cast<void*>(dbb->object());
1097 } else {
1098 if (!quiet) {
1099 REPORT_MESSAGE(MSG::WARNING)
1100 << "Request for an invalid object; requested CLID = "
1101 << clid
1102 << ", proxy primary ID is " << proxy->clID();
1103 }
1104 } // try symlink -- endif
1105 return ptr;
1106 }
#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 838 of file StoreGate/src/VarHandleBase.cxx.

839 {
840#ifdef DEBUG_VHB
841 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));
842#endif
843
844 // First check for cached pointer.
845 if (0 != m_ptr)
846 return m_ptr;
847
848 if (0 == m_proxy) {
849 // No proxy, need to look it up.
850 if (this->setState().isFailure() || !m_proxy) {
851 if (!quiet) {
852 REPORT_MESSAGE(MSG::WARNING)
853 << "could not get proxy for key " << key();
854 if (this->mode() != Gaudi::DataHandle::Reader) {
855 REPORT_MESSAGE(MSG::WARNING)<< " try using a ReadHandle";
856 }
857 } //quiet
858 return 0;
859 } //setstate
860 } //m_proxy
861
863 return m_ptr;
864 }

◆ 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 873 of file StoreGate/src/VarHandleBase.cxx.

874 {
876 if (p != nullptr && isConst())
877 throw SG::ExcConstObject (clid(), key(), store());
878 return p;
879 }
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 629 of file StoreGate/src/VarHandleBase.cxx.

630 {
631 if (!m_ownedKey) {
632 throwExcNonConstHandleKey (m_key->clid(), m_key->key(),
633 m_key->storeHandle().name());
634 }
635 return *m_ownedKey;
636 }
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 525 of file StoreGate/StoreGate/VarHandleBase.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 520 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 507 of file StoreGate/StoreGate/VarHandleBase.h.

◆ m_ptr

void* SG::VarHandleBase::m_ptr
protectedinherited

The object to which we are bound.

Definition at line 504 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 510 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 513 of file StoreGate/StoreGate/VarHandleBase.h.


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