Re: Creating and Filling Many Histogram

From: Jiri Masik <masik_at_fzu.cz>
Date: Sat, 12 Feb 2005 14:57:39 +0100


Hi,

indeed the error "variable argument not supported..." below used to be issued by cint on non-ia32 platforms where Form etc lacked underlying implementation. I think the array of pointers itself is allocated and test_scrip below is legal.

cheers

Jiri

Rene BRUN <brun_at_mail.cern.ch> writes:

> I thought that you were just using CINT and execute
> root > .x test_scrip.C
>
> I see now that you are compiling your code.
> Your code compiles OK with gcc2.3 and gcc3.3.
> I have no way to test it right now with gcc3.4.
> In principle what you do is not legal C++ (it is accepted by
> CINT and all versions of gcc that I know, and also VC++,
> the Alpha/cxx and Aix/xlC compilers.
>
> if gcc3.4 does not accept this, you must use the new operator
> to create a dynamic array of pointers to TH1F.
>
> Rene Brun
>
> On Sat, 12
> Feb
> 2005,
> zaldy wrote:
>
>>
>> Dear Rene,
>>
>> Still not successful even for the simple line as below.
>> Thanks....
>>
>> void test_scrip()
>> {
>> const int nb = 34;
>> float a=-170.;
>> float b=170.;
>>
>> TH1F* histo_xvsz_front[nb];
>> histo_xvsz_front[1] = new TH1F(Form("histo_xvsz_front_001"), Form("Histogram xvsz_front_1"), nb,a,b);
>> }
>>
>> Error Message:
>>
>> Processing test_scrip.C...
>> Limitation: Variable argument is not supported for this platform
>> FILE:test_scrip.C LINE:8
>> *** Interpreter error recovered ***
>>
>> Version 4.02/00 29 January 2005
>> gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
>>
>> //---------------------------------------
>> > Replace
>> > for(Int_t i = 1; i <= nb; i++)
>> > by
>> > for(Int_t i = 0; i < nb; i++)
>> >
>> > Rene Brun
>> >
>> > On Sat, 12 Feb 2005, zaldy wrote:
>> >
>> > >
>> > > Hi,
>> > >
>> > > What is wrong with this piece of code
>> > >
>> > > //--------------------------------
>> > > void test()
>> > > {
>> > > const int nb = 34;
>> > > float a=-170.;
>> > > float b=170.;
>> > >
>> > > TH1F* histo_xvsz_front[nb];
>> > > for(Int_t i = 1; i <= nb; i++)
>> > > {
>> > > histo_xvsz_front[i] = new TH1F(Form("histo_xvsz_front_%03d",i),Form("Histogram xvsz_front #%d",i), nb,a,b);
>> > > }
>> > >
>> > > }
>> > >
>> > > Thanks
>> > >
>> > > using RootVersion 4.02/00 29 January 2005
>> > > on gcc version 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)
>> > >
>> > > //----------------------------
>> > >
>> > > > Hi Zaldy,
>> > > >
>> > > > zaldy <zaldy_at_neutrino.kek.jp> writes:
>> > > >
>> > > > > I have two questions.
>> > > > > I would like to create many histogram simultaneously with names of the
>> > > > > form: histo_1, histo_2, .... , histo_(i) where i=1,2,3,4,....,n.
>> > > > >
>> > > > > I figure out doing it like this:
>> > > > >
>> > > > > for(Int_t i=1; i<n; i++)
>> > > > > {
>> > > > > TH1F * histo_(i) = .....
>> > > > > }
>> > > >
>> > > > First, you need square brackets for array dereferencing in C++.
>> > > >
>> > > > TH1F * histo_[i] = .....
>> > > >
>> > > > As for a sequence of similar histograms I often do things like:
>> > > >
>> > > >
>> > > > const int n=100;
>> > > > TH1F* histo[n];
>> > > > for(Int_t i=1; i<n; i++)
>> > > > {
>> > > > TH1F * histo[i] = new TH1F(Form("name_%03d",i),Form("Histogram #%d",i),...);
>> > > > }
>> > > >
>> > > > If you don't actually care about the name and will always refer to the
>> > > > histogram via the pointer then you don't need a unique name but you
>> > > > need to call SetDirectory(0):
>> > > >
>> > > > const int n=100;
>> > > > TH1F* histo[n];
>> > > > for(Int_t i=1; i<n; i++)
>> > > > {
>> > > > TH1F * histo[i] = new TH1F("blah","Blah Blah",...);
>> > > > histo[i]->SetDirectory(0);
>> > > > }
>> > > >
>> > > >
>> > > > Luck,
>> > > > -Brett.
>> > > >
>> > >
>> > >
>> >
>>
>>
>
>

-- 
Jiri Masik
Institute of Physics, Academy of Sciences of the Czech Republic
Na Slovance 2 // 182 21 Prague 8 // Czech Republic
Phone: +420 266 052 690 // +420 608 271 585 (mobile) // +420 286 585 443 (fax)
Received on Sat Feb 12 2005 - 14:57:47 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:04 MET