File indexing completed on 2025-01-18 09:59:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #ifndef G4SMARTFILTER_HH
0033 #define G4SMARTFILTER_HH
0034
0035 #include "G4VFilter.hh"
0036
0037 template <typename T>
0038 class G4SmartFilter : public G4VFilter<T> {
0039
0040 public:
0041
0042
0043 G4SmartFilter(const G4String& name);
0044
0045 virtual ~G4SmartFilter();
0046
0047
0048 virtual G4bool Evaluate(const T&) const = 0;
0049
0050
0051 virtual void Print(std::ostream& ostr) const = 0;
0052
0053
0054 virtual void Clear() = 0;
0055
0056
0057 G4bool Accept(const T&) const;
0058
0059
0060 virtual void PrintAll(std::ostream& ostr) const;
0061
0062
0063 virtual void Reset();
0064
0065
0066 void SetActive(const G4bool&);
0067 G4bool GetActive() const;
0068
0069
0070 void SetInvert(const G4bool&);
0071 G4bool GetInvert() const;
0072
0073
0074 void SetVerbose(const G4bool&);
0075 G4bool GetVerbose() const;
0076
0077
0078 private:
0079
0080
0081 G4bool fActive;
0082 G4bool fInvert;
0083 G4bool fVerbose;
0084 mutable size_t fNPassed;
0085 mutable size_t fNProcessed;
0086
0087 };
0088
0089 template <typename T>
0090 G4SmartFilter<T>::G4SmartFilter(const G4String& name)
0091 :G4VFilter<T>(name)
0092 ,fActive(true)
0093 ,fInvert(false)
0094 ,fVerbose(false)
0095 ,fNPassed(0)
0096 ,fNProcessed(0)
0097 {}
0098
0099 template <typename T>
0100 G4SmartFilter<T>::~G4SmartFilter() {}
0101
0102 template <typename T>
0103 G4bool
0104 G4SmartFilter<T>::Accept(const T& object) const
0105 {
0106 if (fVerbose) {
0107 G4cout<<"Begin verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
0108 G4cout<<"Active ? : "<<fActive<<G4endl;
0109 }
0110
0111 fNProcessed++;
0112
0113
0114 if (!fActive) {
0115 fNPassed++;
0116 return true;
0117 }
0118
0119
0120 G4bool passed = Evaluate(object);
0121
0122
0123 if (fInvert) passed = !passed;
0124
0125 if (passed) fNPassed++;
0126
0127 if (fVerbose) {
0128 G4cout<<"Inverted ? : "<<fInvert<<G4endl;
0129 G4cout<<"Passed ? : "<<passed<<G4endl;
0130 G4cout<<"End verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
0131 }
0132
0133 return passed;
0134 }
0135
0136 template <typename T>
0137 void
0138 G4SmartFilter<T>::PrintAll(std::ostream& ostr) const
0139 {
0140 ostr<<"Printing data for filter: "<<G4VFilter<T>::Name()<<G4endl;
0141
0142 Print(ostr);
0143
0144 ostr<<"Active ? : " <<fActive<<G4endl;
0145 ostr<<"Inverted ? : " <<fInvert<<G4endl;
0146 ostr<<"#Processed : " <<fNProcessed<<G4endl;
0147 ostr<<"#Passed : " <<fNPassed<<G4endl;
0148 }
0149
0150 template <typename T>
0151 void
0152 G4SmartFilter<T>::Reset()
0153 {
0154 fActive = true;
0155 fInvert = false;
0156 fNProcessed = 0;
0157 fNPassed = 0;
0158
0159
0160 Clear();
0161 }
0162
0163 template <typename T>
0164 void
0165 G4SmartFilter<T>::SetActive(const G4bool& active)
0166 {
0167 fActive = active;
0168 }
0169
0170 template <typename T>
0171 G4bool
0172 G4SmartFilter<T>::GetActive() const
0173 {
0174 return fActive;
0175 }
0176
0177 template <typename T>
0178 void
0179 G4SmartFilter<T>::SetInvert(const G4bool& invert)
0180 {
0181 fInvert = invert;
0182 }
0183
0184 template <typename T>
0185 G4bool
0186 G4SmartFilter<T>::GetInvert() const
0187 {
0188 return fInvert;
0189 }
0190
0191 template <typename T>
0192 void
0193 G4SmartFilter<T>::SetVerbose(const G4bool& verbose)
0194 {
0195 fVerbose = verbose;
0196 }
0197
0198 template <typename T>
0199 G4bool
0200 G4SmartFilter<T>::GetVerbose() const
0201 {
0202 return fVerbose;
0203 }
0204
0205 #endif
0206