ATLAS Offline Software
Loading...
Searching...
No Matches
AsgExampleAlgorithm.cxx
Go to the documentation of this file.
1// AsgExampleAlgorithm.cxx
2
4#include "Gaudi/Property.h"
6#include "AsgTools/AsgTool.h"
7
8using std::string;
9
10//**********************************************************************
11
13AsgExampleAlgorithm(const std::string& name,
14 ISvcLocator* pSvcLocator )
15: ::AthAlgorithm( name, pSvcLocator ) {
16 declareProperty( "Tools", m_asgtools);
17}
18
19//**********************************************************************
20
22
23//**********************************************************************
24
26 StatusCode sc;
27 ATH_MSG_INFO("Initializing " << name() << "...");
28 ATH_MSG_INFO("Retrieving tools...");
29 sc = m_asgtools.retrieve();
30 if ( ! sc.isSuccess() ) {
31 ATH_MSG_ERROR("Tool retrieval failed.");
32 }
33 ATH_MSG_INFO("Tool retrieval completed.");
34 unsigned int ntool = m_asgtools.size();
35 ATH_MSG_INFO(" Tool count: " << ntool);
36 for ( unsigned int itool=0; itool<ntool; ++itool ) {
37 ATH_MSG_INFO(" " << m_asgtools[itool]->name());
38 m_asgtools[itool]->print();
39 // Get the tool's message property:
40 const asg::AsgTool* tool =
41 dynamic_cast< const asg::AsgTool* >( m_asgtools[ itool ].operator->() );
42 if( ! tool ) {
43 ATH_MSG_ERROR( "The received tool is not an AsgTool?!?" );
44 return StatusCode::FAILURE;
45 }
46 const std::string* msg = tool->getProperty< std::string >( "Message" );
47 if( ! msg ) {
48 ATH_MSG_WARNING( "Couldn't get the \"Message\" property of tool "
49 << tool->name() );
50 } else {
51 ATH_MSG_INFO( " Its \"Message\" property: " << *msg );
52 }
53 // Try some invalid retrievals, for fun:
54 tool->getProperty< std::string >( "UnknownProperty" );
55 tool->getProperty< int >( "Message" );
56 }
57 return StatusCode::SUCCESS;
58}
59
60//**********************************************************************
61
63 ATH_MSG_INFO ("Finalizing " << name() << "...");
64 return StatusCode::SUCCESS;
65}
66
67//**********************************************************************
68
70 ATH_MSG_INFO ("Executing " << name() << "...");
71 // Loop over hello tools.
72 ATH_MSG_INFO("Looping over ASG tools.");
73 string line = "---------------------------------------------------";
74 ATH_MSG_INFO(line);
75 for ( ToolHandleArray<IAsgHelloTool>::const_iterator itoo=m_asgtools.begin();
76 itoo!=m_asgtools.end(); ++itoo ) {
77 ToolHandle<IAsgHelloTool> htool = *itoo;
78 int jstat = htool->talk();
79 if ( jstat != 0 ) ATH_MSG_INFO("Tool returned error " << jstat);
80 ATH_MSG_INFO(line);
81 }
82 return StatusCode::SUCCESS;
83}
84
85//**********************************************************************
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
static Double_t sc
StatusCode initialize()
Athena algorithm's Hooks.
AsgExampleAlgorithm()
Default constructor:
ToolHandleArray< IAsgHelloTool > m_asgtools
Athena configured tools.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
MsgStream & msg() const
Base class for the dual-use tool implementation classes.
Definition AsgTool.h:47