Re: problem in histogram computations

From: M. Sievers (sieversm@mail.desy.de)
Date: Mon Feb 08 1999 - 09:52:17 MET


Hello Rene,

thanks for your answer.

On Fri, 5 Feb 1999, Rene Brun wrote:

> M. Sievers wrote:
[...]

> > root [0] TH1D one("hone","histo one",10,0,10);
> > root [1] TH1D two("htwo","histo two",10,0,10);
> > root [2] TH1D three("hthree","histo three",10,0,10);
> > root [3] three.Print()
> > TH1.Print Name= hthree, Total sum= 0
> > root [4] three = one + two;
> > root [5] three.Print()
> > TH1.Print Name= hone, Total sum= 0
[...]

> Hi Michael,
> Apologies for the delay in answering several mails to roottalk, rootdev
> and private lists.

... and sorry for flooding you! I had the impression that posting to our
newsserver did not forward the mail to the roottalk list...
 
> To add histograms using the operator "+", you should not create an
> object
> before making the operation. In your case above, you can do directly:
> The resulting histogram is automatically created in the operation.
> Its name by default is the name of the first histogram.
> This is simply a convention. You can use SetName immediatly after
> to rename it.
> You can also create your histogram "three" before the operation and
> instead of using the operator "+", use directly one of the functions
> TH1::Add.

Please excuse me if my grasp of C++ leads to wrong statements. But I
believe a statement like

TH1D three = one + two;

does not call the overloaded operator=, but the Copy constructor instead.
For the copy constructor, I would agree with the convention of taking the
first name. But the operator= acts on already declared objects, so one has
to be prepared for a name to be present, and should not overwrite it.

If you insist on an object to be defined when the '=' is used, an
overloaded operator= is superfluous (if I'm not mistaken) and even
misleading, since it can only be used when the object has already been
created, which is the way I used it.

Instead of removing operator=, I would suggest keeping the copy
constructor as it is and removing operator= from the Copy routine, or at
least have it check if this->fName is set to some value before overwriting
it.

I still think changing the name of an existing object should be
disallowed.

What do you think?

Bye,
Michael

--------------------------------------------------------
Michael Sievers
Michael.Sievers@desy.de
--------------------------------------------------------
Black holes are where God divided by zero.



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:29 MET