Index: library/bdm/base/bdmbase.h
===================================================================
--- library/bdm/base/bdmbase.h (revision 675)
+++ library/bdm/base/bdmbase.h (revision 676)
@@ -298,4 +298,61 @@
 RV concat ( const RV &rv1, const RV &rv2 );
 
+/*!
+@brief Class for storing results (and semi-results) of an experiment
+
+This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed.
+*/
+class logger : public root {
+	protected:
+		//! RVs of all logged variables.
+		Array<RV> entries;
+		//! Names of logged quantities, e.g. names of algorithm variants
+		Array<string> names;
+		//!separator of prefixes of entries
+		const string separator;
+	public:
+		//!Default constructor
+		logger(const string separator0) : entries ( 0 ), names ( 0 ), separator(separator0) {}
+		
+		//! returns an identifier which will be later needed for calling the \c logit() function
+		//! For empty RV it returns -1, this entry will be ignored by \c logit().
+		virtual int add ( const RV &rv, string prefix = "" ) {
+			int id;
+			if ( rv._dsize() > 0 ) {
+				id = entries.length();
+				names = concat ( names, prefix ); // diff
+				entries.set_length ( id + 1, true );
+				entries ( id ) = rv;
+			} else {
+				id = -1;
+			}
+			return id; // identifier of the last entry
+		}
+		
+		//! log this vector
+		virtual void logit ( int id, const vec &v ) {
+			bdm_error ( "Not implemented" );
+		};
+		//! log this double
+		virtual void logit ( int id, const double &d ) {
+			bdm_error ( "Not implemented" );
+		};
+		
+		//! Shifts storage position for another time step.
+		virtual void step() {
+			bdm_error ( "Not implemneted" );
+		};
+		
+		//! Finalize storing information
+		virtual void finalize() {};
+		
+		//! Initialize the storage
+		virtual void init() {};
+		
+		//!separator of prefixes for this logger
+		const string& prefix_sep() {return separator;}
+};
+
+
 //! Class representing function \f$f(x)\f$ of variable \f$x\f$ represented by \c rv
 class fnc : public root {
@@ -532,4 +589,24 @@
 		//bdm_assert_debug ( isnamed(), "" );
 		return rv;
+	}
+	//! store values of the epdf on the following levels:
+	//!  #1 mean
+	//!  #2 mean + lower & upper bound
+	void log_register(logger &L, const string &prefix){
+		RV r;
+		if ( isnamed() ) {
+			r = _rv();
+		} else {
+			r = RV ( "", dimension() );
+		};
+		root::log_register(L,prefix);
+		logrec->ids.set_size(3);
+		if (log_level >0){
+			logrec->ids(0) = logrec->L.add ( r, prefix + logrec->L.prefix_sep()+ "mean" );
+		}
+		if (log_level >1){
+			logrec->ids(1) = logrec->L.add ( r, prefix + logrec->L.prefix_sep()+ "lb" );
+			logrec->ids(2) = logrec->L.add ( r, prefix + logrec->L.prefix_sep()+ "ub" );
+		}
 	}
 	//!@}
@@ -861,56 +938,4 @@
 };
 
-/*!
-@brief Class for storing results (and semi-results) of an experiment
-
-This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed.
- */
-class logger : public root {
-protected:
-	//! RVs of all logged variables.
-	Array<RV> entries;
-	//! Names of logged quantities, e.g. names of algorithm variants
-	Array<string> names;
-public:
-	//!Default constructor
-	logger() : entries ( 0 ), names ( 0 ) {}
-
-	//! returns an identifier which will be later needed for calling the \c logit() function
-	//! For empty RV it returns -1, this entry will be ignored by \c logit().
-	virtual int add ( const RV &rv, string prefix = "" ) {
-		int id;
-		if ( rv._dsize() > 0 ) {
-			id = entries.length();
-			names = concat ( names, prefix ); // diff
-			entries.set_length ( id + 1, true );
-			entries ( id ) = rv;
-		} else {
-			id = -1;
-		}
-		return id; // identifier of the last entry
-	}
-
-	//! log this vector
-	virtual void logit ( int id, const vec &v ) {
-		bdm_error ( "Not implemented" );
-	};
-	//! log this double
-	virtual void logit ( int id, const double &d ) {
-		bdm_error ( "Not implemented" );
-	};
-
-	//! Shifts storage position for another time step.
-	virtual void step() {
-		bdm_error ( "Not implemneted" );
-	};
-
-	//! Finalize storing information
-	virtual void finalize() {};
-
-	//! Initialize the storage
-	virtual void init() {};
-
-};
-
 
 //! \brief Combines RVs from a list of mpdfs to a single one.
