Changeset 281

Show
Ignore:
Timestamp:
02/24/09 14:13:23 (15 years ago)
Author:
smidl
Message:

new version of mpf_test for TR2245

Files:
6 added
1 removed
10 modified

Legend:

Unmodified
Added
Removed
  • Doxyfile

    r280 r281  
    177177# configuration options related to the LaTeX output 
    178178#--------------------------------------------------------------------------- 
    179 GENERATE_LATEX         = YES 
     179GENERATE_LATEX         = NO 
    180180LATEX_OUTPUT           = latex 
    181181LATEX_CMD_NAME         = latex 
  • bdm/estim/libPF.h

    r279 r281  
    3939        //! Observation model 
    4040        mpdf *obs; 
     41 
     42        //! \name Options 
     43        //!@{ 
     44 
     45        //! Log resampling times 
     46        bool opt_L_res; 
     47        //! Log all samples 
     48        bool opt_L_smp; 
     49        //!@} 
     50 
    4151public: 
    4252        //! \name Constructors 
    4353        //!@{ 
    4454        PF ( ) :est(), _w ( est._w() ),_samples ( est._samples() ) {}; 
    45         PF( mpdf *par0, mpdf *obs0, epdf *epdf0, int n0 ) : 
    46                         est ( ),_w ( est._w() ),_samples ( est._samples() )  
    47                         { par = par0; obs=obs0; est.set_parameters ( ones(n0),epdf0 ); }; 
    48         void set_parameters ( mpdf *par0, mpdf *obs0, int n0 )  
    49                         { par = par0; obs=obs0; n=n0; est.set_n(n);}; 
    50         void set_statistics (const vec w0, epdf *epdf0){est.set_parameters ( w0,epdf0 );}; 
     55        PF ( mpdf *par0, mpdf *obs0, epdf *epdf0, int n0 ) : 
     56                        est ( ),_w ( est._w() ),_samples ( est._samples() ) 
     57        { set_parameters ( par0,obs0,n0 ); set_statistics ( ones ( n0 ),epdf0 ); }; 
     58        void set_parameters ( mpdf *par0, mpdf *obs0, int n0 ) 
     59        { par = par0; obs=obs0; n=n0; est.set_n ( n );}; 
     60        void set_statistics ( const vec w0, epdf *epdf0 ) {est.set_parameters ( w0,epdf0 );}; 
    5161        //!@} 
    5262        //! Set posterior density by sampling from epdf0 
    5363        void set_est ( const epdf &epdf0 ); 
     64        void set_options(const string &opt){ 
     65                opt_L_res= ( s.find ( "logres" ) !=string::npos ); 
     66                opt_L_smp= ( s.find ( "logsmp" ) !=string::npos );               
     67        } 
    5468        void bayes ( const vec &dt ); 
    5569        //!access function 
     
    7690                Array<const epdf*> Coms; 
    7791        public: 
    78                 mpfepdf ( eEmp &E0) : 
     92                mpfepdf ( eEmp &E0 ) : 
    7993                                epdf ( ), E ( E0 ),  _w ( E._w() ), 
    8094                                Coms ( _w.length() ) { 
     
    8397                {_w ( i ) =wi; Coms ( i ) =ep;}; 
    8498 
    85                 void set_n(int n){E.set_n(n); Coms.set_length(n);} 
     99                void set_n ( int n ) {E.set_n ( n ); Coms.set_length ( n );} 
    86100                vec mean() const { 
    87101                        // ugly 
    88                         vec pom=zeros ( Coms(0)->dimension() ); 
     102                        vec pom=zeros ( Coms ( 0 )->dimension() ); 
    89103                        for ( int i=0; i<_w.length(); i++ ) {pom += Coms ( i )->mean() * _w ( i );} 
    90104                        return concat ( E.mean(),pom ); 
     
    93107                        // ugly 
    94108                        vec pom=zeros ( Coms ( 0 )->dimension() ); 
    95                         vec pom2=zeros (  Coms ( 0 )->dimension() ); 
     109                        vec pom2=zeros ( Coms ( 0 )->dimension() ); 
    96110                        for ( int i=0; i<_w.length(); i++ ) { 
    97111                                pom += Coms ( i )->mean() * _w ( i ); 
     
    106120        }; 
    107121 
    108         //! estimate joining PF.est with conditional 
     122        //! Density joining PF.est with conditional parts 
    109123        mpfepdf jest; 
    110124 
     125        //! Log means of BMs 
     126        bool opt_L_mea; 
     127         
    111128public: 
    112129        //! Default constructor. 
    113130        MPF ( mpdf *par0, mpdf *obs0, int n, const BM_T &BMcond0 ) : PF (), jest ( est ) { 
    114                 PF::set_parameters(par0,obs0,n); 
    115                 jest.set_n(n); 
     131                PF::set_parameters ( par0,obs0,n ); 
     132                jest.set_n ( n ); 
    116133                // 
    117134                //TODO test if rv and BMcond.rv are compatible. 
     
    141158                for ( int i=0;i<n;i++ ) {Bms[i]->condition ( _samples ( i ) );} 
    142159        } 
    143  
     160        void set_options(const string &opt){ 
     161                PF:set_options(opt); 
     162                opt_L_mea = ( s.find ( "logmeans" ) !=string::npos ); 
     163        } 
     164         
    144165        //!Access function 
    145166        BM* _BM ( int i ) {return Bms[i];} 
  • bdm/stat/libBM.h

    r279 r281  
    606606        //! @{ 
    607607 
    608         BM () :ll ( 0 ),evalll ( false ) {}; 
     608        BM () :ll ( 0 ),evalll ( true) {}; 
    609609        BM ( const BM &B ) :  drv ( B.drv ), ll ( B.ll ), evalll ( B.evalll ) {} 
    610610        //! Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually! 
  • bdm/stat/libEF.cpp

    r278 r281  
    270270void eEmp::set_parameters ( const vec &w0, const epdf* epdf0 ) { 
    271271        //it_assert_debug(rv==epdf0->rv(),"Wrong epdf0"); 
     272        dim = epdf0->dimension(); 
    272273        w=w0; 
    273274        w/=sum ( w0 );//renormalize 
  • bdm/stat/libEF.h

    r280 r281  
    690690        void set_samples ( const epdf* pdf0 ); 
    691691        //! Set sample 
    692         void set_n ( int n0, bool copy=true ) {w.set_size ( n0,copy );samples.set_size ( n0,copy );}; 
     692        void set_n ( int n0, bool copy=true ) {n=n0; w.set_size ( n0,copy );samples.set_size ( n0,copy );}; 
    693693        //! Potentially dangerous, use with care. 
    694694        vec& _w()  {return w;}; 
  • bdm/uibuilder.cpp

    r278 r281  
    11#include "uibuilder.h" 
    22 
    3 namespace bdm{ 
    4          
    5         //! global map of UIbulder names to instances of UIbuilders. Created by UIREGISTER macro 
     3namespace bdm { 
     4 
     5//! global map of UIbulder names to instances of UIbuilders. Created by UIREGISTER macro 
    66UImap __uimap__; 
    77 
    8 bdmroot* UIexternal::build(Setting &S) const{ 
     8bdmroot* UIexternal::build ( Setting &S ) const { 
    99        Config C; 
    1010        bdmroot* tmp; 
    11         try{ 
    12                 C.readFile((const char*)S["filename"]); 
    13         } catch (...){ 
    14                 it_error("File " + string((const char*)S["filename"]) + " not found or broken"); 
     11        try { 
     12                C.readFile ( ( const char* ) S["filename"] ); 
    1513        } 
    16         try {    
    17                 Setting& remS=C.lookup((const char*)S["path"]); 
    18                 UIbuild(remS,tmp); 
     14        catch ( ... ) { 
     15                it_error ( "File " + string ( ( const char* ) S["filename"] ) + " not found or broken" ); 
    1916        } 
    20         catch (...) { it_error("External field " + string(S.getPath()) + " not valid"); 
     17        try { 
     18                Setting& remS=C.lookup ( ( const char* ) S["path"] ); 
     19                UIbuild ( remS,tmp ); 
     20        } 
     21        catch ( ... ) { 
     22                it_error ( "External field " + string ( S.getPath() ) + " not valid" ); 
    2123        } 
    2224        return tmp; 
    2325}; 
    24 UIREGISTER(UIexternal); 
     26UIREGISTER ( UIexternal ); 
    2527 
    26 bdmroot* UIinternal::build(Setting &S) const{ 
     28bdmroot* UIinternal::build ( Setting &S ) const { 
    2729        bdmroot* tmp; 
    28         try {    
     30        try { 
    2931                Setting* Stmp = &S; 
    30                 do {Stmp=&(Stmp->getParent());} while (!Stmp->isRoot()); 
    31                 Setting& intS=Stmp->lookup((const char*)S["path"]); 
    32                 UIbuild(intS,tmp); 
     32                do {Stmp=& ( Stmp->getParent() );} 
     33                while ( !Stmp->isRoot() ); 
     34                Setting& intS=Stmp->lookup ( ( const char* ) S["path"] ); 
     35                UIbuild ( intS,tmp ); 
    3336        } 
    34         catch (...) { it_error("Internal field " + string(S.getPath()) + " not valid"); 
     37        catch ( ... ) { 
     38                it_error ( "Internal field " + string ( S.getPath() ) + " not valid" ); 
    3539        } 
    3640        return tmp; 
    3741}; 
    38 UIREGISTER(UIinternal); 
     42UIREGISTER ( UIinternal ); 
    3943 
    40         void UI_DBG ( Setting &S, const string &spc ) { 
    41                 const char *Name=S.getName(); 
    42                 if ( Name!=NULL ) {cout << spc << std::string ( Name );}; 
    43                 Setting::Type T=S.getType(); 
    44                 switch ( T ) { 
    45                         case Setting::TypeArray: 
    46                                 cout << endl; 
    47                                 for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );}; 
    48                                 break; 
    49                         case Setting::TypeList: 
    50                                 cout << endl; 
    51                                 for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );}; 
    52                                 break; 
    53                         case Setting::TypeGroup: 
    54                                 cout << endl; 
    55                                 for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );} 
    56                                 break; 
    57                         case Setting::TypeInt: 
    58                                 cout << " = "; 
    59                                 cout << int ( S ) <<endl; 
    60                                 break; 
    61                         case Setting::TypeFloat: 
    62                                 cout << " = "; 
    63                                 cout << double ( S ) <<endl; 
    64                                 break; 
    65                         case Setting::TypeString: 
    66                                 cout << " = "; 
    67                                 cout << ( const char* ) ( S ) <<endl; 
    68                                 break; 
    69                         case Setting::TypeBoolean: 
    70                                 cout << " = "; 
    71                                 cout << bool ( S ) <<endl; 
    72                                 break; 
    73                                 default: {cout << "?";}; 
    74                 } 
     44void UI_DBG ( Setting &S, const string &spc ) { 
     45        const char *Name=S.getName(); 
     46        if ( Name!=NULL ) {cout << spc << std::string ( Name );}; 
     47        Setting::Type T=S.getType(); 
     48        switch ( T ) { 
     49                case Setting::TypeArray: 
     50                        cout << endl; 
     51                        for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );}; 
     52                        break; 
     53                case Setting::TypeList: 
     54                        cout << endl; 
     55                        for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );}; 
     56                        break; 
     57                case Setting::TypeGroup: 
     58                        cout << endl; 
     59                        for ( int i=0;i<S.getLength();i++ ) {UI_DBG ( S[i], spc+" " );} 
     60                        break; 
     61                case Setting::TypeInt: 
     62                        cout << " = "; 
     63                        cout << int ( S ) <<endl; 
     64                        break; 
     65                case Setting::TypeFloat: 
     66                        cout << " = "; 
     67                        cout << double ( S ) <<endl; 
     68                        break; 
     69                case Setting::TypeString: 
     70                        cout << " = "; 
     71                        cout << ( const char* ) ( S ) <<endl; 
     72                        break; 
     73                case Setting::TypeBoolean: 
     74                        cout << " = "; 
     75                        cout << bool ( S ) <<endl; 
     76                        break; 
     77                default: {cout << "?";}; 
    7578        } 
     79} 
    7680 
    7781} 
  • bdm/uibuilder.h

    r278 r281  
    88namespace bdm { 
    99 
    10         using namespace libconfig; 
    11         using namespace std; 
     10using namespace libconfig; 
     11using namespace std; 
    1212 
    1313#define CHECK_UITYPE(S,Type) it_assert_debug(S.getType()==Setting::Type, string("Wrong input path \"")+string(S.getPath())+string("\"")); 
    1414#define UIREGISTER(UI) UI* UI##_global_instance = new UI(); 
    1515 
    16 #define UICATCH         catch ( SettingTypeException e ) {it_error ( "Setting " +string ( e.getPath() ) +" is of incorrect Type" );}    catch ( SettingNotFoundException e ) {it_error ( "Setting " + string ( e.getPath() ) +" was not found" );} 
     16//!Standard catches for UIs, use as: catch UICATCH 
     17#define UICATCH  ( SettingTypeException e ) {it_error ( "Setting " +string ( e.getPath() ) +" is of incorrect Type" );} catch ( SettingNotFoundException e ) {it_error ( "Setting " + string ( e.getPath() ) +" was not found" );} 
    1718 
    1819////////// GLOBAL VAriables 
    1920 
    20         class UIbuilder; 
     21class UIbuilder; 
    2122//! Internal structure mapping strings to UIBuilder objects 
    22         typedef map<const string, const UIbuilder*> UImap; 
    23         extern UImap __uimap__; 
    24  
    25         class UIFile : public Config { 
    26         public: 
    27                 UIFile ( const char * fname ) :Config() { 
    28                         try{Config::readFile ( fname );} 
    29                         catch ( FileIOException f ) {it_error ( "File " + string ( fname ) + " not found" );} 
    30                         catch ( ParseException& P ) { 
    31                                 char msg[200]; 
    32                                 sprintf ( msg,"Error in file %s  on line %d.", fname, P.getLine() ); 
    33                                 it_error ( msg ); 
    34                         } 
    35                 } 
    36         }; 
    37  
    38         /*!\brief Builds computational object from a UserInfo structure 
    39  
    40         Return value is a pointer to the created object (memory management issue?) 
    41         */ 
    42         class UIbuilder { 
    43         protected: 
    44                 const vec getvec ( Setting& S ) const { 
    45                         CHECK_UITYPE ( S,TypeArray ); 
    46                         vec tmp; 
    47                         tmp.set_size ( S.getLength() ); 
    48                         for ( int i=0;i<S.getLength();i++ ) { 
    49                                 switch ( S[i].getType() ) { 
    50                                         case Setting::TypeFloat : 
    51                                                 tmp[i]=double ( S[i] );break; 
    52                                         case Setting::TypeInt : 
    53                                                 tmp[i]=int ( S[i] );break; 
    54                                         case Setting::TypeBoolean : 
    55                                                 tmp[i]=bool ( S[i] );break; 
    56                                         default: it_error ( "libconfig error?" ); 
    57                                 } 
    58                         } 
    59                         return tmp; 
    60                 }; 
    61                 const mat getmat ( Setting& S , int ncols) const { 
    62                         CHECK_UITYPE ( S,TypeArray ); 
    63                         mat tmp; 
    64                         int nrows=S.getLength()/ncols; 
    65                         int r=0,c=0; 
    66                         tmp.set_size ( nrows, ncols ); 
    67                         // Build matrix row-wise 
    68                         for ( int i=0;i<S.getLength();i++ ) { 
    69                                 switch ( S[i].getType() ) { 
    70                                         case Setting::TypeFloat : 
    71                                                 tmp(r,c)=double ( S[i] );break; 
    72                                         case Setting::TypeInt : 
    73                                                 tmp(r,c)=int ( S[i] );break; 
    74                                         case Setting::TypeBoolean : 
    75                                                 tmp(r,c)=bool ( S[i] );break; 
    76                                         default: it_error ( "libconfig error?" ); 
    77                                 } 
    78                                 c++; if (c==ncols) {c=0;r++;} 
    79                         } 
    80                         return tmp; 
    81                 }; 
    82                 const ivec getivec ( Setting& S ) const { 
    83                         CHECK_UITYPE ( S,TypeArray ); 
    84                         ivec tmp; 
    85                         tmp.set_size ( S.getLength() ); 
    86                         for ( int i=0;i<S.getLength();i++ ) { 
    87                                 switch ( S[i].getType() ) { 
    88                                         case Setting::TypeFloat : 
    89                                                 tmp[i]=double ( S[i] );break; 
    90                                         case Setting::TypeInt : 
    91                                                 tmp[i]=int ( S[i] );break; 
    92                                         case Setting::TypeBoolean : 
    93                                                 tmp[i]=bool ( S[i] );break; 
    94                                         default: it_error ( "libconfig error?" ); 
    95                                 } 
    96                         } 
    97                         return tmp; 
    98                 }; 
    99                 const Array<string> get_as ( Setting& S ) const { 
    100                         CHECK_UITYPE ( S,TypeArray ); 
    101                         Array<string> tmp; 
    102                         tmp.set_size ( S.getLength() ); 
    103                         for ( int i=0;i<S.getLength();i++ ) {tmp(i)=(const char*)S[i];} 
    104                         return tmp; 
    105                 }; 
    106                 public: 
    107                 //!Constructor needs to be run only once macro UIREGISTER 
    108                 UIbuilder ( const string &typ ) {__uimap__.insert ( make_pair ( typ,this ) );} 
    109                 //! Function building the computational object 
    110                 virtual bdmroot* build ( Setting &S ) const =0; 
    111         }; 
    112  
    113         class UIexternal:public UIbuilder { 
    114         public: 
    115                 UIexternal() :UIbuilder ( "external" ) {} 
    116                 bdmroot* build ( Setting &S ) const; 
    117         }; 
    118  
    119         class UIinternal:public UIbuilder { 
    120         public: 
    121                 UIinternal() :UIbuilder ( "internal" ) {} 
    122                 bdmroot* build ( Setting &S ) const; 
    123         }; 
    124  
    125         //! [Debugging] Print values in current S to cout 
    126         void UI_DBG ( Setting &S, const string &spc ); 
     23typedef map<const string, const UIbuilder*> UImap; 
     24extern UImap __uimap__; 
     25 
     26class UIFile : public Config { 
     27public: 
     28        UIFile ( const char * fname ) :Config() { 
     29                try{Config::readFile ( fname );} 
     30                catch ( FileIOException f ) {it_error ( "File " + string ( fname ) + " not found" );} 
     31                catch ( ParseException& P ) { 
     32                        char msg[200]; 
     33                        sprintf ( msg,"Error in file %s  on line %d.", fname, P.getLine() ); 
     34                        it_error ( msg ); 
     35                } 
     36        } 
     37}; 
     38 
     39//! \name elem Elementary build functions 
     40//!@{ 
     41 
     42//! construct itpp::vec from Setting of type Array 
     43inline vec getvec ( Setting& S ) { 
     44        CHECK_UITYPE ( S,TypeArray ); 
     45        vec tmp; 
     46        tmp.set_size ( S.getLength() ); 
     47        for ( int i=0;i<S.getLength();i++ ) { 
     48                switch ( S[i].getType() ) { 
     49                        case Setting::TypeFloat : 
     50                                tmp[i]=double ( S[i] );break; 
     51                        case Setting::TypeInt : 
     52                                tmp[i]=int ( S[i] );break; 
     53                        case Setting::TypeBoolean : 
     54                                tmp[i]=bool ( S[i] );break; 
     55                        default: it_error ( "libconfig error?" ); 
     56                } 
     57        } 
     58        return tmp; 
     59}; 
     60 
     61//! construct itpp::mat from Setting of type Array, number of columns must be given 
     62inline mat getmat ( Setting& S , int ncols ) { 
     63        CHECK_UITYPE ( S,TypeArray ); 
     64        mat tmp; 
     65        int nrows=S.getLength() /ncols; 
     66        int r=0,c=0; 
     67        tmp.set_size ( nrows, ncols ); 
     68        // Build matrix row-wise 
     69        for ( int i=0;i<S.getLength();i++ ) { 
     70                switch ( S[i].getType() ) { 
     71                        case Setting::TypeFloat : 
     72                                tmp ( r,c ) =double ( S[i] );break; 
     73                        case Setting::TypeInt : 
     74                                tmp ( r,c ) =int ( S[i] );break; 
     75                        case Setting::TypeBoolean : 
     76                                tmp ( r,c ) =bool ( S[i] );break; 
     77                        default: it_error ( "libconfig error?" ); 
     78                } 
     79                c++; if ( c==ncols ) {c=0;r++;} 
     80        } 
     81        return tmp; 
     82}; 
     83 
     84//! construct itpp::ivec from Setting of type Array 
     85 
     86inline ivec getivec ( Setting& S ) { 
     87        CHECK_UITYPE ( S,TypeArray ); 
     88        ivec tmp; 
     89        tmp.set_size ( S.getLength() ); 
     90        for ( int i=0;i<S.getLength();i++ ) { 
     91                switch ( S[i].getType() ) { 
     92                        case Setting::TypeFloat : 
     93                                tmp[i]=double ( S[i] );break; 
     94                        case Setting::TypeInt : 
     95                                tmp[i]=int ( S[i] );break; 
     96                        case Setting::TypeBoolean : 
     97                                tmp[i]=bool ( S[i] );break; 
     98                        default: it_error ( "libconfig error?" ); 
     99                } 
     100        } 
     101        return tmp; 
     102}; 
     103 
     104//! construct itpp::Array<string> from Setting of type Array 
     105 
     106inline Array<string> get_as ( Setting& S ) { 
     107        CHECK_UITYPE ( S,TypeArray ); 
     108        Array<string> tmp; 
     109        tmp.set_size ( S.getLength() ); 
     110        for ( int i=0;i<S.getLength();i++ ) {tmp ( i ) = ( const char* ) S[i];} 
     111        return tmp; 
     112}; 
     113 
     114//!@} 
     115 
     116/*!\brief Builds computational object from a UserInfo structure 
     117 
     118Return value is a pointer to the created object (memory management issue?) 
     119*/ 
     120class UIbuilder { 
     121protected: 
     122public: 
     123        //!Constructor needs to be run only once macro UIREGISTER 
     124        UIbuilder ( const string &typ ) {__uimap__.insert ( make_pair ( typ,this ) );} 
     125        //! Function building the computational object 
     126        virtual bdmroot* build ( Setting &S ) const =0; 
     127}; 
     128 
     129/*! Recursive build of objects defined in external file 
     130 
     131\code  
     132{type="external"; 
     133filename="my_file.cfg";       // name of file from which to read 
     134path="system.profile.[0]";    // Path in the external file 
     135}; 
     136\endcode 
     137*/ 
     138class UIexternal:public UIbuilder { 
     139public: 
     140        UIexternal() :UIbuilder ( "external" ) {} 
     141        bdmroot* build ( Setting &S ) const; 
     142}; 
     143 
     144/*! Recursive build of objects defined in the same file 
     145 
     146\code  
     147{type="internal"; 
     148path="system.profile.[0]";    // Path from the root  
     149}; 
     150\endcode 
     151 */ 
     152class UIinternal:public UIbuilder { 
     153public: 
     154        UIinternal() :UIbuilder ( "internal" ) {} 
     155        bdmroot* build ( Setting &S ) const; 
     156}; 
     157 
     158//! [Debugging] Print values in current S to cout 
     159void UI_DBG ( Setting &S, const string &spc ); 
    127160 
    128161//! Prototype of a UI builder. Return value is by the second argument since it type checking via \c dynamic_cast. 
    129         template<class T> 
    130         void UIbuild ( Setting &S, T* &ret ) { 
    131                 CHECK_UITYPE ( S,TypeGroup ); 
    132                 // Check if field "type" is present, if not it is not a valid UI 
    133                 it_assert_debug ( S.exists ( "type" ), string ( S.getPath() ) +" is not a valid UI!" ); 
    134  
    135                 const string typ=S["type"]; 
    136                 // Find "type" in list of registred UI builders 
    137                 UImap::const_iterator iter = __uimap__.find ( typ ); 
    138                 if ( iter == __uimap__.end() ) { 
    139                         it_error ( "UI of type \"" + typ + "\" is not registered!" ); 
    140                 } 
    141  
    142                 //BUILD the result 
     162template<class T> 
     163void UIbuild ( Setting &S, T* &ret ) { 
     164        CHECK_UITYPE ( S,TypeGroup ); 
     165        // Check if field "type" is present, if not it is not a valid UI 
     166        it_assert_debug ( S.exists ( "type" ), string ( S.getPath() ) +" is not a valid UI!" ); 
     167 
     168        const string typ=S["type"]; 
     169        // Find "type" in list of registred UI builders 
     170        UImap::const_iterator iter = __uimap__.find ( typ ); 
     171        if ( iter == __uimap__.end() ) { 
     172                it_error ( "UI of type \"" + typ + "\" is not registered!" ); 
     173        } 
     174 
     175        //BUILD the result 
     176        try { 
     177                ret = dynamic_cast<T*> ( iter->second->build ( S ) ); 
     178        } 
     179        catch UICATCH 
     180}; 
     181 
     182//! Auxiliary function allowing recursivity in S (too complex, remove?) 
     183template<class T> 
     184void UIcall ( Setting &S, void ( *func ) ( Setting&, T ), T Tmp ) { 
     185        CHECK_UITYPE ( S,TypeGroup ); 
     186        // Check if field "type" is present, if not it is not a valid UI 
     187        it_assert_debug ( S.exists ( "type" ), string ( S.getPath() ) +" is not a valid UI!" ); 
     188 
     189        const string typ=S["type"]; 
     190        if ( typ=="internal" ) { 
    143191                try { 
    144                         ret = dynamic_cast<T*> ( iter->second->build ( S ) ); 
    145                 } 
    146                 UICATCH; 
    147         }; 
    148  
    149 //! Auxiliary function allowing recursivity in S (too complex, remove?) 
    150         template<class T> 
    151         void UIcall ( Setting &S, void ( *func ) ( Setting&, T ), T Tmp ) { 
    152                 CHECK_UITYPE ( S,TypeGroup ); 
    153                 // Check if field "type" is present, if not it is not a valid UI 
    154                 it_assert_debug ( S.exists ( "type" ), string ( S.getPath() ) +" is not a valid UI!" ); 
    155  
    156                 const string typ=S["type"]; 
    157                 if ( typ=="internal" ) { 
    158                         try { 
    159                                 Setting* Stmp = &S; 
    160                                 do {Stmp=& ( Stmp->getParent() );} 
    161                                 while ( !Stmp->isRoot() ); 
    162                                 Setting& intS=Stmp->lookup ( ( const char* ) S["path"] ); 
    163                                 func ( intS, Tmp ); // <======== calling func 
    164                                 return; 
    165                         } 
    166                         catch ( ... ) { 
    167                                 it_error ( "Internal field " + string ( S.getPath() ) + " not valid" ); 
    168                         } 
    169                 } 
    170                 if ( typ=="external" ) { 
    171                         UIFile C(S["filename"]); 
    172                         try { 
    173                                 func ( C.lookup ( ( const char* ) S["path"] ), Tmp ); 
    174                         } 
    175                         catch ( ... ) { 
    176                                 it_error ( "External field " + string ( S.getPath() ) + " not valid" ); 
    177                         } 
     192                        Setting* Stmp = &S; 
     193                        do {Stmp=& ( Stmp->getParent() );} 
     194                        while ( !Stmp->isRoot() ); 
     195                        Setting& intS=Stmp->lookup ( ( const char* ) S["path"] ); 
     196                        func ( intS, Tmp ); // <======== calling func 
    178197                        return; 
    179198                } 
    180  
    181                 // v======================= calling final func 
    182                 func ( S, Tmp ); 
    183         }; 
     199                catch ( ... ) { 
     200                        it_error ( "Internal field " + string ( S.getPath() ) + " not valid" ); 
     201                } 
     202        } 
     203        if ( typ=="external" ) { 
     204                UIFile C ( S["filename"] ); 
     205                try { 
     206                        func ( C.lookup ( ( const char* ) S["path"] ), Tmp ); 
     207                } 
     208                catch ( ... ) { 
     209                        it_error ( "External field " + string ( S.getPath() ) + " not valid" ); 
     210                } 
     211                return; 
     212        } 
     213 
     214        // v======================= calling final func 
     215        func ( S, Tmp ); 
     216}; 
    184217 
    185218} 
  • library/estimator.cpp

    r278 r281  
    7474                UIbuild ( F.lookup ( "estimator" ),E ); 
    7575        } 
    76         UICATCH; 
     76        catch UICATCH; 
    7777 
    7878        DS->log_add ( *L ); 
  • pmsm/CMakeLists.txt

    r280 r281  
    2323EXEC (sim pmsmsim) 
    2424EXEC (sim_var pmsmsim) 
     25 
     26add_subdirectory (TR2245) 
  • pmsm/pmsm_estim.cpp

    r280 r281  
    3535                } 
    3636        } 
    37         UICATCH; 
     37        catch UICATCH; 
    3838 
    3939        DS->log_add ( *L );