Re: [ROOT] Problem accessing gPad

From: Marco van Leeuwen (mvl@nikhef.nl)
Date: Fri Jun 02 2000 - 14:53:08 MEST


Hi,

If you are anyhow spending time on this subject, please be aware of the
inconvenience as demonstrated in the attached macro (test_update.C): 
apparently Cint doesn't know about gPad in a while-loop, whereas it does
in a for-loop... 

Maybe connected to this is the fact that in a while-loop accessing
subpads, using c1_1 for example, doesn't work. In a for loop, it does
work, provided that the subpads are subpads of the current pad. See
test_update2.C for an illustration.

Maybe you were already aware of these limitations, but I just wanted to
bring them up for completeness sake. By the way: both examples were run
using root 2.23/12 on Linux.

Kind regards,

Marco van Leeuwen.

On Wed, 31 May 2000, Fons Rademakers wrote:

> We'll try to make the interface to CINT better in this respect.
> 
> -- Fons.
> 
> 
> Rutger van der Eijk wrote:
> > 
> > Hi,
> > 
> > Rene wrote:
> > > Before using gPad, a real pad must exist.
> > > Once a canvas has been instantiated, you can use gPad as before.
> > 
> > I find this behaviour confusing. It means that in every macro I use I have
> > to check if a canvas was already created. For one simple macro this is
> > okay. But if I chain them I add a lot of redundant checks. Isn't it
> > possible to somehome tell TRint about TCanvas by default?
> > 
> > cheers,
> > 
> > Rutger
> 
> -- 
> Org:    CERN, European Laboratory for Particle Physics.
> Mail:   1211 Geneve 23, Switzerland
> E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
> WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7677910
> 


{{
  gROOT->Reset();
  TCanvas *c1=new TCanvas("c1","Canvas #1",500,500);

  TH1F *h1=new TH1F("h1","Histo",100,0,1);
  h1->Draw();

  // with a while-loop, gPad won't work

  Int_t i=0;
  while (i<1000) {
    i++;

    // A for-loop would make it work
    // for (Int_t i=0; i<1000;i++) {

    h1->Fill(gRandom->Rndm());
    if (i%100==0) {
      printf("%d entries filled\n",i);
      gPad->Modified();
      // this always works:
      // TVirtualPad::Pad()->Modified();
      c1->Update();    
    }
  }
}}

{{
  gROOT->Reset();
  TCanvas *c1=new TCanvas("c1","Canvas #1",500,500);
  c1->Divide(1,2,0,0,0);
  c1->cd(1);
  TH1F *h1=new TH1F("h1","Histo",100,0,1);
  h1->Draw();
  c1->cd(2);
  TH1F *h2=new TH1F("h2","Histo",100,0,1);
  h2->Draw();

  TCanvas *c2=new TCanvas("c2","Canvas #2",500,500);
  c2->Divide(1,2,0,0,0);
  c2->cd(1);
  TH1F *h3=new TH1F("h3","Histo",60,-3,3);
  h3->Draw();
  c2->cd(2);
  TH1F *h4=new TH1F("h4","Histo",100,0,1);
  h4->Draw();

  // with a while-loop, c1_1 etc won't work

  Int_t i=0;
  while (i<1000) {
    i++;

    // A for-loop would make it work
    // for (Int_t i=0; i<1000;i++) {

    h1->Fill(gRandom->Rndm());
    h2->Fill(sqrt(gRandom->Rndm()));    
    h3->Fill(gRandom->Gaus(0,1));    
    h4->Fill(gRandom->Gaus(0,0.5));

    if (i%100==0) {
      printf("%d entries filled\n",i);
      c1->cd();              // even in a for-loop you need these
      c1_1->Modified();
      c1_2->Modified();
      c1->Update();
      c2->cd();              // even in a for-loop you need these
      c2_1->Modified();
      c2_2->Modified();
      c2->Update();    
    }
  }
}}





This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:27 MET