Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 */
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 
107  explicit VarHandleBase(CLID clid,
108  const std::string& sgkey,
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,
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 
261 
262 
263  //*************************************************************************
264  // State setting.
265  //
266 
267 
275 
276 
286  virtual void reset (bool hard) override;
287 
288 
295  virtual void finalReset() override final;
296 
297 
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 
348  SG::VarHandleKey& vhKey();
349 
350 
360  StatusCode assign (const std::string& sgkey);
361 
362 
363  protected:
364  //*************************************************************************
365  // Protected methods.
366  //
367 
368 
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,
427  IProxyDict* & store) const;
428 
429 
434  void* typeless_dataPointer_impl(bool quiet);
435 
436 
443  void* typeless_dataPointer(bool quiet=defaultQuiet);
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:
520  std::unique_ptr<VarHandleKey> m_ownedKey;
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
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:402
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:963
SG::VarHandleBase::m_ownedKey
std::unique_ptr< VarHandleKey > m_ownedKey
An owned VarHandleKey.
Definition: StoreGate/StoreGate/VarHandleBase.h:520
SG::VarHandleBase::finalReset
virtual void finalReset() override final
Reset this handle at the end of processing.
Definition: StoreGate/src/VarHandleBase.cxx:601
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:648
SG::VarHandleBase::setState
StatusCode setState()
Retrieve and cache all information managed by a handle.
Definition: StoreGate/src/VarHandleBase.cxx:493
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:830
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
SG::VarHandleBase::operator=
VarHandleBase & operator=(const VarHandleBase &rhs)
Assignment operator.
Definition: StoreGate/src/VarHandleBase.cxx:273
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:612
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:557
SG::VarHandleBase::resetProxy
void resetProxy()
Clear the m_proxy field and release the old proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1010
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:525
SG::VarHandleBase::store
std::string store() const
Return the name of the store holding the object we are proxying.
Definition: StoreGate/src/VarHandleBase.cxx:382
Athena_test
functions & macros to test the difference between floats
Definition: InitGaudiGoogleTest.h:30
SG::VarHandleBase::m_proxy
SG::DataProxy * m_proxy
Proxy holding the object to which we are bound.
Definition: StoreGate/StoreGate/VarHandleBase.h:507
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:412
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:43
SG::VarHandleBase::isPresent_impl
bool isPresent_impl(const std::string &key) const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:1107
SG::VarHandleBase::reset
virtual void reset(bool hard) override
Reset this handle.
Definition: StoreGate/src/VarHandleBase.cxx:576
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:1047
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:337
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:993
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:865
SG::VarHandleBase::initialize
StatusCode initialize(bool used=true)
Verify that the handle has been configured properly.
Definition: StoreGate/src/VarHandleBase.cxx:458
SG::VarHandleBase::vhKey
SG::VarHandleKey & vhKey()
Return a non-const reference to the HandleKey.
Definition: StoreGate/src/VarHandleBase.cxx:629
SG::VarHandleBase::m_storeWasSet
bool m_storeWasSet
True if the store was set explicitly via setProxyDict.
Definition: StoreGate/StoreGate/VarHandleBase.h:513
SG::VarHandleBase::m_ptr
void * m_ptr
The object to which we are bound.
Definition: StoreGate/StoreGate/VarHandleBase.h:504
Gaudi
=============================================================================
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:273
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:400
SG::VarHandleBase::isConst
bool isConst() const
True if this handle has a proxy, and the proxy is const.
Definition: StoreGate/src/VarHandleBase.cxx:438
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:788
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:510
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:426
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:719
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:932
SG::VarHandleBase::get_impl
const void * get_impl(const EventContext *ctx, bool quiet=defaultQuiet) const
Definition: StoreGate/src/VarHandleBase.cxx:882
SG::VarHandleBase::setProxy
void setProxy(SG::DataProxy *proxy)
Set a new proxy.
Definition: StoreGate/src/VarHandleBase.cxx:1026
ServiceHandle
Definition: ClusterMakerTool.h:37
DataProxy.h