CLHEP  2.4.7.2
C++ Class Library for High Energy Physics
SymToArgAdaptor.icc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // $Id:
3 #include "SymToArgAdaptor.hh"
4 #include <assert.h>
5 #include <iostream>
6 #include <cfloat>
7 
8 namespace Genfun {
9 
10 
11 //FUNCTION_OBJECT_IMP(SymToArgAdaptor) Do it by hand here:
12 
13 template <class F>
14 inline
15 FunctionComposition SymToArgAdaptor<F>::operator()(const AbsFunction & function) const
16 {
17  return AbsFunction::operator() (function);
18 }
19 
20 template <class F>
21 inline
22 SymToArgAdaptor<F> *SymToArgAdaptor<F>::clone () const {
23  return (SymToArgAdaptor<F> *) _clone();
24 }
25 
26 template <class F>
27 inline
28 AbsFunction *SymToArgAdaptor<F>::_clone () const {
29  return new SymToArgAdaptor<F>(*this);
30 }
31 template <class F>
32 inline
33 ParameterComposition SymToArgAdaptor<F>::operator()(const AbsParameter & p) const
34 { \
35  return AbsFunction::operator() (p); \
36 }
37 
38 template<class F>
39 inline
40 SymToArgAdaptor<F>::SymToArgAdaptor(F &function,
41  const AbsFunction & f_expression,
42  SymToArgAdaptor<F>::ScopedMethodPtr parameterFetchMethod,
43  const AbsFunction * p_expression):
44 
45  _function(function.clone()),
46  _f_expression(f_expression.clone()),
47  _parameterFetchMethod(parameterFetchMethod),
48  _p_expression(p_expression->clone())
49 
50 {
51  _parameterFetchMethod(*_function).setLowerLimit(-DBL_MAX);
52  _parameterFetchMethod(*_function).setUpperLimit(+DBL_MAX);
53  assert(f_expression.dimensionality()==p_expression->dimensionality());
54 }
55 
56 template <class F>
57 inline
58 SymToArgAdaptor<F>::~SymToArgAdaptor() {
59  delete _function;
60  delete _f_expression;
61  delete _p_expression;
62 }
63 
64 template <class F>
65 inline
66 SymToArgAdaptor<F>::SymToArgAdaptor(const SymToArgAdaptor & right):
67  _function(right._function->clone()),
68  _f_expression(right._f_expression->clone()),
69  _parameterFetchMethod(right._parameterFetchMethod),
70  _p_expression(right._p_expression->clone())
71 {
72  _parameterFetchMethod(*_function).setLowerLimit(-DBL_MAX);
73  _parameterFetchMethod(*_function).setUpperLimit(+DBL_MAX);
74 }
75 
76 
77 template <class F>
78 inline
79 double SymToArgAdaptor<F>::operator ()(double x) const
80 {
81  std::cerr
82  << "Warning. SymToArgAdaptor called with scalar argument"
83  << std::endl;
84  assert(0);
85  return 0;
86 }
87 
88 template <class F>
89 inline
90 unsigned int SymToArgAdaptor<F>::dimensionality() const {
91  return _f_expression->dimensionality();
92 }
93 
94 template <class F>
95 inline
96 double SymToArgAdaptor<F>::operator() (const Argument & a) const {
97  if (dimensionality()!= a.dimension()) {
98  std::cerr
99  << "Warning: SymToArgAdaptor function/argument dimension mismatch"
100  << std::endl;
101  assert(0);
102  return 0;
103  }
104 
105  // First evaluate the sumbol.
106  double pVal= (*_p_expression)(a);
107 
108  // Then set the associated parameter:
109  (_parameterFetchMethod(*_function)).setValue(pVal);
110 
111  // Now evaluate the function:
112  return (*_function)((*_f_expression) (a));
113 }
114 } // end of namespace Genfun
115 
116 
Definition: Airy.icc:9