Gaudi Algorithms
Like most algorithms, Gaudi algorithms are a set of instructions used to perform some clear task and, since Gaudi is a C++ framework, SAS algorithms are normally C++ classes. Gaudi algorithms are called once per event; therefore, a Gaudi algorithm acts on the current set of event data available in the TDS.
To be a true Gaudi algorithm, the class must implement the IAlgorithm abstract interface, meaning that any algorithm class must:
- Derive from Gaudi's Algorithm class
- Provide a special algorithm constructor
- Implement three methods:
|
initialize( ) |
|
|
Called once before event processing begins, it is used for setup - accessing required services, accessing input files, etc. |
|
|
|
|
execute( ) |
|
|
Called once per event.
Performs event processing for the algorithm. |
|
|
|
|
finalize( ) |
|
|
Called once after event processing is finished.
Performs cleans up.
For example: |
|
|
#include "GaudiKernel/Algorithm.h"
#include "GaudiKernel/AlgFactory.h"
class HelloWorld : public Algorithm
{
public:
HelloWorld(const std::string& name, ISvcLocator* pSvcLocator);
StatusCode initialize();
StatusCode execute();
StatusCode finalize();
};
|
Note: This does not necessarily mean algorithms without this format cannot be utilized within Gaudi. This is just the typical definition of a Gaudi algorithm. For a full example Gaudi algorithm, see HelloWorld.
This section details how to create a new Gaudi algorithm and use it within the Gaudi framework, by either:
or
Note: Creating a simple Gaudi algorithm that prints the well known phrase "Hello World" is straightforward. To download the HelloWorldGaudi package as a tar.gz, click on: HelloWorldGaudi.tar.gz
Adding a New Algorithm to an Existing Package
-
Update the requirements file of the package, so that the new algorithm is included in the library defined by the package.
- Modify the <packageName>_load.cxx files to include your new algorithm; for example:
DECLARE_ALGORITHM( HelloWorld );
- Define the source file for your new algorithm, for example, HelloWorld.cxx
- Modify all existing jobOptions.txt files to load the new algorithm and set any input parameters; for example:
ApplicationMgr.TopAlg += { "HelloWorld" };
Adding a New Algorithm to a New Package
- To create a new package if you are using:
MRvcmt:
- Click the New button.
- Fill in the name for the new package.
- Set the verson to: v0
- Set the CMTPATH so that it points to the directory where the new package will reside.
glastpack and CMT on a Linux machine:
At the command line, enter:
cmt create HelloWorldGaudi v0
A new package clled HelloWorldGaudi will be created.
- Fill in the empty requirements file.
For example:
package HelloWorldGaudi
version v0
# Intoductory package that implements a simple Gaudi Algorithm
use GaudiInterface v* IExternal
use GlastPolicy v*
# Use this pattern for shareable libraries that Gaudi must load
apply_pattern packageShr
# Define a new library, named HelloWorldGaudi
# Note that all files are assumed relative to the src directory of the package
library HelloWorldGaudi HelloWorld.cxx Dll/*.cxx
private
# Flags for building shared libraries
apply_pattern package_Cshlibflags
# This is the default test application defined in the GlastPolicy package
# This just defines a simple Gaudi main program
apply_pattern package_test |
- Create the source files required by your library.
Source files required for this example:
- Create a jobOptions.txt file in the src/test directory.
Be sure to load the new library and add the new algorithm to the list of TopAlgs:
ApplicationMgr.DLLs += {"HelloWorldGaudi"};
ApplicationMgr.TopAlg += { "HelloWorld" };
Note: The src/test is used by default for all test programs; this can be overridden if desired.
Related Topics
- For a discussion of algorithms, see: The Gaudi Developer Guide, Section 4.5 Algorithms.
Owned by: Heather Kelly
Last updated by: Chuck Patterson
07/27/2005 |
|
|