00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef ROOT_TMVA_Configurable
00028 #define ROOT_TMVA_Configurable
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef ROOT_TObject
00039 #include "TObject.h"
00040 #endif
00041 #ifndef ROOT_TList
00042 #include "TList.h"
00043 #endif
00044
00045 #ifndef ROOT_TMVA_Option
00046 #include "TMVA/Option.h"
00047 #endif
00048
00049 namespace TMVA {
00050
00051 class Configurable : public TObject {
00052
00053 public:
00054
00055
00056 Configurable( const TString& theOption = "" );
00057
00058
00059 virtual ~Configurable();
00060
00061
00062 virtual void ParseOptions();
00063
00064
00065 void PrintOptions() const;
00066
00067 virtual const char* GetName() const { return GetConfigName(); }
00068 const char* GetConfigName() const { return fConfigName; }
00069 const char* GetConfigDescription() const { return fConfigDescription; }
00070 void SetConfigName ( const char* n ) { fConfigName = TString(n); }
00071 void SetConfigDescription( const char* d ) { fConfigDescription = TString(d); }
00072
00073
00074 template<class T>
00075 OptionBase* DeclareOptionRef( T& ref, const TString& name, const TString& desc = "" );
00076
00077 template<class T>
00078 OptionBase* DeclareOptionRef( T*& ref, Int_t size, const TString& name, const TString& desc = "" );
00079
00080
00081 template<class T>
00082 void AddPreDefVal(const T&);
00083
00084 void CheckForUnusedOptions() const;
00085
00086 const TString& GetOptions() const { return fOptions; }
00087 void SetOptions(const TString& s) { fOptions = s; }
00088
00089 void WriteOptionsToStream ( std::ostream& o, const TString& prefix ) const;
00090 void ReadOptionsFromStream( istream& istr );
00091
00092 void AddOptionsXMLTo( void* parent ) const;
00093 void ReadOptionsFromXML( void* node );
00094
00095 protected:
00096
00097 Bool_t LooseOptionCheckingEnabled() const { return fLooseOptionCheckingEnabled; }
00098 void EnableLooseOptions( Bool_t b = kTRUE ) { fLooseOptionCheckingEnabled = b; }
00099
00100 void WriteOptionsReferenceToFile();
00101
00102 void ResetSetFlag();
00103
00104 const TString& GetReferenceFile() const { return fReferenceFile; }
00105
00106 private:
00107
00108
00109 void SplitOptions(const TString& theOpt, TList& loo) const;
00110
00111 TString fOptions;
00112 Bool_t fLooseOptionCheckingEnabled;
00113
00114
00115 OptionBase* fLastDeclaredOption;
00116 TList fListOfOptions;
00117
00118 TString fConfigName;
00119 TString fConfigDescription;
00120 TString fReferenceFile;
00121
00122 protected:
00123
00124
00125 MsgLogger& Log() const { return *fLogger; }
00126
00127 public:
00128
00129
00130 void SetMsgType( EMsgType t ) { fLogger->SetMinType(t); }
00131
00132
00133 private:
00134
00135 mutable MsgLogger* fLogger;
00136
00137 template <class T>
00138 void AssignOpt( const TString& name, T& valAssign ) const;
00139
00140 public:
00141
00142 ClassDef(Configurable,0)
00143
00144 };
00145 }
00146
00147
00148
00149
00150 template <class T>
00151 TMVA::OptionBase* TMVA::Configurable::DeclareOptionRef( T& ref, const TString& name, const TString& desc)
00152 {
00153
00154 OptionBase* o = new Option<T>(ref, name, desc);
00155 fListOfOptions.Add(o);
00156 fLastDeclaredOption = o;
00157 return o;
00158 }
00159
00160 template <class T>
00161 TMVA::OptionBase* TMVA::Configurable::DeclareOptionRef( T*& ref, Int_t size, const TString& name, const TString& desc)
00162 {
00163
00164 OptionBase* o = new Option<T*>(ref, size, name, desc);
00165 fListOfOptions.Add(o);
00166 fLastDeclaredOption = o;
00167 return o;
00168 }
00169
00170
00171 template<class T>
00172 void TMVA::Configurable::AddPreDefVal(const T& val)
00173 {
00174
00175 Option<T>* oc = dynamic_cast<Option<T>*>(fLastDeclaredOption);
00176 if(oc!=0) oc->AddPreDefVal(val);
00177 }
00178
00179
00180 template <class T>
00181 void TMVA::Configurable::AssignOpt(const TString& name, T& valAssign) const
00182 {
00183
00184 TObject* opt = fListOfOptions.FindObject(name);
00185 if (opt!=0) valAssign = ((Option<T>*)opt)->Value();
00186 else
00187 Log() << kFATAL << "Option \"" << name
00188 << "\" not declared, please check the syntax of your option string" << Endl;
00189 }
00190
00191 #endif
00192