1 // @(#)root/minuit2:$Id$ 2 // Authors: M. Winkler, F. James, L. Moneta, A. Zsenei 2003-2005 3 4 /********************************************************************** 5 * * 6 * Copyright (c) 2005 LCG ROOT Math team, CERN/PH-SFT * 7 * * 8 **********************************************************************/ 9 10 #ifndef ROOT_Minuit2_ABObj 11 #define ROOT_Minuit2_ABObj 12 13 #include "Minuit2/ABTypes.h" 14 15 namespace ROOT { 16 17 namespace Minuit2 { 18 19 template <class mtype, class M, class T> 20 class ABObj { 21 22 public: 23 typedef mtype Type; 24 25 private: ABObj()26 ABObj() : fObject(M()), fFactor(T(0.)) {} 27 28 ABObj &operator=(const ABObj &) { return *this; } 29 30 template <class a, class b, class c> ABObj(const ABObj<a,b,c> &)31 ABObj(const ABObj<a, b, c> &) : fObject(M()), fFactor(T(0.)) 32 { 33 } 34 35 template <class a, class b, class c> 36 ABObj &operator=(const ABObj<a, b, c> &) 37 { 38 return *this; 39 } 40 41 public: ABObj(const M & obj)42 ABObj(const M &obj) : fObject(obj), fFactor(T(1.)) {} 43 ABObj(const M & obj,T factor)44 ABObj(const M &obj, T factor) : fObject(obj), fFactor(factor) {} 45 ~ABObj()46 ~ABObj() {} 47 ABObj(const ABObj & obj)48 ABObj(const ABObj &obj) : fObject(obj.fObject), fFactor(obj.fFactor) {} 49 50 template <class b, class c> ABObj(const ABObj<mtype,b,c> & obj)51 ABObj(const ABObj<mtype, b, c> &obj) : fObject(M(obj.Obj())), fFactor(T(obj.f())) 52 { 53 } 54 Obj()55 const M &Obj() const { return fObject; } 56 f()57 T f() const { return fFactor; } 58 59 private: 60 M fObject; 61 T fFactor; 62 }; 63 64 class LAVector; 65 template <> 66 class ABObj<vec, LAVector, double> { 67 68 public: 69 typedef vec Type; 70 71 private: 72 ABObj &operator=(const ABObj &) = delete; 73 74 public: ABObj(const LAVector & obj)75 ABObj(const LAVector &obj) : fObject(obj), fFactor(double(1.)) {} 76 ABObj(const LAVector & obj,double factor)77 ABObj(const LAVector &obj, double factor) : fObject(obj), fFactor(factor) {} 78 ~ABObj()79 ~ABObj() {} 80 81 // remove copy constructure to Fix a problem in AIX 82 // should be able to use the compiler generated one 83 // ABObj(const ABObj& obj) : 84 // fObject(obj.fObject), fFactor(obj.fFactor) {} 85 86 template <class c> ABObj(const ABObj<vec,LAVector,c> & obj)87 ABObj(const ABObj<vec, LAVector, c> &obj) : fObject(obj.fObject), fFactor(double(obj.fFactor)) 88 { 89 } 90 Obj()91 const LAVector &Obj() const { return fObject; } 92 f()93 double f() const { return fFactor; } 94 95 private: 96 const LAVector &fObject; 97 double fFactor; 98 }; 99 100 class LASymMatrix; 101 template <> 102 class ABObj<sym, LASymMatrix, double> { 103 104 public: 105 typedef sym Type; 106 107 private: 108 ABObj &operator=(const ABObj &) { return *this; } 109 110 public: ABObj(const LASymMatrix & obj)111 ABObj(const LASymMatrix &obj) : fObject(obj), fFactor(double(1.)) {} 112 ABObj(const LASymMatrix & obj,double factor)113 ABObj(const LASymMatrix &obj, double factor) : fObject(obj), fFactor(factor) {} 114 ~ABObj()115 ~ABObj() {} 116 ABObj(const ABObj & obj)117 ABObj(const ABObj &obj) : fObject(obj.fObject), fFactor(obj.fFactor) {} 118 119 template <class c> ABObj(const ABObj<vec,LASymMatrix,c> & obj)120 ABObj(const ABObj<vec, LASymMatrix, c> &obj) : fObject(obj.fObject), fFactor(double(obj.fFactor)) 121 { 122 } 123 Obj()124 const LASymMatrix &Obj() const { return fObject; } 125 f()126 double f() const { return fFactor; } 127 128 private: 129 const LASymMatrix &fObject; 130 double fFactor; 131 }; 132 133 // templated scaling operator * 134 template <class mt, class M, class T> 135 inline ABObj<mt, M, T> operator*(T f, const M &obj) 136 { 137 return ABObj<mt, M, T>(obj, f); 138 } 139 140 // templated operator / 141 template <class mt, class M, class T> 142 inline ABObj<mt, M, T> operator/(const M &obj, T f) 143 { 144 return ABObj<mt, M, T>(obj, T(1.) / f); 145 } 146 147 // templated unary operator - 148 template <class mt, class M, class T> 149 inline ABObj<mt, M, T> operator-(const M &obj) 150 { 151 return ABObj<mt, M, T>(obj, T(-1.)); 152 } 153 154 /* 155 // specialization for LAVector 156 157 inline ABObj<vec, LAVector, double> operator*(double f, const LAVector& obj) { 158 return ABObj<vec, LAVector, double>(obj, f); 159 } 160 161 inline ABObj<vec, LAVector, double> operator/(const LAVector& obj, double f) { 162 return ABObj<vec, LAVector, double>(obj, double(1.)/f); 163 } 164 165 inline ABObj<vec,LAVector,double> operator-(const LAVector& obj) { 166 return ABObj<vec,LAVector,double>(obj, double(-1.)); 167 } 168 */ 169 170 } // namespace Minuit2 171 172 } // namespace ROOT 173 174 #endif // ROOT_Minuit2_ABObj 175