Hi rooters, I just started using root v3.02 instead of v2.25, and I found that some of my macros no longer work. I traced it down to some mysterious behaviour when writing a TObjArray to a file, using a single key. It turns out that there is a big difference between writing a dynamically allocated array vs. a 'statically allocated' one. I attached two macros to illustrate the problem. First execute write_arr.C to make a file with two arrays, one dynamically allocated, the other one statically. Using read_arr.C to read them back in gives a surprising result: one of the two arrays is empty (the statically aloocated array). Did I do something wrong? Or is there something inconsistent in ROOT or CINT ? Best regards, Marco van Leeuwen. {{ gROOT->Reset(); TFile fout("temp.root","RECREATE"); TObjArray obj_arr(3); TObjArray *obj_arr_p=new TObjArray(3); for (Int_t i=0; i<3;i++) { obj_arr[i]=new TGraph(2); obj_arr_p->Add(new TGraph(2)); } cout << "Dump of obj_arr" << endl; obj_arr.Print(); cout << endl << "Dump of obj_arr_p" << endl; obj_arr_p->Print(); obj_arr.Write("obj_arr",1); obj_arr_p->Write("obj_arr_p",1); fout.Close(); }} {{ gROOT->Reset(); TFile fin("temp.root"); TObjArray *obj_arr_p1=(TObjArray*) fin.Get("obj_arr"); TObjArray *obj_arr_p2=(TObjArray*) fin.Get("obj_arr_p"); cout << "Dump of obj_arr" << endl; obj_arr_p1->Print(); cout << endl << "Dump of obj_arr_p" << endl; obj_arr_p2->Print(); }}
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:09 MET