Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SmartRefBase.cpp
Go to the documentation of this file.
1 // ====================================================================
2 // SmartRefBase.cpp
3 // --------------------------------------------------------------------
4 //
5 // Package : Root conversion example
6 //
7 // Author : Markus Frank
8 //
9 // ====================================================================
10 #define KERNEL_SMARTREFBASE_CPP 1
11 
12 // Framework include files
15 #include "GaudiKernel/DataObject.h"
18 #include "GaudiKernel/IRegistry.h"
22 
24 
26 void SmartRefBase::set( DataObject* pObj, long hint_id, long link_id ) {
27  m_data = pObj;
28  m_hintID = hint_id;
29  m_linkID = link_id;
30 }
31 
35  const _Container* cnt = dynamic_cast<const _Container*>( accessData( m_data ) );
36  if ( cnt ) return cnt->containedObject( m_linkID );
37  }
38  return nullptr;
39 }
40 
43  DataObject* target = nullptr;
44  DataObject* source = nullptr;
45  if ( !m_data && m_contd ) m_data = m_contd->parent();
46  source = const_cast<DataObject*>( m_data );
47  if ( m_hintID != StreamBuffer::INVALID && source ) {
48  LinkManager* mgr = source->linkMgr();
49  if ( mgr ) {
50  LinkManager::Link* link = mgr->link( m_hintID );
51  if ( link ) {
52  target = link->object();
53  if ( !target ) {
54  IRegistry* reg = source->registry();
55  if ( reg ) {
56  IDataProviderSvc* datasvc = reg->dataSvc();
57  if ( datasvc && datasvc->retrieveObject( link->path(), target ).isSuccess() ) { link->setObject( target ); }
58  }
59  }
60  }
61  }
62  }
63  return target;
64 }
65 
66 // Extended equality check
67 bool SmartRefBase::isEqualEx( const DataObject* pObj, const SmartRefBase& c ) const {
68  if ( c.m_hintID != StreamBuffer::INVALID && pObj ) {
69  DataObject* source = const_cast<DataObject*>( c.m_data );
70  if ( source ) {
71  LinkManager* mgr = source->linkMgr();
72  if ( mgr ) {
73  LinkManager::Link* link = mgr->link( c.m_hintID );
74  if ( link ) {
75  IRegistry* pReg = pObj->registry();
76  return pReg && link->path() == pReg->identifier();
77  }
78  }
79  }
80  }
81  return false;
82 }
83 
84 // Extended equality check
85 bool SmartRefBase::isEqualEx( const ContainedObject* pObj, const SmartRefBase& c ) const {
86  return isEqualEx( pObj->parent(), c ) && pObj->index() == c.m_linkID;
87 }
88 
90  static std::string s_empty_string{};
91  DataObject* source = nullptr;
92  if ( !m_data && m_contd ) m_data = m_contd->parent();
93  source = const_cast<DataObject*>( m_data );
94  if ( m_hintID != StreamBuffer::INVALID && source ) {
95  LinkManager* mgr = source->linkMgr();
96  if ( mgr ) {
97  LinkManager::Link* link = mgr->link( m_hintID );
98  if ( link ) return link->path();
99  }
100  }
101  return s_empty_string;
102 }
bool isEqualEx(const DataObject *pObj, const SmartRefBase &c) const
Extended equality check.
const ContainedObject * accessData(const ContainedObject *typ) const
Load on demand of ContainedObject like references.
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
Definition: SmartRefBase.h:54
ObjectContainerBase _Container
long m_hintID
Object data: ID of the link hint to the identifiable object.
Definition: SmartRefBase.h:50
virtual long index() const
Distance in the parent container.
User example objects: SmartRefBase.
Definition: SmartRefBase.h:47
Data provider interface definition.
const ObjectContainerBase * parent() const
Access to parent object.
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:74
STL class.
virtual ContainedObject * containedObject(long dist) const =0
Pointer to an object of a given distance.
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Definition: SmartRefBase.h:56
const std::string & path() const
Shortcut to access the path to the linked object.
virtual const id_type & identifier() const =0
Full identifier (or key)
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
virtual StatusCode retrieveObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
long m_linkID
Object data: ID of the object within the identifiable container (if any)
Definition: SmartRefBase.h:52
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
ObjectContainerBase is the base class for Gaudi container classes.
void set(DataObject *pObj, long hint_id, long link_id)
Setup smart reference when reading. Must be allowed from external sources.
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30