Geant4-11
Public Types | Public Member Functions | Private Types | Private Attributes
G4AttributeFilterT< T > Class Template Reference

#include <G4AttributeFilterT.hh>

Inheritance diagram for G4AttributeFilterT< T >:
G4SmartFilter< T > G4VFilter< T >

Public Types

typedef T Type
 

Public Member Functions

G4bool Accept (const T &) const
 
void AddInterval (const G4String &)
 
void AddValue (const G4String &)
 
virtual void Clear ()
 
virtual bool Evaluate (const T &) const
 
 G4AttributeFilterT (const G4String &name="Unspecified")
 
G4bool GetActive () const
 
G4bool GetInvert () const
 
G4String GetName () const
 
G4bool GetVerbose () const
 
G4String Name () const
 
virtual void Print (std::ostream &ostr) const
 
virtual void PrintAll (std::ostream &ostr) const
 
virtual void Reset ()
 
void Set (const G4String &name)
 
void SetActive (const G4bool &)
 
void SetInvert (const G4bool &)
 
void SetVerbose (const G4bool &)
 
virtual ~G4AttributeFilterT ()
 

Private Types

enum  Config { Interval , SingleValue }
 
typedef std::vector< PairConfigVect
 
typedef std::pair< G4String, ConfigPair
 

Private Attributes

G4bool fActive
 
G4String fAttName
 
ConfigVect fConfigVect
 
G4bool fFirst
 
G4VAttValueFilterfilter
 
G4bool fInvert
 
G4String fName
 
size_t fNPassed
 
size_t fNProcessed
 
G4bool fVerbose
 

Detailed Description

template<typename T>
class G4AttributeFilterT< T >

Definition at line 43 of file G4AttributeFilterT.hh.

Member Typedef Documentation

◆ ConfigVect

template<typename T >
typedef std::vector<Pair> G4AttributeFilterT< T >::ConfigVect
private

Definition at line 72 of file G4AttributeFilterT.hh.

◆ Pair

template<typename T >
typedef std::pair<G4String, Config> G4AttributeFilterT< T >::Pair
private

Definition at line 71 of file G4AttributeFilterT.hh.

◆ Type

template<typename T >
typedef T G4VFilter< T >::Type
inherited

Definition at line 43 of file G4VFilter.hh.

Member Enumeration Documentation

◆ Config

template<typename T >
enum G4AttributeFilterT::Config
private
Enumerator
Interval 
SingleValue 

Definition at line 69 of file G4AttributeFilterT.hh.

Constructor & Destructor Documentation

◆ G4AttributeFilterT()

template<typename T >
G4AttributeFilterT< T >::G4AttributeFilterT ( const G4String name = "Unspecified")

Definition at line 85 of file G4AttributeFilterT.hh.

87 ,fAttName("")
88 ,fFirst(true)
89 ,filter(0)
90{}
G4VAttValueFilter * filter
const char * name(G4int ptype)

◆ ~G4AttributeFilterT()

template<typename T >
G4AttributeFilterT< T >::~G4AttributeFilterT
virtual

Definition at line 93 of file G4AttributeFilterT.hh.

94{
95 delete filter;
96}

Member Function Documentation

◆ Accept()

template<typename T >
G4bool G4SmartFilter< T >::Accept ( const T &  object) const
virtualinherited

Implements G4VFilter< T >.

Definition at line 104 of file G4SmartFilter.hh.

105{
106 if (fVerbose) {
107 G4cout<<"Begin verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
108 G4cout<<"Active ? : "<<fActive<<G4endl;
109 }
110
111 fNProcessed++;
112
113 // Pass everything if filter is not active
114 if (!fActive) {
115 fNPassed++;
116 return true;
117 }
118
119 // Do filtering
120 G4bool passed = Evaluate(object);
121
122 // Apply inversion if applicable
123 if (fInvert) passed = !passed;
124
125 if (passed) fNPassed++;
126
127 if (fVerbose) {
128 G4cout<<"Inverted ? : "<<fInvert<<G4endl;
129 G4cout<<"Passed ? : "<<passed<<G4endl;
130 G4cout<<"End verbose printout for filter "<<G4VFilter<T>::Name()<<G4endl;
131 }
132
133 return passed;
134}
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
virtual G4bool Evaluate(const T &) const =0
size_t fNProcessed
G4String Name() const
Definition: G4VFilter.hh:80

References G4cout, G4endl, and G4VFilter< T >::Name().

◆ AddInterval()

template<typename T >
void G4AttributeFilterT< T >::AddInterval ( const G4String interval)

Definition at line 197 of file G4AttributeFilterT.hh.

198{
199 std::pair<G4String, Config> myPair(interval, G4AttributeFilterT<T>::Interval);
200
201 typename ConfigVect::iterator iter = std::find(fConfigVect.begin(), fConfigVect.end(), myPair);
202
203 if (iter != fConfigVect.end()) {
205 ed <<"Interval "<< interval <<" already exists";
207 ("G4AttributeFilterT::AddInterval", "modeling0104", JustWarning, ed);
208 return;
209 }
210
211 fConfigVect.push_back(myPair);
212}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40

