Updating a TCanvas before TApplication::Run() instruction

Hi everyone,

I’m trying to implement (in a not-so-elegant way) a “browser” for TH1 objects, created starting from data stored in a file, as a stand-alone program. I need to Draw() on a canvas the waveform associated to an event and then moving through the others either by hitting “return” (next event) or by typing “-” and then hitting return (previous event). Since I’m not so familiar with The TCanvas::Update(), TCanvas::ForceUpdate() or TCanvas::Flush() functions I’m not able to display anything until the TApplication::Run() instruction. Here’s my code:

[code]include
// …

int main() {

// stuff...

chain.GetEntry(0);
wf = event->GetWaveform(0);
hist = wf->GimmeHist();
hist->Draw();
can.Update();

int N = chain.GetEntries();
int i =  1;

while ( 1 == 1 ) {
    
    cout << "event " << i << ": ";
    chain.GetEntry(i);
    wf = event->GetWaveform(0);
    
    hist = wf->GimmeHist();
    can.Update();

    int choice = waitForEnter();
    if ( choice == 1 ) break;
    if ( choice == 2 && i < N ) i++;
    if ( choice == 2 && i == N ) continue;
    if ( choice == 3 && i > 0 ) i--;
    if ( choice == 3 && i == 0 ) continue;
    if ( choice == 4 ) {
        cout << "           Go to: ";
        cin >> i;
    }
}

cout << "Close the ROOT session to exit the program";
app.Run(kFALSE);

return 0;

}

int waitForEnter() {
string input;
getline( cin , input );
if ( input.compare(“exit”) == 0 ) return 1;
if ( input.compare("-") == 0 ) return 3;
if ( input.compare(“goto”) == 0 ) return 4;
else return 2;
}[/code]
As you can see I also tried to draw the first event before the loop and call TCanvas::Update(), but the only thing I can reproduce inside the loop is a blank canvas. What TCanvas member function I should use to update it?
loopOverList.cc (3.37 KB)

Why don’t you use the command root browse coming with the root installation. just type:

rootbrowse yourfile.root

I see it’s not included in my version (6.03.02), i need to install a more recent one.
However, I also want to manipulate my signals before drawing them (e.g. marking them accordingly to the selection provided by an external TEventList object), does that command provide such a feature?

Cheers.

Now I see that that command simply opens the root browser, I cannot use it for my purpose. As you can guess from the complete code in the attachments, the file I’m trying to browse does not consist of TH1 objects. Indeed it consist of instances of a custom class, and I need to use another function to extract the TH1 object and then draw it.

In your 1st post you said:

That’s what root browser does. That’s why I pointed it to your attention.

You are right, my mistake. I will correct the post.