Re: [ROOT] unique name

From: dfaden@iastate.edu
Date: Tue Jan 09 2001 - 23:08:58 MET


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



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