Re: Calling ROOT in a C++ code

Rene Brun (Rene.Brun@cern.ch)
Tue, 10 Jun 1997 17:08:24 +0200


Pascal Perrodo wrote:
>
> Hi,
>
> First as a new root user thanks to root authors to provide a free product
> adapted to Scientific (e.g. Particle Physics) Work!!!
>
> My problem:
> I call root in a C++ code. In there I succeed to open a canvas, fill histos
> and draw them in the canvas. Now when I go in the canvas and try to do
> anything interactively with the mouse, the canvas is not refreshed and
> the histograms don't appear any longer.
> How to solve that?
> I am working with root
> Version 1.01/04 4 June 1997
> on HP-UX 9.x
>
> thanks in advance for help.
>
> Pascal Perrodo.

In the root/test directory, we have an example hworld (see code below)
illustrating how to call ROOT in batch and activate the event loop.

Rene Brun

//__________________________example hworld.cxx ________________________________

// This small demo shows the traditional "Hello World". Its main use is
// to show how to use ROOT graphics and how to enter the eventloop to
// be able to interact with the graphics.

#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TLine.h"
#include "TPaveLabel.h"

extern void InitGui();
VoidFuncPtr_t initfuncs[] = { InitGui, 0 };
int Error; // needed by Motif

TROOT root("hello","Hello World", initfuncs);

int main(int argc, char **argv)
{
TApplication theApp("App", &argc, argv);

TCanvas *c = new TCanvas("Hello", "The Hello Canvas", 400, 400);
c->Show();

TPaveLabel *hello = new TPaveLabel(0.2,0.4,0.8,0.6,"Hello World");
hello->Draw();
c->Update();

// Enter event loop, one can now interact with the objects in
// the canvas. Select "Exit ROOT" from Canvas "File" menu to exit
// the event loop and execute the next statements.
theApp.Run(kTRUE);

TLine *l = new TLine(0.1,0.2,0.5,0.9);
l->Draw();
c->Update();

// Here we don't return from the eventloop. "Exit ROOT" will quit the app.
theApp.Run();

return 0;
}