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;
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  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 
132  bool transientID (CLID id) const;
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 
173  bool isValid() const;
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 
198  bool isConst() const;
199 
200 
207  void setConst();
208 
209 
211  void resetOnly(const bool& flag);
212 
215 
216  bool bindHandle(IResetable* ir);
217  void unbindHandle(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 
309  bool m_resetFlag;
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;
341  typedef std::lock_guard<mutex_t> lock_t;
342  mutable mutex_t m_mutex;
343 
344  Athena::IMessageSvcHolder m_ims;
345 
347  std::atomic<IProxyDict*> m_store;
348 
350  enum ErrNo m_errno; // protected by m_objMutex
351 
352 
353  // For m_dObject.
354  typedef std::recursive_mutex objMutex_t;
355  typedef std::lock_guard<objMutex_t> objLock_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
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:332
SG::DataProxy::m_boundHandles
bool m_boundHandles
True if there are any bound handles.
Definition: DataProxy.h:316
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:347
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:277
calibdata.force
bool force
Definition: calibdata.py:18
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:682
SG::DataProxy::m_t2p
T2pMap * m_t2p
Definition: DataProxy.h:329
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:354
SG::DataProxy::m_ims
Athena::IMessageSvcHolder m_ims
Definition: DataProxy.h:344
SG::DataProxy::objLock_t
std::lock_guard< objMutex_t > objLock_t
Definition: DataProxy.h:355
SG::TransientAddress
Definition: TransientAddress.h:34
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:40
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:695
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:294
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.
SG::DataProxy::AliasCont_t
std::vector< std::string > AliasCont_t
Definition: DataProxy.h:55
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:354
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:209
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:713
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:356
vector
Definition: MultiHisto.h:13
SG::DataProxy::m_dObject
std::atomic< DataObject * > m_dObject
Definition: DataProxy.h:323
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:341
master.flag
bool flag
Definition: master.py:29
CxxUtils
Definition: aligned_vector.h: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:321
SG::DataProxy::m_const
std::atomic< bool > m_const
Is the proxy currently const?
Definition: DataProxy.h:319
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:192
SG::DataProxy::bindHandle
bool bindHandle(IResetable *ir)
Definition: DataProxy.cxx:215
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:306
SG::DataProxy::clID
CLID clID() const
Retrieve clid.
SG::DataProxy::~DataProxy
virtual ~DataProxy()
Definition: DataProxy.cxx:187
SG::DataProxy::release
virtual unsigned long release() override final
release reference to object
Definition: DataProxy.cxx:321
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:393
SG::DataProxy::DataProxy
DataProxy()
Definition: DataProxy.cxx:92
SG::DataProxy::ATLAS_NOT_CONST_THREAD_SAFE
virtual DataObject *object ATLAS_NOT_CONST_THREAD_SAFE() const override final
Retrieve DataObject.
SG::DataProxy::addRef
virtual unsigned long addRef() override final
Add reference to object.
Definition: DataProxy.cxx:314
SG::DataProxy::ErrNo
ErrNo
Definition: DataProxy.h:48
SG::DataProxy::updateAddress
bool updateAddress()
Definition: DataProxy.cxx:599
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:231
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:45
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:241
SG::DataProxy::setAddress
virtual void setAddress(IOpaqueAddress *ioa) override final
set an IOpaqueAddress
Definition: DataProxy.cxx:401
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:513
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:309
SG::DataProxy::NERRORS
@ NERRORS
Definition: DataProxy.h:49
TransientAddress.h
SG::DataProxy::setConst
void setConst()
Mark this object as const.
Definition: DataProxy.cxx:205
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:582
IRegisterTransient.h
Interface for registering a transient object in t2p map.
private
#define private
Definition: xAODTruthCnvAlg.h:20
SG::DataProxy::m_errno
enum ErrNo m_errno
errno-style error code for accessData
Definition: DataProxy.h:350
SG::DataProxy::isResetOnly
bool isResetOnly() const
Check reset only:
SG::DataProxy::refCount
unsigned long refCount() const
return refCount
Definition: DataProxy.cxx:307
SG::DataProxy::finalReset
void finalReset()
Definition: DataProxy.cxx:251
SG::DataProxy::m_tAddress
TransientAddress m_tAddress
Definition: DataProxy.h:325
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:342
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:428
SG::T2pMap
Definition: T2pMap.h:21
SG::DataProxy::m_dataLoader
IConverter * m_dataLoader
Definition: DataProxy.h:327
SG::DataProxy::mutex_t
std::recursive_mutex mutex_t
Definition: DataProxy.h:340
SG::DataProxy::m_handles
handleList_t m_handles
Definition: DataProxy.h:333
SG::DataProxy::setID
void setID(CLID id, const std::string &key)
Set the CLID / key.
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37