Online Histogram Update through Macro

Hi guys,

I’m trying to do a simple online display - a histogram that every second updates with new data arriving.
I did a sample code that reads a tree file that gets update on the go by the daq process (different c++ program)

How do i get the histogram to fill again and redraw? also how do i make my canvas responding while waiting for new data to arrive?

for testing i just want the hist to fill random and redraw itself every second.
i’m running the file with .x OnlineViewer.C

[code]void OnlineViewer()
{
TH1F * OccupancyHist = new TH1F(“Occupancy”,“Occupancy”,200,-5,5);

//Creating the gui canvases 
TCanvas cOccupancy("Occupancy","Occupancy",0,0,1000,700);
cOccupancy.cd();
cOccupancy.Update();
OccupancyHist->FillRandom("gaus");
OccupancyHist->Draw();
cOccupancy.Update();


while ( true )
{
    gSystem->Sleep(1000);
    OccupancyHist->FillRandom("gaus");
    cOccupancy.cd();
    OccupancyHist->Draw();
}

}[/code]

all i’m getting now is a frozen canvas that doesn’t updates at all.
I realize that my problem is fundamental so i would love to get some guidelines & better practices.

Thanks

In order to get your canvas “updated”, replace: cOccupancy.cd(); OccupancyHist->Draw(); with: cOccupancy.Modified(); cOccupancy.Update();
If you want to make your canvas “responding while waiting”, you need to call “gSystem->ProcessEvents();” in regular intervals (if there are any “pending” events they will be “processed”, and if not, your program will simply “continue”).
Try:
grep -r ProcessEvents ${ROOTSYS}/tutorials
grep -r ProcessEvents ${ROOTSYS}/test
and see how it’s used there.
The simplest trial would be to replace: gSystem->Sleep(1000); with: for (Int_t i = 0; i < 10; i++) { gSystem->ProcessEvents(); gSystem->Sleep(100); }

Great, thats a great starting point for me, thanks allot!