@@ -946,14 +971,12 @@
 		//!Description of output data
 		RV Yrv; //
-	//! Remember its own index in Logger L, [0=dt, 1=ut]
-	ivec LIDs;
 public:
 	//! default constructors
-		DS() : Drv(), Urv(),Yrv(), LIDs(2) {};
+		DS() : Drv(), Urv(),Yrv() {log_level=1;};
 
 	//! Returns maximum number of provided data, by default it is set to maximum allowed length, shorter DS should overload this method! See, MemDS.max_length().
 	virtual int max_length() {return std::numeric_limits< int >::max();}
 	//! Returns full vector of observed data=[output, input]
-	virtual void getdata ( vec &dt ) {
+	virtual void getdata ( vec &dt ) const {
 		bdm_error ( "abstract class" );
 	}
@@ -980,24 +1003,30 @@
 
 	//! Register DS for logging into logger L
-	virtual void log_add ( logger &L ) {
-		bdm_assert ( dtsize == Drv._dsize(), "invalid DS: dtsize (" + num2str ( dtsize ) + ") different from Drv " + num2str ( Drv._dsize() ) );
+	virtual void log_register (logger &L,  const string &prefix ) {
+		bdm_assert ( ytsize == Yrv._dsize(), "invalid DS: ytsize (" + num2str ( ytsize ) + ") different from Drv " + num2str ( Yrv._dsize() ) );
 		bdm_assert ( utsize == Urv._dsize(), "invalid DS: utsize (" + num2str ( utsize ) + ") different from Urv " + num2str ( Urv._dsize() ) );
 
-		LIDs(0) = L.add ( Drv, "" );
-		LIDs(1) = L.add ( Urv, "" );
+		root::log_register(L,prefix);
+		//we know that 
+		if (log_level >0){
+			logrec->ids.set_size(2);
+			logrec->ids(0) = logrec->L.add ( Yrv, "" );
+			logrec->ids(1) = logrec->L.add ( Urv, "" );
+		}
 	}
 	//! Register DS for logging into logger L
-	virtual void logit ( logger &L ) {
-		vec tmp ( Drv._dsize() + Urv._dsize() );
-		getdata ( tmp );
-		// d is first in getdata
-		L.logit ( LIDs(0), tmp.left ( Drv._dsize() ) );
-		// u follows after d in getdata
-		L.logit ( LIDs(1), tmp.mid ( Drv._dsize(), Urv._dsize() ) );
+	virtual void log_write ( ) const {
+		if (log_level >0) {
+			vec tmp ( Yrv._dsize() + Urv._dsize());
+			getdata ( tmp );
+			// d is first in getdata
+			logrec->L.logit ( logrec->ids(0), tmp.left ( Yrv._dsize() ) );
+			// u follows after d in getdata
+			logrec->L.logit ( logrec->ids(1), tmp.mid ( Yrv._dsize(), Urv._dsize() ) );
+		}
 	}
 	//!access function
 	virtual const RV& _drv() const {
-		//		return concat (Drv, Urv);// why!!!
-		return Drv;// why!!!
+		return Drv;
 	}
 	//!access function
@@ -1005,12 +1034,12 @@
 		return Urv;
 	}
-		//!access function
-		const RV& _yrv() const {
-			return Yrv;
-		}
+	//!access function
+	const RV& _yrv() const {
+		return Yrv;
+	}
 	//! set random variables
-		virtual void set_drv (const  RV &yrv, const RV &urv) {
-		    Yrv = yrv;
-			Drv = concat(yrv,urv);
+	virtual void set_drv (const  RV &yrv, const RV &urv) {
+		Yrv = yrv;
+		Drv = concat(yrv,urv);
 		Urv = urv;
 	}
@@ -1046,13 +1075,10 @@
 	//!  If true, the filter will compute likelihood of the data record and store it in \c ll . Set to false if you want to save computational time.
 	bool evalll;
+	
 public:
 	//! \name Constructors
 	//! @{
 
-	BM() : ll ( 0 ), evalll ( true ), LIDs ( 4 ), LFlags ( 4 ) {
-		LIDs = -1;/*empty IDs*/
-		LFlags = 0;
-		LFlags ( 0 ) = 1;  /*log only mean*/
-	};
+	BM() : ll ( 0 ), evalll ( true ) { };
 	BM ( const BM &B ) :  drv ( B.drv ), ll ( B.ll ), evalll ( B.evalll ) {}
 	//! \brief Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually!
@@ -1151,43 +1177,32 @@
 	//! Set boolean options from a string, recognized are: "logbounds,logll"
 	virtual void set_options ( const string &opt ) {
-		LFlags ( 0 ) = 1;
 		if ( opt.find ( "logbounds" ) != string::npos ) {
-			LFlags ( 1 ) = 1;
-			LFlags ( 2 ) = 1;
+			const_cast<epdf&>(posterior()).set_log_level(2) ;
+		} else {
+			const_cast<epdf&>(posterior()).set_log_level(1) ;
 		}
 		if ( opt.find ( "logll" ) != string::npos ) {
-			LFlags ( 3 ) = 1;
-		}
-	}
-	//! IDs of storages in loggers 4:[1=mean,2=lb,3=ub,4=ll]
-	ivec LIDs;
-
-	//! Flags for logging - same size as LIDs, each entry correspond to the same in LIDs
-	ivec LFlags;
+			log_level = 1;
+		}
+	}
+
 	//! Add all logged variables to a logger
-	virtual void log_add ( logger &L, const string &name = "" ) {
-		// internal
-		RV r;
-		if ( posterior().isnamed() ) {
-			r = posterior()._rv();
-		} else {
-			r = RV ( "est", posterior().dimension() );
-		};
-
-		// Add mean value
-		if ( LFlags ( 0 ) ) LIDs ( 0 ) = L.add ( r, name + "mean_" );
-		if ( LFlags ( 1 ) ) LIDs ( 1 ) = L.add ( r, name + "lb_" );
-		if ( LFlags ( 2 ) ) LIDs ( 2 ) = L.add ( r, name + "ub_" );
-		if ( LFlags ( 3 ) ) LIDs ( 3 ) = L.add ( RV ( "ll", 1 ), name );    //TODO: "local" RV
-	}
-	virtual void logit ( logger &L ) {
-		L.logit ( LIDs ( 0 ), posterior().mean() );
-		if ( LFlags ( 1 ) || LFlags ( 2 ) ) {  //if one of them is off, its LID==-1 and will not be stored
-			vec ub, lb;
-			posterior().qbounds ( lb, ub );
-			L.logit ( LIDs ( 1 ), lb );
-			L.logit ( LIDs ( 2 ), ub );
-		}
-		if ( LFlags ( 3 ) ) L.logit ( LIDs ( 3 ), ll );
+	//! Log levels two digits: xy where
+	//!  * y = 0/1 log-likelihood is to be logged
+	//!  * x = level of the posterior (typically 0/1/2 for nothing/mean/bounds)
+	virtual void log_register ( logger &L, const string &prefix = "" ) {
+		root::log_register(L,prefix);		
+
+		const_cast<epdf&>(posterior()).log_register(L, prefix+L.prefix_sep()+"apost"); 
+		
+		if ((log_level) > 0){
+			logrec->ids.set_size(1);
+			logrec->ids(0) = L.add(RV("ll",1), prefix+L.prefix_sep()+"ll");
+		}
+	}
+	//! Save results to the given logger, details of what is stored is configured by \c LIDs and \c options
+	virtual void log_write ( ) const {
+		posterior().log_write();
+		if (log_level >0) { logrec->L.logit ( logrec->ids ( 0 ), ll );}
 	}
 	//!@}
