To Add to Rene's reply you can of course also save this list
object directly without going via a TTree:
TFile f1("test.root", "RECREATE");
list->Write("config", TObject::kSingleKey);
f1.Close();
and read it with:
TFile f2("test.root", "READ");
TList *l = (TList*)f2.Get("config");
l->Print();
Cheers, Fons.
Rene Brun wrote:
>
> Hi Thomas,
>
> Except for a TClonesArray, it does not make sense to use the split mode
> for a TCollection. Replace the line :
>
> t->Branch("TList", "TList", &list, 32000, 9);
> by
> t->Branch("TList", "TList", &list, 32000, 0);
>
> Rene Brun
>
> Thomas Bretz wrote:
> >
> > Hello rooters,
> >
> > I want to order some objects in a list, like:
> > TList *list = new TList;
> > TEllipse *ell = new TEllipse;
> > TLine *lin = new TLine;
> > list->Add(ell);
> > list->Add(lin);
> >
> > Now I want to write this list of objects to a root file, like:
> > TFile f1("test.root", "RECREATE");
> > TTree *t = new TTree("List", "My List");
> > t->Branch("TList", "TList", &list, 32000, 9);
> > t->Fill();
> > f1.Write();
> > f1.Close();
> >
> > And read the list again, like:
> > TFile f2("test.root", "READ");
> > t = (TTree*)f2.Get("List");
> > t->GetBranch("TList")->SetAddress(&list);
> > t->GetEntry(0);
> > list->Print();
> >
> > But this fails (as I understand, because of ClassDef(TSeqCollection,
> > 0)). Is there a way to write such a list and get it back as one entry?
> >
> > The idea is to have a list which stores several objects describing a
> > program setup (like the gui elements above, which are describing a
> > graphical setup). I want to be able to store and read this setup with a
> > single expression.
> >
> > Thanks alot,
> > Thomas.
--
Org: CERN, European Laboratory for Particle Physics.
Mail: 1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch Phone: +41 22 7679248
WWW: http://root.cern.ch/~rdm/ Fax: +41 22 7679480
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:08 MET