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) { |
23 |
return _actions[iAction]; |
return _actions[iAction]; |
24 |
} |
} |
25 |
|
|
26 |
void SmartCollection::Setup(PamLevel2 *events){ |
void SmartCollection::Setup(PamLevel2 *events) { |
27 |
PamCutCollection::Setup(events); |
PamCutCollection::Setup(events); |
28 |
|
|
29 |
for (unsigned int i = 0; i < GetSize(); i++){ |
for (unsigned int i = 0; i < _actions.size(); i++) { |
30 |
_actions[i]->Setup(events); |
_actions[i]->Setup(events); |
31 |
} |
} |
32 |
} |
} |
33 |
|
|
34 |
void SmartCollection::Finalize(){ |
void SmartCollection::Finalize() { |
35 |
PamCutCollection::Finalize(); |
PamCutCollection::Finalize(); |
36 |
|
|
37 |
for (unsigned int i = 0; i < GetSize(); i++){ |
for (unsigned int i = 0; i < _actions.size(); i++) { |
38 |
_actions[i]->Finalize(); |
_actions[i]->Finalize(); |
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 < GetSize(); 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 firstFailed = _cuts.size(); |
53 |
PamCutCollection::OnBad(event, selectionResult); |
for (unsigned int icut = 0; icut < _cuts.size(); icut++) { |
54 |
|
if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { |
55 |
|
firstFailed = icut; |
56 |
|
break; |
57 |
|
} |
58 |
|
} |
59 |
|
|
60 |
for (unsigned int i = 0; i < GetSize(); i++){ |
//Do actions |
61 |
_actions[i]->OnBad(event, selectionResult); |
if (_actions.size() > 0) { |
62 |
|
unsigned int lastPosition = _cuts.size(); |
63 |
|
for (unsigned int i = 0; i < _actions.size(); i++) { |
64 |
|
if (_actionsPositions[i] < firstFailed) |
65 |
|
_actions[i]->OnGood(event); |
66 |
|
else { // A cut has failed |
67 |
|
if (lastPosition == _cuts.size()) // Record the position of the end of the bunch |
68 |
|
lastPosition = _actionsPositions[i]; |
69 |
|
if (_actionsPositions[i] > lastPosition) // Don't do actions at the end of successive bunches |
70 |
|
break; |
71 |
|
_actions[i]->OnBad(event, firstFailed); |
72 |
|
} |
73 |
|
} |
74 |
|
} |
75 |
|
|
76 |
|
if (firstFailed == _cuts.size()) { |
77 |
|
_nGood++; |
78 |
|
OnGood(event); |
79 |
|
return CUTOK; |
80 |
|
} |
81 |
|
else { |
82 |
|
OnBad(event, firstFailed); |
83 |
|
return firstFailed; |
84 |
} |
} |
85 |
} |
} |