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

Annotation of /PamCut/Collections/SmartCollection/SmartCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Tue Jun 16 16:45:00 2009 UTC (15 years, 5 months ago) by pam-fi
Branch: MAIN
Changes since 1.3: +27 -40 lines
Bug in actions handling fixed.

1 pam-fi 1.1 /*
2     * SmartCollection.cpp
3     *
4     * Created on: 14-mag-2009
5     * Author: Nicola Mori
6     */
7    
8     /*! @file SmartCollection.cpp The SmartCollection class implementation file */
9    
10     #include "SmartCollection.h"
11    
12     void SmartCollection::AddAction(CollectionAction& action) {
13     _actions.push_back(&action);
14 pam-fi 1.3 _actionsPositions.push_back(GetSize() - 1);
15 pam-fi 1.1 }
16    
17     CollectionAction *SmartCollection::GetAction(unsigned int iAction) {
18     if (_actions.size() == 0)
19     return NULL;
20     if (iAction < 0 || iAction > _actions.size() - 1)
21     return NULL;
22     else
23     return _actions[iAction];
24     }
25    
26 pam-fi 1.2 void SmartCollection::Setup(PamLevel2 *events) {
27 pam-fi 1.1 PamCutCollection::Setup(events);
28    
29 pam-fi 1.2 for (unsigned int i = 0; i < _actions.size(); i++) {
30 pam-fi 1.1 _actions[i]->Setup(events);
31     }
32     }
33    
34 pam-fi 1.2 void SmartCollection::Finalize() {
35 pam-fi 1.1 PamCutCollection::Finalize();
36    
37 pam-fi 1.2 for (unsigned int i = 0; i < _actions.size(); i++) {
38 pam-fi 1.1 _actions[i]->Finalize();
39     }
40     }
41    
42 pam-fi 1.3 int SmartCollection::ApplyCut(PamLevel2 *event) {
43 pam-fi 1.1
44 pam-fi 1.3 _nEv++;
45     // Apply the cuts
46     if (_cuts.size() == 0) {
47     _nGood++;
48     OnGood(event);
49     return CUTOK;
50 pam-fi 1.1 }
51    
52 pam-fi 1.4 unsigned int firstFailed = _cuts.size();
53     for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
54     if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) {
55     firstFailed = icut;
56     break;
57     }
58 pam-fi 1.3 }
59 pam-fi 1.1
60 pam-fi 1.4 //Do actions
61     if (_actions.size() > 0) {
62     unsigned int lastPosition = _cuts.size();
63     for (unsigned int i = 0; i < _actions.size(); i++) {
64     if (_actionsPositions[i] < firstFailed)
65     _actions[i]->OnGood(event);
66     else { // A cut has failed
67     if (lastPosition == _cuts.size()) // Record the position of the end of the bunch
68     lastPosition = _actionsPositions[i];
69     if (_actionsPositions[i] > lastPosition) // Don't do actions at the end of successive bunches
70     break;
71     _actions[i]->OnBad(event, firstFailed);
72 pam-fi 1.3 }
73     }
74 pam-fi 1.1 }
75 pam-fi 1.3
76 pam-fi 1.4 if (firstFailed == _cuts.size()) {
77     _nGood++;
78     OnGood(event);
79     return CUTOK;
80     }
81     else {
82     OnBad(event, firstFailed);
83     return firstFailed;
84     }
85 pam-fi 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.23