StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StiFilter.h
1 #ifndef StiFilter_H
2 #define StiFilter_H 1
3 #include <string>
4 #include <vector>
5 using std::string;
6 #include <Stiostream.h>
7 #include <stdlib.h>
8 
9 class StiFilter
10 {
11  public:
12 
13  enum FilterMode {Null=0,Bool,ByValue,ByRange,ByExcludedRange};
14 
16 
19  name("noname"), used(true), minimum(0.), maximum(1.), mode(Null)
20  {}
21 
23  StiFilter(bool v, const string& n="noname", bool u=true):
24  name(n), used(u), minimum(v), maximum(0.), mode(Bool)
25  {}
26 
28  StiFilter(int v, const string& n="noname", bool u=true):
29  name(n), used(u), minimum(v), maximum(0.), mode(ByValue)
30  {}
31 
33  StiFilter(double v, const string& n="noname", bool u=true):
34  name(n), used(u), minimum(v), maximum(0.), mode(ByValue)
35  {}
36 
38  StiFilter(double min, double max, const string& n="noname", bool u=true):
39  name(n), used(u), minimum(min), maximum(max), mode(ByRange)
40  {}
41 
43  StiFilter(double min, double max, bool reverse, const string& n="noname", bool u=true):
44  name(n), used(u), minimum(min), maximum(max), mode(reverse?ByExcludedRange:ByRange)
45  {}
46 
48  StiFilter(const StiFilter &sp):
49  name(sp.name),used(sp.used),minimum(sp.minimum), maximum(sp.maximum), mode(sp.mode)
50  {}
51 
52  virtual ~StiFilter()
53  {}
54 
55  void setName(const string& n)
56  {
57  name = n;
58  }
59 
60  void setUsed(bool u)
61  {
62  used = u;
63  }
64 
65  void setValue(bool value)
66  {
67  minimum = value?1:0;
68  }
69 
70  void setValue(int value)
71  {
72  minimum = value;
73  }
74 
75  void setValue(double value)
76  {
77  minimum = value;
78  }
79 
80  void setRange(double min, double max)
81  {
82  minimum = min;
83  maximum = max;
84  }
85 
86  void set(double min, double max, bool reverse, const string& n, bool u)
87  {
88  name = n;
89  used = u;
90  minimum = min;
91  maximum = max;
92  mode = reverse?ByExcludedRange:ByRange;
93  }
94 
95  string getName()
96  {
97  return string(name);
98  }
99 
100  bool isUsed()
101  {
102  return used;
103  }
104 
105  double getValue()
106  {
107  return minimum;
108  }
109 
110  double getMinimum()
111  {
112  return minimum;
113  }
114 
115  double getMaximum()
116  {
117  return maximum;
118  }
119 
120  friend ostream& operator<<(ostream& os, const StiFilter &);
121 
122  virtual bool accept(bool value);
123  virtual bool accept(int value);
124  virtual bool accept(double value);
125 
126  protected:
127  string name;
128  bool used;
129  double minimum;
130  double maximum;
131  int mode;
132 };
133 
135 inline bool StiFilter::accept(bool value)
136 {
137  return value? minimum>0 : minimum==0 ;
138 }
139 
141 inline bool StiFilter::accept(int value)
142 {
143  switch (mode)
144  {
145  case Null: return false; // null filter always return false
146  case Bool: return minimum?value>0:value==0;
147  case ByValue: return minimum==value;
148  case ByRange: return value>minimum&&value<=maximum;
149  case ByExcludedRange: return value<=minimum || value>maximum;
150  }
151  return false;
152 }
153 
155 inline bool StiFilter::accept(double value)
156 {
157  switch (mode)
158  {
159  case Null: return false; // null filter always return false
160  case Bool: return minimum?value>0:value==0;
161  case ByValue: return minimum==value;
162  case ByRange: return value>minimum&&value<=maximum;
163  case ByExcludedRange: return value<=minimum || value>maximum;
164  }
165  return false;
166 }
167 
168 typedef vector<StiFilter*> StiFilterVec;
169 #endif
virtual bool accept(bool value)
Filter by value with Bool as input.
Definition: StiFilter.h:135
StiFilter(double min, double max, const string &n="noname", bool u=true)
Instantiation of a filter by range using double as input.
Definition: StiFilter.h:38
StiFilter()
Instantiation of a null filter.
Definition: StiFilter.h:18
StiFilter(double min, double max, bool reverse, const string &n="noname", bool u=true)
Instantiation of a filter by range using double as input and with selective normal/reverse logic...
Definition: StiFilter.h:43
StiFilter(bool v, const string &n="noname", bool u=true)
Instantiation of a boolean filter.
Definition: StiFilter.h:23
StiFilter(int v, const string &n="noname", bool u=true)
Instantiation of a filter by value using integer as input.
Definition: StiFilter.h:28
StiFilter(const StiFilter &sp)
Copy Ctr.
Definition: StiFilter.h:48
StiFilter(double v, const string &n="noname", bool u=true)
Instantiation of a filter by value using double as input.
Definition: StiFilter.h:33