Warning, file /include/root/TMVA/Configurable.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef ROOT_TMVA_Configurable
0028 #define ROOT_TMVA_Configurable
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #include "TNamed.h"
0039 #include "TList.h"
0040
0041 #include "TMVA/Option.h"
0042
0043 namespace TMVA {
0044
0045 class Configurable : public TNamed {
0046
0047 public:
0048
0049
0050 Configurable( const TString& theOption = "" );
0051
0052
0053 virtual ~Configurable();
0054
0055
0056 virtual void ParseOptions();
0057
0058
0059 void PrintOptions() const;
0060
0061 const char* GetConfigName() const { return GetName(); }
0062 const char* GetConfigDescription() const { return fConfigDescription; }
0063 void SetConfigName ( const char* n ) { SetName(n); }
0064 void SetConfigDescription( const char* d ) { fConfigDescription = TString(d); }
0065
0066
0067 template<class T>
0068 OptionBase* DeclareOptionRef( T& ref, const TString& name, const TString& desc = "" );
0069
0070 template<class T>
0071 OptionBase* DeclareOptionRef( T*& ref, Int_t size, const TString& name, const TString& desc = "" );
0072
0073
0074 template<class T>
0075 void AddPreDefVal(const T&);
0076
0077
0078 template<class T>
0079 void AddPreDefVal(const TString&optname ,const T&);
0080
0081
0082 void CheckForUnusedOptions() const;
0083
0084 const TString& GetOptions() const { return fOptions; }
0085 void SetOptions(const TString& s) { fOptions = s; }
0086
0087 void WriteOptionsToStream ( std::ostream& o, const TString& prefix ) const;
0088 void ReadOptionsFromStream( std::istream& istr );
0089
0090 void AddOptionsXMLTo( void* parent ) const;
0091 void ReadOptionsFromXML( void* node );
0092
0093 protected:
0094
0095 Bool_t LooseOptionCheckingEnabled() const { return fLooseOptionCheckingEnabled; }
0096 void EnableLooseOptions( Bool_t b = kTRUE ) { fLooseOptionCheckingEnabled = b; }
0097
0098 void WriteOptionsReferenceToFile();
0099
0100 void ResetSetFlag();
0101
0102 const TString& GetReferenceFile() const { return fReferenceFile; }
0103
0104 private:
0105
0106
0107 void SplitOptions(const TString& theOpt, TList& loo) const;
0108
0109 TString fOptions;
0110 Bool_t fLooseOptionCheckingEnabled;
0111
0112
0113 OptionBase* fLastDeclaredOption;
0114 TList fListOfOptions;
0115
0116 TString fConfigDescription;
0117 TString fReferenceFile;
0118
0119 public:
0120
0121
0122 MsgLogger& Log() const { return *fLogger; }
0123
0124
0125 void SetMsgType( EMsgType t ) { fLogger->SetMinType(t); }
0126
0127 protected:
0128 mutable MsgLogger* fLogger;
0129
0130 private:
0131
0132
0133 template <class T>
0134 void AssignOpt( const TString& name, T& valAssign ) const;
0135
0136 public:
0137
0138 ClassDefOverride(Configurable,1);
0139
0140 };
0141 }
0142
0143
0144
0145
0146 template <class T>
0147 TMVA::OptionBase* TMVA::Configurable::DeclareOptionRef( T& ref, const TString& name, const TString& desc)
0148 {
0149
0150 OptionBase* o = new Option<T>(ref, name, desc);
0151 fListOfOptions.Add(o);
0152 fLastDeclaredOption = o;
0153 return o;
0154 }
0155
0156 template <class T>
0157 TMVA::OptionBase* TMVA::Configurable::DeclareOptionRef( T*& ref, Int_t size, const TString& name, const TString& desc)
0158 {
0159
0160 OptionBase* o = new Option<T*>(ref, size, name, desc);
0161 fListOfOptions.Add(o);
0162 fLastDeclaredOption = o;
0163 return o;
0164 }
0165
0166
0167 template<class T>
0168 void TMVA::Configurable::AddPreDefVal(const T& val)
0169 {
0170
0171 Option<T>* oc = dynamic_cast<Option<T>*>(fLastDeclaredOption);
0172 if(oc) oc->AddPreDefVal(val);
0173 }
0174
0175
0176 template<class T>
0177 void TMVA::Configurable::AddPreDefVal(const TString &optname, const T& val)
0178 {
0179
0180
0181 TListIter optIt( &fListOfOptions );
0182 while (OptionBase * op = (OptionBase *) optIt()) {
0183 if (optname == TString(op->TheName())){
0184 Option<T>* oc = dynamic_cast<Option<T>*>(op);
0185 if(oc){
0186 oc->AddPreDefVal(val);
0187 return;
0188 }
0189 else{
0190 Log() << kFATAL << "Option \"" << optname
0191 << "\" was found, but somehow I could not convert the pointer properly.. please check the syntax of your option declaration" << Endl;
0192 return;
0193 }
0194
0195 }
0196 }
0197 Log() << kFATAL << "Option \"" << optname
0198 << "\" is not declared, hence cannot add predefined value, please check the syntax of your option declaration" << Endl;
0199
0200 }
0201
0202
0203 template <class T>
0204 void TMVA::Configurable::AssignOpt(const TString& name, T& valAssign) const
0205 {
0206
0207 TObject* opt = fListOfOptions.FindObject(name);
0208 if (opt!=0) valAssign = ((Option<T>*)opt)->Value();
0209 else
0210 Log() << kFATAL << "Option \"" << name
0211 << "\" not declared, please check the syntax of your option string" << Endl;
0212 }
0213
0214 #endif
0215