/[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.6.2.1 by pam-fi, Mon Jun 7 11:16:03 2010 UTC
# Line 9  Line 9 
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);    _actionsPositions.push_back(GetSize() - 1);
25  }  }
26    
# Line 23  CollectionAction *SmartCollection::GetAc Line 33  CollectionAction *SmartCollection::GetAc
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);
# Line 42  void SmartCollection::Finalize() { Line 64  void SmartCollection::Finalize() {
64  int SmartCollection::ApplyCut(PamLevel2 *event) {  int SmartCollection::ApplyCut(PamLevel2 *event) {
65    
66    _nEv++;    _nEv++;
67    
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    // Apply the cuts    // Apply the cuts
81    if (_cuts.size() == 0) {    if (_cuts.size() == 0) {
82      _nGood++;      _nGood++;
# Line 49  int SmartCollection::ApplyCut(PamLevel2 Line 84  int SmartCollection::ApplyCut(PamLevel2
84      return CUTOK;      return CUTOK;
85    }    }
86    
87    unsigned int bunchEnd = -1;    unsigned int firstFailed = _cuts.size();
88    unsigned int nActions = 0;    unsigned int iAction = iBeforeCuts;
89    unsigned int firstActionOfBunch = -1;    for (unsigned int iCut = 0; iCut < _cuts.size(); iCut++) {
90    if (_actions.size() > 0) {      if (_cuts[iCut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) {
91      // Set the bunch end to the position of the first action        firstFailed = iCut;
92      bunchEnd = _actionsPositions[0];        // Apply the bad actions at the end of the bunch
93      // Set the position of the first action at the end of the bunch        if (iAction < _actions.size()) {
94      firstActionOfBunch = 0;          unsigned int lastPosition = _actionsPositions[iAction];
95      // Set the number of actions at the end of this bunch of cuts          for (; iAction < _actions.size(); iAction++) {
96      nActions = 1;            if (_actionsPositions[iAction] > (int) lastPosition) // Don't do actions at the end of successive bunches
97      while (_actionsPositions[nActions] == bunchEnd)              break;
98        nActions++;            _actions[iAction]->OnBad(event, (int) firstFailed);
99    }  
   
   for (unsigned int icut = 0; icut < _cuts.size(); icut++) {  
     if (_cuts[icut]->ApplyCut(event) != CUTOK) {  
       // Check if there are actions at the end of the current bunch  
       // (last bunch may have no actions at its end)  
       if (bunchEnd >= icut) {  
         for (unsigned int i = 0; i < nActions; i++) {  
           _actions[firstActionOfBunch + i]->OnBad(event, icut);  
100          }          }
101        }        }
102        OnBad(event, icut);        break;
       return icut;  
103      }      }
104      else if (bunchEnd == icut) {      else if (iAction < _actions.size()) {
105        // We are at the end of the bunch of cuts, so let's execute the actions        // Do the good actions if we are at the end of the bunch
106        for (unsigned int i = 0; i < nActions; i++) {        while (_actionsPositions[iAction] == (int) iCut) {
107          _actions[firstActionOfBunch + i]->OnGood(event);          _actions[iAction]->OnGood(event);
108        }          iAction++;
109        if (firstActionOfBunch + nActions < _actions.size()) {          if (iAction == _actions.size())
110          // Current bunch is done, but actions are not finished yet. Set up the next bunch.            break;
         // 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++;  
111        }        }
112      }      }
113    }    }
114    
115    _nGood++;    if (firstFailed == _cuts.size()) {
116    OnGood(event);      _nGood++;
117    return CUTOK;      OnGood(event);
118        return CUTOK;
119      }
120      else {
121        OnBad(event, firstFailed);
122        return firstFailed;
123      }
124  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23