--- PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/05/29 10:10:31 1.2 +++ PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/06/05 13:14:35 1.3 @@ -11,6 +11,7 @@ void SmartCollection::AddAction(CollectionAction& action) { _actions.push_back(&action); + _actionsPositions.push_back(GetSize() - 1); } CollectionAction *SmartCollection::GetAction(unsigned int iAction) { @@ -38,18 +39,60 @@ } } -void SmartCollection::OnGood(PamLevel2 *event) { - PamCutCollection::OnGood(event); +int SmartCollection::ApplyCut(PamLevel2 *event) { - for (unsigned int i = 0; i < _actions.size(); i++) { - _actions[i]->OnGood(event); + _nEv++; + // Apply the cuts + if (_cuts.size() == 0) { + _nGood++; + OnGood(event); + return CUTOK; } -} -void SmartCollection::OnBad(PamLevel2 *event, int selectionResult) { - PamCutCollection::OnBad(event, selectionResult); + 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++; + } - for (unsigned int i = 0; i < _actions.size(); i++) { - _actions[i]->OnBad(event, selectionResult); + 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; + } + 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++; + } + } } + + _nGood++; + OnGood(event); + return CUTOK; }