Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:05

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // Filter with additional funcionality such as active and inverted states, 
0028 // and filtering statistics
0029 //
0030 // Jane Tinslay, March 2006
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: // With description
0041 
0042   // Construct with filter name
0043   G4SmartFilter(const G4String& name);
0044 
0045   virtual ~G4SmartFilter();
0046 
0047   // Evaluate method implemented in subclass
0048   virtual G4bool Evaluate(const T&) const = 0;
0049 
0050   // Print subclass configuration
0051   virtual void Print(std::ostream& ostr) const = 0;
0052 
0053   // Clear filter 
0054   virtual void Clear() = 0;
0055 
0056   // Filter method
0057   G4bool Accept(const T&) const;
0058   
0059   // Print G4SmartFilter configuration
0060   virtual void PrintAll(std::ostream& ostr) const;
0061 
0062   //Reset
0063   virtual void Reset();
0064 
0065   // Activate/deactivate filter
0066   void SetActive(const G4bool&);
0067   G4bool GetActive() const;
0068 
0069   // Invert filter
0070   void SetInvert(const G4bool&);
0071   G4bool GetInvert() const;
0072 
0073   // Set verbosity
0074   void SetVerbose(const G4bool&);
0075   G4bool GetVerbose() const;
0076   
0077 
0078 private:
0079 
0080   // Data members
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   // Pass everything if filter is not active
0114   if (!fActive) {
0115     fNPassed++;
0116     return true;
0117   }
0118   
0119   // Do filtering
0120   G4bool passed = Evaluate(object);
0121   
0122   // Apply inversion if applicable
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   // Clear subclass data
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