ATLAS Offline Software
Loading...
Searching...
No Matches
SG::VarHandleBase Class Referenceabstract

Base class for VarHandle types. More...

#include <VarHandleBase.h>

Inherits IResetable.

Inherited by SG::ReadHandle< xAOD::CaloClusterContainer >, SG::ReadHandle< IDC >, SG::ReadHandle< DataVector< xAOD::Electron_v1 > >, SG::ReadHandle< T_Cont >, SG::ReadHandle< DataVector< xAOD::TrackParticle_v1 > >, SG::ReadHandle< McEventCollection >, SG::ReadHandle< DataVector< Trk::Track > >, SG::ReadHandle< SpacePointContainer >, SG::ReadHandle< SpacePointOverlapCollection >, SG::ReadHandle< Trk::PRDtoTrackMap >, SG::ReadHandle< PixelGangedClusterAmbiguities >, SG::ReadHandle< DataVector< IParticle > >, SG::ReadHandle< DataVector< xAOD::Jet_v1 > >, SG::ReadHandle< LVL1::jTowerContainer >, SG::ReadHandle< Cont_t >, SG::ReadHandle< MyDataObj >, SG::ReadHandle< VxContainer >, SG::UpdateHandle< IDCBackend >, SG::WriteHandle< xAOD::CaloClusterContainer >, SG::WriteHandle< CaloClusterCellLinkContainer >, SG::WriteHandle< Cont_t >, SG::WriteHandle< IDC >, SG::WriteHandle< xAOD::AuxiliaryMeasurementContainer >, SG::WriteHandle< xAOD::TrackSurfaceContainer >, SG::WriteHandle< DecisionContainer >, SG::WriteHandle< Muon::MuonPrepDataContainer< MuonPrepDataCollection< PrdType > > >, SG::WriteHandle< HitContainerType >, SG::WriteHandle< AtlasHitsVector< TrackRecord > >, SG::WriteHandle< HGTD_RDO_Container >, SG::WriteHandle< HGTD_ALTIROC_RDO_Container >, SG::WriteHandle< InDetSimDataCollection >, SG::WriteHandle< McEventCollection >, SG::WriteHandle< InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > >, SG::WriteHandle< HijingEventParams >, SG::WriteHandle< InDetRawDataContainer< InDetRawDataCollection< PixelRDORawData > > >, SG::WriteHandle< DataVector< xAOD::CaloRings_v1 > >, SG::WriteHandle< DataVector< xAOD::RingSet_v1 > >, SG::WriteHandle< SG::ThinningDecision >, SG::WriteHandle< InDetRawDataContainer< InDetRawDataCollection< TRT_RDORawData > > >, SG::WriteHandle< TrigRoiDescriptorCollection >, SG::WriteHandle< DataVector< Particle_v1 > >, SG::WriteHandle< DataVector< xAOD::TrigMissingET_v1 > >, SG::WriteHandle< DataVector< TrigComposite_v1 > >, SG::WriteHandle< DataVector< xAOD::Vertex_v1 > >, SG::WriteHandle< xAOD::VertexAuxContainer_v1 >, SG::ReadHandle< T >, SG::TypelessWriteHandle, SG::UpdateHandle< T >, and SG::WriteHandle< T >.

Collaboration diagram for SG::VarHandleBase:

Public Member Functions

 VarHandleBase (CLID clid, Gaudi::DataHandle::Mode mode)
 Constructor with default key.
 VarHandleBase (CLID clid, const std::string &sgkey, Gaudi::DataHandle::Mode mode, const std::string &storename, const EventContext *ctx)
 Constructor with full arguments.
 VarHandleBase (CLID clid, const std::string &sgkey, Gaudi::DataHandle::Mode mode, IProxyDict *sg)
 Constructor given an IProxyDict.
 VarHandleBase (const VarHandleKey &key, const EventContext *ctx)
 Constructor from a VarHandleKey.
 VarHandleBase (SG::DataProxy *proxy, Gaudi::DataHandle::Mode mode)
 Constructor from a DataProxy.
 VarHandleBase (const VarHandleBase &rhs)
 Copy constructor.
 VarHandleBase (VarHandleBase &&rhs) noexcept
 Move constructor.
VarHandleBase & operator= (const VarHandleBase &rhs)
 Assignment operator.
VarHandleBase & operator= (VarHandleBase &&rhs) noexcept
 Move operator.
virtual ~VarHandleBase () override
 Destructor.
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.
virtual bool isValid ()=0
 Can the handle be successfully dereferenced?
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

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

std::unique_ptr< VarHandleKey > m_ownedKey
 An owned VarHandleKey.
const VarHandleKey * m_key
 The associated key object.

Friends

void Athena_test::varHandleTest (SGTest::TestStore &)
void Athena_test::resetableTest (void)
void Athena_test::refCountTest (void)

Detailed Description

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.

Constructor & Destructor Documentation

◆ VarHandleBase() [1/7]

SG::VarHandleBase::VarHandleBase ( CLID clid,
Gaudi::DataHandle::Mode mode )
explicit

Constructor with default key.

Parameters
clidCLID of the referenced class.
modeMode of this handle (read/write/update).

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

114 :
115 IResetable(),
116 m_ptr(0),
117 m_proxy(0),
118 m_store(nullptr),
119 m_storeWasSet(false),
120 m_ownedKey (std::make_unique<VarHandleKey> (clid, "", mode)),
121 m_key (m_ownedKey.get())
122 {
123 m_ownedKey->setOwningHandle (this);
124#ifdef DEBUG_VHB
125 dbg::print(stderr, "VarHandleBase() {}\n", dbg::ptr(this));
126#endif
127 }
std::unique_ptr< VarHandleKey > m_ownedKey
An owned VarHandleKey.
bool m_storeWasSet
True if the store was set explicitly via setProxyDict.
IProxyDict * m_store
Pointer to the store that owns the object.
void * m_ptr
The object to which we are bound.
Gaudi::DataHandle::Mode mode() const
Return the mode (read/write/update) for this handle.
const VarHandleKey * m_key
The associated key object.
SG::DataProxy * m_proxy
Proxy holding the object to which we are bound.
CLID clid() const
Return the class ID for the referenced object.
void * ptr(T *p)
Definition SGImplSvc.cxx:76
void print(std::FILE *stream, std::format_string< Args... > fmt, Args &&... args)
Definition SGImplSvc.cxx:72

◆ VarHandleBase() [2/7]

SG::VarHandleBase::VarHandleBase ( CLID clid,
const std::string & sgkey,
Gaudi::DataHandle::Mode mode,
const std::string & storename,
const EventContext * ctx )
explicit

Constructor with full arguments.

Parameters
clidCLID of the referenced class.
sgkeyStoreGate key of the referenced object.
modeMode of this handle (read/write/update).
storenameName of the referenced event store.
ctxThe event context to use, or nullptr.

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

142 :
143 IResetable(),
144 m_ptr(NULL),
145 m_proxy(NULL),
146 m_store(nullptr),
147 m_storeWasSet(false),
148 m_ownedKey (std::make_unique<VarHandleKey> (clid, sgkey, mode, storename)),
149 m_key (m_ownedKey.get())
150 {
151 m_ownedKey->setOwningHandle (this);
152
153 if (ctx && !setStoreFromHandle(ctx)) {
154 throw SG::ExcHandleInitError (clid, sgkey, storename);
155 }
156 }
bool setStoreFromHandle(const EventContext *ctx)
Initialize the store pointer from the store handle.

◆ VarHandleBase() [3/7]

SG::VarHandleBase::VarHandleBase ( CLID clid,
const std::string & sgkey,
Gaudi::DataHandle::Mode mode,
IProxyDict * sg )
explicit

Constructor given an IProxyDict.

Parameters
clidCLID of the referenced class.
sgkeyStoreGate key of the referenced object.
modeMode of this handle (read/write/update).
sgThe referenced store.

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

169 :
170 IResetable(),
171 m_ptr(nullptr),
172 m_proxy(nullptr),
173 m_store(sg),
174 m_storeWasSet(true),
175 m_ownedKey (std::make_unique<VarHandleKey> (clid, sgkey, mode, sg->name())),
176 m_key (m_ownedKey.get())
177 {
178 m_ownedKey->setOwningHandle (this);
179 }

◆ VarHandleBase() [4/7]

SG::VarHandleBase::VarHandleBase ( const VarHandleKey & key,
const EventContext * ctx )
explicit

Constructor from a VarHandleKey.

Parameters
keyThe key object holding the clid/key/store.
ctxThe 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.

Parameters
keyThe key object holding the clid/key/store.
ctxThe 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.

47 : m_key (&key)
48 {
49 }
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.

◆ VarHandleBase() [5/7]

SG::VarHandleBase::VarHandleBase ( SG::DataProxy * proxy,
Gaudi::DataHandle::Mode mode )
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.

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

