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

Contents of /PamCut/Collections/SmartCollection/SmartCollection.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations) (download)
Fri Jun 5 13:14:35 2009 UTC (15 years, 6 months ago) by pam-fi
Branch: MAIN
Changes since 1.2: +52 -9 lines
Changes to the handling of actions.

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 _actionsPositions.push_back(GetSize() - 1);
15 }
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 void SmartCollection::Setup(PamLevel2 *events) {
27 PamCutCollection::Setup(events);
28
29 for (unsigned int i = 0; i < _actions.size(); i++) {
30 _actions[i]->Setup(events);
31 }
32 }
33
34 void SmartCollection::Finalize() {
35 PamCutCollection::Finalize();
36
37 for (unsigned int i = 0; i < _actions.size(); i++) {
38 _actions[i]->Finalize();
39 }
40 }
41
42 int SmartCollection::ApplyCut(PamLevel2 *event) {
43
44 _nEv++;
45 // Apply the cuts
46 if (_cuts.size() == 0) {
47 _nGood++;
48 OnGood(event);
49 return CUTOK;
50 }
51
52 unsigned int bunchEnd = -1;
53 unsigned int nActions = 0;
54 unsigned int firstActionOfBunch = -1;
55 if (_actions.size() > 0) {
56 // Set the bunch end to the position of the first action
57 bunchEnd = _actionsPositions[0];
58 // Set the position of the first action at the end of the bunch
59 firstActionOfBunch = 0;
60 // Set the number of actions at the end of this bunch of cuts
61 nActions = 1;
62 while (_actionsPositions[nActions] == bunchEnd)
63 nActions++;
64 }
65
66 for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
67 if (_cuts[icut]->ApplyCut(event) != CUTOK) {
68 // Check if there are actions at the end of the current bunch
69 // (last bunch may have no actions at its end)
70 if (bunchEnd >= icut) {
71 for (unsigned int i = 0; i < nActions; i++) {
72 _actions[firstActionOfBunch + i]->OnBad(event, icut);
73 }
74 }
75 OnBad(event, icut);
76 return icut;
77 }
78 else if (bunchEnd == icut) {
79 // We are at the end of the bunch of cuts, so let's execute the actions
80 for (unsigned int i = 0; i < nActions; i++) {
81 _actions[firstActionOfBunch + i]->OnGood(event);
82 }
83 if (firstActionOfBunch + nActions < _actions.size()) {
84 // Current bunch is done, but actions are not finished yet. Set up the next bunch.
85 // Set the end of the new bunch and the number of actions at this end
86 firstActionOfBunch += nActions;
87 bunchEnd = _actionsPositions[firstActionOfBunch];
88 nActions = 1;
89 while (_actionsPositions[firstActionOfBunch + nActions] == bunchEnd)
90 nActions++;
91 }
92 }
93 }
94
95 _nGood++;
96 OnGood(event);
97 return CUTOK;
98 }

  ViewVC Help
Powered by ViewVC 1.1.23