The Gaudi Framework  v36r7 (7f57a304)
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 * (c) Copyright 1998-2019 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 \***********************************************************************************/
11 // ====================================================================
12 // SmartRefBase.cpp
13 // --------------------------------------------------------------------
14 //
15 // Package : Root conversion example
16 //
17 // Author : Markus Frank
18 //
19 // ====================================================================
20 #define KERNEL_SMARTREFBASE_CPP 1
21 
22 // Framework include files
25 #include "GaudiKernel/DataObject.h"
28 #include "GaudiKernel/IRegistry.h"
32 
34 
36 void SmartRefBase::set( DataObject* pObj, long hint_id, long link_id ) {
37  m_data = pObj;
38  m_hintID = hint_id;
39  m_linkID = link_id;
40 }
41 
45  const _Container* cnt = dynamic_cast<const _Container*>( accessData( m_data ) );
46  if ( cnt ) return cnt->containedObject( m_linkID );
47  }
48  return nullptr;
49 }
50 
53  DataObject* target = nullptr;
54  DataObject* source = nullptr;
55  if ( !m_data && m_contd ) m_data = m_contd->parent();
56  source = const_cast<DataObject*>( m_data );
57  if ( m_hintID != StreamBuffer::INVALID && source ) {
58  LinkManager* mgr = source->linkMgr();
59  if ( mgr ) {
60  LinkManager::Link* link = mgr->link( m_hintID );
61  if ( link ) {
62  target = link->object();
63  if ( !target ) {
64  IRegistry* reg = source->registry();
65  if ( reg ) {
66  IDataProviderSvc* datasvc = reg->dataSvc();
67  if ( datasvc && datasvc->retrieveObject( link->path(), target ).isSuccess() ) { link->setObject( target ); }
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 && pObj ) {
79  DataObject* source = const_cast<DataObject*>( c.m_data );
80  if ( source ) {
81  LinkManager* mgr = source->linkMgr();
82  if ( mgr ) {
83  LinkManager::Link* link = mgr->link( c.m_hintID );
84  if ( link ) {
85  IRegistry* pReg = pObj->registry();
86  return pReg && link->path() == pReg->identifier();
87  }
88  }
89  }
90  }
91  return false;
92 }
93 
94 // Extended equality check
95 bool SmartRefBase::isEqualEx( const ContainedObject* pObj, const SmartRefBase& c ) const {
96  return isEqualEx( pObj->parent(), c ) && pObj->index() == c.m_linkID;
97 }
98 
100  static std::string s_empty_string{};
101  DataObject* source = nullptr;
102  if ( !m_data && m_contd ) m_data = m_contd->parent();
103  source = const_cast<DataObject*>( m_data );
104  if ( m_hintID != StreamBuffer::INVALID && source ) {
105  LinkManager* mgr = source->linkMgr();
106  if ( mgr ) {
107  LinkManager::Link* link = mgr->link( m_hintID );
108  if ( link ) return link->path();
109  }
110  }
111  return s_empty_string;
112 }
std::string
STL class.
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
GaudiException.h
gaudirun.c
c
Definition: gaudirun.py:525
IRegistry
Definition: IRegistry.h:32
StreamBuffer.h
SmartRefBase
User example objects: SmartRefBase.
Definition: SmartRefBase.h:57
IDataProviderSvc.h
SmartRefBase::m_linkID
long m_linkID
Object data: ID of the object within the identifiable container (if any)
Definition: SmartRefBase.h:62
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
_Container
ObjectContainerBase _Container
Definition: SmartRefBase.cpp:33
SmartRefBase::path
const std::string & path() const
Shortcut to access the path to the linked object.
Definition: SmartRefBase.cpp:99
SmartRefBase::m_data
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
Definition: SmartRefBase.h:64
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:36
DataObject::linkMgr
LinkManager * linkMgr() const
Retrieve Link manager.
Definition: DataObject.h:84
ContainedObject::index
virtual long index() const
Distance in the parent container.
Definition: ContainedObject.h:67
IRegistry.h
SmartRefBase::m_hintID
long m_hintID
Object data: ID of the link hint to the identifiable object.
Definition: SmartRefBase.h:60
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:62
DataObject.h
ObjectContainerBase
Definition: ObjectContainerBase.h:29
SmartRefBase::m_contd
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Definition: SmartRefBase.h:66
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
DataObject
Definition: DataObject.h:40
ObjectContainerBase.h
SmartRefBase::accessData
const ContainedObject * accessData(const ContainedObject *typ) const
Load on demand of ContainedObject like references.
Definition: SmartRefBase.cpp:43
IDataProviderSvc
Definition: IDataProviderSvc.h:53
SmartRefBase.h
SmartRefBase::isEqualEx
bool isEqualEx(const DataObject *pObj, const SmartRefBase &c) const
Extended equality check.
Definition: SmartRefBase.cpp:77
ObjectContainerBase::containedObject
virtual const ContainedObject * containedObject(long dist) const =0
Pointer to an object of a given distance.
ContainedObject.h
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:82
IRegistry::dataSvc
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
ContainedObject
Definition: ContainedObject.h:41
StreamBuffer::INVALID
@ INVALID
Definition: StreamBuffer.h:121