ATLAS Offline Software
Loading...
Searching...
No Matches
TransientAddress.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 SGTOOLS_TRANSIENTADDRESS_H
6#define SGTOOLS_TRANSIENTADDRESS_H
7
9#include <string>
10#include <set>
11#include <vector>
12#include <algorithm>
13#include <atomic>
14
15
22#include "GaudiKernel/ClassID.h"
23#include "GaudiKernel/IOpaqueAddress.h"
24
26class IOpaqueAddress;
28class IProxyDict;
29class EventContext;
30
31namespace SG {
32
34 {
35
36 public:
37
40 typedef std::vector<CLID> TransientClidSet;
41
42 typedef std::vector<std::string> TransientAliasSet;
44
47
49 TransientAddress(CLID id, const std::string& key);
50
52 TransientAddress(CLID id, const std::string& key,
54 bool clearAddress = true);
55
58 TransientAddress(CLID id, const std::string& key,
60 const std::vector<CLID>& clids);
61
64
67
70
73 void setID (CLID id, const std::string& key);
74
76 void reset();
77
79 // Can't change the signature here to satisfy the thread-safety
80 // checker as this should match the signature in the Gaudi IRegistry.
81 IOpaqueAddress* address ATLAS_NOT_CONST_THREAD_SAFE () const;
82
85
87 CLID clID() const;
88
90 const std::string& name() const;
91
93 sgkey_t sgkey() const;
94
96 void setSGKey (sgkey_t sgkey);
97
99 bool transientID (CLID id) const;
100
102 void setTransientID(CLID id);
103
105 const TransientClidSet& transientID() const;
106
108 void setAlias(const std::string& key);
109
111 void setAlias(const std::vector<std::string>& keys);
112
114 void setAlias(std::vector<std::string>&& keys);
115
117 bool removeAlias(const std::string& key);
118
120 bool hasAlias(const std::string& key) const;
121
123 const TransientAliasSet& alias() const;
124
126 void clearAddress(const bool& flag);
127
129 bool clearAddress() const;
130
133 void consultProvider(const bool& flag);
134
139 bool isValid (const EventContext* ctx, bool forceUpdate = false);
140
144 StoreID::type storeID() const;
146
147 private:
148 TransientAddress(CLID id, const std::string& key,
150 bool clearAddress,
151 bool consultProvider);
152
153
154 // PLEASE NOTE: The data members of this class are ordered so that
155 // the most frequently accessed members are grouped together, within
156 // the first cache line, when it is embedded in DataProxy. See the layout
157 // at the end of DataProxy.h.
158 // Be aware of this when making changes to the layout of this class.
159
160
162 std::atomic<CLID> m_clid;
163
165 std::atomic<sgkey_t> m_sgkey;
166
169
172
175
178
181
184
187
190
191 static const std::string s_emptyString;
192 };
193
194 // inlined code:
196
198 inline
199 IOpaqueAddress* TransientAddress::address ATLAS_NOT_CONST_THREAD_SAFE () const
200 {
201 IOpaqueAddress* addr ATLAS_THREAD_SAFE = const_cast<IOpaqueAddress*> (m_address.get());
202 return addr;
203 }
204
206 inline
208 {
209 return m_clid;
210 }
211
213 inline
214 const std::string& TransientAddress::name() const
215 {
216 // Most of the time, m_name is set when the TransientAddress is created
217 // and then never changed. To handle dummy proxies though, m_name
218 // can be created as blank and filled in later, but then never changed
219 // again. Used CachedValue to avoid having to use a lock for this.
220 if (m_name.isValid()) {
221 return *m_name.ptr();
222 }
223 return s_emptyString;
224 }
225
227 inline
232
234 inline
239
241 inline
243 {
244 return std::find (m_transientID.begin(), m_transientID.end(), id) !=
245 m_transientID.end();
246 }
247
249 inline
254
256 inline
257 void TransientAddress::setAlias(const std::string& key)
258 {
259 auto it = std::ranges::lower_bound (m_transientAlias, key);
260 if (it == m_transientAlias.end() || *it != key) {
261 m_transientAlias.insert (it, key);
262 }
263 }
264
266 inline
267 void TransientAddress::setAlias(const std::vector<std::string>& keys)
268 {
269 m_transientAlias = keys;
270 }
271
273 inline
274 void TransientAddress::setAlias(std::vector<std::string>&& keys)
275 {
276 m_transientAlias = std::move(keys);
277 }
278
280 inline bool TransientAddress::removeAlias(const std::string& key)
281 {
282 auto it = std::ranges::lower_bound (m_transientAlias, key);
283 if (it != m_transientAlias.end() && *it == key) {
284 m_transientAlias.erase (it);
285 return true;
286 }
287 return false;
288 }
289
291 inline bool TransientAddress::hasAlias(const std::string& key) const
292 {
293 return std::ranges::binary_search (m_transientAlias, key);
294 }
295
297 inline
302
304 inline
305 void TransientAddress::clearAddress(const bool& flag)
306 {
307 m_clearAddress = flag;
308 }
309
311 inline
313 {
314 return m_clearAddress;
315 }
316
317 inline
319 {
320 m_consultProvider = flag;
321 }
322
325 inline
330 inline
332 {
333 return m_storeID;
334 }
335
336 inline
344} //end namespace SG
345
346#endif // STOREGATE_TRANSIENTADDRESS
Cached value with atomic update.
uint32_t CLID
The Class ID type.
Abstract interface for looking up strings/CLIDs in a pool.
Simple smart pointer for Gaudi-style refcounted objects.
Define macros for attributes used to control the static checker.
#define ATLAS_THREAD_SAFE
Cached value with atomic update.
Definition CachedValue.h:55
Simple smart pointer for Gaudi-style refcounted objects.
interface for IOA providers
SG::sgkey_t sgkey_t
Type of the keys.
Definition IStringPool.h:34
IStringPool::sgkey_t sgkey_t
Default Constructor.
void reset()
Retrieve IOpaqueAddress.
sgkey_t sgkey() const
Set the primary (hashed) SG key.
TransientAddress()
Construct from clid and string key:
const TransientClidSet & transientID() const
set alias'
CLID clID() const
Retrieve string key:
IAddressProvider * m_pAddressProvider
string key of this object
StoreID::type storeID() const
void clearAddress(const bool &flag)
Return the clearAddress flag.
bool hasAlias(const std::string &key) const
get transient alias
const std::string & name() const
Get the primary (hashed) SG key.
std::atomic< sgkey_t > m_sgkey
Store type, needed by updateAddress.
bool isValid(const EventContext *ctx, bool forceUpdate=false)
cache the pointer to the Address provider which can update this transient address
void setTransientID(CLID id)
get transient CLID's
void setAlias(const std::string &key)
set alias'
CxxUtils::CachedValue< std::string > m_name
all transient clids. They come from symlinks
bool clearAddress() const
this sets the flag whether to consult the provider to update this transient address if the IOA is not...
bool removeAlias(const std::string &key)
remove alias from proxy
std::vector< CLID > TransientClidSet
Strictly a set, but there shouldn't be more than a handful of entries, so store it as a sorted vector...
bool m_consultProvider
IOpaqueAddress:
void setAddress(CxxUtils::RefCountedPtr< IOpaqueAddress > pAddress)
Retrieve primary clid.
static const std::string s_emptyString
void setSGKey(sgkey_t sgkey)
check if it is a transient ID (primary or symLinked):
IAddressProvider * provider()
TransientClidSet m_transientID
all alias names for a DataObject. They come from setAlias
std::vector< std::string > TransientAliasSet
TransientAddress & operator=(const TransientAddress &)
StoreID::type m_storeID
Controls if IOpaqueAddress should be deleted:
CxxUtils::RefCountedPtr< IOpaqueAddress > m_address
AddressProvider.
void setProvider(IAddressProvider *provider, StoreID::type storeID)
IOpaqueAddress *address ATLAS_NOT_CONST_THREAD_SAFE() const
set IOpaqueAddress
const TransientAliasSet & alias() const
set the clearAddress flag: IOA will not be deleted in proxy
bool m_clearAddress
Control whether the Address Provider must be consulted.
void consultProvider(const bool &flag)
Check the validity of the Transient Address.
void setID(CLID id, const std::string &key)
Set the CLID / key.
TransientAliasSet m_transientAlias
std::atomic< CLID > m_clid
< clid of the concrete class (persistent clid)
Forward declaration.
IOpaqueAddress *TransientAddress::address ATLAS_NOT_CONST_THREAD_SAFE() const
Retrieve IOpaqueAddress.