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

Diff of /PamCut/Collections/SmartBlindCollection/SmartBlindCollection.cpp

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

revision 1.1 by pam-fi, Fri May 29 10:08:46 2009 UTC revision 1.2 by pam-fi, Fri Jun 5 13:14:34 2009 UTC
# Line 5  Line 5 
5   *      Author: Nicola Mori   *      Author: Nicola Mori
6   */   */
7    
8  /*! @file SmartCollection.cpp The SmartCollection class implementation file */  /*! @file SmartCollection.cpp The SmartBlindCollection class implementation file */
9    
10  #include "SmartBlindCollection.h"  #include "SmartBlindCollection.h"
11    
12  void SmartBlindCollection::AddAction(CollectionAction& action) {  int SmartBlindCollection::ApplyCut(PamLevel2 *event) {
   _actions.push_back(&action);  
 }  
   
 CollectionAction *SmartBlindCollection::GetAction(unsigned int iAction) {  
   if (_actions.size() == 0)  
     return NULL;  
   if (iAction < 0 || iAction > _actions.size() - 1)  
     return NULL;  
   else  
     return _actions[iAction];  
 }  
13    
14  void SmartBlindCollection::Setup(PamLevel2 *events){    _nEv++;
15    BlindCutCollection::Setup(events);    if (_cuts.size() == 0) {
16        _nGood++;
17    for (unsigned int i = 0; i < _actions.size(); i++){      OnGood(event);
18      _actions[i]->Setup(events);      return CUTOK;
19    }    }
 }  
   
 void SmartBlindCollection::Finalize(){  
   BlindCutCollection::Finalize();  
20    
21    for (unsigned int i = 0; i < _actions.size(); i++){    unsigned int bunchEnd = -1;
22      _actions[i]->Finalize();    unsigned int nActions = 0;
23      unsigned int firstActionOfBunch = -1;
24      if (_actions.size() > 0) {
25        // Set the bunch end to the position of the first action
26        bunchEnd = _actionsPositions[0];
27        // Set the position of the first action at the end of the bunch
28        firstActionOfBunch = 0;
29        // Set the number of actions at the end of this bunch of cuts
30        nActions = 1;
31        while (_actionsPositions[nActions] == bunchEnd)
32          nActions++;
33    }    }
 }  
   
 void SmartBlindCollection::OnGood(PamLevel2 *event){  
   BlindCutCollection::OnGood(event);  
34    
35    for (unsigned int i = 0; i < _actions.size(); i++){    int firstFailed = CUTOK;
36      _actions[i]->OnGood(event);    for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
37        if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == CUTOK) {
38          firstFailed = icut;
39        }
40        if (bunchEnd == icut) {
41          if (firstFailed == CUTOK) {
42            for (unsigned int i = 0; i < nActions; i++) {
43              _actions[firstActionOfBunch + i]->OnGood(event);
44            }
45          }
46          else {
47            for (unsigned int i = 0; i < nActions; i++) {
48              _actions[firstActionOfBunch + i]->OnBad(event, icut);
49            }
50          }
51    
52          if (firstActionOfBunch + nActions < _actions.size()) {
53            // Current bunch is done, but actions are not finished yet. Set up the next bunch.
54            // Set the end of the new bunch and the number of actions at this end
55            firstActionOfBunch += nActions;
56            bunchEnd = _actionsPositions[firstActionOfBunch];
57            nActions = 1;
58            while (_actionsPositions[firstActionOfBunch + nActions] == bunchEnd)
59              nActions++;
60          }
61        }
62    }    }
 }  
63    
64  void SmartBlindCollection::OnBad(PamLevel2 *event, int selectionResult){    if (firstFailed == CUTOK) {
65    BlindCutCollection::OnBad(event, selectionResult);      _nGood++;
66        OnGood(event);
67    for (unsigned int i = 0; i < _actions.size(); i++){    }
68      _actions[i]->OnBad(event, selectionResult);    else {
69        OnBad(event, firstFailed);
70    }    }
71      return firstFailed;
72    
73  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.23