Migrate old EventLoop Algorithm to AnaAlgorithm

Last update: 04 Oct 2018 [History] [Edit]

This page is meant to give you a quick overview/cheat sheet on how to migrate your existing EventLoop algorithm into an AnaAlgorithm.

Structural Changes

You will have to change your algorithm to inherit from EL::AnaAlgorithm instead of EL::Algorithm. This requires you to add the following include to your header:

#include <AnaAlgorithm/AnaAlgorithm.h>

The constructor signature changed, meaning that you need to define your own constructor that looks like this:

MyAlgorithm :: MyAlgorithm (const std::string& name,
                            ISvcLocator *pSvcLocator)
  : EL::AnaAlgorithm (name, pSvcLocator)
...

If you don’t have a constructor defined yet, you should add one. You will no longer need/use any other constructor, so if you have one defined you should just change its signature.

For AnaAlgorithm we no longer use the streaming mechanism to create/configure them, so if you added //! to any member variables to protect them from configuration/streaming you can delete the //!. The same holds for any #ifdef statements you added for that purpose, but make sure it was really added for that purpose.

The configuration of an AnaAlgorithm is substantially different from the old EventLoop algorithms. You will need to configure your algorithm through properties the way we explained it in the tutorial. You can in principle keep your configuration script mostly the way you had it, but if you have the time the recommendation is to rewrite it as a python script, utilizing python configurables.

For the old-style EventLoop algorithms you had to define your dictionaries using a so called CINT dictionary via the Root/LinkDef.h file (because the old algorithms derived from TObject). While you can still do that for AnaAlgorithm we do recommend that you use a so called Reflex dictionary instead (via MyPackage/selection.xml and MyPackage/MyPackageDict.h). The details can be found in the tutorial, don’t forget to update your CMakeLists.txt file as well if you create these file from scratch.

Once you have migrated all your algorithms to AnaAlgorithm, you can do some cleanup of your package: If your Root/LinkDef.h file no longer lists any classes, you can just remove it (removing the entry in CMakeLists.txt as well). You should also be able to remove/change any includes of EventLoop header files, and then change the dependency in CMakeLists.txt from EventLoop to AnaAlgorithmLib. For your own packages this will probably matter very little, but if you want to add your code to central repositories this can become an issue.

Translating Virtual Functions

While we tried to keep the virtual functions in the algorithm mostly the same, they are used slightly differently between EventLoop and Athena, so we had to do some adjustments. For “normal” algorithms we don’t expect many changes here, but more advanced algorithms will need some adjustments.

Generally all of your virtual functions have to be changed to return StatusCode instead of EL::StatusCode. This is needed for interoperability with Athena.

  • initialize: This functionality should either stay in initialize or be moved into execute if it actually accesses event data. If you add this code to execute you should make sure you only call this code the first time execute is called, e.g. something like
    StatusCode MyAlgorithm :: execute () {
      if (m_firstExecute) {
        m_firstExecute = false;
        ...
      }
      ...
    

    with a member variable in your class (i.e. in the header file):

    bool m_firstExecute {true};
    
  • histInitialize: This functionality should go into initialize instead.

  • execute: This functionality should stay in execute.

  • finalize: This functionality should stay in finalize. If you moved the corresponding initialization to execute you should add some check that you only finalize values, if you indeed initialized them.

  • histFinalize: This functionality should go into finalize.

  • setupJob: This method no longer exists, and you will instead have to include this code in your configuration script. There was no way of keeping this function, as your algorithm won’t exist until after your job is already set up.

  • fileExecute: This method exists unchanged, but you will have to call requestFileExecute to indicate that this method needs to be called. Note that this method is not supported in Athena and calling requestFileExecute will fail in Athena. It is generally recommended to implement such functionality inside an AsgMetadataTool instead.

  • endOfFile: This method does not currently exist, but could be added if there is sufficient need for it. It is generally recommended to implement such functionality inside an AsgMetadataTool instead.

  • changeInput: This method is now called beginInputFile, but you will have to call requestBeginInputFile to indicate that this method needs to be called. It is generally recommended to implement such functionality inside an AsgMetadataTool instead.

  • postExecute: This functionality should go into a separate algorithm instead, that you then load at the end of your algorithm sequence. This may/will require adding some transient information to the whiteboard.

  • hasName: This functionality no longer exists. Any relevant code should be restructured to use the whiteboard/event store instead.

Athena Support (optional)

One of the main benefits of the AnaAlgorithm is that it can be run inside Athena, and with (hopefully) just a few modifications your algorithm should be able to run in athena as well.

The first thing you have to do is add a component library and an entry for your algorithm in that component library. This requires adding some directives to CMakeLists.txt and adding/modifying files inside src/components/*.cxx. This is described in detail in the tutorial.

Then you need to ensure that you are not relying on any of the EventLoop interfaces. For the most part this means going through your code and replacing any calls to wk() with their dual-use equivalents. For histograms (the most common case) that is described in the tutorial.

Algorithms for N-Tuple Reading (optional)

You can use AnaAlgorithm to process regular TTree objects instead of xAODs. However, you will have to explicitly disable the xAOD reading on your AnaAlgorithmConfig object:

alg.setUseXAODs (False)

or in C++:

alg.setUseXAODs (false)

When you do that, you won’t be able to use the event store/whiteboard and are also locked out from some other of our basic services. And you will actually have to connect to the input file by using the wk() call to access the Worker interface.