// @(#)root/mathcore:$Id$
// Author: L. Moneta Fri Aug 15 2008

/**********************************************************************
 *                                                                    *
 * Copyright (c) 2008  LCG ROOT Math Team, CERN/PH-SFT                *
 *                                                                    *
 *                                                                    *
 **********************************************************************/

#ifndef ROOT_Math_IntegratorOptions
#define ROOT_Math_IntegratorOptions

#ifndef ROOT_Math_AllIntegrationTypes
#include "Math/AllIntegrationTypes.h"
#endif

#include <string>
#include <iostream>

namespace ROOT {


namespace Math {

   class IOptions;


//_______________________________________________________________________________
/**
    Base class for Numerical integration  options
    common in 1D and multi-dimension
    This is an internal class and is not supposed to be instantiated by the user

    @ingroup Integration
*/
class BaseIntegratorOptions {

protected:

   /// protected constructor to avoid user creating this class
   BaseIntegratorOptions();

public:

   // copy constructor
   BaseIntegratorOptions(const BaseIntegratorOptions & opt);

   /// assignment operators
   BaseIntegratorOptions & operator=(const BaseIntegratorOptions & opt);


   /// protected constructor to avoid user creating this class
   virtual ~BaseIntegratorOptions() { ClearExtra(); }


   /// name of 1D integrator
   virtual std::string  Integrator() const = 0;

   /** non-static methods for  retrivieng options */

   /// absolute tolerance
   double AbsTolerance() const { return  fAbsTolerance; }

   /// absolute tolerance
   double RelTolerance() const { return  fRelTolerance; }

   /// size of the workspace
   unsigned int WKSize() const { return fWKSize; }


   /// return extra options
   IOptions * ExtraOptions() const { return fExtraOptions; }

   /** non-static methods for setting options */


   /// set the abs tolerance
   void SetAbsTolerance(double tol) { fAbsTolerance = tol; }

   /// set the relative tolerance
   void SetRelTolerance(double tol) { fRelTolerance = tol; }

   /// set workspace size
   void SetWKSize(unsigned int size) { fWKSize = size; }

   /// set extra options (in this case pointer is cloned)
   void  SetExtraOptions(const IOptions & opt);


protected:

   void ClearExtra();

   int       fIntegType;   // Integrator type (value converted from enum)

   unsigned int fWKSize;        // workspace size
   unsigned int fNCalls;        // (max) funxtion calls
   double fAbsTolerance;        // absolute tolerance
   double fRelTolerance;        // relative tolerance


   // extra options
   ROOT::Math::IOptions *   fExtraOptions;  // extra options

};

//_______________________________________________________________________________
/**
    Numerical one dimensional integration  options

    @ingroup Integration
*/

class IntegratorOneDimOptions : public BaseIntegratorOptions {

public:


   // constructor using the default options
   // can pass a pointer to extra options (N.B. pointer will be managed by the class)
   IntegratorOneDimOptions(IOptions * extraOpts = 0);

   virtual ~IntegratorOneDimOptions() {}

   // copy constructor
   IntegratorOneDimOptions(const IntegratorOneDimOptions & rhs) :
      BaseIntegratorOptions(rhs)
   {}

   // assignment operator
   IntegratorOneDimOptions & operator=(const IntegratorOneDimOptions & rhs) {
      if (this == &rhs) return *this;
      static_cast<BaseIntegratorOptions &>(*this) = rhs;
      return *this;
   }

   // specific method for one-dim
   /// set number of points rule
   /// values of 1,2,3,4,5,6 corresponds to 15,21,31,41,51,61 and they are used in GSL adaptive
   /// values > 6 corresponds to the actual points and they are used by teh GaussLegendre integrator
   void SetNPoints(unsigned int n) { fNCalls = n; }

   /// maximum number of function calls
   unsigned int NPoints() const { return fNCalls; }

   /// name of 1D integrator
   std::string  Integrator() const;

   /// type of the integrator (return the enumeration type)
   IntegrationOneDim::Type IntegratorType() const { return (IntegrationOneDim::Type) fIntegType; }

   /// set 1D integrator name
   void SetIntegrator(const char * name);

   /// print all the options
   void Print(std::ostream & os = std::cout) const;

   // static methods for setting and retrieving the default options

