- 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 namespace bdm{
    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 void init(){};
    00058
    00060         virtual ~logger() {};
    00061 };
    00062
    00063
    00070 class memlog : public logger {
    00071
    00072 protected:
    00074         int maxlen;
    00076         int ind;
    00078         Array<mat> vectors;
    00080 public:
    00082         memlog ( int maxlen0 ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ) {}
    00084         void init() {
    00085                 int i; int n =entries.length();
    00086                 vectors.set_size ( n );
    00087                 for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i).count() );}
    00088                 ;
    00089         }
    00090         void step() {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );}
    00091         void logit ( int id, const vec &v ) {
    00092                 it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
    00093                 vectors ( id ).set_row ( ind,v );}
    00095         void itsave(const char* fname);
    00096 };
    00097
    00106 class dirfilelog : public memlog {
    00107
    00108 protected:
    00110         string dirname;
    00112         Array<string> scalarnames;
    00113 public:
    00117         dirfilelog ( std::string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
    00119         void init();
    00120         void step();
    00121         void finalize();
    00125         void write_buffers ( int Len );
    00126 };
    00127
    00128 }
    00129 #endif // LGR_H