Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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// $Id$
27//
28// Filter with additional funcionality such as active and inverted states,
29// and filtering statistics
30//
31// Jane Tinslay, March 2006
32//
33#ifndef G4SMARTFILTER_HH
34#define G4SMARTFILTER_HH
35
36#include "G4VFilter.hh"
37
38template <typename T>
39class G4SmartFilter : public G4VFilter<T> {
40
41public: // With description
42
43 // Construct with filter name
44 G4SmartFilter(const G4String& name);
45
46 virtual ~G4SmartFilter();
47
48 // Evaluate method implemented in subclass
49 virtual G4bool Evaluate(const T&) const = 0;
50
51 // Print subclass configuration
52 virtual void Print(std::ostream& ostr) const = 0;
53
54 // Clear filter
55 virtual void Clear() = 0;
56
57 // Filter method
58 G4bool Accept(const T&) const;
59
60 // Print G4SmartFilter configuration
61 virtual void PrintAll(std::ostream& ostr) const;
62
63 //Reset
64 virtual void Reset();
65
66 // Activate/deactivate filter
67 void SetActive(const G4bool&);
69
70 // Invert filter
71 void SetInvert(const G4bool&);
73
74 // Set verbosity
75 void SetVerbose(const G4bool&);
77
78
79private:
80
81 // Data members
82 G4bool fActive;
83 G4bool fInvert;
84 G4bool fVerbose;
85 mutable size_t fNPassed;
86 mutable size_t fNProcessed;
87
88};
89
90template <typename T>
92 :G4VFilter<T>(name)
93 ,fActive(true)
94 ,fInvert(false)
95 ,fVerbose(false)
96 ,fNPassed(0)
97 ,fNProcessed(0)
98{}
99
100template <typename T>
102
103template <typename T>
104G4bool
105G4SmartFilter<T>::Accept(const T& object) const
106{
107 if (fVerbose) {
108 G4cout<<"Begin verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
109 G4cout<<"Active ? : "<<fActive<<G4endl;
110 }
111
112 fNProcessed++;
113
114 // Pass everything if filter is not active
115 if (!fActive) {
116 fNPassed++;
117 return true;
118 }
119
120 // Do filtering
121 G4bool passed = Evaluate(object);
122
123 // Apply inversion if applicable
124 if (fInvert) passed = !passed;
125
126 if (passed) fNPassed++;
127
128 if (fVerbose) {
129 G4cout<<"Inverted ? : "<<fInvert<<G4endl;
130 G4cout<<"Passed ? : "<<passed<<G4endl;
131 G4cout<<"End verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
132 }
133
134 return passed;
135}
136
137template <typename T>
138void
139G4SmartFilter<T>::PrintAll(std::ostream& ostr) const
140{
141 ostr<<"Printing data for filter: "<<G4VFilter<T>::Name()<<G4endl;
142
143 Print(ostr);
144
145 ostr<<"Active ? : " <<fActive<<G4endl;
146 ostr<<"Inverted ? : " <<fInvert<<G4endl;
147 ostr<<"#Processed : " <<fNProcessed<<G4endl;
148 ostr<<"#Passed : " <<fNPassed<<G4endl;
149}
150
151template <typename T>
152void
154{
155 fActive = true;
156 fInvert = false;
157 fNProcessed = 0;
158 fNPassed = 0;
159
160 // Clear subclass data
161 Clear();
162}
163
164template <typename T>
165void
167{
168 fActive = active;
169}
170
171template <typename T>
172G4bool
174{
175 return fActive;
176}
177
178template <typename T>
179void
181{
182 fInvert = invert;
183}
184
185template <typename T>
186G4bool
188{
189 return fInvert;
190}
191
192template <typename T>
193void
195{
196 fVerbose = verbose;
197}
198
199template <typename T>
200G4bool
202{
203 return fVerbose;
204}
205
206#endif
207
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT 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:81