RE: Run Graph array macro

From: Ding Hengtong <dinght_at_iopp.ccnu.edu.cn>
Date: Thu, 16 Mar 2006 22:21:32 +0800 (CST)


Hi Fine,

    You are right we should write codes in a standard way. And rootcint is not strict and standard c++ interpreter.

On Thu, 16 Mar 2006, Fine, Valeri wrote:

> I would like to call your attention, even though CINT does not complain one MUST use the " TGraph *gr[4]" - array of the TGraph pointers rather the array of TGraph objects, to avoid the memory leak and any future confusions.
>
> To see what I am speaking about one should add two extra lines to the macro and edit the $ROOTSYS/etc/system.rootrc to make sure it contains
> "Root.ObjectStat: 1"
> The updated macro:
> {
> int i;
> TGraph gr[4];
> gObjectTable->Print(); // <---- NEW LINE
> Float_t a[4]={450,1050,1431,1983};
> Float_t b[4][4]=
> {1576,3420,4854,6635,117,262,402,528,21,53,71,93,4,18,24,28};
> TCanvas *c1=new TCanvas("c1","",1);
> c1->Divide(2,2);
> for(i=1;i<5;i++)
> {
> c1->cd(i);
> gr[i-1]=new TGraph(4,a,b[i-1]);
> gr[i-1]->Draw("AL*");
> }
> gObjectTable->Print(); // <---- NEW LINE
> }
>
> It should produce you 2 "Object tables".
> The first contains:
>
> Object statistics
> class cnt on heap size total size heap size
> TGraph 4 4 104 416 416
> The second one:
>
> Object statistics
> class cnt on heap size total size heap size
> TGraph 8 8 104 832 832
> I.e. the macro in question did create 8 TGraph objects instead of the expected 4.
> In fact this behavior is the bug in CINT to be fixed.
>
> Replacing "TGraph gr[4];" with "TGraph *gr[4];" removes the trace of the memory leak. The second object table contains the correct number of the objects:
> Object statistics
> class cnt on heap size total size heap size
> TGraph 4 4 104 416 416
>
> HTH, Valeri
>
>
>
>
> From: Ding Hengtong
> Sent: Wed 3/15/2006 10:36 PM
> To: Zhu FengRong
> Cc: roottalk_at_pcroot.cern.ch
> Subject: Re: [ROOT] Run Graph array macro
>
>
> Hi ,
>
> You should define "gr[4]" and "i",
> that is to say you should add "TGraph gr[4];" and change
> "for(i=1;i<5;i++)" into "for(Int_t i=1;i<5;i++)" in your macro, then it'll
> gonna be ok.
>
>
> uOn Thu, 16 Mar 2006, Zhu FengRong wrote:
>
>
> > Hello,
> > In the root_v4.01.02.Linux.RH7.3.gcc296 environment,I failed to run the
> > macro like this:
> >
> > {
> > Float_t a[4]={450,1050,1431,1983};
> > Float_t b[4][4]=
> > {1576,3420,4854,6635,117,262,402,528,21,53,71,93,4,18,24,28};
> > TCanvas *c1=new TCanvas("c1","",1);
> > c1->Divide(2,2);
> > for(i=1;i<5;i++)
> > {
> > c1->cd(i);
> > gr[i-1]=new TGraph(4,a,b[i-1]);
> > gr[i-1]->Draw("AL*");
> >
> > }
> > }
> > Would you help me to succeed in running it?
> > Thank you in advance.
> >
> > with best wishes,
> > Fengrong Zhu
> > Institute of High Energy Physics,
> > C.A.S P.R.C
> > zhufr_at_ihep.ac.cn
> > --
> > Open WebMail Project (http://openwebmail.org)
> >
>
>

-- 
************************************************
 *             Hengtong Ding                    *                    
 *                                              *
 *  Address:  Institute of Particle Physics,    *
 *            Central China Normal University   * 
 *            Wuhan, 430079,  P. R. China       *
 *  Tel:      0086 27 6786 7946 (lab)           *
 *            0086 27 8715 0351 (dormitory)     *
 *  Fax:      0086 27 6786 3213                 *
 *  Email:    dinght_at_iopp.ccnu.edu.cn           *
 *	      dinghengtong_at_hotmail.com          *
 ************************************************
Received on Thu Mar 16 2006 - 15:15:48 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET