Problems integrating ROOT into my own code and plotting

Hi

I am writing software for enigineering simulations and I would like to use ROOT to plot the output data in real time while my simulation is running.

First I compiled and installed ROOT in /usr/analysis/root, set up the environment variables and ran some of the tests. I also went through the tutorial by running the ROOT program from the command line. This is all very well and fine but I would like to be able to call the plotting functions from within my own code and update the plots in real time as my simulation runs.

In order to plot a graph I have followed the library dependancies diagram on p.6 of the user guide and linked the Gui, Gpad, Graf, Matrix, Hist, Core and Cint shared libraries into my program. I managed to create a TF1 object as in the user guide and I also managed to call the Draw() method of this object. During program execution a message about creating a default canvas was written to screen but window was opened!

I believe that I may be missing links to some of the graphics and X-Windows libraries neccesary to create a window and draw a graph. I also believe that I omitting to include some of the header files because when I create a TGraph object I get messages about “line ??? does not declare anything”.

I have searched high and low for a solution to my problem and failed to find one. Maybe I have just missed it.

Please could you help me with a list of the libraries I need to link and header files I need to include in my class decleration in order to create a TGraph object and draw a plot from a set of data points. If such a list or instructions on how to do this exists in the documentation then please refer me to it.

We provide several examples in $ROOTSYS/test.
See for example stress.cxx (where stress16 generates graphics).
You must create a TApplication object (or TRint if you want to use the CINT command line from your program).
See the stress main program and use the Makefile in the test directory.

Rene

:confused:

I do not have a problem with how to use the graphics classes and actually draw the graph so I understand the example in stress(16). I seem to have a problem actualling compiling my code. I have examined the makefile in the test directory and all my compiler and linker flags appear to be correct.

I am linking all the shared libraries produced by the “root-config --libs” and “root-config --glibs” commands. I included all the header files which stress.cxx and event.h include. When I compile using g++ I get the folowing errors: (below is a representative sample)

TH1.h:153: error: declaration does not declare anything
TH1.h:153: error: virtual outside class declaration
TH1.h:153: error: syntax error before numeric constant
TH1.h:154: error: declaration does not declare anything
TH1.h:154: error: virtual outside class declaration
TH1.h:154: error: syntax error before numeric constant
TH1.h:155: error: declaration does not declare anything
TH1.h:155: error: virtual outside class declaration
TH1.h:155: error: syntax error before numeric constant
TH2.h:60: error: declaration does not declare anything
TH2.h:60: error: syntax error before numeric constant
TH2.h:61: error: ISO C++ forbids defining types within return type
TH2.h:61: error: syntax error before numeric constant
TH2.h:62: error: syntax error before numeric constant
TH2.h:63: error: syntax error before numeric constant
TH2.h:64: error: syntax error before numeric constant
TH2.h:65: error: syntax error before numeric constant
TH2.h:66: error: syntax error before numeric constant
TH2.h:67: error: virtual outside class declaration
TH2.h:68: error: virtual outside class declaration
TH2.h:69: error: virtual outside class declaration
TH2.h:70: error: virtual outside class declaration
TH2.h:71: error: virtual outside class declaration
TH2.h:72: error: virtual outside class declaration
TH2.h:73: error: virtual outside class declaration
TH2.h:73: error: non-member function Stat_t GetCorrelationFactor(int, int)' cannot haveconst’ method qualifier
TH2.h:74: error: virtual outside class declaration
TH2.h:74: error: non-member function Stat_t GetCovariance(int, int)' cannot haveconst’ method qualifier
TH2.h:75: error: virtual outside class declaration
TH2.h:76: error: virtual outside class declaration
TH2.h:76: error: non-member function void GetStats(Stat_t*)' cannot haveconst’ method qualifier
TH2.h:77: error: virtual outside class declaration
TH2.h:77: error: non-member function Stat_t Integral(const Option_t*)' cannot haveconst’ method qualifier

So basically g++ wont compile the header files. I am compiling using g++ version 3.3.4 on SuSE 9.2 Professional.

I am at a complete loss. Please help.

Thanks in advance.
Tristan
:question:

Compile with
root-config --cflags --glibs

Rene

No such luck I am afraid. I still get exactly the same errors!

I am a fraid that you have to provide more information. It is difficult to guess what you are doing.
From the error message, it looks like you did not declare $ROOTSYS/include to the compiler.

Rene

I will try and provide as many details as possible.

I have isolated the code from my project and put together a simple program which I am now compiling manually at the command line rather than through the KDevelop Integrated Development Environment.

My program is as follows:
[color=red]
int main(int argc, char *argv[])
{
cout << “Hello world!” << endl;

TCanvas *c = new TCanvas("laten","latency simulation",700,600);    
c->Draw();

return EXIT_SUCCESS;

}[/color]

The header files I have included are:
[color=red]#include

#include “TROOT.h”
#include “TSystem.h”
#include “TH1.h”
#include “TH2.h”
#include “TFile.h”
#include “TMath.h”
#include “TF1.h”
#include “TF2.h”
#include “TProfile.h”
#include “TKey.h”
#include “TCanvas.h”
#include “TGraph.h”
#include “TRandom.h”
#include “TPostScript.h”
#include “TNtuple.h”
#include “TChain.h”
#include “TCut.h”
#include “TCutG.h”
#include “TEventList.h”
#include “TBenchmark.h”
#include “TSystem.h”
#include “TApplication.h”
#include “TClassTable.h”
#include “TObject.h”
#include “TClonesArray.h”
#include “TRefArray.h”
#include “TRef.h”
#include “TH1.h”[/color]

and the compile command is:
[color=red]gcc -o testG.sh graphics.cpp -Wall -fPIC -I/usr/analysis/root/include -L/usr/analysis/root/lib -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lGui -pthread -lm -ldl -rdynamic [/color]

With this set up I end up back where I started last week. I no longer get all the error messages described in my previous posts. However, “Hello world” is printed on the display but no canvas is drawn!

I hope this helps.

Tristan