Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AttributeFilterT< T > Class Template Reference

#include <G4AttributeFilterT.hh>

+ Inheritance diagram for G4AttributeFilterT< T >:

Public Member Functions

 G4AttributeFilterT (const G4String &name="Unspecified")
 
virtual ~G4AttributeFilterT ()
 
virtual bool Evaluate (const T &) const
 
virtual void Print (std::ostream &ostr) const
 
virtual void Clear ()
 
void Set (const G4String &name)
 
void AddInterval (const G4String &)
 
void AddValue (const G4String &)
 
- Public Member Functions inherited from G4SmartFilter< T >
 G4SmartFilter (const G4String &name)
 
virtual ~G4SmartFilter ()
 
virtual G4bool Evaluate (const T &) const =0
 
virtual void Print (std::ostream &ostr) const =0
 
virtual void Clear ()=0
 
G4bool Accept (const T &) const
 
virtual void PrintAll (std::ostream &ostr) const
 
virtual void Reset ()
 
void SetActive (const G4bool &)
 
G4bool GetActive () const
 
void SetInvert (const G4bool &)
 
G4bool GetInvert () const
 
void SetVerbose (const G4bool &)
 
G4bool GetVerbose () const
 
- Public Member Functions inherited from G4VFilter< T >
 G4VFilter (const G4String &name)
 
virtual ~G4VFilter ()
 
virtual G4bool Accept (const T &) const =0
 
virtual void PrintAll (std::ostream &ostr) const =0
 
virtual void Reset ()=0
 
G4String Name () const
 
G4String GetName () const
 

Additional Inherited Members

- Public Types inherited from G4VFilter< T >
typedef T Type
 

Detailed Description

template<typename T>
class G4AttributeFilterT< T >

Definition at line 44 of file G4AttributeFilterT.hh.

Constructor & Destructor Documentation

◆ G4AttributeFilterT()

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

Definition at line 87 of file G4AttributeFilterT.hh.

88 :G4SmartFilter<T>(name)
89 ,fAttName("")
90 ,fFirst(true)
91 ,fWarnedMissingAttribute(false)
92 ,filter(0)
93{}

◆ ~G4AttributeFilterT()

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

Definition at line 96 of file G4AttributeFilterT.hh.

97{
98 delete filter;
99}

Member Function Documentation

◆ AddInterval()

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

Definition at line 205 of file G4AttributeFilterT.hh.

206{
207 std::pair<G4String, Config> myPair(interval, G4AttributeFilterT<T>::Interval);
208
209 typename ConfigVect::iterator iter = std::find(fConfigVect.begin(), fConfigVect.end(), myPair);
210
211 if (iter != fConfigVect.end()) {
213 ed <<"Interval "<< interval <<" already exists";
215 ("G4AttributeFilterT::AddInterval", "modeling0104", JustWarning, ed);
216 return;
217 }
218
219 fConfigVect.push_back(myPair);
220}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76

◆ AddValue()

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

Definition at line 224 of file G4AttributeFilterT.hh.

225{
226 std::pair<G4String, Config> myPair(value, G4AttributeFilterT<T>::SingleValue);
227
228 typename ConfigVect::iterator iter = std::find(fConfigVect.begin(), fConfigVect.end(), myPair);
229
230 if (iter != fConfigVect.end()) {
232 ed <<"Single value "<< value <<" already exists";
234 ("G4AttributeFilterT::AddValue", "modeling0105", JustWarning, ed);
235 return;
236 }
237 fConfigVect.push_back(myPair);
238}

◆ Clear()

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

Implements G4SmartFilter< T >.

Definition at line 180 of file G4AttributeFilterT.hh.

181{
182 fConfigVect.clear();
183 if (0 != filter) filter->Reset();
184}
virtual void Reset()=0

◆ Evaluate()

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

Implements G4SmartFilter< T >.

Definition at line 103 of file G4AttributeFilterT.hh.

104{
105 // Return false if attribute name has not been set. Just print one warning.
106 if (fAttName.isNull()) {
107
108 if (!fWarnedMissingAttribute) {
109 G4Exception("G4AttributeFilterT::Evaluate", "modeling0101", JustWarning, "Null attribute name");
110 fWarnedMissingAttribute = true;
111 }
112
113 return false;
114 }
115
116 if (fFirst) {
117
118 fFirst = false;
119
120 // Get attribute definition
121 G4AttDef attDef;
122
123 // Expect definition to exist
124 if (!G4AttUtils::ExtractAttDef(object, fAttName, attDef)) {
125 static G4bool warnedUnableToExtract = false;
126 if (!warnedUnableToExtract) {
128 ed <<"Unable to extract attribute definition named "<<fAttName;
130 ("G4AttributeFilterT::Evaluate", "modeling0102", JustWarning, ed, "Invalid attribute definition");
131 G4cout << "Available attributes:\n"
132 << object.GetAttDefs();
133 warnedUnableToExtract = true;
134 }
135 return false;
136 }
137
138 // Get new G4AttValue filter
139 filter = G4AttFilterUtils::GetNewFilter(attDef);
140
141 // Load both interval and single valued data.
142 typename ConfigVect::const_iterator iter = fConfigVect.begin();
143
144 while (iter != fConfigVect.end()) {
145 if (iter->second == G4AttributeFilterT<T>::Interval) {filter->LoadIntervalElement(iter->first);}
146 else if (iter->second == G4AttributeFilterT<T>::SingleValue) {filter->LoadSingleValueElement(iter->first);}
147 iter++;
148 }
149 }
150
151 // Get attribute value
152 G4AttValue attVal;
153
154 // Expect value to exist
155 if (!G4AttUtils::ExtractAttValue(object, fAttName, attVal)) {
156 static G4bool warnedUnableToExtract = false;
157 if (!warnedUnableToExtract) {
159 ed <<"Unable to extract attribute value named "<<fAttName;
161 ("G4AttributeFilterT::Evaluate", "modeling0103", JustWarning, ed, "InvalidAttributeValue");
162 G4cout << "Available attributes:\n"
163 << object.GetAttDefs();
164 warnedUnableToExtract = true;
165 }
166 return false;
167 }
168
170 G4cout<<"G4AttributeFilterT processing attribute named "<<fAttName;
171 G4cout<<" with value "<<attVal.GetValue()<<G4endl;
172 }
173
174 // Pass subfilter
175 return (filter->Accept(attVal));
176}
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
const G4String & GetValue() const
Definition: G4AttValue.hh:64
G4bool isNull() const
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:62
G4bool ExtractAttValue(const T &object, const G4String &name, G4AttValue &attVal)
Definition: G4AttUtils.hh:76

◆ Print()

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

Implements G4SmartFilter< T >.

Definition at line 188 of file G4AttributeFilterT.hh.

189{
190 ostr<<"Printing data for G4Attribute filter named: "<<G4VFilter<T>::Name()<<std::endl;
191 ostr<<"Filtered attribute name: "<<fAttName<<std::endl;
192 ostr<<"Printing sub filter data:"<<std::endl;
193 if (0 != filter) filter->PrintAll(ostr);
194}
virtual void PrintAll(std::ostream &ostr) const =0
G4String Name() const
Definition: G4VFilter.hh:81

◆ Set()

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

Definition at line 198 of file G4AttributeFilterT.hh.

199{
200 fAttName = name;
201}

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