ATLAS Offline Software
AsgExampleAlgorithm.cxx
Go to the documentation of this file.
1 // AsgExampleAlgorithm.cxx
2 
3 #include "AsgExampleAlgorithm.h"
4 #include "Gaudi/Property.h"
6 #include "AsgTools/AsgTool.h"
7 
8 using std::string;
9 
10 //**********************************************************************
11 
13 AsgExampleAlgorithm(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 = "---------------------------------------------------";
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);
81  }
82  return StatusCode::SUCCESS;
83 }
84 
85 //**********************************************************************
AsgExampleAlgorithm::initialize
StatusCode initialize()
Athena algorithm's Hooks.
Definition: AsgExampleAlgorithm.cxx:25
asg::AsgTool
Base class for the dual-use tool implementation classes.
Definition: AsgTool.h:47
checkFileSG.line
line
Definition: checkFileSG.py:75
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
AsgExampleAlgorithm.h
AsgExampleAlgorithm::execute
StatusCode execute()
Definition: AsgExampleAlgorithm.cxx:69
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AsgExampleAlgorithm::finalize
StatusCode finalize()
Definition: AsgExampleAlgorithm.cxx:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
IAsgHelloTool.h
AsgExampleAlgorithm::AsgExampleAlgorithm
AsgExampleAlgorithm()
Default constructor:
AthAlgorithm
Definition: AthAlgorithm.h:47
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
AsgExampleAlgorithm::~AsgExampleAlgorithm
~AsgExampleAlgorithm()
Destructor:
Definition: AsgExampleAlgorithm.cxx:21
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
AthCommonMsg< Algorithm >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
AsgExampleAlgorithm::m_asgtools
ToolHandleArray< IAsgHelloTool > m_asgtools
Athena configured tools.
Definition: AsgExampleAlgorithm.h:35
AsgTool.h