Geant4
9.6.p02
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
geant4_9_6_p02
source
graphics_reps
include
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
38
template
<
typename
T>
39
class
G4SmartFilter
:
public
G4VFilter
<T> {
40
41
public
:
// 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
&);
68
G4bool
GetActive
()
const
;
69
70
// Invert filter
71
void
SetInvert
(
const
G4bool
&);
72
G4bool
GetInvert
()
const
;
73
74
// Set verbosity
75
void
SetVerbose
(
const
G4bool
&);
76
G4bool
GetVerbose
()
const
;
77
78
79
private
:
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
90
template
<
typename
T>
91
G4SmartFilter<T>::G4SmartFilter
(
const
G4String
&
name
)
92
:
G4VFilter
<T>(name)
93
,fActive(true)
94
,fInvert(false)
95
,fVerbose(false)
96
,fNPassed(0)
97
,fNProcessed(0)
98
{}
99
100
template
<
typename
T>
101
G4SmartFilter<T>::~G4SmartFilter
() {}
102
103
template
<
typename
T>
104
G4bool
105
G4SmartFilter<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
137
template
<
typename
T>
138
void
139
G4SmartFilter<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
151
template
<
typename
T>
152
void
153
G4SmartFilter<T>::Reset
()
154
{
155
fActive =
true
;
156
fInvert =
false
;
157
fNProcessed = 0;
158
fNPassed = 0;
159
160
// Clear subclass data
161
Clear
();
162
}
163
164
template
<
typename
T>
165
void
166
G4SmartFilter<T>::SetActive
(
const
G4bool
&
active
)
167
{
168
fActive =
active
;
169
}
170
171
template
<
typename
T>
172
G4bool
173
G4SmartFilter<T>::GetActive
()
const
174
{
175
return
fActive;
176
}
177
178
template
<
typename
T>
179
void
180
G4SmartFilter<T>::SetInvert
(
const
G4bool
& invert)
181
{
182
fInvert = invert;
183
}
184
185
template
<
typename
T>
186
G4bool
187
G4SmartFilter<T>::GetInvert
()
const
188
{
189
return
fInvert;
190
}
191
192
template
<
typename
T>
193
void
194
G4SmartFilter<T>::SetVerbose
(
const
G4bool
& verbose)
195
{
196
fVerbose = verbose;
197
}
198
199
template
<
typename
T>
200
G4bool
201
G4SmartFilter<T>::GetVerbose
()
const
202
{
203
return
fVerbose;
204
}
205
206
#endif
207
Generated on Sat May 25 2013 14:33:18 for Geant4 by
1.8.4