Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 ~GenAlgoOptions() override {}// { if (fExtraOptions) delete fExtraOptions; }
39
40 // use default copy constructor and assignment operator
41
42 /** generic methods for retrieving options */
43
44
45 // methods implementing the IOptions interface
46
47 IOptions * Clone() const override {
48 return new GenAlgoOptions(*this);
49 }
50
51 // t.b.d need probably to implement in a .cxx file for CINT
52
53
54 bool GetRealValue(const char * name, double & val) const override {
55 const double * pval = FindValue(name, fRealOpts);
56 if (!pval) return false;
57 val = *pval;
58 return true;
59 }
60
61 bool GetIntValue(const char * name, int & val) const override {
62 const int * pval = FindValue(name, fIntOpts);
63 if (!pval) return false;
64 val = *pval;
65 return true;
66 }
67
68 bool GetNamedValue(const char * name, std::string & val) const override {
69 const std::string * pval = FindValue(name, fNamOpts);
70 if (!pval) return false;
71 val = *pval;
72 return true;
73 }
74
75 /// Method that needs to be re-implemented by the derived classes.
76 void SetRealValue(const char * name, double val) override {
78 }
79
80 void SetIntValue(const char * name , int val) override {
82 }
83
84 void SetNamedValue(const char * name, const char * val) override {
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 void Print(std::ostream & os = std::cout ) const override {
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 nullptr;
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
char name[80]
Definition TGX11.cxx:110
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
void SetNamedValue(const char *name, const char *val) override
bool GetRealValue(const char *name, double &val) const override
std::map< std::string, double > fRealOpts
map of the real options
std::vector< std::string > GetAllRealKeys()
void SetIntValue(const char *name, int val) override
static void Print(const M &opts, std::ostream &os)
void SetRealValue(const char *name, double val) override
Method that needs to be re-implemented by the derived classes.
std::map< std::string, int > fIntOpts
map of the integer options
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
bool GetIntValue(const char *name, int &val) const override
static void InsertValue(const std::string &name, M &opts, const typename M::mapped_type &value)
IOptions * Clone() const override
generic methods for retrieving options
void Print(std::ostream &os=std::cout) const override
print 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()
bool GetNamedValue(const char *name, std::string &val) const override
std::map< std::string, std::string > fNamOpts
map of the named options
std::vector< std::string > GetAllNamedKeys()
Generic interface for defining configuration options of a numerical algorithm.
Definition IOptions.h:28
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...