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

Annotation of /PamCut/PamCutBase/PamCutBase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Tue Feb 16 13:33:12 2010 UTC (14 years, 9 months ago) by pam-fi
Branch: MAIN
Changes since 1.5: +2 -0 lines
Bug fix to let Finalize be always executed.

1 pam-fi 1.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 pam-fi 1.5 // Prepare the collection for the new analysis
33     Setup(events);
34    
35 pam-fi 1.1 // Check the range of events to analyze
36     if (firstEvent > lastEvent) {
37 pam-fi 1.6 Finalize();
38 pam-fi 1.1 return;
39     }
40     if (firstEvent < 0 || lastEvent > events->GetEntries() - 1) {
41 pam-fi 1.6 Finalize();
42 pam-fi 1.1 return;
43     }
44    
45     // Apply the cuts
46     for (ULong_t iev = firstEvent; iev < lastEvent + 1; iev++) {
47     events->GetEntry(iev);
48     ApplyCut(events);
49     }
50    
51     // Closes the analysis
52     Finalize();
53    
54     }
55 pam-fi 1.2 void PamCut::Setup(PamLevel2 *events) {
56 pam-fi 1.1 _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 pam-fi 1.2 PamCut& PamCut::operator=(const PamCut &rightValue) {
68     _cutName = rightValue._cutName;
69     return *this;
70     }
71 pam-fi 1.1
72     /* ************************ *
73     * PAMCUTCOLLECTION
74     * ************************ */
75 pam-fi 1.5 PamCutCollection::~PamCutCollection() {
76 pam-fi 1.1
77 pam-fi 1.5 if (_owns) {
78 pam-fi 1.4 for (unsigned int i = 0; i < _cuts.size(); i++)
79 pam-fi 1.5 if (_cuts[i] != NULL) {
80 pam-fi 1.4 delete _cuts[i];
81     _cuts[i] = NULL;
82     }
83     }
84     }
85    
86     void PamCutCollection::AddCut(PamCut *cut) {
87     _cuts.push_back(cut);
88 pam-fi 1.1 }
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 pam-fi 1.3 PamCut *PamCutCollection::GetCut(const char *cutName) {
138     if (_cuts.size() == 0)
139     return NULL;
140 pam-fi 1.5 for (unsigned int i = 0; i < _cuts.size(); i++) {
141 pam-fi 1.3 if (strcmp(_cuts[i]->GetName(), cutName) == 0)
142     return _cuts[i];
143     }
144    
145     return NULL;
146     }
147    
148 pam-fi 1.1 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 pam-fi 1.2 void PamCutCollection::Setup(PamLevel2 *events) {
161 pam-fi 1.1
162     PamCut::Setup(events);
163    
164 pam-fi 1.2 for (unsigned int i = 0; i < GetSize(); i++) {
165 pam-fi 1.1 _cuts[i]->Setup(events);
166     }
167     }
168    
169 pam-fi 1.2 void PamCutCollection::Finalize() {
170 pam-fi 1.1
171 pam-fi 1.2 // PamCut::Finalize() is currently void, but in future it could contain something, so it's good to place a call here.
172 pam-fi 1.1 PamCut::Finalize();
173    
174 pam-fi 1.2 for (unsigned int i = 0; i < GetSize(); i++) {
175 pam-fi 1.1 _cuts[i]->Finalize();
176     }
177     }

  ViewVC Help
Powered by ViewVC 1.1.23