00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef ROOT_Math_GenAlgoOptions
00012 #define ROOT_Math_GenAlgoOptions
00013
00014
00015 #ifndef ROOT_Math_IOptions
00016 #include "Math/IOptions.h"
00017 #endif
00018
00019 #include <map>
00020 #include <iomanip>
00021
00022 namespace ROOT {
00023 namespace Math {
00024
00025
00026
00027
00028
00029
00030
00031
00032 class GenAlgoOptions : public IOptions {
00033
00034 public:
00035
00036 GenAlgoOptions() {}
00037
00038 virtual ~GenAlgoOptions() {}
00039
00040
00041
00042
00043
00044
00045
00046
00047 virtual IOptions * Clone() const {
00048 return new GenAlgoOptions(*this);
00049 }
00050
00051
00052
00053
00054 virtual bool GetRealValue(const char * name, double & val) const {
00055 const double * pval = FindValue(name, fRealOpts);
00056 if (!pval) return false;
00057 val = *pval;
00058 return true;
00059 }
00060
00061 virtual bool GetIntValue(const char * name, int & val) const {
00062 const int * pval = FindValue(name, fIntOpts);
00063 if (!pval) return false;
00064 val = *pval;
00065 return true;
00066 }
00067
00068 virtual bool GetNamedValue(const char * name, std::string & val) const {
00069 const std::string * pval = FindValue(name, fNamOpts);
00070 if (!pval) return false;
00071 val = *pval;
00072 return true;
00073 }
00074
00075
00076 virtual void SetRealValue(const char * name, double val) {
00077 InsertValue(name, fRealOpts, val);
00078 }
00079
00080 virtual void SetIntValue(const char * name , int val) {
00081 InsertValue(name, fIntOpts, val);
00082 }
00083
00084 virtual void SetNamedValue(const char * name, const char * val) {
00085 InsertValue(name, fNamOpts, std::string(val));
00086 }
00087
00088
00089
00090 virtual void Print(std::ostream & os = std::cout ) const {
00091 Print(fNamOpts,os);
00092 Print(fIntOpts,os);
00093 Print(fRealOpts,os);
00094 }
00095
00096
00097
00098
00099
00100
00101 static IOptions * FindDefault(const char * algoname);
00102
00103
00104
00105 static IOptions & Default(const char * algoname);
00106
00107
00108 static void PrintAllDefault(std::ostream & os = std::cout);
00109
00110
00111 protected:
00112
00113
00114
00115 private:
00116
00117 template<class M>
00118 static const typename M::mapped_type * FindValue(const std::string & name, const M & opts) {
00119 typename M::const_iterator pos;
00120 pos = opts.find(name);
00121 if (pos == opts.end()) {
00122 return 0;
00123 }
00124 return &((*pos).second);
00125 }
00126
00127 template<class M>
00128 static void InsertValue(const std::string &name, M & opts, const typename M::mapped_type & value) {
00129 typename M::iterator pos;
00130 pos = opts.find(name);
00131 if (pos != opts.end()) {
00132 pos->second = value;
00133 }
00134 else {
00135 opts.insert(typename M::value_type(name, value) );
00136 }
00137 }
00138
00139 template<class M>
00140 static void Print( const M & opts, std::ostream & os) {
00141
00142 for (typename M::const_iterator pos = opts.begin(); pos != opts.end(); ++pos)
00143 os << std::setw(25) << pos->first << " : " << std::setw(15) << pos->second << std::endl;
00144 }
00145
00146
00147 std::map<std::string, double> fRealOpts;
00148 std::map<std::string, int> fIntOpts;
00149 std::map<std::string, std::string> fNamOpts;
00150
00151 };
00152
00153
00154
00155 }
00156
00157 }
00158
00159 #endif