References G4Exception(), and JustWarning.

◆ AddValue()

template<typename T >
void G4AttributeFilterT< T >::AddValue ( const G4String value)

Definition at line 216 of file G4AttributeFilterT.hh.

217{
218 std::pair<G4String, Config> myPair(value, G4AttributeFilterT<T>::SingleValue);
219
220 typename ConfigVect::iterator iter = std::find(fConfigVect.begin(), fConfigVect.end(), myPair);
221
222 if (iter != fConfigVect.end()) {
224 ed <<"Single value "<< value <<" already exists";
226 ("G4AttributeFilterT::AddValue", "modeling0105", JustWarning, ed);
227 return;
228 }
229 fConfigVect.push_back(myPair);
230}

References G4Exception(), and JustWarning.

◆ Clear()

template<typename T >
void G4AttributeFilterT< T >::Clear
virtual

Implements G4SmartFilter< T >.

Definition at line 172 of file G4AttributeFilterT.hh.

173{
174 fConfigVect.clear();
175 if (0 != filter) filter->Reset();
176}
virtual void Reset()=0

◆ Evaluate()

template<typename T >
G4bool G4AttributeFilterT< T >::Evaluate ( const T &  object) const
virtual

Implements G4SmartFilter< T >.

Definition at line 100 of file G4AttributeFilterT.hh.

101{
102 // Return true (i.e., do not filter out) if attribute name has not yet been set.
103 if (fAttName.empty()) return true;
104
105 // ...or required attribute value has not yet been set
106 if (fConfigVect.size() == 0) return true;
107
108 if (fFirst) {
109
110 fFirst = false;
111
112 // Get attribute definition
113 G4AttDef attDef;
114
115 // Expect definition to exist
116 if (!G4AttUtils::ExtractAttDef(object, fAttName, attDef)) {
117 static G4bool warnedUnableToExtract = false;
118 if (!warnedUnableToExtract) {
120 ed <<"Unable to extract attribute definition named "<<fAttName<<' ';
122 ("G4AttributeFilterT::Evaluate", "modeling0102", JustWarning, ed, "Invalid attribute definition");
123 G4cerr << "Available attributes:\n"
124 << *object.GetAttDefs();
125 warnedUnableToExtract = true;
126 }
127 return false;
128 }
129
130 // Get new G4AttValue filter
132
133 // Load both interval and single valued data.
134 typename ConfigVect::const_iterator iter = fConfigVect.begin();
135
136 while (iter != fConfigVect.end()) {
137 if (iter->second == G4AttributeFilterT<T>::Interval) {filter->LoadIntervalElement(iter->first);}
138 else if (iter->second == G4AttributeFilterT<T>::SingleValue) {filter->LoadSingleValueElement(iter->first);}
139 iter++;
140 }
141 }
142
143 // Get attribute value
144 G4AttValue attVal;
145
146 // Expect value to exist
147 if (!G4AttUtils::ExtractAttValue(object, fAttName, attVal)) {
148 static G4bool warnedUnableToExtract = false;
149 if (!warnedUnableToExtract) {
151 ed <<"Unable to extract attribute value named "<<fAttName<<' ';
153 ("G4AttributeFilterT::Evaluate", "modeling0103", JustWarning, ed, "InvalidAttributeValue");
154 G4cerr << "Available attributes:\n"
155 << *object.GetAttDefs();
156 warnedUnableToExtract = true;
157 }
158 return false;
159 }
160
162 G4cout<<"G4AttributeFilterT processing attribute named "<<fAttName;
163 G4cout<<" with value "<<attVal.GetValue()<<G4endl;
164 }
165
166 // Pass subfilter
167 return (filter->Accept(attVal));
168}
G4GLOB_DLL std::ostream G4cerr
const G4String & GetValue() const
Definition: G4AttValue.hh:63
virtual void LoadIntervalElement(const G4String &)=0
virtual G4bool Accept(const G4AttValue &) const =0
virtual void LoadSingleValueElement(const G4String &)=0
G4VAttValueFilter * GetNewFilter(const G4AttDef &def)
G4bool ExtractAttDef(const T &object, const G4String &name, G4AttDef &def)
Definition: G4AttUtils.hh:61
G4bool ExtractAttValue(const T &object, const G4String &name, G4AttValue &attVal)
Definition: G4AttUtils.hh:75

References G4AttUtils::ExtractAttDef(), G4AttUtils::ExtractAttValue(), G4cerr, G4cout, G4endl, G4Exception(), G4AttFilterUtils::GetNewFilter(), G4AttValue::GetValue(), and JustWarning.

◆ GetActive()

template<typename T >
G4bool G4SmartFilter< T >::GetActive
inherited

Definition at line 172 of file G4SmartFilter.hh.

173{
174 return fActive;
175}

◆ GetInvert()

template<typename T >
G4bool G4SmartFilter< T >::GetInvert
inherited

Definition at line 186 of file G4SmartFilter.hh.

187{
188 return fInvert;
189}

◆ GetName()

template<typename T >
G4String G4VFilter< T >::GetName
inherited

Definition at line 87 of file G4VFilter.hh.

88{
89 return Name();
90}

◆ GetVerbose()

template<typename T >
G4bool G4SmartFilter< T >::GetVerbose
inherited

Definition at line 200 of file G4SmartFilter.hh.

201{
202 return fVerbose;
203}

◆ Name()

template<typename T >
G4String G4VFilter< T >::Name
inherited

Definition at line 80 of file G4VFilter.hh.

81{
82 return fName;
83}
G4String fName
Definition: G4VFilter.hh:66

Referenced by G4SmartFilter< T >::Accept(), G4AttributeFilterT< T >::Print(), and G4SmartFilter< T >::PrintAll().

◆ Print()

template<typename T >
void G4AttributeFilterT< T >::Print ( std::ostream &  ostr) const
virtual

Implements G4SmartFilter< T >.

Definition at line 180 of file G4AttributeFilterT.hh.

181{
182 ostr<<"Printing data for G4Attribute filter named: "<<G4VFilter<T>::Name()<<std::endl;
183 ostr<<"Filtered attribute name: "<<fAttName<<std::endl;
184 ostr<<"Printing sub filter data:"<<std::endl;
185 if (0 != filter) filter->PrintAll(ostr);
186}
virtual void PrintAll(std::ostream &ostr) const =0

References G4VFilter< T >::Name().

◆ PrintAll()

template<typename T >
void G4SmartFilter< T >::PrintAll ( std::ostream &  ostr) const
virtualinherited

Implements G4VFilter< T >.

Definition at line 138 of file G4SmartFilter.hh.

139{
140 ostr<<"Printing data for filter: "<<G4VFilter<T>::Name()<<G4endl;
141
142 Print(ostr);
143
144 ostr<<"Active ? : " <<fActive<<G4endl;
145 ostr<<"Inverted ? : " <<fInvert<<G4endl;
146 ostr<<"#Processed : " <<fNProcessed<<G4endl;
147 ostr<<"#Passed : " <<fNPassed<<G4endl;
148}
virtual void Print(std::ostream &ostr) const =0

References G4endl, G4VFilter< T >::Name(), and pyG4Element::Print().

◆ Reset()

template<typename T >
void G4SmartFilter< T >::Reset
virtualinherited

Implements G4VFilter< T >.

Definition at line 152 of file G4SmartFilter.hh.

153{
154 fActive = true;
155 fInvert = false;
156 fNProcessed = 0;
157 fNPassed = 0;
158
159 // Clear subclass data
160 Clear();
161}
virtual void Clear()=0

◆ Set()

template<typename T >
void G4AttributeFilterT< T >::Set ( const G4String name)

Definition at line 190 of file G4AttributeFilterT.hh.

191{
192 fAttName = name;
193}

References G4InuclParticleNames::name().

◆ SetActive()

template<typename T >
void G4SmartFilter< T >::SetActive ( const G4bool active)
inherited

Definition at line 165 of file G4SmartFilter.hh.

166{
167 fActive = active;
168}

◆ SetInvert()

template<typename T >
void G4SmartFilter< T >::SetInvert ( const G4bool invert)
inherited

Definition at line 179 of file G4SmartFilter.hh.

180{
181 fInvert = invert;
182}

◆ SetVerbose()

template<typename T >
void G4SmartFilter< T >::SetVerbose ( const G4bool verbose)
inherited

Definition at line 193 of file G4SmartFilter.hh.

194{
195 fVerbose = verbose;
196}

Field Documentation

◆ fActive

template<typename T >
G4bool G4SmartFilter< T >::fActive
privateinherited

Definition at line 81 of file G4SmartFilter.hh.

◆ fAttName

template<typename T >
G4String G4AttributeFilterT< T >::fAttName
private

Definition at line 75 of file G4AttributeFilterT.hh.

◆ fConfigVect

template<typename T >
ConfigVect G4AttributeFilterT< T >::fConfigVect
private

Definition at line 76 of file G4AttributeFilterT.hh.

◆ fFirst

template<typename T >
G4bool G4AttributeFilterT< T >::fFirst
mutableprivate

Definition at line 79 of file G4AttributeFilterT.hh.

◆ filter

template<typename T >
G4VAttValueFilter* G4AttributeFilterT< T >::filter
mutableprivate

Definition at line 80 of file G4AttributeFilterT.hh.

◆ fInvert

template<typename T >
G4bool G4SmartFilter< T >::fInvert
privateinherited

Definition at line 82 of file G4SmartFilter.hh.

◆ fName

template<typename T >
G4String G4VFilter< T >::fName
privateinherited

Definition at line 66 of file G4VFilter.hh.

◆ fNPassed

template<typename T >
size_t G4SmartFilter< T >::fNPassed
mutableprivateinherited

Definition at line 84 of file G4SmartFilter.hh.

◆ fNProcessed

template<typename T >
size_t G4SmartFilter< T >::fNProcessed
mutableprivateinherited

Definition at line 85 of file G4SmartFilter.hh.

◆ fVerbose

template<typename T >
G4bool G4SmartFilter< T >::fVerbose
privateinherited

Definition at line 83 of file G4SmartFilter.hh.


The documentation for this class was generated from the following file: