-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilter.h
206 lines (131 loc) · 4.89 KB
/
Filter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#ifndef FILTER_H
#define FILTER_H
#include <vector>
#include "TString.h"
#include "Config.h"
#include "Event.h"
class Filter {
public:
static const Filter* create(const TString &expr, const std::vector<TString> &dataSetLabels, unsigned int lineNum, const TString &label) { return create(expr,dataSetLabels,lineNum,true,label); }
static void clear();
Filter(const TString &uid) : uid_(uid) { garbage_.push_back(this); }
virtual ~Filter() {};
virtual TString printOut() const = 0;
virtual bool passes(const Event* evt, const TString &dataSetLabel) const = 0;
TString uid() const { return uid_; }
protected:
static TString offset_;
static TString cleanExpression(const TString &expr);
TString uid_;
private:
static std::vector<Filter*> garbage_;
static const Filter* create(const TString &expr, const std::vector<TString> &dataSetLabels, unsigned int lineNum, bool firstIteration, const TString &label);
static void checkForDanglingOperators(const TString &expr, unsigned int lineNum);
static void checkForMismatchingParentheses(const TString &expr, unsigned int lineNum);
static void checkForInvalidBooleanOperators(const TString &expr, unsigned int lineNum);
static bool isNegated(TString &expr);
static bool isSplit(const TString &expr, TString &expr1, TString &expr2, TString &op);
};
class Cut : public Filter {
public:
static Cut* create(const TString &expr, unsigned int lineNum);
Cut(const TString &uid) : Filter(uid) {};
virtual ~Cut() {};
TString printOut() const { return offset_+"|-- "+uid(); }
virtual bool passes(const Event* evt, const TString &dataSetLabel) const = 0;
protected:
TString var_;
double val_;
};
class CutGreaterThan : public Cut {
public:
CutGreaterThan(const TString &var, double val);
bool passes(const Event* evt, const TString &dataSetLabel) const { return evt->get(var_) > val_; }
};
class CutGreaterEqualThan : public Cut {
public:
CutGreaterEqualThan(const TString &var, double val);
bool passes(const Event* evt, const TString &dataSetLabel) const { return evt->get(var_) >= val_; }
};
class CutLessThan : public Cut {
public:
CutLessThan(const TString &var, double val);
bool passes(const Event* evt, const TString &dataSetLabel) const { return evt->get(var_) < val_; }
};
class CutLessEqualThan : public Cut {
public:
CutLessEqualThan(const TString &var, double val);
bool passes(const Event* evt, const TString &dataSetLabel) const { return evt->get(var_) <= val_; }
};
class CutEqual : public Cut {
public:
CutEqual(const TString &var, double val);
bool passes(const Event* evt, const TString &dataSetLabel) const { return evt->get(var_) == val_; }
};
class CutNotEqual : public Cut {
public:
CutNotEqual(const TString &var, double val);
bool passes(const Event* evt, const TString &dataSetLabel) const { return evt->get(var_) != val_; }
};
class CutLessThanLessThan : public Cut {
public:
CutLessThanLessThan(double val1, const TString &var, double val2);
bool passes(const Event* evt, const TString &dataSetLabel) const;
private:
double val2_;
};
class CutLessEqualThanLessEqualThan : public Cut {
public:
CutLessEqualThanLessEqualThan(double val1, const TString &var, double val2);
bool passes(const Event* evt, const TString &dataSetLabel) const;
private:
double val2_;
};
class BooleanOperator : public Filter {
public:
BooleanOperator(const Filter* filter1, const Filter* filter2, const TString &name);
TString printOut() const;
virtual bool passes(const Event* evt, const TString &dataSetLabel) const = 0;
protected:
const Filter* filter1_;
const Filter* filter2_;
private:
TString name_;
};
class FilterAND : public BooleanOperator {
public:
FilterAND(const Filter* filter1, const Filter* filter2);
bool passes(const Event* evt, const TString &dataSetLabel) const;
};
class FilterOR : public BooleanOperator {
public:
FilterOR(const Filter* filter1, const Filter* filter2);
bool passes(const Event* evt, const TString &dataSetLabel) const;
};
class FilterNOT : public Filter {
public:
FilterNOT(const Filter* filter);
TString printOut() const { return offset_+"|-- "+uid(); }
bool passes(const Event* evt, const TString &dataSetLabel) const { return !(filter_->passes(evt,dataSetLabel)); }
private:
const Filter* filter_;
};
// Lets pass all events
class FilterTRUE : public Filter {
public:
FilterTRUE() : Filter("FilterTRUE") {};
TString printOut() const { return offset_+"TRUE"; }
bool passes(const Event* evt, const TString &dataSetLabel) const { return true; }
};
// Returns true for all but the specified datasets
// Otherwise apply cuts
class FilterDataSet : public Filter {
public:
FilterDataSet(const Filter* filter, const std::vector<TString> &applyToDataSets);
TString printOut() const;
bool passes(const Event* evt, const TString &dataSetLabel) const;
private:
const Filter* filter_;
std::vector<TString> applyToDataSets_;
};
#endif