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.
12 #include "AliRsnExpression.h"
14 #include "AliRsnCutSet.h"
16 ClassImp(AliRsnCutSet)
18 //_____________________________________________________________________________
19 AliRsnCutSet::AliRsnCutSet() :
24 fCutSchemeIndexed(""),
30 // Constructor without name (not recommended)
33 fBoolValues = new Bool_t[1];
34 AliRsnExpression::fgCutSet = this;
37 //_____________________________________________________________________________
38 AliRsnCutSet::AliRsnCutSet(const char *name, RSNTARGET target) :
39 AliRsnTarget(name, target),
43 fCutSchemeIndexed(""),
49 // Constructor with argument name (recommended)
52 fBoolValues = new Bool_t[1];
54 AliRsnExpression::fgCutSet = this;
57 //_____________________________________________________________________________
58 AliRsnCutSet::AliRsnCutSet(const AliRsnCutSet & copy) :
61 fNumOfCuts(copy.fNumOfCuts),
62 fCutScheme(copy.fCutScheme),
63 fCutSchemeIndexed(copy.fCutSchemeIndexed),
65 fIsScheme(copy.fIsScheme),
66 fExpression(copy.fExpression)
73 fBoolValues = new Bool_t[fNumOfCuts];
74 for (i = 0; i < fNumOfCuts; ++i) {
75 fBoolValues[i] = copy.fBoolValues[i];
78 AliRsnExpression::fgCutSet = this;
81 //_____________________________________________________________________________
82 AliRsnCutSet& AliRsnCutSet::operator=(const AliRsnCutSet & copy)
85 // Assignment operator.
88 AliRsnTarget::operator=(copy);
91 fNumOfCuts = copy.fNumOfCuts;
92 fCutScheme = copy.fCutScheme;
93 fCutSchemeIndexed = copy.fCutSchemeIndexed;
94 fIsScheme = copy.fIsScheme;
95 fExpression = copy.fExpression;
97 if (fBoolValues) delete [] fBoolValues;
100 fBoolValues = new Bool_t[fNumOfCuts];
101 for (i = 0; i < fNumOfCuts; ++i) {
102 fBoolValues[i] = copy.fBoolValues[i];
105 AliRsnExpression::fgCutSet = this;
110 //_____________________________________________________________________________
111 AliRsnCutSet::~AliRsnCutSet()
118 delete [] fBoolValues;
121 //_____________________________________________________________________________
122 void AliRsnCutSet::AddCut(AliRsnCut *cut)
126 // This must be done for all components of the final expression.
127 // If the target of the cut does not match the target of this,
128 // the cut is not added.
131 if (!cut->IsTarget(GetTargetType())) {
132 AliError(Form("Cannot add this cut (cut set name,target = [%s],[%s] --- cut name,target = [%s],[%s]", GetName(), GetTargetTypeName(), cut->GetName(), cut->GetTargetTypeName()));
138 AliDebug(AliLog::kDebug, "<-");
140 AliInfo(Form("====> Adding a new cut: [%s]", cut->GetName()));
144 if (fBoolValues) delete [] fBoolValues;
146 fBoolValues = new Bool_t[fNumOfCuts];
147 for (i = 0; i < fNumOfCuts; i++) {
148 fBoolValues[i] = kTRUE;
151 AliDebug(AliLog::kDebug, Form("%d", fCuts.GetEntriesFast()));
152 AliDebug(AliLog::kDebug, "->");
155 //_____________________________________________________________________________
156 void AliRsnCutSet::ShowCuts() const
163 for (Int_t i = 0; i < fCuts.GetEntriesFast() ; i++) {
164 cut = (AliRsnCut*)fCuts.At(i);
169 //_____________________________________________________________________________
170 Bool_t AliRsnCutSet::IsSelected(TObject *object)
173 // Checks an object according to the cut expression defined here.
178 if (!fNumOfCuts) return kTRUE;
180 Bool_t boolReturn = kTRUE;
182 for (i = 0; i < fNumOfCuts; i++) {
183 cut = (AliRsnCut*)fCuts.At(i);
184 fBoolValues[i] = cut->IsSelected(object);
187 if (fIsScheme) boolReturn = Passed();
191 //_____________________________________________________________________________
192 void AliRsnCutSet::SetCutScheme(const char *theValue)
195 // Define the combination of cuts with logical operators
196 // and using the names given to all defined cuts.
199 AliDebug(AliLog::kDebug, "<-");
201 fCutScheme = theValue;
202 SetCutSchemeIndexed(theValue);
204 AliDebug(AliLog::kDebug, "->");
207 //_____________________________________________________________________________
208 void AliRsnCutSet::SetCutSchemeIndexed(TString theValue)
211 // Internal method which indexes all cuts to organize their combo
214 AliDebug(AliLog::kDebug, "<-");
215 theValue.Append(" ");
216 // fCutSchemeIndexed = theValue;
217 fCutSchemeIndexed = GetCutSchemeIndexed();
218 AliDebug(AliLog::kDebug, "->");
221 //_____________________________________________________________________________
222 Int_t AliRsnCutSet::GetIndexByCutName(TString s)
225 // Retrieve the cut index from its name
231 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
232 cut = (AliRsnCut*) fCuts.At(i);
233 if (!s.CompareTo(cut->GetName())) return i;
239 //_____________________________________________________________________________
240 Bool_t AliRsnCutSet::Passed()
243 // Combines the cuts according to expression
244 // and gives a global response to the cut check
247 AliRsnExpression::fgCutSet = this;
249 fExpression = new AliRsnExpression(fCutSchemeIndexed);
250 AliDebug(AliLog::kDebug, "fExpression was created.");
253 if (fCuts.IsEmpty()) return kTRUE;
255 return fExpression->Value(*GetCuts());
258 //_____________________________________________________________________________
259 Bool_t AliRsnCutSet::IsValidScheme()
262 // Validity check on cut expression specified by user
265 TString str(fCutScheme);
267 for (Int_t i = 0; i < fNumOfCuts; i++) {
268 cut = (AliRsnCut*)fCuts.At(i);
269 str.ReplaceAll(cut->GetName(), "");
271 str.ReplaceAll("&", "");
272 str.ReplaceAll("!", "");
273 str.ReplaceAll("|", "");
274 str.ReplaceAll("(", "");
275 str.ReplaceAll(")", "");
278 AliError(Form("Cut scheme '%s' is not valid !!!", fCutScheme.Data()));
283 // return (!(ShowCutScheme().Contains("Error")));
286 //_____________________________________________________________________________
287 TString AliRsnCutSet::ShowCutScheme()
290 // Utility method to check validity of expression
294 // return fExpression->Unparse();
297 //_____________________________________________________________________________
298 Int_t AliRsnCutSet::TestExpression(TString opt)
301 // AliRsnCut *cut1 = new AliRsnCut ("aaa","aaa");
302 // cut1->SetCutValues (AliRsnCut::kEsdPt,0.0,1.0);
303 // AliRsnCut *cut2 = new AliRsnCut ("bbb","bbb");
304 // cut2->SetCutValues (AliRsnCut::kEsdPt,1.,2.0);
305 // AliRsnCut *cut3 = new AliRsnCut ("ccc","ccc");
306 // cut3->SetCutValues (AliRsnCut::kEsdPt,2.0,3.0);
308 // AliRsnCutSet* set = new AliRsnCutSet ("setOne");
309 // set->AddCut (cut1);
310 // set->AddCut (cut2);
311 // set->AddCut (cut3);
313 // set->SetCutScheme ("(aaa&!(ccc))&(bbb&!(ccc))");
317 AliDebug(1, opt.Data());
321 //_____________________________________________________________________________
322 void AliRsnCutSet::PrintSetInfo()
325 // Show data about the cut set
330 AliInfo("========== Rsn Cut Set info ==============");
331 AliInfo(Form("Scheme : %s", fCutScheme.Data()));
332 AliInfo(Form("Scheme : %s", fCutSchemeIndexed.Data()));
333 AliInfo(Form("Num of Cuts: %d", fCuts.GetEntriesFast()));
334 AliInfo("====== Cuts ======");
336 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
337 cut = (AliRsnCut*) fCuts.At(i);
338 if (cut) AliInfo(Form("%d %d", i, fBoolValues[i]));
340 AliInfo("========== END Rsn Cut Mgr info ==============");
343 //_____________________________________________________________________________
344 TString AliRsnCutSet::GetCutSchemeIndexed()
347 // Internal method to retrieve the list of cuts with their indexes
348 // for evaluation of cut expression
351 AliDebug(AliLog::kDebug, "<-");
353 TString str(fCutScheme);
354 AliDebug(AliLog::kDebug, Form("Num of cuts %d", fCuts.GetEntriesFast()));
356 for (i = 0; i < fCuts.GetEntriesFast(); i++) {
357 cut = (AliRsnCut*) fCuts.At(i);
358 str.ReplaceAll(cut->GetName(), Form("%d", i));
360 AliDebug(AliLog::kDebug, "->");