00001
00013 #ifndef LGR_H
00014 #define LGR_H
00015
00016 #include "libBM.h"
00017
00018 namespace bdm{
00019 using std::string;
00020
00026 class logger : public bdmroot{
00027 protected:
00029 Array<RV> entries;
00031 Array<string> names;
00032 public:
00034 logger ( ) : entries(0),names ( 0 ) {}
00035
00037 virtual int add (const RV &rv, string name="" ) {
00038 int id=entries.length();
00039 names=concat ( names, name );
00040 entries.set_length(id+1,true);
00041 entries(id)= rv;
00042 return id;
00043 }
00044
00046 virtual void logit ( int id, const vec &v ) =0;
00047
00049 virtual void step() =0;
00050
00052 virtual void finalize() {};
00053
00055 virtual void init(){};
00056
00058 virtual ~logger() {};
00059 };
00060
00061
00068 class memlog : public logger {
00069
00070 protected:
00072 int maxlen;
00074 int ind;
00076 Array<mat> vectors;
00078 public:
00080 memlog ( int maxlen0 ) : logger(),maxlen ( maxlen0 ),ind ( 0 ),vectors ( 0 ) {}
00082 void init() {
00083 int i; int n =entries.length();
00084 vectors.set_size ( n );
00085 for ( i=0;i<n;i++ ) {vectors(i).set_size (maxlen,entries(i).count() );}
00086 ;
00087 }
00088 void step() {if ( ind<maxlen ) ind++; else it_error ( "memlog::ind is too high;" );}
00089 void logit ( int id, const vec &v ) {
00090 it_assert_debug(id<vectors.length(),"Logger was not initialized, run init().");
00091 vectors ( id ).set_row ( ind,v );}
00093 void itsave(const char* fname);
00094 };
00095
00104 class dirfilelog : public memlog {
00105
00106 protected:
00108 string dirname;
00110 Array<string> scalarnames;
00111 public:
00115 dirfilelog ( std::string dirname0, int maxlen0 ) : memlog ( maxlen0 ), dirname ( dirname0 ), scalarnames ( 0 ) {}
00117 void init();
00118 void step();
00119 void finalize();
00123 void write_buffers ( int Len );
00124 };
00125
00126 }
00127 #endif // LGR_H