Geant4 11.1.1
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 43 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.

86 :G4SmartFilter<T>(name)
87 ,fAttName("")
88 ,fFirst(true)
89 ,filter(0)
90{}

◆ ~G4AttributeFilterT()

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

Definition at line 93 of file G4AttributeFilterT.hh.

94{
95 delete filter;
96}

Member Function Documentation

◆ 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:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40

◆ 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}

◆ 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<<'\n'
121 << "Available attributes:\n"
122 << *object.GetAttDefs();
124 ("G4AttributeFilterT::Evaluate", "modeling0102", JustWarning, ed, "Invalid attribute definition");
125 warnedUnableToExtract = true;
126 }
127 return false;
128 }
129
130 // Get new G4AttValue filter
131 filter = G4AttFilterUtils::GetNewFilter(attDef);
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 definition named "<<fAttName<<'\n'
152 << "Available attributes:\n"
153 << *object.GetAttDefs();
155 ("G4AttributeFilterT::Evaluate", "modeling0103", JustWarning, ed, "InvalidAttributeValue");
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}
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
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:76

◆ 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
G4String Name() const
Definition: G4VFilter.hh:80

◆ Set()

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

Definition at line 190 of file G4AttributeFilterT.hh.

191{
192 fAttName = name;
193}
const char * name(G4int ptype)

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