ATLAS Offline Software
Loading...
Searching...
No Matches
StoreGate/StoreGate/VarHandleBase.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5*/
12
13#ifndef STOREGATE_SG_VARHANDLEBASE_H
14#define STOREGATE_SG_VARHANDLEBASE_H 1
15
16// STL includes
17#include <string>
18
20
21// fwk includes
26#include "GaudiKernel/ServiceHandle.h"
27#include "GaudiKernel/EventContext.h"
28
29// SGTools includes
30#include "SGTools/DataProxy.h"
31#include "SGTools/ProxyMap.h"
34#include "SGTools/StlMapClids.h"
35
36namespace SGTest {
37 class TestStore;
38}
39namespace Athena_test {
41 void resetableTest(void);
42 void refCountTest(void);
43}
44namespace SG {
45 static constexpr bool defaultQuiet = false;
46
47
83 {
84 // For testing.
86 friend void Athena_test::resetableTest(void);
87 friend void Athena_test::refCountTest(void);
88 friend std::ostream& operator<<( std::ostream&, const VarHandleBase&);
89
90 public:
96 explicit VarHandleBase(CLID clid, Gaudi::DataHandle::Mode mode);
97
98
107 explicit VarHandleBase(CLID clid,
108 const std::string& sgkey,
109 Gaudi::DataHandle::Mode mode,
110 const std::string& storename,
111 const EventContext* ctx);
112
113
126 explicit VarHandleBase (const VarHandleKey& key, const EventContext* ctx);
127
128
136 explicit VarHandleBase (SG::DataProxy* proxy,
137 Gaudi::DataHandle::Mode mode);
138
139
143 VarHandleBase( const VarHandleBase& rhs );
144
145
149 VarHandleBase( VarHandleBase&& rhs ) noexcept;
150
151
155 VarHandleBase& operator=( const VarHandleBase& rhs );
156
157
161 VarHandleBase& operator=( VarHandleBase&& rhs ) noexcept;
162
163
167 virtual ~VarHandleBase() override;
168
169
170 //*************************************************************************
171 // Accessors
172 //
173
174
178 virtual const std::string& key() const override final;
179
180
186 const std::string& name() const ;
187
188
192 std::string store() const;
193
194
195 //*************************************************************************
196 // Validity checking.
197 //
198
199
205 virtual bool isValid() = 0;
206
207
213 bool isPresent() const;
214
215
221 bool isInitialized() const;
222
223
229 virtual bool isSet() const override final;
230
231
237 bool isConst() const;
238
239
248 StatusCode initialize (bool used = true);
249
250
260 StatusCode setState();
261
262
263 //*************************************************************************
264 // State setting.
265 //
266
267
274 virtual StatusCode setProxyDict (IProxyDict* store);
275
276
286 virtual void reset (bool hard) override;
287
288
295 virtual void finalReset() override final;
296
297
301 StatusCode setConst();
302
303
304 //*************************************************************************
305 // @c VarHandleKey methods.
306 //
307
308
313
314
319
320
325
326
332 const std::string& objKey() const;
333
334
338 const DataObjID& fullKey() const;
339
340
349
350
360 StatusCode assign (const std::string& sgkey);
361
362
363 protected:
364 //*************************************************************************
365 // Protected methods.
366 //
367
368
375 StatusCode setState(SG::DataProxy* proxy);
376
377
385 StatusCode setState(IProxyDict* store, const std::string& name);
386
387
399 StatusCode record_impl (std::unique_ptr<DataObject> dobj,
400 void* dataPtr,
401 bool allowMods,
402 bool returnExisting);
403
404
422 const void* put_impl (const EventContext* ctx,
423 std::unique_ptr<DataObject> dobj,
424 const void* dataPtr,
425 bool allowMods,
426 bool returnExisting,
428
429
435
436
444
445
452
453
460 void* typeless_ptr(bool quiet=defaultQuiet);
461
462
463 /*
464 * @brief Retrieve an object from SG as a const pointer without caching.
465 * @param ctx The event context, or nullptr to use the current context.
466 * @param quiet If true, suppress failure messages.
467 *
468 * Like typeless_dataPointer_impl, except that we don't change
469 * any members of the handle.
470 */
471 const void* get_impl (const EventContext* ctx,
472 bool quiet = defaultQuiet) const;
473
474
485 StatusCode symLink_impl (CLID newClid, const std::string& newKey);
486
487
494 bool isPresent_impl (const std::string& key) const;
495
496
497
498 protected:
499 //*************************************************************************
500 // Protected data.
501 //
502
504 void* m_ptr;
505
508
511
514
515
516 private:
521
526
531 IProxyDict* storeFromHandle (const EventContext* ctx) const;
532
533
541 bool setStoreFromHandle (const EventContext* ctx);
542
543
547 void resetProxy();
548
549
554 void setProxy (SG::DataProxy* proxy);
555
556
564 void*
566 bool quiet) const;
567
568 };
569
570
571 //*************************************************************************
572 // Free functions.
573 //
574
575
581 std::ostream& operator<<( std::ostream& out, const VarHandleBase& o );
582
583
587 bool operator==(const VarHandleBase& l, const VarHandleBase& r);
588
589
593 bool operator!=(const VarHandleBase& l, const VarHandleBase& r);
594
595
596} /* namespace SG */
597
598
599#include "StoreGate/VarHandleBase.icc"
600
601
602#endif //> !STOREGATE_SG_VARHANDLEBASE_H
uint32_t CLID
The Class ID type.
#define protected
convert to and from a SG storable
A property holding a SG store/key/clid from which a VarHandle is made.
an iterator over instances of a given type in StoreGateSvc.
Definition DataHandle.h:43
a resetable object (e.g.
Definition IResetable.h:15
void * typeless_ptr(bool quiet=defaultQuiet)
Retrieve an object from StoreGate as non-const pointer.
StatusCode assign(const std::string &sgkey)
Update the underlying key from a string.
VarHandleBase(CLID clid, Gaudi::DataHandle::Mode mode)
Constructor with default key.
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.
std::unique_ptr< VarHandleKey > m_ownedKey
An owned VarHandleKey.
bool isPresent_impl(const std::string &key) const
Is the referenced object present in SG?
IProxyDict * storeFromHandle(const EventContext *ctx) const
Return the store instance to use.
StatusCode symLink_impl(CLID newClid, const std::string &newKey)
Make a symlink or alias to the object currently referenced by this handle.
StatusCode setState()
Retrieve and cache all information managed by a handle.
bool isPresent() const
Is the referenced object present in SG?
void setProxy(SG::DataProxy *proxy)
Set a new proxy.
const void * typeless_cptr()
Retrieve an object from StoreGate as a const pointer.
bool m_storeWasSet
True if the store was set explicitly via setProxyDict.
void * typeless_dataPointer_fromProxy(SG::DataProxy *proxy, bool quiet) const
Retrieve a pointer from a proxy.
const std::string & objKey() const
Return the key string of the underlying DataObjID.
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
const void * get_impl(const EventContext *ctx, bool quiet=defaultQuiet) const
virtual void finalReset() override final
Reset this handle at the end of processing.
virtual bool isSet() const override final
Has a proxy been retrieved from SG?
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.
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.
IProxyDict * m_store
Pointer to the store that owns the object.
void * m_ptr
The object to which we are bound.
virtual bool isValid()=0
Can the handle be successfully dereferenced?
StatusCode record_impl(std::unique_ptr< DataObject > dobj, void *dataPtr, bool allowMods, bool returnExisting)
Helper to record an object in the event store.
Gaudi::DataHandle::Mode mode() const
Return the mode (read/write/update) for this handle.
void * typeless_dataPointer(bool quiet=defaultQuiet)
Retrieve an object from StoreGate.
const VarHandleKey * m_key
The associated key object.
SG::DataProxy * m_proxy
Proxy holding the object to which we are bound.
const DataObjID & fullKey() const
Return the key as a DataObjID.
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
void * typeless_dataPointer_impl(bool quiet)
Retrieve an object from StoreGate.
VarHandleBase & operator=(const VarHandleBase &rhs)
Assignment operator.
friend std::ostream & operator<<(std::ostream &, const VarHandleBase &)
Return the name of the store holding the object we are proxying.
std::string store() const
Return the name of the store holding the object we are proxying.
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
bool isInitialized() const
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.
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.
CLID clid() const
Return the class ID for the referenced object.
virtual ~VarHandleBase() override
Destructor.
const std::string & name() const
Return the StoreGate ID for the referenced object.
A property holding a SG store/key/clid from which a VarHandle is made.
STL class.
STL class.
holding In fact this class is here in order to allow STL container for all features This class is sho...
int r
Definition globals.cxx:22
functions & macros to test the difference between floats
void refCountTest(void)
void varHandleTest(SGTest::TestStore &)
void resetableTest(void)
=============================================================================
Forward declaration.
static constexpr bool defaultQuiet
STL namespace.
#define private