StatsResult.cc

00001 // File:  StatsResult.cc
00002 
00003 // --8<--8<--8<--8<--
00004 //
00005 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
00006 //
00007 // This file is part of rdbstats
00008 //
00009 // rdbstats is free software; you can redistribute it and/or
00010 // modify it under the terms of the GNU General Public License
00011 // as published by the Free Software Foundation; either version 2
00012 // of the License, or (at your option) any later version.
00013 //
00014 // rdbstats is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the 
00021 //       Free Software Foundation, Inc. 
00022 //       51 Franklin Street, Fifth Floor
00023 //       Boston, MA  02110-1301, USA
00024 //
00025 // -->8-->8-->8-->8--
00026 
00027 #define StatsResult_cc
00028 #include "StatsResult.h"
00029 
00030 template <class Type>
00031 StatsResult<Type>::StatsResult( Type& col, RDB& otable ) throw( Exception ) :
00032   rdb_stats_columns( col ), ordbtable( otable ) {
00033 
00034   try {
00035 
00036 #ifdef TRACEFCT
00037     TraceFct tf( "StatsResult<Type>::StatsResult( Type&, RDB& ) "
00038                  "throw( Exception )" );
00039 #endif
00040 
00041     // set_output_columns must be done here instead of within
00042     // the constructor of RdbStats is because stl calls the
00043     // ~RdbStats upon inserting an element in the vector container
00044     // which will lead the pointers of RdbStats to point to no man's land.
00045     for ( size_t ii = 0; ii < rdb_stats_columns.size( ); ii++ )
00046       rdb_stats_columns[ ii ].set_output_columns( ordbtable );
00047 
00048   } catch( Exception& e ) {
00049 
00050     throw;
00051 
00052   }
00053 
00054 }
00055 
00056 template <class Type>
00057 void StatsResult<Type>::calculate_statistics( ) throw( ) {
00058 
00059 #ifdef TRACEFCT
00060     TraceFct tf( "StatsResult<Type>::calculate_statistics(  ) throw( )" );
00061 #endif
00062 
00063   for ( size_t ii = 0; ii < rdb_stats_columns.size( ); ii++ )
00064       rdb_stats_columns[ ii ].calculate_statistics( ) ;
00065 
00066   //  ordbtable.advanceIdx( );
00067   ordbtable.write( );
00068 
00069   for ( size_t ii = 0; ii < rdb_stats_columns.size( ); ii++ )
00070     rdb_stats_columns[ ii ].init( );
00071 
00072 }
00073 
00074 template <class Type>
00075 void StatsResult<Type>::update_statistics( ) throw( Exception ) {
00076 
00077   try {
00078 
00079 #ifdef TRACEFCT
00080     TraceFct tf( "StatsResult<Type>::update_statistics(  ) throw( )" );
00081 #endif
00082 
00083     for ( size_t ii = 0; ii < rdb_stats_columns.size( ); ii++ )
00084       rdb_stats_columns[ ii ].update_statistics( );
00085 
00086   } catch ( Exception& e ) {
00087 
00088     throw;
00089 
00090   }
00091 
00092 }