| 11 |
|
|
| 12 |
void SmartCollection::AddAction(CollectionAction& action) { |
void SmartCollection::AddAction(CollectionAction& action) { |
| 13 |
_actions.push_back(&action); |
_actions.push_back(&action); |
| 14 |
|
_actionsPositions.push_back(GetSize() - 1); |
| 15 |
} |
} |
| 16 |
|
|
| 17 |
CollectionAction *SmartCollection::GetAction(unsigned int iAction) { |
CollectionAction *SmartCollection::GetAction(unsigned int iAction) { |
| 39 |
} |
} |
| 40 |
} |
} |
| 41 |
|
|
| 42 |
void SmartCollection::OnGood(PamLevel2 *event) { |
int SmartCollection::ApplyCut(PamLevel2 *event) { |
|
PamCutCollection::OnGood(event); |
|
| 43 |
|
|
| 44 |
for (unsigned int i = 0; i < _actions.size(); i++) { |
_nEv++; |
| 45 |
_actions[i]->OnGood(event); |
// Apply the cuts |
| 46 |
|
if (_cuts.size() == 0) { |
| 47 |
|
_nGood++; |
| 48 |
|
OnGood(event); |
| 49 |
|
return CUTOK; |
| 50 |
} |
} |
|
} |
|
| 51 |
|
|
| 52 |
void SmartCollection::OnBad(PamLevel2 *event, int selectionResult) { |
unsigned int bunchEnd = -1; |
| 53 |
PamCutCollection::OnBad(event, selectionResult); |
unsigned int nActions = 0; |
| 54 |
|
unsigned int firstActionOfBunch = -1; |
| 55 |
|
if (_actions.size() > 0) { |
| 56 |
|
// Set the bunch end to the position of the first action |
| 57 |
|
bunchEnd = _actionsPositions[0]; |
| 58 |
|
// Set the position of the first action at the end of the bunch |
| 59 |
|
firstActionOfBunch = 0; |
| 60 |
|
// Set the number of actions at the end of this bunch of cuts |
| 61 |
|
nActions = 1; |
| 62 |
|
while (_actionsPositions[nActions] == bunchEnd) |
| 63 |
|
nActions++; |
| 64 |
|
} |
| 65 |
|
|
| 66 |
for (unsigned int i = 0; i < _actions.size(); i++) { |
for (unsigned int icut = 0; icut < _cuts.size(); icut++) { |
| 67 |
_actions[i]->OnBad(event, selectionResult); |
if (_cuts[icut]->ApplyCut(event) != CUTOK) { |
| 68 |
|
// Check if there are actions at the end of the current bunch |
| 69 |
|
// (last bunch may have no actions at its end) |
| 70 |
|
if (bunchEnd >= icut) { |
| 71 |
|
for (unsigned int i = 0; i < nActions; i++) { |
| 72 |
|
_actions[firstActionOfBunch + i]->OnBad(event, icut); |
| 73 |
|
} |
| 74 |
|
} |
| 75 |
|
OnBad(event, icut); |
| 76 |
|
return icut; |
| 77 |
|
} |
| 78 |
|
else if (bunchEnd == icut) { |
| 79 |
|
// We are at the end of the bunch of cuts, so let's execute the actions |
| 80 |
|
for (unsigned int i = 0; i < nActions; i++) { |
| 81 |
|
_actions[firstActionOfBunch + i]->OnGood(event); |
| 82 |
|
} |
| 83 |
|
if (firstActionOfBunch + nActions < _actions.size()) { |
| 84 |
|
// Current bunch is done, but actions are not finished yet. Set up the next bunch. |
| 85 |
|
// Set the end of the new bunch and the number of actions at this end |
| 86 |
|
firstActionOfBunch += nActions; |
| 87 |
|
bunchEnd = _actionsPositions[firstActionOfBunch]; |
| 88 |
|
nActions = 1; |
| 89 |
|
while (_actionsPositions[firstActionOfBunch + nActions] == bunchEnd) |
| 90 |
|
nActions++; |
| 91 |
|
} |
| 92 |
|
} |
| 93 |
} |
} |
| 94 |
|
|
| 95 |
|
_nGood++; |
| 96 |
|
OnGood(event); |
| 97 |
|
return CUTOK; |
| 98 |
} |
} |