   static void SetDefaultIntegrator(const char * name);
   static void SetDefaultAbsTolerance(double tol);
   static void SetDefaultRelTolerance(double tol);
   static void SetDefaultWKSize(unsigned int size);
   static void SetDefaultNPoints(unsigned int n);

   static std::string  DefaultIntegrator();
   static IntegrationOneDim::Type DefaultIntegratorType();
   static double DefaultAbsTolerance();
   static double DefaultRelTolerance();
   static unsigned int DefaultWKSize();
   static unsigned int DefaultNPoints();

   /// retrieve specific options - if not existing create a IOptions
   static ROOT::Math::IOptions & Default(const char * name);

   // find specific options - return 0 if not existing
   static ROOT::Math::IOptions * FindDefault(const char * name);

   /// print only the specified default options
   static void PrintDefault(const char * name = 0, std::ostream & os = std::cout);


private:


};

//_______________________________________________________________________________
/**
    Numerical multi dimensional integration  options

    @ingroup Integration
*/

class IntegratorMultiDimOptions : public BaseIntegratorOptions {

public:


   // constructor using the default options
   // can pass a pointer to extra options (N.B. pointer will be managed by the class)
   IntegratorMultiDimOptions(IOptions * extraOpts = 0);

   virtual ~IntegratorMultiDimOptions() {}

   // copy constructor
   IntegratorMultiDimOptions(const IntegratorMultiDimOptions & rhs) :
      BaseIntegratorOptions(rhs)
   {}

   // assignment operator
   IntegratorMultiDimOptions & operator=(const IntegratorMultiDimOptions & rhs) {
      if (this == &rhs) return *this;
      static_cast<BaseIntegratorOptions &>(*this) = rhs;
      return *this;
   }

   // specific method for multi-dim
   /// set maximum number of function calls
   void SetNCalls(unsigned int calls) { fNCalls = calls; }

   /// maximum number of function calls
   unsigned int NCalls() const { return fNCalls; }

   /// name of multi-dim integrator
   std::string  Integrator() const;

   /// type of the integrator (return the enumeration type)
   IntegrationMultiDim::Type IntegratorType() const { return (IntegrationMultiDim::Type) fIntegType; }

   /// set multi-dim integrator name
   void SetIntegrator(const char * name);

   /// print all the options
   void Print(std::ostream & os = std::cout) const;

   // static methods for setting and retrieving the default options

   static void SetDefaultIntegrator(const char * name);
   static void SetDefaultAbsTolerance(double tol);
   static void SetDefaultRelTolerance(double tol);
   static void SetDefaultWKSize(unsigned int size);
   static void SetDefaultNCalls(unsigned int ncall);

   static std::string DefaultIntegrator();
   static IntegrationMultiDim::Type DefaultIntegratorType();
   static double DefaultAbsTolerance();
   static double DefaultRelTolerance();
   static unsigned int DefaultWKSize();
   static unsigned int DefaultNCalls();

   // retrieve specific options
   static ROOT::Math::IOptions & Default(const char * name);

   // find specific options - return 0 if not existing
   static ROOT::Math::IOptions * FindDefault(const char * name);

   /// print only the specified default options
   static void PrintDefault(const char * name = 0, std::ostream & os = std::cout);


private:


};


   } // end namespace Math

} // end namespace ROOT

