Athena Developer Guide
Athena Developer Guide
Athena Developer Guide
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Athena</strong><br />
Chapter 5 Writing algorithms Version/Issue: 2.0.0<br />
Just because an algorithm derives from the Algorithm base class does not mean that it is limited to<br />
using or overriding only the methods defined by the base class. In general, your code will be much<br />
better structured (i.e. understandable, maintainable, etc.) if you do not, for example, implement the<br />
execute() method as a single block of 100 lines, but instead define your own utility methods and<br />
classes to better structure the code.<br />
If an algorithm fails in some manner, e.g. a fit fails to converge, or its data is nonsense it should return<br />
from the execute() method with StatusCode::FAILURE. This will cause the application<br />
manager to stop processing events and end the job. This default behaviour can be modified by setting<br />
the .ErrorMax job option to something greater than 1. In this case a message will<br />
be printed, but the job will continue as if there had been no error, and just increment an error count. The<br />
job will only stop if the error count reaches the ErrorMax limit set in the job option.<br />
The framework (the Algorithm base class) calls the execute() method within a try/catch clause.<br />
This means that any exception not handled in the execution of an Algorithm will be caught at the level<br />
of sysExecute() implemented in the base class. The behaviour on these exceptions is identical to<br />
that described above for errors.<br />
Finalization The finalize() method is called at the end of the job. It can be used to analyse<br />
statistics, fit histograms, or whatever you like. Similarly to initialization, the framework invokes a<br />
sysFinalize() method which in turn invokes the finalize() method of the algorithm and of<br />
any sub-algorithms.<br />
Monitoring of the execution (e.g. cpu usage) of each Algorithm instance is performed by auditors under<br />
control of the Auditor service (described in Chapter 13). This monitoring can be turned on or off with<br />
the boolean properties AuditInitialize, AuditExecute, AuditFinalize.<br />
The following is a list of things to do when implementing an algorithm.<br />
• Derive your algorithm from the Algorithm base class.<br />
• Provide the appropriate constructor and the three methods initialize(), execute()<br />
and finalize().<br />
• Make sure you have implemented a factory by adding the magic two lines of code (see 5.3.1).<br />
5.4 Nesting algorithms<br />
The application manager is responsible for initializing, executing once per event, and finalizing the set<br />
of top level algorithms, i.e. the set of algorithms specified in the job options file. However such a<br />
simple linear structure is very limiting. You may wish to execute some algorithms only for specific<br />
types of event, or you may wish to “loop” over an algorithm’s execute method. Within the <strong>Athena</strong><br />
application framework the way to have such control is via the nesting of algorithms or through<br />
algorithm sequences (described in section 5.5). A nested (or sub-) algorithm is one which is created by,<br />
and thus belongs to and is controlled by, another algorithm (its parent) as opposed to the application<br />
manager. In this section we discuss a number of points which are specific to sub-algorithms.<br />
page 29