[ROOT] TDirectory question

From: Mike Kordosky (kordosky@mail.hep.utexas.edu)
Date: Tue Oct 16 2001 - 20:47:06 MEST


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