#endif
 IntegratorOptions.h:1
 IntegratorOptions.h:2
 IntegratorOptions.h:3
 IntegratorOptions.h:4
 IntegratorOptions.h:5
 IntegratorOptions.h:6
 IntegratorOptions.h:7
 IntegratorOptions.h:8
 IntegratorOptions.h:9
 IntegratorOptions.h:10
 IntegratorOptions.h:11
 IntegratorOptions.h:12
 IntegratorOptions.h:13
 IntegratorOptions.h:14
 IntegratorOptions.h:15
 IntegratorOptions.h:16
 IntegratorOptions.h:17
 IntegratorOptions.h:18
 IntegratorOptions.h:19
 IntegratorOptions.h:20
 IntegratorOptions.h:21
 IntegratorOptions.h:22
 IntegratorOptions.h:23
 IntegratorOptions.h:24
 IntegratorOptions.h:25
 IntegratorOptions.h:26
 IntegratorOptions.h:27
 IntegratorOptions.h:28
 IntegratorOptions.h:29
 IntegratorOptions.h:30
 IntegratorOptions.h:31
 IntegratorOptions.h:32
 IntegratorOptions.h:33
 IntegratorOptions.h:34
 IntegratorOptions.h:35
 IntegratorOptions.h:36
 IntegratorOptions.h:37
 IntegratorOptions.h:38
 IntegratorOptions.h:39
 IntegratorOptions.h:40
 IntegratorOptions.h:41
 IntegratorOptions.h:42
 IntegratorOptions.h:43
 IntegratorOptions.h:44
 IntegratorOptions.h:45
 IntegratorOptions.h:46
 IntegratorOptions.h:47
 IntegratorOptions.h:48
 IntegratorOptions.h:49
 IntegratorOptions.h:50
 IntegratorOptions.h:51
 IntegratorOptions.h:52
 IntegratorOptions.h:53
 IntegratorOptions.h:54
 IntegratorOptions.h:55
 IntegratorOptions.h:56
 IntegratorOptions.h:57
 IntegratorOptions.h:58
 IntegratorOptions.h:59
 IntegratorOptions.h:60
 IntegratorOptions.h:61
 IntegratorOptions.h:62
 IntegratorOptions.h:63
 IntegratorOptions.h:64
 IntegratorOptions.h:65
 IntegratorOptions.h:66
 IntegratorOptions.h:67
 IntegratorOptions.h:68
 IntegratorOptions.h:69
 IntegratorOptions.h:70
 IntegratorOptions.h:71
 IntegratorOptions.h:72
 IntegratorOptions.h:73
 IntegratorOptions.h:74
 IntegratorOptions.h:75
 IntegratorOptions.h:76
 IntegratorOptions.h:77
 IntegratorOptions.h:78
 IntegratorOptions.h:79
 IntegratorOptions.h:80
 IntegratorOptions.h:81
 IntegratorOptions.h:82
 IntegratorOptions.h:83
 IntegratorOptions.h:84
 IntegratorOptions.h:85
 IntegratorOptions.h:86
 IntegratorOptions.h:87
 IntegratorOptions.h:88
 IntegratorOptions.h:89
 IntegratorOptions.h:90
 IntegratorOptions.h:91
 IntegratorOptions.h:92
 IntegratorOptions.h:93
 IntegratorOptions.h:94
 IntegratorOptions.h:95
 IntegratorOptions.h:96
 IntegratorOptions.h:97
 IntegratorOptions.h:98
 IntegratorOptions.h:99
 IntegratorOptions.h:100
 IntegratorOptions.h:101
 IntegratorOptions.h:102
 IntegratorOptions.h:103
 IntegratorOptions.h:104
 IntegratorOptions.h:105
 IntegratorOptions.h:106
 IntegratorOptions.h:107
 IntegratorOptions.h:108
 IntegratorOptions.h:109
 IntegratorOptions.h:110
 IntegratorOptions.h:111
 IntegratorOptions.h:112
 IntegratorOptions.h:113
 IntegratorOptions.h:114
 IntegratorOptions.h:115
 IntegratorOptions.h:116
 IntegratorOptions.h:117
 IntegratorOptions.h:118
 IntegratorOptions.h:119
 IntegratorOptions.h:120
 IntegratorOptions.h:121
 IntegratorOptions.h:122
 IntegratorOptions.h:123
 IntegratorOptions.h:124
 IntegratorOptions.h:125
 IntegratorOptions.h:126
 IntegratorOptions.h:127
 IntegratorOptions.h:128
 IntegratorOptions.h:129
 IntegratorOptions.h:130
 IntegratorOptions.h:131
 IntegratorOptions.h:132
 IntegratorOptions.h:133
 IntegratorOptions.h:134
 IntegratorOptions.h:135
 IntegratorOptions.h:136
 IntegratorOptions.h:137
 IntegratorOptions.h:138
 IntegratorOptions.h:139
 IntegratorOptions.h:140
 IntegratorOptions.h:141
 IntegratorOptions.h:142
 IntegratorOptions.h:143
 IntegratorOptions.h:144
 IntegratorOptions.h:145
 IntegratorOptions.h:146
 IntegratorOptions.h:147
 IntegratorOptions.h:148
 IntegratorOptions.h:149
 IntegratorOptions.h:150
 IntegratorOptions.h:151
 IntegratorOptions.h:152
 IntegratorOptions.h:153
 IntegratorOptions.h:154
 IntegratorOptions.h:155
 IntegratorOptions.h:156
 IntegratorOptions.h:157
 IntegratorOptions.h:158
 IntegratorOptions.h:159
 IntegratorOptions.h:160
 IntegratorOptions.h:161
 IntegratorOptions.h:162
 IntegratorOptions.h:163
 IntegratorOptions.h:164
 IntegratorOptions.h:165
 IntegratorOptions.h:166
 IntegratorOptions.h:167
 IntegratorOptions.h:168
 IntegratorOptions.h:169
 IntegratorOptions.h:170
 IntegratorOptions.h:171
 IntegratorOptions.h:172
 IntegratorOptions.h:173
 IntegratorOptions.h:174
 IntegratorOptions.h:175
 IntegratorOptions.h:176
 IntegratorOptions.h:177
 IntegratorOptions.h:178
 IntegratorOptions.h:179
 IntegratorOptions.h:180
 IntegratorOptions.h:181
 IntegratorOptions.h:182
 IntegratorOptions.h:183
 IntegratorOptions.h:184
 IntegratorOptions.h:185
 IntegratorOptions.h:186
 IntegratorOptions.h:187
 IntegratorOptions.h:188
 IntegratorOptions.h:189
 IntegratorOptions.h:190
 IntegratorOptions.h:191
 IntegratorOptions.h:192
 IntegratorOptions.h:193
 IntegratorOptions.h:194
 IntegratorOptions.h:195
 IntegratorOptions.h:196
 IntegratorOptions.h:197
 IntegratorOptions.h:198
 IntegratorOptions.h:199
 IntegratorOptions.h:200
 IntegratorOptions.h:201
 IntegratorOptions.h:202
 IntegratorOptions.h:203
 IntegratorOptions.h:204
 IntegratorOptions.h:205
 IntegratorOptions.h:206
 IntegratorOptions.h:207
 IntegratorOptions.h:208
 IntegratorOptions.h:209
 IntegratorOptions.h:210
 IntegratorOptions.h:211
 IntegratorOptions.h:212
 IntegratorOptions.h:213
 IntegratorOptions.h:214
 IntegratorOptions.h:215
 IntegratorOptions.h:216
 IntegratorOptions.h:217
 IntegratorOptions.h:218
 IntegratorOptions.h:219
 IntegratorOptions.h:220
 IntegratorOptions.h:221
 IntegratorOptions.h:222
 IntegratorOptions.h:223
 IntegratorOptions.h:224
 IntegratorOptions.h:225
 IntegratorOptions.h:226
 IntegratorOptions.h:227
 IntegratorOptions.h:228
 IntegratorOptions.h:229
 IntegratorOptions.h:230
 IntegratorOptions.h:231
 IntegratorOptions.h:232
 IntegratorOptions.h:233
 IntegratorOptions.h:234
 IntegratorOptions.h:235
 IntegratorOptions.h:236
 IntegratorOptions.h:237
 IntegratorOptions.h:238
 IntegratorOptions.h:239
 IntegratorOptions.h:240
 IntegratorOptions.h:241
 IntegratorOptions.h:242
 IntegratorOptions.h:243
 IntegratorOptions.h:244
 IntegratorOptions.h:245
 IntegratorOptions.h:246
 IntegratorOptions.h:247
 IntegratorOptions.h:248
 IntegratorOptions.h:249
 IntegratorOptions.h:250
 IntegratorOptions.h:251
 IntegratorOptions.h:252
 IntegratorOptions.h:253
 IntegratorOptions.h:254
 IntegratorOptions.h:255
 IntegratorOptions.h:256
 IntegratorOptions.h:257
 IntegratorOptions.h:258
 IntegratorOptions.h:259
 IntegratorOptions.h:260
 IntegratorOptions.h:261
 IntegratorOptions.h:262
 IntegratorOptions.h:263
 IntegratorOptions.h:264
 IntegratorOptions.h:265
 IntegratorOptions.h:266
 IntegratorOptions.h:267
 IntegratorOptions.h:268
 IntegratorOptions.h:269
 IntegratorOptions.h:270
 IntegratorOptions.h:271
 IntegratorOptions.h:272
 IntegratorOptions.h:273