Hi Ruben,
Create your TList and TIter outside the main loop.
Inside the loop , call
next.Reset(); //this is required in the loop
Rene Brun
On Mon, 22 Apr 2002, Ruben Shahoian wrote:
> Hello,
> we are getting segmentation violation in the following situation:
> we loop over the event object, containing the list, and if certain
> conditions satisfied, we loop over the TList in the event using TIter.
> If TIter happens to work just at the first cycle of the loop, it runs
> without problems. Otherwise using next() ( TIter next(lst) ) causes
> seg.vol. The simple macros below demonstrates this behaviour.
>
> Are there any suggestions?
>
> Best regards,
> Ruben
>
> void testnext(Int_t firstEv=2,Int_t threshold=2)
> {
> int lastEv = 5;
> char strg[10];
> for(int nev = firstEv; nev < lastEv; nev++){
> printf("event %d\n",nev);
> TList *lst = new TList();
> sprintf(strg,"Ev#%d",nev);
> lst->Add(new TNamed(strg,strg));
> if (nev>=threshold ) {
> printf("TList::Print produces: ");
> lst->Print();
> TIter next(lst);
> TNamed* dig;
> printf("Using TIter() produces: ");
> while( (dig=(TNamed*)next()) ) {
> dig->Print();
> }
> }
> delete lst;
> }
> }
>
> *******************************************
> * *
> * W E L C O M E to R O O T *
> * *
> * Version 3.02/07 14 February 2002 *
> * *
> * You are welcome to visit our Web site *
> * http://root.cern.ch *
> * *
> *******************************************
>
> Compiled for linux with thread support.
>
> CINT/ROOT C/C++ Interpreter version 5.15.25, Jan 6 2002
> Type ? for help. Commands must be C++ statements.
> Enclose multiple statements between { }.
> root [0] .x testnext.C(2,2)
> event 2
> TList::Print produces: OBJ: TNamed Ev#2 Ev#2
> Using TIter() produces: OBJ: TNamed Ev#2 Ev#2
> event 3
> TList::Print produces: OBJ: TNamed Ev#3 Ev#3
> Using TIter() produces: OBJ: TNamed Ev#3 Ev#3
> event 4
> TList::Print produces: OBJ: TNamed Ev#4 Ev#4
> Using TIter() produces: OBJ: TNamed Ev#4 Ev#4
>
> root [1] .x testnext.C(1,2)
> event 1
> event 2
> TList::Print produces: OBJ: TNamed Ev#2 Ev#2
> Using TIter() produces:
> *** Break *** segmentation violation
> Root > Function testnext() busy flag cleared
>
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:51 MET