]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnCutSet.cxx
Fix for coverity
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnCutSet.cxx
CommitLineData
e0baff8c 1//
2// Class AliRsnCutSet
3//
4// This is the front-end for cut management and checking.
5// It must be prepared by adding all required single cuts,
6// and then with a logical expression which combines all cuts
7// with the "AND", "OR" and "NOT" operators.
8//
9
06351446 10#include "AliLog.h"
11
06351446 12#include "AliRsnExpression.h"
b63357a0 13#include "AliRsnCut.h"
06351446 14
15#include "AliRsnCutSet.h"
16
aec0ec32 17ClassImp(AliRsnCutSet)
e2bafbbc 18
19//_____________________________________________________________________________
32992791 20AliRsnCutSet::AliRsnCutSet() :
2a1c7696 21 AliRsnTarget(),
22 fCuts(0),
23 fNumOfCuts(0),
24 fCutScheme(""),
25 fCutSchemeIndexed(""),
26 fBoolValues(0),
27 fIsScheme(kFALSE),
28 fExpression(0)
06351446 29{
e2bafbbc 30//
31// Constructor without name (not recommended)
32//
33
2a1c7696 34 fBoolValues = new Bool_t[1];
35 AliRsnExpression::fgCutSet = this;
06351446 36}
37
e2bafbbc 38//_____________________________________________________________________________
32992791 39AliRsnCutSet::AliRsnCutSet(const char *name, RSNTARGET target) :
2a1c7696 40 AliRsnTarget(name, target),
41 fCuts(0),
42 fNumOfCuts(0),
43 fCutScheme(""),
44 fCutSchemeIndexed(""),
45 fBoolValues(0),
46 fIsScheme(kFALSE),
47 fExpression(0)
06351446 48{
e2bafbbc 49//
50// Constructor with argument name (recommended)
51//
52
2a1c7696 53 fBoolValues = new Bool_t[1];
54 fExpression = 0;
55 AliRsnExpression::fgCutSet = this;
06351446 56}
57
e2bafbbc 58//_____________________________________________________________________________
aec0ec32 59AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
2a1c7696 60 AliRsnTarget(copy),
61 fCuts(copy.fCuts),
62 fNumOfCuts(copy.fNumOfCuts),
63 fCutScheme(copy.fCutScheme),
64 fCutSchemeIndexed(copy.fCutSchemeIndexed),
65 fBoolValues(0),
66 fIsScheme(copy.fIsScheme),
67 fExpression(copy.fExpression)
06351446 68{
e2bafbbc 69//
70// Copy constructor
71//
72
2a1c7696 73 Int_t i;
74 fBoolValues = new Bool_t[fNumOfCuts];
75 for (i = 0; i < fNumOfCuts; ++i) {
76 fBoolValues[i] = copy.fBoolValues[i];
77 }
78
79 AliRsnExpression::fgCutSet = this;
32992791 80}
81
82//_____________________________________________________________________________
83AliRsnCutSet& AliRsnCutSet::operator=(const AliRsnCutSet & copy)
84{
85//
86// Assignment operator.
87//
2a1c7696 88
89 AliRsnTarget::operator=(copy);
e6f3a909 90 if (this == &copy)
91 return *this;
92
2a1c7696 93 fCuts = copy.fCuts;
94 fNumOfCuts = copy.fNumOfCuts;
95 fCutScheme = copy.fCutScheme;
96 fCutSchemeIndexed = copy.fCutSchemeIndexed;
97 fIsScheme = copy.fIsScheme;
98 fExpression = copy.fExpression;
99
100 if (fBoolValues) delete [] fBoolValues;
101
102 Int_t i;
103 fBoolValues = new Bool_t[fNumOfCuts];
104 for (i = 0; i < fNumOfCuts; ++i) {
105 fBoolValues[i] = copy.fBoolValues[i];
106 }
107
108 AliRsnExpression::fgCutSet = this;
109
110 return (*this);
06351446 111}
112
e2bafbbc 113//_____________________________________________________________________________
06351446 114AliRsnCutSet::~AliRsnCutSet()
115{
e2bafbbc 116//
117// Destructor
118//
119
2a1c7696 120 delete fExpression;
121 delete [] fBoolValues;
06351446 122}
123
e2bafbbc 124//_____________________________________________________________________________
aec0ec32 125void AliRsnCutSet::AddCut(AliRsnCut *cut)
06351446 126{
e2bafbbc 127//
128// Add a new cut.
2dab9030 129// This must be done for all components of the final expression.
130// If the target of the cut does not match the target of this,
131// the cut is not added.
e2bafbbc 132//
06351446 133
2a1c7696 134 if (!cut->IsTarget(GetTargetType())) {
135 AliError(Form("Cannot add this cut (cut set name,target = [%s],[%s] --- cut name,target = [%s],[%s]", GetName(), GetTargetTypeName(), cut->GetName(), cut->GetTargetTypeName()));
136 return;
137 }
2dab9030 138
2a1c7696 139 Int_t i;
aec0ec32 140
2a1c7696 141 AliDebug(AliLog::kDebug, "<-");
142 fCuts.Add(cut);
143 AliInfo(Form("====> Adding a new cut: [%s]", cut->GetName()));
2b1a5e62 144 //cut->Print();
2a1c7696 145 fNumOfCuts++;
aec0ec32 146
2a1c7696 147 if (fBoolValues) delete [] fBoolValues;
aec0ec32 148
2a1c7696 149 fBoolValues = new Bool_t[fNumOfCuts];
150 for (i = 0; i < fNumOfCuts; i++) {
151 fBoolValues[i] = kTRUE;
152 }
aec0ec32 153
2a1c7696 154 AliDebug(AliLog::kDebug, Form("%d", fCuts.GetEntriesFast()));
155 AliDebug(AliLog::kDebug, "->");
06351446 156}
157
e2bafbbc 158//_____________________________________________________________________________
4fbb2459 159void AliRsnCutSet::ShowCuts() const
06351446 160{
e2bafbbc 161//
162// Prints all cuts
163//
2a1c7696 164 AliRsnCut *cut;
165
166 for (Int_t i = 0; i < fCuts.GetEntriesFast() ; i++) {
167 cut = (AliRsnCut*)fCuts.At(i);
168 cut->Print();
169 }
06351446 170}
171
e2bafbbc 172//_____________________________________________________________________________
32992791 173Bool_t AliRsnCutSet::IsSelected(TObject *object)
06351446 174{
e2bafbbc 175//
176// Checks an object according to the cut expression defined here.
177//
06351446 178
2a1c7696 179 Int_t i;
180
181 if (!fNumOfCuts) return kTRUE;
aec0ec32 182
2a1c7696 183 Bool_t boolReturn = kTRUE;
184 AliRsnCut *cut;
185 for (i = 0; i < fNumOfCuts; i++) {
186 cut = (AliRsnCut*)fCuts.At(i);
187 fBoolValues[i] = cut->IsSelected(object);
188 }
e0baff8c 189
2a1c7696 190 if (fIsScheme) boolReturn = Passed();
191 return boolReturn;
e0baff8c 192}
193
e2bafbbc 194//_____________________________________________________________________________
5faf5a07 195void AliRsnCutSet::SetCutScheme(const char *theValue)
06351446 196{
e2bafbbc 197//
198// Define the combination of cuts with logical operators
199// and using the names given to all defined cuts.
200//
06351446 201
2a1c7696 202 AliDebug(AliLog::kDebug, "<-");
203
204 fCutScheme = theValue;
205 SetCutSchemeIndexed(theValue);
206 fIsScheme = kTRUE;
207 AliDebug(AliLog::kDebug, "->");
e2bafbbc 208}
06351446 209
e2bafbbc 210//_____________________________________________________________________________
aec0ec32 211void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
06351446 212{
e2bafbbc 213//
214// Internal method which indexes all cuts to organize their combo
215//
216
2a1c7696 217 AliDebug(AliLog::kDebug, "<-");
218 theValue.Append(" ");
219 // fCutSchemeIndexed = theValue;
220 fCutSchemeIndexed = GetCutSchemeIndexed();
221 AliDebug(AliLog::kDebug, "->");
06351446 222}
223
e2bafbbc 224//_____________________________________________________________________________
aec0ec32 225Int_t AliRsnCutSet::GetIndexByCutName(TString s)
06351446 226{
e2bafbbc 227//
228// Retrieve the cut index from its name
229//
06351446 230
2a1c7696 231 Int_t i;
232 AliRsnCut *cut;
aec0ec32 233
2a1c7696 234 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
235 cut = (AliRsnCut*) fCuts.At(i);
236 if (!s.CompareTo(cut->GetName())) return i;
237 }
aec0ec32 238
2a1c7696 239 return -1;
06351446 240}
241
e2bafbbc 242//_____________________________________________________________________________
06351446 243Bool_t AliRsnCutSet::Passed()
244{
e2bafbbc 245//
246// Combines the cuts according to expression
247// and gives a global response to the cut check
248//
249
2a1c7696 250 AliRsnExpression::fgCutSet = this;
251 if (!fExpression) {
252 fExpression = new AliRsnExpression(fCutSchemeIndexed);
253 AliDebug(AliLog::kDebug, "fExpression was created.");
254 }
255
256 if (fCuts.IsEmpty()) return kTRUE;
aec0ec32 257
2a1c7696 258 return fExpression->Value(*GetCuts());
06351446 259}
260
e2bafbbc 261//_____________________________________________________________________________
06351446 262Bool_t AliRsnCutSet::IsValidScheme()
263{
e2bafbbc 264//
265// Validity check on cut expression specified by user
266//
267
2a1c7696 268 TString str(fCutScheme);
269 AliRsnCut *cut;
270 for (Int_t i = 0; i < fNumOfCuts; i++) {
271 cut = (AliRsnCut*)fCuts.At(i);
272 str.ReplaceAll(cut->GetName(), "");
273 }
274 str.ReplaceAll("&", "");
275 str.ReplaceAll("!", "");
276 str.ReplaceAll("|", "");
277 str.ReplaceAll("(", "");
278 str.ReplaceAll(")", "");
279
280 if (!str.IsNull()) {
281 AliError(Form("Cut scheme '%s' is not valid !!!", fCutScheme.Data()));
282 return kFALSE;
283 }
284
285 return kTRUE;
cf4668f7 286// return (!(ShowCutScheme().Contains("Error")));
06351446 287}
288
e2bafbbc 289//_____________________________________________________________________________
b63357a0 290TString AliRsnCutSet::ShowCutScheme() const
06351446 291{
e2bafbbc 292//
293// Utility method to check validity of expression
294//
cf4668f7 295
2a1c7696 296 return fCutScheme;
cf4668f7 297// return fExpression->Unparse();
06351446 298}
299
e2bafbbc 300//_____________________________________________________________________________
aec0ec32 301Int_t AliRsnCutSet::TestExpression(TString opt)
06351446 302{
e2bafbbc 303
304// AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
305// cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
306// AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
307// cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
308// AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
309// cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
06351446 310//
e2bafbbc 311// AliRsnCutSet* set = new AliRsnCutSet ("setOne");
312// set->AddCut (cut1);
313// set->AddCut (cut2);
314// set->AddCut (cut3);
06351446 315//
e2bafbbc 316// set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
06351446 317//
318// set->ShowCuts ();
319
2a1c7696 320 AliDebug(1, opt.Data());
321 return 0;
06351446 322}
323
e2bafbbc 324//_____________________________________________________________________________
06351446 325void AliRsnCutSet::PrintSetInfo()
326{
e2bafbbc 327//
328// Show data about the cut set
329//
06351446 330
2a1c7696 331 Int_t i;
aec0ec32 332
2a1c7696 333 AliInfo("========== Rsn Cut Set info ==============");
334 AliInfo(Form("Scheme : %s", fCutScheme.Data()));
335 AliInfo(Form("Scheme : %s", fCutSchemeIndexed.Data()));
336 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
337 AliInfo("====== Cuts ======");
338 AliRsnCut *cut;
339 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
340 cut = (AliRsnCut*) fCuts.At(i);
341 if (cut) AliInfo(Form("%d %d", i, fBoolValues[i]));
342 }
343 AliInfo("========== END Rsn Cut Mgr info ==============");
06351446 344}
345
e2bafbbc 346//_____________________________________________________________________________
06351446 347TString AliRsnCutSet::GetCutSchemeIndexed()
348{
e2bafbbc 349//
350// Internal method to retrieve the list of cuts with their indexes
351// for evaluation of cut expression
352//
06351446 353
2a1c7696 354 AliDebug(AliLog::kDebug, "<-");
355 Int_t i;
356 TString str(fCutScheme);
357 AliDebug(AliLog::kDebug, Form("Num of cuts %d", fCuts.GetEntriesFast()));
358 AliRsnCut *cut;
359 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
360 cut = (AliRsnCut*) fCuts.At(i);
361 str.ReplaceAll(cut->GetName(), Form("%d", i));
362 }
363 AliDebug(AliLog::kDebug, "->");
364 return str;
e2bafbbc 365}