/[PAMELA software]/PamCut/Collections/SmartCollection/SmartCollection.cpp
ViewVC logotype

Diff of /PamCut/Collections/SmartCollection/SmartCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by pam-fi, Fri May 29 10:10:31 2009 UTC revision 1.3 by pam-fi, Fri Jun 5 13:14:35 2009 UTC
# Line 11  Line 11 
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) {
# Line 38  void SmartCollection::Finalize() { Line 39  void SmartCollection::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 < _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  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.23