Hi all,
I have a TFolder structure in memory that I’d like to save to a file while translating the folder hierarchy into a TDirectory heirarchy. I feel that my users are more used to accessing histograms in the TDirectory structure.
Is there a preexisting feature that does the translation? I looked but did not find one and so I wrote this little bit of
void trans(TFolder* f, TDirectory* bd){
// translate the folder heirarchy hanging off f
// into a directory heirarcy inside the directory pointed to by bd
// if bd is null, translate into the current directory (gDirectory)
// also append any objects held by the folders (e.g. histograms)
// to the new directory structure
if(!bd) bd=gDirectory;
// make a directory for this folder
TDirectory* dir = bd->mkdir(f->GetName());
dir->cd();
// look for subfolders of this one
TCollection* col = f->GetListOfFolders();
TIter it(col->MakeIterator());
TObject* obj;
while ( obj=it() ){
if(obj->InheritsFrom("TFolder")){
TFolder* fol = (TFolder*) obj;
// I'm recursive!
trans(fol);
dir->cd();
}
else{
dir->Append(obj);
}
}
}
This appears to do what I want. Could it be added as a static method in either TFolder or TDirectory? By the way, the TFolder::GetListOfFolders() call is very poorly named since it returns a list of objects only some of which are folders. This really calls for a comment in the html documentation.[/code]
Regards,
mike kordosky