GSI Forum
GSI Helmholtzzentrum für Schwerionenforschung

Home » PANDA » PandaRoot » Bugs, Fixes, Releases » [WARN] Removing candidates while looping over TCandList
[WARN] Removing candidates while looping over TCandList [message #14252] Fri, 30 November 2012 11:31
Klaus Götzen is currently offline  Klaus Götzen
Messages: 293
Registered: June 2006
Location: GSI
first-grade participant
From: *gsi.de
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

[Updated on: Fri, 19 April 2013 12:36] by Moderator

Report message to a moderator

 
Read Message
Previous Topic: Problem with PndKinVtxFitter and Ks decays
Next Topic: [FIXED] error after svn update
Goto Forum:
  


Current Time: Mon Nov 11 13:40:59 CET 2024

Total time taken to generate the page: 0.00987 seconds