Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: G4SmartFilter.hh 66376 2012-12-18 09:42:59Z gcosmo $
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
85  mutable size_t fNPassed;
86  mutable size_t fNProcessed;
87 
88 };
89 
90 template <typename T>
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>
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
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
167 {
168  fActive = active;
169 }
170 
171 template <typename T>
172 G4bool
174 {
175  return fActive;
176 }
177 
178 template <typename T>
179 void
181 {
182  fInvert = invert;
183 }
184 
185 template <typename T>
186 G4bool
188 {
189  return fInvert;
190 }
191 
192 template <typename T>
193 void
195 {
196  fVerbose = verbose;
197 }
198 
199 template <typename T>
200 G4bool
202 {
203  return fVerbose;
204 }
205 
206 #endif
207 
void SetInvert(const G4bool &)
virtual void PrintAll(std::ostream &ostr) const
const XML_Char * name
Definition: expat.h:151
G4bool GetVerbose() const
G4SmartFilter(const G4String &name)
void Clear(Node *)
#define G4endl
Definition: G4ios.hh:61
virtual void Reset()
virtual void Clear()=0
virtual void Print(std::ostream &ostr) const =0
virtual ~G4SmartFilter()
G4bool Accept(const T &) const
void SetVerbose(const G4bool &)
bool G4bool
Definition: G4Types.hh:79
virtual G4bool Evaluate(const T &) const =0
G4String Name() const
Definition: G4VFilter.hh:81
void Print(G4Element &ele)
Definition: pyG4Element.cc:56
G4GLOB_DLL std::ostream G4cout
void SetActive(const G4bool &)
G4bool GetInvert() const
size_t fNProcessed
G4bool GetActive() const