ATLAS Offline Software
TransientAddress.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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 }
29 
30 // Constructor with CLID, string key and IOpaqueAddress:
31 // (typically used by a ProxyProvider)
33  IOpaqueAddress* addr,
34  bool clearAddress)
35  : TransientAddress (id, key, addr, clearAddress, true)
36 {
37 }
38 
39 
41  IOpaqueAddress* addr,
42  bool clearAddress,
43  bool consultProvider)
44  : m_clid(id),
45  m_sgkey(0),
46  m_storeID(StoreID::UNKNOWN),
47  m_clearAddress(clearAddress),
48  m_consultProvider(consultProvider),
49  m_address(nullptr),
50  m_pAddressProvider(nullptr)
51 {
52  if (!key.empty()) {
53  m_name.store (key);
54  }
55  if (id != CLID_NULL)
56  m_transientID.push_back(id);
57  if (addr) {
58  setAddress(addr);
59  }
60 }
61 
62 
64  : m_clid (static_cast<CLID>(other.m_clid)),
65  m_sgkey (static_cast<sgkey_t>(other.m_sgkey)),
66  m_storeID (other.m_storeID),
67  m_clearAddress (other.m_clearAddress),
68  m_consultProvider (other.m_consultProvider),
69  m_pAddressProvider (other.m_pAddressProvider),
70  m_name (other.m_name),
71  m_transientID (other.m_transientID),
72  m_transientAlias (other.m_transientAlias)
73 {
74  m_address = nullptr;
75  setAddress (other.m_address);
76 }
77 
78 
80  : m_clid (static_cast<CLID>(other.m_clid)),
81  m_sgkey (static_cast<sgkey_t>(other.m_sgkey)),
82  m_storeID (other.m_storeID),
83  m_clearAddress (other.m_clearAddress),
84  m_consultProvider (other.m_consultProvider),
85  m_pAddressProvider (other.m_pAddressProvider),
86  m_name (std::move (other.m_name)),
87  m_transientID (std::move (other.m_transientID)),
88  m_transientAlias (std::move (other.m_transientAlias))
89 {
90  m_address = other.m_address;
91  other.m_address = nullptr;
92 }
93 
94 
95 // Destructor
97 {
98  setAddress(0);
99 }
100 
101 
103 {
104  if (this != &other) {
105  m_clid = static_cast<CLID>(other.m_clid);
106  m_name = other.m_name;
107  m_transientID = other.m_transientID;
108  m_transientAlias = other.m_transientAlias;
109  m_clearAddress = other.m_clearAddress;
110  m_consultProvider = other.m_consultProvider;
111  m_pAddressProvider = other.m_pAddressProvider;
112  m_storeID = other.m_storeID;
113  m_sgkey = static_cast<sgkey_t>(other.m_sgkey);
114 
115  setAddress (other.m_address);
116  }
117  return *this;
118 }
119 
120 
122 {
123  if (this != &other) {
124  m_clid = static_cast<CLID>(other.m_clid);
125  m_name = std::move (other.m_name);
126  m_transientID = std::move (other.m_transientID);
127  m_transientAlias = std::move (other.m_transientAlias);
128  m_clearAddress = other.m_clearAddress;
129  m_consultProvider = other.m_consultProvider;
130  m_pAddressProvider = other.m_pAddressProvider;
131  m_storeID = other.m_storeID;
132  m_sgkey = static_cast<sgkey_t>(other.m_sgkey);
133 
134  m_address = other.m_address;
135  other.m_address = nullptr;
136  }
137  return *this;
138 }
139 
140 
143 {
144  if (m_transientID.empty()) {
145  m_transientID.push_back (id);
146  }
147  else if (!transientID (id)) {
148  m_transientID.push_back (id);
149  std::sort (m_transientID.begin(), m_transientID.end());
150  }
151 }
152 
153 
161 void TransientAddress::setID (CLID id, const std::string& key)
162 {
163  assert (m_clid == CLID_NULL && !m_name.isValid() && m_transientID.empty() &&
164  m_transientAlias.empty());
165  m_clid = id;
166  m_name.set (key);
167  if (id != CLID_NULL)
168  m_transientID.push_back(id);
169 }
170 
172 void TransientAddress::setAddress(IOpaqueAddress* pAddress)
173 {
174  if (0 != pAddress) pAddress->addRef();
175  if (0 != m_address) m_address->release();
176  m_address = pAddress;
177 }
178 
179 bool TransientAddress::isValid(const EventContext* ctx,
180  bool forceUpdate /*= false*/)
181 {
182  if (!forceUpdate && 0 != address()) return true;
183 
184  if (ctx && m_consultProvider && 0 != provider()) {
185  if ((provider()->updateAddress(storeID(), this, *ctx)).isSuccess())
186  return true;
187  }
188  return false;
189 }
SG::TransientAddress::m_clid
std::atomic< CLID > m_clid
< clid of the concrete class (persistent clid)
Definition: TransientAddress.h:150
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
CxxUtils::CachedValue::isValid
bool isValid() const
Test to see if the value is valid.
SG::TransientAddress
Definition: TransientAddress.h:32
SG::TransientAddress::~TransientAddress
~TransientAddress()
Definition: TransientAddress.cxx:96
SG::TransientAddress::m_address
IOpaqueAddress * m_address
AddressProvider.
Definition: TransientAddress.h:165
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:156
SG::TransientAddress::m_transientID
TransientClidSet m_transientID
all alias names for a DataObject. They come from setAlias
Definition: TransientAddress.h:174
SG::TransientAddress::m_sgkey
std::atomic< sgkey_t > m_sgkey
Store type, needed by updateAddress.
Definition: TransientAddress.h:153
SG::TransientAddress::provider
IAddressProvider * provider()
Definition: TransientAddress.h:306
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
SG::TransientAddress::sgkey_t
IStringPool::sgkey_t sgkey_t
Default Constructor.
Definition: TransientAddress.h:41
StoreID
defines an enum used by address providers to decide what kind of StoreGateSvc they are providing addr...
Definition: StoreID.h:18
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:177
IProxyDict.h
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
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
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: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
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
SG::TransientAddress::m_consultProvider
bool m_consultProvider
IOpaqueAddress:
Definition: TransientAddress.h:162
TransientAddress.h
IAddressProvider.h
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:168
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
DataProxy.h