/[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.3 by pam-fi, Fri Jun 5 13:14:35 2009 UTC revision 1.5 by pam-fi, Wed Jun 17 13:02:39 2009 UTC
# Line 23  CollectionAction *SmartCollection::GetAc Line 23  CollectionAction *SmartCollection::GetAc
23      return _actions[iAction];      return _actions[iAction];
24  }  }
25    
26    CollectionAction *SmartCollection::GetAction(const char *actionName) {
27      if (_actions.size() == 0)
28        return NULL;
29      for (unsigned int i = 0; i < _actions.size(); i++){
30        if (strcmp(_actions[i]->GetName(), actionName) == 0)
31          return _actions[i];
32      }
33    
34      return NULL;
35    }
36    
37  void SmartCollection::Setup(PamLevel2 *events) {  void SmartCollection::Setup(PamLevel2 *events) {
38    PamCutCollection::Setup(events);    PamCutCollection::Setup(events);
39    
# Line 49  int SmartCollection::ApplyCut(PamLevel2 Line 60  int SmartCollection::ApplyCut(PamLevel2
60      return CUTOK;      return CUTOK;
61    }    }
62    
63    unsigned int bunchEnd = -1;    unsigned int firstFailed = _cuts.size();
   unsigned int nActions = 0;  
   unsigned int firstActionOfBunch = -1;  
   if (_actions.size() > 0) {  
     // Set the bunch end to the position of the first action  
     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++;  
   }  
   
64    for (unsigned int icut = 0; icut < _cuts.size(); icut++) {    for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
65      if (_cuts[icut]->ApplyCut(event) != CUTOK) {      if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) {
66        // Check if there are actions at the end of the current bunch        firstFailed = icut;
67        // (last bunch may have no actions at its end)        break;
       if (bunchEnd >= icut) {  
         for (unsigned int i = 0; i < nActions; i++) {  
           _actions[firstActionOfBunch + i]->OnBad(event, icut);  
         }  
       }  
       OnBad(event, icut);  
       return icut;  
68      }      }
69      else if (bunchEnd == icut) {    }
70        // We are at the end of the bunch of cuts, so let's execute the actions  
71        for (unsigned int i = 0; i < nActions; i++) {    //Do actions
72          _actions[firstActionOfBunch + i]->OnGood(event);    if (_actions.size() > 0) {
73        }      unsigned int lastPosition = _cuts.size();
74        if (firstActionOfBunch + nActions < _actions.size()) {      for (unsigned int i = 0; i < _actions.size(); i++) {
75          // Current bunch is done, but actions are not finished yet. Set up the next bunch.        if (_actionsPositions[i] < firstFailed)
76          // Set the end of the new bunch and the number of actions at this end          _actions[i]->OnGood(event);
77          firstActionOfBunch += nActions;        else { // A cut has failed
78          bunchEnd = _actionsPositions[firstActionOfBunch];          if (lastPosition == _cuts.size()) // Record the position of the end of the bunch
79          nActions = 1;            lastPosition = _actionsPositions[i];
80          while (_actionsPositions[firstActionOfBunch + nActions] == bunchEnd)          if (_actionsPositions[i] > lastPosition) // Don't do actions at the end of successive bunches
81            nActions++;            break;
82            _actions[i]->OnBad(event, firstFailed);
83        }        }
84      }      }
85    }    }
86    
87    _nGood++;    if (firstFailed == _cuts.size()) {
88    OnGood(event);      _nGood++;
89    return CUTOK;      OnGood(event);
90        return CUTOK;
91      }
92      else {
93        OnBad(event, firstFailed);
94        return firstFailed;
95      }
96  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23