Re: [ROOT] TGraph to file

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri May 24 2002 - 17:43:13 MEST


Hi Dimitris,

Only TH1 and TTree objects are automatically registered to
gDirectory->GetList(). TGraphs are not.

You can register any TObject derived object (eg TGraph) to this list with a
statement like
  gDirectory->Append(mygraph);
where TGraph *mygraph is an already existing TGraph.

You can replace your saveAll function with
   gDirectory->Write();
This statement will write all objects registered in the directory.

To see the list of objects in a directory, do
  dir->ls(), eg gDirectory->ls();

Rene Brun

Dimitris Sideris wrote:
> 
>    Part 1.1       Type: Plain Text (text/plain)
>               Encoding: quoted-printable
Hi,

when I try to save all root objects to a file, any TGraphs I have created do not
appear in the list (see below). I also don't understand how root represents
TGraphs internally, e.g. a histogram has a unique name in a string. This name
appears as the object identifyer when you ls() a file. How would a tgraph
appear?

Dimitris

void SaveAll()
{

// TObject * obj;

// TIter *AllClassesList = new TIter(root.GetListOfClasses());
 CString cstr;

  TList *AllClassesList = gDirectory->GetList();
  
 TObject *obj;
 TH1F *h;

 int k=0;

  printf("listing objects...\n");

 TIter next(AllClassesList);

 int size=AllClassesList->GetSize();
 int i=0;

 while((obj = (TObject*) next())) 
 {
  i++;
//   if (obj->InheritsFrom("TH1") || obj->InheritsFrom("TH2") ||
obj->InheritsFrom("TTree"))
//   {
    printf("Writing %s (%s)...\n",obj->GetName(), obj->GetTitle());
    obj->Write();
//   }


 
 }
 gDirectory->DeleteAll();
//

}



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:53 MET