ATLAS Offline Software
Control/SGTools/SGTools/DataStore.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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/StatusCode.h"
22 
23 #include <exception>
24 #include <list>
25 #include <vector>
26 #include <map>
27 #include <string>
28 #include <typeinfo> /*typeid*/
29 #include <utility> /*std::pair*/
30 #include <unordered_map>
31 #include <mutex>
32 
33 
34 class ISvcLocator;
35 class ISGAudSvc;
36 class MsgStream;
38 
39 namespace SG {
40 
41  class DataProxy;
42 
43 
72  class DataStore : virtual public IProxyRegistry
73  {
74 
75  public:
76 
78  typedef std::map<CLID, SG::ProxyMap> StoreMap;
80  typedef StoreMap::const_iterator ConstStoreIterator;
81 
82  typedef std::pair<SG::ConstProxyIterator, SG::ConstProxyIterator> constProxyRange;
83 
89  virtual ~DataStore();
90 
92  virtual StoreID::type storeID() const { return m_storeID; }
93 
94  // If FORCE is true, then force deleting of all proxies,
95  // even if they would normally only be reset.
99  void clearStore(bool force, bool hard, MsgStream* pmlog);
100 
103 
104  virtual StatusCode addToStore(const CLID& id, DataProxy* proxy);
107  virtual DataProxy* proxy(const TransientAddress* tAddr) const;
109  virtual DataProxy* proxy(const CLID& id,
110  const std::string& key=SG::DEFAULTKEY) const;
111 
115 
121  std::recursive_mutex& mutex) const;
122 
125  virtual SG::DataProxy* proxy_exact(const CLID& id,
126  const std::string& key) const;
127 
133  StatusCode removeProxy(DataProxy* proxy, bool forceRemove, bool hard);
134 
136  StatusCode addSymLink(const CLID& linkid, DataProxy* proxy);
137 
139  StatusCode addAlias(const std::string& aliasKey, DataProxy* proxy);
140 
142  int typeCount(const CLID& id) const;
143 
146 
149  SG::ConstProxyIterator& e) const;
150 
151 
155  std::vector<const DataProxy*> pacReport() const { return m_t2p.pacReport();}
156 
158  StatusCode t2pRegister(const void* const pTrans, DataProxy* const pPers);
159  void t2pRemove(const void* const pTrans);
160 
162  DataProxy* locatePersistent(const void* const pTransient) const;
163 
164  // return list of keys associated with an object
165  void keys(const CLID& id, std::vector<std::string>& vkeys,
166  bool includeAlias, bool onlyValid);
167 
170  const std::vector<DataProxy*>& proxies() const;
171 
172 
173  private:
176 
179  std::vector<DataProxy*> m_proxies;
180 
183 
185  using KeyMap_t = CxxUtils::ConcurrentMap<
186  sgkey_t, DataProxy*,
189  0,
190  static_cast<CxxUtils::detail::ConcurrentHashmapVal_t> (-1)>;
192 
194 
195  // Map to hold the relation between transient and persistent object:
196  // we have changed to DataProxy as it is faster while recording
197  // to check if it already exists
199 
200  void setSGAudSvc();
202  bool m_noAudSvc;
203  inline bool doAudit() {
204  if (!m_noAudSvc) setSGAudSvc();
205  return (m_pSGAudSvc);
206  }
207 
208  ISvcLocator* m_pSvcLoc;
210 
211 
230  DataProxy* findDummy (CLID id, const std::string& key);
231 
232 
238 
239 
248  StatusCode
250  };
252  inline void
253  DataStore::t2pRemove(const void* const pTrans)
254  {
255  m_t2p.t2pRemove(pTrans);
256  }
258 } //end namespace SG
259 
260 
261 #endif // STOREGATE_DATASTORE
262 
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
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
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
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:198
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:82
SG::DataStore::m_pSGAudSvc
ISGAudSvc * m_pSGAudSvc
Definition: Control/SGTools/SGTools/DataStore.h:201
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:191
SG::DataStore::m_storeMap
StoreMap m_storeMap
Maps locating proxies by clid/key.
Definition: Control/SGTools/SGTools/DataStore.h:182
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:80
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:51
SG::DataStore::setStoreID
void setStoreID(StoreID::type id)
Definition: Control/SGTools/SGTools/DataStore.h:91
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:203
SG::DataStore::StoreIterator
StoreMap::iterator StoreIterator
Definition: Control/SGTools/SGTools/DataStore.h:79
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:30
SG::DataStore::StoreMap
std::map< CLID, SG::ProxyMap > StoreMap
Definition: Control/SGTools/SGTools/DataStore.h:78
SG::DataStore::m_proxies
std::vector< DataProxy * > m_proxies
All proxies managed by this store.
Definition: Control/SGTools/SGTools/DataStore.h:179
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:175
DataProxy
DataProxy provides the registry services for StoreGate.
Definition: DataProxy.h:31
SG::DataStore::m_pSvcLoc
ISvcLocator * m_pSvcLoc
Definition: Control/SGTools/SGTools/DataStore.h:208
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:77
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:155
IProxyDict.h
SG::DataStore::storeID
virtual StoreID::type storeID() const
Definition: Control/SGTools/SGTools/DataStore.h:92
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:191
SG::DataStore::KeyMap_t
CxxUtils::ConcurrentMap< sgkey_t, DataProxy *, CxxUtils::SimpleUpdater, SGKeyHash, SGKeyEqual, 0, static_cast< CxxUtils::detail::ConcurrentHashmapVal_t >(-1)> KeyMap_t
Map of hashed sgkey -> DataProxy.
Definition: Control/SGTools/SGTools/DataStore.h:190
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:193
SG::DataStore::setPac
void setPac(IPageAccessControlSvc *pac)
set IPageAccessControlSvc ptr in T2PMap
Definition: Control/SGTools/SGTools/DataStore.h:153
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
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:73
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:253
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:44
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:202
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