RE: writing pointers to pointers to a file

From: Fine, Valeri <fine_at_bnl.gov>
Date: Tue, 12 Feb 2008 12:37:37 -0500


>
> Dear rooters,
>
> would it be possible to write pointers to pointers into a file?
The
> problem arises from the need to write an instance of a class which
> contains pointers to pointers data members into a file. In particular,
> the pointers to pointers are TH1F**, and the error message reads:
>
> Program received signal SIGSEGV, Segmentation fault.
> [Switching to Thread -1433986848 (LWP 24923)]
> 0x048e1245 in vtable for TAxis ()
> from /home/zampolli/SOFT/ROOT/root/lib/libHist.so
>
> This, as I said, trying to write an instance of the class. Moreover,
> trying to write directly on a file a pointer to pointer - such as
with:
>
> TH1F **hSPD = new TH1F*[2];
> char name[100];
> for (Int_t i=0;i<2;i++){
> sprintf(name,"hist_%i",i);
> hSPD[i]=new TH1F(name,name,10*(i+1),10*i,10*(i+1));
> }
>
> hSPD->Write();
>
> does not work either...

I believe there the straight forward ROOT ( and OO) solution for that. You should create the ROOT container (for example TObjArray). Add all your obiect pointers there and write the container out.

What about:

     TObjArray *h_array = new TObjArray;

     for (Int_t i=0;i<2;i++){
         sprintf(name,"hist_%i",i);
         h_array->Add(new TH1F(name,name,10*(i+1),10*i,10*(i+1)));
     }
 
     h_array->Write();

Of course, you can create the nested container also, if you need.

Hope this helps,

                              Valeri


> So, I'm wondering whether writing pointers to pointers to a file is
not
> possible at all...
> Thanks for your help.
> Cheers,
> chiara
Received on Tue Feb 12 2008 - 18:38:13 CET

This archive was generated by hypermail 2.2.0 : Tue Feb 12 2008 - 23:50:01 CET