ATLAS Offline Software
Control/SGTools/SGTools/DataStore.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef STOREGATE_DATASTORE_H
6 #define STOREGATE_DATASTORE_H
7 
13 #include "SGTools/ProxyMap.h"
14 #include "SGTools/T2pMap.h"
18 #include "CxxUtils/sgkey_t.h"
20 #include "GaudiKernel/ClassID.h"
21 #include "GaudiKernel/SmartIF.h"
22 #include "GaudiKernel/StatusCode.h"
23 
24 #include <exception>
25 #include <list>
26 #include <vector>
27 #include <map>
28 #include <string>
29 #include <typeinfo> /*typeid*/
30 #include <utility> /*std::pair*/
31 #include <unordered_map>
32 #include <mutex>
33 
34 
35 class ISvcLocator;
36 class ISGAudSvc;
37 class MsgStream;
39 
40 namespace SG {
41 
42  class DataProxy;
43 
44 
73  class DataStore : public IProxyRegistry
74  {
75 
76  public:
77 
79  typedef std::map<CLID, SG::ProxyMap> StoreMap;
81  typedef StoreMap::const_iterator ConstStoreIterator;
82 
83  typedef std::pair<SG::ConstProxyIterator, SG::ConstProxyIterator> constProxyRange;
84 
90  virtual ~DataStore();
91 
93  virtual StoreID::type storeID() const override { return m_storeID; }
94 
95  // If FORCE is true, then force deleting of all proxies,
96  // even if they would normally only be reset.
100  void clearStore(bool force, bool hard, MsgStream* pmlog);
101 
104 
105  virtual StatusCode addToStore(const CLID& id, DataProxy* proxy) override;
108  virtual DataProxy* proxy(const TransientAddress* tAddr) const override;
110  virtual DataProxy* proxy(const CLID& id,
111  const std::string& key=SG::DEFAULTKEY) const override;
112 
115  virtual SG::DataProxy* proxy_exact (sgkey_t sgkey) const override;
116 
122  std::recursive_mutex& mutex) const;
123 
126  virtual SG::DataProxy* proxy_exact(const CLID& id,
127  const std::string& key) const override;
128 
134  StatusCode removeProxy(DataProxy* proxy, bool forceRemove, bool hard);
135 
137  StatusCode addSymLink(const CLID& linkid, DataProxy* proxy);
138 
140  virtual StatusCode addAlias(const std::string& aliasKey, DataProxy* proxy) override;
141 
143  int typeCount(const CLID& id) const;
144 
147 
150  SG::ConstProxyIterator& e) const;
151 
152 
156  std::vector<const DataProxy*> pacReport() const { return m_t2p.pacReport();}
157 
159  StatusCode t2pRegister(const void* const pTrans, DataProxy* const pPers);
160  void t2pRemove(const void* const pTrans);
161 
163  DataProxy* locatePersistent(const void* const pTransient) const;
164 
165  // return list of keys associated with an object
166  void keys(const CLID& id, std::vector<std::string>& vkeys,
167  bool includeAlias, bool onlyValid);
168 
171  const std::vector<DataProxy*>& proxies() const;
172 
173 
174  private:
177 
180  std::vector<DataProxy*> m_proxies;
181 
184 
188 
190 
191  // Map to hold the relation between transient and persistent object:
192  // we have changed to DataProxy as it is faster while recording
193  // to check if it already exists
195 
196  void setSGAudSvc();
197  SmartIF<ISGAudSvc> m_pSGAudSvc;
198  bool m_noAudSvc;
199  inline bool doAudit() {
200  if (!m_noAudSvc) setSGAudSvc();
201  return (m_pSGAudSvc);
202  }
203 
204  ISvcLocator* m_pSvcLoc;
206 
207 
226  DataProxy* findDummy (CLID id, const std::string& key);
227 
228 
234 
235 
244  StatusCode
246  };
248  inline void
249  DataStore::t2pRemove(const void* const pTrans)
250  {
251  m_t2p.t2pRemove(pTrans);
252  }
254 } //end namespace SG
255 
256 
257 #endif // STOREGATE_DATASTORE
258 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
SG::T2pMap::setPac
void setPac(IPageAccessControlSvc *pac)
set IPageAccessControlSvc ptr in T2PMap
Definition: T2pMap.h:65
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
SG::DataStore::typeCount
int typeCount(const CLID &id) const
Count number of object of a given type in store.
Definition: Control/SGTools/src/DataStore.cxx:406
common.sgkey
def sgkey(tool)
Definition: common.py:1027
SG::DataStore::t2pRegister
StatusCode t2pRegister(const void *const pTrans, DataProxy *const pPers)
methods to query the T2PMap:
Definition: Control/SGTools/src/DataStore.cxx:614
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::DataStore::~DataStore
virtual ~DataStore()
Definition: Control/SGTools/src/DataStore.cxx:41
calibdata.force
bool force
Definition: calibdata.py:18
IProxyRegistry
a proxy registry (a read/write dictionary)
Definition: IProxyRegistry.h:27
SG::DataStore::proxy
virtual DataProxy * proxy(const TransientAddress *tAddr) const override
return proxy for a given type/key pair if key is empty returns the default proxy (currently last regi...
Definition: Control/SGTools/src/DataStore.cxx:415
index
Definition: index.py:1
SG::DataStore::m_t2p
T2pMap m_t2p
Definition: Control/SGTools/SGTools/DataStore.h:194
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
IProxyRegistry.h
SG::DataStore::constProxyRange
std::pair< SG::ConstProxyIterator, SG::ConstProxyIterator > constProxyRange
Definition: Control/SGTools/SGTools/DataStore.h:83
SG::DataStore::addAlias
virtual StatusCode addAlias(const std::string &aliasKey, DataProxy *proxy) override
add alias to store
Definition: Control/SGTools/src/DataStore.cxx:378
pool
pool namespace
Definition: libname.h:15
SG::DataStore::m_keyMap
KeyMap_t m_keyMap
Definition: Control/SGTools/SGTools/DataStore.h:187
SG::DataStore::m_storeMap
StoreMap m_storeMap
Maps locating proxies by clid/key.
Definition: Control/SGTools/SGTools/DataStore.h:183
SG::TransientAddress
Definition: TransientAddress.h:34
SG::DataStore::ConstStoreIterator
StoreMap::const_iterator ConstStoreIterator
Definition: Control/SGTools/SGTools/DataStore.h:81
SG::DataStore::clearStore
void clearStore(bool force, bool hard, MsgStream *pmlog)
If HARD is true, then the bound objects should also clear any data that depends on the identity of th...
Definition: Control/SGTools/src/DataStore.cxx:67
IStringPool::sgkey_t
SG::sgkey_t sgkey_t
Type of the keys.
Definition: IStringPool.h:34
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SG::DataStore::setStoreID
void setStoreID(StoreID::type id)
Definition: Control/SGTools/SGTools/DataStore.h:92
ProxyMap.h
SG::DataStore::KeyMap_t
ConcurrentSGKeyMap< DataProxy * > KeyMap_t
Map of hashed sgkey -> DataProxy.
Definition: Control/SGTools/SGTools/DataStore.h:186
SG::DataStore::removeFromKeyMap
StatusCode removeFromKeyMap(DataProxy *proxy)
Remove a proxy from m_keyMap.
Definition: Control/SGTools/src/DataStore.cxx:236
SG::DataStore::doAudit
bool doAudit()
Definition: Control/SGTools/SGTools/DataStore.h:199
SG::DataStore::StoreIterator
StoreMap::iterator StoreIterator
Definition: Control/SGTools/SGTools/DataStore.h:80
SG::DataStore::setSGAudSvc
void setSGAudSvc()
Definition: Control/SGTools/src/DataStore.cxx:53
IPageAccessControlSvc
Interface to a service that monitors memory page accesses.
Definition: IPageAccessControlSvc.h:19
SG::DataStore::StoreMap
std::map< CLID, SG::ProxyMap > StoreMap
Definition: Control/SGTools/SGTools/DataStore.h:79
SG::DataStore::m_proxies
std::vector< DataProxy * > m_proxies
All proxies managed by this store.
Definition: Control/SGTools/SGTools/DataStore.h:180
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SG::DataStore::findDummy
DataProxy * findDummy(CLID id, const std::string &key)
Look for (and convert) a matching dummy proxy.
Definition: Control/SGTools/src/DataStore.cxx:506
SG::DataStore::m_pool
IProxyDict & m_pool
The string pool associated with this store.
Definition: Control/SGTools/SGTools/DataStore.h:176
SG::DataStore::m_pSGAudSvc
SmartIF< ISGAudSvc > m_pSGAudSvc
Definition: Control/SGTools/SGTools/DataStore.h:197
DataProxy
DataProxy provides the registry services for StoreGate.
Definition: DataProxy.h:32
SG::DataStore::m_pSvcLoc
ISvcLocator * m_pSvcLoc
Definition: Control/SGTools/SGTools/DataStore.h:204
SG::DataStore::addSymLink
StatusCode addSymLink(const CLID &linkid, DataProxy *proxy)
add symlink to store:
Definition: Control/SGTools/src/DataStore.cxx:331
SG::DataStore::sgkey_t
IStringPool::sgkey_t sgkey_t
Definition: Control/SGTools/SGTools/DataStore.h:78
hist_file_dump.f
f
Definition: hist_file_dump.py:140
SG::DEFAULTKEY
const std::string DEFAULTKEY
Definition: DefaultKey.h:12
SG::ConcurrentSGKeyMap
CxxUtils::ConcurrentMap< sgkey_t, T, CxxUtils::SimpleUpdater, SGKeyHash, SGKeyEqual, 0, s_sgkey_nullval > ConcurrentSGKeyMap
A concurrent map using sgkey_t as key.
Definition: sgkey_utilities.h:33
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
sgkey_utilities.h
Additional utilities and types related to sgkey_t.
SG::DataStore::pacReport
std::vector< const DataProxy * > pacReport() const
request an access control report, i.e. a list of proxies that have not been accessed since monitored
Definition: Control/SGTools/SGTools/DataStore.h:156
SG::DataStore::storeID
virtual StoreID::type storeID() const override
Definition: Control/SGTools/SGTools/DataStore.h:93
IProxyDict.h
SG::DataStore::removeProxyImpl
StatusCode removeProxyImpl(DataProxy *proxy, int index)
Helper for removing a proxy.
Definition: Control/SGTools/src/DataStore.cxx:264
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
ISGAudSvc
Definition: ISGAudSvc.h:17
SG::DataStore::keys
void keys(const CLID &id, std::vector< std::string > &vkeys, bool includeAlias, bool onlyValid)
Definition: Control/SGTools/src/DataStore.cxx:120
SG::DataStore::setSvcLoc
StatusCode setSvcLoc()
Definition: Control/SGTools/src/DataStore.cxx:46
SG::sgkey_t
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition: CxxUtils/CxxUtils/sgkey_t.h:32
SG::DataStore::locatePersistent
DataProxy * locatePersistent(const void *const pTransient) const
locate the persistent (proxy) for a given T* (void*):
Definition: Control/SGTools/src/DataStore.cxx:607
SG::DataStore::m_storeID
StoreID::type m_storeID
Definition: Control/SGTools/SGTools/DataStore.h:189
SG::DataStore::setPac
void setPac(IPageAccessControlSvc *pac)
set IPageAccessControlSvc ptr in T2PMap
Definition: Control/SGTools/SGTools/DataStore.h:154
SG::DataStore::addToStore
virtual StatusCode addToStore(const CLID &id, DataProxy *proxy) override
add proxy to store.
Definition: Control/SGTools/src/DataStore.cxx:141
SG::DataStore::proxy_exact
virtual SG::DataProxy * proxy_exact(sgkey_t sgkey) const override
get proxy with given key.
Definition: Control/SGTools/src/DataStore.cxx:525
sgkey_t.h
Define the type used for hashed StoreGate key+CLID pairs.
StoreID::type
type
Definition: StoreID.h:24
SG::DataStore
Hold DataProxy instances associated with a store.
Definition: Control/SGTools/SGTools/DataStore.h:74
SG::DataStore::proxies
const std::vector< DataProxy * > & proxies() const
All proxies managed by this store.
Definition: Control/SGTools/src/DataStore.cxx:628
SG::DataStore::DataStore
DataStore(IProxyDict &pool)
Constructor.
Definition: Control/SGTools/src/DataStore.cxx:30
SG::DataStore::t2pRemove
void t2pRemove(const void *const pTrans)
Definition: Control/SGTools/SGTools/DataStore.h:249
SG::DataStore::pRange
StatusCode pRange(const CLID &id, SG::ConstProxyIterator &f, SG::ConstProxyIterator &e) const
Return an iterator over proxy for a given CLID:
Definition: Control/SGTools/src/DataStore.cxx:575
SG::T2pMap::t2pRemove
void t2pRemove(const void *const pTrans)
Definition: T2pMap.h:59
SG::DataStore::removeProxy
StatusCode removeProxy(DataProxy *proxy, bool forceRemove, bool hard)
remove proxy from store, unless proxy is reset only.
Definition: Control/SGTools/src/DataStore.cxx:198
DefaultKey.h
SG::T2pMap::pacReport
std::vector< const DataProxy * > pacReport() const
request an access control report, i.e. a list of proxies that have not been accessed since under cont...
Definition: T2pMap.cxx:7
SG::DataProxy
Definition: DataProxy.h:45
SG::T2pMap
Definition: T2pMap.h:21
SG::DataStore::tRange
StatusCode tRange(ConstStoreIterator &f, ConstStoreIterator &e) const
Return an iterator over the StoreMap:
Definition: Control/SGTools/src/DataStore.cxx:597
SG::DataStore::proxy_exact_unlocked
SG::DataProxy * proxy_exact_unlocked(sgkey_t sgkey, std::recursive_mutex &mutex) const
Like proxy_exact, but intended to be called without holding the store lock.
Definition: Control/SGTools/src/DataStore.cxx:544
SG::DataStore::m_noAudSvc
bool m_noAudSvc
Definition: Control/SGTools/SGTools/DataStore.h:198
SG::ConstProxyIterator
ProxyMap::const_iterator ConstProxyIterator
Definition: ProxyMap.h:28
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
T2pMap.h