Hi Ben, It is not obvious to follow your explanations without looking at a concrete piece of code ::) I have the feeling that you do not fill the TClonesArray correctly. You must call the constructor of the class in the TClonesArray (as shown in $ROOTSYS/test/Event.cxx). Could you send the shortest possible file reproducing the problem? Rene brun Ben Kilminster wrote: > > I am trying to figure out how to fill a Tree in one object with a > TClonesArray from another object. > My code is crashing when I try to do the copying. > > In my main class, I define a tree with a branch, with a TClonesArray of > objects in it: > > class MainSim > { > TTree* SimTree; > TClonesArray* CloneXftpixel; > xft2Lpixel* xftpixelB; > ... > } > > MainSim::MainSim() > { > CloneXftpixel = new TClonesArray("xft2Lpixel"); > SimTree = new TTree("T","SimTree"); > SimTree->Branch("xft2Lpixel",&CloneXftpixel,32000,2); > ... > } > > I then fill the TClonesArray in another class, like : > > class FinderChip > { TClonesArray* CloneXftpixel; > xft2Lpixel* xft2pixelF; > int iPixel; > ... > } > > FinderChip::FillBlock() > { > iPixel++; > xft2pixelF = new ((*CloneXftpixel)[iPixel]) xft2Lpixel; > xft2pixelF->Chip = this->COT_chip; > ... > } > > Now, I want to fill the SimTree with the array of xft2Lpixels from the > FinderChip object. > But I have many FinderChip objects, with any number of xft2pixelF > objects, so I have to gather them by checking the iPixel counter for > each FinderChip : > > MainSim::FillTree() > { > CloneXftpixel->Clear() > > for(int nbrd=0; nbrd<8; nbrd++) { > for (int nchp=0;nchp<8;nchp++) { > int nPix = > XFTSystem->finderCrate[crate]->FinderBoard2_4Elements[nbrd]- > >finderChipElements[nchp]->iPixel; > if (nPix > 0) > CloneXftpixel = > (TClonesArray*)XFTSystem->finderCrate[crate]- > >FinderBoard2_4Elements[nbrd]->finderChipElements[nchp]->CloneXftpixel- > >Clone(); > } > } > > SimTree->Fill() > > This compiles and runs, but crashes filling the CloneXftpixel in the > FillTree() method. > > Instead of the if (nPix>0), I also tried to do this with a loop as in > the At() statement : > for (int i=0; i < nPix; nPix++) { > xftpixelB = > (xft2Lpixel*)XFTSystem->finderCrate[crate]- > >FinderBoard2_4Elements[nbrd]->finderChipElements[nchp]->CloneXftpixel- > >At(i); > } > > but this crashed in the same place. > > What is the correct way to do this ? > > Cheers, > Ben
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET