I agree, good example. operator = was overlooked :-(
However "memcpy" here is useful to show what is going
on "behind the curtain" :-)
Thank you.
-----
Dr.Valeri Fine
STAR/US Atlas E-mail: fine@bnl.gov
Brookhaven National Lab Phone: +1 631 344 7806
Upton, NY 11973-5000 FAX: +1 631 344 4206
USA
----- Original Message -----
From: "Christian Holm Christensen" <cholm@hehi03.nbi.dk>
To: <fine@bnl.gov>
Cc: <tim.miller@vanderbilt.edu>; <roottalk@pcroot.cern.ch>
Sent: Thursday, September 06, 2001 12:38 PM
Subject: Re: [ROOT] PAW to ROOT
> Hi,
>
> On Wed, 5 Sep 2001 18:10:37 -0400
> "Valeri Fine" <fine@bnl.gov> wrote
> concerning "Re: [ROOT] PAW to ROOT":
> > Since both classes TH1F as well as TH2F ( http://root.cern.ch/root/htmldoc/TH2F.html ) are
> > derived from TArrayF (http://root.cern.ch/root/htmldoc/TArrayF.html)
> > all methods of the last one are available.
>
> >
> > TH2F *hist = (TH2F*)file->Get("hist_id");
> > int dimX = (int)hist->GetNbinsX();
> > int dimY = (int)hist->GetNbinsY();
> >
> > float *vect = new float[dimX*dimY];
> > memcpy(vect,hist->fArray,sizeof(vector));
> >
> > > Whether there is a clean, simple function call in a ROOT
> > > class, I'm not sure (haven't look at recent versions)
> >
> > One one needs no special function.
> > The function "memcpy" can do job.
>
> One can do it even simpler than that:
>
> TRandom* r = new TRandom;
> TH1F* h1 = new TH1F("h1", "Hello World", 100, 0, 10);
> for (Int_t i = 0; i < 1000; i++) h->Fill(r->Gaus(5,2));
> TH2F* h2 = new TH2F("h2", "Hello World", 100, 0, 10, 100, 0, 10);
> for (Int_t i = 0; i < 1000; i++) h->Fill(r->Gaus(5,2),r->Gaus(5,2));
> TArrayF* a1 = new TArrayF(*h1);
> TArrayF* a2 = new TArrayF(*h2);
>
> Now you have the bounds checking TArray class instead of the low-level
> float** type to play around with. IMHO, much simpler. You can
> probably write the above as
>
> TArrayF a1 = *h1;
> TArrayF a2 = *h2;
>
> I'm personally not really keen on C functions like memcpy, and the
> like. memcpy is especially "bad", since it just copies bit for bit
> the input to the output, and hence surcumvents the C++ strong typing,
> which is one of the reasons for using C++ in the first place. This is
> also the reason why one should strive to use classes like string (or
> in case of ROOT TString) rather than pointers to const char, and so
> on. Much cleaner OOP. Perhaps, the methods like TNamed::SetName
> should really take a string/TString reference as argument, rather than
> a const Char_t pointer (I know it's probably not gonna happen, but IMHO
> it's cleaner - maybe for ROOT 4 :-).
>
> Yours,
>
> Christian Holm Christensen -------------------------------------------
> Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91
> DK-2200 Copenhagen N Cell: (+45) 28 82 16 23
> Denmark Office: (+45) 353 25 305
> Email: cholm@nbi.dk Web: www.nbi.dk/~cholm
>
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:59 MET