Loading [MathJax]/jax/input/TeX/config.js
The Gaudi Framework  master (d98a2936)
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-2025 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 \***********************************************************************************/
12 #include <GaudiKernel/DataObject.h>
15 #include <GaudiKernel/IRegistry.h>
20 
22 
24 void SmartRefBase::set( DataObject* pObj, long hint_id, long link_id ) {
25  m_data = pObj;
26  m_hintID = hint_id;
27  m_linkID = link_id;
28 }
29 
33  const _Container* cnt = dynamic_cast<const _Container*>( accessData( m_data ) );
34  if ( cnt ) return cnt->containedObject( m_linkID );
35  }
36  return nullptr;
37 }
38 
41  if ( !m_data && m_contd ) m_data = m_contd->parent();
42  DataObject* source = const_cast<DataObject*>( m_data );
43  if ( m_hintID == StreamBuffer::INVALID || !source ) return nullptr;
44  LinkManager* mgr = source->linkMgr();
45  if ( !mgr ) return nullptr;
46  LinkManager::Link* link = mgr->link( m_hintID );
47  if ( !link ) return nullptr;
48  DataObject* target = link->object();
49  if ( !target ) {
50  IRegistry* reg = source->registry();
51  if ( !reg ) return nullptr;
52  IDataProviderSvc* datasvc = reg->dataSvc();
53  if ( datasvc && datasvc->retrieveObject( link->path(), target ).isSuccess() ) { link->setObject( target ); }
54  }
55  return target;
56 }
57 
58 // Extended equality check
59 bool SmartRefBase::isEqualEx( const DataObject* pObj, const SmartRefBase& c ) const {
60  if ( c.m_hintID != StreamBuffer::INVALID && pObj ) {
61  DataObject* source = const_cast<DataObject*>( c.m_data );
62  if ( source ) {
63  LinkManager* mgr = source->linkMgr();
64  if ( mgr ) {
65  const LinkManager::Link* link = mgr->link( c.m_hintID );
66  if ( link ) {
67  IRegistry* pReg = pObj->registry();
68  return pReg && link->path() == pReg->identifier();
69  }
70  }
71  }
72  }
73  return false;
74 }
75 
76 // Extended equality check
77 bool SmartRefBase::isEqualEx( const ContainedObject* pObj, const SmartRefBase& c ) const {
78  return isEqualEx( pObj->parent(), c ) && pObj->index() == c.m_linkID;
79 }
80 
81 const std::string& SmartRefBase::path() const {
82  static std::string s_empty_string{};
83  DataObject* source = nullptr;
84  if ( !m_data && m_contd ) m_data = m_contd->parent();
85  source = const_cast<DataObject*>( m_data );
86  if ( m_hintID != StreamBuffer::INVALID && source ) {
87  LinkManager* mgr = source->linkMgr();
88  if ( mgr ) {
89  const LinkManager::Link* link = mgr->link( m_hintID );
90  if ( link ) return link->path();
91  }
92  }
93  return s_empty_string;
94 }
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
GaudiException.h
gaudirun.c
c
Definition: gaudirun.py:525
IRegistry
Definition: IRegistry.h:29
StreamBuffer.h
SmartRefBase
User example objects: SmartRefBase.
Definition: SmartRefBase.h:45
IDataProviderSvc.h
SmartRefBase::m_linkID
long m_linkID
Object data: ID of the object within the identifiable container (if any)
Definition: SmartRefBase.h:50
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:21
SmartRefBase::path
const std::string & path() const
Shortcut to access the path to the linked object.
Definition: SmartRefBase.cpp:81
SmartRefBase::m_data
const DataObject * m_data
Object data: Pointer to the identifiable object the link originates.
Definition: SmartRefBase.h:52
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:24
ContainedObject::index
virtual long index() const
Distance in the parent container.
Definition: ContainedObject.h:64
IRegistry.h
SmartRefBase::m_hintID
long m_hintID
Object data: ID of the link hint to the identifiable object.
Definition: SmartRefBase.h:48
ContainedObject::parent
const ObjectContainerBase * parent() const
Access to parent object.
Definition: ContainedObject.h:59
DataObject.h
ObjectContainerBase
Definition: ObjectContainerBase.h:26
SmartRefBase::m_contd
const ContainedObject * m_contd
Object data: Pointer to the Contained object (if applicable)
Definition: SmartRefBase.h:54
IRegistry::identifier
virtual const id_type & identifier() const =0
Full identifier (or key)
DataObject
Definition: DataObject.h:37
ObjectContainerBase.h
SmartRefBase::accessData
const ContainedObject * accessData(const ContainedObject *typ) const
Load on demand of ContainedObject like references.
Definition: SmartRefBase.cpp:31
IDataProviderSvc
Definition: IDataProviderSvc.h:48
SmartRefBase.h
DataObject::linkMgr
LinkManager * linkMgr()
Retrieve Link manager.
Definition: DataObject.h:81
SmartRefBase::isEqualEx
bool isEqualEx(const DataObject *pObj, const SmartRefBase &c) const
Extended equality check.
Definition: SmartRefBase.cpp:59
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:79
IRegistry::dataSvc
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
ContainedObject
Definition: ContainedObject.h:37
StreamBuffer::INVALID
@ INVALID
Definition: StreamBuffer.h:117