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:
54 virtual std::vector<const SG::DataProxy*> proxies() const override;
55 virtual const std::string* keyToString (sgkey_t /*key*/) const override;
56 virtual void registerKey (sgkey_t /*key*/,
57 const std::string& /*str*/,
58 CLID /*clid*/) override;
59
60
61 // These have dummy implementations.
62 virtual const std::string& name() const override;
63 virtual SG::DataProxy* proxy(const void* const pTransient) const override;
64 virtual SG::DataProxy* proxy(const CLID& id, const std::string& key) const override;
65 virtual SG::DataProxy* proxy_exact (SG::sgkey_t sgkey) const override;
66 virtual sgkey_t stringToKey (const std::string& str, CLID clid) override;
67 virtual const std::string* keyToString (sgkey_t key, CLID& clid) const override;
68 virtual bool tryELRemap (sgkey_t sgkey_in, size_t index_in,
69 sgkey_t& sgkey_out, size_t& index_out) override;
70 virtual StatusCode addToStore (CLID /*id*/, SG::DataProxy* proxy) override;
71 virtual void boundHandle (IResetable* handle) override;
72 virtual void unboundHandle (IResetable* handle) override;
73
75 const std::string& key,
76 bool allowMods,
77 bool returnExisting) override;
78
79
80 template <class T>
81 void record (const T* p, const std::string& key)
82 {
83 lock_t lock (m_mutex);
84 T* p_nc ATLAS_THREAD_SAFE = const_cast<T*>(p);
85 DataObject* obj = SG::asStorable<T>(p_nc);
87 record1 (lock, p, obj, clid, key);
88 }
89
90
91 template <class T>
92 void record (std::unique_ptr<T> up, const std::string& key)
93 {
94 lock_t lock (m_mutex);
95 T* p = up.get();
96 DataObject* obj = SG::asStorable<T>(std::move (up));
98 record1 (lock, p, obj, clid, key);
99 }
100
101
102 void remap (sgkey_t sgkey_in, sgkey_t sgkey_out,
103 size_t index_in = 0, size_t index_out = 0);
104
105
106 template <class T>
107 void remap (const std::string& key_in, const std::string& key_out,
108 size_t index_in = 0, size_t index_out = 0)
109 {
111 sgkey_t sgkey_in = stringToKey (key_in, clid);
112 sgkey_t sgkey_out = stringToKey (key_out, clid);
113 remap (sgkey_in, sgkey_out, index_in, index_out);
114 }
115
116 void alias (SG::DataProxy* proxy, const std::string& newKey);
117
118 typedef std::unordered_map<const void*, SG::DataProxy*> tmap_t;
120
123
124 typedef std::unordered_map<TestStoreRemap, TestStoreRemap, TestStoreRemapHash> remap_t;
126
127 mutable SG::StringPool m_stringPool ATLAS_THREAD_SAFE;
128
129 std::vector<IResetable*> m_boundHandles;
130
131 // Log failed calls to proxy(CLID, std::string).
132 mutable std::vector<std::pair<CLID, std::string> > m_missedProxies ATLAS_THREAD_SAFE;
133
134 typedef std::mutex mutex_t;
135 typedef std::lock_guard<mutex_t> lock_t;
137
138 SG::DataProxy* proxy(lock_t&, const void* const pTransient) const;
139 SG::DataProxy* proxy(lock_t&, const CLID& id, const std::string& key) const;
140 SG::DataProxy* record1 (lock_t&, const void* p, DataObject* obj,
141 CLID clid, const std::string& key);
142};
143
144
145// Initialize the global, static test store.
146extern TestStore store;
147void initTestStore ATLAS_NOT_THREAD_SAFE ();
148
149
150// Create a new test store and install it.
151std::unique_ptr<TestStore> getTestStore();
152
153
154} // namespace SGTest
155
156
157#endif // not SGTOOLS_TESTSTORE_H
uint32_t CLID
The Class ID type.
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:118
virtual void boundHandle(IResetable *handle) override
std::vector< IResetable * > m_boundHandles
Definition TestStore.h:129
SG::SGKeyMap< SG::DataProxy * > kmap_t
Definition TestStore.h:121
virtual const std::string * keyToString(sgkey_t) const override
Definition TestStore.cxx:32
virtual void registerKey(sgkey_t, const std::string &, CLID) override
Definition TestStore.cxx:38
virtual SG::DataProxy * recordObject(SG::DataObjectSharedPtr< DataObject > obj, const std::string &key, bool allowMods, bool returnExisting) override
Definition TestStore.cxx:46
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
std::mutex mutex_t
Definition TestStore.h:134
void record(std::unique_ptr< T > up, const std::string &key)
Definition TestStore.h:92
void record(const T *p, const std::string &key)
Definition TestStore.h:81
void alias(SG::DataProxy *proxy, const std::string &newKey)
virtual const std::string & name() const override
Definition TestStore.cxx:97
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:107
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:124
virtual std::vector< const SG::DataProxy * > proxies() const override
Definition TestStore.cxx:26
virtual void unboundHandle(IResetable *handle) override
SG::StringPool m_stringPool ATLAS_THREAD_SAFE
Definition TestStore.h:127
virtual StatusCode addToStore(CLID, SG::DataProxy *proxy) override
std::lock_guard< mutex_t > lock_t
Definition TestStore.h:135
std::map< std::string, std::string > remap
list of directories to be explicitly remapped
Definition hcg.cxx:95
TestStore store
Definition TestStore.cxx:23
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