RE: [ROOT] TClonesArray of Event objects

From: Philippe Canal (pcanal@fnal.gov)
Date: Wed Jul 02 2003 - 17:37:38 MEST


Hi,

The problems is:

   if (!fgTracks) fgTracks = new TClonesArray("Track", 1000);
   fTracks = fgTracks;
   ...
   Track *t = (Track*)event.GetTracks()->UncheckedAt(nt);
   AddTrack(*t);

which I am not sure what it actually does BUT it is very unlikely to be doing what you expect it to do.  Since the fgTrack is global, this is essentially doing:

   Track *t = fgTracks->UncheckedAt(nt);
   Track *newt = new ((*fgTrack)[fNtrack++]) Track(*t);

which is likely to be deleting/overwriting the existing track.  In your current code there is onely ONE list of track at a time.

Cheers,
Philippe.
   


-----Original Message-----
From: Tommaso Chiarusi [mailto:Tommaso.Chiarusi@bo.infn.it]
Sent: Wednesday, July 02, 2003 5:05 AM
To: Philippe Canal
Cc: Root Newsgroup
Subject: RE: [ROOT] TClonesArray of Event objects


On Tue, 1 Jul 2003, Philippe Canal wrote:

> > I think that the problem resides in the destruction of the Event objects
> > at the end of the loop. But I don't know why,  since when I fill the
> > TClonesArray of Event objects, it should copy the objects..., shouldn't
> > it?
> 
> yes except that in $ROOTSYS/test/Event.h the copy constructor has not been
> implemented and the default one (provided by the compiler) is wrong due to
> the usage of pointers.  Worse the design of that class assume (but do not
> enforce) that it is basically a singleton.
> So unless you change those quirks, you will have some trouble keeping
> several 'Event' around.
> 
> Cheers,
> Philippe
> 

Hi,
I indeed  provided a Copy constructor for the Event class: 

//---------

Event::Event(const Event& event)
{
   // Create  an Event object by copying the tracks from a second event.
   // When the constructor is invoked for the first time, the class static
   // variable fgTracks is 0 and the TClonesArray fgTracks is created.
   //	


   if (!fgTracks) fgTracks = new TClonesArray("Track", 1000);
   fTracks = fgTracks;
   fNtrack = 0;
   fH      = 0;
   Int_t i0,i1;
   for (i0 = 0; i0 < 4; i0++) {
	  for (i1 = 0; i1 < 4; i1++) {
	     fMatrix[i0][i1] = 0.0;
	  }
   }
   for (i0 = 0; i0 <10; i0++) fMeasures[i0] = 0;
   fClosestDistance = 0;
   fEventName = 0;
   fWebHistogram.SetAction(this);


  int ntra = event.GetNtrack();
  for(int nt = 0;nt<ntra;nt++)
    {
	Track *t = (Track*)event.GetTracks()->UncheckedAt(nt);
	AddTrack(*t);
    }


}

//---------
But the result (segmentation violation) remains the same....
I also tried to use an STL vector instead of the TClonesArray but the 
segmentation keeps on....

Any idea?
Thank you very much,
Tommaso



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET