> 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 -----Original Message----- From: owner-roottalk@pcroot.cern.ch [mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Tommaso Chiarusi Sent: Tuesday, July 01, 2003 6:23 AM To: Root Newsgroup Subject: [ROOT] TClonesArray of Event objects Hello, I use the Event class (that in $ROOTSYS/test) slightely modified to work with my Track class. The problem I get is when i try to group various Event objects into a TClonesArray . For my purposes, one Event object contains always four tracks. The interesting part of the code (which compiles as a stand-alone executable) is the following: //-------------------------------------- TClonesArray vev("Event",10000); /* IN ORDER TO BETTER UNDERSTAND THE PROBLEM, I FILL A TClonesArray OF Track TOO */ TClonesArray tra("Track",10000); i=0; /* ve[i][j] IS A STL VECTOR CONTAINING THE ID OF THE TRACKS */ for(it=ve.begin(); it!=ve.end();it++){ Event event; /* THE TRACKS I NEED ARE STORED IN FOUR TREES: */ int i0 = ve[i][0], i1 = ve[i][1], i2 = ve[i][2], i3 = ve[i][3]; Branch0->GetEntry(i0); event.AddTrack(*tr0); Branch1->GetEntry(i1); event.AddTrack(*tr1); Branch2->GetEntry(i2); event.AddTrack(*tr2); Branch3->GetEntry(i3); event.AddTrack(*tr3); new(vev[i]) Event(event) ; // FILL THE TClonesArray OF Event new(tra[i]) Track(*tr0) ; // FILL THE TClonesArray OF Track /* NOW A CHECK: I RETRIEVE THE SAME INFO y() DIRECTLY FORM tr0 AND TRACK ttt, WHICH IS RETRIEVED FROM THE Event OBJECT "event"; NOTE: THIS CHECK GIVES POSITIVE RESULTS, I.E. THE PRINTED VALUES OF THE y() ARE THE SAME FOR tr0 AND ttt. */ Event &te = *((Event*)vev.UncheckedAt(i)); Track *ttt = (Track*)te.GetTracks()->UncheckedAt(0); cout<<"ID "<<ve[i][0]<<" tr0 "<<tr0->y()<<" ttt "<<ttt->y()<<endl; i++; } /* NOW, OUT OF THE LOOP I RETRIEVE THE FIRST TRACK INFO ABOUT y() */ Track *ttt = (Track*)tra.UncheckedAt(0); cout<<ttt->y()<<endl; /* ... AND IT WORKS!!!! BUT NOW I TRY TO DO THE SAME WITH THE TClonesArray OF EVENTS... */ for(int j=0; j<i;j++) { Event &te = *((Event*)vev.UncheckedAt(j)); Track *ttt = (Track*)te.GetTracks()->UncheckedAt(0); cout<<ttt->y()<<endl; } /* ... AND I GET SEGMENTATION VIOLATION /* //--------------------------------- 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? RootVesion : 3.03/09 18 September 2002 System : Linux RedHat 7.2 gcc version : 2.96 Thank you very much!!!! Tommaso -- ----------------------- Dr. Tommaso Chiarusi Dipartimento di Fisica Universita' di Bologna INFN. Sez. Bologna Tel +39.051.209.5234 Fax +39.051.209.5269 -----------------------
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:13 MET