ATLAS Offline Software
Loading...
Searching...
No Matches
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
8
9HelloAlg::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
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()) {
58 << ": Failed to retrieve tool "
59 << m_myPrivateHelloTool.type());
60 return StatusCode::FAILURE;
61 } else {
63 << ": Retrieved tool " << m_myPrivateHelloTool.type());
64 }
65
66 // or just use ATH_CHECK to be less verbose
68
69 return StatusCode::SUCCESS;
70}
71
72StatusCode HelloAlg::execute() {
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
96StatusCode 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}
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
MsgStream & msg() const
Gaudi::Property< Matrix_t > m_myMatrix
Definition HelloAlg.h:40
ToolHandle< IHelloTool > m_myPrivateHelloTool
Definition HelloAlg.h:48
Gaudi::Property< bool > m_myBool
Definition HelloAlg.h:30
Gaudi::Property< int > m_myInt
Definition HelloAlg.h:29
Table_t m_myTable
Definition HelloAlg.h:45
PublicToolHandle< IHelloTool > m_myPublicHelloTool
Definition HelloAlg.h:51
virtual StatusCode finalize() override
Definition HelloAlg.cxx:96
virtual StatusCode execute() override
Definition HelloAlg.cxx:72
Gaudi::Property< std::vector< std::string > > m_myStringVec
Definition HelloAlg.h:33
Gaudi::Property< double > m_myDouble
Definition HelloAlg.h:31
HelloAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition HelloAlg.cxx:9
virtual StatusCode initialize() override
Definition HelloAlg.cxx:25
Gaudi::Property< Dict_t > m_myDict
Definition HelloAlg.h:37