source: trunk/source/graphics_reps/include/G4SmartFilter.hh @ 1202

Last change on this file since 1202 was 1058, checked in by garnier, 15 years ago

file release beta

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