 |
|
| Damian Pieloth @ DESY Zeuthen |
|
|
Using Eclipse IDE with CDT plugin to develop IceTray software modules
On this page I put together some information about using Eclipse IDE with the CDT plugin for software development in IceTray.
Eclipse is an open source Integrated Development Environment (IDE) that can be used for Java, C/C++, Fortran, Python, Macromedia Flash, whateveryouwant development. Eclipse IDE is free of charge, it is well documented, gets support from industry vendors like Intel, Nokia and IBM. The best thing about Eclipse IDE is; it is very easy to use it for IceTray software development - it runs on every platform we support, so you can develop your code on a Linux box in the office and then try out something else on your mac at home. To be true: it's easy to use, because the IceTray environment is.
Before using Eclipse/CDT for software development in IceTray be sure your box(s) fulfill the requirements below
Also: Eclipse is on other piece of software you have to learn to work with. While I found it's very easy to install and use for software development in IceTray, you might think different. Eclipse put all the things together we need for software development: editor, run time environment, debugger, source code management. But you only get a payoff, if you use it properly.
Installation of Eclipse IDE, CDT and Subclipse plugin
Let's start with the installation of Eclipse IDE, CDT and the Subclipse plugin (this is the same on a Linux box and under Mac OS X). I assume, you have a $HOME with
- $HOME/icecube/work
(with a working copy of IceTray software)
- $HOME/icecube/tools
- $HOME/projects/c++ (a fairground where you can play e.g. with sieglinde...)
- $HOME/projects/java (for java development)
- $HOME/download (where you store your downloads)
First download the latest release (3.1.1) of the Eclipse IDE and the latest (3.0.1) CDT plugin from the eclipse download side (http://www.eclipse.org/downloads/index.php). The CDT plugin provides C/C++ Development Tools like C/C++ editor, debugger, etc. to the Eclipse IDE. Assuming you are on a Linux box, you should downloaded
http://download.eclipse.org/eclipse/downloads/drops/R-3.1.1-200509290840/download.php?dropFile=eclipse-SDK-3.1.1-linux-gtk.tar.gz http://download.eclipse.org/tools/cdt/releases/eclipse3.1/dist/3.0.1/org.eclipse.cdt-3.0.1-linux.x86.tar.gz
Having eclipse-SDK-3.1.1-linux-gtk.tar.gz and org.eclipse.cdt-3.0.1-linux.x86.tar.gz in your $HOME, do gunzip and tar xvf for both, first for eclipse-SDK-... then org.eclipse... This will create an eclipse directory in your $HOME. Looking in $HOME/eclipse you should see

Now you can start the Eclipse IDE. Do ./eclipse at $HOME/eclipse to start the IDE. Starting for the first time, Eclipse will asking you where to place your workspace (Eclipse will store there your projects you will create). Choose $HOME/eclipse/workspace.

You can choose almost every dir, but choosing $HOME/icecube/work might be not a good idea. We are using this directory for IceTray software development and you don't want to put every new created C/C++, Java, Python project under subversion control, right? After choosing the directory and checking the "Use this as..." checkbox, you should see the Eclipse IDE intro view:

Now you can install the Subclipse plugin. It adds the Subversion integration to the Eclipse IDE. To install Subclipse, go to the Help->Software Updates->Find and Install.. menu to use Eclipse's update manager to install subclipse. (You can use Eclipse's update manager to install almost every plugin). Check the "Search for new features to install" checkbox

and then push "New Remote Site..." adding the subclipse update URL: http://subclipse.tigris.org/update

After pushing the "OK" button, checking the eclipse checkbox, then 2 times the "Next" button and then the "Finish" button



the installation will begin. After a while you will be asked to install the Subclipse plugin. Choose the "Install all" button.

Great, you are almost there! Push "Yes" and you the installation is ready to work with.

Setting up the subcipse plugin for IceTray development
Now you are ready to setup the Eclipse IDE for IceTray development. Let's start with setting up the subversion repository we will use. Go to the "SVN Repository Perspective" via the Window->Open Perspective->Other.. menu. On a Mac OS X box, you should get a window like that:
Choose "SVN Repository Exploring". You should see the SVN Repository Exploring window:

Now add the svn repository by pushing the svn database button in the left window above. Add the repository location, username, password, etc. Please, choose http://code.icecube.wisc.edu/svn/ as Url and Root url to avoid subversion hassle, I will talk about below.

If everything went fine, you can surf the subversion repository. Right clicking a directory icon, choosing "Show in Resource History", let you know, what is going on... I only use the SVN Repository Exploring perspective to surf the repository. I do not check out a meta-project, update or commit things here. I will tell you why below.
NOTE!!! IN A GUI YOUR ARE JUST ONE CLICK AWAY FROM MAKING A MISTAKE. SO DO NOT USE ANY FEATURE OF SUBCLIPSE PLUGIN, YOU DON'T UNDERSTAND IN WHOLE. YOU COULD DAMAGE A REPOSITORY!

