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-2026 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
89 public:
95 explicit VarHandleBase(CLID clid, Gaudi::DataHandle::Mode mode);
96
97
106 explicit VarHandleBase(CLID clid,
107 const std::string& sgkey,
108 Gaudi::DataHandle::Mode mode,
109 const std::string& storename,
110 const EventContext* ctx);
111
112
120 explicit VarHandleBase(CLID clid,
121 const std::string& sgkey,
122 Gaudi::DataHandle::Mode mode,
123 IProxyDict* sg);
124
125
138 explicit VarHandleBase (const VarHandleKey& key, const EventContext* ctx);
139
140
148 explicit VarHandleBase (SG::DataProxy* proxy,
149 Gaudi::DataHandle::Mode mode);
150
151
155 VarHandleBase( const VarHandleBase& rhs );
156
157
161 VarHandleBase( VarHandleBase&& rhs ) noexcept;
162
163
167 VarHandleBase& operator=( const VarHandleBase& rhs );
168
169
173 VarHandleBase& operator=( VarHandleBase&& rhs ) noexcept;
174
175
179 virtual ~VarHandleBase() override;
180
181
182 //*************************************************************************
183 // Accessors
184 //
185
186
190 virtual const std::string& key() const override final;
191
192
198 const std::string& name() const ;
199
200
204 std::string store() const;
205
206
207 //*************************************************************************
208 // Validity checking.
209 //
210
211
217 virtual bool isValid() = 0;
218
219
225 bool isPresent() const;
226
227
233 bool isInitialized() const;
234
235
241 virtual bool isSet() const override final;
242
243
249 bool isConst() const;
250
251
260 StatusCode initialize (bool used = true);
261
262
272 StatusCode setState();
273
274
275 //*************************************************************************
276 // State setting.
277 //
278
279
286 virtual StatusCode setProxyDict (IProxyDict* store);
287
288
298 virtual void reset (bool hard) override;
299
300
307 virtual void finalReset() override final;
308
309
313 StatusCode setConst();
314
315
316 //*************************************************************************
317 // @c VarHandleKey methods.
318 //
319
320
325
326
331
332
336 Gaudi::DataHandle::Mode mode() const;
337
338
344 const std::string& objKey() const;
345
346
350 const DataObjID& fullKey() const;
351
352
361
362
372 StatusCode assign (const std::string& sgkey);
373
374
378 std::string toString() const;
379
380
381 protected:
382 //*************************************************************************
383 // Protected methods.
384 //
385
386
393 StatusCode setState(SG::DataProxy* proxy);
394
395
403 StatusCode setState(IProxyDict* store, const std::string& name);
404
405
417 StatusCode record_impl (std::unique_ptr<DataObject> dobj,
418 void* dataPtr,
419 bool allowMods,
420 bool returnExisting);
421
422
440 const void* put_impl (const EventContext* ctx,
441 std::unique_ptr<DataObject> dobj,
442 const void* dataPtr,
443 bool allowMods,
444 bool returnExisting,
446
447
453
454
462
463
470
471
478 void* typeless_ptr(bool quiet=defaultQuiet);
479
480
481 /*
482 * @brief Retrieve an object from SG as a const pointer without caching.
483 * @param ctx The event context, or nullptr to use the current context.
484 * @param quiet If true, suppress failure messages.
485 *
486 * Like typeless_dataPointer_impl, except that we don't change
487 * any members of the handle.
488 */
489 const void* get_impl (const EventContext* ctx,
490 bool quiet = defaultQuiet) const;
491
492
503 StatusCode symLink_impl (CLID newClid, const std::string& newKey);
504
505
512 bool isPresent_impl (const std::string& key) const;
513
514
515
516 protected:
517 //*************************************************************************
518 // Protected data.
519 //
520
522 void* m_ptr;
523
526
529
532
533
534 private:
539
544
549 IProxyDict* storeFromHandle (const EventContext* ctx) const;
550
551
559 bool setStoreFromHandle (const EventContext* ctx);
560
561
565 void resetProxy();
566
567
572 void setProxy (SG::DataProxy* proxy);
573
574
582 void*
584 bool quiet) const;
585
586 };
587
588
589 //*************************************************************************
590 // Free functions.
591 //
592
593
599 std::ostream& operator<<( std::ostream& out, const VarHandleBase& o );
600
601
605 bool operator==(const VarHandleBase& l, const VarHandleBase& r);
606
607
611 bool operator!=(const VarHandleBase& l, const VarHandleBase& r);
612
613
614} /* namespace SG */
615
616
617namespace std {
618
619// C++23 compatible formatter.
620template <std::derived_from<SG::VarHandleBase> T>
621struct formatter<T>
622 : public formatter<string_view>
623{
624 template <class FmtContext>
625 FmtContext::iterator format(const T& k, FmtContext& ctx) const;
626};
627
628} // namespace std
629
630
632
633
634#endif //> !STOREGATE_SG_VARHANDLEBASE_H
uint32_t CLID
The Class ID type.
convert to and from a SG storable
A property holding a SG store/key/clid from which a VarHandle is made.
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.
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.
std::string toString() const
Convert to a string representation.
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.
FmtContext::iterator format(const T &k, FmtContext &ctx) const
#define protected
Definition testRead.cxx:26
#define private
Definition testRead.cxx:27