Problem for launching a C-script outside CINT

Hi all,

I have to implement a “live” histogram in a data acquisition program for IIHE (Inter-University Insitute for High Energies).

The problem is that the histogram handling must be done inside a bigger c++ program. And I don’t know how to do this.

I have written a little test who shows the problem I face in the bigger program:

[code]lxpub2> cat test_histo.c

#include <TH1.h>

int main(void)
TH1C *h = new TH1C(“histo”, “Delta Histo for 2 detectors”, 200, -100, 100);
h -> Draw();
h -> Fill(1);
h -> Fill(2);

lxpub2> cat Makefile

GCC = g++
CFLAGS = -O -pipe
ROOTLIBS = -L$(ROOTSYS)/lib -lASImage -lGraf -lCore -lCint -lHist -lHistPainter -lGpad -lMatrix

$(GCC) $(CFLAGS) $(ROOTLIBS) $(INCLUDES) test_histo.c -o test_histo

lxpub2> make
g++ -O -pipe -L/user/adeprell/root/lib -lASImage -lGraf -lCore -lCint -lHist -lHistPainter -lGpad -lMatrix -I/user/adeprell/root/include test_histo.c -o test_histo
lxpub2> ./test_histo
TCanvas::MakeDefCanvas: created default TCanvas with name c1

So this script launched standalone in a shell is well running but no histogram does appear
PS: when I launch the script in CINT (.x test_histo), the histogram is well appearing.
What’s wrong with this ?

Thank you for your help :wink:

You must include a TApplication object in your program.
See examples eg in $ROOTSYS/test/hworlld2.cxx.

In your case, do:

[code]#include <TH1.h>
#include <TApplication.h>

int main(int argc, char **argv)
TApplication theApp(“App”, &argc, argv);

TH1C *h = new TH1C(“histo”, “Delta Histo for 2 detectors”, 200, -100, 100);
h -> Draw();
h -> Fill(1);
h -> Fill(2);



It works,

Thank you very much !

I have a question in relation with TApplication::Run().

The function doesn’t seem to give back the hand to the program which call it.
So I launched the Run() routine in another thread while the main thread will fill the histo. Is it possible ?

My method seems wrong…
Here is a snip of the output:

[quote]TCanvas::MakeDefCanvas: created default TCanvas with name c1
Error in TApplication::TApplication: only one instance of TApplication allowed[/quote]

And here is a snip of the code:

... void *root_launcher(void *arg) { TApplication syncHistApp("Sync", NULL, NULL); syncHistApp.Run(); return NULL; } ... int main(void) { ... pthread_t sync_t; ... TH1C *h = new TH1C("histo", "Delta Histo for 2 detectors", 200, -100, 100); h -> Draw(); if (pthread_create(&sync_t, NULL, root_launcher, (void *) i)) { perror("ROOT Init failed"); exit(EXIT_FAILURE); } ... }

Thank you for any welcome help :wink:

[EDIT] Sorry, I forgot TApplication syncHistApp(“Sync”, NULL, NULL); in the main() … :blush: It is well working now :wink: