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:
00038         memlog ( int maxlen0, string itf = "" ) : maxlen ( maxlen0 ), ind ( 0 ), vectors ( 0 ), itfilename ( itf ) {}
00039 
00041         memlog() : maxlen ( 0 ), ind ( 0 ), vectors ( 0 ) {}
00042 
00044         void init();
00045 
00046         void step() {
00047                 if ( ind < maxlen ) ind++;
00048                 else bdm_error ( "memlog::ind is too high;" );
00049         }
00050 
00051         void logit ( int id, const vec &v ) {
00052                 bdm_assert ( id < vectors.length(), "Logger was not initialized, run init()." );
00053                 if ( id >= 0 ) {
00054                         vectors ( id ).set_row ( ind, v );
00055                 }
00056         }
00057         void logit ( int id, const double &d ) {
00058                 bdm_assert_debug ( id < vectors.length(), "Logger was not initialized, run init()." );
00059                 bdm_assert_debug ( vectors ( id ).cols() == 1, "Vector expected" );
00060                 if ( id >= 0 ) {
00061                         vectors ( id ) ( ind ) = d;
00062                 }
00063         }
00065         void itsave ( const char* fname );
00067         void finalize() {
00068                 if ( itfilename.length() > 0 ) itsave ( itfilename.c_str() );
00069         };
00070 
00071 
00084         void from_setting ( const Setting &set );
00085 
00086         
00087 };
00088 
00089 UIREGISTER ( memlog );
00090 SHAREDPTR ( memlog );
00091 
00092 
00096 class stdlog: public memlog{
00097         public:
00099                 stdlog():memlog(1){};
00100                 
00101                 void init() {
00102                         memlog::init();
00103                         for (int i=0; i<entries.length();i++){
00104                                 if (entries(i)._dsize()==1) {
00105                                         cout << names(i) << entries(i).name(0) << "\t";
00106                                 }
00107                                 else
00108                                 for (int j=0; j<vectors(i).cols(); j++){
00109                                         cout << names(i) << entries(i).scalarname(j) << "\t";
00110                                 }
00111                         }
00112                         cout << endl;
00113                         
00114                         
00115                 }
00117                 void step() {
00118                         for (int i=0; i<vectors.length();i++){
00119                                 for (int j=0; j<vectors(i).cols(); j++){
00120                                         cout << vectors(i)(0,j) << "\t";
00121                                 }
00122                         }
00123                         cout << endl;
00124                 }
00135                 void from_setting ( const Setting &set ){
00136                 }
00137                 
00138 };
00139 UIREGISTER(stdlog);
00140 
00148 class dirfilelog : public memlog {
00149 
00150 protected:
00152         string dirname;
00154         Array<string> scalarnames;
00155 public:
00159         dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
00160 
00161         dirfilelog() {}
00162 
00164         void init();
00165         void step();
00166         void finalize();
00170         void write_buffers ( int Len );
00171 
00181         void from_setting ( const Setting &set );
00182 
00183         
00184 };
00185 
00186 UIREGISTER ( dirfilelog );
00187 SHAREDPTR ( dirfilelog );
00188 
00189 };
00190 #endif // LGR_H