Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
22namespace ROOT {
23namespace Math {
24
25typedef std::map<std::string, ROOT::Math::GenAlgoOptions > OptionsMap;
26
27namespace GenAlgoOptUtil {
28
29 // map with the generic options for all ROOT::Math numerical algorithm
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 nullptr;
45 }
46}
47
49 // find default options - return 0 if not found
50 std::string algoname(algo);
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);
59 IOptions * opt = GenAlgoOptUtil::DoFindDefault(algoname, gOpts);
60 if (opt) return *opt;
61 // if not existing 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 if (ret.second) return gOpts[algoname];
64 return *opt;
65 }
66
67 void GenAlgoOptions::PrintAllDefault(std::ostream & os) {
69 for ( OptionsMap::const_iterator pos = gOpts.begin();
70 pos != gOpts.end(); ++pos) {
71 os << "Default specific options for algorithm " << pos->first << " : " << std::endl;
72 (pos->second).Print(os);
73 }
74 }
75
76 } // end namespace Math
77
78} // end namespace ROOT
79
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
static void PrintAllDefault(std::ostream &os=std::cout)
print all the default options
void Print(std::ostream &os=std::cout) const override
print options
static IOptions & Default(const char *algoname)
static IOptions * FindDefault(const char *algoname)
Generic interface for defining configuration options of a numerical algorithm.
Definition IOptions.h:28
Namespace for new Math classes and functions.
static OptionsMap gAlgoOptions
IOptions * DoFindDefault(std::string &algoname, OptionsMap &gOpts)
std::map< std::string, ROOT::Math::GenAlgoOptions > OptionsMap
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.