220 : IResetable(),
221 m_ptr (nullptr),
222 m_proxy (nullptr),
223 m_store (proxy->store()),
224 m_storeWasSet (true),
225 m_ownedKey (std::make_unique<VarHandleKey> (proxy->clID(),
226 proxy->name(),
227 mode,
228 m_store ? m_store->name() : "")),
229 m_key (m_ownedKey.get())
230 {
231 m_ownedKey->setOwningHandle (this);
232 setProxy (proxy);
233 }
void setProxy(SG::DataProxy *proxy)
Set a new proxy.

◆ VarHandleBase() [6/7]

SG::VarHandleBase::VarHandleBase ( const VarHandleBase & rhs)

Copy constructor.

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

239 :
240 IResetable(),
241 m_ptr(rhs.m_ptr),
242 m_proxy(nullptr),
243 m_store(rhs.m_store),
244 m_storeWasSet(rhs.m_storeWasSet)
245 {
246 if (rhs.m_ownedKey) {
247 m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
248 m_ownedKey->setOwningHandle (this);
249 m_key = m_ownedKey.get();
250 }
251 else {
252 m_key = rhs.m_key;
253 }
254#ifdef DEBUG_VHB
255 dbg::print(stderr, "::VHB::copy constr from {} to {} with proxy={} => {}, key={}, store={}\n", dbg::ptr(&rhs), dbg::ptr(this), dbg::proxy(this->m_proxy), dbg::proxy(rhs.m_proxy), this->key(), dbg::store(this->m_store));
256#endif
257
258 setProxy (rhs.m_proxy);
259 }

◆ VarHandleBase() [7/7]

SG::VarHandleBase::VarHandleBase ( VarHandleBase && rhs)
noexcept

Move constructor.

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

265 :
266 IResetable(),
267 m_ptr(rhs.m_ptr),
268 m_proxy(nullptr),
269 m_store(rhs.m_store),
270 m_storeWasSet(rhs.m_storeWasSet),
271 m_ownedKey (std::move (rhs.m_ownedKey)),
272 m_key (rhs.m_key)
273 {
274 if (m_ownedKey) {
275 m_ownedKey->setOwningHandle (this);
276 }
277 rhs.m_ptr=0;
278
279 if (rhs.m_proxy) {
280 if (m_ownedKey) {
281 rhs.m_proxy->unbindHandle (&rhs);
282 rhs.m_proxy->bindHandle(this);
283 }
284 m_proxy = rhs.m_proxy;
285 rhs.m_proxy=0; //no release: this has the ref now
286 }
287#ifdef DEBUG_VHB
288 dbg::print(stderr, "::VHB::move constr from {} to {} with proxy={}, key={}, store={}\n", dbg::ptr(&rhs), dbg::ptr(this), dbg::proxy(this->m_proxy), this->key(), dbg::store(this->m_store));
289#endif
290 }

◆ ~VarHandleBase()

SG::VarHandleBase::~VarHandleBase ( )
overridevirtual

Destructor.

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

