How to set up Eclipse for ROOT
This tutorial aims to introduce Eclipse as and IDE for code development involving ROOT.
If you already familiar with the usage of Eclipse for ROOT you can skip to the next section.
Get ROOT
ROOT can be downloaded from
root.cern.ch
You can either download a binary for your system or compile it from source. A 'How to' is given on the ROOT homepage.
However, if you want to debug ROOT applications down to ROOT objects, you need a debug version of ROOT. This can be obtained by compiling ROOT with a debug flag.
Recommended location
While you can install ROOT in any folder you wish it is recommended to install it to a location which does not require admin right.
Since you will at some point end up with multiple ROOT versions (switching from one to another) I recommend this setup:
#create /software/root if not existent
sudo mkdir -p /software/root
#change the owner
sudo chown -R <yourusername> /software
#you no longer need admin rights to install something here
cd /software/root
#get the latest ROOT version
#untar it, tar -zxf file
mkdir v5.XX.XX
mv root v5.XX.XX/normal
cp -r v5.XX.XX/debug
#now you are set up to compile ROOT for both normal use and debugging
Compilation of ROOT
Normal version:
cd myROOT_version
./configure --enable-roofit --enable-minuit2 --enable-builtin-freetype
make -j2
Debug version:
cd myROOT_version
./configure --build=debug --enable-roofit --enable-minuit2 --enable-builtin-freetype
make -j2
Special instructions for Mac user
- Make sure you have the latest XCode version installed (comes with all the libraries and includes you will need)
- configure ROOT with the appropriate python include and library paths
#find out the location of your python installation:
which python
#copy & paste the lib and include locations into the command below
./configure --enable-roofit --enable-minuit2 --enable-builtin-freetype
make -j2
Get rootplot
This is optional for version <= 1.0.
Install rootplot (once
PyROOT is configured)
sudo env PYTHONPATH=$PYTHONPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH easy_install rootplot
Get rootpy
sudo easy_install rootpy
Or follow manual instruction on
http://rootpy.org/#manual-installation
Get Eclipse
Eclipse is a free IDE for various programming languages. Interesting for this tutorial are Eclipse's capabilities in C++ and Python.
Eclipse can be obtained from the Eclipse website:
Get Eclipse
In the download section, choose the right version for your operating system. Note that for Linux OS you have the possibility to download Eclipse with additional Linux tools (recommended).


In case you are using a 64bit Linux, you will need to add following line to 'eclipse.ini' (workaround for bug in Java):
-XX:-UseCompressedOops
First steps
At the first start you will be prompted for the workspace, the area/folder/path you will create your projects in.
Once started, you should find something like this:
Click on the arrow highlighted in red. This will get you to the project explorer.
Create a new C++ project (with ROOT)
First let's test if C++ is set up correctly. In order to create a new C++ project, right-click on an empty space in the project explorer and select 'New->C++ Project':
This will get you to the project wizard. For now we only want to create an simple 'Hello World' project:
Select it, name the project 'HelloROOT' and press finish.
All is left is to run our application now: click the green arrow button ('play').
'!!!Hello World!!!' should be now displayed in the console below the code.
Set environment variables
In order to compile our own ROOT application we need to tell Eclipse where ROOT is installed.
This is done by setting environmental variables under:
You will need to set ROOTSYS and LD_OLIBRARY_PATH to your ROOT install and library directory.
Edit Indexer
Once inside the preferences of Eclipse we can also edit the Indexer options. The Indexer will index the source code and prepare it for code-assist (auto-completion, code preview, etc.).
Two settings need to be changed:
- select the checkbox for 'index unused headers
- Select 'Use active build configuration' under 'Build configuration for the indexer'
- (optional) increase the absolute memory limit of the indexer (useful for big projects)
Set include and library path
Once the environment variables are set we can include ROOT in our project.
In order to do so, right-click on the project and select 'preferences'.
Now go to 'C/C++ General-> Paths and Symbols' and choose the 'includes' tab and the 'GNU C++' entry.
Add a new variable:
Next the same with the library path:
Edit linker settings
Once the paths are set you will need to edit the linker settings. You can find them under project preferences-> C/C++ Build -> Settings.
Note: If you are using OS X make sure to switch you linker under C/C++ Build -> Tool chain editor to
MacOSX GCC tool chain (instead of Linux GCC tool chain).
Under Linker -> Miscellaneous you have to add following option:
-L/usr/local/lib `${ROOTSYS}/bin/root-config --libs --glibs --cflags --ldflags --auxlibs --auxcflags` -pthread -lm -ldl
If you are a linux user you will also have to move ${FLAGS} to the end in the GCC C++ Linker path
Edit Run settings
The only thing left to do is to ensure Eclipse finds the linked ROOT libraries at runtime. For this we enter the Run Configurations:
Select 'HelloROOT' configuration (which was created before the first run) and go to the tab 'Environment':
Enter the path to $ROOTSYS/lib.
To test the setup modify the source code of HelloROOT.cpp:
#include <iostream>
#include "TH1F.h"
#include "TCanvas.h"
using namespace std;
int main() {
cout << "!!!Hello ROOT!!!" << endl; // prints !!!Hello World!!!
TCanvas *c1 = new TCanvas("c1","test", 600,600);
TH1F *hist = new TH1F("test", "test", 100,0,1);
hist->Fill(0.1);
hist->Fill(0.5);
hist->Draw();
c1->SaveAs("test.png");
delete c1;
return 0;
}
Now run the project. If successful it should create a image file, test.png, in the project directory.
Since Python is widely used within the collaboration, it is useful to teach Eclipse how to interpret it. Luckily most of the work is already done for you and all is left is to install an Eclipse plug-in:
Then add the
PyDev project site:
http://pydev.org/updates
And finally select
PyDev for installation:
All is left is to follow the steps of the installation wizard. At the end of the installation a restart of Eclipse is required.
Set the Python interpreter
Next we have to tell Eclipse which Python interpreter we want to use. Usually (on Linux) you want to use the default interpreter on your system, /usr/bin/python:
Confirming our selection you will be prompted for additional paths you want to include to your PYTHONPATH. If you've followed the steps until now you will be given the option to add your $ROOTSYS/lib path:
Now we can create our own
PyROOT project (the same way as the C++ project):
In the src folder we create a new Python module, HelloROOT.py with following content:
from ROOT import TCanvas, TH1F
if __name__ == '__main__':
print "!!!Hello ROOT!!!"
c1 = TCanvas("c1","test", 600,600);
hist = TH1F("test", "test", 100,0,1);
hist.Fill(0.1);
hist.Fill(0.5);
hist.Draw();
c1.SaveAs("testPyROOT.png");
del c1;
Once saved you can run it as 'Python Run'. That's it, ready to start the real work.
NOTES:
By design the ROOT import resolves dynamically, which means at runtime, which has at least two consequences:
- ROOT import as not correctly recognised in the editor, but it run fine.
- auto-completion is not available for PyROOT
boost libraries
The Bristol
AnalysisTools use smart pointers to great extend. Smart pointers are part of the new C++0x Standard, which is still in development. The implemented features are available in the form of the boost libraries.
The libraries can be downloaded here:
http://www.boost.org
.
It is recommended to place the libraries in '/usr/include/' as this is the value already set in the project configuration. However, this can be changed at any time.
With ROOT,
PyDev and boost libraries set up the analysis code can now be checked out from the CVS/SVN repository.
Import project from CVS/SVN
In order to import a project from a repository right-click on an empty space in the project explorer and click on 'Import ...'.
CVS
For CVS select 'Projects from CVS'.
You will need to enter the location of the repository. Use
host |
cmscvs.cern.ch |
Repository Path |
/cvs_server/repositories/CMSSW |
user |
your cern user ID |
password |
you cern password |
Under 'connection type' select extssh. If you want you can save your password.
In the next step you can specify the name of the project. Follow the import wizard to the end.
The repository contains Eclipse configuration files and the project will start building when imported. However, the standard recipe includes tcmalloc, a library for performance analysis.
You will have to either remove it in the linker step (
linker under libraries) or download the Google Performance tools (described
here)
You are now ready for analysis.
SVN
If you haven't installed SVN already, goto to
Install SVN first.
For SVN select 'Projects from CVS'.
You will need to enter the location of the repository. Use
URL |
svn+ssh://svn.cern.ch/reps/bat/trunk/AnalysisTools |
user |
your cern user ID |
password |
you cern password |
In the next step you can specify the name of the project. Follow the import wizard to the end.
The repository contains Eclipse configuration files and the project will start building when imported. However, the standard recipe includes tcmalloc, a library for performance analysis.
You will have to either remove it in the linker step (
linker under libraries) or download the Google Performance tools (described
here)
Submit changes to CVS/SVN
The easiest way to commit multiple files and to check for new files in the repository is to use the Synchronise Project View. To get there right-click on your project, select Team->Synchronise Project with repository:
Once you switch to the Synchronise View you will see all the changes others did to the project and your own. You can compare the changes of a specific file by double-clicking on it.
This is especially useful if a conflict occurs, i.e. when a file you were working on changed in the meanwhile. You can then merge the changes together and update the file.
CUTE (C++ Unit Testing Easier)
Unit tests are very important to maintain the functionality intended. Changes in the code can be non-trivial and affect other parts. Therefore it is alway important to run the tests as well.
The way it is done in Eclipse is to install the CUTE plugin which will help to run the tests and visualise the test results
Install Cute plugin
Installation instructions can be found
here
.
Run Unit Tests
Since the project in the repository already contains the build for CUTE, you can start it right away.
Go to Run Configurations:
There go on CUTE Test and click on 'Run':
Eclipse will display results like this:
Google Performance Tools (optional)
http://goog-perftools.sourceforge.net/
Code formatter
Optional plugins
SVN
To install SVN perform the same steps as in
Install PyDev.
Select 'Helios -
http://download.eclipse.org/releases/helios'
from the available update sites.
First time you attempt to use SVN or when you restart Eclipse you will be prompted to choose your SVN connector.
To get the right one, check first which SVN version is installed on your machine:
svn --version
I recommend the usage of the Java only connector (SVN Kit, works on all OSs):
Eclipse will now install the SVN connector and prompt you for a restart.
Linux profiling Tools (Linux only)
Remote System Explorer
Since we usually end up transferring the code to a remote machine to perform the analysis. Also you might want to edit a single file, i.e. changing the input file, on a remote machine.
This is where the Remote System Explorer comes in handy. It allows you to open and edit either single remote files or whole folder structures when used as remote projects.
You can find it the same way as SVN (
here) under "General Purpose Tools".
Addtional plugins, which I haven't tested myself yet, can be obtained from the CUTE update page. They include the Remote Compiler and Debugger.
Late
How to link other projects within Eclipse (Example TopQuarkAnalysis/TopHitFit)
Get Project
- create an empty C++ project with the name TopQuarkAnalysis
- in the project wizard choose shared library as the project type (Shared Library -> Empty Project)
- follow the instructions in Import Project to import the TopHitFit package from CVS.
- use specified module name: CMSSW/TopQuarkAnalysis/TopHitFit
- use: Check out into existing project then pick TopQuarkAnalysis
- Finish the import
Compile
You won't be able to compile as:
- CMSSW used the complete Project path (TopQuarkAnalysis/TopHitFit)
- some files depend on CMSSW
What you need to do:
- fix the include path: * Right-click on project and go to properties * go to 'C/C++ General -> Paths and Symbols -> Includes' * add your workspace path as an include directory to ALL configurations for C++ (i.e. if path to project is /home/user/workspace/TopQuarkAnalysis use /home/user/workspace/)
- exclude CMSSW dependet files from build: * Right-click on project and go to properties * go to 'C/C++ General -> Paths and Symbols -> Source location' * select the project and click on 'Edit Filter' * click on 'Add Multiple' and select all files fitting TopQuarkAnalysis/TopHitFi/src/Pat* as well as the TopQuarkAnalysis/TopHitFi/plugins folder
If you try to compile at this point you might get an saying that you have to recompile with the 'fPIC' option. To enable this:
- Right-click on project and go to properties
- go to 'C/C++ Build -> Settings'
- select C++ complier and go to 'Miscellanious' option
- enable 'Position independent Code (fPIC)' checkbox. If not available add the option manually (-fPIC) in the text-box
- add the include path: * Right-click on project and go to properties * go to 'C/C++ General -> Paths and Symbols -> Includes' * add your workspace path as an include directory to ALL configurations for C++ (i.e. if path to project is /home/user/workspace/TopQuarkAnalysis use /home/user/workspace/)
- Link to the library: * Right-click on project and go to properties * go to 'C/C++ General -> Paths and Symbols -> Library Paths' * add 'TopQuarkAnalysis/Release' to all configurations * In 'Libraries' add 'TopQuarkAnalysis'
--
LukasKreczko - 04-Sep-2011
- CUTE test results: