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#include <vector>
21
22namespace ROOT {
23 namespace Math {
24
25//_______________________________________________________________________________
26/**
27 class implementing generic options for a numerical algorithm
28 Just store the options in a map of string-value pairs
29
30 @ingroup NumAlgo
31*/
32class GenAlgoOptions : public IOptions {
33
34public:
35
36 GenAlgoOptions() /* : fExtraOptions(0) */ {}
37
38 virtual ~GenAlgoOptions() {}// { if (fExtraOptions) delete fExtraOptions; }
39
40 // use default copy constructor and assignment operator
41
42 /** generic methods for retrivieng options */
43
44
45 // methods implementing the IOptions interface
46
47 virtual IOptions * Clone() const {
48 return new GenAlgoOptions(*this);
49 }
50
51 // t.b.d need probably to implement in a .cxx file for CINT
52
53
54 virtual bool GetRealValue(const char * name, double & val) const {
55 const double * pval = FindValue(name, fRealOpts);
56 if (!pval) return false;
57 val = *pval;
58 return true;
59 }
60
61 virtual bool GetIntValue(const char * name, int & val) const {
62 const int * pval = FindValue(name, fIntOpts);
63 if (!pval) return false;
64 val = *pval;
65 return true;
66 }
67
68 virtual bool GetNamedValue(const char * name, std::string & val) const {
69 const std::string * pval = FindValue(name, fNamOpts);
70 if (!pval) return false;
71 val = *pval;
72 return true;
73 }
74
75 /// method wich need to be re-implemented by the derived classes
76 virtual void SetRealValue(const char * name, double val) {
78 }
79
80 virtual void SetIntValue(const char * name , int val) {
82 }
83
84 virtual void SetNamedValue(const char * name, const char * val) {
85 InsertValue(name, fNamOpts, std::string(val));
86 }
87
88 std::vector<std::string> GetAllNamedKeys() {
89 std::vector<std::string> names;
90 names.reserve(fNamOpts.size());
91 // start by named options
92 for (auto const & e : fNamOpts)
93 names.push_back(e.first);
94 return names;
95 }
96 std::vector<std::string> GetAllRealKeys() {
97 std::vector<std::string> names;
98 names.reserve(fRealOpts.size());
99 // start by named options
100 for (auto const & e : fRealOpts)
101 names.push_back(e.first);
102 return names;
103 }
104 std::vector<std::string> GetAllIntKeys() {
105 std::vector<std::string> names;
106 names.reserve(fIntOpts.size());
107 // start by named options
108 for (auto const & e : fIntOpts)
109 names.push_back(e.first);
110 return names;
111 }
112
113 /// print options
114 virtual void Print(std::ostream & os = std::cout ) const {
115 Print(fNamOpts,os);
116 Print(fIntOpts,os);
117 Print(fRealOpts,os);
118 }
119
120
121 // static methods to retrieve the default options
122
123 // find the option given a name
124 // return 0 if the option is not found
125 static IOptions * FindDefault(const char * algoname);
126
127 // retrieve options given the name
128 // if option is not found create a new GenAlgoOption for the given name
129 static IOptions & Default(const char * algoname);
130
131 /// print all the default options
132 static void PrintAllDefault(std::ostream & os = std::cout);
133
134
135protected:
136
137
138
139private:
140
141 template<class M>
142 static const typename M::mapped_type * FindValue(const std::string & name, const M & opts) {
143 typename M::const_iterator pos;
144 pos = opts.find(name);
145 if (pos == opts.end()) {
146 return 0;
147 }
148 return &((*pos).second);
149 }
150
151 template<class M>
152 static void InsertValue(const std::string &name, M & opts, const typename M::mapped_type & value) {
153 typename M::iterator pos;
154 pos = opts.find(name);
155 if (pos != opts.end()) {
156 pos->second = value;
157 }
158 else {
159 opts.insert(typename M::value_type(name, value) );
160 }
161 }
162
163 template<class M>
164 static void Print( const M & opts, std::ostream & os) {
165 //const std::ios_base::fmtflags prevFmt = os.flags();
166 for (typename M::const_iterator pos = opts.begin(); pos != opts.end(); ++pos)
167 os << std::setw(25) << pos->first << " : " << std::setw(15) << pos->second << std::endl;
168 }
169
170 std::map<std::string, int> fIntOpts; // map of the integer options
171 std::map<std::string, double> fRealOpts; // map of the real options
172 std::map<std::string, std::string> fNamOpts; // map of the named options
173
174};
175
176
177
178 } // end namespace Math
179
180} // end namespace ROOT
181
182#endif
#define e(i)
Definition: RSha256.hxx:103
char name[80]
Definition: TGX11.cxx:110
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
std::map< std::string, double > fRealOpts
std::vector< std::string > GetAllRealKeys()
static void Print(const M &opts, std::ostream &os)
std::map< std::string, int > fIntOpts
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
static void InsertValue(const std::string &name, M &opts, const typename M::mapped_type &value)
virtual void Print(std::ostream &os=std::cout) const
print options
virtual void SetRealValue(const char *name, double val)
method wich need to be re-implemented by the derived classes
virtual void SetIntValue(const char *name, int val)
virtual bool GetIntValue(const char *name, int &val) const
virtual IOptions * Clone() const
generic methods for retrivieng options
static IOptions & Default(const char *algoname)
static const M::mapped_type * FindValue(const std::string &name, const M &opts)
static IOptions * FindDefault(const char *algoname)
std::vector< std::string > GetAllIntKeys()
std::map< std::string, std::string > fNamOpts
virtual void SetNamedValue(const char *name, const char *val)
std::vector< std::string > GetAllNamedKeys()
virtual bool GetNamedValue(const char *name, std::string &val) const
virtual bool GetRealValue(const char *name, double &val) const
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:31
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...