ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SmartFilter.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4SmartFilter.hh
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // Filter with additional funcionality such as active and inverted states,
28 // and filtering statistics
29 //
30 // Jane Tinslay, March 2006
31 //
32 #ifndef G4SMARTFILTER_HH
33 #define G4SMARTFILTER_HH
34 
35 #include "G4VFilter.hh"
36 
37 template <typename T>
38 class G4SmartFilter : public G4VFilter<T> {
39 
40 public: // With description
41 
42  // Construct with filter name
43  G4SmartFilter(const G4String& name);
44 
45  virtual ~G4SmartFilter();
46 
47  // Evaluate method implemented in subclass
48  virtual G4bool Evaluate(const T&) const = 0;
49 
50  // Print subclass configuration
51  virtual void Print(std::ostream& ostr) const = 0;
52 
53  // Clear filter
54  virtual void Clear() = 0;
55 
56  // Filter method
57  G4bool Accept(const T&) const;
58 
59  // Print G4SmartFilter configuration
60  virtual void PrintAll(std::ostream& ostr) const;
61 
62  //Reset
63  virtual void Reset();
64 
65  // Activate/deactivate filter
66  void SetActive(const G4bool&);
67  G4bool GetActive() const;
68 
69  // Invert filter
70  void SetInvert(const G4bool&);
71  G4bool GetInvert() const;
72 
73  // Set verbosity
74  void SetVerbose(const G4bool&);
75  G4bool GetVerbose() const;
76 
77 
78 private:
79 
80  // Data members
84  mutable size_t fNPassed;
85  mutable size_t fNProcessed;
86 
87 };
88 
89 template <typename T>
91  :G4VFilter<T>(name)
92  ,fActive(true)
93  ,fInvert(false)
94  ,fVerbose(false)
95  ,fNPassed(0)
96  ,fNProcessed(0)
97 {}
98 
99 template <typename T>
101 
102 template <typename T>
103 G4bool
104 G4SmartFilter<T>::Accept(const T& object) const
105 {
106  if (fVerbose) {
107  G4cout<<"Begin verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
108  G4cout<<"Active ? : "<<fActive<<G4endl;
109  }
110 
111  fNProcessed++;
112 
113  // Pass everything if filter is not active
114  if (!fActive) {
115  fNPassed++;
116  return true;
117  }
118 
119  // Do filtering
120  G4bool passed = Evaluate(object);
121 
122  // Apply inversion if applicable
123  if (fInvert) passed = !passed;
124 
125  if (passed) fNPassed++;
126 
127  if (fVerbose) {
128  G4cout<<"Inverted ? : "<<fInvert<<G4endl;
129  G4cout<<"Passed ? : "<<passed<<G4endl;
130  G4cout<<"End verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
131  }
132 
133  return passed;
134 }
135 
136 template <typename T>
137 void
138 G4SmartFilter<T>::PrintAll(std::ostream& ostr) const
139 {
140  ostr<<"Printing data for filter: "<<G4VFilter<T>::Name()<<G4endl;
141 
142  Print(ostr);
143 
144  ostr<<"Active ? : " <<fActive<<G4endl;
145  ostr<<"Inverted ? : " <<fInvert<<G4endl;
146  ostr<<"#Processed : " <<fNProcessed<<G4endl;
147  ostr<<"#Passed : " <<fNPassed<<G4endl;
148 }
149 
150 template <typename T>
151 void
153 {
154  fActive = true;
155  fInvert = false;
156  fNProcessed = 0;
157  fNPassed = 0;
158 
159  // Clear subclass data
160  Clear();
161 }
162 
163 template <typename T>
164 void
166 {
167  fActive = active;
168 }
169 
170 template <typename T>
171 G4bool
173 {
174  return fActive;
175 }
176 
177 template <typename T>
178 void
180 {
181  fInvert = invert;
182 }
183 
184 template <typename T>
185 G4bool
187 {
188  return fInvert;
189 }
190 
191 template <typename T>
192 void
194 {
195  fVerbose = verbose;
196 }
197 
198 template <typename T>
199 G4bool
201 {
202  return fVerbose;
203 }
204 
205 #endif
206