Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v38r1p1 (ae26267b)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
MyGaudiAlgorithm.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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
13 #include "GaudiKernel/IToolSvc.h"
14 #include "GaudiKernel/MsgStream.h"
15 
16 #include "IMyTool.h"
17 #include "MyGaudiAlgorithm.h"
18 
19 // Static Factory declaration
21 
22 // Constructor
23 //------------------------------------------------------------------------------
25  // Keep at least one old-style ToolHandle property to test compilation
26  declareProperty( "LegacyToolHandle", m_legacyToolHandle );
27  declareProperty( "UndefinedToolHandle", m_undefinedToolHandle );
28 
29  //------------------------------------------------------------------------------
30  m_myCopiedConstToolHandle = m_myPubToolHandle;
31  m_myCopiedToolHandle = m_myPubToolHandle;
32  m_myCopiedConstToolHandle2 = m_myConstToolHandle;
33 }
34 
35 //------------------------------------------------------------------------------
37  //------------------------------------------------------------------------------
38 
40  if ( sc.isFailure() ) return sc;
41 
42  info() << "initializing...." << endmsg;
43 
44  m_publicTool = tool<IMyTool>( "MyTool" );
45  m_privateTool = tool<IMyTool>( "MyTool", this );
46  m_publicGTool = tool<IMyTool>( "MyGaudiTool" );
47  m_privateGTool = tool<IMyTool>( "MyGaudiTool", this );
48  m_privateToolWithName = tool<IMyTool>( m_privateToolType, "ToolWithName", this );
49  m_privateOtherInterface = tool<IMyOtherTool>( "MyGaudiTool", this );
50 
51  // disable ToolHandle
53 
54  info() << m_tracks.objKey() << endmsg;
55  info() << m_hits.objKey() << endmsg;
56  info() << m_raw.objKey() << endmsg;
57 
58  info() << m_selectedTracks.objKey() << endmsg;
59 
60  // m_wrongIfaceTool is being retrieved via the wrong interface.
61  // we expect the retrieve() to throw an exception.
62  try {
64  error() << "unable to retrieve " << m_wrongIfaceTool.typeAndName() << " (unexpected)" << endmsg;
66  }
67  } catch ( GaudiException& ex ) {
68  info() << "unable to retrieve " << m_wrongIfaceTool.typeAndName() << " (expected) with exception: " << ex.what()
69  << endmsg;
71  }
72 
73  info() << "....initialization done" << endmsg;
74 
75  return sc;
76 }
77 
78 //------------------------------------------------------------------------------
80  //------------------------------------------------------------------------------
81  info() << "executing...." << endmsg;
82 
83  info() << "tools created with tool<T>..." << endmsg;
84 
85  m_publicTool->doIt();
91 
92  info() << "tools created via ToolHandle<T>...." << endmsg;
93 
94  m_myPrivToolHandle->doIt();
95  m_myPubToolHandle->doIt();
96  m_myConstToolHandle->doIt();
97 
98  info() << "tools copied assigned via ToolHandle<T>...." << endmsg;
99 
101  m_myCopiedToolHandle->doIt();
103 
104  info() << "tools copied constructed via ToolHandle<T>...." << endmsg;
105 
106  // copy construct some handles
110  h1->doIt();
111  h2->doIt();
112  h3->doIt();
113 
114  return StatusCode::SUCCESS;
115 }
116 
117 //------------------------------------------------------------------------------
119  //------------------------------------------------------------------------------
120  info() << "finalizing...." << endmsg;
121 
122  return GaudiAlgorithm::finalize();
123 }
IMyOtherTool::doItAgain
virtual void doItAgain() const =0
Do something else.
MyGaudiAlgorithm::m_wrongIfaceTool
ToolHandle< IWrongTool > m_wrongIfaceTool
Definition: MyGaudiAlgorithm.h:64
ToolHandle::retrieve
StatusCode retrieve() const override
Retrieve the AlgTool.
Definition: ToolHandle.h:228
MyGaudiAlgorithm::m_myUnusedToolHandle
ToolHandle< IAlgTool > m_myUnusedToolHandle
Definition: MyGaudiAlgorithm.h:59
GaudiAlgorithm::finalize
StatusCode finalize() override
standard finalization method
Definition: GaudiAlgorithm.cpp:65
MyGaudiAlgorithm::m_privateOtherInterface
IMyOtherTool * m_privateOtherInterface
Definition: MyGaudiAlgorithm.h:50
BaseToolHandle::disable
void disable()
Definition: ToolHandle.h:109
MyGaudiAlgorithm::m_publicGTool
IMyTool * m_publicGTool
Definition: MyGaudiAlgorithm.h:46
IMyTool::doIt
virtual void doIt() const =0
Do something.
MyGaudiAlgorithm::m_hits
DataObjectReadHandle< DataObject > m_hits
Definition: MyGaudiAlgorithm.h:77
ISvcLocator
Definition: ISvcLocator.h:46
GaudiException
Definition: GaudiException.h:31
MyGaudiAlgorithm::m_myPubToolHandle
PublicToolHandle< IMyTool > m_myPubToolHandle
Definition: MyGaudiAlgorithm.h:55
MyGaudiAlgorithm::m_tracks
DataObjectReadHandle< DataObject > m_tracks
Definition: MyGaudiAlgorithm.h:76
MyGaudiAlgorithm::m_myCopiedConstToolHandle2
PublicToolHandle< const IMyTool > m_myCopiedConstToolHandle2
Definition: MyGaudiAlgorithm.h:69
MyGaudiAlgorithm
Trivial Algorithm for tutorial purposes.
Definition: MyGaudiAlgorithm.h:27
IDataProviderSvc.h
MyGaudiAlgorithm::m_privateToolWithName
IMyTool * m_privateToolWithName
Definition: MyGaudiAlgorithm.h:48
IToolSvc.h
ToolHandle< const IMyTool >
StatusCode
Definition: StatusCode.h:65
GaudiAlgorithm
Definition: GaudiAlgorithm.h:104
MyGaudiAlgorithm::m_raw
DataObjectReadHandle< DataObject > m_raw
Definition: MyGaudiAlgorithm.h:78
MyGaudiAlgorithm::m_myConstToolHandle
PublicToolHandle< const IMyTool > m_myConstToolHandle
Definition: MyGaudiAlgorithm.h:66
MyGaudiAlgorithm::m_publicTool
IMyTool * m_publicTool
Definition: MyGaudiAlgorithm.h:44
GaudiAlgorithm::initialize
StatusCode initialize() override
standard initialization method
Definition: GaudiAlgorithm.cpp:52
MyGaudiAlgorithm::initialize
StatusCode initialize() override
Three mandatory member functions of any algorithm.
Definition: MyGaudiAlgorithm.cpp:36
MyGaudiAlgorithm::m_privateTool
IMyTool * m_privateTool
Definition: MyGaudiAlgorithm.h:43
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:203
MyGaudiAlgorithm::m_privateGTool
IMyTool * m_privateGTool
Definition: MyGaudiAlgorithm.h:45
MyGaudiAlgorithm::finalize
StatusCode finalize() override
Definition: MyGaudiAlgorithm.cpp:118
MyGaudiAlgorithm::execute
StatusCode execute() override
standard execution method
Definition: MyGaudiAlgorithm.cpp:79
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
MyGaudiAlgorithm::m_myCopiedToolHandle
PublicToolHandle< IMyTool > m_myCopiedToolHandle
Definition: MyGaudiAlgorithm.h:70
MyGaudiAlgorithm::m_selectedTracks
DataObjectWriteHandle< DataObject > m_selectedTracks
Definition: MyGaudiAlgorithm.h:80
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:76
IMyTool.h
MyGaudiAlgorithm.h
MyGaudiAlgorithm::m_privateToolType
Gaudi::Property< std::string > m_privateToolType
Definition: MyGaudiAlgorithm.h:40
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
MyGaudiAlgorithm::m_myPrivToolHandle
ToolHandle< IMyTool > m_myPrivToolHandle
Definition: MyGaudiAlgorithm.h:54
ToolHandle::typeAndName
std::string typeAndName() const override
Definition: ToolHandle.h:273
MyGaudiAlgorithm::m_myCopiedConstToolHandle
PublicToolHandle< const IMyTool > m_myCopiedConstToolHandle
Definition: MyGaudiAlgorithm.h:68
GaudiException::what
const char * what() const override
method from std::exception
Definition: GaudiException.h:110
MsgStream.h