The Gaudi Framework  master (37c0b60a)
SmartRefBase.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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
24 #include <GaudiKernel/DataObject.h>
27 #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  if ( !m_data && m_contd ) m_data = m_contd->parent();
54  DataObject* source = const_cast<DataObject*>( m_data );
55  if ( m_hintID == StreamBuffer::INVALID || !source ) return nullptr;
56  LinkManager* mgr = source->linkMgr();
57  if ( !mgr ) return nullptr;
58  LinkManager::Link* link = mgr->link( m_hintID );
59  if ( !link ) return nullptr;
60  DataObject* target = link->object();
61  if ( !target ) {
62  IRegistry* reg = source->registry();
63  if ( !reg ) return nullptr;
64  IDataProviderSvc* datasvc = reg->dataSvc();
65  if ( datasvc && datasvc->retrieveObject( link->path(), target ).isSuccess() ) { link->setObject( target ); }
66  }
67  return target;
68 }
69 
70 // Extended equality check
71 bool SmartRefBase::isEqualEx( const DataObject* pObj, const SmartRefBase& c ) const {
72  if ( c.m_hintID != StreamBuffer::INVALID && pObj ) {
73  DataObject* source = const_cast<DataObject*>( c.m_data );
74  if ( source ) {
75  LinkManager* mgr = source->linkMgr();
76  if ( mgr ) {
77  const LinkManager::Link* link = mgr->link( c.m_hintID );
78  if ( link ) {
79  IRegistry* pReg = pObj->registry();
80  return pReg && link->path() == pReg->identifier();
81  }
82  }
83  }
84  }
85  return false;
86 }
87 
88 // Extended equality check
89 bool SmartRefBase::isEqualEx( const ContainedObject* pObj, const SmartRefBase& c ) const {
90  return isEqualEx( pObj->parent(), c ) && pObj->index() == c.m_linkID;
91 }
92 
94  static std::string s_empty_string{};
95  DataObject* source = nullptr;
96  if ( !m_data && m_contd ) m_data = m_contd->parent();
97  source = const_cast<DataObject*>( m_data );
98  if ( m_hintID != StreamBuffer::INVALID && source ) {
99  LinkManager* mgr = source->linkMgr();
100  if ( mgr ) {
101  const LinkManager::Link* link = mgr->link( m_hintID );
102  if ( link ) return link->path();
103  }
104  }
105  return s_empty_string;
106 }
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
compareOutputFiles.target
target
Definition: compareOutputFiles.py:489
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:93
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
ContainedObject::index
virtual long index() const
Distance in the parent container.
Definition: ContainedObject.h:68
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:63
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:36
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
DataObject::linkMgr
LinkManager * linkMgr()
Retrieve Link manager.
Definition: DataObject.h:80
SmartRefBase::isEqualEx
bool isEqualEx(const DataObject *pObj, const SmartRefBase &c) const
Extended equality check.
Definition: SmartRefBase.cpp:71
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:78
IRegistry::dataSvc
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
ContainedObject
Definition: ContainedObject.h:41
StreamBuffer::INVALID
@ INVALID
Definition: StreamBuffer.h:121