- 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; int n =entries.length();
    00045                 vectors.set_size ( n );
    00046                 for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i)._dsize() );}
    00047         }
    00048         void step() {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );}
    00049         void logit ( int id, const vec &v ) {
    00050                 it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
    00051                 if(id>=0){ vectors ( id ).set_row ( ind,v );}
    00052         }
    00053         void logit ( int id, const double &d ) {
    00054                 it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
    00055                 it_assert_debug(vectors(id).cols()==1,"Vector expected");
    00056                 if(id>=0){ vectors ( id ) ( ind )=d;}
    00057         }
    00059         void itsave(const char* fname);
    00061         void finalize() {if (itfilename.length()>0) itsave(itfilename.c_str());};
    00062
    00063
    00076         void from_setting( const Setting &set );
    00077
    00078         // TODO dodelat void to_setting( Setting &set ) const;
    00079 };
    00080
    00081 UIREGISTER(memlog);
    00082
    00090 class dirfilelog : public memlog {
    00091
    00092 protected:
    00094         string dirname;
    00096         Array<string> scalarnames;
    00097 public:
    00101         dirfilelog ( string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
    00102
    00103         dirfilelog() {}
    00104
    00106         void init();
    00107         void step();
    00108         void finalize();
    00112         void write_buffers ( int Len );
    00113
    00123         void from_setting( const Setting &set );
    00124
    00125         // TODO dodelat void to_setting( Setting &set ) const;
    00126 };
    00127
    00128 UIREGISTER(dirfilelog);
    00129
    00130 };
    00131 #endif // LGR_H