--- PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/10/27 10:24:00 1.6 +++ PamCut/Collections/SmartCollection/SmartCollection.cpp 2010/07/08 14:00:33 1.7 @@ -9,14 +9,14 @@ #include "SmartCollection.h" -SmartCollection::~SmartCollection(){ - if (_owns){ - for (unsigned int i = 0; i < _actions.size(); i++) - if (_actions[i] != NULL){ - delete _actions[i]; - _actions[i] = NULL; - } - } +SmartCollection::~SmartCollection() { + if (_owns) { + for (unsigned int i = 0; i < _actions.size(); i++) + if (_actions[i] != NULL) { + delete _actions[i]; + _actions[i] = NULL; + } + } } void SmartCollection::AddAction(CollectionAction *action) { @@ -85,25 +85,29 @@ } unsigned int firstFailed = _cuts.size(); + unsigned int iAction = iBeforeCuts; for (unsigned int iCut = 0; iCut < _cuts.size(); iCut++) { if (_cuts[iCut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { firstFailed = iCut; + // Apply the bad actions at the end of the bunch + if (iAction < _actions.size()) { + unsigned int lastPosition = _actionsPositions[iAction]; + for (; iAction < _actions.size(); iAction++) { + if (_actionsPositions[iAction] > (int) lastPosition) // Don't do actions at the end of successive bunches + break; + _actions[iAction]->OnBad(event, (int) firstFailed); + + } + } break; } - } - - //Do actions - if (_actions.size() > 0) { - unsigned int lastPosition = _cuts.size(); - for (unsigned int i = iBeforeCuts; i < _actions.size(); i++) { - if (_actionsPositions[i] < (int) 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] > (int) lastPosition) // Don't do actions at the end of successive bunches + else if (iAction < _actions.size()) { + // Do the good actions if we are at the end of the bunch + while (_actionsPositions[iAction] == (int) iCut) { + _actions[iAction]->OnGood(event); + iAction++; + if (iAction == _actions.size()) break; - _actions[i]->OnBad(event, (int) firstFailed); } } }