362 {
363#ifdef DEBUG_VHB
364 dbg::print(stderr, "::VHB:: DESTROY {} with 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));
365#endif
366
367 if (m_ownedKey) {
368 resetProxy();
369 }
370 m_ptr = 0;
371 }
void resetProxy()
Clear the m_proxy field and release the old proxy.

Member Function Documentation

◆ assign()

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

673 {
674 return vhKey().assign (sgkey);
675 }
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.

◆ clid()

CLID SG::VarHandleBase::clid ( ) const

Return the class ID for the referenced object.

◆ finalReset()

void SG::VarHandleBase::finalReset ( )
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 625 of file StoreGate/src/VarHandleBase.cxx.

625 {
626#ifdef DEBUG_VHB
627 dbg::print(stderr, "::VHB::finalReset {} with proxy={}, key={}, store={}\n", dbg::ptr(this), dbg::proxy(m_proxy), this->key(), dbg::store(this->m_store));
628#endif
629 reset (true);
630 }
virtual void reset() override
Free all allocated elements.

◆ fullKey()

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

Return the key as a DataObjID.

◆ get_impl()

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

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

933 {
934 if (this->mode() != Gaudi::DataHandle::Reader) {
935 if (!quiet)
936 REPORT_ERROR (StatusCode::FAILURE)
937 << "get_impl called for a non-read handle.";
938 return nullptr;
939 }
940
941 if (this->key().empty()) {
942 if (!quiet)
943 REPORT_ERROR (StatusCode::FAILURE)
944 << "Cannot initialize a Read/Write/Update handle with a null key.";
945 return nullptr;
946 }
947
948 IProxyDict* store = storeFromHandle (ctx);
949 if (!store) {
950 if (!quiet)
951 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
952 return nullptr;
953 }
954
955 SG::DataProxy* proxy = store->proxy_exact(m_key->hashedKey());
956 if (!proxy) {
957 proxy = store->proxy(this->clid(), this->key());
958 if (!proxy) {
959 if (!quiet)
960 REPORT_ERROR (StatusCode::FAILURE)
961 << "Cannot find proxy for "
962 << this->clid() << "/" << this->key();
963 return nullptr;
964 }
965 }
966
968 }
#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.
std::string store() const
Return the name of the store holding the object we are proxying.

◆ initialize()

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

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

483 {
484 if (!used) {
485 if (m_ownedKey) {
486 CHECK( m_ownedKey->initialize (used) );
487 }
488 return StatusCode::SUCCESS;
489 }
490
491 if (!m_store) {
492 if (m_ownedKey) {
493 CHECK( m_ownedKey->initialize() );
494 }
495 m_store = &*(this->storeHandle());
496 m_storeWasSet = false;
497 }
498
499 if (!m_store) {
500 return StatusCode::FAILURE;
501 }
502
503 return StatusCode::SUCCESS;
504 }
#define CHECK(...)
Evaluate an expression and check for errors.
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.

◆ isConst()

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

463 {
464#ifdef DEBUG_VHB
465 dbg::print(stderr, "::VHB::isConst({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
466#endif
467 return 0 != m_proxy
468 ? m_proxy->isConst()
469 : false;
470 }

◆ isInitialized()

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

437 {
438#ifdef DEBUG_VHB
439 dbg::print(stderr, "::VHB::isInitialized({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(m_proxy));
440#endif
441 return (0 != m_proxy);
442 }

◆ isPresent()

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

425 {
426 return isPresent_impl (key());
427 }
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
protected

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

1156 {
1157 const DataProxy* proxy = m_proxy;
1158 if (!proxy) {
1159 const IProxyDict* store = m_store;
1160 if (!store)
1161 store = this->storeHandle().get();
1162 if (store)
1163 proxy = store->proxy(this->clid(), key);
1164 }
1165 if (proxy) {
1166 return proxy->isValid();
1167 }
1168 return false;
1169 }

◆ isSet()

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

Has a proxy been retrieved from SG?

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

Implements IResetable.

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

451 {
452 return isInitialized();
453 }
bool isInitialized() const
Has a proxy been retrieved from SG?

◆ isValid()

virtual bool SG::VarHandleBase::isValid ( )
pure virtual

Can the handle be successfully dereferenced?

Non-const method; the handle may cache information as a result of this.

Implemented in SG::ReadHandle< T >, SG::ReadHandle< Cont_t >, SG::ReadHandle< DataVector< IParticle > >, SG::ReadHandle< DataVector< Trk::Track > >, SG::ReadHandle< DataVector< xAOD::Electron_v1 > >, SG::ReadHandle< DataVector< xAOD::Jet_v1 > >, SG::ReadHandle< DataVector< xAOD::TrackParticle_v1 > >, SG::ReadHandle< IDC >, 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< Trk::PRDtoTrackMap >, SG::ReadHandle< VxContainer >, SG::ReadHandle< xAOD::CaloClusterContainer >, SG::TypelessWriteHandle, SG::UpdateHandle< T >, SG::UpdateHandle< IDCBackend >, SG::WriteHandle< T >, SG::WriteHandle< AtlasHitsVector< TrackRecord > >, SG::WriteHandle< CaloClusterCellLinkContainer >, SG::WriteHandle< Cont_t >, SG::WriteHandle< DataVector< Particle_v1 > >, SG::WriteHandle< DataVector< TrigComposite_v1 > >, SG::WriteHandle< DataVector< xAOD::CaloRings_v1 > >, SG::WriteHandle< DataVector< xAOD::RingSet_v1 > >, SG::WriteHandle< DataVector< xAOD::TrigMissingET_v1 > >, SG::WriteHandle< DataVector< xAOD::Vertex_v1 > >, SG::WriteHandle< DecisionContainer >, SG::WriteHandle< HGTD_ALTIROC_RDO_Container >, SG::WriteHandle< HGTD_RDO_Container >, SG::WriteHandle< HijingEventParams >, SG::WriteHandle< HitContainerType >, SG::WriteHandle< IDC >, SG::WriteHandle< InDetRawDataContainer< InDetRawDataCollection< PixelRDORawData > > >, SG::WriteHandle< InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > >, SG::WriteHandle< InDetRawDataContainer< InDetRawDataCollection< TRT_RDORawData > > >, SG::WriteHandle< InDetSimDataCollection >, SG::WriteHandle< McEventCollection >, SG::WriteHandle< Muon::MuonPrepDataContainer< MuonPrepDataCollection< PrdType > > >, SG::WriteHandle< SG::ThinningDecision >, SG::WriteHandle< TrigRoiDescriptorCollection >, SG::WriteHandle< xAOD::AuxiliaryMeasurementContainer >, SG::WriteHandle< xAOD::CaloClusterContainer >, SG::WriteHandle< xAOD::TrackSurfaceContainer >, and SG::WriteHandle< xAOD::VertexAuxContainer_v1 >.

◆ key()

const std::string & SG::VarHandleBase::key ( ) const
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.

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

◆ mode()

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

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

◆ name()

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

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

Return the key string of the underlying DataObjID.

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

◆ operator=() [1/2]

VarHandleBase & SG::VarHandleBase::operator= ( const VarHandleBase & rhs)

Assignment operator.

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

298 {
299 if (this != &rhs) {
300 if (rhs.m_ownedKey) {
301 m_ownedKey = std::make_unique<VarHandleKey> (*rhs.m_ownedKey);
302 m_ownedKey->setOwningHandle (this);
303 m_key = m_ownedKey.get();
304 }
305 else {
306 m_key = rhs.m_key;
307 m_ownedKey.reset();
308 }
309
310 m_ptr = rhs.m_ptr;
311 m_store = rhs.m_store;
312 m_storeWasSet = rhs.m_storeWasSet;
313 setProxy (rhs.m_proxy);
314 }
315#ifdef DEBUG_VHB
316 dbg::print(stderr, "::VHB::assignment from {} to {} with proxy={}, key={}, store={}\n", dbg::ptr(&rhs), dbg::ptr(this), dbg::proxy(this->m_proxy), this->key(), dbg::store(this->m_store));
317#endif
318 return *this;
319 }

◆ operator=() [2/2]

VarHandleBase & SG::VarHandleBase::operator= ( VarHandleBase && rhs)
noexcept

Move operator.

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

327 {
328 if (this != &rhs) {
329 m_ownedKey = std::move (rhs.m_ownedKey);
330 if (m_ownedKey) {
331 m_ownedKey->setOwningHandle (this);
332 }
333 m_key = rhs.m_key;
334
335 m_ptr = rhs.m_ptr;
336 m_store = rhs.m_store;
337 m_storeWasSet = rhs.m_storeWasSet;
338
339 rhs.m_ptr=0;
340
341 resetProxy();
342 if (rhs.m_proxy) {
343 if (m_ownedKey) {
344 rhs.m_proxy->unbindHandle (&rhs);
345 rhs.m_proxy->bindHandle (this);
346 }
347 m_proxy = rhs.m_proxy;
348 rhs.m_proxy=0; //no release: this has the ref now
349 }
350 }
351#ifdef DEBUG_VHB
352 dbg::print(stderr, "::VHB:: move assign from {} to {} with proxy={}, key={}, store={}\n", dbg::ptr(&rhs), dbg::ptr(this), dbg::proxy(this->m_proxy), this->key(), dbg::store(this->m_store));
353#endif
354 return *this;
355 }

◆ 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
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.

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

839 {
840 if (this->name().empty()) {
841 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
842 return nullptr;
843 }
844
845 store = storeFromHandle (ctx);
846 if (!store) {
847 REPORT_ERROR (StatusCode::FAILURE) << "No store.";
848 return nullptr;
849 }
850 if (!dobj) {
851 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer.";
852 return nullptr;
853 }
854
855 SG::DataObjectSharedPtr<DataObject> sptr (std::move (dobj));
856 unsigned int initRefCount = sptr->refCount();
857 SG::DataProxy* new_proxy =
858 store->recordObject (sptr, this->name(), allowMods, returnExisting);
859 if (!new_proxy) {
860 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
861 return nullptr;
862 }
863
864 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
865 // If the reference count hasn't changed, then we've returned an existing
866 // object rather than recording a new one. Retrieve the pointer.
867 dataPtr = typeless_dataPointer_fromProxy (new_proxy, true);
868 }
869
870 return dataPtr;
871 }
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 )
protected

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

764 {
765 if (!m_store) {
766 if (m_ownedKey) {
767 CHECK (m_ownedKey->initialize());
768 }
769 m_store = &*(this->storeHandle());
770 m_storeWasSet = false;
771 }
772
773 if (this->name().empty()) {
774 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record an object with a null key";
775 return StatusCode::FAILURE;
776 }
777 if (!dobj) {
778 REPORT_ERROR (StatusCode::FAILURE) << "Attempt to record null pointer";
779 return StatusCode::FAILURE;
780 }
781
782 SG::DataObjectSharedPtr<DataObject> sptr (dobj.release());
783 unsigned int initRefCount = sptr->refCount();
784 SG::DataProxy* new_proxy =
785 m_store->recordObject (sptr, this->name(), allowMods, returnExisting);
786 if (!new_proxy) {
787 REPORT_ERROR (StatusCode::FAILURE) << "recordObject failed";
788 resetProxy();
789 return StatusCode::FAILURE;
790 }
791 if (m_proxy != new_proxy) {
792 CHECK (this->setState (new_proxy));
793 }
794
795 if (new_proxy && initRefCount == sptr->refCount() && new_proxy->isValid()) {
796 // If the reference count hasn't changed, then we've returned an existing
797 // object rather than recording a new one. Retrieve the pointer, making
798 // sure that it isn't const.
799 if (m_proxy->isConst()) {
800 REPORT_ERROR (StatusCode::FAILURE)
801 << "Found an existing const object from recordOrRetrieve.";
802 return StatusCode::FAILURE;
803 }
805 if (!allowMods)
806 CHECK( setConst() );
807 }
808 else
809 m_ptr=(void*)dataPtr;
810
811 return StatusCode::SUCCESS;
812 }
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 * typeless_dataPointer_impl(bool quiet)
Retrieve an object from StoreGate.

◆ reset()

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

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

600 {
601#ifdef DEBUG_VHB
602 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);
603#endif
604 m_ptr = 0;
605
606 if (hard) {
607 m_store = 0;
608 m_storeWasSet = false;
609 }
610
611 //if the proxy is not resetOnly then release it as it will become invalid
612 // Also release on a hard reset.
613 if (0 != m_proxy && (!m_proxy->isResetOnly() || hard)) {
614 resetProxy();
615 }
616 }

