GSI Forum - RDF feed
type: channel
description: GSI Helmholtzzentrum für Schwerionenforschung
items: [WARN] Removing candidates while looping over TCandList

[WARN] Removing candidates while looping over TCandList
type: item
description: Hi, I just wanted to point you to a (possible) problem when looping over TCandList and removing candidates of this list within the loop. It seems at some places in macro/run/..., a routine similar to the following one is used: int n_removed=0, i=0; for (l=0; l<list.GetLength(); ++l) { i = l-n_removed; if( ... Some criterion ...) { list.Remove( list[i] ); n_removed++; } } This actually does not work properly, since it doesn't take into account, that the quantity 'list.GetLength()' is changed by the removal process. It can be fixed by replacing for (l=0; l<list.GetLength(); ++l) by int nl = list.GetLength(); for (l=0; l<nl; ++l) At least for me, this worked correctly afterwards. The safest thing of course is to do something like TCandList newlist; for (l=0; l<list.GetLength(); ++l) { if( ... the OPPOSITE criterion ...) ) newlist.Put( list[i] ); } list=newlist; In case you used the first kind of construction in one of your analysis studies, you should check your results. Best regards, Klaus
creator: Klaus Götzen
date: 2012-11-30T10:31:04-00:00