--- PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/06/05 13:14:35 1.3 +++ PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/06/16 16:45:00 1.4 @@ -49,50 +49,37 @@ return CUTOK; } - unsigned int bunchEnd = -1; - unsigned int nActions = 0; - unsigned int firstActionOfBunch = -1; - if (_actions.size() > 0) { - // Set the bunch end to the position of the first action - bunchEnd = _actionsPositions[0]; - // Set the position of the first action at the end of the bunch - firstActionOfBunch = 0; - // Set the number of actions at the end of this bunch of cuts - nActions = 1; - while (_actionsPositions[nActions] == bunchEnd) - nActions++; - } - + unsigned int firstFailed = _cuts.size(); for (unsigned int icut = 0; icut < _cuts.size(); icut++) { - if (_cuts[icut]->ApplyCut(event) != CUTOK) { - // Check if there are actions at the end of the current bunch - // (last bunch may have no actions at its end) - if (bunchEnd >= icut) { - for (unsigned int i = 0; i < nActions; i++) { - _actions[firstActionOfBunch + i]->OnBad(event, icut); - } - } - OnBad(event, icut); - return icut; + if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { + firstFailed = icut; + break; } - else if (bunchEnd == icut) { - // We are at the end of the bunch of cuts, so let's execute the actions - for (unsigned int i = 0; i < nActions; i++) { - _actions[firstActionOfBunch + i]->OnGood(event); - } - if (firstActionOfBunch + nActions < _actions.size()) { - // Current bunch is done, but actions are not finished yet. Set up the next bunch. - // Set the end of the new bunch and the number of actions at this end - firstActionOfBunch += nActions; - bunchEnd = _actionsPositions[firstActionOfBunch]; - nActions = 1; - while (_actionsPositions[firstActionOfBunch + nActions] == bunchEnd) - nActions++; + } + + //Do actions + if (_actions.size() > 0) { + unsigned int lastPosition = _cuts.size(); + for (unsigned int i = 0; i < _actions.size(); i++) { + if (_actionsPositions[i] < firstFailed) + _actions[i]->OnGood(event); + else { // A cut has failed + if (lastPosition == _cuts.size()) // Record the position of the end of the bunch + lastPosition = _actionsPositions[i]; + if (_actionsPositions[i] > lastPosition) // Don't do actions at the end of successive bunches + break; + _actions[i]->OnBad(event, firstFailed); } } } - _nGood++; - OnGood(event); - return CUTOK; + if (firstFailed == _cuts.size()) { + _nGood++; + OnGood(event); + return CUTOK; + } + else { + OnBad(event, firstFailed); + return firstFailed; + } }