◆ resetProxy()

void SG::VarHandleBase::resetProxy ( )
private

Clear the m_proxy field and release the old proxy.

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

1059 {
1060 if (m_proxy) {
1061 if (m_ownedKey) {
1062 m_proxy->unbindHandle(this);
1063 m_proxy->release();
1064 }
1065 m_proxy = nullptr;
1066 }
1067 }

◆ setConst()

StatusCode SG::VarHandleBase::setConst ( )

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

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

637 {
638 if (typeless_dataPointer()) {
639 m_proxy->setConst();
640 return StatusCode::SUCCESS;
641 }
642 return StatusCode::FAILURE;
643 }
void * typeless_dataPointer(bool quiet=defaultQuiet)
Retrieve an object from StoreGate.

◆ setProxy()

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

Set a new proxy.

Release any old one first.

Parameters
proxyThe new proxy.

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

1075 {
1076 resetProxy();
1077 if (proxy) {
1078 if (m_ownedKey) {
1079 proxy->addRef();
1080 proxy->bindHandle (this);
1081 }
1082 m_proxy = proxy;
1083 }
1084 }

◆ setProxyDict()

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

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

582 {
583 reset(true);
584 m_store = store;
585 m_storeWasSet = true;
586 return StatusCode::SUCCESS;
587 }

◆ setState() [1/3]

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

518 {
519 CHECK( initialize() );
520 if (!m_storeWasSet) {
521 IProxyDict* store = storeFromHandle (nullptr);
522 if (store) m_store = store;
523 }
524
525#ifdef DEBUG_VHB
526 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());
527#endif
528
529 SG::DataProxy* proxy = m_store->proxy_exact (m_key->hashedKey());
530 if (!proxy) {
531#ifdef DEBUG_VHB
532 dbg::print(stderr, "::VHB:: setState() on {} ==> null proxy!\n", dbg::ptr(this));
533#endif
534 proxy = m_store->proxy(this->clid(), this->key());
535 }
536
537 if (!proxy) {
538#ifdef DEBUG_VHB
539 dbg::print(stderr, "::VHB:: setState() on {} ==> STILL null proxy!\n", dbg::ptr(this));
540#endif
541 }
542 else if (!proxy->isValid()) {
543#ifdef DEBUG_VHB
544 dbg::print(stderr, "::VHB:: setState() on {} ==> proxy not valid! Dumping Store\n", dbg::ptr(this));
545 if (!m_store) {
546 dbg::print(stderr, "::VHB:: setState() on {} ==> m_store is a nullptr\n", dbg::ptr(this));
547 }
548 else {
549 SGImplSvc* stor = dynamic_cast<SGImplSvc*>(m_store);
550 if (!stor) {
551 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()));
552 }
553 else {
554 dbg::print(stderr, "\n{}\n", stor->dump());
555 }
556 }
557#endif
558 }
559 StatusCode sc = this->setState(proxy);
560
561 // Failure to find the proxy is ok in the case of a @c WriteHandle
562 // that has not yet been written to.
563 if (sc.isFailure() && mode() == Gaudi::DataHandle::Writer && m_ptr == nullptr)
564 return StatusCode::SUCCESS;
565
566 return sc;
567 }
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 )
protected

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

