Writing a TList into a ROOT file

From: ROHLFS Reiner (Reiner.Rohlfs@obs.unige.ch)
Date: Wed Mar 08 2000 - 12:03:47 MET


Hi Root - Team,

Is it possible to write a TList into a ROOT file? I do not understand the
behavior of the macro below.  
It seams to me that the TList is not written to the ROOT file but all its
objects by themselves. And I cannot read all objects back into a TList?

{
   gROOT->Reset();
   TFile * file = new TFile("list.root", "recreate");

   TList * list = new TList;
   TNamed * n1, * n2;

   n1 = new TNamed("name1", "title1");
   n2 = new TNamed("name2", "title2");

   list->Add(n1);
   list->Add(n2);

   list->Write("list");
   file->Write();

   file->ls();

   printf("number of names in list: %d\n", list->GetSize());

   list->Delete();
   delete list;

   list = (TList*)file->Get("list");
   printf("number of names in list: %d\n", list->GetSize());

   n1 = (TNamed*)file->Get("list");
   printf("name: %s   title: %s\n", n1->GetName(), n1->GetTitle());

   delete file;
}

The output of this macro is 

TFile**    list.root
 TFile*    list.root
  KEY: TNamed   list;2  title2
  KEY: TNamed   list;1  title1
number of names in list: 2
number of names in list: 13
name: name2   title: title2


I use ROOT  Version   2.23/12  21 February 2000  

Thanks Reiner.



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:21 MET