The Gaudi Framework  master (37c0b60a)
bug34121_MyAlgorithm.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 files
12 #include <GaudiKernel/Algorithm.h>
13 #include <GaudiKernel/DataObject.h>
15 #include <GaudiKernel/IToolSvc.h>
16 #include <GaudiKernel/MsgStream.h>
17 
18 #include "../AlgTools/IMyTool.h"
19 
20 namespace bug_34121 {
21 
22  class MyAlgorithm : public Algorithm {
23  public:
26 
28  StatusCode initialize() override;
29  StatusCode execute() override;
30  StatusCode finalize() override;
31 
32  private:
33  Gaudi::Property<std::string> m_toolName{ this, "Tool", "bug_34121::Tool", "Type of the tool to use" };
34  IMyTool* m_tool = nullptr;
35  };
36 
37  //------------------------------------------------------------------------------
39  //------------------------------------------------------------------------------
40 
41  StatusCode sc;
42  info() << "initializing...." << endmsg;
43 
44  sc = toolSvc()->retrieveTool( m_toolName, m_tool, this );
45  if ( sc.isFailure() ) {
46  error() << "Error retrieving the tool" << endmsg;
47  return sc;
48  }
49  info() << "....initialization done" << endmsg;
50 
51  return StatusCode::SUCCESS;
52  }
53 
54  //------------------------------------------------------------------------------
56  //------------------------------------------------------------------------------
57  info() << "executing...." << endmsg;
58 
59  m_tool->doIt();
60 
61  return StatusCode::SUCCESS;
62  }
63 
64  //------------------------------------------------------------------------------
66  //------------------------------------------------------------------------------
67  info() << "finalizing...." << endmsg;
68 
69  toolSvc()->releaseTool( m_tool ).ignore();
70 
71  return StatusCode::SUCCESS;
72  }
73 
74  // Static Factory declaration
76 
77 } // namespace bug_34121
Gaudi::Algorithm::toolSvc
SmartIF< IToolSvc > & toolSvc() const
The standard ToolSvc service, Return a pointer to the service if present.
Definition: Algorithm.cpp:564
bug_34121::MyAlgorithm
Definition: bug34121_MyAlgorithm.cpp:22
IMyTool::doIt
virtual void doIt() const =0
Do something.
bug_34121::MyAlgorithm::m_tool
IMyTool * m_tool
Definition: bug34121_MyAlgorithm.cpp:34
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
Algorithm.h
IMyTool
Definition: IMyTool.h:22
IDataProviderSvc.h
IToolSvc.h
StatusCode
Definition: StatusCode.h:65
bug_34121::MyAlgorithm::finalize
StatusCode finalize() override
Definition: bug34121_MyAlgorithm.cpp:65
bug_34121::MyAlgorithm::execute
StatusCode execute() override
Definition: bug34121_MyAlgorithm.cpp:55
bug_34121::MyAlgorithm::m_toolName
Gaudi::Property< std::string > m_toolName
Definition: bug34121_MyAlgorithm.cpp:33
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
DataObject.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
bug_34121::MyAlgorithm::initialize
StatusCode initialize() override
Three mandatory member functions of any algorithm.
Definition: bug34121_MyAlgorithm.cpp:38
Gaudi::Algorithm::Algorithm
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition: Algorithm.h:101
Gaudi::Property< std::string >
MsgStream.h
bug_34121
Definition: bug_34121.py:1