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

Annotation of /PamCut/PamCutBase/PamCutBase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations) (download)
Tue Oct 27 10:24:02 2009 UTC (15 years, 1 month ago) by pam-fi
Branch: MAIN
Changes since 1.3: +13 -2 lines
New ownership feature added.

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     // Check the range of events to analyze
33     if (firstEvent > lastEvent) {
34     return;
35     }
36     if (firstEvent < 0 || lastEvent > events->GetEntries() - 1) {
37     return;
38     }
39    
40     // Prepare the counters for the new analysis
41     Setup(events);
42    
43     // Apply the cuts
44     for (ULong_t iev = firstEvent; iev < lastEvent + 1; iev++) {
45     events->GetEntry(iev);
46     ApplyCut(events);
47     }
48    
49     // Closes the analysis
50     Finalize();
51    
52     }
53 pam-fi 1.2 void PamCut::Setup(PamLevel2 *events) {
54 pam-fi 1.1 _nEv = _nGood = 0;
55     }
56    
57     const char* PamCut::GetName() const {
58     return _cutName;
59     }
60    
61     void PamCut::SetName(const char *newName) {
62     _cutName = newName;
63     }
64    
65 pam-fi 1.2 PamCut& PamCut::operator=(const PamCut &rightValue) {
66     _cutName = rightValue._cutName;
67     return *this;
68     }
69 pam-fi 1.1
70     /* ************************ *
71     * PAMCUTCOLLECTION
72     * ************************ */
73 pam-fi 1.4 PamCutCollection::~PamCutCollection(){
74 pam-fi 1.1
75 pam-fi 1.4 if (_owns){
76     for (unsigned int i = 0; i < _cuts.size(); i++)
77     if (_cuts[i] != NULL){
78     delete _cuts[i];
79     _cuts[i] = NULL;
80     }
81     }
82     }
83    
84    
85     void PamCutCollection::AddCut(PamCut *cut) {
86     _cuts.push_back(cut);
87 pam-fi 1.1 }
88    
89     int PamCutCollection::Check(PamLevel2 *event) {
90    
91     // Apply the cuts
92     if (_cuts.size() == 0) {
93     return CUTOK;
94     }
95    
96     for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
97     if (_cuts[icut]->Check(event) != CUTOK) {
98     return icut;
99     }
100     }
101    
102     return CUTOK;
103     }
104    
105     int PamCutCollection::ApplyCut(PamLevel2 *event) {
106    
107     _nEv++;
108     // Apply the cuts
109     if (_cuts.size() == 0) {
110     _nGood++;
111     OnGood(event);
112     return CUTOK;
113     }
114    
115     for (unsigned int icut = 0; icut < _cuts.size(); icut++) {
116     if (_cuts[icut]->ApplyCut(event) != CUTOK) {
117     OnBad(event, icut);
118     return icut;
119     }
120     }
121    
122     _nGood++;
123     OnGood(event);
124     return CUTOK;
125     }
126    
127     PamCut *PamCutCollection::GetCut(unsigned int iCut) {
128     if (_cuts.size() == 0)
129     return NULL;
130     if (iCut < 0 || iCut > _cuts.size() - 1)
131     return NULL;
132     else
133     return _cuts[iCut];
134     }
135    
136 pam-fi 1.3 PamCut *PamCutCollection::GetCut(const char *cutName) {
137     if (_cuts.size() == 0)
138     return NULL;
139     for (unsigned int i = 0; i < _cuts.size(); i++){
140     if (strcmp(_cuts[i]->GetName(), cutName) == 0)
141     return _cuts[i];
142     }
143    
144     return NULL;
145     }
146    
147 pam-fi 1.1 unsigned int PamCutCollection::GetSize() {
148     return (unsigned int) _cuts.size();
149    
150     }
151    
152     PamCutCollection& PamCutCollection::operator=(const PamCutCollection &rightValue) {
153    
154     PamCut::operator=(rightValue);
155     _cuts = rightValue._cuts;
156     return *this;
157     }
158    
159 pam-fi 1.2 void PamCutCollection::Setup(PamLevel2 *events) {
160 pam-fi 1.1
161     PamCut::Setup(events);
162    
163 pam-fi 1.2 for (unsigned int i = 0; i < GetSize(); i++) {
164 pam-fi 1.1 _cuts[i]->Setup(events);
165     }
166     }
167    
168 pam-fi 1.2 void PamCutCollection::Finalize() {
169 pam-fi 1.1
170 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.
171 pam-fi 1.1 PamCut::Finalize();
172    
173 pam-fi 1.2 for (unsigned int i = 0; i < GetSize(); i++) {
174 pam-fi 1.1 _cuts[i]->Finalize();
175     }
176     }

  ViewVC Help
Powered by ViewVC 1.1.23