File indexing completed on 2025-01-30 10:22:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ROOT_Math_GenAlgoOptions
0012 #define ROOT_Math_GenAlgoOptions
0013
0014
0015 #include "Math/IOptions.h"
0016
0017 #include <map>
0018 #include <iomanip>
0019 #include <string>
0020 #include <vector>
0021
0022 namespace ROOT {
0023 namespace Math {
0024
0025
0026
0027
0028
0029
0030
0031
0032 class GenAlgoOptions : public IOptions {
0033
0034 public:
0035
0036 GenAlgoOptions() {}
0037
0038 ~GenAlgoOptions() override {}
0039
0040
0041
0042
0043
0044
0045
0046
0047 IOptions * Clone() const override {
0048 return new GenAlgoOptions(*this);
0049 }
0050
0051
0052
0053
0054 bool GetRealValue(const char * name, double & val) const override {
0055 const double * pval = FindValue(name, fRealOpts);
0056 if (!pval) return false;
0057 val = *pval;
0058 return true;
0059 }
0060
0061 bool GetIntValue(const char * name, int & val) const override {
0062 const int * pval = FindValue(name, fIntOpts);
0063 if (!pval) return false;
0064 val = *pval;
0065 return true;
0066 }
0067
0068 bool GetNamedValue(const char * name, std::string & val) const override {
0069 const std::string * pval = FindValue(name, fNamOpts);
0070 if (!pval) return false;
0071 val = *pval;
0072 return true;
0073 }
0074
0075
0076 void SetRealValue(const char * name, double val) override {
0077 InsertValue(name, fRealOpts, val);
0078 }
0079
0080 void SetIntValue(const char * name , int val) override {
0081 InsertValue(name, fIntOpts, val);
0082 }
0083
0084 void SetNamedValue(const char * name, const char * val) override {
0085 InsertValue(name, fNamOpts, std::string(val));
0086 }
0087
0088 std::vector<std::string> GetAllNamedKeys() {
0089 std::vector<std::string> names;
0090 names.reserve(fNamOpts.size());
0091
0092 for (auto const & e : fNamOpts)
0093 names.push_back(e.first);
0094 return names;
0095 }
0096 std::vector<std::string> GetAllRealKeys() {
0097 std::vector<std::string> names;
0098 names.reserve(fRealOpts.size());
0099
0100 for (auto const & e : fRealOpts)
0101 names.push_back(e.first);
0102 return names;
0103 }
0104 std::vector<std::string> GetAllIntKeys() {
0105 std::vector<std::string> names;
0106 names.reserve(fIntOpts.size());
0107
0108 for (auto const & e : fIntOpts)
0109 names.push_back(e.first);
0110 return names;
0111 }
0112
0113
0114 void Print(std::ostream & os = std::cout ) const override {
0115 Print(fNamOpts,os);
0116 Print(fIntOpts,os);
0117 Print(fRealOpts,os);
0118 }
0119
0120
0121
0122
0123
0124
0125 static IOptions * FindDefault(const char * algoname);
0126
0127
0128
0129 static IOptions & Default(const char * algoname);
0130
0131
0132 static void PrintAllDefault(std::ostream & os = std::cout);
0133
0134
0135 protected:
0136
0137
0138
0139 private:
0140
0141 template<class M>
0142 static const typename M::mapped_type * FindValue(const std::string & name, const M & opts) {
0143 typename M::const_iterator pos;
0144 pos = opts.find(name);
0145 if (pos == opts.end()) {
0146 return nullptr;
0147 }
0148 return &((*pos).second);
0149 }
0150
0151 template<class M>
0152 static void InsertValue(const std::string &name, M & opts, const typename M::mapped_type & value) {
0153 typename M::iterator pos;
0154 pos = opts.find(name);
0155 if (pos != opts.end()) {
0156 pos->second = value;
0157 }
0158 else {
0159 opts.insert(typename M::value_type(name, value) );
0160 }
0161 }
0162
0163 template<class M>
0164 static void Print( const M & opts, std::ostream & os) {
0165
0166 for (typename M::const_iterator pos = opts.begin(); pos != opts.end(); ++pos)
0167 os << std::setw(25) << pos->first << " : " << std::setw(15) << pos->second << std::endl;
0168 }
0169
0170 std::map<std::string, int> fIntOpts;
0171 std::map<std::string, double> fRealOpts;
0172 std::map<std::string, std::string> fNamOpts;
0173
0174 };
0175
0176
0177
0178 }
0179
0180 }
0181
0182 #endif