The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SmartDataObjectPtr.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 \***********************************************************************************/
11 #include <GaudiKernel/DataObject.h>
14 
16 
18 
20 StatusCode SmartDataObjectPtr::retrieve( IRegistry* pRegistry, std::string_view path, DataObject*& refpObject ) {
21  return ( m_dataProvider && pRegistry ) ? m_dataProvider->retrieveObject( pRegistry, path, refpObject )
23 }
24 
26 StatusCode SmartDataObjectPtr::retrieve( std::string_view fullPath, DataObject*& refpObject ) {
27  return m_dataProvider ? m_dataProvider->retrieveObject( fullPath, refpObject ) : StatusCode::FAILURE;
28 }
29 
31 StatusCode SmartDataObjectPtr::find( IRegistry* pDirectory, std::string_view path, DataObject*& refpObject ) {
32  return ( m_dataProvider && pDirectory ) ? m_dataProvider->findObject( pDirectory, path, refpObject )
34  ;
35 }
36 
38 StatusCode SmartDataObjectPtr::find( std::string_view fullPath, DataObject*& refpObject ) {
39  return m_dataProvider ? m_dataProvider->findObject( fullPath, refpObject ) : StatusCode::FAILURE;
40 }
41 
44  return ( m_dataProvider && pRegistry ) ? m_dataProvider->updateObject( pRegistry ) : StatusCode::FAILURE;
45 }
46 
48 StatusCode SmartDataObjectPtr::update( std::string_view fullPath ) {
50 }
51 
58  DataObject* pObj = nullptr;
59  m_status = ( !m_pRegistry ? retrieve( m_path, pObj ) : retrieve( m_pRegistry, m_path, pObj ) );
60  if ( m_status.isSuccess() ) {
61  m_pRegistry = pObj->registry();
62  m_path.clear();
63  }
64  return pObj;
65 }
66 
73  DataObject* pObj = nullptr;
74  m_status = ( m_pRegistry ? find( m_pRegistry, m_path, pObj ) : find( m_path, pObj ) );
75  if ( m_status.isSuccess() ) {
76  m_pRegistry = pObj->registry();
77  m_path.clear();
78  }
79  return pObj;
80 }
81 
88  DataObject* pObj = accessData(); // Have to load AND update if not present.
89  if ( m_status.isSuccess() ) {
91  if ( !m_status.isSuccess() ) pObj = nullptr;
92  }
93  return pObj;
94 }
95 
108 bool operator&&( SmartDataObjectPtr& object_1, SmartDataObjectPtr& object_2 ) {
109  return object_1.accessData() && object_2.accessData();
110 }
111 
128 bool operator||( SmartDataObjectPtr& object_1, SmartDataObjectPtr& object_2 ) {
129  return object_1.accessData() || object_2.accessData();
130 }
SmartDataObjectPtr::ObjectLoader::access
static AccessFunction access()
Definition: SmartDataObjectPtr.cpp:15
SmartDataObjectPtr::retrieve
static DataObject * retrieve(SmartDataObjectPtr *ptr)
Static Object retrieval method.
Definition: SmartDataObjectPtr.h:94
SmartDataObjectPtr::m_dataProvider
IDataProviderSvc * m_dataProvider
Pointer to contained object.
Definition: SmartDataObjectPtr.h:165
SmartDataObjectPtr::m_status
StatusCode m_status
Keep track of the last error.
Definition: SmartDataObjectPtr.h:169
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
SmartDataObjectPtr::findObject
DataObject * findObject()
Object find method.
Definition: SmartDataObjectPtr.cpp:72
operator||
bool operator||(SmartDataObjectPtr &object_1, SmartDataObjectPtr &object_2)
Helper to test Smart data objects efficiently This construct allows statements like: SmartEvtDataPtr<...
Definition: SmartDataObjectPtr.cpp:128
SmartDataObjectPtr::AccessFunction
DataObject *(*)(SmartDataObjectPtr *ptr) AccessFunction
Definition: SmartDataObjectPtr.h:39
IRegistry
Definition: IRegistry.h:29
IDataProviderSvc.h
SmartDataObjectPtr::find
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
Definition: SmartDataObjectPtr.h:97
operator&&
bool operator&&(SmartDataObjectPtr &object_1, SmartDataObjectPtr &object_2)
Helper to test Smart data objects efficiently This construct allows statements like: SmartEvtDataPtr<...
Definition: SmartDataObjectPtr.cpp:108
SmartDataObjectPtr::m_pRegistry
IRegistry * m_pRegistry
Pointer to the data registry containing the object.
Definition: SmartDataObjectPtr.h:167
SmartDataObjectPtr.h
StatusCode
Definition: StatusCode.h:64
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
SmartDataObjectPtr::updateObject
DataObject * updateObject()
Object update method.
Definition: SmartDataObjectPtr.cpp:87
SmartDataObjectPtr
Definition: SmartDataObjectPtr.h:37
SmartDataObjectPtr::retrieveObject
DataObject * retrieveObject()
Object retrieve method.
Definition: SmartDataObjectPtr.cpp:57
SmartDataObjectPtr::update
static DataObject * update(SmartDataObjectPtr *ptr)
Static Object update method.
Definition: SmartDataObjectPtr.h:100
DataObject.h
DataObject
Definition: DataObject.h:37
SmartDataObjectPtr::ObjectFinder::access
static AccessFunction access()
Definition: SmartDataObjectPtr.cpp:17
SmartDataObjectPtr::m_path
std::string m_path
Path to object.
Definition: SmartDataObjectPtr.h:171
SmartDataObjectPtr::path
const std::string & path() const
Path name.
Definition: SmartDataObjectPtr.h:76
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:100
DataObject::registry
IRegistry * registry() const
Get pointer to Registry.
Definition: DataObject.h:79
IDataProviderSvc::updateObject
virtual StatusCode updateObject(IRegistry *pDirectory)=0
Update object identified by its directory entry.
IDataProviderSvc::findObject
virtual StatusCode findObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Find object identified by its directory entry.
SmartDataObjectPtr::accessData
DataObject * accessData()
Static Object retrieval method: must call specific function.
Definition: SmartDataObjectPtr.h:91