ATLAS Offline Software
|
Base class for VarHandle types. More...
#include <VarHandleBase.h>
Inherits IResetable.
Inherited by SG::ReadHandle< AthenaHitsVector< LArG4H6FrontHit > >, SG::ReadHandle< CaloCellContainerVector >, SG::ReadHandle< ConstDataVector< CaloCellContainerVector > >, SG::ReadHandle< DataVector >, SG::ReadHandle< LArHitContainer >, SG::ReadHandle< LVL1::jTowerContainer >, SG::ReadHandle< McEventCollection >, SG::ReadHandle< MyDataObj >, SG::ReadHandle< PixelGangedClusterAmbiguities >, SG::ReadHandle< SpacePointContainer >, SG::ReadHandle< SpacePointOverlapCollection >, SG::ReadHandle< T_Cont >, SG::ReadHandle< TBEventInfo >, SG::ReadHandle< Trk::PRDtoTrackMap >, SG::ReadHandle< VxContainer >, SG::ReadHandle< T >, SG::TypelessWriteHandle, SG::UpdateHandle< T >, SG::WriteHandle< T >, SG::WriteHandle< AthenaHitsVector >, SG::WriteHandle< AtlasHitsVector >, SG::WriteHandle< CaloCalibrationHitContainer >, SG::WriteHandle< CaloCellContainer >, SG::WriteHandle< DataVector >, SG::WriteHandle< HGTD_RDO_Container >, SG::WriteHandle< HijingEventParams >, SG::WriteHandle< HitContainerType >, SG::WriteHandle< InDetRawDataContainer >, SG::WriteHandle< InDetSimDataCollection >, SG::WriteHandle< LArHitContainer >, SG::WriteHandle< McEventCollection >, SG::WriteHandle< Muon::MuonPrepDataContainer >, SG::WriteHandle< SG::ThinningDecision >, SG::WriteHandle< TBEventInfo >, SG::WriteHandle< TBTrack >, SG::WriteHandle< TrigRoiDescriptorCollection >, SG::WriteHandle< xAOD::VertexAuxContainer_v1 >, and SG::WriteHandle< ZDC_SimFiberHit_Collection >.
Public Member Functions | |
VarHandleBase (CLID clid, Gaudi::DataHandle::Mode mode) | |
Constructor with default key. More... | |
VarHandleBase (CLID clid, const std::string &sgkey, Gaudi::DataHandle::Mode mode, const std::string &storename=StoreID::storeName(StoreID::EVENT_STORE)) | |
Constructor with full arguments. More... | |
VarHandleBase (const VarHandleKey &key, const EventContext *ctx) | |
Constructor from a VarHandleKey. More... | |
VarHandleBase (SG::DataProxy *proxy, Gaudi::DataHandle::Mode mode) | |
Constructor from a DataProxy. More... | |
VarHandleBase (const VarHandleBase &rhs) | |
Copy constructor. More... | |
VarHandleBase (VarHandleBase &&rhs) noexcept | |
Move constructor. More... | |
VarHandleBase & | operator= (const VarHandleBase &rhs) |
Assignment operator. More... | |
VarHandleBase & | operator= (VarHandleBase &&rhs) noexcept |
Move operator. More... | |
virtual | ~VarHandleBase () override |
Destructor. More... | |
virtual const std::string & | key () const override final |
Return the StoreGate ID for the referenced object. More... | |
const std::string & | name () const |
Return the StoreGate ID for the referenced object. More... | |
std::string | store () const |
Return the name of the store holding the object we are proxying. More... | |
virtual bool | isValid ()=0 |
Can the handle be successfully dereferenced? More... | |
bool | isPresent () const |
Is the referenced object present in SG? More... | |
bool | isInitialized () const |
Has a proxy been retrieved from SG? More... | |
virtual bool | isSet () const override final |
Has a proxy been retrieved from SG? More... | |
bool | isConst () const |
True if this handle has a proxy, and the proxy is const. More... | |
StatusCode | initialize (bool used=true) |
Verify that the handle has been configured properly. More... | |
StatusCode | setState () |
Retrieve and cache all information managed by a handle. More... | |
virtual StatusCode | setProxyDict (IProxyDict *store) |
Explicitly set the event store. More... | |
virtual void | reset (bool hard) override |
Reset this handle. More... | |
virtual void | finalReset () override final |
Reset this handle at the end of processing. More... | |
StatusCode | setConst () |
Set the 'const' bit for the bound proxy in the store. More... | |
CLID | clid () const |
Return the class ID for the referenced object. More... | |
const ServiceHandle< IProxyDict > & | storeHandle () const |
Return handle to the referenced store. More... | |
Gaudi::DataHandle::Mode | mode () const |
Return the mode (read/write/update) for this handle. More... | |
const std::string & | objKey () const |
Return the key string of the underlying DataObjID . More... | |
const DataObjID & | fullKey () const |
Return the key as a DataObjID . More... | |
SG::VarHandleKey & | vhKey () |
Return a non-const reference to the HandleKey. More... | |
StatusCode | assign (const std::string &sgkey) |
Update the underlying key from a string. More... | |
Protected Member Functions | |
StatusCode | setState (SG::DataProxy *proxy) |
Set the state of the handle to a given proxy. More... | |
StatusCode | setState (IProxyDict *store, const std::string &name) |
Set the state of a handle from a store and a key name. More... | |
StatusCode | record_impl (std::unique_ptr< DataObject > dobj, void *dataPtr, bool allowMods, bool returnExisting) |
Helper to record an object in the event store. More... | |
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. More... | |
void * | typeless_dataPointer_impl (bool quiet) |
Retrieve an object from StoreGate. More... | |
void * | typeless_dataPointer (bool quiet=defaultQuiet) |
Retrieve an object from StoreGate. More... | |
const void * | typeless_cptr () |
Retrieve an object from StoreGate as a const pointer. More... | |
void * | typeless_ptr (bool quiet=defaultQuiet) |
Retrieve an object from StoreGate as non-const pointer. More... | |
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. More... | |
bool | isPresent_impl (const std::string &key) const |
Is the referenced object present in SG? More... | |
Protected Attributes | |
void * | m_ptr |
The object to which we are bound. More... | |
SG::DataProxy * | m_proxy |
Proxy holding the object to which we are bound. More... | |
IProxyDict * | m_store |
Pointer to the store that owns the object. More... | |
bool | m_storeWasSet |
True if the store was set explicitly via setProxyDict. More... | |
Private Member Functions | |
IProxyDict * | storeFromHandle (const EventContext *ctx) const |
Return the store instance to use. More... | |
bool | setStoreFromHandle (const EventContext *ctx) |
Initialize the store pointer from the store handle. More... | |
void | resetProxy () |
Clear the m_proxy field and release the old proxy. More... | |
void | setProxy (SG::DataProxy *proxy) |
Set a new proxy. More... | |
void * | typeless_dataPointer_fromProxy (SG::DataProxy *proxy, bool quiet) const |
Retrieve a pointer from a proxy. More... | |
Private Attributes | |
std::unique_ptr< VarHandleKey > | m_ownedKey |
An owned VarHandleKey . More... | |
const VarHandleKey * | m_key |
The associated key object. More... | |
Friends | |
void | Athena_test::varHandleTest (SGTest::TestStore &) |
void | Athena_test::resetableTest (void) |
void | Athena_test::refCountTest (void) |
std::ostream & | operator<< (std::ostream &, const VarHandleBase &) |
Output stream. More... | |
Base class for VarHandle types.
This is the base class for smart pointer types used to access objects in an IProxyDict
(such as a StoreGateSvc). The handle types ReadHandle
, WriteHandle
, and UpdateHandle
derive from this; see those classes for usage information.
This class references a VarHandleKey
, which holds the CLID of the class we're referencing (which gets passed to the constructor of this class from the templated derived classes), the StoreGate key of the object we're referencing, and a handle to the event store. The key object can be passed to this object via the constructor; otherwise, we create and own a new VarHandleKey
object.
In this class, we keep a pointer to the actual event store being used (may be thread-dependent), a pointer to the DataProxy
for the referenced object, and a cached pointer to the object itself.
A handle object may be used as a algorithm/tool property directly. Because the handle caches state, however, this means that the component using it cannot be reentrant. In such a case, the handle will be reset when the current algorithm completes. In this case, the handle will be bound to the proxy.
The preferred way of using handles is to use a HandleKey object (one of ReadHandleKey<T>, WriteHandleKey<T>, UpdateHandleKey<T>) as the property, and to create a handle instance on the stack from the key object (and the event context, if available). In this case, the handle will not be bound to the proxy. A handle created in this way should not live beyond the end of the algorithm in which it was created.
Definition at line 82 of file StoreGate/StoreGate/VarHandleBase.h.
|
explicit |
Constructor with default key.
clid | CLID of the referenced class. |
mode | Mode of this handle (read/write/update). |
Definition at line 113 of file StoreGate/src/VarHandleBase.cxx.
|
explicit |
Constructor with full arguments.
clid | CLID of the referenced class. |
sgkey | StoreGate key of the referenced object. |
mode | Mode of this handle (read/write/update). |
storename | Name of the referenced event store. |
Definition at line 136 of file StoreGate/src/VarHandleBase.cxx.
|
explicit |
Constructor from a VarHandleKey.
key | The key object holding the clid/key/store. |
ctx | The event context to use, or nullptr. |
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 ctx
will be used. If ctx
is null, then the current event context will be read.
key | The key object holding the clid/key/store. |
ctx | The event context to use, or nullptr. |
This will raise an exception if the StoreGate key is blank, or if the event store cannot be found.
Definition at line 45 of file AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx.
|
explicit |
Constructor from a DataProxy.
proxy | The proxy to which to bind. |
mode | Mode of this handle (read/write/update). |
This handle will be bound to the given proxy.
Definition at line 188 of file StoreGate/src/VarHandleBase.cxx.
SG::VarHandleBase::VarHandleBase | ( | const VarHandleBase & | rhs | ) |
Copy constructor.
Definition at line 209 of file StoreGate/src/VarHandleBase.cxx.
|
noexcept |
Move constructor.
Definition at line 235 of file StoreGate/src/VarHandleBase.cxx.
|
overridevirtual |
Destructor.
Definition at line 331 of file StoreGate/src/VarHandleBase.cxx.
StatusCode SG::VarHandleBase::assign | ( | const std::string & | sgkey | ) |
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 642 of file StoreGate/src/VarHandleBase.cxx.
CLID SG::VarHandleBase::clid | ( | ) | const |
Return the class ID for the referenced object.
|
finaloverridevirtual |
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 595 of file StoreGate/src/VarHandleBase.cxx.
const DataObjID& SG::VarHandleBase::fullKey | ( | ) | const |
Return the key as a DataObjID
.
|
protected |
Definition at line 876 of file StoreGate/src/VarHandleBase.cxx.
StatusCode SG::VarHandleBase::initialize | ( | bool | used = true | ) |
Verify that the handle has been configured properly.
used | If 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 452 of file StoreGate/src/VarHandleBase.cxx.
bool SG::VarHandleBase::isConst | ( | ) | const |
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 432 of file StoreGate/src/VarHandleBase.cxx.
bool SG::VarHandleBase::isInitialized | ( | ) | const |
Has a proxy been retrieved from SG?
(Weaker test than isValid
, but does not touch the disk.)
Definition at line 406 of file StoreGate/src/VarHandleBase.cxx.
bool SG::VarHandleBase::isPresent | ( | ) | const |
Is the referenced object present in SG?
Const method; the handle does not change as a result of this.
Definition at line 394 of file StoreGate/src/VarHandleBase.cxx.
|
protected |
Is the referenced object present in SG?
key | SG key to test. |
Const method; the handle does not change as a result of this.
Definition at line 1101 of file StoreGate/src/VarHandleBase.cxx.
|
finaloverridevirtual |
Has a proxy been retrieved from SG?
Same as isInitialized
; this is an interface required by IResetable
.
Implements IResetable.
Definition at line 420 of file StoreGate/src/VarHandleBase.cxx.
|
pure virtual |
Can the handle be successfully dereferenced?
Non-const method; the handle may cache information as a result of this.
Implemented in SG::UpdateHandle< T >, SG::WriteHandle< T >, SG::WriteHandle< McEventCollection >, SG::WriteHandle< HijingEventParams >, SG::WriteHandle< InDetSimDataCollection >, SG::WriteHandle< Muon::MuonPrepDataContainer >, SG::WriteHandle< TrigRoiDescriptorCollection >, SG::WriteHandle< HGTD_RDO_Container >, SG::WriteHandle< DataVector >, SG::WriteHandle< HitContainerType >, SG::WriteHandle< SG::ThinningDecision >, SG::WriteHandle< xAOD::VertexAuxContainer_v1 >, SG::WriteHandle< CaloCellContainer >, SG::WriteHandle< CaloCalibrationHitContainer >, SG::WriteHandle< AtlasHitsVector >, SG::WriteHandle< InDetRawDataContainer >, SG::WriteHandle< AthenaHitsVector >, SG::WriteHandle< TBTrack >, SG::WriteHandle< TBEventInfo >, SG::WriteHandle< ZDC_SimFiberHit_Collection >, SG::WriteHandle< LArHitContainer >, SG::ReadHandle< T >, SG::ReadHandle< McEventCollection >, SG::ReadHandle< SpacePointOverlapCollection >, SG::ReadHandle< ConstDataVector< CaloCellContainerVector > >, SG::ReadHandle< AthenaHitsVector< LArG4H6FrontHit > >, SG::ReadHandle< PixelGangedClusterAmbiguities >, SG::ReadHandle< DataVector >, SG::ReadHandle< Trk::PRDtoTrackMap >, SG::ReadHandle< LVL1::jTowerContainer >, SG::ReadHandle< VxContainer >, SG::ReadHandle< MyDataObj >, SG::ReadHandle< TBEventInfo >, SG::ReadHandle< SpacePointContainer >, SG::ReadHandle< T_Cont >, SG::ReadHandle< CaloCellContainerVector >, SG::ReadHandle< LArHitContainer >, and SG::TypelessWriteHandle.
|
finaloverridevirtual |
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.
Gaudi::DataHandle::Mode SG::VarHandleBase::mode | ( | ) | const |
Return the mode (read/write/update) for this handle.
const std::string & SG::VarHandleBase::name | ( | ) | const |
Return the StoreGate ID for the referenced object.
Definition at line 75 of file AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx.
const std::string& SG::VarHandleBase::objKey | ( | ) | const |
Return the key string of the underlying DataObjID
.
Compared to key()
, this will be prefixed with the store name.
VarHandleBase & SG::VarHandleBase::operator= | ( | const VarHandleBase & | rhs | ) |
Assignment operator.
Definition at line 267 of file StoreGate/src/VarHandleBase.cxx.
|
noexcept |
Move operator.
Definition at line 296 of file StoreGate/src/VarHandleBase.cxx.
|
protected |
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.
ctx | The event context, or nullptr to use the current context. | |
dobj | The wrapped data object (DataBucket) to record. | |
dataPtr | Pointer to the transient object itself. | |
allowMods | If false, record the object as const. | |
returnExisting | Allow an existing object. | |
[out] | store | The 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 782 of file StoreGate/src/VarHandleBase.cxx.
|
protected |
Helper to record an object in the event store.
The | wrapped data object (DataBucket) to record. |
dataPtr | Pointer to the transient object itself. |
allowMods | If false, record the object as const. |
returnExisting | Allow 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 713 of file StoreGate/src/VarHandleBase.cxx.
|
overridevirtual |
Reset this handle.
hard | If 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 >.
Definition at line 570 of file StoreGate/src/VarHandleBase.cxx.
|
private |
Clear the m_proxy field and release the old proxy.
Definition at line 1004 of file StoreGate/src/VarHandleBase.cxx.
StatusCode SG::VarHandleBase::setConst | ( | ) |
Set the 'const' bit for the bound proxy in the store.
Definition at line 606 of file StoreGate/src/VarHandleBase.cxx.
|
private |
Set a new proxy.
Release any old one first.
proxy | The new proxy. |
Definition at line 1020 of file StoreGate/src/VarHandleBase.cxx.
|
virtual |
Explicitly set the event store.
store | The new event store. |
This implicitly does a reset().
Reimplemented in SG::WriteDecorHandle< DataVector, int >, SG::WriteDecorHandle< DataVector, float >, SG::WriteDecorHandle< DataVector, std::vector< float > >, SG::WriteDecorHandle< DataVector, std::vector< int > >, SG::WriteDecorHandle< DataVector, std::vector< bool > >, and SG::WriteDecorHandle< DataVector, uint32_t >.
Definition at line 551 of file StoreGate/src/VarHandleBase.cxx.
StatusCode SG::VarHandleBase::setState | ( | ) |
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 487 of file StoreGate/src/VarHandleBase.cxx.
|
protected |
Set the state of a handle from a store and a key name.
store | The event store to access. |
name | The StoreGate key to search for. |
Fails if no such object is recorded.
store | The event store to access. |
name | The StoreGate key to search for. |
Definition at line 686 of file StoreGate/src/VarHandleBase.cxx.
|
protected |
Set the state of the handle to a given proxy.
proxy | The proxy to set. |
The proxy must be valid; otherwise FAILURE will be returned.
Definition at line 660 of file StoreGate/src/VarHandleBase.cxx.
|
private |
Initialize the store pointer from the store handle.
Also checks that the key is valid.
ctx | The current event context, or nullptr. |
Returns true on success.
Definition at line 987 of file StoreGate/src/VarHandleBase.cxx.
std::string SG::VarHandleBase::store | ( | ) | const |
Return the name of the store holding the object we are proxying.
Definition at line 376 of file StoreGate/src/VarHandleBase.cxx.
|
private |
Return the store instance to use.
ctx | The current event context, or nullptr. |
ctx | The current event context, or nullptr. |
If we're referencing the default event store, pick the specific store to use in this order:
For another store:
Definition at line 957 of file StoreGate/src/VarHandleBase.cxx.
const ServiceHandle<IProxyDict>& SG::VarHandleBase::storeHandle | ( | ) | const |
Return handle to the referenced store.
Make a symlink or alias to the object currently referenced by this handle.
newClid | CLID of link. |
newKey | SG 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 926 of file StoreGate/src/VarHandleBase.cxx.
|
protected |
Retrieve an object from StoreGate as a const pointer.
Same as typeless_dataPointer with the return value converted to const.
|
protected |
Retrieve an object from StoreGate.
quiet | If true, suppress failure messages. |
Inline method: first check cached pointer, then call the _impl method.
|
private |
Retrieve a pointer from a proxy.
proxy | The proxy object. |
quiet | If true, suppress failure messages. |
Warning — doesn't enforce const rules; the caller must do that.
Definition at line 1041 of file StoreGate/src/VarHandleBase.cxx.
|
protected |
Retrieve an object from StoreGate.
quiet | If true, suppress failure messages. |
Definition at line 824 of file StoreGate/src/VarHandleBase.cxx.
|
protected |
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 859 of file StoreGate/src/VarHandleBase.cxx.
SG::VarHandleKey & SG::VarHandleBase::vhKey | ( | ) |
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 623 of file StoreGate/src/VarHandleBase.cxx.
|
friend |
|
friend |
|
friend |
|
friend |
Output stream.
out | Stream to which to write. |
o | Object to write. |
Definition at line 107 of file AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx.
|
private |
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 523 of file StoreGate/StoreGate/VarHandleBase.h.
|
private |
An owned VarHandleKey
.
This is set in the case where a VarHandle
is not initialized from a key object.
Definition at line 518 of file StoreGate/StoreGate/VarHandleBase.h.
|
protected |
Proxy holding the object to which we are bound.
Definition at line 505 of file StoreGate/StoreGate/VarHandleBase.h.
|
protected |
The object to which we are bound.
Definition at line 502 of file StoreGate/StoreGate/VarHandleBase.h.
|
protected |
Pointer to the store that owns the object.
Definition at line 508 of file StoreGate/StoreGate/VarHandleBase.h.
|
protected |
True if the store was set explicitly via setProxyDict.
Definition at line 511 of file StoreGate/StoreGate/VarHandleBase.h.