--- PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/05/27 13:30:09 1.1 +++ PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/06/16 16:45:00 1.4 @@ -11,6 +11,7 @@ void SmartCollection::AddAction(CollectionAction& action) { _actions.push_back(&action); + _actionsPositions.push_back(GetSize() - 1); } CollectionAction *SmartCollection::GetAction(unsigned int iAction) { @@ -22,34 +23,63 @@ return _actions[iAction]; } -void SmartCollection::Setup(PamLevel2 *events){ +void SmartCollection::Setup(PamLevel2 *events) { PamCutCollection::Setup(events); - for (unsigned int i = 0; i < GetSize(); i++){ + for (unsigned int i = 0; i < _actions.size(); i++) { _actions[i]->Setup(events); } } -void SmartCollection::Finalize(){ +void SmartCollection::Finalize() { PamCutCollection::Finalize(); - for (unsigned int i = 0; i < GetSize(); i++){ + for (unsigned int i = 0; i < _actions.size(); i++) { _actions[i]->Finalize(); } } -void SmartCollection::OnGood(PamLevel2 *event){ - PamCutCollection::OnGood(event); +int SmartCollection::ApplyCut(PamLevel2 *event) { - for (unsigned int i = 0; i < GetSize(); 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 firstFailed = _cuts.size(); + for (unsigned int icut = 0; icut < _cuts.size(); icut++) { + if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { + firstFailed = icut; + break; + } + } - for (unsigned int i = 0; i < GetSize(); i++){ - _actions[i]->OnBad(event, selectionResult); + //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); + } + } + } + + if (firstFailed == _cuts.size()) { + _nGood++; + OnGood(event); + return CUTOK; + } + else { + OnBad(event, firstFailed); + return firstFailed; } }