/[PAMELA software]/PamCut/PamCutBase/PamCutBase.cpp
ViewVC logotype

Contents of /PamCut/PamCutBase/PamCutBase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations) (download)
Thu Mar 18 14:41:13 2010 UTC (14 years, 8 months ago) by pam-fi
Branch: MAIN
CVS Tags: Root_V8, MergedToHEAD_1, nuclei_reproc, MergedFromV8_1, BeforeMergingFromV8_1, V9, HEAD
Branch point for: V8
Changes since 1.6: +2 -2 lines
Error occurred while calculating annotation data.
Current event index added.

1 /*
2 * PamCutBase.cpp
3 *
4 * Created on: 12-feb-2009
5 * Author: Nicola Mori
6 */
7
8 /*! @file PamCutBase.cpp Implementation for classes defined in PamCut.h */
9
10 #include "PamCutBase.h"
11
12 /* ************** *
13 * PAMCUT
14 * ************** */
15 int PamCut::ApplyCut(PamLevel2 *event) {
16
17 _nEv++;
18 int result = Check(event);
19 if (result == CUTOK) {
20 _nGood++;
21 OnGood(event);
22 }
23 else {
24 OnBad(event, result);
25 }
26 return result;
27
28 }
29
30 void PamCut::Process(PamLevel2 *events, ULong_t firstEvent, ULong_t lastEvent) {
31
32 // Prepare the collection for the new analysis
33 Setup(events);
34
35 // Check the range of events to analyze
36 if (firstEvent > lastEvent) {
37 Finalize();
38 return;
39 }
40 if (firstEvent < 0 || lastEvent > events->GetEntries() - 1) {
41 Finalize();
42 return;
43 }
44
45 // Apply the cuts
46 for (_currEv = firstEvent; _currEv < lastEvent + 1; _currEv++) {
47 events->GetEntry(_currEv);
48 ApplyCut(events);
49 }
50
51 // Closes the analysis
52 Finalize();
53
54 }
55 void PamCut::Setup(PamLevel2 *events) {
56 _nEv = _nGood = 0;
57 }
58
59 const char* PamCut::GetName() const {
60 return _cutName;
61 }
62
63 void PamCut::SetName(const char *newName) {
64 _cutName = newName;
65 }
66
67 PamCut& PamCut::operator=(const PamCut &rightValue) {
68 _cutName = rightValue._cutName;
69 return *this;
70 }
71
72 /* ************************ *
73 * PAMCUTCOLLECTION
74 * ************************ */
75 PamCutCollection::~PamCutCollection() {
76
77 if (_owns) {
78 for (unsigned int i = 0; i < _cuts.size(); i++)
79 if (_cuts[i] != NULL) {
80 delete _cuts[i];
81 _cuts[i] = NULL;
82 }
83 }
84 }
85
86 void PamCutCollection::AddCut(PamCut *cut) {
87 _cuts.push_back(cut);
88 }
89
90 int PamCutCollection::Check(PamLevel2 *event) {
91
92 // Apply the cuts
93 if (_cuts.size() == 0) {
94 return CUTOK;
95 }
96
97 for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
98 if (_cuts[icut]->Check(event) != CUTOK) {
99 return icut;
100 }
101 }
102
103 return CUTOK;
104 }
105
106 int PamCutCollection::ApplyCut(PamLevel2 *event) {
107
108 _nEv++;
109 // Apply the cuts
110 if (_cuts.size() == 0) {
111 _nGood++;
112 OnGood(event);
113 return CUTOK;
114 }
115
116 for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
117 if (_cuts[icut]->ApplyCut(event) != CUTOK) {
118 OnBad(event, icut);
119 return icut;
120 }
121 }
122
123 _nGood++;
124 OnGood(event);
125 return CUTOK;
126 }
127
128 PamCut *PamCutCollection::GetCut(unsigned int iCut) {
129 if (_cuts.size() == 0)
130 return NULL;
131 if (iCut < 0 || iCut > _cuts.size() - 1)
132 return NULL;
133 else
134 return _cuts[iCut];
135 }
136
137 PamCut *PamCutCollection::GetCut(const char *cutName) {
138 if (_cuts.size() == 0)
139 return NULL;
140 for (unsigned int i = 0; i < _cuts.size(); i++) {
141 if (strcmp(_cuts[i]->GetName(), cutName) == 0)
142 return _cuts[i];
143 }
144
145 return NULL;
146 }
147
148 unsigned int PamCutCollection::GetSize() {
149 return (unsigned int) _cuts.size();
150
151 }
152
153 PamCutCollection& PamCutCollection::operator=(const PamCutCollection &rightValue) {
154
155 PamCut::operator=(rightValue);
156 _cuts = rightValue._cuts;
157 return *this;
158 }
159
160 void PamCutCollection::Setup(PamLevel2 *events) {
161
162 PamCut::Setup(events);
163
164 for (unsigned int i = 0; i < GetSize(); i++) {
165 _cuts[i]->Setup(events);
166 }
167 }
168
169 void PamCutCollection::Finalize() {
170
171 // PamCut::Finalize() is currently void, but in future it could contain something, so it's good to place a call here.
172 PamCut::Finalize();
173
174 for (unsigned int i = 0; i < GetSize(); i++) {
175 _cuts[i]->Finalize();
176 }
177 }

  ViewVC Help
Powered by ViewVC 1.1.23