Logo ROOT   6.08/07
Reference Guide
GSLFunctionWrapper.h
Go to the documentation of this file.
1 // @(#)root/mathmore:$Id$
2 // Authors: L. Moneta, A. Zsenei 08/2005
3 
4  /**********************************************************************
5  * *
6  * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7  * *
8  * This library is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License *
10  * as published by the Free Software Foundation; either version 2 *
11  * of the License, or (at your option) any later version. *
12  * *
13  * This library is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16  * General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this library (see file COPYING); if not, write *
20  * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21  * 330, Boston, MA 02111-1307 USA, or contact the author. *
22  * *
23  **********************************************************************/
24 
25 // Header file for class GSLFunctionWrapper
26 //
27 // Created by: moneta at Sat Nov 13 14:54:41 2004
28 //
29 // Last update: Sat Nov 13 14:54:41 2004
30 //
31 #ifndef ROOT_Math_GSLFunctionWrapper
32 #define ROOT_Math_GSLFunctionWrapper
33 
34 #include "gsl/gsl_math.h"
35 
37 
38 #include <cassert>
39 
40 namespace ROOT {
41 namespace Math {
42 
43 
44 
45 typedef double ( * GSLFuncPointer ) ( double, void *);
46 typedef void ( * GSLFdfPointer ) ( double, void *, double *, double *);
47 
48 
49 /**
50  Wrapper class to the gsl_function C structure.
51  This class to fill the GSL C structure gsl_function with
52  the C++ function objcet.
53  Use the class ROOT::Math::GSLFunctionAdapter to adapt the
54  C++ function object to the right signature (function pointer type)
55  requested by GSL
56 */
58 
59 public:
60 
62  {
63  fFunc.function = 0;
64  fFunc.params = 0;
65  }
66 
67  /// set in the GSL C struct the pointer to the function evaluation
68  void SetFuncPointer( GSLFuncPointer f) { fFunc.function = f; }
69 
70  /// set in the GSL C struct the extra-object pointer
71  void SetParams ( void * p) { fFunc.params = p; }
72 
73  /// fill the GSL C struct from a generic C++ callable object
74  /// implementing operator()
75  template<class FuncType>
76  void SetFunction(const FuncType &f) {
77  const void * p = &f;
78  assert (p != 0);
80  SetParams(const_cast<void *>(p));
81  }
82 
83  gsl_function * GetFunc() { return &fFunc; }
84 
85  GSLFuncPointer FunctionPtr() { return fFunc.function; }
86 
87  // evaluate the function
88  double operator() (double x) { return GSL_FN_EVAL(&fFunc, x); }
89 
90  /// check if function is valid (has been set)
91  bool IsValid() {
92  return (fFunc.function != 0) ? true : false;
93  }
94 
95 private:
97 
98 
99 };
100 
101 
102  /**
103  class to wrap a gsl_function_fdf (with derivatives)
104  */
106 
107  public:
108 
110  {
111  fFunc.f = 0;
112  fFunc.df = 0;
113  fFunc.fdf = 0;
114  fFunc.params = 0;
115  }
116 
117 
120  void SetFdfPointer( GSLFdfPointer f) { fFunc.fdf = f; }
121  void SetParams ( void * p) { fFunc.params = p; }
122 
123 
124  gsl_function_fdf * GetFunc() { return &fFunc; }
125 
126  // evaluate the function and derivatives
127  double operator() (double x) { return GSL_FN_FDF_EVAL_F(&fFunc, x); }
128 
129  double Derivative (double x) { return GSL_FN_FDF_EVAL_DF(&fFunc, x); }
130 
131  void Fdf(double x, double & f, double & df) {
132  return GSL_FN_FDF_EVAL_F_DF(&fFunc, x, &f, &df);
133  }
134 
135  /// check if function is valid (has been set)
136  bool IsValid() {
137  return (fFunc.f != 0 ) ? true : false;
138  }
139 
140  private:
141  gsl_function_fdf fFunc;
142 
143  };
144 
145 
146 
147 } // namespace Math
148 } // namespace ROOT
149 
150 #endif /* ROOT_Math_GSLFunctionWrapper */
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
bool IsValid()
check if function is valid (has been set)
class to wrap a gsl_function_fdf (with derivatives)
void SetFunction(const FuncType &f)
fill the GSL C struct from a generic C++ callable object implementing operator()
void Fdf(double x, double &f, double &df)
Double_t x[n]
Definition: legend1.C:17
#define GSL_FN_EVAL(F, x)
double(* GSLFuncPointer)(double, void *)
Function pointer corresponding to gsl_function signature.
Class for adapting any C++ functor class to C function pointers used by GSL.
bool IsValid()
check if function is valid (has been set)
double f(double x)
struct gsl_function_struct gsl_function
void SetFuncPointer(GSLFuncPointer f)
set in the GSL C struct the pointer to the function evaluation
Namespace for new Math classes and functions.
typedef void((*Func_t)())
Wrapper class to the gsl_function C structure.
void SetParams(void *p)
set in the GSL C struct the extra-object pointer
void(* GSLFdfPointer)(double, void *, double *, double *)