ATLAS Offline Software
TransientAddress.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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::set<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 
58 
61 
64  void setID (CLID id, const std::string& key);
65 
67  void reset();
68 
70  // Can't change the signature here to satisfy the thread-safety
71  // checker as this should match the signature in the Gaudi IRegistry.
72  IOpaqueAddress* address ATLAS_NOT_CONST_THREAD_SAFE () const;
73 
75  void setAddress(IOpaqueAddress* pAddress);
76 
78  CLID clID() const;
79 
81  const std::string& name() const;
82 
84  sgkey_t sgkey() const;
85 
87  void setSGKey (sgkey_t sgkey);
88 
90  bool transientID (CLID id) const;
91 
93  void setTransientID(CLID id);
94 
96  const TransientClidSet& transientID() const;
97 
99  void setAlias(const std::string& key);
100 
102  void setAlias(const std::set<std::string>& keys);
103 
105  void setAlias(std::set<std::string>&& keys);
106 
108  bool removeAlias(const std::string& key);
109 
111  const TransientAliasSet& alias() const;
112 
114  void clearAddress(const bool& flag);
115 
117  bool clearAddress() const;
118 
121  void consultProvider(const bool& flag);
122 
127  bool isValid (const EventContext* ctx, bool forceUpdate = false);
128 
132  StoreID::type storeID() const;
134 
135  private:
136  TransientAddress(CLID id, const std::string& key,
137  IOpaqueAddress* addr,
138  bool clearAddress,
139  bool consultProvider);
140 
141 
142  // PLEASE NOTE: The data members of this class are ordered so that
143  // the most frequently accessed members are grouped together, within
144  // the first cache line, when it is embedded in DataProxy. See the layout
145  // at the end of DataProxy.h.
146  // Be aware of this when making changes to the layout of this class.
147 
148 
150  std::atomic<CLID> m_clid;
151 
153  std::atomic<sgkey_t> m_sgkey;
154 
157 
160 
163 
165  IOpaqueAddress* m_address;
166 
169 
172 
175 
178 
179  static const std::string s_emptyString;
180  };
182  // inlined code:
184 
185  // Reset the TransientAddress
186  inline
188  {
189  if (m_clearAddress) setAddress(0);
190  }
191 
193  inline
195  {
196  return m_address;
197  }
198 
200  inline
202  {
203  return m_clid;
204  }
205 
207  inline
208  const std::string& TransientAddress::name() const
209  {
210  // Most of the time, m_name is set when the TransientAddress is created
211  // and then never changed. To handle dummy proxies though, m_name
212  // can be created as blank and filled in later, but then never changed
213  // again. Used CachedValue to avoid having to use a lock for this.
214  if (m_name.isValid()) {
215  return *m_name.ptr();
216  }
217  return s_emptyString;
218  }
219 
221  inline
223  {
224  return m_sgkey;
225  }
226 
228  inline
230  {
231  m_sgkey = sgkey;
232  }
233 
235  inline
237  {
238  return std::find (m_transientID.begin(), m_transientID.end(), id) !=
239  m_transientID.end();
240  }
241 
243  inline
245  {
246  return m_transientID;
247  }
248 
250  inline
251  void TransientAddress::setAlias(const std::string& key)
252  {
253  m_transientAlias.insert(key);
254  }
255 
257  inline
258  void TransientAddress::setAlias(const std::set<std::string>& keys)
259  {
261  }
262 
264  inline
265  void TransientAddress::setAlias(std::set<std::string>&& keys)
266  {
267  m_transientAlias = std::move(keys);
268  }
269 
271  inline bool TransientAddress::removeAlias(const std::string& key)
272  {
273  return (m_transientAlias.erase(key) == 1) ? true:false;
274  }
275 
277  inline
279  {
280  return m_transientAlias;
281  }
282 
284  inline
286  {
288  }
289 
291  inline
293  {
294  return m_clearAddress;
295  }
296 
297  inline
299  {
301  }
302 
305  inline
307  {
308  return m_pAddressProvider;
309  }
310  inline
312  {
313  return m_storeID;
314  }
315 
316  inline
318  StoreID::type storeID)
319  {
321  m_consultProvider = true;
323  }
324 } //end namespace SG
325 
326 #endif // STOREGATE_TRANSIENTADDRESS
common.sgkey
def sgkey(tool)
Definition: common.py:1028
SG::TransientAddress::m_clid
std::atomic< CLID > m_clid
< clid of the concrete class (persistent clid)
Definition: TransientAddress.h:150
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:311
SG::TransientAddress::m_name
CxxUtils::CachedValue< std::string > m_name
all transient clids. They come from symlinks
Definition: TransientAddress.h:171
SG::TransientAddress::operator=
TransientAddress & operator=(const TransientAddress &)
Definition: TransientAddress.cxx:102
SG::ATLAS_NOT_CONST_THREAD_SAFE
IOpaqueAddress *TransientAddress::address ATLAS_NOT_CONST_THREAD_SAFE() const
Retrieve IOpaqueAddress.
Definition: TransientAddress.h:194
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:251
SG::TransientAddress
Definition: TransientAddress.h:32
SG::TransientAddress::~TransientAddress
~TransientAddress()
Definition: TransientAddress.cxx:96
SG::TransientAddress::sgkey
sgkey_t sgkey() const
Set the primary (hashed) SG key.
Definition: TransientAddress.h:222
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:292
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:271
SG::TransientAddress::reset
void reset()
Retrieve IOpaqueAddress.
Definition: TransientAddress.h:187
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:165
IProxyDict
A proxy dictionary.
Definition: AthenaKernel/AthenaKernel/IProxyDict.h:51
SG::TransientAddress::m_storeID
StoreID::type m_storeID
Controls if IOpaqueAddress should be deleted:
Definition: TransientAddress.h:156
SG::TransientAddress::name
const std::string & name() const
Get the primary (hashed) SG key.
Definition: TransientAddress.h:208
SG::TransientAddress::m_transientID
TransientClidSet m_transientID
all alias names for a DataObject. They come from setAlias
Definition: TransientAddress.h:174
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:153
SG::TransientAddress::alias
const TransientAliasSet & alias() const
set the clearAddress flag: IOA will not be deleted in proxy
Definition: TransientAddress.h:278
SG::TransientAddress::provider
IAddressProvider * provider()
Definition: TransientAddress.h:306
SG::TransientAddress::clID
CLID clID() const
Retrieve string key:
Definition: TransientAddress.h:201
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:179
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:317
SG::TransientAddress::m_transientAlias
TransientAliasSet m_transientAlias
Definition: TransientAddress.h:177
StoreID.h
CachedValue.h
Cached value with atomic update.
SG::TransientAddress::setTransientID
void setTransientID(CLID id)
get transient CLID's
Definition: TransientAddress.cxx:142
SG::TransientAddress::m_clearAddress
bool m_clearAddress
Control whether the Address Provider must be consulted.
Definition: TransientAddress.h:159
SG::TransientAddress::setID
void setID(CLID id, const std::string &key)
Set the CLID / key.
Definition: TransientAddress.cxx:161
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
SG::TransientAddress::setAddress
void setAddress(IOpaqueAddress *pAddress)
Retrieve primary clid.
Definition: TransientAddress.cxx:172
SG::TransientAddress::transientID
const TransientClidSet & transientID() const
set alias'
Definition: TransientAddress.h:244
SG::TransientAddress::consultProvider
void consultProvider(const bool &flag)
Check the validity of the Transient Address.
Definition: TransientAddress.h:298
StoreID::type
type
Definition: StoreID.h:24
SG::TransientAddress::m_consultProvider
bool m_consultProvider
IOpaqueAddress:
Definition: TransientAddress.h:162
SG::TransientAddress::setSGKey
void setSGKey(sgkey_t sgkey)
check if it is a transient ID (primary or symLinked):
Definition: TransientAddress.h:229
python.Bindings.keys
keys
Definition: Control/AthenaPython/python/Bindings.py:790
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
checker_macros.h
Define macros for attributes used to control the static checker.
SG::TransientAddress::TransientAliasSet
std::set< std::string > TransientAliasSet
Definition: TransientAddress.h:40
SG::TransientAddress::m_pAddressProvider
IAddressProvider * m_pAddressProvider
string key of this object
Definition: TransientAddress.h:168
SG::TransientAddress::s_emptyString
static const std::string s_emptyString
Definition: TransientAddress.h:179
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37