- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# loggers.h

Go to the documentation of this file.

    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         // TODO dodelat void to_setting( Setting &set ) const;
    00086 };
    00087
    00088 UIREGISTER ( memlog );
    00089 SHAREDPTR ( memlog );
    00090
    00098 class dirfilelog : public memlog {
    00099
    00100 protected:
    00102         string dirname;
    00104         Array<string> scalarnames;
    00105 public:
    00109         dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
    00110
    00111         dirfilelog() {}
    00112
    00114         void init();
    00115         void step();
    00116         void finalize();
    00120         void write_buffers ( int Len );
    00121
    00131         void from_setting ( const Setting &set );
    00132
    00133         // TODO dodelat void to_setting( Setting &set ) const;
    00134 };
    00135
    00136 UIREGISTER ( dirfilelog );
    00137 SHAREDPTR ( dirfilelog );
    00138
    00139 };
    00140 #endif // LGR_H