Hi Sean, Objects like TPolyLine3D can be stored in TClonesArray, but you do not take any advantage of TClonesArray for classes like TPolyLine3D allocating dynamically 99.9% of their body. But it should work. You can forget the warning message generated when building the dictionary. When reading you have an error because you forget to call t2->GetEntry(0) to read your first event. I assume that in read you want to do something like: void read() { TClonesArray *clones = 0; TFile *infile = new TFile("event.root","READ"); TTree *t2 = (TTree*)infile->Get("T"); t2->SetBranchAddress("test",&clones); int nevent = T->GetEntries(); T->Print(); for (int i=0;i<nevent;i++) { t2->GetEntry(i); TPolyLine3D *line = (TPolyLine3D*)clones->At(1); line->GetN(); printf("number of points = %d\n",line->GetN()); } } Rene Brun Sean Liddick wrote: > > I am relatively new to root and am trying to create a simple example for > the use of TClonesArray. What I am trying to do is create a TClonesArray > of TPolyline3D objects and store this array into a branch of a tree. I > then want to read in the root file that is created and access the different > TPolyLine3D objects. > > The macros that are run to create and then read a root file follow: > > void write() > { > TFile *hfile = new TFile("event.root","RECREATE","benchmark"); > TTree *tree = new TTree("T","Tree example"); > TClonesArray *a = new TClonesArray("TPolyLine3D"); > TClonesArray &aa = *a; > > tree->Branch("test",&a,32000,0); > > Double_t x[5] = {0.2,0.7,0.7,0.1,1}; > Double_t y[5] = {0.2,0.7,0.7,0.1,1}; > Double_t z[5] = {0.2,0.7,0.7,0.1,1}; > > for(int i=0; i<10;i++){ > new(aa[i]) TPolyLine3D(5,x,y,z); > } > > TPolyLine3D *line = (TPolyLine3D*)a->At(5); > cout << line->GetN() << endl; > > tree->Fill(); > tree->Print(); > hfile->Write(); > hfile->Close(); > } > > void read() > { > TClonesArray *clones = new TClonesArray("TPolyLine3D",10); > TFile *infile = new TFile("event.root","READ"); > TTree *t2 = (TTree*)infile->Get("T"); > TBranch *branch = t2->GetBranch("test"); > branch->SetAddress(&clones); > > int nevent = T->GetEntries(); > T->Print(); > TPolyLine3D *line = (TPolyLine3D*)clones->At(1); > line->GetN(); > printf("number of points = %d\n",line->GetN()); > } > > After executing the write macro in ROOT 3.10/01 I get the following > output. > > >root [1] write() > >5 > >Error in <TStreamerInfo::Build>: TPolyLine3D, discarding: Float_t* fP, > illegal [3*fN] Array of 3-D >>coordinates (x,y,z) > > > >****************************************************************************** > >*Tree :T : Tree example > * > >*Entries : 1 : Total = 13663 bytes File Size = > 0 * > >* : : Tree compression factor = 1.00 > * > >****************************************************************************** > >*Br 0 :test : > * > >*Entries : 1 : Total Size= 13411 bytes One basket in memory > * > >*Baskets : 0 : Basket Size= 64000 bytes Compression= 1.00 > * > >*............................................................................* > > When I run write() a second time, the "error in <TStreamerInfo::Build> > ..." disappears and I do not understand why. > > Secondly when I run the read script the output produced is: > > >root [3] read() > >****************************************************************************** > >*Tree :T : Tree example > * > >*Entries : 1 : Total = 13710 bytes File Size = > 4044 * > >* : : Tree compression factor = 1.00 > * > >****************************************************************************** > >*Br 0 :test : > * > >*Entries : 1 : Total Size= 13411 bytes One basket in memory > * > >*Baskets : 0 : Basket Size= 64000 bytes Compression= 1.00 > * > >*............................................................................* > >Error: illegal pointer to class object line 0x0 116 FILE:root.C LINE:40 > >*** Interpreter error recovered *** > > What am I doing wrong in the read macro that prevents me from accessing > the TPolyLine objects? > Thanks for the help. > > Sean Liddick > National Superconducting Cyclotron Laboratory > Michigan State University > East Lansing, Mi 48824 > Email : liddick@nscl.msu.edu
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:05 MET