Hi Tommaso, Instead of: new(&vUp[nozone][contau[nozone]]) Track(trUp->x(),trUp->y(),trUp->a(),trUp->b(),trUp->pol()); do TClonesArray &vupzone = *(vUp[nozone]); int count = contau[nozone]; new(vupzone[count]) Track(trUp->x(),trUp->y(),trUp->a(),trUp->b(),trUp->pol()); Your code will be more readable and less error prone. Rene Brun On Wed, 21 May 2003, Tommaso Chiarusi wrote: > Hello. > I have a script which works under cint. > I need to convert it into a compiled executable. > I become aware that cint automatically cures all the C++ venial sins in > the code... > Unfortunately, my g++ compilator feels such sins become as unforgiven. > > I try to cure my mistakens, so I managed to compile, > But I get Segmentation fault. > > I am quite sure that my problem IS NOT on some include files or > libraries which may lack. > It is a problem of segmentation, so it should concern the usage of > pointers. > > The problem is when I try to fill and then read an > "array of TClonesArray" > > > Conceptual sketch: > Imagine a detector subdivided into several zones. > The number of interesting zone is variable, say "ntotal_zone" > > For each zone I have several tracks. > So I need to make "ntotal_zone" collection of tracks. > I decided to collect the tracks of each zone by means of a TClonesArray. > So, I find myself with an array of TClonesArray. > > In the cint-script I use the following (!uncorrect! but working syntax) > > TClonesArray *vUp = new TClonesArray[ntotal_zone]; > TClonesArray *vDown = new TClonesArray[ntotal_zone]; > > int *contau = new int[ntotal_zone];// vectors which counts the > number of tracks for each zone > int *contad = new int[ntotal_zone]; > > TMatrix *notru = new TMatrix(ntotal_zone,neventUp); > TMatrix *notrd = new TMatrix(ntotal_zone,neventDown); > > > for(int in =0;in<ntotal_zone;in++) // initialization of all the > TClonesArrays > { > vUp[in]= new TClonesArray("Track",neventUp); > vDown[in]= new TClonesArray("Track",neventDown); > contau[in]=0; > contad[in]=0; > } > > Then when I fill I use the following (whithin a loop on the total > number of the zones - > nozone is the number of the currently analysed zone, let's call this > procedure as (p.1) ): > > > new(vUp[nozone][contau[nozone]]) > Track(trUp->x(),trUp->y(),trUp->a(),trUp->b(),trUp->pol()); > > > Note the array-form of the TClonesArray: > vUp[nozone] ....... should give the pointer to a TClonesArray > vUp[nozone][contau[nozone]] ....... should give the component of such > pointer > > > > > When trying to convert everithing into a g++ stand-alone executables, I > noticed that I was using a unforgiven syntax and I changed it by > using the following: > > TClonesArray* *vUp = new TClonesArray*[ntotal_zone]; > TClonesArray* *vDown = new TClonesArray*[ntotal_zone]; > > ... i.e. as a list of pointers to TClonesArray, which are initialized as > the same as in the cint-script. > > > The filling procedure should remain the same as (p.1). If I do this the > compiler prompt out the following errors > > Analisi_match3.C:321: no matching function for call to `Track::operator > new (unsigned int, TClonesArray &)' > /home/applicazioni/root/include/TObject.h:153: candidates are: static > void *TObject::operator new > (unsigned int) > /home/applicazioni/root/include/TObject.h:154: static > void *TObject::operator new > (unsigned int, void *) > > Instead, if I write (note the "&" in the argument of "new()" ) > > new(&vUp[nozone][contau[nozone]]) > Track(trUp->x(),trUp->y(),trUp->a(),trUp->b(),trUp->pol()); > > I get the program to compile, but when I start to iterate through the > TClonesArray, the program crashes dumping a sementation fault. > > What's wrong? > > My system is > > Toshiba Satellite 1800 LapTop, > Linux Mandrake 8.1 > Root Version 3.03/09 18 September 2002 > gcc version 2.96 20000731 (Mandrake Linux 8.1 2.96-0.62mdk) > > Thank you very much > > Tommaso >
This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:11 MET