G4AttributeFilterT< T > Class Template Reference

#include <G4AttributeFilterT.hh>

Inheritance diagram for G4AttributeFilterT< T >:

G4SmartFilter< T > G4VFilter< 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 &)

Detailed Description

template<typename T>
class G4AttributeFilterT< T >

Definition at line 44 of file G4AttributeFilterT.hh.


Constructor & Destructor Documentation

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

Definition at line 87 of file G4AttributeFilterT.hh.

00088   :G4SmartFilter<T>(name)
00089   ,fAttName("")
00090   ,fFirst(true)
00091   ,fWarnedMissingAttribute(false)
00092   ,filter(0)
00093 {}

template<typename T>
G4AttributeFilterT< T >::~G4AttributeFilterT (  )  [virtual]

Definition at line 96 of file G4AttributeFilterT.hh.

00097 {
00098   delete filter;
00099 }


Member Function Documentation

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

Definition at line 205 of file G4AttributeFilterT.hh.

References G4Exception(), and JustWarning.

00206 {
00207   std::pair<G4String, Config> myPair(interval, G4AttributeFilterT<T>::Interval);
00208 
00209   typename ConfigVect::iterator iter = std::find(fConfigVect.begin(), fConfigVect.end(), myPair);
00210   
00211   if (iter != fConfigVect.end()) {
00212     G4ExceptionDescription ed;
00213     ed <<"Interval "<< interval <<" already exists";
00214     G4Exception
00215       ("G4AttributeFilterT::AddInterval", "modeling0104", JustWarning, ed);
00216     return;
00217   }
00218 
00219   fConfigVect.push_back(myPair);
00220 }

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

Definition at line 224 of file G4AttributeFilterT.hh.

References G4Exception(), and JustWarning.

00225 {
00226   std::pair<G4String, Config> myPair(value, G4AttributeFilterT<T>::SingleValue);
00227 
00228   typename ConfigVect::iterator iter = std::find(fConfigVect.begin(), fConfigVect.end(), myPair);
00229   
00230   if (iter != fConfigVect.end()) {
00231     G4ExceptionDescription ed;
00232     ed <<"Single value "<< value <<" already exists";
00233     G4Exception
00234       ("G4AttributeFilterT::AddValue", "modeling0105", JustWarning, ed);
00235     return;
00236   }
00237   fConfigVect.push_back(myPair);
00238 }

template<typename T>
void G4AttributeFilterT< T >::Clear (  )  [virtual]

Implements G4SmartFilter< T >.

Definition at line 180 of file G4AttributeFilterT.hh.

References G4VAttValueFilter::Reset().

00181 {
00182   fConfigVect.clear();
00183   if (0 != filter) filter->Reset();
00184 }

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

Implements G4SmartFilter< T >.

Definition at line 103 of file G4AttributeFilterT.hh.

References G4VAttValueFilter::Accept(), G4AttUtils::ExtractAttDef(), G4AttUtils::ExtractAttValue(), G4cout, G4endl, G4Exception(), G4AttFilterUtils::GetNewFilter(), G4AttValue::GetValue(), G4String::isNull(), JustWarning, G4VAttValueFilter::LoadIntervalElement(), and G4VAttValueFilter::LoadSingleValueElement().

00104 {
00105   // Return false if attribute name has not been set. Just print one warning.
00106   if (fAttName.isNull()) {
00107 
00108     if (!fWarnedMissingAttribute) {
00109       G4Exception("G4AttributeFilterT::Evaluate", "modeling0101", JustWarning, "Null attribute name");
00110       fWarnedMissingAttribute = true;
00111     }
00112     
00113     return false;
00114   }
00115   
00116   if (fFirst) {
00117 
00118     fFirst = false;
00119 
00120     // Get attribute definition
00121     G4AttDef attDef;
00122     
00123     // Expect definition to exist    
00124     if (!G4AttUtils::ExtractAttDef(object, fAttName, attDef)) {
00125       static G4bool warnedUnableToExtract = false;
00126       if (!warnedUnableToExtract) {
00127         G4ExceptionDescription ed;
00128         ed <<"Unable to extract attribute definition named "<<fAttName;
00129         G4Exception
00130           ("G4AttributeFilterT::Evaluate", "modeling0102", JustWarning, ed, "Invalid attribute definition");
00131         G4cout << "Available attributes:\n"
00132                << object.GetAttDefs();
00133         warnedUnableToExtract = true;
00134       }
00135       return false;
00136     }
00137     
00138     // Get new G4AttValue filter
00139     filter = G4AttFilterUtils::GetNewFilter(attDef);
00140 
00141     // Load both interval and single valued data.
00142     typename ConfigVect::const_iterator iter = fConfigVect.begin();
00143     
00144     while (iter != fConfigVect.end()) {
00145       if (iter->second == G4AttributeFilterT<T>::Interval) {filter->LoadIntervalElement(iter->first);}
00146       else if (iter->second == G4AttributeFilterT<T>::SingleValue) {filter->LoadSingleValueElement(iter->first);}
00147       iter++;
00148     }
00149   }
00150 
00151   // Get attribute value
00152   G4AttValue attVal;
00153 
00154   // Expect value to exist
00155   if (!G4AttUtils::ExtractAttValue(object, fAttName, attVal)) {
00156     static G4bool warnedUnableToExtract = false;
00157     if (!warnedUnableToExtract) {
00158       G4ExceptionDescription ed;
00159       ed <<"Unable to extract attribute value named "<<fAttName;
00160       G4Exception
00161         ("G4AttributeFilterT::Evaluate", "modeling0103", JustWarning, ed, "InvalidAttributeValue");
00162       G4cout << "Available attributes:\n"
00163              << object.GetAttDefs();
00164       warnedUnableToExtract = true;
00165     }
00166     return false;
00167   }
00168 
00169   if (G4SmartFilter<T>::GetVerbose()) {
00170     G4cout<<"G4AttributeFilterT processing attribute named "<<fAttName;
00171     G4cout<<" with value "<<attVal.GetValue()<<G4endl;
00172   }
00173 
00174   // Pass subfilter
00175   return (filter->Accept(attVal));
00176 }

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

Implements G4SmartFilter< T >.

Definition at line 188 of file G4AttributeFilterT.hh.

References G4VFilter< T >::Name(), and G4VAttValueFilter::PrintAll().

00189 {
00190   ostr<<"Printing data for G4Attribute filter named: "<<G4VFilter<T>::Name()<<std::endl;
00191   ostr<<"Filtered attribute name: "<<fAttName<<std::endl;
00192   ostr<<"Printing sub filter data:"<<std::endl;
00193   if (0 != filter) filter->PrintAll(ostr);
00194 }

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

Definition at line 198 of file G4AttributeFilterT.hh.

00199 {
00200   fAttName = name;
00201 }


The documentation for this class was generated from the following file:
Generated on Mon May 27 17:51:29 2013 for Geant4 by  doxygen 1.4.7