ATLAS Offline Software
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-2024 CERN for the benefit of the ATLAS collaboration
5 */
13 #ifndef STOREGATE_SG_VARHANDLEBASE_H
14 #define STOREGATE_SG_VARHANDLEBASE_H 1
15 
16 // STL includes
17 #include <string>
18 
19 #include "StoreGate/VarHandleKey.h"
20 
21 // fwk includes
24 #include "AthenaKernel/StoreID.h"
26 #include "GaudiKernel/ServiceHandle.h"
27 #include "GaudiKernel/EventContext.h"
28 
29 // SGTools includes
30 #include "SGTools/DataProxy.h"
31 #include "SGTools/ProxyMap.h"
32 #include "SGTools/BuiltinsClids.h"
33 #include "SGTools/StlVectorClids.h"
34 #include "SGTools/StlMapClids.h"
35 
36 namespace SGTest {
37  class TestStore;
38 }
39 namespace Athena_test {
41  void resetableTest(void);
42  void refCountTest(void);
43 }
44 namespace SG {
45  static constexpr bool defaultQuiet = false;
46 
47 
82  class VarHandleBase : public IResetable
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:
97 
98 
106  explicit VarHandleBase(CLID clid,
107  const std::string& sgkey,
109  const std::string& storename = StoreID::storeName(StoreID::EVENT_STORE));
110 
111 
124  explicit VarHandleBase (const VarHandleKey& key, const EventContext* ctx);
125 
126 
134  explicit VarHandleBase (SG::DataProxy* proxy,
136 
137 
141  VarHandleBase( const VarHandleBase& rhs );
142 
143 
147  VarHandleBase( VarHandleBase&& rhs ) noexcept;
148 
149 
153  VarHandleBase& operator=( const VarHandleBase& rhs );
154 
155 
159  VarHandleBase& operator=( VarHandleBase&& rhs ) noexcept;
160 
161 
165  virtual ~VarHandleBase() override;
166 
167 
168  //*************************************************************************
169  // Accessors
170  //
171 
172 
176  virtual const std::string& key() const override final;
177 
178 
184  const std::string& name() const ;
185 
186 
190  std::string store() const;
191 
192 
193  //*************************************************************************
194  // Validity checking.
195  //
196 
197 
203  virtual bool isValid() = 0;
204 
205 
211  bool isPresent() const;
212 
213 
219  bool isInitialized() const;
220 
221 
227  virtual bool isSet() const override final;
228 
229 
235  bool isConst() const;
236 
237 
246  StatusCode initialize (bool used = true);
247 
248 
259 
260 
261  //*************************************************************************
262  // State setting.
263  //
264 
265 
273 
274 
284  virtual void reset (bool hard) override;
285 
286 
293  virtual void finalReset() override final;
294 
295 
300 
301 
302  //*************************************************************************
303  // @c VarHandleKey methods.
304  //
305 
306 
311 
312 
317 
318 
323 
324 
330  const std::string& objKey() const;
331 
332 
336  const DataObjID& fullKey() const;
337 
338 
346  SG::VarHandleKey& vhKey();
347 
348 
358  StatusCode assign (const std::string& sgkey);
359 
360 
361  protected:
362  //*************************************************************************
363  // Protected methods.
364  //
365 
366 
374 
375 
383  StatusCode setState(IProxyDict* store, const std::string& name);
384 
385 
397  StatusCode record_impl (std::unique_ptr<DataObject> dobj,
398  void* dataPtr,
399  bool allowMods,
400  bool returnExisting);
401 
402 
420  const void* put_impl (const EventContext* ctx,
421  std::unique_ptr<DataObject> dobj,
422  const void* dataPtr,
423  bool allowMods,
424  bool returnExisting,
425  IProxyDict* & store) const;
426 
427 
432  void* typeless_dataPointer_impl(bool quiet);
433 
434 
441  void* typeless_dataPointer(bool quiet=defaultQuiet);
442 
443 
450 
451 
458  void* typeless_ptr(bool quiet=defaultQuiet);
459 
460 
461  /*
462  * @brief Retrieve an object from SG as a const pointer without caching.
463  * @param ctx The event context, or nullptr to use the current context.
464  * @param quiet If true, suppress failure messages.
465  *
466  * Like typeless_dataPointer_impl, except that we don't change
467  * any members of the handle.
468  */
469  const void* get_impl (const EventContext* ctx,
470  bool quiet = defaultQuiet) const;
471 
472 
483  StatusCode symLink_impl (CLID newClid, const std::string& newKey);
484 
485 
492  bool isPresent_impl (const std::string& key) const;
493 
494 
495 
496  protected:
497  //*************************************************************************
498  // Protected data.
499  //
500 
502  void* m_ptr;
503 
506 
509 
512 
513 
514  private:
518  std::unique_ptr<VarHandleKey> m_ownedKey;
519 
524 
529  IProxyDict* storeFromHandle (const EventContext* ctx) const;
530 
531 
539  bool setStoreFromHandle (const EventContext* ctx);
540 
541 
545  void resetProxy();
546 
547 
552  void setProxy (SG::DataProxy* proxy);
553 
554 
562  void*
564  bool quiet) const;
565 
566  };
567 
568 
569  //*************************************************************************
570  // Free functions.
571  //
572 
573 
579  std::ostream& operator<<( std::ostream& out, const VarHandleBase& o );
580 
581 
585  bool operator==(const VarHandleBase& l, const VarHandleBase& r);
586 
587 
591  bool operator!=(const VarHandleBase& l, const VarHandleBase& r);
592 
593 
594 } /* namespace SG */
595 
596 
597 #include "StoreGate/VarHandleBase.icc"
598 
599 
600 #endif //> !STOREGATE_SG_VARHANDLEBASE_H
used
beamspotman.r
def r
Definition: beamspotman.py:676
common.sgkey
def sgkey(tool)
Definition: common.py:1028
SG::VarHandleBase::VarHandleBase
VarHandleBase(CLID clid, Gaudi::DataHandle::Mode mode)
Constructor with default key.
Definition: StoreGate/src/VarHandleBase.cxx:113
SGTest
Definition: TestStore.h:26
StateLessPT_NewConfig.proxy
proxy
Definition: StateLessPT_NewConfig.py:392
VarHandleKey.h
A property holding a SG store/key/clid from which a VarHandle is made.
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::VarHandleBase::storeFromHandle
IProxyDict * storeFromHandle(const EventContext *ctx) const
Return the store instance to use.
Definition: StoreGate/src/VarHandleBase.cxx:957
SG::VarHandleBase::m_ownedKey
std::unique_ptr< VarHandleKey > m_ownedKey
An owned VarHandleKey.
Definition: StoreGate/StoreGate/VarHandleBase.h:518
SG::VarHandleBase::finalReset
virtual void finalReset() override final
Reset this handle at the end of processing.
Definition: StoreGate/src/VarHandleBase.cxx:595
SG::VarHandleBase::typeless_dataPointer
void * typeless_dataPointer(bool quiet=defaultQuiet)
Retrieve an object from StoreGate.
StorableConversions.h
convert to and from a SG storable
Athena_test::refCountTest
void refCountTest(void)
quiet
bool quiet
Definition: TrigGlobEffCorrValidation.cxx:190
SG::VarHandleBase::name
const std::string & name() const
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:75
SG::VarHandleBase::assign
StatusCode assign(const std::string &sgkey)
Update the underlying key from a string.
Definition: StoreGate/src/VarHandleBase.cxx:642
SG::VarHandleBase::setState
StatusCode setState()
Retrieve and cache all information managed by a handle.
Definition: StoreGate/src/VarHandleBase.cxx:487
SG::VarHandleBase
Base class for VarHandle types.
Definition: StoreGate/StoreGate/VarHandleBase.h:83
SG::VarHandleBase::clid
CLID clid() const
Return the class ID for the referenced object.
Athena_test::resetableTest
void resetableTest(void)
SG::VarHandleBase::typeless_dataPointer_impl
void * typeless_dataPointer_impl(bool quiet)
Retrieve an object from StoreGate.
Definition: StoreGate/src/VarHandleBase.cxx:824
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
SG::VarHandleBase::operator=
VarHandleBase & operator=(const VarHandleBase &rhs)
Assignment operator.
Definition: StoreGate/src/VarHandleBase.cxx:267
UploadAMITag.l
list l
Definition: UploadAMITag.larcaf.py:158
BuiltinsClids.h
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SG::VarHandleBase::setConst
StatusCode setConst()
Set the 'const' bit for the bound proxy in the store.
Definition: StoreGate/src/VarHandleBase.cxx:606
protected
#define protected
Definition: DetDescrConditionsDict_dict_fixes.cxx:14
SGTest::TestStore
Definition: TestStore.h:52
ProxyMap.h
SG::VarHandleBase::operator<<
friend std::ostream & operator<<(std::ostream &, const VarHandleBase &)
Output stream.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:107
Athena_test::varHandleTest
void varHandleTest(SGTest::TestStore &)
IResetable
a resetable object (e.g. a SG DataHandle)
Definition: IResetable.h:15
StlVectorClids.h
SG::VarHandleBase::setProxyDict
virtual StatusCode setProxyDict(IProxyDict *store)
Explicitly set the event store.
Definition: StoreGate/src/VarHandleBase.cxx:551
SG::VarHandleBase::resetProxy
void resetProxy()
Clear the m_proxy field and release the old proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1004
IResetable.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::VarHandleBase::m_key
const VarHandleKey * m_key
The associated key object.
Definition: StoreGate/StoreGate/VarHandleBase.h:523
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:376
Athena_test
functions & macros to test the difference between floats
Definition: InitGaudiGoogleTest.h:31
SG::VarHandleBase::m_proxy
SG::DataProxy * m_proxy
Proxy holding the object to which we are bound.
Definition: StoreGate/StoreGate/VarHandleBase.h:505
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::VarHandleBase::isInitialized
bool isInitialized() const
Has a proxy been retrieved from SG?
Definition: StoreGate/src/VarHandleBase.cxx:406
StoreID.h
IProxyDict.h
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
SG::VarHandleBase::mode
Gaudi::DataHandle::Mode mode() const
Return the mode (read/write/update) for this handle.
StlMapClids.h
EventContainers::Mode
Mode
Definition: IdentifiableContainerBase.h:13
DataHandle
an iterator over instances of a given type in StoreGateSvc. It d-casts and caches locally the pointed...
Definition: DataHandle.h:42
SG::VarHandleBase::isPresent_impl
bool isPresent_impl(const std::string &key) const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:1101
SG::VarHandleBase::reset
virtual void reset(bool hard) override
Reset this handle.
Definition: StoreGate/src/VarHandleBase.cxx:570
SG::VarHandleBase::typeless_dataPointer_fromProxy
void * typeless_dataPointer_fromProxy(SG::DataProxy *proxy, bool quiet) const
Retrieve a pointer from a proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1041
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
SG::VarHandleKey
A property holding a SG store/key/clid from which a VarHandle is made.
Definition: StoreGate/StoreGate/VarHandleKey.h:62
SG::VarHandleBase::~VarHandleBase
virtual ~VarHandleBase() override
Destructor.
Definition: StoreGate/src/VarHandleBase.cxx:331
SG::VarHandleBase::objKey
const std::string & objKey() const
Return the key string of the underlying DataObjID.
SG::VarHandleBase::storeHandle
const ServiceHandle< IProxyDict > & storeHandle() const
Return handle to the referenced store.
SG::VarHandleBase::typeless_cptr
const void * typeless_cptr()
Retrieve an object from StoreGate as a const pointer.
SG::VarHandleBase::setStoreFromHandle
bool setStoreFromHandle(const EventContext *ctx)
Initialize the store pointer from the store handle.
Definition: StoreGate/src/VarHandleBase.cxx:987
SG::VarHandleBase::fullKey
const DataObjID & fullKey() const
Return the key as a DataObjID.
SG::VarHandleBase::typeless_ptr
void * typeless_ptr(bool quiet=defaultQuiet)
Retrieve an object from StoreGate as non-const pointer.
Definition: StoreGate/src/VarHandleBase.cxx:859
SG::VarHandleBase::initialize
StatusCode initialize(bool used=true)
Verify that the handle has been configured properly.
Definition: StoreGate/src/VarHandleBase.cxx:452
SG::VarHandleBase::vhKey
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
Definition: StoreGate/src/VarHandleBase.cxx:623
SG::VarHandleBase::m_storeWasSet
bool m_storeWasSet
True if the store was set explicitly via setProxyDict.
Definition: StoreGate/StoreGate/VarHandleBase.h:511
SG::VarHandleBase::m_ptr
void * m_ptr
The object to which we are bound.
Definition: StoreGate/StoreGate/VarHandleBase.h:502
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:394
SG::VarHandleBase::isConst
bool isConst() const
True if this handle has a proxy, and the proxy is const.
Definition: StoreGate/src/VarHandleBase.cxx:432
StoreID::EVENT_STORE
@ EVENT_STORE
Definition: StoreID.h:26
SG::VarHandleBase::put_impl
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.
Definition: StoreGate/src/VarHandleBase.cxx:782
SG::VarHandleBase::isValid
virtual bool isValid()=0
Can the handle be successfully dereferenced?
SG::VarHandleBase::m_store
IProxyDict * m_store
Pointer to the store that owns the object.
Definition: StoreGate/StoreGate/VarHandleBase.h:508
SG::DataProxy
Definition: DataProxy.h:45
SG::VarHandleBase::isSet
virtual bool isSet() const override final
Has a proxy been retrieved from SG?
Definition: StoreGate/src/VarHandleBase.cxx:420
SG::VarHandleBase::record_impl
StatusCode record_impl(std::unique_ptr< DataObject > dobj, void *dataPtr, bool allowMods, bool returnExisting)
Helper to record an object in the event store.
Definition: StoreGate/src/VarHandleBase.cxx:713
StoreID::storeName
static const std::string & storeName(const StoreID::type &s)
Definition: StoreID.cxx:77
SG::VarHandleBase::symLink_impl
StatusCode symLink_impl(CLID newClid, const std::string &newKey)
Make a symlink or alias to the object currently referenced by this handle.
Definition: StoreGate/src/VarHandleBase.cxx:926
SG::VarHandleBase::get_impl
const void * get_impl(const EventContext *ctx, bool quiet=defaultQuiet) const
Definition: StoreGate/src/VarHandleBase.cxx:876
SG::VarHandleBase::setProxy
void setProxy(SG::DataProxy *proxy)
Set a new proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1020
ServiceHandle
Definition: ClusterMakerTool.h:37
DataProxy.h