Adding a double array to tobjarr

Hello All,

I have a macro

{
TFile fout(“temp.root”,“CREATE”);

TObjArray *obj_arr_p=new TObjArray(1);

double FAD[100];
for(int i=0; i<100; i++)
FAD[i] = i;

obj_arr_p->Add(FAD);
obj_arr_p->Write(“obj_arr_p”,1);
fout.Close();
}

Which gives error when I add FAD. I am sure this is not right, what is the right way to add ?

Once added I can read the objarr by doing
TFile f1(“temp.root”);
TObjArray *obj_arr = f1.Get(“obj_arr_p”);

how do I read obj FAD from obj_arr ?

Please advice.

[quote=“vaibhavtewari”]Hello All,

I have a macro

{
TFile fout(“temp.root”,“CREATE”);

TObjArray *obj_arr_p=new TObjArray(1);

double FAD[100];
for(int i=0; i<100; i++)
FAD[i] = i;

obj_arr_p->Add(FAD);
obj_arr_p->Write(“obj_arr_p”,1);
fout.Close();
}

Which gives error when I add FAD. I am sure this is not right, what is the right way to add ?

Once added I can read the objarr by doing
TFile f1(“temp.root”);
TObjArray *obj_arr = f1.Get(“obj_arr_p”);

how do I read obj FAD from obj_arr ?

Please advice.[/quote]

Hello.

TObjArray is a special container in ROOT. It contains pointers to TObject, so it’s not for built-in types (like double or something constructed from double - arrays). You can not do it this way. You can either use TTree (have a look at tutorials/user’s guide) or you can wrap array of double into some class inheriting TObject and write/read this object.

Thank You. I used ttree and it worked fine.