Masahiro Sugaya--------------------------- Address: 1-1 Oho, Tsukuba, Ibaraki 305-0801 Japan Office: 0298-79-6123 Mail: sugayam@post.kek.jp From: Rene Brun <Rene.Brun@cern.ch> Subject: Re: [ROOT] reading / writing object to disk Date: Sun, 25 Nov 2001 19:35:32 +0100 (MET) Message-ID: <Pine.LNX.4.04.10111251933260.25631-100000@pcbrun.cern.ch> Hi rooters !! I have a question. When we write a program compiling with the root library and persist the TObject with TFile::Write method, I don't know who has the remote ownership and duty to delete of the TObject. I mean I wonder if it is necessary to delete the TObject in the next code. #include <TFile.h> #include <Myclass.h> #include <TROOT.h> TROOT root("myapp","myapp"); int main(){ TFile f("joe.root","recreate"); Myclass *obj = new Myclass; obj->Write("aname"); f.Write(); f.Close(); delete obj; <- Is this line needed ? return 0; ^^^^^^^^^^^^^^^^^^^^^ } > Hi Joe, > > To write an object of class Myclass to a file, do: > TFile f("joe.root","recreate"); > Myclass *obj = new Myclass; > obj->Write("aname"); > f.Close(); > > To read an object from a file: > TFile f("joe.root"); > Myclass *obj = (Myclass*)f.Get("aname"); > > Rene Brun > > > On Sun, 25 Nov 2001, joe robe wrote: > > > Hi rooters, > > > > just try to understand TFILE. > > > > I created a small testclass (with ClassImp etc macros > > and creating dict. file and are able to write this to > > disk. > > > > All I see is the only data member the class has. > > > > I just dont understand yet how to save and retrieve my > > WHOLE class to/from disk. Is that not possible ?? I > > have classes with huge data arrays which are filled > > after doing some calculations. I just want to save and > > later retrieve this COMPLETE state of the object with > > all its datamebers, objects etc. > > > > Is there a simple way to do that ?? > > > > Thanks > > > > Joe > > > > > > > > > > __________________________________________________ > > Do You Yahoo!? > > Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month. > > http://geocities.yahoo.com/ps/info1 > >
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:09 MET