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 "CxxUtils/RefCountedPtr.h"
20 #include "CxxUtils/CachedValue.h"
22 #include "GaudiKernel/ClassID.h"
23 #include "GaudiKernel/IOpaqueAddress.h"
24 
26 class IOpaqueAddress;
27 class IAddressProvider;
28 class IProxyDict;
29 class EventContext;
30 
31 namespace 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  };
194  // inlined code:
196 
198  inline
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
229  {
230  return m_sgkey;
231  }
232 
234  inline
236  {
237  m_sgkey = sgkey;
238  }
239 
241  inline
243  {
244  return std::find (m_transientID.begin(), m_transientID.end(), id) !=
245  m_transientID.end();
246  }
247 
249  inline
251  {
252  return m_transientID;
253  }
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  {
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
299  {
300  return m_transientAlias;
301  }
302 
304  inline
306  {
308  }
309 
311  inline
313  {
314  return m_clearAddress;
315  }
316 
317  inline
319  {
321  }
322 
325  inline
327  {
328  return m_pAddressProvider;
329  }
330  inline
332  {
333  return m_storeID;
334  }
335 
336  inline
338  StoreID::type storeID)
339  {
341  m_consultProvider = true;
343  }
344 } //end namespace SG
345 
346 #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:162
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:331
SG::TransientAddress::m_name
CxxUtils::CachedValue< std::string > m_name
all transient clids. They come from symlinks
Definition: TransientAddress.h:183
SG::TransientAddress::operator=
TransientAddress & operator=(const TransientAddress &)
Definition: TransientAddress.cxx:116
SG::ATLAS_NOT_CONST_THREAD_SAFE
IOpaqueAddress *TransientAddress::address ATLAS_NOT_CONST_THREAD_SAFE() const
Retrieve IOpaqueAddress.
Definition: TransientAddress.h:199
SG::TransientAddress::m_address
CxxUtils::RefCountedPtr< IOpaqueAddress > m_address
AddressProvider.
Definition: TransientAddress.h:177
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:257
skel.it
it
Definition: skel.GENtoEVGEN.py:407
SG::TransientAddress
Definition: TransientAddress.h:34
SG::TransientAddress::~TransientAddress
~TransientAddress()
Definition: TransientAddress.cxx:111
RefCountedPtr.h
Simple smart pointer for Gaudi-style refcounted objects.
SG::TransientAddress::sgkey
sgkey_t sgkey() const
Set the primary (hashed) SG key.
Definition: TransientAddress.h:228
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:312
CxxUtils::RefCountedPtr< IOpaqueAddress >
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:40
SG::TransientAddress::removeAlias
bool removeAlias(const std::string &key)
remove alias from proxy
Definition: TransientAddress.h:280
IStringPool::sgkey_t
SG::sgkey_t sgkey_t
Type of the keys.
Definition: IStringPool.h:34
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:168
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:214
SG::TransientAddress::m_transientID
TransientClidSet m_transientID
all alias names for a DataObject. They come from setAlias
Definition: TransientAddress.h:186
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:165
SG::TransientAddress::alias
const TransientAliasSet & alias() const
set the clearAddress flag: IOA will not be deleted in proxy
Definition: TransientAddress.h:298
SG::TransientAddress::provider
IAddressProvider * provider()
Definition: TransientAddress.h:326
SG::TransientAddress::clID
CLID clID() const
Retrieve string key:
Definition: TransientAddress.h:207
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:194
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:43
SG::TransientAddress::reset
void reset()
Retrieve IOpaqueAddress.
Definition: TransientAddress.cxx:183
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:337
SG::TransientAddress::m_transientAlias
TransientAliasSet m_transientAlias
Definition: TransientAddress.h:189
StoreID.h
CachedValue.h
Cached value with atomic update.
SG::TransientAddress::setTransientID
void setTransientID(CLID id)
get transient CLID's
Definition: TransientAddress.cxx:153
SG::TransientAddress::m_clearAddress
bool m_clearAddress
Control whether the Address Provider must be consulted.
Definition: TransientAddress.h:171
SG::TransientAddress::setID
void setID(CLID id, const std::string &key)
Set the CLID / key.
Definition: TransientAddress.cxx:172
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
SG::TransientAddress::transientID
const TransientClidSet & transientID() const
set alias'
Definition: TransientAddress.h:250
SG::TransientAddress::consultProvider
void consultProvider(const bool &flag)
Check the validity of the Transient Address.
Definition: TransientAddress.h:318
StoreID::type
type
Definition: StoreID.h:24
SG::TransientAddress::m_consultProvider
bool m_consultProvider
IOpaqueAddress:
Definition: TransientAddress.h:174
SG::TransientAddress::setSGKey
void setSGKey(sgkey_t sgkey)
check if it is a transient ID (primary or symLinked):
Definition: TransientAddress.h:235
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::setAddress
void setAddress(CxxUtils::RefCountedPtr< IOpaqueAddress > pAddress)
Retrieve primary clid.
Definition: TransientAddress.cxx:189
SG::TransientAddress::TransientAddress
TransientAddress()
Construct from clid and string key:
Definition: TransientAddress.cxx:18
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
SG::TransientAddress::TransientAliasSet
std::vector< std::string > TransientAliasSet
Definition: TransientAddress.h:42
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:180
SG::TransientAddress::hasAlias
bool hasAlias(const std::string &key) const
get transient alias
Definition: TransientAddress.h:291
SG::TransientAddress::s_emptyString
static const std::string s_emptyString
Definition: TransientAddress.h:191
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37