ATLAS Offline Software
Control/SGTools/SGTools/DataStore.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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/ConcurrentMap.h"
19 #include "CxxUtils/SimpleUpdater.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 : virtual 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 { 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);
108  virtual DataProxy* proxy(const TransientAddress* tAddr) const;
110  virtual DataProxy* proxy(const CLID& id,
111  const std::string& key=SG::DEFAULTKEY) const;
112 
116 
122  std::recursive_mutex& mutex) const;
123 
126  virtual SG::DataProxy* proxy_exact(const CLID& id,
127  const std::string& key) const;
128 
134  StatusCode removeProxy(DataProxy* proxy, bool forceRemove, bool hard);
135 
137  StatusCode addSymLink(const CLID& linkid, DataProxy* proxy);
138 
140  StatusCode addAlias(const std::string& aliasKey, DataProxy* proxy);
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 
186  // Separating this avoids a cppcheck 2.14 syntax error.
189  using KeyMap_t = CxxUtils::ConcurrentMap<
190  sgkey_t, DataProxy*,
193  0, s_nullval>;
195 
197 
198  // Map to hold the relation between transient and persistent object:
199  // we have changed to DataProxy as it is faster while recording
200  // to check if it already exists
202 
203  void setSGAudSvc();
204  SmartIF<ISGAudSvc> m_pSGAudSvc;
205  bool m_noAudSvc;
206  inline bool doAudit() {
207  if (!m_noAudSvc) setSGAudSvc();
208  return (m_pSGAudSvc);
209  }
210 
211  ISvcLocator* m_pSvcLoc;
213 
214 
233  DataProxy* findDummy (CLID id, const std::string& key);
234 
235 
241 
242 
251  StatusCode
253  };
255  inline void
256  DataStore::t2pRemove(const void* const pTrans)
257  {
258  m_t2p.t2pRemove(pTrans);
259  }
261 } //end namespace SG
262 
263 
264 #endif // STOREGATE_DATASTORE
265 
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
CxxUtils::SimpleUpdater
Simple (non-deleting) Updater implementation.
Definition: SimpleUpdater.h: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:405
common.sgkey
def sgkey(tool)
Definition: common.py:1028
SG::DataStore::s_nullval
static constexpr CxxUtils::detail::ConcurrentHashmapVal_t s_nullval
Map of hashed sgkey -> DataProxy.
Definition: Control/SGTools/SGTools/DataStore.h:187
SG::DataStore::t2pRegister
StatusCode t2pRegister(const void *const pTrans, DataProxy *const pPers)
methods to query the T2PMap:
Definition: Control/SGTools/src/DataStore.cxx:613
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
SG::DataStore::~DataStore
virtual ~DataStore()
Definition: Control/SGTools/src/DataStore.cxx:42
calibdata.force
bool force
Definition: calibdata.py:19
IProxyRegistry
a proxy registry (a read/write dictionary)
Definition: IProxyRegistry.h:27
CxxUtils::detail::ConcurrentHashmapVal_t
uintptr_t ConcurrentHashmapVal_t
Type used for keys and values — an unsigned big enough to hold a pointer.
Definition: ConcurrentHashmapImpl.h:41
index
Definition: index.py:1
SG::DataStore::m_t2p
T2pMap m_t2p
Definition: Control/SGTools/SGTools/DataStore.h:201
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
ConcurrentMap.h
Hash map from integers/pointers allowing concurrent, lockless reads.
pool
pool namespace
Definition: libname.h:15
SG::DataStore::m_keyMap
KeyMap_t m_keyMap
Definition: Control/SGTools/SGTools/DataStore.h:194
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:32
SG::DataStore::addToStore
virtual StatusCode addToStore(const CLID &id, DataProxy *proxy)
add proxy to store.
Definition: Control/SGTools/src/DataStore.cxx:139
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:68
SG::SGKeyHash
Hash functional for sgkey_t.
Definition: CxxUtils/CxxUtils/sgkey_t.h:59
IStringPool::sgkey_t
SG::sgkey_t sgkey_t
Type of the keys.
Definition: IStringPool.h:34
SG::DataStore::proxy
virtual DataProxy * proxy(const TransientAddress *tAddr) const
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:414
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::removeFromKeyMap
StatusCode removeFromKeyMap(DataProxy *proxy)
Remove a proxy from m_keyMap.
Definition: Control/SGTools/src/DataStore.cxx:234
SG::DataStore::doAudit
bool doAudit()
Definition: Control/SGTools/SGTools/DataStore.h:206
SG::DataStore::StoreIterator
StoreMap::iterator StoreIterator
Definition: Control/SGTools/SGTools/DataStore.h:80
SG::DataStore::proxy_exact
SG::DataProxy * proxy_exact(sgkey_t sgkey) const
get proxy with given key.
Definition: Control/SGTools/src/DataStore.cxx:524
SG::DataStore::setSGAudSvc
void setSGAudSvc()
Definition: Control/SGTools/src/DataStore.cxx:54
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:505
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:204
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:211
SG::DataStore::addSymLink
StatusCode addSymLink(const CLID &linkid, DataProxy *proxy)
add symlink to store:
Definition: Control/SGTools/src/DataStore.cxx:330
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:135
SG::DEFAULTKEY
const std::string DEFAULTKEY
Definition: DefaultKey.h:12
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
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
IProxyDict.h
SG::DataStore::storeID
virtual StoreID::type storeID() const
Definition: Control/SGTools/SGTools/DataStore.h:93
SG::DataStore::removeProxyImpl
StatusCode removeProxyImpl(DataProxy *proxy, int index)
Helper for removing a proxy.
Definition: Control/SGTools/src/DataStore.cxx:262
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
ISGAudSvc
Definition: ISGAudSvc.h:21
SG::DataStore::keys
void keys(const CLID &id, std::vector< std::string > &vkeys, bool includeAlias, bool onlyValid)
Definition: Control/SGTools/src/DataStore.cxx:118
SG::DataStore::setSvcLoc
StatusCode setSvcLoc()
Definition: Control/SGTools/src/DataStore.cxx:47
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:606
SG::DataStore::m_storeID
StoreID::type m_storeID
Definition: Control/SGTools/SGTools/DataStore.h:196
SG::DataStore::setPac
void setPac(IPageAccessControlSvc *pac)
set IPageAccessControlSvc ptr in T2PMap
Definition: Control/SGTools/SGTools/DataStore.h:154
SimpleUpdater.h
Simple (non-deleting) Updater implementation.
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:627
SG::DataStore::addAlias
StatusCode addAlias(const std::string &aliasKey, DataProxy *proxy)
add alias to store
Definition: Control/SGTools/src/DataStore.cxx:377
SG::DataStore::DataStore
DataStore(IProxyDict &pool)
Constructor.
Definition: Control/SGTools/src/DataStore.cxx:31
SG::DataStore::t2pRemove
void t2pRemove(const void *const pTrans)
Definition: Control/SGTools/SGTools/DataStore.h:256
SG::DataStore::KeyMap_t
CxxUtils::ConcurrentMap< sgkey_t, DataProxy *, CxxUtils::SimpleUpdater, SGKeyHash, SGKeyEqual, 0, s_nullval > KeyMap_t
Definition: Control/SGTools/SGTools/DataStore.h:193
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:574
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:196
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:596
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:543
SG::DataStore::m_noAudSvc
bool m_noAudSvc
Definition: Control/SGTools/SGTools/DataStore.h:205
SG::ConstProxyIterator
ProxyMap::const_iterator ConstProxyIterator
Definition: ProxyMap.h:28
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
SG::SGKeyEqual
Comparison functional for sgkey_t.
Definition: CxxUtils/CxxUtils/sgkey_t.h:72
T2pMap.h