/[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.1.1.1 by pam-fi, Wed May 27 13:30:09 2009 UTC revision 1.5 by pam-fi, Wed Jun 17 13:02:39 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 22  CollectionAction *SmartCollection::GetAc Line 23  CollectionAction *SmartCollection::GetAc
23      return _actions[iAction];      return _actions[iAction];
24  }  }
25    
26  void SmartCollection::Setup(PamLevel2 *events){  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) {
38    PamCutCollection::Setup(events);    PamCutCollection::Setup(events);
39    
40    for (unsigned int i = 0; i < GetSize(); i++){    for (unsigned int i = 0; i < _actions.size(); i++) {
41      _actions[i]->Setup(events);      _actions[i]->Setup(events);
42    }    }
43  }  }
44    
45  void SmartCollection::Finalize(){  void SmartCollection::Finalize() {
46    PamCutCollection::Finalize();    PamCutCollection::Finalize();
47    
48    for (unsigned int i = 0; i < GetSize(); i++){    for (unsigned int i = 0; i < _actions.size(); i++) {
49      _actions[i]->Finalize();      _actions[i]->Finalize();
50    }    }
51  }  }
52    
53  void SmartCollection::OnGood(PamLevel2 *event){  int SmartCollection::ApplyCut(PamLevel2 *event) {
   PamCutCollection::OnGood(event);  
54    
55    for (unsigned int i = 0; i < GetSize(); i++){    _nEv++;
56      _actions[i]->OnGood(event);    // Apply the cuts
57      if (_cuts.size() == 0) {
58        _nGood++;
59        OnGood(event);
60        return CUTOK;
61    }    }
 }  
62    
63  void SmartCollection::OnBad(PamLevel2 *event, int selectionResult){    unsigned int firstFailed = _cuts.size();
64    PamCutCollection::OnBad(event, selectionResult);    for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
65        if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) {
66          firstFailed = icut;
67          break;
68        }
69      }
70    
71    for (unsigned int i = 0; i < GetSize(); i++){    //Do actions
72      _actions[i]->OnBad(event, selectionResult);    if (_actions.size() > 0) {
73        unsigned int lastPosition = _cuts.size();
74        for (unsigned int i = 0; i < _actions.size(); i++) {
75          if (_actionsPositions[i] < firstFailed)
76            _actions[i]->OnGood(event);
77          else { // A cut has failed
78            if (lastPosition == _cuts.size()) // Record the position of the end of the bunch
79              lastPosition = _actionsPositions[i];
80            if (_actionsPositions[i] > lastPosition) // Don't do actions at the end of successive bunches
81              break;
82            _actions[i]->OnBad(event, firstFailed);
83          }
84        }
85      }
86    
87      if (firstFailed == _cuts.size()) {
88        _nGood++;
89        OnGood(event);
90        return CUTOK;
91      }
92      else {
93        OnBad(event, firstFailed);
94        return firstFailed;
95    }    }
96  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23