- Main Page
- Related Pages
- Modules
- Classes
- Files

# work/git/mixpp/bdm/stat/loggers.h

Go to the documentation of this file.

    00001
    00013 #ifndef LGR_H
    00014 #define LGR_H
    00015
    00016 #include <itpp/itbase.h>
    00017 #include "libBM.h"
    00018 #include "../itpp_ext.h"
    00019
    00020 using namespace itpp;
    00021 using std::string;
    00022
    00028 class logger {
    00029 protected:
    00031         Array<RV> entries;
    00033         Array<string> names;
    00034 public:
    00036         logger ( ) : entries(0),names ( 0 ) {}
    00037
    00039         virtual int add (const RV &rv, string name="" ) {
    00040                 int id=entries.length();
    00041                 names=concat ( names, name ); // diff
    00042                 entries.set_length(id+1,true);
    00043                 entries(id)= rv;
    00044                 return id; // identifier of the last entry
    00045         }
    00046
    00048         virtual void logit ( int id, const vec &v ) =0;
    00049
    00051         virtual void step() =0;
    00052
    00054         virtual void finalize() {};
    00055
    00057         virtual ~logger() {};
    00058 };
    00059
    00060
    00067 class memlog : public logger {
    00068
    00069 protected:
    00071         int maxlen;
    00073         int ind;
    00075         Array<mat> vectors;
    00077 public:
    00079         memlog ( int maxlen0 ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ) {}
    00081         void init() {
    00082                 int i; int n =entries.length();
    00083                 vectors.set_size ( n );
    00084                 for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i).count() );}
    00085                 ;
    00086         }
    00087         void step() {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );}
    00088         void logit ( int id, const vec &v ) {
    00089                 it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
    00090                 vectors ( id ).set_row ( ind,v );}
    00092         void itsave(const char* fname);
    00093 };
    00094
    00103 class dirfilelog : public memlog {
    00104
    00105 protected:
    00107         string dirname;
    00109         Array<string> scalarnames;
    00110 public:
    00114         dirfilelog ( std::string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
    00116         void init();
    00117         void step();
    00118         void finalize();
    00122         void write_buffers ( int Len );
    00123 };
    00124
    00125
    00126 #endif // LGR_H