Logo ROOT  
Reference Guide
GenAlgoOptions.h
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Nov 2010
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2010 LCG ROOT Math Team, CERN/PH-SFT *
7  * *
8  * *
9  **********************************************************************/
10 
11 #ifndef ROOT_Math_GenAlgoOptions
12 #define ROOT_Math_GenAlgoOptions
13 
14 
15 #include "Math/IOptions.h"
16 
17 #include <map>
18 #include <iomanip>
19 #include <string>
20 
21 namespace ROOT {
22  namespace Math {
23 
24 //_______________________________________________________________________________
25 /**
26  class implementing generic options for a numerical algorithm
27  Just store the options in a map of string-value pairs
28 
29  @ingroup NumAlgo
30 */
31 class GenAlgoOptions : public IOptions {
32 
33 public:
34 
35  GenAlgoOptions() /* : fExtraOptions(0) */ {}
36 
37  virtual ~GenAlgoOptions() {}// { if (fExtraOptions) delete fExtraOptions; }
38 
39  // use default copy constructor and assignment operator
40 
41  /** generic methods for retrivieng options */
42 
43 
44  // methods implementing the IOptions interface
45 
46  virtual IOptions * Clone() const {
47  return new GenAlgoOptions(*this);
48  }
49 
50  // t.b.d need probably to implement in a .cxx file for CINT
51 
52 
53  virtual bool GetRealValue(const char * name, double & val) const {
54  const double * pval = FindValue(name, fRealOpts);
55  if (!pval) return false;
56  val = *pval;
57  return true;
58  }
59 
60  virtual bool GetIntValue(const char * name, int & val) const {
61  const int * pval = FindValue(name, fIntOpts);
62  if (!pval) return false;
63  val = *pval;
64  return true;
65  }
66 
67  virtual bool GetNamedValue(const char * name, std::string & val) const {
68  const std::string * pval = FindValue(name, fNamOpts);
69  if (!pval) return false;
70  val = *pval;
71  return true;
72  }
73 
74  /// method wich need to be re-implemented by the derived classes
75  virtual void SetRealValue(const char * name, double val) {
76  InsertValue(name, fRealOpts, val);
77  }
78 
79  virtual void SetIntValue(const char * name , int val) {
80  InsertValue(name, fIntOpts, val);
81  }
82 
83  virtual void SetNamedValue(const char * name, const char * val) {
84  InsertValue(name, fNamOpts, std::string(val));
85  }
86 
87 
88  /// print options
89  virtual void Print(std::ostream & os = std::cout ) const {
91  Print(fIntOpts,os);
92  Print(fRealOpts,os);
93  }
94 
95 
96  // static methods to retrieve the default options
97 
98  // find the option given a name
99  // return 0 if the option is not found
100  static IOptions * FindDefault(const char * algoname);
101 
102  // retrieve options given the name
103  // if option is not found create a new GenAlgoOption for the given name
104  static IOptions & Default(const char * algoname);
105 
106  /// print all the default options
107  static void PrintAllDefault(std::ostream & os = std::cout);
108 
109 
110 protected:
111 
112 
113 
114 private:
115 
116  template<class M>
117  static const typename M::mapped_type * FindValue(const std::string & name, const M & opts) {
118  typename M::const_iterator pos;
119  pos = opts.find(name);
120  if (pos == opts.end()) {
121  return 0;
122  }
123  return &((*pos).second);
124  }
125 
126  template<class M>
127  static void InsertValue(const std::string &name, M & opts, const typename M::mapped_type & value) {
128  typename M::iterator pos;
129  pos = opts.find(name);
130  if (pos != opts.end()) {
131  pos->second = value;
132  }
133  else {
134  opts.insert(typename M::value_type(name, value) );
135  }
136  }
137 
138  template<class M>
139  static void Print( const M & opts, std::ostream & os) {
140  //const std::ios_base::fmtflags prevFmt = os.flags();
141  for (typename M::const_iterator pos = opts.begin(); pos != opts.end(); ++pos)
142  os << std::setw(25) << pos->first << " : " << std::setw(15) << pos->second << std::endl;
143  }
144 
145 
146  std::map<std::string, double> fRealOpts; // map of the real options
147  std::map<std::string, int> fIntOpts; // map of the integer options
148  std::map<std::string, std::string> fNamOpts; // map of the named options
149 
150 };
151 
152 
153 
154  } // end namespace Math
155 
156 } // end namespace ROOT
157 
158 #endif
ROOT::Math::GenAlgoOptions::SetNamedValue
virtual void SetNamedValue(const char *name, const char *val)
Definition: GenAlgoOptions.h:98
ROOT::Math::GenAlgoOptions::PrintAllDefault
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
Definition: GenAlgoOptions.cxx:79
ROOT::Math::GenAlgoOptions::fNamOpts
std::map< std::string, std::string > fNamOpts
Definition: GenAlgoOptions.h:163
ROOT::Math::GenAlgoOptions::FindValue
static const M::mapped_type * FindValue(const std::string &name, const M &opts)
Definition: GenAlgoOptions.h:132
ROOT::Math::GenAlgoOptions::SetRealValue
virtual void SetRealValue(const char *name, double val)
method wich need to be re-implemented by the derived classes
Definition: GenAlgoOptions.h:90
ROOT::Math::GenAlgoOptions::GetRealValue
virtual bool GetRealValue(const char *name, double &val) const
Definition: GenAlgoOptions.h:68
ROOT::Math::GenAlgoOptions::fRealOpts
std::map< std::string, double > fRealOpts
Definition: GenAlgoOptions.h:161
IOptions.h
ROOT::Math::GenAlgoOptions::FindDefault
static IOptions * FindDefault(const char *algoname)
Definition: GenAlgoOptions.cxx:58
ROOT::Math::GenAlgoOptions::InsertValue
static void InsertValue(const std::string &name, M &opts, const typename M::mapped_type &value)
Definition: GenAlgoOptions.h:142
ROOT::Math::IOptions
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:41
ROOT::Math::GenAlgoOptions::fIntOpts
std::map< std::string, int > fIntOpts
Definition: GenAlgoOptions.h:162
ROOT::Math::GenAlgoOptions::Print
virtual void Print(std::ostream &os=std::cout) const
print options
Definition: GenAlgoOptions.h:104
ROOT::Math::GenAlgoOptions::GetNamedValue
virtual bool GetNamedValue(const char *name, std::string &val) const
Definition: GenAlgoOptions.h:82
ROOT::Math::GenAlgoOptions::~GenAlgoOptions
virtual ~GenAlgoOptions()
Definition: GenAlgoOptions.h:52
ROOT::Math::GenAlgoOptions::Default
static IOptions & Default(const char *algoname)
Definition: GenAlgoOptions.cxx:65
name
char name[80]
Definition: TGX11.cxx:110
ROOT::Math::GenAlgoOptions::GetIntValue
virtual bool GetIntValue(const char *name, int &val) const
Definition: GenAlgoOptions.h:75
ROOT::Math::GenAlgoOptions::SetIntValue
virtual void SetIntValue(const char *name, int val)
Definition: GenAlgoOptions.h:94
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
ROOT::Math::GenAlgoOptions::GenAlgoOptions
GenAlgoOptions()
Definition: GenAlgoOptions.h:50
ROOT::Math::GenAlgoOptions::Clone
virtual IOptions * Clone() const
generic methods for retrivieng options
Definition: GenAlgoOptions.h:61