ATLAS Offline Software
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 
18 #include "AthenaKernel/StoreID.h"
19 #include "GaudiKernel/ClassID.h"
20 #include "CxxUtils/CachedValue.h"
22 
24 class IOpaqueAddress;
25 class IAddressProvider;
26 class IProxyDict;
27 class EventContext;
28 
29 namespace SG {
30 
32  {
33 
34  public:
35 
38  typedef std::vector<CLID> TransientClidSet;
39 
40  typedef std::vector<std::string> TransientAliasSet;
42 
45 
47  TransientAddress(CLID id, const std::string& key);
48 
50  TransientAddress(CLID id, const std::string& key,
51  IOpaqueAddress* addr, bool clearAddress = true);
52 
55  TransientAddress(CLID id, const std::string& key,
56  IOpaqueAddress* addr,
57  const std::vector<CLID>& clids);
58 
61 
64 
67 
70  void setID (CLID id, const std::string& key);
71 
73  void reset();
74 
76  // Can't change the signature here to satisfy the thread-safety
77  // checker as this should match the signature in the Gaudi IRegistry.
78  IOpaqueAddress* address ATLAS_NOT_CONST_THREAD_SAFE () const;
79 
81  void setAddress(IOpaqueAddress* pAddress);
82 
84  CLID clID() const;
85 
87  const std::string& name() const;
88 
90  sgkey_t sgkey() const;
91 
93  void setSGKey (sgkey_t sgkey);
94 
96  bool transientID (CLID id) const;
97 
99  void setTransientID(CLID id);
100 
102  const TransientClidSet& transientID() const;
103 
105  void setAlias(const std::string& key);
106 
108  void setAlias(const std::vector<std::string>& keys);
109 
111  void setAlias(std::vector<std::string>&& keys);
112 
114  bool removeAlias(const std::string& key);
115 
117  bool hasAlias(const std::string& key) const;
118 
120  const TransientAliasSet& alias() const;
121 
123  void clearAddress(const bool& flag);
124 
126  bool clearAddress() const;
127 
130  void consultProvider(const bool& flag);
131 
136  bool isValid (const EventContext* ctx, bool forceUpdate = false);
137 
141  StoreID::type storeID() const;
143 
144  private:
145  TransientAddress(CLID id, const std::string& key,
146  IOpaqueAddress* addr,
147  bool clearAddress,
148  bool consultProvider);
149 
150 
151  // PLEASE NOTE: The data members of this class are ordered so that
152  // the most frequently accessed members are grouped together, within
153  // the first cache line, when it is embedded in DataProxy. See the layout
154  // at the end of DataProxy.h.
155  // Be aware of this when making changes to the layout of this class.
156 
157 
159  std::atomic<CLID> m_clid;
160 
162  std::atomic<sgkey_t> m_sgkey;
163 
166 
169 
172 
174  IOpaqueAddress* m_address;
175 
178 
181 
184 
187 
188  static const std::string s_emptyString;
189  };
191  // inlined code:
193 
194  // Reset the TransientAddress
195  inline
197  {
198  if (m_clearAddress) setAddress(0);
199  }
200 
202  inline
204  {
205  return m_address;
206  }
207 
209  inline
211  {
212  return m_clid;
213  }
214 
216  inline
217  const std::string& TransientAddress::name() const
218  {
219  // Most of the time, m_name is set when the TransientAddress is created
220  // and then never changed. To handle dummy proxies though, m_name
221  // can be created as blank and filled in later, but then never changed
222  // again. Used CachedValue to avoid having to use a lock for this.
223  if (m_name.isValid()) {
224  return *m_name.ptr();
225  }
226  return s_emptyString;
227  }
228 
230  inline
232  {
233  return m_sgkey;
234  }
235 
237  inline
239  {
240  m_sgkey = sgkey;
241  }
242 
244  inline
246  {
247  return std::find (m_transientID.begin(), m_transientID.end(), id) !=
248  m_transientID.end();
249  }
250 
252  inline
254  {
255  return m_transientID;
256  }
257 
259  inline
260  void TransientAddress::setAlias(const std::string& key)
261  {
262  auto it = std::ranges::lower_bound (m_transientAlias, key);
263  if (it == m_transientAlias.end() || *it != key) {
264  m_transientAlias.insert (it, key);
265  }
266  }
267 
269  inline
270  void TransientAddress::setAlias(const std::vector<std::string>& keys)
271  {
273  }
274 
276  inline
277  void TransientAddress::setAlias(std::vector<std::string>&& keys)
278  {
279  m_transientAlias = std::move(keys);
280  }
281 
283  inline bool TransientAddress::removeAlias(const std::string& key)
284  {
285  auto it = std::ranges::lower_bound (m_transientAlias, key);
286  if (it != m_transientAlias.end() && *it == key) {
287  m_transientAlias.erase (it);
288  return true;
289  }
290  return false;
291  }
292 
294  inline bool TransientAddress::hasAlias(const std::string& key) const
295  {
296  return std::ranges::binary_search (m_transientAlias, key);
297  }
298 
300  inline
302  {
303  return m_transientAlias;
304  }
305 
307  inline
309  {
311  }
312 
314  inline
316  {
317  return m_clearAddress;
318  }
319 
320  inline
322  {
324  }
325 
328  inline
330  {
331  return m_pAddressProvider;
332  }
333  inline
335  {
336  return m_storeID;
337  }
338 
339  inline
341  StoreID::type storeID)
342  {
344  m_consultProvider = true;
346  }
347 } //end namespace SG
348 
349 #endif // STOREGATE_TRANSIENTADDRESS
common.sgkey
def sgkey(tool)
Definition: common.py:1027
SG::TransientAddress::m_clid
std::atomic< CLID > m_clid
< clid of the concrete class (persistent clid)
Definition: TransientAddress.h:159
CxxUtils::CachedValue::ptr
const T * ptr() const
Return a pointer to the cached value.
SG
Forward declaration.
Definition: CaloCellPacker_400_500.h:32
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
SG::TransientAddress::storeID
StoreID::type storeID() const
Definition: TransientAddress.h:334
SG::TransientAddress::m_name
CxxUtils::CachedValue< std::string > m_name
all transient clids. They come from symlinks
Definition: TransientAddress.h:180
SG::TransientAddress::operator=
TransientAddress & operator=(const TransientAddress &)
Definition: TransientAddress.cxx:124
SG::ATLAS_NOT_CONST_THREAD_SAFE
IOpaqueAddress *TransientAddress::address ATLAS_NOT_CONST_THREAD_SAFE() const
Retrieve IOpaqueAddress.
Definition: TransientAddress.h:203
CxxUtils::CachedValue::isValid
bool isValid() const
Test to see if the value is valid.
SG::TransientAddress::setAlias
void setAlias(const std::string &key)
set alias'
Definition: TransientAddress.h:260
skel.it
it
Definition: skel.GENtoEVGEN.py:407
SG::TransientAddress
Definition: TransientAddress.h:32
SG::TransientAddress::~TransientAddress
~TransientAddress()
Definition: TransientAddress.cxx:116
SG::TransientAddress::sgkey
sgkey_t sgkey() const
Set the primary (hashed) SG key.
Definition: TransientAddress.h:231
SG::TransientAddress::clearAddress
bool clearAddress() const
this sets the flag whether to consult the provider to update this transient address if the IOA is not...
Definition: TransientAddress.h:315
SG::TransientAddress::TransientClidSet
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...
Definition: TransientAddress.h:38
SG::TransientAddress::removeAlias
bool removeAlias(const std::string &key)
remove alias from proxy
Definition: TransientAddress.h:283
SG::TransientAddress::reset
void reset()
Retrieve IOpaqueAddress.
Definition: TransientAddress.h:196
IStringPool::sgkey_t
SG::sgkey_t sgkey_t
Type of the keys.
Definition: IStringPool.h:34
SG::TransientAddress::m_address
IOpaqueAddress * m_address
AddressProvider.
Definition: TransientAddress.h:174
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:47
SG::TransientAddress::m_storeID
StoreID::type m_storeID
Controls if IOpaqueAddress should be deleted:
Definition: TransientAddress.h:165
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:217
SG::TransientAddress::m_transientID
TransientClidSet m_transientID
all alias names for a DataObject. They come from setAlias
Definition: TransientAddress.h:183
IStringPool.h
Abstract interface for looking up strings/CLIDs in a pool.
SG::TransientAddress::m_sgkey
std::atomic< sgkey_t > m_sgkey
Store type, needed by updateAddress.
Definition: TransientAddress.h:162
SG::TransientAddress::alias
const TransientAliasSet & alias() const
set the clearAddress flag: IOA will not be deleted in proxy
Definition: TransientAddress.h:301
SG::TransientAddress::provider
IAddressProvider * provider()
Definition: TransientAddress.h:329
SG::TransientAddress::clID
CLID clID() const
Retrieve string key:
Definition: TransientAddress.h:210
SG::TransientAddress::isValid
bool isValid(const EventContext *ctx, bool forceUpdate=false)
cache the pointer to the Address provider which can update this transient address
Definition: TransientAddress.cxx:201
master.flag
bool flag
Definition: master.py:29
IAddressProvider
interface for IOA providers
Definition: IAddressProvider.h:28
CxxUtils::CachedValue< std::string >
SG::TransientAddress::sgkey_t
IStringPool::sgkey_t sgkey_t
Default Constructor.
Definition: TransientAddress.h:41
CLID
uint32_t CLID
The Class ID type.
Definition: Event/xAOD/xAODCore/xAODCore/ClassID_traits.h:47
SG::TransientAddress::setProvider
void setProvider(IAddressProvider *provider, StoreID::type storeID)
Definition: TransientAddress.h:340
SG::TransientAddress::m_transientAlias
TransientAliasSet m_transientAlias
Definition: TransientAddress.h:186
StoreID.h
CachedValue.h
Cached value with atomic update.
SG::TransientAddress::setTransientID
void setTransientID(CLID id)
get transient CLID's
Definition: TransientAddress.cxx:164
SG::TransientAddress::m_clearAddress
bool m_clearAddress
Control whether the Address Provider must be consulted.
Definition: TransientAddress.h:168
SG::TransientAddress::setID
void setID(CLID id, const std::string &key)
Set the CLID / key.
Definition: TransientAddress.cxx:183
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
SG::TransientAddress::setAddress
void setAddress(IOpaqueAddress *pAddress)
Retrieve primary clid.
Definition: TransientAddress.cxx:194
SG::TransientAddress::transientID
const TransientClidSet & transientID() const
set alias'
Definition: TransientAddress.h:253
SG::TransientAddress::consultProvider
void consultProvider(const bool &flag)
Check the validity of the Transient Address.
Definition: TransientAddress.h:321
StoreID::type
type
Definition: StoreID.h:24
SG::TransientAddress::m_consultProvider
bool m_consultProvider
IOpaqueAddress:
Definition: TransientAddress.h:171
SG::TransientAddress::setSGKey
void setSGKey(sgkey_t sgkey)
check if it is a transient ID (primary or symLinked):
Definition: TransientAddress.h:238
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:801
SG::TransientAddress::ATLAS_NOT_CONST_THREAD_SAFE
IOpaqueAddress *address ATLAS_NOT_CONST_THREAD_SAFE() const
set IOpaqueAddress
SG::TransientAddress::TransientAddress
TransientAddress()
Construct from clid and string key:
Definition: TransientAddress.cxx:18
SG::TransientAddress::TransientAliasSet
std::vector< std::string > TransientAliasSet
Definition: TransientAddress.h:40
checker_macros.h
Define macros for attributes used to control the static checker.
SG::TransientAddress::m_pAddressProvider
IAddressProvider * m_pAddressProvider
string key of this object
Definition: TransientAddress.h:177
SG::TransientAddress::hasAlias
bool hasAlias(const std::string &key) const
get transient alias
Definition: TransientAddress.h:294
SG::TransientAddress::s_emptyString
static const std::string s_emptyString
Definition: TransientAddress.h:188
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37