Re: [ROOT] unique name

From: Victor Perevoztchikov (perev@bnl.gov)
Date: Wed Jan 10 2001 - 21:23:05 MET


Hi Rene,

> > Hi David,
> > I do not see how to implement your suggestion in a general way. This will have
> > too many side-effects. Could you give some examples affecting your program?

why not instead of delete object with the same name, just rename it?
Let say add ".bak" to the name. If it not unique again add ".bak" again.

The it would be useful to add method Clear to delete all ".bak" objects
if needed

Victor


dfaden@iastate.edu wrote:
> 
> Hi,
>    Sorry, I don't have a concise demo code example.
>    I would like a general facility for creating uniquely named objects mostly
> for methods or classes that create internal, named objects. For example, I
> have a class which opens a new TCanvas. I would like it to be possible for
> multiple instances of this class to coexist -- without having one class's
> TCanvas overwrite another's. Some object's, like TCanvas, seem to require a
> name (under 2.23 at least, a no name TCanvas doesn't seem to be given a
> TCanvasImp).
>    Is it possible to TTree:Draw into an unnamed TH1?
>    Right now, I'm using the following code to generate unique names:
> 
> Char_t* GetUniqueName(const Char_t* baseName, Int_t baseNum)
> {
>   Char_t *name = new Char_t[200];
>   baseNum = abs(baseNum);
>   do {
>     sprintf(name, "%s%d", baseName, baseNum);
>     baseNum++;
>   } while (gROOT->FindObject(name));
>   return name;
> }
> 
>    Is there a better way?
>    Thank you.
> 
> David
> 
> > Hi David,
> > I do not see how to implement your suggestion in a general way. This will have
> > too many side-effects. Could you give some examples affecting your program?
> > The only objects that are automatically added to collections in memory
> > are histograms and Trees. We already provide an option (see TH1::AddDirectory)
> > to not add automatically histograms to the lists in memory.
> >
> > Rene Brun

-- 
Victor M. Perevoztchikov   perev@bnl.gov  perev@vxcern.cern.ch       
Brookhaven National Laboratory MS 510A PO Box 5000 Upton NY 11973-5000
tel office : 631-344-7894; fax 631-344-4206; home 631-345-2690



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:33 MET