ganga.GangaCore.Lib.Root.Root module

Root application – running ROOT

To run a job in ROOT you need to specify the CINT script to be executed. Additional files required at run time (shared libraries, source files, other scripts, Ntuples) should be placed in the inputsandbox of the job. Arguments can be passed onto the script using the ‘args’ field of the application.

Defining a Simple Job:

As an example the script analysis.C in the directory ~/abc might contain:

void analysis(const char* type, int events) {
std::cout << type << ” ” << events << std::endl;

}

To define an LCG job on the Ganga command line with this script, running in ROOT version 5.14.00b with the arguments ‘MinBias’ and 10, you would do the following:

r = Root() r.version = ‘6.04.02’ r.script = ‘~/abc/analysis.C’ r.args = [‘Minbias’, 10]

j = Job(application=r, backend=LCG())

Using Shared Libraries:

If you have private shared libraries that should be loaded you need to include them in the inputsandbox. Files you want back as a result of running your job should be placed in your outputsandbox.

The shared library mechanism is particularly useful in order to create a thin wrapper around code that uses precompiled libraries, or that has not been designed to work in the CINT environment.

For more detailed instructions, see the following Wiki page:

https://twiki.cern.ch/twiki/bin/view/ArdaGrid/HowToRootJobsSharedObject

A summary of this page is given below:

Consider the follow in CINT script, runMain.C, that makes use of a ROOT compatible shared library:

void runMain(){

//set up main, eg command line opts char* argv[] = {“runMain.C”,”–muons”,”100”}; int argc = 3;

//load the shared library gSystem->Load(“libMain”);

//run the code Main m(argv,argc); int returnCode = m.run();

}

The class Main is as follows and has been compiled into a shared library, libMain.so.

Main.h:

#ifndef MAIN_H #define MAIN_H #include “TObject.h”

class Main : public TObject {

public:

Main(){}//needed by Root IO Main(char* argv[], int argc); int run();

ClassDef(Main,1)//Needed for CINT

}; #endif

Main.cpp:

#include <iostream> using std::cout; using std::endl; #include “Main.h”

ClassImp(Main)//needed for CINT Main::Main(char* arvv[], int argc){

//do some setup, command line opts etc

}

int Main::run(){
cout << “Running Main…” << endl; return 0;

}

To run this on LCG, a Job could be created as follows:

r = Root() r.version = ‘5.12.00’ #version must be on LCG external site r.script = ‘runMain.C’

j = Job(application=r,backend=LCG()) j.inputsandbox = [‘libMain.so’]

It is a requirement that your script contains a function with the same name as the script itself and that the shared library file is built to be binary compatible with the Grid environment (e.g. same architecture and version of gcc). As shown above, the wrapper class must be made CINT compatible. This restriction does not, however, apply to classes used by the wrapper class. When running remote (e.g. LCG) jobs, the architecture used is ‘slc3_ia32_gcc323’ if the Root version is 5.16 or earlier and ‘slc4_ia32_gcc34’ otherwise. This reflects the availability of builds on the SPI server:

http://service-spi.web.cern.ch/service-spi/external/distribution/

For backends that use a local installation of ROOT the location should be set correctly in the [Root] section of the configuration.

Using Python and Root:

The Root project provides bindings for Python, the language supported by the Ganga command line interface. These bindings are referred to as PyRoot. A job is run using PyRoot if the script has the ‘.py’ extension or the usepython flag is set to True.

There are many example PyRoot scripts available in the Root tutorials. A short example is given below:

gengaus.py:

if __name__ == ‘__main__’:

from ROOT import gRandom

output = open(‘gaus.txt’,’w’) try:

for i in range(100):
print(gRandom.Gaus(), file=output)
finally:
output.close()

The above script could be run in Ganga as follows:

r = Root() r.version = ‘5.14.00’ r.script = ‘~/gengaus.py’ r.usepython = True #set automatically for ‘.py’ scripts

j = Job(application=r,backend=Local()) j.outputsandbox = [‘gaus.txt’] j.submit()

When running locally, the python interpreter used for running PyRoot jobs will default to the one being used in the current Ganga session. The Root binaries selected must be binary compatible with this version.

The pythonhome variable in the [Root] section of .gangarc controls which interpreter will be used for PyRoot jobs.

When using PyRoot on a remote backend, e.g. LCG, the python version that is used will depend on that used to build the Root version requested.

ganga.GangaCore.Lib.Root.Root.const_lock

This is a context manager which acquires the const write lock on the object’s root object.

This lock acquires exclusive access over an object tree to prevent it from changing. Reading schema attributes on the object is still allowed but changing them is not. Only one thread can hold this lock at once.