Importing existing IceTray projects into the Eclipse IDE
There are two different ways to import IceTray projects into the Eclipse IDE:
The first way has - at least for me - two drawbacks. Importing a whole meta-project, all the code in there is under control of subversion. There is no way to disconnect subversion for looking at say, $I3_WORK/icepick. So checked out let say the trunk of icerec, you could damage the release of offline-software changing accidentally and commit something in the modules belongs to offline-software release. The second thing is, added a meta-project to the workspace, you can't add any other project simply because subclipse can't handle that. So let say your $3WORK comes from "svn co http://code.icecube.wisc.edu/svn/meta-projects/icerec/trunk/", you will not be able to add to Eclipse IDE a project from the sandbox e.g. like http://code.icecube.wisc.edu/svn/sandbox/i3anis/.
That's why I choose a different approach. My $I3_WORK comes from
http://code.icecube.wisc.edu/svn/meta-projects/offline-software/releases/V01-07-05/ -> $I3_WORK
plus the release versions of modules I'm interested in or need for running, and the trunk of the module I'm currently working on, e.g.
http://code.icecube.wisc.edu/svn/projects/analog2hits/releases/V01-01-01/ -> $I3_WORK/analog2hits http://code.icecube.wisc.edu/svn/projects/amanda-mantle/releases/V01-00-01/ -> $I3_WORK/amanda-mantle http://code.icecube.wisc.edu/svn/projects/linefit/releases/V01-02-02/ -> $I3_WORK/linefit http://code.icecube.wisc.edu/svn/projects/directwalk/trunk/ -> $I3_WORK/directwalk
After checked out this modules, going through the normal IceTray procedure, make env.sh, . env.sh, make, etc. you can import the needed projects into Eclipse IDE. NOTE: I'm talking here so long about subclipse, trunk, etc. just to avoid any hassle with breaking a working release in working with a repository.
Change via the Window->Open Perspective->Other.. menu into the C/C++ perspective. Choose the File->New->Project.. menu, you will get the "New Project" window. Choose "Standard Make C++ Project".

Add a new C++ project. (Remember, my I3_WORK points to /home/dpieloth/icecube/work. I checked out there e.g. the linefit project.
In the next window, choose the settings like that.(I will tell you something about the Indexer later.)


Now, you imported your first IceTray project into the workspace. You should see a workspace window similar to that one below. Notice, Eclipse IDE already compiled the code. You should also notice the connection to the subversion repository. This can be seen by the database symbol in the left window.

THE NEXT STEP IS VERY IMPORTANT! DISCONNECT THE MODULES YOU DON'T HAVE TO CHANGE OR DON'T WANNA CHANGE FROM SUBVERSION. Do that by right click the linefit module e.g., the choose the Team->Disconnect menu. You will be asked for disconnect SVN from analog2hits module. CHOOSE YES!
Now the workspace should look like this: (You see, the database symbols gone.)
Importing all the modules you need, the workspace should look like this:
Notice: for the trunk version of directwalk, I did not disconnected the module from SVN. Now, changing something in the I3DirectwalkModule.cxx file and saving the changes, the IDE compiles the module and give you a hint about the changes you did relative to the version you checked out: (notice the star symbols in the left window.)
Now you can work with your code, compiling it, checking in changes to svn via a right click on file -> Team -> Commit.. menu. DONT BREAK THE TRUNK! :O) Additional, you can add other targets (of course, they must be in the Makefile...) to the workspace. Go for that through right click on a module -> Build Make Target.
You can add e.g. a clean bin and all-tests-run target:




Running the all-test-run target should give you an output like that:
Running and Debugging modules within Eclipse IDE
We are running our modules within the ROOT environment, so we will do the same in Eclipse. First, I made a little - the one and only addition! - to my shell environment. I added a .rootrc in my $HOME with
simply because ROOT complains about "cannot find MACRO..." - the macro I'm using here for explanation. I change the CFirstTest.C macro a little bit, to run it within a ROOT session and rename it to Test.C
int run()
{
bool eventViewer = false;
//string inputType = "AmandaAnalog";
string inputType = "RecoHit";
// Load some of the needed libraries into ROOT.
gSystem->Load("libamanda-core.so");
gSystem->Load("libdataclasses.so");
gSystem->Load("libdataio.so");
gSystem->Load("libicetray.so");
gSystem->Load("libphys-services.so");
...
outfile.append("/cfirst/output/cfirst.root");
tray.SetParameter("root_tree", "RootFileName", outfile);
tray.SetParameter("root_tree", "TreeName", "treeCFirst");
tray.Execute();
tray.Finish();
return 0;
}
To run a makro within the Eclipse IDE go through the steps below:
First go to the Run->Run.. menu. Choose New C/C++ Local Application. For the example I used here, the settings are:



Pushing the Run button should bring in IDE into the run modus. You can load the macro by .L Test.C then run() command in the console:
If everything went fine, you should see below the same output if running CFirstTest.C from a shell:
Stop your run session by pushing the Terminate button.
To debugging a module within Eclipse IDE you should first set a breakpoint by right click the source code on the left margin and choosing "Toggle Breakpoint".

then, second choosing the Run->Debug.. menu. Create a New C/C++ Local Application with the same settings like before for running the module. (Note: a module will be attached to ROOT exe. GDB is complaining about no debug symbols in the ROOT exe.) You will be asked for change into the debug perspective, say Yes.

Now your are in the Debug perspective, again load the macro in the console by .L Test.C and then run it by run(). The execution should stop at the breakpoint:

Depending on your CPU, memory, etc. this could take a while. Also, it takes a while before the variable values, etc. can be seen. Be patient... Now you can step through your code step by step, looking at variables, registers, etc. Terminate your debugging session by pushing the Terminate button.
Further notice
I do not use the indexer, because I takes to much time to indexing the whole code and I do not like, that the code is indexed every time you start the IDE.
Please, do not import any plugin into your setup, this might break your installation of Eclipse IDE. E.g. importing the photran plugin into your working copy of Eclipse IDE will make it useless for C/C++ development.
You can use Eclipse IDE for Sieglinde development too. CVS support is included into Eclipse IDE, you don't need any plugin for that.
The are many other plugins, you can use within that IDE, e.g. phyton, etc.
Also: Eclipse and CDT are under steady development. I do not guarantee, that this will all work for you with other versions, etc.
LinksEclipse IDE - Eclipse IDE
CDT Plugin - CDT Plugin
Subclipse - Subclipse Plugin
Photran - Fortran Plugin
Pydev - Python Plugin
|