The Gaudi Framework  master (181af51f)
Loading...
Searching...
No Matches
SmartRefBase.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
20
22
24void SmartRefBase::set( DataObject* pObj, long hint_id, long link_id ) {
25 m_data = pObj;
26 m_hintID = hint_id;
27 m_linkID = link_id;
28}
29
33 const _Container* cnt = dynamic_cast<const _Container*>( accessData( m_data ) );
34 if ( cnt ) return cnt->containedObject( m_linkID );
35 }
36 return nullptr;
37}
38
41 if ( !m_data && m_contd ) m_data = m_contd->parent();
42 DataObject* source = const_cast<DataObject*>( m_data );
43 if ( m_hintID == StreamBuffer::INVALID || !source ) return nullptr;
44 LinkManager* mgr = source->linkMgr();
45 if ( !mgr ) return nullptr;
46 LinkManager::Link* link = mgr->link( m_hintID );
47 if ( !link ) return nullptr;
48 DataObject* target = link->object();
49 if ( !target ) {
50 IRegistry* reg = source->registry();
51 if ( !reg ) return nullptr;
52 IDataProviderSvc* datasvc = reg->dataSvc();
53 if ( datasvc && datasvc->retrieveObject( link->path(), target ).isSuccess() ) { link->setObject( target ); }
54 }
55 return target;
56}
57
58// Extended equality check
59bool SmartRefBase::isEqualEx( const DataObject* pObj, const SmartRefBase& c ) const {
60 if ( c.m_hintID != StreamBuffer::INVALID && pObj ) {
61 DataObject* source = const_cast<DataObject*>( c.m_data );
62 if ( source ) {
63 LinkManager* mgr = source->linkMgr();
64 if ( mgr ) {
65 const LinkManager::Link* link = mgr->link( c.m_hintID );
66 if ( link ) {
67 IRegistry* pReg = pObj->registry();
68 return pReg && link->path() == pReg->identifier();
69 }
70 }
71 }
72 }
73 return false;
74}
75
76// Extended equality check
77bool SmartRefBase::isEqualEx( const ContainedObject* pObj, const SmartRefBase& c ) const {
78 return isEqualEx( pObj->parent(), c ) && pObj->index() == c.m_linkID;
79}
80
81const std::string& SmartRefBase::path() const {
82 static std::string s_empty_string{};
83 DataObject* source = nullptr;
84 if ( !m_data && m_contd ) m_data = m_contd->parent();
85 source = const_cast<DataObject*>( m_data );
86 if ( m_hintID != StreamBuffer::INVALID && source ) {
87 LinkManager* mgr = source->linkMgr();
88 if ( mgr ) {
89 const LinkManager::Link* link = mgr->link( m_hintID );
90 if ( link ) return link->path();
91 }
92 }
93 return s_empty_string;
94}
ObjectContainerBase _Container
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
const ObjectContainerBase * parent() const
Access to parent object.
virtual long index() const
Distance in the parent container.
A DataObject is the base class of any identifiable object on any data store.
Definition DataObject.h:37
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
LinkManager * linkMgr()
Retrieve Link manager.
Definition DataObject.h:81
Data provider interface definition.
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition IRegistry.h:29
virtual const id_type & identifier() const =0
Full identifier (or key)
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
ObjectContainerBase is the base class for Gaudi container classes.
virtual const ContainedObject * containedObject(long dist) const =0
Pointer to an object of a given distance.
User example objects: SmartRefBase.
bool isEqualEx(const DataObject *pObj, const SmartRefBase &c) const
Extended equality check.
void set(DataObject *pObj, long hint_id, long link_id)
Setup smart reference when reading. Must be allowed from external sources.
long m_linkID
Object data: ID of the object within the identifiable container (if any)
const ContainedObject * accessData(const ContainedObject *typ) const
Load on demand of ContainedObject like references.
long m_hintID
Object data: ID of the link hint to the identifiable object.
const std::string & path() const
Shortcut to access the path to the linked object.
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
bool isSuccess() const
Definition StatusCode.h:314