--- PamCut/Collections/SmartBlindCollection/SmartBlindCollection.cpp 2009/06/05 13:14:34 1.2 +++ PamCut/Collections/SmartBlindCollection/SmartBlindCollection.cpp 2010/07/08 14:00:30 1.5 @@ -12,62 +12,62 @@ int SmartBlindCollection::ApplyCut(PamLevel2 *event) { _nEv++; + + // Execute the actions placed before the cuts + unsigned int iBeforeCuts = 0; + //cout << GetName() << endl; + if (_actions.size() > 0) { + while (_actionsPositions[iBeforeCuts] == -1) { + _actions[iBeforeCuts]->OnGood(event); + iBeforeCuts++; + if (iBeforeCuts == _actions.size()) + break; + } + } + + // Apply the cuts if (_cuts.size() == 0) { _nGood++; OnGood(event); 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++; - } - - int firstFailed = CUTOK; - for (unsigned int icut = 0; icut < _cuts.size(); icut++) { - if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == CUTOK) { - firstFailed = icut; + 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; } - if (bunchEnd == icut) { - if (firstFailed == CUTOK) { - for (unsigned int i = 0; i < nActions; i++) { - _actions[firstActionOfBunch + i]->OnGood(event); + + if (iAction < _actions.size()) { + if (firstFailed == _cuts.size()) { // No cut has failed yet + while (_actionsPositions[iAction] == (int) iCut) { + _actions[iAction]->OnGood(event); + iAction++; + if (iAction == _actions.size()) + break; } } else { - for (unsigned int i = 0; i < nActions; i++) { - _actions[firstActionOfBunch + i]->OnBad(event, icut); + while (_actionsPositions[iAction] == (int) iCut) { + _actions[iAction]->OnBad(event, (int) firstFailed); + iAction++; + if (iAction == _actions.size()) + break; } } - 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++; - } } } - if (firstFailed == CUTOK) { + if (firstFailed == _cuts.size()) { _nGood++; OnGood(event); + return CUTOK; } else { OnBad(event, firstFailed); + return firstFailed; } - return firstFailed; }