Hi Mike,
I have some difficulties understanding why you need this kind of logic.
Anyhow, it is your business ::)
You can simplify the logic to be like:
void CalAnal::WriteObjects(TDirectory* dir)
{
TDirectory* save_dir = gDirectory;
if(dir==0) return;
dir->cd();
ObjVecIter it = fHolder.begin();
while(it != fHolder.end()){
TObject* obj = *it;
if( obj->IsA() == TDirectory::Class()) {
TDirectory* adir = (TDirectory*)obj;
dir->Append(adir);
adir->Write();
save_dir->cd();
adir->cd(0);
} else {
obj->Write();
}
it++;
}
save_dir->cd();
}
Rene Brun
Mike Kordosky wrote:
>
> Hi,
>
> Could someone tell me how to do the following, or if it is possible:
>
> Create a TDirectory to hold some objects.
> Place objects in the directory.
> At a later time, supply a file and save the directory in the file.
> Preserve ownership of the directory in the object that created it.
> The file is not known at the time of directory creation.
>
> Here is my code snippet, but it doesn't work:
>
> void CalAnal::WriteObjects(TDirectory* dir)
> {
> TDirectory* save_dir = gDirectory;
> if(dir==0) return;
> dir->cd();
> ObjVecIter it = fHolder.begin();
> while(it != fHolder.end()){
> TObject* obj = *it;
> TClass* cl = obj->Class();
> TString name(cl->GetName());
> Bool_t ok = kTRUE;
> if( (name==(TString("TDirectory")) ) )
> {
> TDirectory* adir = dynamic_cast<TDirectory*>(obj);
> if(adir!=0){
> dir->Append(adir);
> adir->Write();
> save_dir->cd();
> adir->cd(0);
> }
> else {ok = kFALSE;}
> }
> else {
> obj->Write();
> }
> it++;
> }
> save_dir->cd();
> }
>
> How I do this?
>
> mike
>
> --
> Graduate Research Assistant // High Energy Physics Lab
> kordosky@hep.utexas.edu // University of Texas at Austin
> kordosky@fnal.gov //
> ph: (512) 471-8426 (RLM Lab, Office)
> (512) 475-8673 (ENS Lab)
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:03 MET