|
NCBI C++ ToolKit
|
00001 /* $Id: presenter.hpp 38827 2008-08-04 17:33:15Z kans $ 00002 * =========================================================================== 00003 * 00004 * PUBLIC DOMAIN NOTICE 00005 * National Center for Biotechnology Information 00006 * 00007 * This software/database is a "United States Government Work" under the 00008 * terms of the United States Copyright Act. It was written as part of 00009 * the author's official duties as a United States Government employee and 00010 * thus cannot be copyrighted. This software/database is freely available 00011 * to the public for use. The National Library of Medicine and the U.S. 00012 * Government have not placed any restriction on its use or reproduction. 00013 * 00014 * Although all reasonable efforts have been taken to ensure the accuracy 00015 * and reliability of the software and data, the NLM and the U.S. 00016 * Government do not and cannot warrant the performance or results that 00017 * may be obtained by using this software or data. The NLM and the U.S. 00018 * Government disclaim all warranties, express or implied, including 00019 * warranties of performance, merchantability or fitness for any particular 00020 * purpose. 00021 * 00022 * Please cite the author in any work or product based on this material. 00023 * 00024 * =========================================================================== 00025 * 00026 * Author: 00027 * 00028 * File Description: 00029 * 00030 * =========================================================================== 00031 */ 00032 00033 #ifndef __presenter_hpp__ 00034 #define __presenter_hpp__ 00035 00036 // ============================================================================ 00037 class CSeqEntryPresenter 00038 // ============================================================================ 00039 { 00040 public: 00041 // ------------------------------------------------------------------------ 00042 CSeqEntryPresenter() 00043 // ------------------------------------------------------------------------ 00044 : m_process( 0 ) 00045 , m_run_time( 0 ) 00046 , m_process_time( 0 ) 00047 , m_diff_time( 0 ) 00048 , m_report_final( true ) 00049 , m_report_interval( 1000 ) 00050 , m_repeatitions( 1 ) 00051 {}; 00052 00053 // ------------------------------------------------------------------------ 00054 virtual ~CSeqEntryPresenter() 00055 // ------------------------------------------------------------------------ 00056 {}; 00057 00058 // ------------------------------------------------------------------------ 00059 virtual void Initialize( 00060 const CArgs& args ) 00061 // ------------------------------------------------------------------------ 00062 { 00063 m_report_final = args["rf"]; 00064 m_report_interval = args["ri"].AsInteger(); 00065 m_repeatitions = args["count"].AsInteger(); 00066 00067 m_meter.Restart(); 00068 }; 00069 00070 // ------------------------------------------------------------------------ 00071 virtual void Run( 00072 CSeqEntryProcess* process ) 00073 // ------------------------------------------------------------------------ 00074 { 00075 m_process = process; 00076 }; 00077 00078 // ------------------------------------------------------------------------ 00079 virtual void Finalize( 00080 const CArgs& args ) 00081 // ------------------------------------------------------------------------ 00082 { 00083 m_run_time = m_meter.Elapsed(); 00084 m_meter.Stop(); 00085 00086 if (m_report_final) { 00087 FinalReport(); 00088 } 00089 }; 00090 00091 // ------------------------------------------------------------------------ 00092 double GetDiffTime() const 00093 // ------------------------------------------------------------------------ 00094 { 00095 return m_diff_time; 00096 }; 00097 00098 // ------------------------------------------------------------------------ 00099 double GetProcessTime() const 00100 // ------------------------------------------------------------------------ 00101 { 00102 return m_process_time; 00103 }; 00104 00105 // ------------------------------------------------------------------------ 00106 double GetRunTime() const 00107 // ------------------------------------------------------------------------ 00108 { 00109 return m_run_time; 00110 }; 00111 00112 // ------------------------------------------------------------------------ 00113 virtual void Process( 00114 CRef< CSeq_entry >& se ) 00115 // ------------------------------------------------------------------------ 00116 { 00117 try { 00118 if ( m_process ) { 00119 m_process->SeqEntryInitialize( se ); 00120 00121 m_stopwatch.Restart(); 00122 00123 for ( int i=0; i < m_repeatitions; ++i ) { 00124 m_process->SeqEntryProcess(); 00125 } 00126 00127 if ( m_stopwatch.IsRunning() ) { 00128 double elapsed = m_stopwatch.Elapsed(); 00129 m_stopwatch.Stop(); 00130 m_process_time += elapsed; 00131 m_diff_time += elapsed; 00132 } 00133 00134 m_process->SeqEntryFinalize(); 00135 } 00136 } 00137 catch (CException& e) { 00138 LOG_POST(Error << "error processing seqentry: " << e.what()); 00139 } 00140 if ( m_report_interval && 00141 ! (m_process->GetObjectCount() % m_report_interval) ) 00142 { 00143 ProgressReport(); 00144 } 00145 }; 00146 00147 protected: 00148 // ------------------------------------------------------------------------ 00149 void ProgressReport() 00150 // ------------------------------------------------------------------------ 00151 { 00152 cerr << "-----------------------------------------------------" << endl; 00153 cerr << "Current object count : " << m_process->GetObjectCount() 00154 << endl; 00155 cerr << "Time since last report : " << GetDiffTime() 00156 << " secs" << endl; 00157 m_diff_time = 0; 00158 }; 00159 00160 // ------------------------------------------------------------------------ 00161 void FinalReport() 00162 // ------------------------------------------------------------------------ 00163 { 00164 cerr << "=====================================================" << endl; 00165 cerr << "Final object count : " << m_process->GetObjectCount() 00166 << endl; 00167 cerr << "Internal process time : " << GetProcessTime() 00168 << " secs" << endl; 00169 cerr << "Total running time : " << GetRunTime() 00170 << " secs" << endl; 00171 cerr << "=====================================================" << endl; 00172 }; 00173 00174 protected: 00175 CSeqEntryProcess* m_process; 00176 CStopWatch m_stopwatch; 00177 CStopWatch m_meter; 00178 double m_run_time; 00179 double m_process_time; 00180 double m_diff_time; 00181 bool m_report_final; 00182 int m_report_interval; 00183 int m_repeatitions; 00184 }; 00185 00186 #endif /* __presenter_hpp__ */ 00187
1.7.5.1
Modified on Wed May 23 13:03:20 2012 by modify_doxy.py rev. 337098