Hi Doug,
Here is a simple example FindTitle.C
TObject *FindTitle(TDirectory *dir, const char *title)
{
//find an object with title in the current directory on disk
//and import this object in memory
TKey *key;
TIter next(dir->GetListOfKeys());
while ((key = (TKey *) next())) {
if (strcmp(title,key->GetTitle()) == 0) return key->ReadObj();
}
return 0;
}
Example of use:
root > .L FindTitle.C
root > TFile *f = new TFile("myfile.root");
root > FindTitle(f,"some title")->Draw();
Rene Brun
Douglas Roberts wrote:
>
> Hi,
> Does anyone know of a good (and easy) way to find a TTree based on its
> title instead of by its name? Something like FindObject that takes the
> title as an argument.
> The specific application I'm trying to solve is taking h2root-ed hbook
> files that, depending on the job configuration, can assign varying ID
> numbers to ntuples but the titles stay the same. So, the object name
> generated by h2root can vary from job to job.
>
> Any help would be appreciated,
> Doug
>
> Douglas Roberts
> Department of Physics
> University of Maryland
> College Park, MD 20742
> Office: Physics 4308
> Phone: (301)405-6067
> FAX: (301)699-9195
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:33 MET