ProgressBar in non-gui program

I have an application that processes a root TFile and save the results back in the file. This processes very large files so I would like to display a TGHProgressBar to show progress. How do I (or can I) do this without using TApplication::Run() which just goes away?

Thanks,
Glenn Sembroski

Hi Glenn,

The “pseudo” progress bar example that shows up on the root prompt could be useful for you. I have extracted it from the code provided by Christian Stratowa at: root.cern.ch/phpBB2/viewtopic.php?t=2193

To see how it works, please do:root [0] .x MyProgress.cxx++ root [1] .L macroMyProgress.C root [2] Init() root [3] Test("MyTest", 100) All files are included in the prog.tar file, attached below.

Cheers, Ilka
prog.tar (10 KB)

Thank you for the example. I will use that method but was hoping to make a nice gui type standalone Progress box (like can be done with qt). Does anyone have an idea how to do that (without resorting to threads)?

Glenn

[quote=“dsteele”]Thank you for the example. I will use that method but was hoping to make a nice gui type standalone Progress box (like can be done with qt). Does anyone have an idea how to do that (without resorting to threads)?

Glenn[/quote]
Just turn Qt Root layer on and use it :smiley:

[quote=“dsteele”]I have an application that processes a root TFile and save the results back in the file. This processes very large files so I would like to display a TGHProgressBar to show progress. How do I (or can I) do this without using TApplication::Run() which just goes away?
Glenn Sembroski[/quote]

What you really want?

I think the TTimer class can help you.
Create TTimer and connect its Timeout() slot with the TGProgressBar::Increment() method, then perform your long action:

while(1) {
ReadRecord();
gSystem->DispatchOneEvent();
AnalizeRecord();
gSystem->DispatchOneEvent();
WriteRecord();
gSystem->DispatchOneEvent();
}

(sorry, I have no good access to the real computer right now to test and provide you the running example)

Hi Glenn,

It seems I misunderstood your first message. The reasons of sending a non-GUI example were two: the subject of this posting: “Progress bar in non-gui program” and the fact, that TApplication::Run() goes away. The TGApplication might do the job (TGApplication creates a GUI application environment and can be used with the ROOT GUI and no other services). In short, I got an impression that you want stay away from the GUI, but it was not the case as your answer shows.

Cheers, Ilka

Hi Glenn,

Please take a look at the code in attachment (code taken from guitest)

Cheers,
Bertrand.
test.cxx (2.25 KB)

I did try to use TApplication.
Below is a listing of how I tried to do it.
I will be the first to admit I don’t know what I’m doing. There are probably
a lot of errors in this.
When I run this, well, basically nothing appears on the screen (no little
window with a progress bar) but the analysis loop completes with no problems.

Glenn


main program


#include <TROOT.h>
#include <TApplication.h>
#include “VAProgress.h”
.
.
.
int main(int argc, char** argv)
{
//.
//.
//Bunch more stuff, nothing to do with ROOT
//.
//.

TROOT root(“Analysis”,“Analyse Events”);
TApplication theApp(“App”,&argc,argv);
VAProgress* fAnlProgressBar = new VAProgress(gClient->GetRoot());

//.
//Start of analysis loop
//…
//.
//just before end of analysis loop
float fProg=(float)nEvent/(float)fNumArrayEvents;
fAnlProgressBar->UpdateProgress(fProg);
} //End analysis loop
//.
//.
} //end of main

//VAProgress.h******************************
#include <TGWindow.h>
#include <TGFrame.h>
#include <TGProgressBar.h>
#include <TGClient.h>

class VAProgress: public TGMainFrame
{
private:
TGHProgressBar* fProgress;
public:
VAProgress(const TGWindow* p);
~VAProgress();
void UpdateProgress(float fProg);
};

VAProgress::VAProgress(const TGWindow* p):TGMainFrame(p,300,300)
{
fProgress = new TGHProgressBar(this,TGProgressBar::kStandard,300);
fProgress->SetBarColor(“blue”);
fProgress->SetRange(0.,1.0);
fProgress->ShowPosition(kTRUE,kFALSE);
this->AddFrame(fProgress,new TGLayoutHints(kLHintsTop |
kLHintsLeft | kLHintsExpandX,5,5,5,10));
this->SetWindowName(“Analysis Progress”);
this->MapSubwindows();
this->Resize(this->GetDefaultSize());
this->MapWindow();
return;
}

VAProgress::~VAProgress()
{
//nothing to do
}

void VAProgress::UpdateProgress(float fProg)
{
fProgress->SetPosition(fProg);
return;
}

You need

gSystem->DispatchOneEvent();
somewhere

The good candidate is
void VAProgress::UpdateProgress(float fProg)

Thank you Valeri. Thta’s what I needed. I did have to use:
gSystem->DispatchOneEvent(kTRUE) otherwise it stalled after the third call.
So, it all works now, pretty much as given above.

Thanks again,
Glenn Sembroski
sembrosk@physics.purdue.edu

:smiley:

What about Qt. With Qt/Root layer “On”, in the other words with

Gui.Backend qt Gui.Factory qt
in your “.rootrc”/ $ROOTSYS/etc/system.rootrc file instead of the regular

Gui.Backend native Gui.Factory native
you can use the Qt QProgressDialog as prescribed by
doc.trolltech.com/3.3/qprogressdialog.html

Call your attention that within Qt/ROOT layer you can still use

as the TrollTech suggests. However you can use

instead. The outcome should be :unamused: the same.