%CERTIFY%

Creating a new algorithm by duplicating Athena Hello World

Introduction

This page describes how to add a new algorithm to an existing package and how to run the two algorithms at the same time. The easiest way is to copy an existing algorithm and make modifications. We will copy the HelloWorld algorithm to a new one, we will modify the new one slightly and we will run both at the same time.

Please also see a discussion at https://twiki.cern.ch/twiki/bin/view/AtlasProtected/PhysicsAnalysisWorkBookAlgorithmRel15

First, log into your account and set up CMT (as described in WorkBookSetAccount). Assuming you are running in a folder with the same name as the Athena version and located in the ~/testarea, if you have a bash shell define this variable which will help as move from a folder to another folder easily while allowing us to use the same copy paste commands for different versions of Athena.

export ATHENA_VERSION=17.0.6

Copying the HelloAlg algorithm to HelloAlgNEW and making the necessary changes

cd ~/testarea/$ATHENA_VERSION/Control/AthenaExamples/AthExHelloWorld/src
cp HelloAlg.cxx HelloAlgNEW.cxx

Then, replace all appearances of HelloAlg with within HelloAlgNEW within HelloAlgNEW.cxx or equivalently:

sed -i 's/HelloAlg/HelloAlgNEW/g' HelloAlgNEW.cxx

Assuming in the previous exercise we modified the HelloAlg algorithm to print "TEST" in each of the initialize(), execute() and finalize() parts of the algorithm, let's replace "TEST" with "TEST_NEW".

sed -i 's/TEST/TEST_NEW/g' HelloAlgNEW.cxx

Now let's do the same for the HelloAlg.h file

cp HelloAlg.h HelloAlgNEW.h
sed -i 's/HelloAlg/HelloAlgNEW/g' HelloAlgNEW.h

Now something particular to the HelloAlg algorithm. In the beginning of the .cxx file there is an << operator defined outside the class and the compilation would fail if we keep this code in both files. So let's comment these lines in HelloAlgNEW.cxx, where you should have this:

///////////////////////////////////////////////////////////////////////////// 
// FIXME Looks like we need operator<<( ostream&, pair<double, double > ) for gcc41 
//std::ostream& operator<<( std::ostream& s, std::pair<double, double > p ) 
//{ 
//s << p.first << " " << p.second; 
//return s; 
//} 
//we should comment it, as it is already in the HelloAlg.cxx and it gives compilation error

...and one more thing! Open HelloAlgNEW.h and modify the preprocessor lines: for example, replace:

#ifndef ATHEXHELLOWORLD_HELLOALG_H
#define ATHEXHELLOWORLD_HELLOALG_H 1
with:
#ifndef ATHEXHELLOWORLD_HELLOALG_NEW_H
#define ATHEXHELLOWORLD_HELLOALG_NEW_H 1

Then we need to add a line for the new algorithm for every line for the old algorithm in the components directory.

cd components
emacs -nw AthExHelloWorld_entries.cxx

The file will look like this

#include "../HelloAlg.h"
#include "../HelloAlgNEW.h"
#include "../HelloTool.h"

#include "GaudiKernel/DeclareFactoryEntries.h"

DECLARE_ALGORITHM_FACTORY( HelloAlg )
DECLARE_ALGORITHM_FACTORY( HelloAlgNEW )
DECLARE_TOOL_FACTORY( HelloTool )

DECLARE_FACTORY_ENTRIES(AthExHelloWorld) {
DECLARE_ALGORITHM( HelloAlg )
DECLARE_ALGORITHM( HelloAlgNEW )
DECLARE_TOOL( HelloTool )
}

Compiling the package hosting the two algorithms

Now let's compile the AthExHelloWorld package, which contains now two algorithms

cd ../../cmt
cmt config
gmake

Preparing to run the two algorithms at the same time

Now let's modify the job options so that we run both algorithms at the same time. Let's copy the option in a new file and modify only this copy, so that we can always compare with the original one for reference.

cd ~/testarea/$ATHENA_VERSION/PhysicsAnalysis/AnalysisCommon/UserAnalysis/run
cp HelloWorldOptions.py HelloWorldOptionsNEW.py
emacs -nw HelloWorldOptionsNEW.py

Replace these lines

# Add top algorithms to be run                                                                                                                   
from AthExHelloWorld.AthExHelloWorldConf import HelloAlg
job += HelloAlg( "HelloWorld" )   # 1 alg, named "HelloWorld                                                                                     

with these lines

# Add top algorithms to be run                                                                                                                   
from AthExHelloWorld.AthExHelloWorldConf import HelloAlg, HelloAlgNEW
job += HelloAlg( "HelloWorld" )   # 1 alg, named "HelloWorld                                                                                     
job += HelloAlgNEW( "HelloWorldNEW" )   # 1 alg, named "HelloWorldNEW"

Running the two algorithms at the same time

We can now run again, without a need to recompile the UserAnalysis package

athena.py HelloWorldOptionsNEW.py

We can check that we ran both algorithms together if we have an output line containing "TEST" and just under it another line containing "TEST_NEW".


Major updates:
-- AdrianBuzatu - 25-Jan-2012

%RESPONSIBLE% AdrianBuzatu
%REVIEW% Never reviewed

-- AdrianBuzatu - 26-Jan-2012

Edit | Attach | Watch | Print version | History: r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r1 - 2012-01-26 - AdrianBuzatu
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Sandbox All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback