| 9 |
|
|
| 10 |
#include "SmartCollection.h" |
#include "SmartCollection.h" |
| 11 |
|
|
| 12 |
void SmartCollection::AddAction(CollectionAction& action) { |
SmartCollection::~SmartCollection(){ |
| 13 |
_actions.push_back(&action); |
if (_owns){ |
| 14 |
|
for (unsigned int i = 0; i < _actions.size(); i++) |
| 15 |
|
if (_actions[i] != NULL){ |
| 16 |
|
delete _actions[i]; |
| 17 |
|
_actions[i] = NULL; |
| 18 |
|
} |
| 19 |
|
} |
| 20 |
|
} |
| 21 |
|
|
| 22 |
|
void SmartCollection::AddAction(CollectionAction *action) { |
| 23 |
|
_actions.push_back(action); |
| 24 |
|
_actionsPositions.push_back(GetSize() - 1); |
| 25 |
} |
} |
| 26 |
|
|
| 27 |
CollectionAction *SmartCollection::GetAction(unsigned int iAction) { |
CollectionAction *SmartCollection::GetAction(unsigned int iAction) { |
| 33 |
return _actions[iAction]; |
return _actions[iAction]; |
| 34 |
} |
} |
| 35 |
|
|
| 36 |
|
CollectionAction *SmartCollection::GetAction(const char *actionName) { |
| 37 |
|
if (_actions.size() == 0) |
| 38 |
|
return NULL; |
| 39 |
|
for (unsigned int i = 0; i < _actions.size(); i++) { |
| 40 |
|
if (strcmp(_actions[i]->GetName(), actionName) == 0) |
| 41 |
|
return _actions[i]; |
| 42 |
|
} |
| 43 |
|
|
| 44 |
|
return NULL; |
| 45 |
|
} |
| 46 |
|
|
| 47 |
void SmartCollection::Setup(PamLevel2 *events) { |
void SmartCollection::Setup(PamLevel2 *events) { |
| 48 |
PamCutCollection::Setup(events); |
PamCutCollection::Setup(events); |
| 49 |
|
//cout << GetName() << endl; |
| 50 |
|
|
| 51 |
for (unsigned int i = 0; i < _actions.size(); i++) { |
for (unsigned int i = 0; i < _actions.size(); i++) { |
| 52 |
_actions[i]->Setup(events); |
_actions[i]->Setup(events); |
| 61 |
} |
} |
| 62 |
} |
} |
| 63 |
|
|
| 64 |
void SmartCollection::OnGood(PamLevel2 *event) { |
int SmartCollection::ApplyCut(PamLevel2 *event) { |
|
PamCutCollection::OnGood(event); |
|
| 65 |
|
|
| 66 |
for (unsigned int i = 0; i < _actions.size(); i++) { |
_nEv++; |
| 67 |
_actions[i]->OnGood(event); |
|
| 68 |
|
// Execute the actions placed before the cuts |
| 69 |
|
unsigned int iBeforeCuts = 0; |
| 70 |
|
//cout << GetName() << endl; |
| 71 |
|
if (_actions.size() > 0) { |
| 72 |
|
while (_actionsPositions[iBeforeCuts] == -1) { |
| 73 |
|
_actions[iBeforeCuts]->OnGood(event); |
| 74 |
|
iBeforeCuts++; |
| 75 |
|
if (iBeforeCuts == _actions.size()) |
| 76 |
|
break; |
| 77 |
|
} |
| 78 |
} |
} |
|
} |
|
| 79 |
|
|
| 80 |
void SmartCollection::OnBad(PamLevel2 *event, int selectionResult) { |
// Apply the cuts |
| 81 |
PamCutCollection::OnBad(event, selectionResult); |
if (_cuts.size() == 0) { |
| 82 |
|
_nGood++; |
| 83 |
|
OnGood(event); |
| 84 |
|
return CUTOK; |
| 85 |
|
} |
| 86 |
|
|
| 87 |
for (unsigned int i = 0; i < _actions.size(); i++) { |
unsigned int firstFailed = _cuts.size(); |
| 88 |
_actions[i]->OnBad(event, selectionResult); |
for (unsigned int iCut = 0; iCut < _cuts.size(); iCut++) { |
| 89 |
|
if (_cuts[iCut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { |
| 90 |
|
firstFailed = iCut; |
| 91 |
|
break; |
| 92 |
|
} |
| 93 |
|
} |
| 94 |
|
|
| 95 |
|
//Do actions |
| 96 |
|
if (_actions.size() > 0) { |
| 97 |
|
unsigned int lastPosition = _cuts.size(); |
| 98 |
|
for (unsigned int i = iBeforeCuts; i < _actions.size(); i++) { |
| 99 |
|
if (_actionsPositions[i] < (int) firstFailed) |
| 100 |
|
_actions[i]->OnGood(event); |
| 101 |
|
else { // A cut has failed |
| 102 |
|
if (lastPosition == _cuts.size()) // Record the position of the end of the bunch |
| 103 |
|
lastPosition = _actionsPositions[i]; |
| 104 |
|
if (_actionsPositions[i] > (int) lastPosition) // Don't do actions at the end of successive bunches |
| 105 |
|
break; |
| 106 |
|
_actions[i]->OnBad(event, (int) firstFailed); |
| 107 |
|
} |
| 108 |
|
} |
| 109 |
|
} |
| 110 |
|
|
| 111 |
|
if (firstFailed == _cuts.size()) { |
| 112 |
|
_nGood++; |
| 113 |
|
OnGood(event); |
| 114 |
|
return CUTOK; |
| 115 |
|
} |
| 116 |
|
else { |
| 117 |
|
OnBad(event, firstFailed); |
| 118 |
|
return firstFailed; |
| 119 |
} |
} |
| 120 |
} |
} |