ATLAS Offline Software
Loading...
Searching...
No Matches
TestStore.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 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4*/
11
12
13#ifndef SGTOOLS_TESTSTORE_H
14#define SGTOOLS_TESTSTORE_H
15
16
18#include "SGTools/StringPool.h"
19#include "SGTools/DataProxy.h"
22#include <unordered_map>
23#include <mutex>
24
25
26namespace SGTest {
27
28
30
31
33{
34 TestStoreRemap (SG::sgkey_t the_key=0, size_t the_index = 0)
35 : key (the_key), index (the_index) {}
36 bool operator== (const TestStoreRemap& other) const
37 { return other.key == key && other.index == index; }
39 size_t index;
40};
41
42
44{
45 size_t operator() (const TestStoreRemap& m) const
46 { return m.key + m.index; }
47};
48
49
51 : public implements<IProxyDict>
52{
53public:
55 virtual StoreID::type storeID() const override;
56 virtual std::vector<const SG::DataProxy*> proxies() const override;
57 virtual const std::string* keyToString (sgkey_t /*key*/) const override;
58 virtual void registerKey (sgkey_t /*key*/,
59 const std::string& /*str*/,
60 CLID /*clid*/) override;
61
62
63 // These have dummy implementations.
64 virtual const std::string& name() const override;
65 virtual SG::DataProxy* proxy(const void* const pTransient) const override;
66 virtual SG::DataProxy* proxy(const CLID& id, const std::string& key) const override;
67 virtual SG::DataProxy* proxy_exact (SG::sgkey_t sgkey) const override;
68 virtual sgkey_t stringToKey (const std::string& str, CLID clid) override;
69 virtual const std::string* keyToString (sgkey_t key, CLID& clid) const override;
70 virtual bool tryELRemap (sgkey_t sgkey_in, size_t index_in,
71 sgkey_t& sgkey_out, size_t& index_out) override;
72 virtual StatusCode addToStore (CLID /*id*/, SG::DataProxy* proxy) override;
73 virtual void boundHandle (IResetable* handle) override;
74 virtual void unboundHandle (IResetable* handle) override;
75
77 const std::string& key,
78 bool allowMods,
79 bool returnExisting) override;
80
81
82 template <class T>
83 void record (const T* p, const std::string& key)
84 {
86 T* p_nc ATLAS_THREAD_SAFE = const_cast<T*>(p);
87 DataObject* obj = SG::asStorable<T>(p_nc);
89 record1 (lock, p, obj, clid, key);
90 }
91
92
93 template <class T>
94 void record (std::unique_ptr<T> up, const std::string& key)
95 {
97 T* p = up.get();
98 DataObject* obj = SG::asStorable<T>(std::move (up));
100 record1 (lock, p, obj, clid, key);
101 }
102
103
104 void remap (sgkey_t sgkey_in, sgkey_t sgkey_out,
105 size_t index_in = 0, size_t index_out = 0);
106
107
108 template <class T>
109 void remap (const std::string& key_in, const std::string& key_out,
110 size_t index_in = 0, size_t index_out = 0)
111 {
113 sgkey_t sgkey_in = stringToKey (key_in, clid);
114 sgkey_t sgkey_out = stringToKey (key_out, clid);
115 remap (sgkey_in, sgkey_out, index_in, index_out);
116 }
117
118 void alias (SG::DataProxy* proxy, const std::string& newKey);
119
120 typedef std::unordered_map<const void*, SG::DataProxy*> tmap_t;
122
125
126 typedef std::unordered_map<TestStoreRemap, TestStoreRemap, TestStoreRemapHash> remap_t;
128
129 mutable SG::StringPool m_stringPool ATLAS_THREAD_SAFE;
130
131 std::vector<IResetable*> m_boundHandles;
132
133 // Log failed calls to proxy(CLID, std::string).
134 mutable std::vector<std::pair<CLID, std::string> > m_missedProxies ATLAS_THREAD_SAFE;
135
136 typedef std::mutex mutex_t;
137 typedef std::lock_guard<mutex_t> lock_t;
139
141
142 SG::DataProxy* proxy(lock_t&, const void* const pTransient) const;
143 SG::DataProxy* proxy(lock_t&, const CLID& id, const std::string& key) const;
144 SG::DataProxy* record1 (lock_t&, const void* p, DataObject* obj,
145 CLID clid, const std::string& key);
146};
147
148
149// Initialize the global, static test store.
150extern TestStore store;
151void initTestStore ATLAS_NOT_THREAD_SAFE ();
152
153
154// Create a new test store and install it.
155std::unique_ptr<TestStore> getTestStore();
156
157
158} // namespace SGTest
159
160
161#endif // not SGTOOLS_TESTSTORE_H
uint32_t CLID
The Class ID type.
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
Hold a pointer to the current event store.
Maintain a mapping of strings to 64-bit ints.
Define macros for attributes used to control the static checker.
a resetable object (e.g.
Definition IResetable.h:15
std::unordered_map< const void *, SG::DataProxy * > tmap_t
Definition TestStore.h:120
virtual void boundHandle(IResetable *handle) override
std::vector< IResetable * > m_boundHandles
Definition TestStore.h:131
SG::SGKeyMap< SG::DataProxy * > kmap_t
Definition TestStore.h:123
virtual const std::string * keyToString(sgkey_t) const override
Definition TestStore.cxx:43
virtual void registerKey(sgkey_t, const std::string &, CLID) override
Definition TestStore.cxx:49
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Definition TestStore.cxx:57
virtual bool tryELRemap(sgkey_t sgkey_in, size_t index_in, sgkey_t &sgkey_out, size_t &index_out) override
virtual sgkey_t stringToKey(const std::string &str, CLID clid) override
StoreID::type m_id
Definition TestStore.h:140
virtual StoreID::type storeID() const override
Definition TestStore.cxx:31
std::mutex mutex_t
Definition TestStore.h:136
void record(std::unique_ptr< T > up, const std::string &key)
Definition TestStore.h:94
void record(const T *p, const std::string &key)
Definition TestStore.h:83
void alias(SG::DataProxy *proxy, const std::string &newKey)
virtual const std::string & name() const override
virtual SG::DataProxy * proxy(const void *const pTransient) const override
void remap(const std::string &key_in, const std::string &key_out, size_t index_in=0, size_t index_out=0)
Definition TestStore.h:109
SG::DataProxy * record1(lock_t &, const void *p, DataObject *obj, CLID clid, const std::string &key)
virtual SG::DataProxy * proxy_exact(SG::sgkey_t sgkey) const override
std::unordered_map< TestStoreRemap, TestStoreRemap, TestStoreRemapHash > remap_t
Definition TestStore.h:126
virtual std::vector< const SG::DataProxy * > proxies() const override
Definition TestStore.cxx:37
virtual void unboundHandle(IResetable *handle) override
TestStore(StoreID::type id=StoreID::EVENT_STORE)
Definition TestStore.cxx:25
SG::StringPool m_stringPool ATLAS_THREAD_SAFE
Definition TestStore.h:129
virtual StatusCode addToStore(CLID, SG::DataProxy *proxy) override
std::lock_guard< mutex_t > lock_t
Definition TestStore.h:137
@ EVENT_STORE
Definition StoreID.h:26
std::map< std::string, std::string > remap
list of directories to be explicitly remapped
Definition hcg.cxx:97
TestStore store
Definition TestStore.cxx:22
void initTestStore ATLAS_NOT_THREAD_SAFE()
std::unique_ptr< TestStore > getTestStore()
SG::sgkey_t sgkey_t
Definition TestStore.h:29
CxxUtils::RefCountedPtr< T > DataObjectSharedPtr
uint32_t sgkey_t
Type used for hashed StoreGate key+CLID pairs.
Definition sgkey_t.h:32
DataObject * asStorable(SG::DataObjectSharedPtr< T > pObject)
std::unordered_map< sgkey_t, T > SGKeyMap
A map using sgkey_t as a key.
Definition sgkey_t.h:93
Definition index.py:1
size_t operator()(const TestStoreRemap &m) const
Definition TestStore.h:45
TestStoreRemap(SG::sgkey_t the_key=0, size_t the_index=0)
Definition TestStore.h:34
bool operator==(const TestStoreRemap &other) const
Definition TestStore.h:36