ToolExample

From Atlas Wiki
Revision as of 11:20, 25 October 2006 by Zkestere (talk | contribs)
Jump to navigation Jump to search

introduction

During the workshop only one participant managed to get this exercise working. The "ToolExample.cxx" contained bugs causing ATHENA to crash. In this section, this exercise will be explained in detail.

Getting the complete answer

A tar file with the whole AnalysisExample package containing the result of the exercise is to be found here. Compiling this package and running ATHENA should work out-of-the-box. In the section below the key lines in the package will be discussed. To get this package working copy the .tgz file into your Tutorial directory and type:

* tar xzf ToolExample.tgz ExampleAnalysis
* cd ExampleAnalysis/cmt
* source setup.csh
* gmake

Running ATHENA should show the output of EvtMax events with a dump stating that the ToolExample->useTool() method is indeed called every event.

Retrieving the ToolExample from ToolSvc

In ExampleAlg.cxx, one can see the following lines in the initialize() method:

1  StatusCode sc = toolSvc()->retrieveTool("ToolExample", m_tool);
2  if(sc.isFailure()) {
3    log << MSG::ERROR << "ToolSvc could not retrieve ToolExample" << endreq;
4  } else log << MSG::INFO << "ToolSvc retrieved ToolExample" << endreq;

The first line uses the toolSvc() method to retrieve the ToolSvc. Any algorithm can do this, since they inherit this method from the base Algorithm class. The ToolService itself calls the method retrieveTool(<tool_name>,<tool_instance>), which loads the Tool 'ToolExample' into the instance m_tool. Mind, that this instance should be declared in your headerfile!

   class IToolExample;
   class ExampleAlg : public Algorithm {
       ...
       private :
       IToolExample* m_tool;
   };