/[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.5 - (hide annotations) (download)
Wed Jun 17 13:02:39 2009 UTC (15 years, 5 months ago) by pam-fi
Branch: MAIN
Changes since 1.4: +11 -0 lines
Added GetAction(const char *actionName) to retrieve actions by name and GetActionsSize().

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.5 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 pam-fi 1.2 void SmartCollection::Setup(PamLevel2 *events) {
38 pam-fi 1.1 PamCutCollection::Setup(events);
39    
40 pam-fi 1.2 for (unsigned int i = 0; i < _actions.size(); i++) {
41 pam-fi 1.1 _actions[i]->Setup(events);
42     }
43     }
44    
45 pam-fi 1.2 void SmartCollection::Finalize() {
46 pam-fi 1.1 PamCutCollection::Finalize();
47    
48 pam-fi 1.2 for (unsigned int i = 0; i < _actions.size(); i++) {
49 pam-fi 1.1 _actions[i]->Finalize();
50     }
51     }
52    
53 pam-fi 1.3 int SmartCollection::ApplyCut(PamLevel2 *event) {
54 pam-fi 1.1
55 pam-fi 1.3 _nEv++;
56     // Apply the cuts
57     if (_cuts.size() == 0) {
58     _nGood++;
59     OnGood(event);
60     return CUTOK;
61 pam-fi 1.1 }
62    
63 pam-fi 1.4 unsigned int firstFailed = _cuts.size();
64     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 pam-fi 1.3 }
70 pam-fi 1.1
71 pam-fi 1.4 //Do actions
72     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 pam-fi 1.3 }
84     }
85 pam-fi 1.1 }
86 pam-fi 1.3
87 pam-fi 1.4 if (firstFailed == _cuts.size()) {
88     _nGood++;
89     OnGood(event);
90     return CUTOK;
91     }
92     else {
93     OnBad(event, firstFailed);
94     return firstFailed;
95     }
96 pam-fi 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.23