- Main Page
- Related Pages
- Classes
- Files

# work/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 ( 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, vec v ) =0;
    00049
    00051         virtual void step(bool final=false) =0;
    00052
    00054         virtual ~logger() {};
    00055 };
    00056
    00057
    00064 class memlog : public logger {
    00065
    00066 protected:
    00068         int maxlen;
    00070         int ind;
    00072         Array<mat> vectors;
    00074 public:
    00076         memlog ( int maxlen0 ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ) {}
    00078         void init() {
    00079                 int i; int n =entries.length();
    00080                 vectors.set_size ( n );
    00081                 for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i).count() );}
    00082                 ;
    00083         }
    00084         void step(bool final=false) {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );}
    00085         void logit ( int id, vec v ) {vectors ( id ).set_row ( ind,v );}
    00086         void itsave(const char* fname);
    00087 };
    00088
    00097 class dirfilelog : public memlog {
    00098
    00099 protected:
    00101         string dirname;
    00103         Array<string> scalarnames;
    00104 public:
    00108         dirfilelog ( std::string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
    00110         void init();
    00111         void step(bool final=false);
    00115         void write_buffers ( int Len );
    00116 };
    00117
    00118
    00119 #endif // LGR_H