RdbStats.h

00001 #ifndef RdbStats_H
00002 #define RdbStats_H
00003 
00004 /* --8<--8<--8<--8<--
00005  *
00006  * Copyright (C) 2006 Smithsonian Astrophysical Observatory
00007  *
00008  * This file is part of rdbstats
00009  *
00010  * rdbstats is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU General Public License
00012  * as published by the Free Software Foundation; either version 2
00013  * of the License, or (at your option) any later version.
00014  *
00015  * rdbstats is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with this program; if not, write to the 
00022  *       Free Software Foundation, Inc. 
00023  *       51 Franklin Street, Fifth Floor
00024  *       Boston, MA  02110-1301, USA
00025  *
00026  * -->8-->8-->8-->8-- */
00027 
00028 #include <rdbxx/RDB.h>
00029 #include <cmath>                        // sqrt fabs
00030 
00031 using namespace std;
00032 
00038 class RdbStats {
00039 
00040 public:
00041 
00042   virtual ~RdbStats( ) throw( );
00043 
00044   RdbStats( RDB& irdbtable, const string& name ) throw( Exception );
00045 
00047   virtual int calculate_statistics( ) throw( );
00048 
00050   double get_absolute_average( ) const { return fabs( the_statistics[AVG] ); }
00051 
00052   virtual void init( ) throw( );
00053 
00054   virtual void normalize_results( const double norm ) throw( );
00055 
00056   virtual void set_output_columns( RDB& ordbtable ) throw( Exception );
00057 
00059   virtual void update_statistics( ) throw( Exception );
00060 
00061 private:
00062 
00063   // input_column is the input rdb column ptr. It is
00064   // allocated by the library so do not free the memory.
00065   RDBColumn* input_column;
00066 
00067   // The pointer to the output rdb columns.
00068   vector<RDBColumn*> output_stats;
00069 
00070 protected:
00071 
00072   enum Stats { AVG, MAX, MIN, SD, SUM, SUM2, SUM_T };
00073 
00074   double   num_n;
00075 
00076   string column_name;
00077 
00078   double the_statistics[ 7 ];
00079 
00080   double get_value( ) throw( Exception );
00081 
00082 };
00083 
00084 #endif