ATLAS Offline Software
TransientAddress.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "SGTools/DataProxy.h"
9 #include "GaudiKernel/IOpaqueAddress.h"
10 
11 #include <assert.h>
12 
14 
15 const std::string TransientAddress::s_emptyString;
16 
17 // Default Constructor:
18 TransientAddress::TransientAddress()
19  : TransientAddress (CLID_NULL, "", nullptr, true, false)
20 {
21 }
22 
23 // Constructor with CLID and string key:
24 // (typically used through a StoreGate::record()
26  : TransientAddress (id, key, nullptr, true, false)
27 {
28  if (id != CLID_NULL)
29  m_transientID.push_back(id);
30 }
31 
32 // Constructor with CLID, string key and IOpaqueAddress:
33 // (typically used by a ProxyProvider)
36  bool clearAddress)
37  : TransientAddress (id, key, std::move(addr), clearAddress, true)
38 {
39  if (id != CLID_NULL)
40  m_transientID.push_back(id);
41 }
42 
43 
44 // Constructor giving full list of symlinked IDs
45 // --- used from DataHeaderElement::getAddress().
48  const std::vector<CLID>& clids)
49  : TransientAddress (id, key, std::move(addr), true, true)
50 {
51  m_transientID.reserve (clids.size() + 1);
52  m_transientID = clids;
53  if (id != CLID_NULL) {
54  m_transientID.push_back (id);
55  std::ranges::sort (m_transientID);
56  }
57 }
58 
59 
60 // Note: this is a private ctor, only used from other ctors.
61 // It does not initialize m_transientID.
64  bool clearAddress,
65  bool consultProvider)
66  : m_clid(id),
67  m_sgkey(0),
68  m_storeID(StoreID::UNKNOWN),
69  m_clearAddress(clearAddress),
70  m_consultProvider(consultProvider),
71  m_address(std::move(addr)),
72  m_pAddressProvider(nullptr)
73 {
74  if (!key.empty()) {
75  m_name.store (key);
76  }
77 }
78 
79 
81  : m_clid (static_cast<CLID>(other.m_clid)),
82  m_sgkey (static_cast<sgkey_t>(other.m_sgkey)),
83  m_storeID (other.m_storeID),
84  m_clearAddress (other.m_clearAddress),
85  m_consultProvider (other.m_consultProvider),
86  m_address (other.m_address),
87  m_pAddressProvider (other.m_pAddressProvider),
89  m_transientID (other.m_transientID),
90  m_transientAlias (other.m_transientAlias)
91 {
92 }
93 
94 
96  : m_clid (static_cast<CLID>(other.m_clid)),
97  m_sgkey (static_cast<sgkey_t>(other.m_sgkey)),
98  m_storeID (other.m_storeID),
99  m_clearAddress (other.m_clearAddress),
100  m_consultProvider (other.m_consultProvider),
101  m_address (std::move (other.m_address)),
102  m_pAddressProvider (other.m_pAddressProvider),
103  m_name (std::move (other.m_name)),
104  m_transientID (std::move (other.m_transientID)),
105  m_transientAlias (std::move (other.m_transientAlias))
106 {
107 }
108 
109 
110 // Destructor
112 {
113 }
114 
115 
117 {
118  if (this != &other) {
119  m_clid = static_cast<CLID>(other.m_clid);
120  m_name = other.m_name;
121  m_transientID = other.m_transientID;
122  m_transientAlias = other.m_transientAlias;
123  m_clearAddress = other.m_clearAddress;
124  m_consultProvider = other.m_consultProvider;
125  m_pAddressProvider = other.m_pAddressProvider;
126  m_storeID = other.m_storeID;
127  m_sgkey = static_cast<sgkey_t>(other.m_sgkey);
128  m_address = other.m_address;
129  }
130  return *this;
131 }
132 
133 
135 {
136  if (this != &other) {
137  m_clid = static_cast<CLID>(other.m_clid);
138  m_name = std::move (other.m_name);
139  m_transientID = std::move (other.m_transientID);
140  m_transientAlias = std::move (other.m_transientAlias);
141  m_clearAddress = other.m_clearAddress;
142  m_consultProvider = other.m_consultProvider;
143  m_pAddressProvider = other.m_pAddressProvider;
144  m_storeID = other.m_storeID;
145  m_sgkey = static_cast<sgkey_t>(other.m_sgkey);
146  m_address = std::move (other.m_address);
147  }
148  return *this;
149 }
150 
151 
154 {
155  if (m_transientID.empty()) {
156  m_transientID.push_back (id);
157  }
158  else if (!transientID (id)) {
159  m_transientID.push_back (id);
160  std::sort (m_transientID.begin(), m_transientID.end());
161  }
162 }
163 
164 
172 void TransientAddress::setID (CLID id, const std::string& key)
173 {
174  assert (m_clid == CLID_NULL && !m_name.isValid() && m_transientID.empty() &&
175  m_transientAlias.empty());
176  m_clid = id;
177  m_name.set (key);
178  if (id != CLID_NULL)
179  m_transientID.push_back(id);
180 }
181 
182 // Reset the TransientAddress
184 {
186 }
187 
190 {
191  m_address = std::move(pAddress);
192 }
193 
194 bool TransientAddress::isValid(const EventContext* ctx,
195  bool forceUpdate /*= false*/)
196 {
197  if (!forceUpdate && 0 != address()) return true;
198 
199  if (ctx && m_consultProvider && 0 != provider()) {
200  if ((provider()->updateAddress(storeID(), this, *ctx)).isSuccess())
201  return true;
202  }
203  return false;
204 }
SG::TransientAddress::m_clid
std::atomic< CLID > m_clid
< clid of the concrete class (persistent clid)
Definition: TransientAddress.h:162
CxxUtils::RefCountedPtr::reset
void reset(T *ptr=nullptr)
Change the pointer.
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::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
Definition: TransientAddress.h:34
SG::TransientAddress::~TransientAddress
~TransientAddress()
Definition: TransientAddress.cxx:111
CxxUtils::RefCountedPtr< IOpaqueAddress >
m_name
std::string m_name
Definition: ColumnarPhysliteTest.cxx:64
CxxUtils::CachedValue::store
void store(const T &val)
Store a new value.
SG::TransientAddress::m_storeID
StoreID::type m_storeID
Controls if IOpaqueAddress should be deleted:
Definition: TransientAddress.h:168
SG::TransientAddress::m_transientID
TransientClidSet m_transientID
all alias names for a DataObject. They come from setAlias
Definition: TransientAddress.h:186
SG::TransientAddress::m_sgkey
std::atomic< sgkey_t > m_sgkey
Store type, needed by updateAddress.
Definition: TransientAddress.h:165
SG::TransientAddress::provider
IAddressProvider * provider()
Definition: TransientAddress.h:326
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
SG::TransientAddress::sgkey_t
IStringPool::sgkey_t sgkey_t
Default Constructor.
Definition: TransientAddress.h:43
StoreID
defines an enum used by address providers to decide what kind of StoreGateSvc they are providing addr...
Definition: StoreID.h:18
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::m_transientAlias
TransientAliasSet m_transientAlias
Definition: TransientAddress.h:189
IProxyDict.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
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
CxxUtils::CachedValue::set
void set(const T &val) const
Set the value, assuming it is currently invalid.
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
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::TransientAddress::m_consultProvider
bool m_consultProvider
IOpaqueAddress:
Definition: TransientAddress.h:174
TransientAddress.h
IAddressProvider.h
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
SG::TransientAddress::m_pAddressProvider
IAddressProvider * m_pAddressProvider
string key of this object
Definition: TransientAddress.h:180
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
DataProxy.h