00001
00013 #ifndef LGR_H
00014 #define LGR_H
00015
00016 #include "bdmbase.h"
00017 #include "user_info.h"
00018
00019 namespace bdm {
00020 using std::string;
00021
00025 class memlog : public logger {
00026
00027 protected:
00029 int maxlen;
00031 int ind;
00033 Array<mat> vectors;
00035 string itfilename;
00036 public:
00037 memlog ( int maxlen0, string itf = "" ) : maxlen ( maxlen0 ), ind ( 0 ), vectors ( 0 ), itfilename ( itf ) {}
00038
00040 memlog() : maxlen ( 0 ), ind ( 0 ), vectors ( 0 ) {}
00041
00043 void init();
00044
00045 void step() {
00046 if ( ind < maxlen ) ind++;
00047 else bdm_error ( "memlog::ind is too high;" );
00048 }
00049
00050 void logit ( int id, const vec &v ) {
00051 bdm_assert_debug ( id < vectors.length(), "Logger was not initialized, run init()." );
00052 if ( id >= 0 ) {
00053 vectors ( id ).set_row ( ind, v );
00054 }
00055 }
00056 void logit ( int id, const double &d ) {
00057 bdm_assert_debug ( id < vectors.length(), "Logger was not initialized, run init()." );
00058 bdm_assert_debug ( vectors ( id ).cols() == 1, "Vector expected" );
00059 if ( id >= 0 ) {
00060 vectors ( id ) ( ind ) = d;
00061 }
00062 }
00064 void itsave ( const char* fname );
00066 void finalize() {
00067 if ( itfilename.length() > 0 ) itsave ( itfilename.c_str() );
00068 };
00069
00070
00083 void from_setting ( const Setting &set );
00084
00085
00086 };
00087
00088 UIREGISTER ( memlog );
00089 SHAREDPTR ( memlog );
00090
00091
00095 class stdlog: public memlog{
00096 public:
00098 stdlog():memlog(1){};
00099
00100 void init() {
00101 memlog::init();
00102 for (int i=0; i<entries.length();i++){
00103 if (entries(i)._dsize()==1) {
00104 cout << names(i) << entries(i).name(0) << "\t";
00105 }
00106 else
00107 for (int j=0; j<vectors(i).cols(); j++){
00108 cout << names(i) << entries(i).scalarname(j) << "\t";
00109 }
00110 }
00111 cout << endl;
00112
00113
00114 }
00116 void step() {
00117 for (int i=0; i<vectors.length();i++){
00118 for (int j=0; j<vectors(i).cols(); j++){
00119 cout << vectors(i)(0,j) << "\t";
00120 }
00121 }
00122 cout << endl;
00123 }
00134 void from_setting ( const Setting &set ){
00135 }
00136
00137 };
00138 UIREGISTER(stdlog);
00139
00147 class dirfilelog : public memlog {
00148
00149 protected:
00151 string dirname;
00153 Array<string> scalarnames;
00154 public:
00158 dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
00159
00160 dirfilelog() {}
00161
00163 void init();
00164 void step();
00165 void finalize();
00169 void write_buffers ( int Len );
00170
00180 void from_setting ( const Setting &set );
00181
00182
00183 };
00184
00185 UIREGISTER ( dirfilelog );
00186 SHAREDPTR ( dirfilelog );
00187
00188 };
00189 #endif // LGR_H