Logo ROOT   6.14/05
Reference Guide
GenAlgoOptions.cxx
Go to the documentation of this file.
1 // @(#)root/mathcore:$Id$
2 // Author: L. Moneta Nov 2010
3 /**********************************************************************
4  * *
5  * Copyright (c) 2010 LCG ROOT Math Team, CERN/PH-SFT *
6  * *
7  * *
8  **********************************************************************/
9 
10 // implementation file for static methods of GenAlgoOptions
11 // this file contains also the pointer to the static std::map<algorithm name, options>
12 
13 #include "Math/GenAlgoOptions.h"
14 #include <cassert>
15 
16 // for toupper
17 #include <algorithm>
18 #include <functional>
19 #include <ctype.h> // need to use c version of tolower defined here
20 #include <string>
21 
22 namespace ROOT {
23 namespace Math {
24 
25 typedef std::map<std::string, ROOT::Math::GenAlgoOptions > OptionsMap;
26 
27 namespace GenAlgoOptUtil {
28 
29  // map with the generic options for all ROOT::Math numerical algorithm
30  static OptionsMap gAlgoOptions;
31 
32 
33  IOptions * DoFindDefault(std::string & algoname, OptionsMap & gOpts) {
34  // internal function to retrieve the
35  // default extra options for the given algorithm type
36  // return zero if not found
37  // store always name in upper case
38  std::transform(algoname.begin(), algoname.end(), algoname.begin(), (int(*)(int)) toupper );
39 
40  OptionsMap::iterator pos = gOpts.find(algoname);
41  if (pos != gOpts.end() ) {
42  return &(pos->second);
43  }
44  return 0;
45  }
46 }
47 
48  IOptions * GenAlgoOptions::FindDefault(const char * algo) {
49  // find default options - return 0 if not found
50  std::string algoname(algo);
51  OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions;
52  return GenAlgoOptUtil::DoFindDefault(algoname, gOpts);
53  }
54 
55  IOptions & GenAlgoOptions::Default(const char * algo) {
56  // create default extra options for the given algorithm type
57  std::string algoname(algo);
58  OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions;
59  IOptions * opt = GenAlgoOptUtil::DoFindDefault(algoname, gOpts);
60  if (opt == 0) {
61  // create new extra options for the given type
62  std::pair<OptionsMap::iterator,bool> ret = gOpts.insert( OptionsMap::value_type(algoname, ROOT::Math::GenAlgoOptions()) );
63  assert(ret.second);
64  opt = &((ret.first)->second);
65  }
66  return *opt;
67  }
68 
69  void GenAlgoOptions::PrintAllDefault(std::ostream & os) {
70  const OptionsMap & gOpts = GenAlgoOptUtil::gAlgoOptions;
71  for ( OptionsMap::const_iterator pos = gOpts.begin();
72  pos != gOpts.end(); ++pos) {
73  os << "Default specific options for algorithm " << pos->first << " : " << std::endl;
74  (pos->second).Print(os);
75  }
76  }
77 
78  } // end namespace Math
79 
80 } // end namespace ROOT
81 
std::map< std::string, ROOT::Math::GenAlgoOptions > OptionsMap
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
static OptionsMap gAlgoOptions
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
static constexpr double second
IOptions * DoFindDefault(std::string &algoname, OptionsMap &gOpts)
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
void Print(std::ostream &os, const OptionType &opt)
Namespace for new Math classes and functions.
static IOptions & Default(const char *algoname)
Generic interface for defining configuration options of a numerical algorithm.
Definition: IOptions.h:30
static IOptions * FindDefault(const char *algoname)