- 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:
    00038         memlog ( int maxlen0, string itf = "" ) : maxlen ( maxlen0 ), ind ( 0 ), vectors ( 0 ), itfilename ( itf ) {}
    00039
    00040         memlog() : ind ( 0 ), vectors ( 0 ) {}
    00041
    00043         void init() {
    00044                 int i;
    00045                 int n = entries.length();
    00046                 vectors.set_size ( n );
    00047                 for ( i = 0; i < n; i++ ) {
    00048                         vectors ( i ).set_size ( maxlen, entries ( i )._dsize() );
    00049                 }
    00050         }
    00051         void step() {
    00052                 if ( ind < maxlen ) ind++;
    00053                 else it_error ( "memlog::ind is too high;" );
    00054         }
    00055         void logit ( int id, const vec &v ) {
    00056                 it_assert_debug ( id < vectors.length(), "Logger was not initialized, run init()." );
    00057                 if ( id >= 0 ) {
    00058                         vectors ( id ).set_row ( ind, v );
    00059                 }
    00060         }
    00061         void logit ( int id, const double &d ) {
    00062                 it_assert_debug ( id < vectors.length(), "Logger was not initialized, run init()." );
    00063                 it_assert_debug ( vectors ( id ).cols() == 1, "Vector expected" );
    00064                 if ( id >= 0 ) {
    00065                         vectors ( id ) ( ind ) = d;
    00066                 }
    00067         }
    00069         void itsave ( const char* fname );
    00071         void finalize() {
    00072                 if ( itfilename.length() > 0 ) itsave ( itfilename.c_str() );
    00073         };
    00074
    00075
    00088         void from_setting ( const Setting &set );
    00089
    00090         // TODO dodelat void to_setting( Setting &set ) const;
    00091 };
    00092
    00093 UIREGISTER ( memlog );
    00094 SHAREDPTR ( memlog );
    00095
    00103 class dirfilelog : public memlog {
    00104
    00105 protected:
    00107         string dirname;
    00109         Array<string> scalarnames;
    00110 public:
    00114         dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
    00115
    00116         dirfilelog() {}
    00117
    00119         void init();
    00120         void step();
    00121         void finalize();
    00125         void write_buffers ( int Len );
    00126
    00136         void from_setting ( const Setting &set );
    00137
    00138         // TODO dodelat void to_setting( Setting &set ) const;
    00139 };
    00140
    00141 UIREGISTER ( dirfilelog );
    00142 SHAREDPTR ( dirfilelog );
    00143
    00144 };
    00145 #endif // LGR_H