00001 // @(#)root/mathmore:$Id: GSLMonteFunctionAdapter.h 21503 2007-12-19 17:34:54Z moneta $ 00002 // Authors: L. Moneta, 08/2007 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT * 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU General Public License * 00010 * as published by the Free Software Foundation; either version 2 * 00011 * of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this library (see file COPYING); if not, write * 00020 * to the Free Software Foundation, Inc., 59 Temple Place, Suite * 00021 * 330, Boston, MA 02111-1307 USA, or contact the author. * 00022 * * 00023 **********************************************************************/ 00024 00025 // Header file for class GSLMultiMinFunctionAdapter 00026 // 00027 // Generic adapter for gsl_multimin_function signature 00028 // usable for any c++ class which defines operator( ) 00029 // 00030 // Created by: Lorenzo Moneta at Fri Nov 12 16:58:51 2004 00031 // 00032 // Last update: Fri Nov 12 16:58:51 2004 00033 // 00034 #ifndef ROOT_Math_GSLMonteFunctionAdapter 00035 #define ROOT_Math_GSLMonteFunctionAdapter 00036 00037 00038 namespace ROOT { 00039 namespace Math { 00040 00041 00042 /** 00043 Class for adapting any multi-dimension C++ functor class to C function pointers used by 00044 GSL MonteCarlo integration algorithms. 00045 The templated C++ function class must implement: 00046 00047 <em> double operator( const double * x)</em> 00048 00049 This class defines static methods with will be used to fill the 00050 \a gsl_monte_function used by GSL. 00051 See for examples the 00052 <A HREF="http://www.gnu.org/software/gsl/manual/html_node/Monte-Carlo-Interface.html">GSL online manual</A> 00053 00054 @ingroup MCIntegration 00055 */ 00056 typedef double ( * GSLMonteFuncPointer ) ( double *, size_t, void *); 00057 00058 template<class UserFunc> 00059 struct GSLMonteFunctionAdapter { 00060 00061 static double F( double * x, size_t, void * p) { 00062 00063 UserFunc * function = reinterpret_cast< UserFunc *> (p); 00064 return (*function)( x ); 00065 } 00066 00067 }; 00068 00069 00070 00071 } // namespace Math 00072 } // namespace ROOT 00073 00074 00075 #endif /* ROOT_Math_GSLMonteFunctionAdapter */