TGProgressBar finishes way before loop

ROOT Version : 6.12/04
Hello all, I’ve created a TGProgressBar to track the progress of my TTreeReader Loop. The problem is that the progress bar “finishes” way before my loop through the tree.

I create my progress bar like so:

TGMainFrame *fMain = new TGMainFrame(gClient->GetRoot(), 600, 300);
TGVerticalFrame *fVframe = new TGVerticalFrame(fMain, 0, 0, 0);
TGHProgressBar *Prog = new TGHProgressBar(fVframe, TGProgressBar::kFancy, 300);
Prog->SetBarColor("purple");
Prog->ShowPosition(kTRUE, kFALSE, "%.0f events");
Prog->SetRange(0, number_of_events);
fVframe->Resize(300, 300);
fVframe->AddFrame(Prog);
fMain->AddFrame(fVframe);
fMain->SetWindowName("Progress Bar for Event Loop");
TGDimension size = fMain->GetDefaultSize();
fMain->Resize(size);
fMain->MapSubwindows();
fMain->MapWindow();

Prog->Reset();

Then in my TTreeReader loop I do:

int cnt = 0;
while (reader.Next()) {
    cnt++;
    Prog->Increment(cnt);

   //Do some analysis . . . . 

    if (reader.GetCurrentEntry()%1000 == 0) gSystem->ProcessEvents();
}

My TTree has about 47 million events in it, and takes about 140 seconds to loop through, whereas the progressbar fills up in maybe 5 seconds.

Hi,

is the number_of_events parameter a float? (as it should be…)

Yes it is a float.:stuck_out_tongue:

Then I would need a minimal reproducer…

My ROOT file is quite large (10 Gb), so I’m not sure how I can upload it to here…

OK, forget it, I’ll try to reproduce it when I have some time…

Cheers, Bertrand.

I think I figured it out, I was incrementing an integer ‘cnt’ by one every loop and then calling prog->increment(cnt), as below

int cnt = 0;
for (.......) {
    cnt += 1;
    Prog->Increment(cnt);
}

so the maximum of the progress bar was being reached well before the loop was over

I changed it to

Prog->Increment(1);

and now it works correctly, thank you anyways!

1 Like

OOps! Sorry, I overlooked your code… Please try to replace:

by:

Prog->Increment(1);

And let me know.

Cheers, Bertrand.

Yep, that’ll do it. Thanks

Sorry, I just saw that I was too late… :tired_face:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.