| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
13 #include "GaudiKernel/SmartRefBase.h"
14 #include "GaudiKernel/ContainedObject.h"
15 #include "GaudiKernel/DataObject.h"
16 #include "GaudiKernel/GaudiException.h"
17 #include "GaudiKernel/IDataProviderSvc.h"
18 #include "GaudiKernel/IRegistry.h"
19 #include "GaudiKernel/LinkManager.h"
20 #include "GaudiKernel/ObjectContainerBase.h"
21 #include "GaudiKernel/StreamBuffer.h"
22
23 typedef ObjectContainerBase _Container;
24
26 void SmartRefBase::set( DataObject* pObj, long hint_id, long link_id )
27 {
28 m_data = pObj;
29 m_hintID = hint_id;
30 m_linkID = link_id;
31 }
32
34 const ContainedObject* SmartRefBase::accessData( const ContainedObject* ) const
35 {
36 if ( m_hintID != StreamBuffer::INVALID && m_linkID != StreamBuffer::INVALID ) {
37 const _Container* cnt = dynamic_cast<const _Container*>( accessData( m_data ) );
38 if ( cnt ) return cnt->containedObject( m_linkID );
39 }
40 return nullptr;
41 }
42
44 const DataObject* SmartRefBase::accessData( const DataObject* ) const
45 {
46 DataObject* target = nullptr;
47 DataObject* source = nullptr;
48 if ( !m_data && m_contd ) m_data = m_contd->parent();
49 source = const_cast<DataObject*>( m_data );
50 if ( m_hintID != StreamBuffer::INVALID && source ) {
51 LinkManager* mgr = source->linkMgr();
52 if ( mgr ) {
53 LinkManager::Link* link = mgr->link( m_hintID );
54 if ( link ) {
55 target = link->object();
56 if ( !target ) {
57 IRegistry* reg = source->registry();
58 if ( reg ) {
59 IDataProviderSvc* datasvc = reg->dataSvc();
60 if ( datasvc && datasvc->retrieveObject( link->path(), target ).isSuccess() ) {
61 link->setObject( target );
62 }
63 }
64 }
65 }
66 }
67 }
68 return target;
69 }
70
71 // Extended equality check
72 bool SmartRefBase::isEqualEx( const DataObject* pObj, const SmartRefBase& c ) const
73 {
74 if ( c.m_hintID != StreamBuffer::INVALID && pObj ) {
75 DataObject* source = const_cast<DataObject*>( c.m_data );
76 if ( source ) {
77 LinkManager* mgr = source->linkMgr();
78 if ( mgr ) {
79 LinkManager::Link* link = mgr->link( c.m_hintID );
80 if ( link ) {
81 IRegistry* pReg = pObj->registry();
82 return pReg && link->path() == pReg->identifier();
83 }
84 }
85 }
86 }
87 return false;
88 }
89
90 // Extended equality check
91 bool SmartRefBase::isEqualEx( const ContainedObject* pObj, const SmartRefBase& c ) const
92 {
93 return isEqualEx( pObj->parent(), c ) && pObj->index() == c.m_linkID;
94 }
95
96 const std::string& SmartRefBase::path() const
97 {
98 static std::string s_empty_string{};
99 DataObject* source = nullptr;
100 if ( !m_data && m_contd ) m_data = m_contd->parent();
101 source = const_cast<DataObject*>( m_data );
102 if ( m_hintID != StreamBuffer::INVALID && source ) {
103 LinkManager* mgr = source->linkMgr();
104 if ( mgr ) {
105 LinkManager::Link* link = mgr->link( m_hintID );
106 if ( link ) return link->path();
107 }
108 }
109 return s_empty_string;
110 }
LinkManager::Link::path
const std::string & path() const
Access to path of object.
Definition: LinkManager.h:66
gaudirun.c
c
Definition: gaudirun.py:407
SmartRefBase::isEqualEx
bool isEqualEx(const DataObject *pObj, const SmartRefBase &c) const
Extended equality check.
Definition: SmartRefBase.cpp:72
LinkManager.h
SmartRefBase::accessData
const ContainedObject * accessData(const ContainedObject *typ) const
Load on demand of ContainedObject like references.
Definition: SmartRefBase.cpp:34
SmartRefBase::m_data
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
Definition: SmartRefBase.h:55
_Container
ObjectContainerBase _Container
Definition: SmartRefBase.cpp:23
SmartRefBase::m_hintID
long m_hintID
Object data: ID of the link hint to the identifiable object.
Definition: SmartRefBase.h:51
ContainedObject::index
virtual long index() const
Distance in the parent container.
Definition: ContainedObject.h:57
ObjectContainerBase.h
SmartRefBase
User example objects: SmartRefBase.
Definition: SmartRefBase.h:47
SmartRefBase.h
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:45
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:52
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:72
StreamBuffer.h
DataObject::linkMgr
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:74
std::string
STL class.
ObjectContainerBase::containedObject
virtual ContainedObject * containedObject(long dist) const =0
Pointer to an object of a given distance.
SmartRefBase::m_contd
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Definition: SmartRefBase.h:57
IDataProviderSvc.h
LinkManager::Link::setObject
void setObject(const DataObject *pObject)
Update object pointer.
Definition: LinkManager.h:61
SmartRefBase::path
const std::string & path() const
Shortcut to access the path to the linked object.
Definition: SmartRefBase.cpp:96
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
GaudiException.h
LinkManager::link
Link * link(long id)
Retrieve symbolic link identified by ID.
Definition: LinkManager.cpp:31
IRegistry::dataSvc
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
IRegistry.h
IRegistry
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
SmartRefBase::m_linkID
long m_linkID
Object data: ID of the object within the identifiable container (if any)
Definition: SmartRefBase.h:53
ContainedObject
All classes that their objects may be contained in an LHCb ObjectContainer (e.g.
Definition: ContainedObject.h:31
ContainedObject.h
ObjectContainerBase
ObjectContainerBase is the base class for Gaudi container classes.
Definition: ObjectContainerBase.h:19
StreamBuffer::INVALID
Definition: StreamBuffer.h:119
SmartRefBase::set
void set(DataObject *pObj, long hint_id, long link_id)
Setup smart reference when reading. Must be allowed from external sources.
Definition: SmartRefBase.cpp:26
LinkManager::Link::object
const DataObject * object() const
Const access to data object.
Definition: LinkManager.h:63
LinkManager::Link
Embedded class defining a symbolic link Note: No copy constructor; bitwise copy (done by the compiler...
Definition: LinkManager.h:32
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:29
LinkManager
A LinkManager is the object aggregated into a DataObject, which is responsible for the handling of no...
Definition: LinkManager.h:21
DataObject.h
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.