735 {
736 if (0 == store) {
737 return StatusCode::FAILURE;
738 }
739#ifdef DEBUG_VHB
740 dbg::print(stderr, "::VHB::setState({}, store={}, key={}) const\n", dbg::ptr(this), dbg::store(store), key);
741#endif
742 CLID cid = this->clid();
743 SG::DataProxy* proxy = store->proxy(cid, key);
744 return this->setState(proxy);
745 }
uint32_t CLID
The Class ID type.

◆ setState() [3/3]

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

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

709 {
710#ifdef DEBUG_VHB
711 dbg::print(stderr, "::VHB::setState({}, proxy={}) const\n", dbg::ptr(this), dbg::proxy(proxy));
712#endif
713 if (0 == proxy || !proxy->isValid()) {
714 return StatusCode::FAILURE;
715 }
716
717 if (m_proxy != proxy) {
718 // We're changing proxies. Release the old and bind to the new.
719 setProxy (proxy);
720 // Clear cached pointer.
721 m_ptr=0;
722 }
723
724 return StatusCode::SUCCESS;
725 }

◆ setStoreFromHandle()

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

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

1042 {
1043 if (m_ownedKey) {
1044 if (m_ownedKey->initialize().isFailure()) {
1045 return false;
1046 }
1047 }
1048 m_store = storeFromHandle (ctx);
1049 m_storeWasSet = (ctx && m_store ==
1050 Atlas::getExtendedEventContext(*ctx).proxy());
1051 return true;
1052 }
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.

◆ store()

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

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

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

407 {
408 if (m_store)
409 return m_store->name();
410 return this->storeHandle().name();
411 }

◆ storeFromHandle()

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

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

1013 {
1014 if (m_key->isEventStore()) {
1015 if (ctx)
1016 return Atlas::getExtendedEventContext(*ctx).proxy();
1017 if (m_storeWasSet && m_store) return m_store;
1018
1019 const Atlas::ExtendedEventContext* ectx =
1020 Atlas::tryGetExtendedEventContext (Gaudi::Hive::currentContext());
1021
1022 return (ectx ? ectx->proxy() : nullptr);
1023 }
1024
1025 if (m_storeWasSet && m_store) return m_store;
1026 IProxyDict* store = m_store;
1027 if (!store)
1028 store = &*this->storeHandle();
1029
1030 return store->hiveProxyDict();
1031 }
const ExtendedEventContext * tryGetExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.

◆ storeHandle()

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

Return handle to the referenced store.

◆ symLink_impl()

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

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

983 {
984 if (!m_ptr || !m_store) {
985 REPORT_ERROR (StatusCode::FAILURE) << "symlink: Handle not valid.";
986 return StatusCode::FAILURE;
987 }
988
989 SG::DataObjectSharedPtr<DataObject> obj (new SymlinkDataObject (newClid, m_ptr));
990 SG::DataProxy* prox = m_store->recordObject (obj, newKey, false, true);
991 if (!prox)
992 return StatusCode::FAILURE;
993 return StatusCode::SUCCESS;
994 }

◆ toString()

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

Convert to a string representation.

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

682 {
683 std::string s =
684 std::format ("VarHandleBase @{} store={}, clid={}, key{}----------- ptr@{}, proxy@{}",
685 static_cast<const void*>(this),
686 store(), clid(), key(),
688 static_cast<const void*>(m_proxy));
689 if (m_proxy)
690 s += std::format (", DataObject@{}",
691 static_cast<const void*>(m_proxy->object()));
692 return s;
693 }
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 ( )
protected

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)
protected

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
private

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

