thanks for the reply.
that code is interesting… the call to gSystem->ProcessEvents(), seems to be part of an event loop written to explicitly cause the display update to happen. i see Draw()ing happens only once.
i used the TApplication::Run() call in main(), which i believe includes an event loop.
i expect there are many ways to accomplish the same things with the root libraries.
i am verry new to root programming. i tried to use threads for my application. my approach may be unusual, but it seems like it should work provided there is some thread safety in the root objects and methods.
in my application there are three threads. the calls used in the threads are: TPad::Modified(), TCanvas::Update(), TH1D::Fill(), and in the main() thread there is a call to TApplication::Run().
i have simplified the code to “test.c” as an example:
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <TRandom1.h>
#include <TH1.h>
#include <TApplication.h>
//#include <TTimer.h>
#include <TCanvas.h>
TCanvas *theCanvas;
TH1D *theHistograms[4];
pthread_t displayupdatethread;
pthread_t histogramfillthread;
static void *
histogramfill(void *qqq)
// this is the plot handleing thread for plots processed on the local machine.
{TRandom1 theRand;
while (1)
{ usleep(1000);
{ int i, j;
for (i = 0; i < 4; i++)
for (j = 0; j < 1000; j++)
theHistograms[i]->Fill(theRand.Gaus(5, 1));
}
}
pthread_exit(NULL);// (code execution never gets here)
}
static void *
displayupdate(void *qqq)
// this is the thread that should cause the display to be updated.
// here i can try various calls to see if the display is updated as expected.
{ while (1)
{ usleep(100000);// delay 1/10 second
//*
// this is one set of calls that cause the display to be updated:
int i;
for (i = 0; i < 4; i++)
{ theCanvas->cd(i + 1);
gPad->Modified();
//gPad->Update();
}
theCanvas->cd(0);
theCanvas->Update();
//*/
/*
// this is another set of calls that cause the display to be updated:
theCanvas->Paint();
theCanvas->Update();
*/
/*
// this set of calls does not cause the display to be updated:
theCanvas->Modified();
theCanvas->Update();
*/
}
pthread_exit(NULL);// (code execution never gets here)
}
int
connecthistogramfill(void *qqq)
{ if (pthread_create(&histogramfillthread, NULL, &histogramfill, qqq))
{ printf("the histogramfill thread did not start\n");
return(-1);
}
else return(0);
}
int
connectdisplayupdate(void *qqq)
{ if (pthread_create(&displayupdatethread, NULL, &displayupdate, qqq))
{ printf("the displayupdate thread did not start\n");
return(-1);
}
else return(0);
}
int
main(int argc, char* argv[])
{ TApplication* rootapp = new TApplication("test", &argc, argv);
//theCanvas is allocated for the life of the program:
{ Double_t w = 600;
Double_t h = 600;
theCanvas = new TCanvas("theCanvas", "the Canvas", w, h);
theCanvas->SetWindowSize(w + (w - theCanvas->GetWw()), h + (h - theCanvas->GetWh()));
}
// theHistograms[i] are allocated for the life of the program:
{ int i;
char name[255], title[255];
for (i = 0; i < 4; i++)
{ sprintf(name, "theHistogram[%d]", i);
sprintf(title, "the Histogram #%d", i);
theHistograms[i] = new TH1D(name, title, 200, 0.0, 10.0);
}
}
// create the sub pads:
theCanvas->Divide(1, 4);
// draw the histograms once
{ int i;
for (i = 0; i < 4; i++)
{ theCanvas->cd(i + 1);
theHistograms[i]->Draw();
}
theCanvas->cd(0);
}
// create two threads for filling and displsaying theHistograms[i].
{ int i, j;
if ((i = connecthistogramfill(NULL)) == 0)
printf("successfully started thread to fill histogram..\n");
if ((j = connectdisplayupdate(NULL)) == 0)
printf("successfully started thread to update the display..\n");
}
/*
// display could be updated with TTimer instead of with histogramfillthread:
TTimer *timer = 0;
timer = new TTimer(100,kFALSE); // 100 msec timeout
timer->Connect("Timeout()", "TCanvas", theCanvas, "Paint()");
timer->Connect("Timeout()", "TCanvas", theCanvas, "Update()");
timer->Start(100, kFALSE);
*/
rootapp->Run();
return 0;
}
the above code in file “test.c” was compiled:
g++ -pthread -c `root-config --cflags` test.c
g++ -pthread `root-config --libs` test.o -o test
when the resulting program “test” is run, it seems to be fine as long as the mouse is kept away from the window, but if you move the mouse over the histograms a while it shows artifacts and crashes.
could this be a bug in root?
even if it is a bug, i do need to work around the problem in order to use root for this application.
thanks
J
test.tar.gz (1.39 KB)