12 |
int SmartBlindCollection::ApplyCut(PamLevel2 *event) { |
int SmartBlindCollection::ApplyCut(PamLevel2 *event) { |
13 |
|
|
14 |
_nEv++; |
_nEv++; |
15 |
|
|
16 |
|
// Execute the actions placed before the cuts |
17 |
|
unsigned int iBeforeCuts = 0; |
18 |
|
//cout << GetName() << endl; |
19 |
|
if (_actions.size() > 0) { |
20 |
|
while (_actionsPositions[iBeforeCuts] == -1) { |
21 |
|
_actions[iBeforeCuts]->OnGood(event); |
22 |
|
iBeforeCuts++; |
23 |
|
if (iBeforeCuts == _actions.size()) |
24 |
|
break; |
25 |
|
} |
26 |
|
} |
27 |
|
|
28 |
|
// Apply the cuts |
29 |
if (_cuts.size() == 0) { |
if (_cuts.size() == 0) { |
30 |
_nGood++; |
_nGood++; |
31 |
OnGood(event); |
OnGood(event); |
32 |
return CUTOK; |
return CUTOK; |
33 |
} |
} |
34 |
|
|
35 |
unsigned int bunchEnd = -1; |
unsigned int firstFailed = _cuts.size(); |
36 |
unsigned int nActions = 0; |
unsigned int iAction = iBeforeCuts; |
37 |
unsigned int firstActionOfBunch = -1; |
for (unsigned int iCut = 0; iCut < _cuts.size(); iCut++) { |
38 |
if (_actions.size() > 0) { |
if (_cuts[iCut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { |
39 |
// Set the bunch end to the position of the first action |
firstFailed = iCut; |
|
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; |
|
40 |
} |
} |
41 |
if (bunchEnd == icut) { |
|
42 |
if (firstFailed == CUTOK) { |
if (iAction < _actions.size()) { |
43 |
for (unsigned int i = 0; i < nActions; i++) { |
if (firstFailed == _cuts.size()) { // No cut has failed yet |
44 |
_actions[firstActionOfBunch + i]->OnGood(event); |
while (_actionsPositions[iAction] == (int) iCut) { |
45 |
|
_actions[iAction]->OnGood(event); |
46 |
|
iAction++; |
47 |
|
if (iAction == _actions.size()) |
48 |
|
break; |
49 |
} |
} |
50 |
} |
} |
51 |
else { |
else { |
52 |
for (unsigned int i = 0; i < nActions; i++) { |
while (_actionsPositions[iAction] == (int) iCut) { |
53 |
_actions[firstActionOfBunch + i]->OnBad(event, icut); |
_actions[iAction]->OnBad(event, (int) firstFailed); |
54 |
|
iAction++; |
55 |
|
if (iAction == _actions.size()) |
56 |
|
break; |
57 |
} |
} |
58 |
} |
} |
59 |
|
|
|
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++; |
|
|
} |
|
60 |
} |
} |
61 |
} |
} |
62 |
|
|
63 |
if (firstFailed == CUTOK) { |
if (firstFailed == _cuts.size()) { |
64 |
_nGood++; |
_nGood++; |
65 |
OnGood(event); |
OnGood(event); |
66 |
|
return CUTOK; |
67 |
} |
} |
68 |
else { |
else { |
69 |
OnBad(event, firstFailed); |
OnBad(event, firstFailed); |
70 |
|
return firstFailed; |
71 |
} |
} |
|
return firstFailed; |
|
72 |
|
|
73 |
} |
} |