ATLAS Offline Software
|
Manage DataProxy
reference in ElementLink/DataLink.
More...
#include <DataProxyHolder.h>
Public Types | |
typedef IStringPool::sgkey_t | sgkey_t |
Type of hashed keys. More... | |
typedef std::string | ID_type |
Type of string keys. More... | |
typedef void * | pointer_t |
Generic pointer type. More... | |
typedef const void * | const_pointer_t |
typedef void * | castfn_t(SG::DataProxy *) |
Function casting from a SG::DataProxy to a pointer. More... | |
typedef Athena::IInputRename::InputRenameMap_t | InputRenameMap_t |
Input renaming map. More... | |
typedef Athena::IInputRename::InputRenameRCU_t | InputRenameRCU_t |
Public Member Functions | |
DataProxyHolder () | |
Default constructor. More... | |
template<class FROM_STORABLE , class TO_STORABLE > | |
DataProxyHolder (const DataProxyHolder &other, FROM_STORABLE *, TO_STORABLE *) | |
Constructor from a holder referencing a different type. More... | |
DataProxyHolder (const DataProxyHolder &)=default | |
DataProxyHolder & | operator= (const DataProxyHolder &)=default |
void | clear () |
Reset the link to null. More... | |
sgkey_t | toStorableObject (const_pointer_t obj, CLID link_clid, IProxyDict *sg) |
Set the link to an object given by a pointer. More... | |
sgkey_t | toIdentifiedObject (const ID_type &dataID, CLID link_clid, IProxyDict *sg) |
Set the link to an object given by a string key. More... | |
void | toIdentifiedObject (sgkey_t key, CLID link_clid, IProxyDict *sg) |
Set the link to an object given by a hashed key. More... | |
bool | isDefault () const |
Test to see if this is a null link. More... | |
const ID_type & | dataID () const |
Return the SG key that we reference, as a string. More... | |
void * | storableBase (castfn_t *castfn, CLID clid, bool isConst) const |
Return a pointer to the currently-referenced object. More... | |
SG::DataProxy * | proxy (bool nothrow=false) const |
Return the DataProxy for this link. More... | |
IProxyDict * | source () const |
Return the data source for this reference. More... | |
void | toTransient (sgkey_t sgkey, IProxyDict *sg=0) |
Finish initialization after link has been read. More... | |
sgkey_t | toTransient (const ID_type &dataID, CLID link_clid, IProxyDict *sg=0) |
Finish initialization after link has been read. More... | |
void | toPersistentNoRemap (sgkey_t &sgkey) |
Prepare this link for writing. More... | |
bool | toPersistent (sgkey_t &sgkey, uint64_t &index) |
Prepare this link for writing. More... | |
bool | toPersistent (sgkey_t &sgkey, uint32_t &index) |
Prepare this link for writing. More... | |
template<class T > | |
bool | toPersistent (sgkey_t &sgkey, const T &) |
Prepare this link for writing. More... | |
bool | operator== (const DataProxyHolder &other) const |
Compare for equality. More... | |
void | throwInvalidLink (sgkey_t sgkey) const |
Throw a ExcInvalidLink exception for this link. More... | |
Static Public Member Functions | |
static bool | thin (sgkey_t &sgkey, size_t &index, const SG::ThinningCache *thinningCache) |
Adjust for thinning, with explicitly provided thinning cache. More... | |
static void setInputRenameMap | ATLAS_NOT_THREAD_SAFE (const InputRenameRCU_t *map) |
Set map used for performing input renaming in toTransient. More... | |
static void | resetCachedSource () |
Private Member Functions | |
bool | isObjpointer () const |
Test to see if we're pointing directly at an object. More... | |
pointer_t | objpointer () const |
Return a pointer to the object we're pointing at directly. More... | |
void | storeObjpointer (const_pointer_t p) |
Store a direct pointer to an object. More... | |
SG::DataProxy * | proxy1 (bool nothrow) const |
Helper for proxy() , for the case of a direct object pointer. More... | |
IProxyDict * | source1 () |
Return the data source for this reference. More... | |
bool | tryRemap (sgkey_t &sgkey, size_t &index) |
Test to see if the link has been remapped. More... | |
Private Attributes | |
SG::DataProxy * | m_proxy |
The DataProxy referring to our object, if the LSB is clear; pointer to the object which we're referencing directly if the LSB is set. More... | |
Manage DataProxy
reference in ElementLink/DataLink.
This class factors out operations on DataProxy
that are common between ElementLink
and DataLink
, and holds a pointer to the proxy. This pointer is transient; the (persistent) SG key field is stored in the class that holds this one, and is passed as a parameter where needed.
We can be initialized either with a key or with a pointer to an object. In the former case, we try immediately to look up the proxy for that key. If we find it, then we use it; otherwise, we create a dummy DataProxy
for that key and add it to our store. If we're given a pointer, we again immediately try to look up the corresponding proxy. If we don't find it, then we store the pointer directly in the proxy member, with a flag to identify this case. Subsequent operations that require a proxy will again try to look up the proxy in the store; if that fails, then an exception will be thrown.
When we create a new link, the store by default is taken from the global default given by SG::CurrentEventStore::store(). This is a thread-specific value, so fetching it can be expensive. If you are creating links inside a loop, it is best to fetch the default before the loop and then passing the result explicitly when you create the links.
Definition at line 60 of file DataProxyHolder.h.
typedef void* SG::DataProxyHolder::castfn_t(SG::DataProxy *) |
Function casting from a SG::DataProxy
to a pointer.
Definition at line 74 of file DataProxyHolder.h.
typedef const void* SG::DataProxyHolder::const_pointer_t |
Definition at line 71 of file DataProxyHolder.h.
typedef std::string SG::DataProxyHolder::ID_type |
Type of string keys.
Definition at line 67 of file DataProxyHolder.h.
Input renaming map.
Definition at line 77 of file DataProxyHolder.h.
Definition at line 78 of file DataProxyHolder.h.
typedef void* SG::DataProxyHolder::pointer_t |
Generic pointer type.
Definition at line 70 of file DataProxyHolder.h.
Type of hashed keys.
Definition at line 64 of file DataProxyHolder.h.
SG::DataProxyHolder::DataProxyHolder | ( | ) |
Default constructor.
Make a null link.
SG::DataProxyHolder::DataProxyHolder | ( | const DataProxyHolder & | other, |
FROM_STORABLE * | , | ||
TO_STORABLE * | |||
) |
Constructor from a holder referencing a different type.
other | The object from which to copy. |
FROM_STORABLE
is the storable class to which other
refers; TO_STORABLE
is the storable class for this object. The actual pointer values are not used, just the types are used. Default conversions for the storable pointer (i.e., derived->base) are allowed.
|
default |
|
static |
Set map used for performing input renaming in toTransient.
map | The new map, or nullptr for no renmaing. |
void SG::DataProxyHolder::clear | ( | ) |
Reset the link to null.
const DataProxyHolder::ID_type & SG::DataProxyHolder::dataID | ( | ) | const |
Return the SG key that we reference, as a string.
Returns a null string on failure.
Definition at line 227 of file DataProxyHolder.cxx.
bool SG::DataProxyHolder::isDefault | ( | ) | const |
Test to see if this is a null link.
|
private |
|
private |
Return a pointer to the object we're pointing at directly.
Should be used only if isObjpointer()
is true.
|
default |
bool SG::DataProxyHolder::operator== | ( | const DataProxyHolder & | other | ) | const |
SG::DataProxy* SG::DataProxyHolder::proxy | ( | bool | nothrow = false | ) | const |
Return the DataProxy
for this link.
nothrow | If true, return 0 on failure instead of throwing an exception. |
If this is a null link, we return 0. Otherwise, if we're pointing at a DataProxy
, return it. Otherwise, we're pointing at an object directly. Try to look up the corresponding DataProxy
using the default store. Return it if we find it; otherwise, either throw ExcPointerNotInSG
or return 0, depending on the nothrow
parameter.
|
private |
Helper for proxy()
, for the case of a direct object pointer.
nothrow | If true, return 0 on failure instead of throwing an exception. |
This is the out-of-line portion of proxy()
, called if this link is directly pointing at an object. Try to look up the corresponding DataProxy
using the default store. Return it if we find it; otherwise, either throw ExcPointerNotInSG
or return 0, depending on the nothrow
parameter.
Definition at line 568 of file DataProxyHolder.cxx.
|
static |
IProxyDict * SG::DataProxyHolder::source | ( | ) | const |
Return the data source for this reference.
If the link is null, return 0. If we're pointing at an object directly, then we return the default store if the object is found in SG; otherwise, throw ExcPointerNotInSG
.
Definition at line 303 of file DataProxyHolder.cxx.
|
private |
Return the data source for this reference.
If we're holding a pointer directly, rather than a proxy, then return 0 rather than raising an exception.
Return a pointer to the currently-referenced object.
castfn | Function to do the cast from data proxy to object. If 0, use a dynamic cast. |
clid | The CLID of the desired object. This is used to determine how the returned pointer is to be converted. |
isConst | True if the returned object will be treated as const. |
Definition at line 249 of file DataProxyHolder.cxx.
|
private |
Store a direct pointer to an object.
p | Pointer to the object that we're referencing. |
This will overwrite m_proxy
with the reference to the object.
|
static |
Adjust for thinning, with explicitly provided thinning cache.
Adjust for thinning.
sgkey | Reference to the hashed SG key. |
index | Index of this link. |
thinningCache | Thinning cache for the current stream (may be null). |
If this link points to a container that has been thinned, sgkey
and index
will be adjusted accordingly.
Returns true
if the index was changed; false
otherwise.
Definition at line 504 of file DataProxyHolder.cxx.
void SG::DataProxyHolder::throwInvalidLink | ( | sgkey_t | sgkey | ) | const |
Throw a ExcInvalidLink
exception for this link.
sgkey | The hashed key for this link. |
This will fill in parameters for the exception message from the proxy.
Definition at line 544 of file DataProxyHolder.cxx.
DataProxyHolder::sgkey_t SG::DataProxyHolder::toIdentifiedObject | ( | const ID_type & | dataID, |
CLID | link_clid, | ||
IProxyDict * | sg | ||
) |
Set the link to an object given by a string key.
dataID | Key of the object. |
link_clid | CLID of the link being set. |
sg | Associated store. |
This will try to look up the proxy for dataID
. If that succeeds, then we store the pointer to the proxy. Otherwise, we create a dummy proxy and add it to the store. We return the SG key in either case.
If sg
is 0, then we take the store from whatever the link's currently set to. If the link has no current store, then we take the global default.
Definition at line 123 of file DataProxyHolder.cxx.
void SG::DataProxyHolder::toIdentifiedObject | ( | sgkey_t | sgkey, |
CLID | link_clid, | ||
IProxyDict * | sg | ||
) |
Set the link to an object given by a hashed key.
key | Hashed key of the object. |
link_clid | CLID of the link being set. |
sg | Associated store. |
This will try to look up the proxy for key
. If that succeeds, then we store the pointer to the proxy. Otherwise, we create a dummy proxy and add it to the store.
If sg
is 0, then we take the store from whatever the link's currently set to. If the link has no current store, then we take the global default.
May throw ExcCLIDMismatch
.
Definition at line 169 of file DataProxyHolder.cxx.
Prepare this link for writing.
sgkey | Reference to the hashed SG key. |
index | Index of this link. |
One of the toPersistent
methods should be called before trying to write the link with root.
This takes a reference to the hashed SG key. In the case where we're referencing an object directly by pointer, the hashed key will be 0. In that case, we try to look up the object in the default store. If we find it, the hashed key is updated appropriately; otherwise, we throw ExcPointerNotInSG
.
This version is for the case where indices are not given by size_t
. No remapping will be performed for this case; this function will always return false.
bool SG::DataProxyHolder::toPersistent | ( | sgkey_t & | sgkey, |
uint32_t & | index | ||
) |
Prepare this link for writing.
sgkey | Reference to the hashed SG key. |
index | Index of this link. |
One of the toPersistent
methods should be called before trying to write the link with root.
This takes a reference to the hashed SG key. In the case where we're referencing an object directly by pointer, the hashed key will be 0. In that case, we try to look up the object in the default store. If we find it, the hashed key is updated appropriately; otherwise, we throw ExcPointerNotInSG
.
If the target of the link has been remapped, then the sgkey
and index
parameters will be updated to reflect that, and true
will be returned. Otherwise, if there was no remapping, then false
will be returned.
This version is for the case where indices are given by uint32_t
.
Definition at line 452 of file DataProxyHolder.cxx.
bool SG::DataProxyHolder::toPersistent | ( | sgkey_t & | sgkey, |
uint64_t & | index | ||
) |
Prepare this link for writing.
sgkey | Reference to the hashed SG key. |
index | Index of this link. |
One of the toPersistent
methods should be called before trying to write the link with root.
This takes a reference to the hashed SG key. In the case where we're referencing an object directly by pointer, the hashed key will be 0. In that case, we try to look up the object in the default store. If we find it, the hashed key is updated appropriately; otherwise, we throw ExcPointerNotInSG
.
If the target of the link has been remapped, then the sgkey
and index
parameters will be updated to reflect that, and true
will be returned. Otherwise, if there was no remapping, then false
will be returned.
This version is for the case where indices are given by uint64_t
.
Definition at line 421 of file DataProxyHolder.cxx.
void SG::DataProxyHolder::toPersistentNoRemap | ( | sgkey_t & | sgkey | ) |
Prepare this link for writing.
sgkey | Reference to the hashed SG key. |
One of the toPersistent
methods should be called before trying to write the link with root.
This takes a reference to the hashed SG key. In the case where we're referencing an object directly by pointer, the hashed key will be 0. In that case, we try to look up the object in the default store. If we find it, the hashed key is updated appropriately; otherwise, we throw ExcPointerNotInSG
.
This version does not perform link remapping.
Definition at line 392 of file DataProxyHolder.cxx.
DataProxyHolder::sgkey_t SG::DataProxyHolder::toStorableObject | ( | const_pointer_t | obj, |
CLID | link_clid, | ||
IProxyDict * | sg | ||
) |
Set the link to an object given by a pointer.
obj | Pointer to the object. |
link_clid | CLID of the link being set. |
sg | Associated store. |
This will try to look up the proxy for obj
. If that succeeds, then we store the pointer to the proxy and return the SG key. Otherwise, we store a pointer to the object itself, flagging this case with the low bit, and return 0.
If sg
is 0, then we take the store from whatever the link's currently set to. If the link has no current store, then we take the global default.
May throw ExcCLIDMismatch
.
obj | Pointer to the object. |
link_clid | CLID of the link being set. |
sg | Associated store. |
This will try to look up the proxy for obj
. If that succeeds, then we store the pointer to the proxy and return the SG key. Otherwise, we store a pointer to the object itself, flagging this case with the low bit, and return 0.
If sg
is 0, then we take the store from whatever the link's currently set to. If the link has no current store, then we take the global default.
Definition at line 58 of file DataProxyHolder.cxx.
DataProxyHolder::sgkey_t SG::DataProxyHolder::toTransient | ( | const ID_type & | dataID, |
CLID | link_clid, | ||
IProxyDict * | sg = 0 |
||
) |
Finish initialization after link has been read.
dataID | Key of the object. |
link_clid | CLID of the link being set. |
sg | Associated store. |
This should be called after a link has been read by root in order to set the proxy pointer. It calls toIdentifiedObject
with the provided hashed key.
If sg
is 0, then we use the global default store.
Definition at line 361 of file DataProxyHolder.cxx.
void SG::DataProxyHolder::toTransient | ( | sgkey_t | sgkey, |
IProxyDict * | sg = 0 |
||
) |
Finish initialization after link has been read.
sgkey | Hashed SG key. |
sg | Associated store. |
This should be called after a link has been read by root in order to set the proxy pointer. It calls toIdentifiedObject
with the provided hashed key.
If sg
is 0, then we use the global default store.
Definition at line 324 of file DataProxyHolder.cxx.
|
private |
Test to see if the link has been remapped.
sgkey | Reference to the hashed SG key. |
index | Index of this link. |
If this link has been remapped, sgkey
and index
will be adjusted accordingly.
Returns true
if the link was remapped, false
otherwise.
Definition at line 473 of file DataProxyHolder.cxx.
|
private |
The DataProxy
referring to our object, if the LSB is clear; pointer to the object which we're referencing directly if the LSB is set.
Definition at line 453 of file DataProxyHolder.h.