ATLAS Offline Software
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:
29 class DataObject;
30 class IConverter;
31 class IResetable;
32 class IProxyDict;
33 
40 namespace SG {
41  class T2pMap;
42 class 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;
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  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  virtual IOpaqueAddress* address() const override final;
114 
116  virtual IDataProviderSvc* dataSvc() const override final;
118 
121 
124 
127 
129  bool transientID (CLID id) const;
130 
133 
136 
140 
142  bool hasAlias (const std::string& key) const;
143 
145  void setAlias(const std::string& key);
146 
148  bool removeAlias(const std::string& key);
149 
152 
155 
158  void setID (CLID id, const std::string& key);
159 
161 
166  void reset (bool hard = false);
167  void finalReset();
168 
170  bool isValid() const;
171 
173  bool isValidAddress() const;
174 
177 
178  bool updateAddress();
179 
183  void setObject(DataObject* obj, bool doreg = true);
184 
187  DataObject* accessData();
188 
190 
193 
195  bool isConst() const;
196 
197 
204  void setConst();
205 
206 
208  void resetOnly(const bool& flag);
209 
212 
213  bool bindHandle(IResetable* ir);
214  void unbindHandle(IResetable* ir);
215 
216  // cache the t2p
217  void setT2p(T2pMap* t2p);
218 
225  virtual void registerTransient (void* p) override final;
226 
229 
232 
235 
240  void resetBoundHandles (bool hard);
241 
242  IConverter* loader();
243 
244 
257  std::unique_ptr<DataObject> readData();
258 
259 
260  private:
262  friend class SG::DataStore;
263 
265  DataProxy& operator=(const DataProxy&) = delete;
266 
267 
269  DataObject* accessDataOol();
270 
271 
293  bool requestRelease(bool force, bool hard);
294 
296  void resetRef();
297 
298  // PLEASE NOTE: The data members of this class are ordered so that
299  // the most frequently accessed members are grouped together, within
300  // the first cache line. See the layout at the end of this file.
301  // Be aware of this when making changes to the layout of this class.
302 
303  unsigned int m_refCount;
304 
306  bool m_resetFlag;
307 
309  // Strictly redundant with m_handles below, but put here to speed up the
310  // test for m_handles.empty() --- both by eliminating the pointer
311  // comparison and by moving the data into the part of DataProxy covered
312  // by the first cache line.
314 
316  std::atomic<bool> m_const;
319 
320  std::atomic<DataObject*> m_dObject;
321 
323 
324  IConverter* m_dataLoader;
325 
327 
331 
332  // Needs to be recursive since updateAddress can call back
333  // into the DataProxy.
334  // To prevent deadlocks, the store lock should be acquired
335  // before this one. This implies that we shouldn't call anything
336  // that might acquire the store lock while holding m_mutex.
337  typedef std::recursive_mutex mutex_t;
338  typedef std::lock_guard<mutex_t> lock_t;
339  mutable mutex_t m_mutex;
340 
341  // For m_dObject.
342  typedef std::recursive_mutex objMutex_t;
343  typedef std::lock_guard<objMutex_t> objLock_t;
344  mutable objMutex_t m_objMutex; // For m_dObject, m_errno
345 
346 
347  Athena::IMessageSvcHolder m_ims;
348 
350  std::atomic<IProxyDict*> m_store;
351 
353  enum ErrNo m_errno; // protected by m_objMutex
354 
355 
361  void lock (objLock_t&);
362 
363 
375  std::unique_ptr<DataObject> readData (objLock_t& objLock, ErrNo* errNo);
376 
377 
381  void setObject (objLock_t& objLock, DataObject* obj, bool doreg);
382 
383 
393  const EventContext& contextFromStore() const;
394 
395  };
396 
397 
398 } //end namespace SG
399 
400 
401 // DP+ 0: two vptrs
402 // DP+10: int m_refCount
403 // DP+14: bool m_resetFlag
404 // DP+15: bool m_boundHandles
405 // DP+16: bool m_const
406 // DP+17: bool m_origConst
407 // DP+18: DataObject* m_dObject
408 
409 // TA = DP+20
410 // + 0: CLID m_clid
411 // + 4: sgkey_t m_sgkey
412 // + 8: type m_storeID (size 4)
413 // + c: bool m_clearAddress
414 // + d: bool m_consultProvider
415 // + e: padding
416 // +10: IOpaqueAddress* m_address
417 // +18: IAddressProvider* m_pAddressProvider
418 // +20: SG::CachedValue<std::string> m_name <== 2nd cache line starts at +20
419 // +48: vector m_transientID
420 // +60: set m_transientAlias <== 3rd cache line starts at +60
421 // +90..
422 
423 // DP+b0: IConverter* m_dataLoader
424 // DP+b8: T2PMap* m_t2p
425 // DP+c0: vector m_handles <== 4th cache line starts at +c0
426 // DP+d8: m_mutex
427 // DP+100: m_objMutex <== 5th cache line starts at +100
428 // DP+128: IMessageSvc* m_ims
429 // DP+130: std::atomic<IProxyDict*> m_store
430 // DP+138: ErrNo m_errno
431 // DP+13c: padding
432 // DP+140: end
433 
434 
435 #include "SGTools/DataProxy.icc"
436 
437 #endif // SGTOOLS_DATAPROXY
SG::IRegisterTransient
Interface for registering a transient object in t2p map.
Definition: IRegisterTransient.h:28
exceptions.h
Exceptions that can be thrown by SGTools.
SG::DataProxy::handleList_t
std::vector< IResetable * > handleList_t
list of bound DataHandles
Definition: DataProxy.h:329
SG::DataProxy::m_boundHandles
bool m_boundHandles
True if there are any bound handles.
Definition: DataProxy.h:313
SG::DataProxy::storeID
StoreID::type storeID() const
check if it is a transient ID (primary or symLinked):
SG::DataProxy::name_type
std::string name_type
Definition: DataProxy.h:52
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::DataProxy::isConst
bool isConst() const
Check if it is a const object.
SG::DataProxy::sgkey
sgkey_t sgkey() const
< Get the primary (hashed) SG key.
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
SG::DataProxy::m_store
std::atomic< IProxyDict * > m_store
The store of which we are a part.
Definition: DataProxy.h:350
SG::DataProxy::resetBoundHandles
void resetBoundHandles(bool hard)
reset the bound DataHandles If HARD is true, then the bound objects should also clear any data that d...
Definition: DataProxy.cxx:276
calibdata.force
bool force
Definition: calibdata.py:19
SG::DataProxy::transientID
CLIDCont_t transientID() const
SG::DataProxy::registerTransient
virtual void registerTransient(void *p) override final
Register a transient object in a t2p map.
Definition: DataProxy.cxx:666
SG::DataProxy::m_t2p
T2pMap * m_t2p
Definition: DataProxy.h:326
SG::DataProxy::removeAlias
bool removeAlias(const std::string &key)
remove alias from proxy
SG::DataProxy::objMutex_t
std::recursive_mutex objMutex_t
Definition: DataProxy.h:342
SG::DataProxy::m_ims
Athena::IMessageSvcHolder m_ims
Definition: DataProxy.h:347
SG::DataProxy::objLock_t
std::lock_guard< objMutex_t > objLock_t
Definition: DataProxy.h:343
SG::TransientAddress
Definition: TransientAddress.h:32
SG::DataProxy::accessData
DataObject * accessData()
Access DataObject on-demand using conversion service.
SG::TransientAddress::TransientClidSet
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...
Definition: TransientAddress.h:38
SG::DataProxy::isValid
bool isValid() const
called by destructor
SG::DataProxy::RECURSIVEREAD
@ RECURSIVEREAD
Definition: DataProxy.h:49
SG::DataProxy::sgkey_t
IStringPool::sgkey_t sgkey_t
Definition: DataProxy.h:56
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
IStringPool::sgkey_t
SG::sgkey_t sgkey_t
Type of the keys.
Definition: IStringPool.h:34
SG::DataProxy::NOCNVSVC
@ NOCNVSVC
Definition: DataProxy.h:48
SG::DataProxy::lock
void lock(objLock_t &)
Lock the data object we're holding, if any.
Definition: DataProxy.cxx:679
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SG::DataProxy::dataSvc
virtual IDataProviderSvc * dataSvc() const override final
set DataSvc (Gaudi-specific); do nothing for us
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
SG::DataProxy::NOIOA
@ NOIOA
Definition: DataProxy.h:48
SG::DataProxy::unbindHandle
void unbindHandle(IResetable *ir)
Definition: DataProxy.cxx:293
SG::DataProxy::CLIDCont_t
TransientAddress::TransientClidSet CLIDCont_t
Definition: DataProxy.h:54
SG::DataProxy::setProvider
void setProvider(IAddressProvider *provider, StoreID::type storeID)
Set the address provider.
SG::DataProxy::setStore
void setStore(IProxyDict *store)
Set the store of which we're a part.
IResetable
a resetable object (e.g. a SG DataHandle)
Definition: IResetable.h:15
SG::DataProxy::requestRelease
bool requestRelease(bool force, bool hard)
Reset/release a proxy at the end of an event.
Definition: DataProxy.cxx:353
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SG::DataProxy::address
virtual IOpaqueAddress * address() const override final
Retrieve IOpaqueAddress.
SG::DataProxy::contextFromStore
const EventContext & contextFromStore() const
Retrieve the EventContext saved in the owning store.
Definition: DataProxy.cxx:697
SG::DataProxy::setSGKey
void setSGKey(sgkey_t sgkey)
Return the ID of the store containing this proxy.
Athena
Some weak symbol referencing magic...
Definition: AthLegacySequence.h:21
SG::DataProxy::m_objMutex
objMutex_t m_objMutex
Definition: DataProxy.h:344
vector
Definition: MultiHisto.h:13
SG::DataProxy::m_dObject
std::atomic< DataObject * > m_dObject
Definition: DataProxy.h:320
SG::DataProxy::alias
AliasCont_t alias() const
access set of proxy aliases Returns a COPY of the alias set.
SG::DataProxy::lock_t
std::lock_guard< mutex_t > lock_t
Definition: DataProxy.h:338
master.flag
bool flag
Definition: master.py:29
IAddressProvider
interface for IOA providers
Definition: IAddressProvider.h:28
SG::DataProxy::m_origConst
bool m_origConst
Was the proxy created as const?
Definition: DataProxy.h:318
SG::DataProxy::m_const
std::atomic< bool > m_const
Is the proxy currently const?
Definition: DataProxy.h:316
SG::DataProxy::T2PREGFAILED
@ T2PREGFAILED
Definition: DataProxy.h:48
StoreID
defines an enum used by address providers to decide what kind of StoreGateSvc they are providing addr...
Definition: StoreID.h:18
SG::DataProxy::identifier
virtual const id_type & identifier() const override final
Retrieve data object key == string duplicated for Gaudi folks does same as name()
SG::DataProxy::store
IProxyDict * store()
Return the store of which we're a part.
SG::DataProxy::setT2p
void setT2p(T2pMap *t2p)
Definition: DataProxy.cxx:191
SG::DataProxy::bindHandle
bool bindHandle(IResetable *ir)
Definition: DataProxy.cxx:214
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::DataProxy::m_refCount
unsigned int m_refCount
Definition: DataProxy.h:303
SG::DataProxy::clID
CLID clID() const
Retrieve clid.
SG::DataProxy::~DataProxy
virtual ~DataProxy()
Definition: DataProxy.cxx:186
SG::DataProxy::release
virtual unsigned long release() override final
release reference to object
Definition: DataProxy.cxx:320
SG::DataProxy::ALLOK
@ ALLOK
Definition: DataProxy.h:48
SG::DataProxy::setObject
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.
Definition: DataProxy.cxx:392
SG::DataProxy::DataProxy
DataProxy()
Definition: DataProxy.cxx:91
SG::DataProxy::ATLAS_NOT_CONST_THREAD_SAFE
virtual DataObject *object ATLAS_NOT_CONST_THREAD_SAFE() const override final
Retrieve DataObject.
private
#define private
Definition: DetDescrConditionsDict_dict_fixes.cxx:13
SG::DataProxy::addRef
virtual unsigned long addRef() override final
Add reference to object.
Definition: DataProxy.cxx:313
SG::DataProxy::ErrNo
ErrNo
Definition: DataProxy.h:48
SG::DataProxy::updateAddress
bool updateAddress()
Definition: DataProxy.cxx:583
SG::DataProxy::loader
IConverter * loader()
SG::DataProxy::name
virtual const name_type & name() const override final
Retrieve data object key == string.
SG::DataProxy::resetRef
void resetRef()
Drop the reference to the data object.
Definition: DataProxy.cxx:230
SG::DataProxy::setAlias
void setAlias(const std::string &key)
Add a new proxy alias.
SG::DataProxy::setTransientID
void setTransientID(CLID id)
Add a new transient ID.
SG::DataProxy::provider
IAddressProvider * provider()
Return the address provider.
ir
int ir
counter of the current depth
Definition: fastadd.cxx:49
SG::DataProxy::isValidObject
bool isValidObject() const
is the object valid?
calibdata.delete
list delete
Definition: calibdata.py:46
SG::DataProxy::hasAlias
bool hasAlias(const std::string &key) const
Test to see if a given string is in the alias set.
SG::DataProxy::reset
void reset(bool hard=false)
Other methods of DataProxy (not in Interface IRegistry):
Definition: DataProxy.cxx:240
SG::DataProxy::setAddress
virtual void setAddress(IOpaqueAddress *ioa) override final
set an IOpaqueAddress
Definition: DataProxy.cxx:400
SG::DataProxy::resetOnly
void resetOnly(const bool &flag)
set the reset only flag: Clear Store will reset and not delete.
SG::DataProxy::accessDataOol
DataObject * accessDataOol()
Out-of-line part of accessData().
Definition: DataProxy.cxx:497
SG::DataStore
Hold DataProxy instances associated with a store.
Definition: Control/SGTools/SGTools/DataStore.h:74
SG::DataProxy::m_resetFlag
bool m_resetFlag
reset and not delete: default is true
Definition: DataProxy.h:306
SG::DataProxy::NERRORS
@ NERRORS
Definition: DataProxy.h:49
TransientAddress.h
SG::DataProxy::setConst
void setConst()
Mark this object as const.
Definition: DataProxy.cxx:204
SG::DataProxy::id_type
std::string id_type
Definition: DataProxy.h:53
SG::DataProxy::CNVFAILED
@ CNVFAILED
Definition: DataProxy.h:48
SG::DataProxy::isValidAddress
bool isValidAddress() const
is the address valid?
Definition: DataProxy.cxx:566
IRegisterTransient.h
Interface for registering a transient object in t2p map.
SG::DataProxy::m_errno
enum ErrNo m_errno
errno-style error code for accessData
Definition: DataProxy.h:353
SG::DataProxy::isResetOnly
bool isResetOnly() const
Check reset only:
SG::DataProxy::refCount
unsigned long refCount() const
return refCount
Definition: DataProxy.cxx:306
SG::DataProxy::finalReset
void finalReset()
Definition: DataProxy.cxx:250
SG::DataProxy::m_tAddress
TransientAddress m_tAddress
Definition: DataProxy.h:322
checker_macros.h
Define macros for attributes used to control the static checker.
python.PyAthena.obj
obj
Definition: PyAthena.py:132
SG::DataProxy::errNo
ErrNo errNo() const
SG::DataProxy::m_mutex
mutex_t m_mutex
Definition: DataProxy.h:339
SG::DataProxy
Definition: DataProxy.h:45
SG::DataProxy::readData
std::unique_ptr< DataObject > readData()
Read in a new copy of the object referenced by this proxy.
Definition: DataProxy.cxx:420
SG::T2pMap
Definition: T2pMap.h:21
SG::TransientAddress::TransientAliasSet
std::set< std::string > TransientAliasSet
Definition: TransientAddress.h:40
SG::DataProxy::AliasCont_t
TransientAddress::TransientAliasSet AliasCont_t
Definition: DataProxy.h:55
SG::DataProxy::m_dataLoader
IConverter * m_dataLoader
Definition: DataProxy.h:324
SG::DataProxy::mutex_t
std::recursive_mutex mutex_t
Definition: DataProxy.h:337
SG::DataProxy::m_handles
handleList_t m_handles
Definition: DataProxy.h:330
SG::DataProxy::setID
void setID(CLID id, const std::string &key)
Set the CLID / key.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37