Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4SmartFilter.hh
Go to the documentation of this file.
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
37template <typename T>
38class G4SmartFilter : public G4VFilter<T> {
39
40public: // 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&);
68
69 // Invert filter
70 void SetInvert(const G4bool&);
72
73 // Set verbosity
74 void SetVerbose(const G4bool&);
76
77
78private:
79
80 // Data members
81 G4bool fActive;
82 G4bool fInvert;
83 G4bool fVerbose;
84 mutable size_t fNPassed;
85 mutable size_t fNProcessed;
86
87};
88
89template <typename T>
91 :G4VFilter<T>(name)
92 ,fActive(true)
93 ,fInvert(false)
94 ,fVerbose(false)
95 ,fNPassed(0)
96 ,fNProcessed(0)
97{}
98
99template <typename T>
101
102template <typename T>
103G4bool
104G4SmartFilter<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
136template <typename T>
137void
138G4SmartFilter<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
150template <typename T>
151void
153{
154 fActive = true;
155 fInvert = false;
156 fNProcessed = 0;
157 fNPassed = 0;
158
159 // Clear subclass data
160 Clear();
161}
162
163template <typename T>
164void
166{
167 fActive = active;
168}
169
170template <typename T>
171G4bool
173{
174 return fActive;
175}
176
177template <typename T>
178void
180{
181 fInvert = invert;
182}
183
184template <typename T>
185G4bool
187{
188 return fInvert;
189}
190
191template <typename T>
192void
194{
195 fVerbose = verbose;
196}
197
198template <typename T>
199G4bool
201{
202 return fVerbose;
203}
204
205#endif
206
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
virtual void Print(std::ostream &ostr) const =0
virtual void PrintAll(std::ostream &ostr) const
void SetVerbose(const G4bool &)
virtual void Reset()
G4SmartFilter(const G4String &name)
virtual G4bool Evaluate(const T &) const =0
virtual void Clear()=0
G4bool GetVerbose() const
void SetActive(const G4bool &)
G4bool GetActive() const
virtual ~G4SmartFilter()
void SetInvert(const G4bool &)
G4bool Accept(const T &) const
G4bool GetInvert() const
G4String Name() const
Definition: G4VFilter.hh:80