--- PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/06/17 13:02:39 1.5 +++ PamCut/Collections/SmartCollection/SmartCollection.cpp 2009/10/27 10:24:00 1.6 @@ -9,8 +9,18 @@ #include "SmartCollection.h" -void SmartCollection::AddAction(CollectionAction& action) { - _actions.push_back(&action); +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) { + _actions.push_back(action); _actionsPositions.push_back(GetSize() - 1); } @@ -26,7 +36,7 @@ CollectionAction *SmartCollection::GetAction(const char *actionName) { if (_actions.size() == 0) return NULL; - for (unsigned int i = 0; i < _actions.size(); i++){ + for (unsigned int i = 0; i < _actions.size(); i++) { if (strcmp(_actions[i]->GetName(), actionName) == 0) return _actions[i]; } @@ -36,6 +46,7 @@ void SmartCollection::Setup(PamLevel2 *events) { PamCutCollection::Setup(events); + //cout << GetName() << endl; for (unsigned int i = 0; i < _actions.size(); i++) { _actions[i]->Setup(events); @@ -53,6 +64,19 @@ int SmartCollection::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++; @@ -61,9 +85,9 @@ } 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; + for (unsigned int iCut = 0; iCut < _cuts.size(); iCut++) { + if (_cuts[iCut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { + firstFailed = iCut; break; } } @@ -71,15 +95,15 @@ //Do actions if (_actions.size() > 0) { unsigned int lastPosition = _cuts.size(); - for (unsigned int i = 0; i < _actions.size(); i++) { - if (_actionsPositions[i] < firstFailed) + 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] > lastPosition) // Don't do actions at the end of successive bunches + if (_actionsPositions[i] > (int) lastPosition) // Don't do actions at the end of successive bunches break; - _actions[i]->OnBad(event, firstFailed); + _actions[i]->OnBad(event, (int) firstFailed); } } }