All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SmartRefBase.cpp
Go to the documentation of this file.
1 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/SmartRefBase.cpp,v 1.8 2005/05/10 12:24:16 hmd Exp $
2 // ====================================================================
3 // SmartRefBase.cpp
4 // --------------------------------------------------------------------
5 //
6 // Package : Root conversion example
7 //
8 // Author : Markus Frank
9 //
10 // ====================================================================
11 #define KERNEL_SMARTREFBASE_CPP 1
12 // $Header: /tmp/svngaudi/tmp.jEpFh25751/Gaudi/GaudiKernel/src/Lib/SmartRefBase.cpp,v 1.8 2005/05/10 12:24:16 hmd Exp $
13 
14 // Framework include files
17 #include "GaudiKernel/IRegistry.h"
18 #include "GaudiKernel/DataObject.h"
24 
26 
28 void SmartRefBase::set(DataObject* pObj, long hint_id, long link_id) {
29  m_data = pObj;
30  m_hintID = hint_id;
31  m_linkID = link_id;
32 }
33 
37  const _Container* cnt = dynamic_cast<const _Container*>(accessData(m_data));
38  if ( 0 != cnt ) {
39  return cnt->containedObject(m_linkID);
40  }
41  }
42  return 0;
43 }
44 
47  DataObject* target = 0;
48  DataObject* source =0;
49  if ( 0 == m_data && 0 != m_contd ) {
50  m_data = m_contd->parent();
51  }
52  source = const_cast<DataObject*>(m_data);
53  if ( m_hintID != StreamBuffer::INVALID && source != 0 ) {
54  LinkManager* mgr = source->linkMgr();
55  if ( 0 != mgr ) {
56  LinkManager::Link* link = mgr->link(m_hintID);
57  if ( 0 != link ) {
58  target = link->object();
59  if ( 0 == target ) {
60  IRegistry* reg = source->registry();
61  if ( 0 != reg ) {
62  IDataProviderSvc* datasvc = reg->dataSvc();
63  if ( 0 != datasvc ) {
64  if ( datasvc->retrieveObject(link->path(), target).isSuccess() ) {
65  link->setObject(target);
66  }
67  }
68  }
69  }
70  }
71  }
72  }
73  return target;
74 }
75 
76 // Extended equality check
77 bool SmartRefBase::isEqualEx(const DataObject* pObj, const SmartRefBase& c) const {
78  if ( c.m_hintID != StreamBuffer::INVALID && 0 != pObj ) {
79  DataObject* source = const_cast<DataObject*>(c.m_data);
80  if ( 0 != source ) {
81  LinkManager* mgr = source->linkMgr();
82  if ( 0 != mgr ) {
83  LinkManager::Link* link = mgr->link(c.m_hintID);
84  if ( 0 != link ) {
85  IRegistry* pReg = pObj->registry();
86  if ( pReg != 0 ) {
87  return link->path() == pReg->identifier();
88  }
89  }
90  }
91  }
92  }
93  return false;
94 }
95 
96 // Extended equality check
97 bool SmartRefBase::isEqualEx(const ContainedObject* pObj, const SmartRefBase& c) const {
98  if ( isEqualEx(pObj->parent(), c) ) {
99  return pObj->index() == c.m_linkID;
100  }
101  return false;
102 }
103 
104 const std::string &SmartRefBase::path () const {
105  static std::string s_empty_string = std::string();
106  DataObject *source = 0;
107  if ( 0 == m_data && 0 != m_contd ) {
108  m_data = m_contd->parent();
109  }
110  source = const_cast<DataObject*>(m_data);
111  if ( m_hintID != StreamBuffer::INVALID && source != 0 ) {
112  LinkManager* mgr = source->linkMgr();
113  if ( 0 != mgr ) {
114  LinkManager::Link* link = mgr->link(m_hintID);
115  if ( 0 != link )
116  return link->path();
117  }
118  }
119  return s_empty_string;
120 }
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
tuple c
Definition: gaudirun.py:341
virtual long index() const
Distance in the parent container.
virtual ContainedObject * containedObject(long dist) const =0
Pointer to an object of a given distance.
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:69
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:73
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.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
Definition: IRegistry.h:22
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.
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
virtual const id_type & identifier() const =0
Full identifier (or key)
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:31
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.