ATLAS Offline Software
Loading...
Searching...
No Matches
DataProxy.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*/
6
7#ifndef SGTOOLS_DATAPROXY_H
8#define SGTOOLS_DATAPROXY_H
9
10// includes
11#include <string>
12#include <set>
13#include <vector>
14#include <typeinfo>
15#include <memory>
16#include <mutex>
17#include <atomic>
18#include "GaudiKernel/IRegistry.h"
19#include "GaudiKernel/ClassID.h"
20#include "GaudiKernel/EventContext.h"
21#include "AthenaKernel/getMessageSvc.h" /*Athena::IMessageSvcHolder*/
24#include "SGTools/exceptions.h"
26
27
28// forward declarations:
29class DataObject;
30class IConverter;
31class IResetable;
32class IProxyDict;
33
39
40namespace SG {
41 class T2pMap;
42class DataStore;
43
44 class DataProxy : public IRegistry, public IRegisterTransient
45 {
46
47 public:
50 //FIXME private typedef IRegistry::name_type name_type;
51 //FIXME private typedef IRegistry::id_type id_type;
52 typedef std::string name_type;
53 typedef std::string id_type;
55 typedef std::vector<std::string> AliasCont_t;
57
58 // Constructors
59 DataProxy(); // default constructor
60
64 IConverter* pDataLoader,
65 bool constFlag=false, bool resetOnly=true);
66
68 DataProxy(std::unique_ptr<TransientAddress> tAddr,
69 IConverter* pDataLoader,
70 bool constFlag=false, bool resetOnly=true);
71
73 IConverter* pDataLoader,
74 bool constFlag=false, bool resetOnly=true);
75
77 DataProxy(DataObject* dObject,
78 TransientAddress* tAddr,
79 bool constFlag=false, bool resetOnly=true);
80
81 DataProxy(DataObject* dObject,
82 TransientAddress&& tAddr,
83 bool constFlag=false, bool resetOnly=true);
84
85 // Destructor
86 virtual ~DataProxy();
87
89
90
91 virtual unsigned long addRef() override final;
92
94 virtual unsigned long release() override final;
95
97 unsigned long refCount() const;
98
100 virtual const name_type& name() const override final;
101
104 virtual const id_type& identifier() const override final;
105
107 virtual DataObject* object ATLAS_NOT_CONST_THREAD_SAFE () const override final;
108
110 virtual void setAddress(IOpaqueAddress* ioa) override final;
111
113 void setAddress(CxxUtils::RefCountedPtr<IOpaqueAddress> ioa);
114
116 virtual IOpaqueAddress* address() const override final;
117
119 virtual IDataProviderSvc* dataSvc() const override final;
121
124
127
130
133
136
139
143
145 bool hasAlias (const std::string& key) const;
146
148 void setAlias(const std::string& key);
149
151 bool removeAlias(const std::string& key);
152
155
158
161 void setID (CLID id, const std::string& key);
162
164
169 void reset (bool hard = false);
170 void finalReset();
171
174
176 bool isValidAddress() const;
177
180
181 bool updateAddress();
182
186 void setObject(DataObject* obj, bool doreg = true);
187
190 DataObject* accessData();
191
193
196
199
200
207 void setConst();
208
209
211 void resetOnly(const bool& flag);
212
215
216 bool bindHandle(IResetable* ir);
218
219 // cache the t2p
220 void setT2p(T2pMap* t2p);
221
228 virtual void registerTransient (void* p) override final;
229
232
235
238
243 void resetBoundHandles (bool hard);
244
245 IConverter* loader();
246
247
260 std::unique_ptr<DataObject> readData();
261
262
263 private:
265 friend class SG::DataStore;
266
268 DataProxy& operator=(const DataProxy&) = delete;
269
270
272 DataObject* accessDataOol();
273
274
296 bool requestRelease(bool force, bool hard);
297
299 void resetRef();
300
301 // PLEASE NOTE: The data members of this class are ordered so that
302 // the most frequently accessed members are grouped together, within
303 // the first cache line. See the layout at the end of this file.
304 // Be aware of this when making changes to the layout of this class.
305
306 unsigned int m_refCount;
307
310
312 // Strictly redundant with m_handles below, but put here to speed up the
313 // test for m_handles.empty() --- both by eliminating the pointer
314 // comparison and by moving the data into the part of DataProxy covered
315 // by the first cache line.
317
319 std::atomic<bool> m_const;
322
323 std::atomic<DataObject*> m_dObject;
324
326
327 IConverter* m_dataLoader;
328
330
334
335 // Needs to be recursive since updateAddress can call back
336 // into the DataProxy.
337 // To prevent deadlocks, the store lock should be acquired
338 // before this one. This implies that we shouldn't call anything
339 // that might acquire the store lock while holding m_mutex.
340 typedef std::recursive_mutex mutex_t;
343
344 Athena::IMessageSvcHolder m_ims;
345
348
350 enum ErrNo m_errno; // protected by m_objMutex
351
352
353 // For m_dObject.
354 typedef std::recursive_mutex objMutex_t;
356 mutable objMutex_t m_objMutex; // For m_dObject, m_errno
357
358
364 void lock (objLock_t&);
365
366
378 std::unique_ptr<DataObject> readData (objLock_t& objLock, ErrNo* errNo);
379
380
384 void setObject (objLock_t& objLock, DataObject* obj, bool doreg);
385
386
396 const EventContext& contextFromStore() const;
397
398 };
399
400
401} //end namespace SG
402
403
404// DP+ 0: two vptrs
405// DP+10: int m_refCount
406// DP+14: bool m_resetFlag
407// DP+15: bool m_boundHandles
408// DP+16: bool m_const
409// DP+17: bool m_origConst
410// DP+18: DataObject* m_dObject
411
412// TA = DP+20
413// + 0: CLID m_clid
414// + 4: sgkey_t m_sgkey
415// + 8: type m_storeID (size 4)
416// + c: bool m_clearAddress
417// + d: bool m_consultProvider
418// + e: padding
419// +10: IOpaqueAddress* m_address
420// +18: IAddressProvider* m_pAddressProvider
421// +20: SG::CachedValue<std::string> m_name <== 2nd cache line starts at +20
422// +48: vector m_transientID
423// +60: vector m_transientAlias <== 3rd cache line starts at +60
424// +7c..
425
426// DP+9c: IConverter* m_dataLoader
427// DP+a0: T2PMap* m_t2p
428// DP+a8: vector m_handles
429// DP+c0: m_mutex <== 4th cache line starts at +c0
430// DP+e8: IMessageSvc* m_ims
431// DP+f0: std::atomic<IProxyDict*> m_store
432// DP+f8: ErrNo m_errno
433// DP+fc: padding
434// DP+100: m_objMutex <== 5th cache line starts at +100
435// DP+128: end
436
437
438#include "SGTools/DataProxy.icc"
439
440#endif // SGTOOLS_DATAPROXY
Exceptions that can be thrown by SGTools.
uint32_t CLID
The Class ID type.
Interface for registering a transient object in t2p map.
Define macros for attributes used to control the static checker.
Hold DataProxy instances associated with a store.
interface for IOA providers
a resetable object (e.g.
Definition IResetable.h:15
SG::sgkey_t sgkey_t
Type of the keys.
Definition IStringPool.h:34
CLID clID() const
Retrieve clid.
void resetBoundHandles(bool hard)
reset the bound DataHandles If HARD is true, then the bound objects should also clear any data that d...
std::lock_guard< objMutex_t > objLock_t
Definition DataProxy.h:355
void setTransientID(CLID id)
Add a new transient ID.
std::recursive_mutex objMutex_t
Definition DataProxy.h:354
std::string id_type
Definition DataProxy.h:53
handleList_t m_handles
Definition DataProxy.h:333
virtual const name_type & name() const override final
Retrieve data object key == string.
unsigned int m_refCount
Definition DataProxy.h:306
ErrNo errNo() const
virtual DataObject *object ATLAS_NOT_CONST_THREAD_SAFE() const override final
Retrieve DataObject.
AliasCont_t alias() const
access set of proxy aliases Returns a COPY of the alias set.
std::vector< IResetable * > handleList_t
list of bound DataHandles
Definition DataProxy.h:332
IConverter * m_dataLoader
Definition DataProxy.h:327
void setID(CLID id, const std::string &key)
Set the CLID / key.
bool transientID(CLID id) const
return the list of transient IDs (primary or symLinked):
std::recursive_mutex mutex_t
Definition DataProxy.h:340
void setConst()
Mark this object as const.
friend class SG::DataStore
For access to requestRelease.
Definition DataProxy.h:265
DataObject * accessDataOol()
Out-of-line part of accessData().
bool requestRelease(bool force, bool hard)
Reset/release a proxy at the end of an event.
virtual void setAddress(IOpaqueAddress *ioa) override final
set an IOpaqueAddress
std::unique_ptr< DataObject > readData()
Read in a new copy of the object referenced by this proxy.
bool m_resetFlag
reset and not delete: default is true
Definition DataProxy.h:309
bool removeAlias(const std::string &key)
remove alias from proxy
IStringPool::sgkey_t sgkey_t
Definition DataProxy.h:56
bool m_boundHandles
True if there are any bound handles.
Definition DataProxy.h:316
virtual void registerTransient(void *p) override final
Register a transient object in a t2p map.
virtual IOpaqueAddress * address() const override final
Retrieve IOpaqueAddress.
std::vector< std::string > AliasCont_t
Definition DataProxy.h:55
virtual unsigned long release() override final
release reference to object
void finalReset()
sgkey_t sgkey() const
< Get the primary (hashed) SG key.
std::string name_type
Definition DataProxy.h:52
bool isResetOnly() const
Check reset only:
void reset(bool hard=false)
Other methods of DataProxy (not in Interface IRegistry):
bool isValid() const
called by destructor
void lock(objLock_t &)
Lock the data object we're holding, if any.
void setProvider(IAddressProvider *provider, StoreID::type storeID)
Set the address provider.
void setObject(DataObject *obj, bool doreg=true)
set DataObject If doreg is true, then call setRegistry to set the backpointer from obj to the proxt.
IProxyDict * store()
Return the store of which we're a part.
void setAlias(const std::string &key)
Add a new proxy alias.
bool isValidAddress() const
is the address valid?
void resetRef()
Drop the reference to the data object.
enum ErrNo m_errno
errno-style error code for accessData
Definition DataProxy.h:350
TransientAddress m_tAddress
Definition DataProxy.h:325
IAddressProvider * provider()
Return the address provider.
void resetOnly(const bool &flag)
set the reset only flag: Clear Store will reset and not delete.
bool isConst() const
Check if it is a const object.
IConverter * loader()
DataObject * accessData()
Access DataObject on-demand using conversion service.
std::atomic< IProxyDict * > m_store
The store of which we are a part.
Definition DataProxy.h:347
Athena::IMessageSvcHolder m_ims
Definition DataProxy.h:344
std::atomic< DataObject * > m_dObject
Definition DataProxy.h:323
void setT2p(T2pMap *t2p)
TransientAddress::TransientClidSet CLIDCont_t
Definition DataProxy.h:54
void unbindHandle(IResetable *ir)
std::atomic< bool > m_const
Is the proxy currently const?
Definition DataProxy.h:319
StoreID::type storeID() const
check if it is a transient ID (primary or symLinked):
unsigned long refCount() const
return refCount
virtual ~DataProxy()
virtual const id_type & identifier() const override final
Retrieve data object key == string duplicated for Gaudi folks does same as name()
bool m_origConst
Was the proxy created as const?
Definition DataProxy.h:321
bool bindHandle(IResetable *ir)
void setSGKey(sgkey_t sgkey)
Return the ID of the store containing this proxy.
const EventContext & contextFromStore() const
Retrieve the EventContext saved in the owning store.
void setStore(IProxyDict *store)
Set the store of which we're a part.
objMutex_t m_objMutex
Definition DataProxy.h:356
bool updateAddress()
bool hasAlias(const std::string &key) const
Test to see if a given string is in the alias set.
std::lock_guard< mutex_t > lock_t
Definition DataProxy.h:341
bool isValidObject() const
is the object valid?
mutex_t m_mutex
Definition DataProxy.h:342
virtual IDataProviderSvc * dataSvc() const override final
set DataSvc (Gaudi-specific); do nothing for us
virtual unsigned long addRef() override final
Add reference to object.
T2pMap * m_t2p
Definition DataProxy.h:329
Interface for registering a transient object in t2p map.
std::vector< CLID > TransientClidSet
Strictly a set, but there shouldn't be more than a handful of entries, so store it as a sorted vector...
defines an enum used by address providers to decide what kind of StoreGateSvc they are providing addr...
Definition StoreID.h:18
STL class.
STL class.
int ir
counter of the current depth
Definition fastadd.cxx:49
singleton-like access to IMessageSvc via open function and helper
Some weak symbol referencing magic... These are declared in AthenaKernel/getMessageSvc....
Forward declaration.
STL namespace.
#define private