Add new Task

Creating class for Task

A C++ class for user-defined task has to inherit from FairTask class. According to the convention, name has to start with "R3B", followed by sub-detector short-name (e.g. Land, Dch, Psp, ...), followed by task name (e.g. Digitizer, ClusterFinder, Analysis, ...). Header and source files should have the same name (with extensions .h and .cxx) as the class.
Derived class has to implement following public functions:

  • InitStatus Init(); // called at the initialisation stage, before the event loop. Used to get access to data, register data for output. Return values: kSUCCESS, kERROR, kFATAL.
  • void Exec(Option_t*); // called once for every event from the input data. Used for actual algorithm implementation.
  • void FinishEvent(); // called after processing an event.
  • void FinishTask(); // called after processing all events.

Accessing input data

Retrieving the pointer to input data is to be implemented in the Init() function using FairRootManager singleton object, e.g. assuming fLandPoints is the (TClonesArray*) member-variable of the task:

fLandPoints = (TClonesArray*) FairRootManager::Instance()->GetObject("LandPoint");

Framework will then take care that the object is filled with data when calling the Exec() function.

Registerring output data

If the task is producing data, it can be stored to the output file as follows:

fLandHits = new TClonesArray("R3BLandRawHit");
FairRootManager::Instance()->Register("LandRawHit", "Land", fLandHits, kTRUE);

In addition, one has to implement resetting of output data after each event:

void R3BLandAnalysis::FinishEvent()

Compile task into shared library

In order that a user-defined task is included into the shared library, following steps are required:
Add the "TASK_NAME".cxx file into the CMakeLists.txt: variable SRCS
Add the following line into LinkDef.h file (for ROOT CINT): "#pragma link C++ class TASK_NAME+;"

Note: additional include paths are to be set in CMakeLists.txt variable INCLUDE_DIRECTORIES, and additional libraries in variable DEPENDENCIES.