Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members | Related Pages

BaseCutHelpers.h

Go to the documentation of this file.
00001 
00010 #ifndef __BASECUTHELPERS_H
00011 #define __BASECUTHELPERS_H
00012 
00013 #include "jbltools/sfh/BaseCut.h"
00014 #include "jbltools/sfh/IntFunBase.h"
00015 #include "jbltools/sfh/FloatFunBase.h"
00016 #include "jbltools/sfh/ROListPoR.h"
00017 #include "jbltools/sfh/BaseCutPoR.h"
00018 #include "jbltools/sfh/FillIteratorPoR.h"
00019 #include "jbltools/sfh/CachedO.h"
00020 
00021 #include <vector>
00022 
00023 
00024 // Class FloatBaseCut:
00025 //  Helper class to create a FloatFun out of a BaseCut
00026 class FloatBaseCut: public FloatFun {
00027   public:
00029     explicit FloatBaseCut (const BaseCut& theBaseCut_,  
00030                            const char *name_ = 0    
00031                           );
00033     virtual Float_FF operator() () const { return theBaseCut();} 
00035     virtual const FillIterator *getIterator() const { 
00036       return theBaseCut.getIterator(); 
00037     }
00038     
00039   protected:  
00041     virtual ~FloatBaseCut() {}
00042     const BaseCut& theBaseCut;                
00043 };
00044 
00045 // Class IntBaseCut:
00046 //  Helper class to create a IntFun out of a BaseCut
00047 class IntBaseCut: public IntFun {
00048   public:
00050     explicit IntBaseCut (const BaseCut& theBaseCut_,  
00051                          const char *name_ = 0    
00052                         );
00054     virtual int operator() () const { return theBaseCut();} 
00056     virtual const FillIterator *getIterator() const { 
00057       return theBaseCut.getIterator(); 
00058     }
00059   protected:  
00061     virtual ~IntBaseCut() {}
00062     const BaseCut& theBaseCut;                
00063 };
00064 
00065 //  Class TwoCutCompound:
00066 //  Helper class for binary logical operations between BaseCut objects
00067 /* 
00068  * This cut holds pointers to two other cuts.
00069  * The derived classes AndOfTwoCuts and OrOfTwoCuts implement
00070  * operator().
00071  */
00072 class TwoCutCompound : public BaseCut {
00073   public:
00075     TwoCutCompound (const BaseCut& lhs_,          
00076                     const std::string opname_,    
00077                     const BaseCut& rhs_           
00078                    );    
00079     TwoCutCompound (const BaseCut& lhs_,          
00080                     const BaseCut& rhs_,          
00081                     const std::string name_       
00082                     );   
00083                     
00084     virtual const FillIterator *getIterator() const;
00085     
00086   protected:
00088     virtual ~TwoCutCompound() {} 
00089     const BaseCut& lhs;                     
00090     const BaseCut& rhs;                     
00091 };
00092 
00093 //  Class AndOfTwoCuts:
00094 //  Helper class for the implementation of BaseCut && BaseCut
00095 /* 
00096  * Returns the AND of two cuts.
00097  * If the value of the first cut is false, the second cut is
00098  * not evaluated.
00099  */
00100 class AndOfTwoCuts : public TwoCutCompound {
00101   public:
00102     AndOfTwoCuts (const BaseCut& lhs_,    
00103                   const BaseCut& rhs_     
00104                   )
00105       : TwoCutCompound (lhs_, "&&", rhs_) 
00106       {}
00108     virtual bool operator() () const {
00109       return lhs() && rhs();
00110     };
00111     
00112   protected:
00114     virtual ~AndOfTwoCuts() {}
00115 };
00116 
00117 //  Class OrOfTwoCuts:
00118 //  Helper class for the implementation of BaseCut || BaseCut
00119 /* 
00120  * Returns the OR of two cuts.
00121  * If the value of the first cut is true, the second cut is
00122  * not evaluated.
00123  */
00124 class OrOfTwoCuts : public TwoCutCompound {
00125   public:
00126     OrOfTwoCuts (const BaseCut& lhs_,    
00127                  const BaseCut& rhs_     
00128                  )
00129       : TwoCutCompound (lhs_, "||", rhs_) 
00130       {}
00132     virtual bool operator() () const {
00133       return lhs() || rhs();
00134     }
00135   protected:
00137     virtual ~OrOfTwoCuts() {}
00138 };
00139 
00140 
00141 //  Class OneCutCompound:
00142 //  Helper class for unary logical operations on BaseCut objects
00143 /* 
00144  * This cut holds a pointer to one other cut.
00145  * The derived class NotOfACut implements operator().
00146  */ 
00147 class OneCutCompound : public BaseCut {
00148   public:
00149     OneCutCompound (const std::string& funname_,    
00150                     const BaseCut& arg_             
00151                     );
00152     OneCutCompound (const BaseCut& arg_,            
00153                     const std::string& name_        
00154                     );
00155     
00156     virtual const FillIterator *getIterator() const {  
00157       return arg.getIterator(); 
00158     }
00159     
00160   protected:
00162     virtual ~OneCutCompound() {} 
00163 
00164     const BaseCut& arg;                  
00165 };
00166 
00167 //  Class NotOfACut:
00168 //  Helper class  for ! BaseCut
00169 /* 
00170  * Returns NOT of a cut.
00171  */
00172 class NotOfACut : public OneCutCompound {
00173   public:
00174     NotOfACut (const BaseCut& arg_        
00175               )
00176     : OneCutCompound ("!", arg_){}
00178     virtual bool operator() () const {
00179       return !arg();
00180     }
00181   protected:
00183     virtual ~NotOfACut() {}; 
00184 };
00185 
00186 
00187 class CachedBaseCut: public BaseCut, public CachedO {
00188   public:
00190     CachedBaseCut (const ROListPoR& rol,      
00191                    const BaseCut&  arg_       
00192                   );
00193     CachedBaseCut (const ROListPoR& rol,      
00194                    const BaseCut&  arg_,      
00195                    const std::string& name_   
00196                   );
00197     
00199     virtual bool operator() () const;
00200     
00202     virtual void invalidateCache() { cacheValid = false; }
00203     
00204   protected:
00206     virtual ~CachedBaseCut() {}
00207     
00208     // Data members
00209     const   BaseCut& arg;         
00210     mutable bool cacheValid;       
00211     mutable bool cachedValue;     
00212 };
00213 
00214 class CachedBaseCutIt: public BaseCut, public CachedO {
00215   public:
00217     CachedBaseCutIt (const ROListPoR&     rol,  
00218                      const BaseCut&      arg_  
00219                     );
00221     CachedBaseCutIt (const ROListPoR&     rol,  
00222                      const BaseCut&      arg_, 
00223                      const FillIterator&  iter_ 
00224                     );
00226     CachedBaseCutIt (const ROListPoR&     rol,  
00227                      const BaseCut&      arg_, 
00228                      const std::string& name_   
00229                     );
00231     CachedBaseCutIt (const ROListPoR&     rol,  
00232                      const BaseCut&      arg_, 
00233                      const FillIterator&  iter_, 
00234                      const std::string& name_   
00235                     );
00236     
00238     virtual bool operator() () const;
00239     
00241     virtual const FillIterator *getIterator() const { 
00242       return &iter; 
00243     }
00244     
00246     virtual void invalidateCache() {   
00247       cacheValid.resize(0);
00248       cachedValues.resize(0);
00249     }
00250     
00251   protected:
00253     void growCache (unsigned int s) const;
00254   
00256     virtual ~CachedBaseCutIt() {}
00257     
00258     // Data members
00259     const   BaseCut& arg;                      
00260     const   FillIterator&  iter;                  
00261     mutable std::vector<bool>  cacheValid;      
00262     mutable std::vector<bool> cachedValues;    
00263 };
00264 
00265 
00266 
00267 
00268 #endif /* #ifndef __BASECUTHELPERS_H */

Generated on Thu Oct 26 12:52:55 2006 for SFH by doxygen 1.3.2