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-2024 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() <<
endmsg
29
<<
" MyBool = "
<<
m_myBool
.value() <<
endmsg
30
<<
" 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
(
" "
<<
m_myPrivateHelloTool
.propertyName() <<
" = "
51
<<
m_myPrivateHelloTool
.type() <<
endmsg
<<
" "
52
<<
m_myPublicHelloTool
.propertyName() <<
" = "
53
<<
m_myPublicHelloTool
.type());
54
55
// Part 3: Retrieve the tools using the ToolHandles
56
if
(
m_myPrivateHelloTool
.retrieve().isFailure()) {
57
ATH_MSG_FATAL
(
m_myPrivateHelloTool
.propertyName()
58
<<
": Failed to retrieve tool "
59
<<
m_myPrivateHelloTool
.type());
60
return
StatusCode::FAILURE;
61
}
else
{
62
ATH_MSG_INFO
(
m_myPrivateHelloTool
.propertyName()
63
<<
": Retrieved tool "
<<
m_myPrivateHelloTool
.type());
64
}
65
66
// or just use ATH_CHECK to be less verbose
67
ATH_CHECK
(
m_myPublicHelloTool
.retrieve());
68
69
return
StatusCode::SUCCESS;
70
}
71
72
StatusCode
HelloAlg::execute
(
const
EventContext&
/*ctx*/
) {
73
// Print where you are if needed (should never be INFO)
74
ATH_MSG_DEBUG
(
"execute()"
);
75
76
// Print out the different levels of messages
77
ATH_MSG_DEBUG
(
"A DEBUG message"
);
78
ATH_MSG_INFO
(
"An INFO message"
);
79
ATH_MSG_WARNING
(
"A WARNING message"
);
80
ATH_MSG_ERROR
(
"An ERROR message"
);
81
ATH_MSG_FATAL
(
"A FATAL error message"
);
82
83
// Let publicly declared tool say something
84
ATH_MSG_INFO
(
"Let the tool "
<<
m_myPublicHelloTool
.propertyName()
85
<<
" say something:"
);
86
ATH_CHECK
(
m_myPublicHelloTool
->saySomething());
87
88
// Let privately declared tool say something
89
ATH_MSG_INFO
(
"Let the tool "
<<
m_myPrivateHelloTool
.propertyName()
90
<<
" say something:"
);
91
ATH_CHECK
(
m_myPrivateHelloTool
->saySomething());
92
93
return
StatusCode::SUCCESS;
94
}
95
96
StatusCode
HelloAlg::finalize
() {
97
// Just an example: if there is nothing to be done do not re-implement finalize
98
ATH_MSG_DEBUG
(
"finalize()"
);
99
100
return
StatusCode::SUCCESS;
101
}
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_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition
AthMsgStreamMacros.h:34
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition
AthMsgStreamMacros.h:32
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
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:96
HelloAlg::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
HelloAlg.cxx:72
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