ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaExamples
AthExHelloWorld
src
HelloAlg.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
HelloAlg.h
"
6
7
#include <
AthExHelloWorld/IHelloTool.h
>
8
9
HelloAlg::HelloAlg
(
const
std::string &name, ISvcLocator *pSvcLocator)
10
:
AthAlgorithm
(name, pSvcLocator),
m_myTable
() {
11
12
// override some default values (headers are preferred)
13
m_myDict
[
"Bonjour"
] =
"Guten Tag"
;
14
m_myDict
[
"Good Morning"
] =
"Bonjour"
;
15
m_myDict
[
"one"
] =
"uno"
;
16
17
// legacy way of properties (headers are preferred)
18
declareProperty
(
"MyTable"
,
m_myTable
,
"A table of <double,double>"
);
19
// some default values
20
m_myTable
.push_back(std::make_pair(1., 1.));
21
m_myTable
.push_back(std::make_pair(2., 2. * 2.));
22
m_myTable
.push_back(std::make_pair(3., 3. * 3.));
23
}
24
25
StatusCode
HelloAlg::initialize
() {
26
27
// Print out the property values
28
ATH_MSG_INFO
(
" MyInt = {}"
,
m_myInt
.value());
29
ATH_MSG_INFO
(
" MyBool = {}"
,
m_myBool
.value());
30
ATH_MSG_INFO
(
" MyDouble = {}"
,
m_myDouble
.value());
31
32
for
(
size_t
i = 0; i <
m_myStringVec
.size(); i++) {
33
ATH_MSG_INFO
(
" MyStringVec[{}] = {}"
, i,
m_myStringVec
[i]);
34
}
35
36
for
(
const
auto
&[key, value] :
m_myDict
) {
37
ATH_MSG_INFO
(
" MyDict['{}'] = '{}'"
, key, value);
38
}
39
for
(
const
auto
&[key, value] :
m_myTable
) {
40
ATH_MSG_INFO
(
" MyTable['{}'] = '{}'"
, key, value);
41
}
42
for
(
size_t
row = 0; row <
m_myMatrix
.size(); row++) {
43
msg
(MSG::INFO) <<
" MyMatrix["
<< row <<
"] = [ "
;
44
for
(
double
value :
m_myMatrix
[row]) {
45
msg
() << value <<
" "
;
46
}
47
msg
() <<
"]"
<<
endmsg
;
48
}
49
50
ATH_MSG_INFO
(
" {} = {}"
,
51
m_myPrivateHelloTool
.propertyName(),
52
m_myPrivateHelloTool
.type());
53
ATH_MSG_INFO
(
" {} = {}"
,
54
m_myPublicHelloTool
.propertyName(),
55
m_myPublicHelloTool
.type());
56
57
// Part 3: Retrieve the tools using the ToolHandles
58
if
(
m_myPrivateHelloTool
.retrieve().isFailure()) {
59
ATH_MSG_FATAL
(
"{}: Failed to retrieve tool {}"
,
60
m_myPrivateHelloTool
.propertyName(),
61
m_myPrivateHelloTool
.type());
62
return
StatusCode::FAILURE;
63
}
else
{
64
ATH_MSG_INFO
(
"{}: Retrieved tool {}"
,
65
m_myPrivateHelloTool
.propertyName(),
66
m_myPrivateHelloTool
.type());
67
}
68
69
// or just use ATH_CHECK to be less verbose
70
ATH_CHECK
(
m_myPublicHelloTool
.retrieve());
71
72
return
StatusCode::SUCCESS;
73
}
74
75
StatusCode
HelloAlg::execute
(
const
EventContext&
/*ctx*/
) {
76
// Print where you are if needed (should never be INFO)
77
ATH_MSG_DEBUG
(
"execute()"
);
78
79
// Print out the different levels of messages
80
ATH_MSG_DEBUG
(
"A DEBUG message"
);
81
ATH_MSG_INFO
(
"An INFO message"
);
82
ATH_MSG_WARNING
(
"A WARNING message"
);
83
ATH_MSG_ERROR
(
"An ERROR message"
);
84
ATH_MSG_FATAL
(
"A FATAL error message"
);
85
86
// Let publicly declared tool say something
87
ATH_MSG_INFO
(
"Let the tool {} say something:"
,
88
m_myPublicHelloTool
.propertyName());
89
ATH_CHECK
(
m_myPublicHelloTool
->saySomething());
90
91
// Let privately declared tool say something
92
ATH_MSG_INFO
(
"Let the tool {} say something:"
,
93
m_myPrivateHelloTool
.propertyName());
94
ATH_CHECK
(
m_myPrivateHelloTool
->saySomething());
95
96
return
StatusCode::SUCCESS;
97
}
98
99
StatusCode
HelloAlg::finalize
() {
100
// Just an example: if there is nothing to be done do not re-implement finalize
101
ATH_MSG_DEBUG
(
"finalize()"
);
102
103
return
StatusCode::SUCCESS;
104
}
endmsg
#define endmsg
Definition
AnalysisConfig_Ntuple.cxx:54
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x,...)
Definition
AthMsgStreamMacros.h:46
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x,...)
Definition
AthMsgStreamMacros.h:48
HelloAlg.h
IHelloTool.h
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Definition
AthCommonDataStore.h:145
AthCommonAlgorithm< Gaudi::Algorithm >::msg
MsgStream & msg() const
Definition
AthCommonMsg.h:24
HelloAlg::m_myMatrix
Gaudi::Property< Matrix_t > m_myMatrix
Definition
HelloAlg.h:40
HelloAlg::m_myPrivateHelloTool
ToolHandle< IHelloTool > m_myPrivateHelloTool
Definition
HelloAlg.h:48
HelloAlg::m_myBool
Gaudi::Property< bool > m_myBool
Definition
HelloAlg.h:30
HelloAlg::m_myInt
Gaudi::Property< int > m_myInt
Definition
HelloAlg.h:29
HelloAlg::m_myTable
Table_t m_myTable
Definition
HelloAlg.h:45
HelloAlg::m_myPublicHelloTool
PublicToolHandle< IHelloTool > m_myPublicHelloTool
Definition
HelloAlg.h:51
HelloAlg::finalize
virtual StatusCode finalize() override
Definition
HelloAlg.cxx:99
HelloAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
HelloAlg.cxx:75
HelloAlg::m_myStringVec
Gaudi::Property< std::vector< std::string > > m_myStringVec
Definition
HelloAlg.h:33
HelloAlg::m_myDouble
Gaudi::Property< double > m_myDouble
Definition
HelloAlg.h:31
HelloAlg::HelloAlg
HelloAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition
HelloAlg.cxx:9
HelloAlg::initialize
virtual StatusCode initialize() override
Definition
HelloAlg.cxx:25
HelloAlg::m_myDict
Gaudi::Property< Dict_t > m_myDict
Definition
HelloAlg.h:37
Generated on
for ATLAS Offline Software by
1.17.0