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

H1BankFuns.h

Go to the documentation of this file.
00001 
00016 #ifndef __H1BANKFUNS_H
00017 #define __H1BANKFUNS_H
00018 
00019 #include "jbltools/sfh/h1/H1Funs.h"
00020 #include "H1OOBanks/H1BankPtr.h"
00021 #include "H1OOBanks/H1Row.h"
00022 
00023 
00024 #include <cassert>
00025 #include <cstring>
00026 
00027 class H1DmisBankPtr;
00028 class H1DmisRow;
00029 
00031 template <class H1SomeBankPtr, class H1SomeRow, class TM>
00032 class JBLH1SomeBankFloatFun: public FloatFun {
00033   public:
00035     JBLH1SomeBankFloatFun (const H1SomeBankPtr& ptr_,           
00036                            const FillIterator& iter_,           
00037                            TM (H1SomeRow::* ptr_mem_)() const,  
00038                            const char *attribname = 0           
00039                            )
00040       : FloatFun(getH1PtrName(ptr_)
00041                  +'['+iter_.getName()+"]."+attribname),
00042         ptr (ptr_), 
00043         iter (iter_),  
00044         ptr_mem(ptr_mem_)
00045       { assert (&ptr); 
00046       }
00048     virtual Float_FF operator() () const { 
00049       assert (ptr[iter()]);
00050       H1SomeRow& row = *ptr[iter()];
00051       return (row.*ptr_mem)();
00052     }
00053       
00055     virtual const FillIterator *getIterator() const { return &iter; }
00056   protected:
00058     virtual ~JBLH1SomeBankFloatFun() {}
00059   private:
00060    // Data members
00061     const H1SomeBankPtr& ptr;            
00062     const FillIterator&  iter;           
00063     TM (H1SomeRow::* ptr_mem)() const;   
00064 };
00065 
00066 class JBLH1BankFloatFun: public FloatFun {
00067   public:
00069     JBLH1BankFloatFun (const char *name_,            
00070                        const FillIterator& iter_,    
00071                        int column_ = 0,              
00072                        const char *attribname = 0    
00073                       )
00074       : FloatFun(std::string(name_)+'['+iter_.getName()+"]."
00075                  + (attribname ? std::string(attribname) : std::string("Float(")+str(column_)+')')),
00076         ptr (*new H1BankPtr(name_)), 
00077         iter (iter_), 
00078         column (column_)
00079       {   
00080         assert (&ptr);  
00081       }
00083     JBLH1BankFloatFun (const H1BankPtr& ptr_,      
00084                        const FillIterator& iter_,  
00085                        int column_ = 0,            
00086                        const char *attribname = 0  
00087                       )
00088       : FloatFun(getH1PtrName(ptr_)
00089                  +'['+iter_.getName()+"]."
00090                  + (attribname ? std::string(attribname) : std::string("Float(")+str(column_)+')')),
00091         ptr (ptr_), 
00092         iter (iter_), 
00093         column (column_)               
00094       {   
00095         assert (&ptr);  
00096       }
00098     virtual Float_FF operator() () const { 
00099       assert (ptr[iter()]);
00100       return ptr[iter()]->GetFloat (column);
00101     }
00103     virtual JBLH1BankFloatFun& operator[] (int newcolumn    
00104                                           ) const {
00105       return *new JBLH1BankFloatFun (ptr, iter, newcolumn);
00106     }   
00107       
00109     virtual const FillIterator *getIterator() const { return &iter; }
00110   protected:
00112     virtual ~JBLH1BankFloatFun() {}
00113   private:
00114     // Data members
00115     const H1BankPtr&    ptr;        
00116     const FillIterator& iter;       
00117           int           column;     
00118 };
00119 
00121 class JBLH1BankFloatFunInt: public FloatFun {
00122   public:
00124     JBLH1BankFloatFunInt (const char *name_,           
00125                           const FillIterator& iter_,    
00126                           int column_ = 0,              
00127                           const char *attribname = 0    
00128                          )
00129       : FloatFun(std::string(name_)+'['+iter_.getName()+"]."
00130                  + (attribname ? std::string(attribname) : std::string("Int(")+str(column_)+')')),
00131         ptr (*new H1BankPtr(name_)), 
00132         iter (iter_), 
00133         column (column_)  
00134       { assert (&ptr); }
00136     JBLH1BankFloatFunInt (const H1BankPtr& ptr_,      
00137                           const FillIterator& iter_,  
00138                           int column_ = 0,            
00139                           const char *attribname = 0  
00140                          )
00141       : FloatFun(getH1PtrName(ptr_)
00142                  +'['+iter_.getName()+"]."
00143                  + (attribname ? std::string(attribname) : std::string("Int(")+str(column_)+')')),
00144         ptr (ptr_), iter (iter_), column (column_)                  
00145       { assert (&ptr); }
00147     virtual Float_FF operator() () const { 
00148       assert (ptr[iter()]);
00149       return ptr[iter()]->GetInt (column);
00150     }
00152     virtual JBLH1BankFloatFunInt& operator[] (int newcolumn    
00153                                              ) const {
00154       return *new JBLH1BankFloatFunInt (ptr, iter, newcolumn);
00155     }   
00156       
00158     virtual const FillIterator *getIterator() const { return &iter; }
00159   protected:
00161     virtual ~JBLH1BankFloatFunInt() {}
00162   private:
00163     // Data members
00164     const H1BankPtr&    ptr;        
00165     const FillIterator& iter;       
00166           int           column;     
00167 };
00168 
00170 class JBLH1BankIntFun: public IntFun {
00171   public:
00173     JBLH1BankIntFun (const char *name_,            
00174                      const FillIterator& iter_,    
00175                      int column_ = 0,              
00176                      const char *attribname = 0    
00177                     )
00178       : IntFun(std::string(name_)+'['+iter_.getName()+"]."
00179                + (attribname ? std::string(attribname) : std::string("Int(")+str(column_)+')')),
00180         ptr (*new H1BankPtr(name_)), iter (iter_), column (column_)  
00181       { assert (&ptr); }
00183     JBLH1BankIntFun (const H1BankPtr& ptr_,      
00184                      const FillIterator& iter_,  
00185                      int column_ = 0,            
00186                      const char *attribname = 0    
00187                     )
00188       : IntFun(getH1PtrName(ptr_)
00189                +'['+iter_.getName()+"]."
00190                + (attribname ? std::string(attribname) : std::string("Int(")+str(column_)+')')),
00191         ptr (ptr_), iter (iter_), column (column_)                  
00192       { assert (&ptr); }
00194     virtual int operator() () const { 
00195       assert (ptr[iter()]);
00196       return ptr[iter()]->GetInt (column);
00197     }
00198     
00200     virtual JBLH1BankIntFun& operator[] (int newcolumn    
00201                                         ) const {
00202       return *new JBLH1BankIntFun (ptr, iter, newcolumn);
00203     }
00205     virtual JBLH1BankIntFun& Int (int newcolumn    
00206                                  ) const {
00207       return *new JBLH1BankIntFun (ptr, iter, newcolumn);
00208     }
00210     virtual JBLH1BankFloatFun& Float (int newcolumn    
00211                                      ) const {
00212       return *new JBLH1BankFloatFun (ptr, iter, newcolumn);
00213     }
00215     virtual JBLH1BankFloatFunInt& FloatFromInt (int newcolumn    
00216                                                ) const {
00217       return *new JBLH1BankFloatFunInt (ptr, iter, newcolumn);
00218     }
00219       
00221     virtual const FillIterator *getIterator() const { return &iter; }
00222   protected:
00224     virtual ~JBLH1BankIntFun() {}
00225   private:
00226     const H1BankPtr& ptr;              
00227     const FillIterator& iter;          
00228     int column;                        
00229 };
00230 
00231 
00233 
00240 template <class H1SomeBankPtr = H1BankPtr, class H1SomeRow = H1Row>
00241 class JBLH1SomeBankIterator: public FillIterator {
00242   public:
00244     JBLH1SomeBankIterator () 
00245       : FillIterator(),
00246         ptr (*new H1SomeBankPtr), 
00247         index (0)
00248       {    
00249         assert (&ptr); 
00250         setName(getH1PtrName(ptr));
00251       }
00253     explicit JBLH1SomeBankIterator (const char *name_        
00254                                    ) 
00255       : FillIterator(name_),
00256         ptr (*new H1SomeBankPtr(name_)), 
00257         index (0)
00258       {    
00259         assert (&ptr);   
00260       }
00262     explicit JBLH1SomeBankIterator (const H1SomeBankPtr& ptr_     
00263                                 ) 
00264       : FillIterator(getH1PtrName(ptr_)),
00265         ptr (ptr_), index (0)
00266       {    
00267         assert (&ptr);   
00268       }
00270     virtual int operator() () const {
00271       return index;
00272     }   
00274     virtual bool next() {
00275       return (++index < ptr.GetEntries());
00276     }
00278     virtual bool reset() {
00279       return ((index=0) < ptr.GetEntries());
00280     }
00282     virtual bool isValid() const {
00283       return index>=0 && index < ptr.GetEntries();
00284       
00285     }          
00287     virtual JBLH1BankFloatFun& GetFloat(int column,                 
00288                                         const char *attribname = 0  
00289                                        ) {
00290       return *new JBLH1BankFloatFun (ptr, *this, column, attribname);
00291     }
00292     
00294     template<class TM>
00295     JBLH1SomeBankFloatFun<H1SomeBankPtr, H1SomeRow, TM>& 
00296       GetFloat(TM (H1SomeRow::* ptr_mem)() const, 
00297                const char *attribname = 0         
00298                                        ) {
00299       return *new JBLH1SomeBankFloatFun<H1SomeBankPtr, H1SomeRow, TM> (ptr, *this, ptr_mem, attribname);
00300     }
00302     virtual JBLH1BankFloatFunInt& GetFloatFromInt (int column    
00303                                        ) {
00304       return *new JBLH1BankFloatFunInt (ptr, *this, column);
00305     }
00307     virtual JBLH1BankIntFun& GetInt(int column    
00308                                     ) {
00309       return *new JBLH1BankIntFun (ptr, *this, column);
00310     }
00311   
00312   protected:
00314     virtual ~JBLH1SomeBankIterator() {}
00315 
00316   private:
00317     // Data members
00318     const H1SomeBankPtr& ptr;    
00319     int index;               
00320 };
00321 
00322 typedef JBLH1SomeBankIterator<H1BankPtr, H1Row> JBLH1BankIterator;
00323 typedef JBLH1SomeBankIterator<H1DmisBankPtr, H1DmisRow> JBLH1DmisBankIterator;
00324 
00326 
00332 template <class H1SomeBankPtr = H1BankPtr, class H1SomeRow = H1Row>
00333 class JBLH1SomeBank {
00334   public:
00336     JBLH1SomeBank () 
00337       : ptr (*new H1SomeBankPtr)
00338       { 
00339         assert (&ptr); 
00340         name = getH1PtrName(ptr);
00341       }
00343     explicit JBLH1SomeBank (const char *name_         
00344                        ) 
00345       : ptr (*new H1SomeBankPtr(name_)), name (name_)
00346       {  
00347         assert (&ptr);  
00348       }
00350     explicit JBLH1SomeBank (const H1SomeBankPtr& ptr_     
00351                        ) 
00352       : ptr (ptr_)
00353       {  
00354         assert (&ptr);   
00355         name = getH1PtrName(ptr);
00356       }
00358     virtual JBLH1SomeBankIterator<H1SomeBankPtr, H1SomeRow>& iter() const { 
00359       return *new JBLH1SomeBankIterator<H1SomeBankPtr, H1SomeRow> (ptr); 
00360     }
00362     virtual const H1SomeBankPtr& getH1BankPtr() const {return ptr;}
00364     virtual const char *getName() const { return name.c_str(); }
00365   protected: 
00367     virtual ~JBLH1SomeBank() {}
00368   private:
00369     // Data members
00370     const H1SomeBankPtr& ptr;     
00371     std::string name;             
00372 };
00373 
00374 typedef JBLH1SomeBank<H1BankPtr, H1Row> JBLH1Bank;
00375 typedef JBLH1SomeBank<H1DmisBankPtr, H1DmisRow> JBLH1DmisBank;
00376 
00377 
00378 #endif /* #ifndef __H1BANKFUNS_H */ 

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