![]() |
ATLAS Offline Software
|
Base class for ElementLinks to vectors of pointers. More...
#include <ElementLinkBase.h>
Public Types | |
typedef size_t | index_type |
The index type presented to and returned from the link. More... | |
typedef uint32_t | stored_index_type |
The type of the index as it is stored internally. More... | |
typedef SG::DataProxyHolder::sgkey_t | sgkey_t |
Type of hashed keys. More... | |
typedef SG::DataProxyHolder::ID_type | ID_type |
Type of string keys. More... | |
typedef void * | castfn_t(SG::DataProxy *) |
Function casting from a SG::DataProxy to a pointer. More... | |
Public Member Functions | |
ElementLinkBase (const ElementLinkBase &)=default | |
ElementLinkBase & | operator= (const ElementLinkBase &)=default |
bool | isDefaultIndex () const |
Test the index validity. More... | |
bool | hasCachedElement () const |
Test to see if this link has a cached element pointer. More... | |
bool | isDefault () const |
Test to see if this link is in the default state. More... | |
index_type | index () const |
Return the index of the link. More... | |
stored_index_type | persIndex () const |
Return the index of the link. More... | |
const ID_type & | dataID () const |
Return the SG key that we reference, as a string. More... | |
sgkey_t | key () const |
Return the SG key that we reference, as a hash. More... | |
sgkey_t | persKey () const |
Return the SG key that we reference, as a hash. More... | |
IProxyDict * | source () const |
Return the data source for this reference. More... | |
const SG::DataProxy * | proxy () const |
Return the SG proxy for the container holding this element. More... | |
void | reset () |
Reset the link to a null state. More... | |
bool | toTransient (IProxyDict *sg=0) |
Finish initialization after link has been read. More... | |
bool | toPersistent () |
Prepare this link for writing. More... | |
bool | thin () |
Adjust for thinning. More... | |
bool | thin (const SG::ThinningCache *thinningCache) |
Adjust for thinning. More... | |
ElementLinkBase () | |
Default constructor. More... | |
ElementLinkBase (uint32_t key=0, uint32_t index=INVALID) | |
Default constructor. More... | |
virtual | ~ElementLinkBase () |
Destructor. More... | |
uint32_t | persKey () const |
Get the key/identifier of the referenced container. More... | |
void | setPersKey (uint32_t key) |
Set the key/identifier of the referenced container. More... | |
uint32_t | persIndex () const |
Get the index of the referenced object in the container. More... | |
void | setPersIndex (uint32_t index) |
Set the index of the referenced object in the container. More... | |
virtual bool | toTransient ()=0 |
Reset the object's internal cache. More... | |
bool | isDefault () const |
Is the link in the default state. More... | |
Protected Member Functions | |
ElementLinkBase (const ID_type &dataID, CLID link_clid, index_type elemID, IProxyDict *sg) | |
Construct a link from a string key and an index. More... | |
ElementLinkBase (sgkey_t key, CLID link_clid, index_type elemID, IProxyDict *sg) | |
Construct a link from a hashed key and an index. More... | |
ElementLinkBase (const ID_type &dataID, CLID link_clid, index_type elemID, const void *elt, IProxyDict *sg) | |
Construct a link from a string key, index, AND pointer to element. More... | |
ElementLinkBase (sgkey_t key, CLID link_clid, index_type elemID, const void *elt, IProxyDict *sg) | |
Construct a link from a hashed key, index, AND pointer to element. More... | |
ElementLinkBase (const_pointer_t obj, CLID link_clid, index_type elemID, IProxyDict *sg) | |
Construct a link from an index and pointer to the container. More... | |
ElementLinkBase (const ElementLinkBase &other, index_type elemID) | |
Construct a link from another link, changing the index. More... | |
ElementLinkBase (const DataLinkBase &dlink, index_type index) | |
Construct a link from a DataLink and an index. More... | |
template<class FROM_TRAITS , class TO_TRAITS > | |
ElementLinkBase (const ElementLinkBase &other, FROM_TRAITS *, TO_TRAITS *) | |
Constructor from a link referencing a different type. More... | |
void * | storableBase (castfn_t *castfn, CLID clid, bool isConst) const |
Return a pointer to the currently-referenced container object. More... | |
bool | setStorableObject (const_pointer_t data, CLID link_clid, bool replace, IProxyDict *sg) |
Set the container referenced by the link to data . More... | |
bool | toIndexedElement (const_pointer_t obj, CLID link_clid, index_type elemID, IProxyDict *sg) |
Set the link to an element given by index and pointer to container. More... | |
void | resetWithKeyAndIndex (const ID_type &dataID, CLID link_clid, index_type elemID, IProxyDict *sg) |
Set the link to an element given by string key and index. More... | |
void | resetWithKeyAndIndex (sgkey_t key, CLID link_clid, index_type elemID, IProxyDict *sg) |
Set the link to an element given by string key and index. More... | |
void | setIndex (index_type index) |
Set the index part of the link. More... | |
const stored_index_type & | storedIndex () const |
Return the stored representation of the link index. More... | |
void | setCachedElement (ElementType elt) const |
Set the cached element stored in the link, assuming the cached element is null. More... | |
void | storeCachedElement (ElementType elt) |
Set the cached element stored in the link. More... | |
template<class T > | |
bool | getCachedElement (const T *&elt) const |
Retrieve the cached element from the link. More... | |
const SG::DataProxyHolder & | proxyHolder () const |
Return the internal proxy holder object. More... | |
Protected Attributes | |
uint32_t | m_persKey |
Key/identifier of the referenced container. More... | |
uint32_t | m_persIndex |
Index of the referenced object in the container. More... | |
bool | m_isDirectIO |
A transient variable signalling when direct I/O is happening. More... | |
Private Types | |
typedef const void * | ElementType |
Generic pointer to an element. More... | |
typedef SG::DataProxyHolder::const_pointer_t | const_pointer_t |
Generic pointer to the container (storable). More... | |
Private Member Functions | |
void | clearCachedElement () |
Clear the currently-cached element. More... | |
Private Attributes | |
SG::sgkey_t | m_persKey |
The hashed key for this link. More... | |
stored_index_type | m_persIndex |
The index of the element within the container for this link. More... | |
SG::DataProxyHolder | m_proxy |
SG proxy for this link. More... | |
CxxUtils::CachedPointer< void > | m_element |
Transient. More... | |
Static Private Attributes | |
static const uint32_t | INVALID = static_cast<uint32_t> (-1) |
Value to mark an invalid index. More... | |
static constexpr uint32_t | INVALID = static_cast<uint32_t> (-1) |
Value to mark a default index. More... | |
Friends | |
class | ElementLinkBase_test |
For regression testing. More... | |
Base class for ElementLinks to vectors of pointers.
A base class holding the container independent part of ElementLink.
This holds the type-independent portion of an ElementLink
for the case where the target container holds pointers and has vector-like indexing. This is the most common case, and for this case, we can have a non-templated class; this simplifies persistency.
Other types of ElementLink
will use instead GenericElementLinkBase
.
See ElementLinkTraits.h for a summary of the requirements for these base classes.
This class stores the hashed SG key of the target container and the index of the element within the container. (The type of the index should be the same as in ForwardIndexingPolicy
; however, we don't depend on the indexing policy since that class is templated.) Those two members make up the persistent state. We also store a transient DataProxyHolder
, which encapsulates the pointer to the DataProxy
and factors out code that's common with DataLink
. Further, we store a copy of the element to which the link refers; this is also transient (and mutable). In the case of ElementLinkBase
, the element will always be a pointer, so we can store it as a generic void*.
For technical reasons it's a good idea to define a common base class for the ElementLink classes, it helps with ROOT I/O immensely.
Definition at line 58 of file AthLinks/ElementLinkBase.h.
typedef void* ElementLinkBase::castfn_t(SG::DataProxy *) |
Function casting from a SG::DataProxy
to a pointer.
Definition at line 85 of file AthLinks/ElementLinkBase.h.
|
private |
Generic pointer to the container (storable).
Definition at line 68 of file AthLinks/ElementLinkBase.h.
|
private |
Generic pointer to an element.
Definition at line 65 of file AthLinks/ElementLinkBase.h.
Type of string keys.
Definition at line 82 of file AthLinks/ElementLinkBase.h.
typedef size_t ElementLinkBase::index_type |
The index type presented to and returned from the link.
Definition at line 73 of file AthLinks/ElementLinkBase.h.
Type of hashed keys.
Definition at line 79 of file AthLinks/ElementLinkBase.h.
typedef uint32_t ElementLinkBase::stored_index_type |
The type of the index as it is stored internally.
Definition at line 76 of file AthLinks/ElementLinkBase.h.
|
default |
ElementLinkBase::ElementLinkBase | ( | ) |
|
protected |
Construct a link from a string key and an index.
dataID | Key of the object. |
link_clid | CLID of the link being set. |
elemID | The index of the element within the container. |
sg | Associated store. |
If sg
is 0, we take the global default.
|
protected |
Construct a link from a hashed key and an index.
key | Hashed key of the object. |
link_clid | CLID of the link being set. |
elemID | The index of the element within the container. |
sg | Associated store. |
If sg
is 0, we take the global default.
|
protected |
Construct a link from a string key, index, AND pointer to element.
dataID | Key of the object. |
link_clid | CLID of the link being set. |
elemID | The index of the element within the container. |
elt | Pointer to the element. |
sg | Associated store. |
USE CAREFULLY: no coherency checks, we just trust you!
If sg
is 0, we take the global default.
|
protected |
Construct a link from a hashed key, index, AND pointer to element.
key | Hashed key of the object. |
link_clid | CLID of the link being set. |
elemID | The index of the element within the container. |
elt | Pointer to the element. |
sg | Associated store. |
USE CAREFULLY: no coherency checks, we just trust you!
If sg
is 0, we take the global default.
|
protected |
Construct a link from an index and pointer to the container.
obj | Pointer to the container (storable). |
link_clid | CLID of the link being set. |
elemID | The index of the element within the container. |
sg | Associated store. |
If sg
is 0, we take the global default.
|
protected |
Construct a link from another link, changing the index.
other | The source link. |
elemID | The index for the new link. |
The index being constructed will reference the same container as other
, but it will refer to element elemID
.
|
protected |
Construct a link from a DataLink and an index.
dlink | Link to the container. |
index | The index of the element within the container. |
|
protected |
Constructor from a link referencing a different type.
other | The object from which to copy. |
FROM_TRAITS
is the ElementLinkTraits
class for other
; TO_TRAITS
is the traits 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.
ElementLinkBase::ElementLinkBase | ( | uint32_t | key = 0 , |
uint32_t | index = INVALID |
||
) |
Default constructor.
Definition at line 8 of file ElementLinkBase.cxx.
|
inlinevirtual |
|
private |
Clear the currently-cached element.
Return the SG key that we reference, as a string.
Returns a null string on failure.
|
protected |
Retrieve the cached element from the link.
elt[out] | The cached element. |
elt
is left unmodified if there is no cached element.
bool ElementLinkBase::hasCachedElement | ( | ) | const |
Test to see if this link has a cached element pointer.
index_type ElementLinkBase::index | ( | ) | const |
Return the index of the link.
bool ElementLinkBase::isDefault | ( | ) | const |
Is the link in the default state.
A link in the default state was purposefully constructed as a null link
bool ElementLinkBase::isDefault | ( | ) | const |
Test to see if this link is in the default state.
Definition at line 49 of file ElementLinkBase.cxx.
bool ElementLinkBase::isDefaultIndex | ( | ) | const |
Test the index validity.
sgkey_t ElementLinkBase::key | ( | ) | const |
Return the SG key that we reference, as a hash.
Returns 0 on failure.
|
default |
uint32_t ElementLinkBase::persIndex | ( | ) | const |
Get the index of the referenced object in the container.
uint32_t ElementLinkBase::persIndex | ( | ) | const |
Return the index of the link.
(Deprecated; use index()
instead.)
Definition at line 31 of file ElementLinkBase.cxx.
uint32_t ElementLinkBase::persKey | ( | ) | const |
Get the key/identifier of the referenced container.
uint32_t ElementLinkBase::persKey | ( | ) | const |
Return the SG key that we reference, as a hash.
(Deprecated; use key
instead.)
Returns 0 on failure.
Definition at line 13 of file ElementLinkBase.cxx.
const SG::DataProxy* ElementLinkBase::proxy | ( | ) | const |
Return the SG proxy for the container holding this element.
If this is a null link, we return 0. If we're directly referencing an object that's not in StoreGate, either return 0 or throw ExcPointerNotInSG
, depending on nothrow
. Otherwise, return the proxy for the object we're referencing.
|
protected |
Return the internal proxy holder object.
void ElementLinkBase::reset | ( | ) |
Reset the link to a null state.
|
protected |
Set the link to an element given by string key and index.
dataID | Key of the object. |
link_clid | CLID of the link being set. |
elemID | The index of the element within the container. |
sg | Associated 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.
|
protected |
Set the link to an element given by string key and index.
key | Hashed key of the object. |
link_clid | CLID of the link being set. |
elemID | The index of the element within the container. |
sg | Associated 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.
|
protected |
Set the cached element stored in the link, assuming the cached element is null.
elt | New value for the cached element. |
This method will set the current cached element if it is currently unset. If it has previously been assigned, then this method will do nothing.
|
protected |
Set the index part of the link.
index | New index value. |
void ElementLinkBase::setPersIndex | ( | uint32_t | index | ) |
Set the index of the referenced object in the container.
Definition at line 36 of file ElementLinkBase.cxx.
void ElementLinkBase::setPersKey | ( | uint32_t | key | ) |
Set the key/identifier of the referenced container.
Definition at line 18 of file ElementLinkBase.cxx.
|
protected |
Set the container referenced by the link to data
.
data | Pointer to the new container. |
link_clid | CLID of the link being set. |
replace | True if we can change an existing link. |
sg | Associated store. |
If the link is already set, this will return false and leave the link unchanged unless replace
is set. The replace
argument should be set if the element is now in a new storable container; e.g. element ptr has been put in a new view container.
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.
IProxyDict* ElementLinkBase::source | ( | ) | const |
Return the data source for this reference.
Return a pointer to the currently-referenced container 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. |
|
protected |
Set the cached element stored in the link.
elt | New value for the cached element. |
|
protected |
Return the stored representation of the link index.
bool ElementLinkBase::thin | ( | ) |
Adjust for thinning.
If this link points to a container that has been thinned, it will be adjusted accordingly.
Returns true
if the link was changed; false
otherwise.
bool ElementLinkBase::thin | ( | const SG::ThinningCache * | thinningCache | ) |
Adjust for thinning.
If this link points to a container that has been thinned, it will be adjusted accordingly.
thinningCache | Thinning cache for the current stream (may be null). |
Returns true
if the link was changed; false
otherwise.
|
protected |
Set the link to an element given by index and pointer to container.
obj | Pointer to the container (storable). |
link_clid | CLID of the link being set. |
elemID | The index of the element within the container. |
sg | Associated store. |
If the link is already set, this will return false and leave the link unchanged.
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.
bool ElementLinkBase::toPersistent | ( | ) |
Prepare this link for writing.
This method should be called before trying to write the link with root. It will make sure the persistent fields of the link are valid. It will also perform remapping if needed.
Will return true on success. Will return false if either the container or the element index has not been specified. Will throw ExcPointerNotInSG
if the link is referencing a container that is not in SG.
|
pure virtual |
Reset the object's internal cache.
bool ElementLinkBase::toTransient | ( | IProxyDict * | sg = 0 | ) |
Finish initialization after link has been read.
sg | Associated store. |
This should be called after a link has been read by root in order to set the proxy pointer. Returns true.
If sg
is 0, then we use the global default store.
|
friend |
For regression testing.
Definition at line 495 of file AthLinks/ElementLinkBase.h.
|
staticconstexprprivate |
Value to mark a default index.
Definition at line 27 of file A/AthLinks/ElementLinkBase.h.
|
staticprivate |
Value to mark an invalid index.
Definition at line 62 of file AthLinks/ElementLinkBase.h.
|
private |
Transient.
Definition at line 509 of file AthLinks/ElementLinkBase.h.
|
protected |
A transient variable signalling when direct I/O is happening.
This flag is used exclusively by the ElementLink<>::toTransient() function to know when it should take the persistent data stored in this object into account. That function may be called in normal P->T conversions as well, in which case using the data from this class would just reset the object to its default state.
Definition at line 68 of file A/AthLinks/ElementLinkBase.h.
|
protected |
Index of the referenced object in the container.
Definition at line 58 of file A/AthLinks/ElementLinkBase.h.
|
private |
The index of the element within the container for this link.
Definition at line 504 of file AthLinks/ElementLinkBase.h.
|
protected |
Key/identifier of the referenced container.
Definition at line 56 of file A/AthLinks/ElementLinkBase.h.
|
private |
The hashed key for this link.
Definition at line 501 of file AthLinks/ElementLinkBase.h.
|
private |
SG proxy for this link.
Definition at line 507 of file AthLinks/ElementLinkBase.h.