The Gaudi Framework
master (53dee381)
Toggle main menu visibility
Loading...
Searching...
No Matches
DataObjectHandleBase.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2026 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 <
Gaudi/Algorithm.h
>
12
#include <
GaudiKernel/AlgTool.h
>
13
#include <
GaudiKernel/DataObjectHandleBase.h
>
14
#include <
GaudiKernel/IDataProviderSvc.h
>
15
#include <
GaudiKernel/SerializeSTL.h
>
16
#include <
GaudiKernel/ServiceLocatorHelper.h
>
17
18
#include <boost/tokenizer.hpp>
19
#include <ostream>
20
#include <sstream>
21
#include <string>
22
23
const
DataObjID
INVALID_DATAOBJID
=
DataObjID
();
24
25
//---------------------------------------------------------------------------
26
DataObjectHandleBase::DataObjectHandleBase
(
DataObjectHandleBase
&& other )
27
:
Gaudi
::
DataHandle
( other )
28
,
m_EDS
(
std
::move( other.
m_EDS
) )
29
,
m_MS
(
std
::move( other.
m_MS
) )
30
,
m_init
( other.
m_init
) {
31
if
( !
m_owner
) {
32
throw
GaudiException
(
"DataObjectHandleBase requires a non-null owner"
,
"Invalid Owner"
,
StatusCode::FAILURE
);
33
}
34
m_owner
->declare( *
this
);
35
}
36
37
//---------------------------------------------------------------------------
38
DataObjectHandleBase
&
DataObjectHandleBase::operator=
(
const
DataObjectHandleBase
& other ) {
39
// FIXME: operator= should not change our owner, only our 'value'
40
Gaudi::DataHandle::operator=( other );
41
m_EDS
= other.
m_EDS
;
42
m_MS
= other.
m_MS
;
43
m_init
= other.
m_init
;
44
return
*
this
;
45
}
46
47
//---------------------------------------------------------------------------
48
DataObjectHandleBase::DataObjectHandleBase
(
DataObjID
k,
Gaudi::DataHandle::Mode
a,
IDataHandleHolder
*
owner
)
49
:
Gaudi
::
DataHandle
(
std
::move( k ), a,
owner
) {
50
if
( !
m_owner
) {
51
throw
GaudiException
(
"DataObjectHandleBase requires a non-null owner"
,
"Invalid Owner"
,
StatusCode::FAILURE
);
52
}
53
m_owner
->declare( *
this
);
54
}
55
56
//---------------------------------------------------------------------------
57
58
DataObjectHandleBase::DataObjectHandleBase
( std::string k,
Gaudi::DataHandle::Mode
a,
IDataHandleHolder
*
owner
)
59
:
DataObjectHandleBase
(
DataObjID
{
std
::move( k ) }, a,
owner
) {}
60
61
//---------------------------------------------------------------------------
62
DataObjectHandleBase::~DataObjectHandleBase
() {
63
// Regular DataObjectHandles are declared to an owner during construction,
64
// but destruction must remain harmless for exceptional or moved-from states.
65
if
(
owner
() )
owner
()->
renounce
( *
this
);
66
}
67
68
//---------------------------------------------------------------------------
69
DataObject
*
DataObjectHandleBase::fetch
()
const
{
70
// convenience towards users -- remind them to register
71
// but as m_MS is not yet set, we cannot use a MsgStream...
72
if
( !
m_init
) {
73
std::cerr << (
owner
() ?
owner
()->
name
() :
"<UNKNOWN>:"
) <<
"DataObjectHandle: uninitialized data handle"
74
<< std::endl;
75
}
76
DataObject
* p =
nullptr
;
77
m_EDS
->retrieveObject(
objKey
(), p ).ignore();
78
return
p;
79
}
80
81
//---------------------------------------------------------------------------
82
83
bool
DataObjectHandleBase::init
() {
84
if
(
m_init
)
return
true
;
// initialization already done
85
86
if
( !
owner
() )
return
false
;
87
88
Gaudi::Algorithm
* algorithm =
dynamic_cast<
Gaudi::Algorithm
*
>
(
owner
() );
89
if
( algorithm ) {
90
// Fetch the event Data Service from the algorithm
91
m_EDS
= algorithm->
evtSvc
();
92
m_MS
= algorithm->
msgSvc
();
93
}
else
{
94
AlgTool
* tool =
dynamic_cast<
AlgTool
*
>
(
owner
() );
95
if
( tool ) {
96
m_EDS
= tool->evtSvc();
97
m_MS
= tool->msgSvc();
98
}
else
{
99
throw
GaudiException
(
"owner is neither AlgTool nor Gaudi::Algorithm"
,
"Invalid Cast"
,
StatusCode::FAILURE
);
100
}
101
}
102
m_init
=
true
;
103
return
true
;
104
}
105
106
//---------------------------------------------------------------------------
107
108
bool
DataObjectHandleBase::isValid
()
const
{
return
fullKey
() !=
INVALID_DATAOBJID
; }
109
110
//---------------------------------------------------------------------------
111
112
std::ostream&
operator<<
( std::ostream& str,
const
DataObjectHandleBase
& d ) {
113
114
str << d.
fullKey
() <<
" m: "
<< d.
mode
();
115
if
( d.
owner
() ) str <<
" o: "
<< d.
owner
()->
name
();
116
return
str;
117
}
AlgTool.h
INVALID_DATAOBJID
const DataObjID INVALID_DATAOBJID
Definition
DataObjectHandleBase.cpp:23
operator<<
std::ostream & operator<<(std::ostream &str, const DataObjectHandleBase &d)
Definition
DataObjectHandleBase.cpp:112
DataObjectHandleBase.h
Algorithm.h
IDataProviderSvc.h
SerializeSTL.h
Provide serialization function (output only) for some common STL classes (vectors,...
ServiceLocatorHelper.h
AlgTool
Base class from which all the concrete tool classes should be derived.
Definition
AlgTool.h:55
CommonMessagingBase::msgSvc
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition
CommonMessaging.h:79
DataObjID
Definition
DataObjID.h:47
DataObjectHandleBase::m_init
bool m_init
Definition
DataObjectHandleBase.h:58
DataObjectHandleBase::init
bool init() override
Definition
DataObjectHandleBase.cpp:83
DataObjectHandleBase::m_EDS
SmartIF< IDataProviderSvc > m_EDS
Definition
DataObjectHandleBase.h:55
DataObjectHandleBase::m_MS
SmartIF< IMessageSvc > m_MS
Definition
DataObjectHandleBase.h:56
DataObjectHandleBase::DataObjectHandleBase
DataObjectHandleBase(DataObjID k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
Definition
DataObjectHandleBase.cpp:48
DataObjectHandleBase::isValid
bool isValid() const
Definition
DataObjectHandleBase.cpp:108
DataObjectHandleBase::~DataObjectHandleBase
~DataObjectHandleBase() override
Definition
DataObjectHandleBase.cpp:62
DataObjectHandleBase::fetch
DataObject * fetch() const
Definition
DataObjectHandleBase.cpp:69
DataObjectHandleBase::operator=
DataObjectHandleBase & operator=(const DataObjectHandleBase &)
Definition
DataObjectHandleBase.cpp:38
DataObjectHandle::DataObjectHandleBase
DataObjectHandleBase(DataObjID k, Gaudi::DataHandle::Mode a, IDataHandleHolder *owner)
Definition
DataObjectHandleBase.cpp:48
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition
DataObject.h:37
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition
Algorithm.h:87
Gaudi::Algorithm::evtSvc
SmartIF< IDataProviderSvc > & evtSvc() const
shortcut for method eventSvc
Definition
Algorithm.h:233
Gaudi::DataHandle::m_owner
IDataHandleHolder * m_owner
Definition
DataHandle.h:86
Gaudi::DataHandle::owner
virtual IDataHandleHolder * owner() const
Definition
DataHandle.h:58
Gaudi::DataHandle::objKey
virtual const std::string & objKey() const
Definition
DataHandle.h:65
Gaudi::DataHandle::mode
virtual Mode mode() const
Definition
DataHandle.h:60
Gaudi::DataHandle::fullKey
virtual const DataObjID & fullKey() const
Definition
DataHandle.h:66
Gaudi::DataHandle::DataHandle
DataHandle(DataObjID k, Mode a=Reader, IDataHandleHolder *owner=nullptr)
Definition
DataHandle.h:47
Gaudi::DataHandle::Mode
Mode
Definition
DataHandle.h:45
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
IDataHandleHolder
Definition
IDataHandleHolder.h:23
IDataHandleHolder::renounce
virtual void renounce(Gaudi::DataHandle &)=0
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
std
STL namespace.
GaudiKernel
src
Lib
DataObjectHandleBase.cpp
Generated on
for The Gaudi Framework by
1.17.0