Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:16

0001 // @(#)root/mathmore:$Id$
0002 // Authors: L. Moneta, A. Zsenei   08/2005
0003 
0004  /**********************************************************************
0005   *                                                                    *
0006   * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
0007   *                                                                    *
0008   * This library is free software; you can redistribute it and/or      *
0009   * modify it under the terms of the GNU General Public License        *
0010   * as published by the Free Software Foundation; either version 2     *
0011   * of the License, or (at your option) any later version.             *
0012   *                                                                    *
0013   * This library is distributed in the hope that it will be useful,    *
0014   * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
0015   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
0016   * General Public License for more details.                           *
0017   *                                                                    *
0018   * You should have received a copy of the GNU General Public License  *
0019   * along with this library (see file COPYING); if not, write          *
0020   * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
0021   * 330, Boston, MA 02111-1307 USA, or contact the author.             *
0022   *                                                                    *
0023   **********************************************************************/
0024 
0025 // Header file for class GSLFunctionAdapter
0026 //
0027 // Generic adapter for gsl_function signature
0028 // usable for any c++ class which defines operator( )
0029 //
0030 // Created by: Lorenzo Moneta  at Fri Nov 12 16:58:51 2004
0031 //
0032 // Last update: Fri Nov 12 16:58:51 2004
0033 //
0034 #ifndef ROOT_Math_GSLFunctionAdapter
0035 #define ROOT_Math_GSLFunctionAdapter
0036 
0037 
0038 namespace ROOT {
0039 namespace Math {
0040 
0041   /**
0042      Function pointer corresponding to gsl_function signature
0043    */
0044 
0045   typedef double ( * GSLFuncPointer ) ( double, void *);
0046 
0047 
0048   /**
0049      Class for adapting any C++ functor class to C function pointers used by GSL.
0050      The templated C++ function class must implement:
0051 
0052     <em> double operator( double x)</em>
0053     and if the derivatives are required:
0054     <em> double Gradient( double x)</em>
0055 
0056     This class defines static methods with will be used to fill the
0057     \a gsl_function and \a gsl_function_fdf structs used by GSL.
0058     See for examples the <A HREF="http://www.gnu.org/software/gsl/manual/gsl-ref_32.html#SEC432">GSL online manual</A>
0059   */
0060 
0061 
0062   template<class UserFunc>
0063   class GSLFunctionAdapter {
0064 
0065   public:
0066 
0067     GSLFunctionAdapter() {}
0068     virtual ~GSLFunctionAdapter() {}
0069 
0070     static double F( double x, void * p) {
0071 
0072       UserFunc * function = reinterpret_cast< UserFunc *> (p);
0073       return (*function)( x );
0074     }
0075 
0076 
0077     static double Df( double x, void * p) {
0078 
0079       UserFunc * function = reinterpret_cast< UserFunc *> (p);
0080       return (*function).Derivative( x );
0081     }
0082 
0083     static void Fdf( double x, void * p, double *f, double *df ) {
0084 
0085       UserFunc * function = reinterpret_cast< UserFunc *> (p);
0086       *f  = (*function) ( x );
0087       *df = (*function).Derivative( x );
0088     }
0089 
0090   };
0091 
0092 
0093 } // namespace Math
0094 } // namespace ROOT
0095 
0096 
0097 #endif /* ROOT_Math_GSLFunctionAdapter */