Re: [ROOT] array of histograms

From: Jiri Masik (masik@pc203b.fzu.cz)
Date: Fri Feb 28 2003 - 16:37:03 MET


Jano Hruby <fly@pobox.sk> writes:

>   Hello,
> I have problem with this small program in loop.
> If I comment in program exam.C 2 lines:
> // else
> //  TH1F *hcham[p1] = (TH1F*)gDirectory->FindObject(hname[p1]);
> program working, but every loop: Warning in <TH1::Build>: Replacing
> existing histogram: x1 ....
>
> If I uncomment this 2 lines:
> root [0].x exam.C
> Error: Non-static-const variable in array dimension .....
>
>
> Please help me, thanks
> Jan
>
>
> listing exam.C
> void exam()
> {
>
>   if ( !(gROOT->GetListOfCanvases()->FindObject("c1")) )
>     {
>       c1 = new TCanvas("c1","");
>       c1->cd();
>     }
>
>   const UShort_t num=4;
>   char *hname[num]={"x1","y1","x2","y2"};
>
>   TH1F *hcham[num];
>
>   for (UShort_t p1=0; p1<num; p1++)
>     if( !(c1->GetPrimitive(hname[p1])) )
>       {
> 	hcham[p1] = new TH1F(hname[p1],"",10,0,10);
> 	hcham[p1]->SetBit(kCanDelete);
>       }
>     else
>        	TH1F *hcham[p1] = (TH1F*)gDirectory->FindObject(hname[p1]);
>
>   // filling histo
>   // for (UShort_t p2; p2 <num; p2++)
>   //   hcham[p2]->Fill(.....);
>   // draw histo
>   // for (UShort_t p3; p3 <num; p3++)
>   //   hcham[p3]->Draw(.....);
> }
>

Hi Jano,

the error Non-static ... comes from the fact that there is an
invalid declaration of TH1F *hcham[p1] inside the else statement. 
The statement should be just
else hcham[p1] = (TH1F*)gDirectory->FindObject(hname[p1]);
you have a *hchan[num] declaration above.
Also p2 and p3 should be given an initial value.

cheers
Jiri



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:09 MET