Hi,
I'm using this function for many years:
const char* nextname(const char* base="h") {
// if name 'base' already exists increaments it like h_1, h_2, etc.
// returns pointer to circular buffer owned by ROOT function Form
bool found = gDirectory->Get(base);
if (!found) return base;
Int_t icycle = 0;
while (found) {
std::stringstream ss; ss.str(""); ss << base << "_" << ++icycle; //cout<< " current hname: " << ss.str() <<endl; found = gDirectory->Get(ss.str().c_str());}
My 2 cents,
Andrei.
On Tue, Apr 13, 2010 at 9:44 PM, Fine, Valeri <fine_at_bnl.gov> wrote:
>
> > > I discussed with Fons, it's a pretty common issue. We could put the
> > > random string generator into TString. Could you suggest a function?
>
> As far as I know there is no common "TNamed-related" problem that can be
> resolved with the single silver bullet ("random string generator").
> There are several separated issues. Each needs its own carefully
> crafted solution.
>
> Which concrete class / issue are we discussing right now?
>
> For example, for the histogram objects (subclasses of TH1) it is
> sufficient to invoke the static method:
>
> TH1::AddDirectory(false);
>
> See: void TH1::Build() as well
>
>
>
>
> Thank you,
> Valeri
>
> > I'm not sure whether we need a random string, I can't think of an
> > application where a unique string wouldn't be sufficient.
> >
> > I've attached a prototype of a TUniqueString class with a static
> counter
> > protected by a TMutex. To prevent collisions of strings originating
> > from different ROOT instances, a TUUID is prepended.
> >
> > (The whole thing could be integrated into TString easily, but I'm not
> > sure, whether it would a problem if TString depended on TMutex.)
> >
> > What do you think?
> >
> > Funnily, the implementation crashes CINT (ROOT 5.26/00b) when running
> as
> > a script, but works well when running compiled. (I haven't tested
> > against the trunk.)
> >
> > Cheers!
> >
> > Thiemo
> >
> > --
> > +-----------------------------------+--------------------------+
> > | Dipl.-Phys. Thiemo Nagel | |
> > | Technische Universitaet Muenchen | Room PH1 3276 |
> > | Physik-Department E18 | |
> > | James-Franck-Strasse | Phone +49 89 289-12379 |
> > | D-85747 Garching | Fax +49 89 289-12570 |
> > +-----------------------------------+--------------------------+
>
>
Received on Wed Apr 14 2010 - 00:05:38 CEST
This archive was generated by hypermail 2.2.0 : Wed Apr 14 2010 - 17:50:01 CEST