1097 {
1098 if (!proxy || !proxy->isValid()) {
1099 // invalid proxy
1100 if (!quiet) {
1101 REPORT_MESSAGE(MSG::WARNING)
1102 << "Proxy "
1103 << " [" << (proxy != 0 ? proxy->clID() : 0)
1104 << "/" << (proxy != 0
1105 ? proxy->name()
1106 : std::string("<N/A>"))
1107 << "] is in an invalid state";
1108 } //quiet
1109 return nullptr;
1110 }
1111
1112 DataObject* dobj = proxy->accessData();
1113 if (!dobj) {
1114 // invalid dobj
1115 if (!quiet) {
1116 REPORT_MESSAGE(MSG::WARNING)
1117 << "this proxy " << MSG::hex << proxy
1118 << MSG::dec << " has a NULL data object ptr";
1119 }
1120 return nullptr;
1121 }
1122
1123 const CLID clid = this->clid();
1124 void* ptr = SG::Storable_cast(dobj, clid, nullptr, true, proxy);
1125 if (ptr)
1126 return ptr;
1127
1128 // If ptr is null, probably the clid we gave wasn't the clid
1129 // the object was stored with, nor it inherits from it.
1130 // before giving up, let's check its transient CLIDs
1131 DataBucketBase *dbb = 0;
1132 if (proxy->transientID(clid) &&
1133 0 != (dbb = dynamic_cast<DataBucketBase*>(dobj))) {
1134 // it is a symlink after all.
1135 // Let's hard cast (and keep our fingers Xed)
1136 ptr = static_cast<void*>(dbb->object());
1137 } else {
1138 if (!quiet) {
1139 REPORT_MESSAGE(MSG::WARNING)
1140 << "Request for an invalid object; requested CLID = "
1141 << clid
1142 << ", proxy primary ID is " << proxy->clID();
1143 }
1144 } // try symlink -- endif
1145 return ptr;
1146 }
#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)
protected

Retrieve an object from StoreGate.

Parameters
quietIf true, suppress failure messages.

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

880 {
881#ifdef DEBUG_VHB
882 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));
883#endif
884
885 // First check for cached pointer.
886 if (0 != m_ptr)
887 return m_ptr;
888
889 if (0 == m_proxy) {
890 // No proxy, need to look it up.
891 if (this->setState().isFailure() || !m_proxy) {
892 if (!quiet) {
893 REPORT_MESSAGE(MSG::WARNING)
894 << "could not get proxy for key " << key();
895 if (this->mode() != Gaudi::DataHandle::Reader) {
896 REPORT_MESSAGE(MSG::WARNING)<< " try using a ReadHandle";
897 }
898 } //quiet
899 return 0;
900 } //setstate
901 } //m_proxy
902
904 return m_ptr;
905 }

◆ typeless_ptr()

void * SG::VarHandleBase::typeless_ptr ( bool quiet = defaultQuiet)
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 914 of file StoreGate/src/VarHandleBase.cxx.

915 {
917 if (p != nullptr && isConst())
918 throw SG::ExcConstObject (clid(), key(), store());
919 return p;
920 }
bool isConst() const
True if this handle has a proxy, and the proxy is const.

◆ vhKey()

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

654 {
655 if (!m_ownedKey) {
656 throwExcNonConstHandleKey (m_key->clid(), m_key->key(),
657 m_key->storeHandle().name());
658 }
659 return *m_ownedKey;
660 }
void throwExcNonConstHandleKey(CLID clid, const std::string &sgkey, const std::string &storename)
Throw a SG::ExcNonConstHandleKey exception.

◆ Athena_test::refCountTest

void Athena_test::refCountTest ( void )
friend

◆ Athena_test::resetableTest

void Athena_test::resetableTest ( void )
friend

◆ Athena_test::varHandleTest

Member Data Documentation

◆ m_key

const VarHandleKey* SG::VarHandleBase::m_key
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 543 of file StoreGate/StoreGate/VarHandleBase.h.

◆ m_ownedKey

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

An owned VarHandleKey.

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

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

◆ m_proxy

SG::DataProxy* SG::VarHandleBase::m_proxy
protected

Proxy holding the object to which we are bound.

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

◆ m_ptr

void* SG::VarHandleBase::m_ptr
protected

The object to which we are bound.

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

◆ m_store

IProxyDict* SG::VarHandleBase::m_store
protected

Pointer to the store that owns the object.

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

◆ m_storeWasSet

bool SG::VarHandleBase::m_storeWasSet
protected

True if the store was set explicitly via setProxyDict.

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


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