source: Sophya/trunk/SophyaPI/PIext/nomtmatvecadapter.cc@ 2930

Last change on this file since 2930 was 2930, checked in by ansari, 19 years ago

Instanciation explicite Adapterde NamedObjMgr et enregsitrement pour la prise en charge des tableaux (TArray/TMatrix/TVector) de type <int_2> <uint_2> <int_8> - Reza 3/4/2006

File size: 9.8 KB
Line 
1#include "sopnamsp.h"
2#include "machdefs.h"
3#include <stdlib.h>
4#include <typeinfo>
5#include <iostream>
6#include <string>
7#include <complex>
8
9#include "datatype.h"
10
11#include "tvector.h"
12#include "objfitter.h"
13#include "nomtmatvecadapter.h"
14#include "piyfxdrw.h"
15#include "pitvmaad.h"
16
17#include "fioarr.h"
18#include "fitstarray.h"
19
20
21//----------------------------------------------------------------
22// Class Adaptateur d'objet (Pour NamedObjMgr) d'objet TMatrix<T>
23//----------------------------------------------------------------
24
25
26/* --Methode-- */
27template <class T>
28NOMAdapter_TMatrix<T>::NOMAdapter_TMatrix(TMatrix<T>* o)
29 : NObjMgrAdapter(o)
30{
31mMtx = o;
32}
33
34/* --Methode-- */
35template <class T>
36NOMAdapter_TMatrix<T>::~NOMAdapter_TMatrix()
37{
38}
39
40/* --Methode-- */
41template <class T>
42NObjMgrAdapter* NOMAdapter_TMatrix<T>::Clone(AnyDataObj* o)
43{
44TMatrix<T>* m = dynamic_cast<TMatrix<T> *>(o);
45if (m) return ( new NOMAdapter_TMatrix<T>(m) );
46return ( new NObjMgrAdapter(o) );
47}
48
49/* --Methode-- */
50template <class T>
51string NOMAdapter_TMatrix<T>::GetDataObjType()
52{
53string type = "TMatrix< ";
54
55TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
56if (v != NULL) type = "TVector< ";
57
58// type += DecodeTypeIdName(typeid(T).name());
59type += DataTypeInfo<T>::getTypeName();
60type += " > ";
61return(type);
62}
63
64/* --Methode-- */
65template <class T>
66AnyDataObj* NOMAdapter_TMatrix<T>::CloneDataObj(bool share)
67{
68if (mMtx == NULL) return(NULL);
69TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
70if (v != NULL) return( new TVector<T>(*v, share) );
71else return ( new TMatrix<T>(*mMtx, share) );
72}
73
74
75/* --Methode-- */
76template <class T>
77void NOMAdapter_TMatrix<T>::SavePPF(POutPersist& pos, string const & nom)
78{
79if (mMtx == NULL) return;
80TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
81if (v != NULL) {
82 FIO_TArray<T> fio(v);
83 fio.Write(pos, nom);
84 }
85else {
86 FIO_TArray<T> fio(mMtx);
87 fio.Write(pos, nom);
88 }
89}
90
91/* --Methode-- */
92template <class T>
93void NOMAdapter_TMatrix<T>::Print(ostream& os)
94{
95TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
96if (v != NULL) os << (*v);
97else os << (*mMtx);
98}
99
100/* --Methode-- */
101template <class T>
102PIDrawer* NOMAdapter_TMatrix<T>::GetDrawer(string & dopt)
103{
104TVector<T>* v = dynamic_cast<TVector<T> *>(mMtx);
105if (v == NULL) return(NULL);
106else {
107 dopt = "thinline " + dopt;
108 return( new PIYfXDrawer( new POTVectorAdapter<T>(v, false), NULL, true) );
109 }
110}
111
112/* --Methode-- */
113template <class T>
114P2DArrayAdapter* NOMAdapter_TMatrix<T>::Get2DArray(string &)
115{
116return ( new POTMatrixAdapter<T>(mMtx, false) );
117}
118
119/* --Methode-- */
120template <class T>
121NTupleInterface* NOMAdapter_TMatrix<T>::GetNTupleInterface(bool& adel)
122{
123adel = true;
124return( new NTupInt_TMatrix<T>(mMtx) );
125}
126
127
128/* --Methode-- */
129template <class T>
130GeneralFitData* NOMAdapter_TMatrix<T>::GetGeneralFitData(bool& adel
131 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
132 ,int i1,int i2,int j1,int j2)
133{
134adel = false;
135if(!mMtx) return(NULL);
136
137int nx,ny;
138TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
139
140if(vec) { // C'est un TVector
141 nx = vec->NElts();
142 ny = 1;
143} else {
144 nx = mMtx->NRows();
145 ny = mMtx->NCol();
146 if(nx<=0 || ny<=0) return(NULL);
147}
148
149i1 = (i1<0||i1>=nx)? 0: i1;
150i2 = (i2<0||i2>=nx||i2<i1)? nx-1: i2;
151j1 = (j1<0||j1>=ny)? 0: j1;
152j2 = (j2<0||j2>=ny||j2<j1)? ny-1: j2;
153
154GeneralFitData* mGData = NULL;
155
156if(vec) { // C'est un TVector
157 mGData = new GeneralFitData(1,(i2-i1+1),0);
158 adel = true;
159 for(int i=i1;i<=i2;i++) {
160 double x = (double) i;
161 double f = (*vec)(i);
162 double e = 1.;
163 e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
164 mGData->AddData1(x,f,e);
165 }
166} else {
167 mGData = new GeneralFitData(2,(i2-i1+1)*(j2-j1+1),0);
168 adel = true;
169 for(int i=i1;i<=i2;i++) for(int j=j1;j<=j2;j++) {
170 double x = (double) i;
171 double y = (double) j;
172 double f = (*mMtx)(i,j);
173 double e = 1.;
174 e = GeneralFitData::ComputeError(f,e,errtype,errscale,errmin);
175 mGData->AddData2(x,y,f,e);
176 }
177}
178
179return mGData;
180}
181
182template <class T>
183AnyDataObj* NOMAdapter_TMatrix<T>::FitResidusObj(GeneralFit& mfit)
184{
185TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
186if(vec) {
187 TVector<T>* v = new TVector<T>(ObjectFitter::FitResidus(*vec,mfit),true);
188 return v;
189} else {
190 TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitResidus(*mMtx,mfit),true);
191 return m;
192}
193}
194
195template <class T>
196AnyDataObj* NOMAdapter_TMatrix<T>::FitFunctionObj(GeneralFit& mfit)
197{
198TVector<T>* vec = dynamic_cast<TVector<T> *>(mMtx);
199if(vec) {
200 TVector<T>* v = new TVector<T>(ObjectFitter::FitFunction(*vec,mfit),true);
201 return v;
202} else {
203 TMatrix<T>* m = new TMatrix<T>(ObjectFitter::FitFunction(*mMtx,mfit),true);
204 return m;
205}
206}
207
208// ---- Specialisation pour complexes -----
209DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
210GeneralFitData* NOMAdapter_TMatrix< complex<r_4> >::GetGeneralFitData(bool& adel
211 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
212 ,int i1,int i2,int j1,int j2)
213{
214 return(NULL);
215}
216
217DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
218AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitResidusObj(GeneralFit& mfit)
219{
220 return(NULL);
221}
222
223DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
224AnyDataObj* NOMAdapter_TMatrix< complex<r_4> >::FitFunctionObj(GeneralFit& mfit)
225{
226 return(NULL);
227}
228
229DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
230GeneralFitData* NOMAdapter_TMatrix< complex<r_8> >::GetGeneralFitData(bool& adel
231 ,GeneralFitData::FitErrType errtype,double errscale,double errmin
232 ,int i1,int i2,int j1,int j2)
233{
234 return(NULL);
235}
236
237DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
238AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitResidusObj(GeneralFit& mfit)
239{
240 return(NULL);
241}
242
243DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
244AnyDataObj* NOMAdapter_TMatrix< complex<r_8> >::FitFunctionObj(GeneralFit& mfit)
245{
246 return(NULL);
247}
248
249// -------------------------------------------------------------
250
251/* --Methode-- */
252template <class T>
253NTupInt_TMatrix<T>::NTupInt_TMatrix(TMatrix<T>* m)
254{
255mMtx = m;
256}
257
258/* --Methode-- */
259template <class T>
260NTupInt_TMatrix<T>::~NTupInt_TMatrix()
261{
262}
263
264/* --Methode-- */
265template <class T>
266sa_size_t NTupInt_TMatrix<T>::NbLines() const
267{
268return( mMtx->NRows()*mMtx->NCols() );
269}
270
271/* --Methode-- */
272template <class T>
273sa_size_t NTupInt_TMatrix<T>::NbColumns() const
274{
275return(8);
276}
277
278/* --Methode-- */
279template <class T>
280r_8* NTupInt_TMatrix<T>::GetLineD(sa_size_t n) const
281{
282int i,j;
283if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
284 mRet[0] = n;
285 for(i=1; i<8; i++) mRet[i] = 0.;
286}
287else {
288 i = n/mMtx->NCols(); j = n%mMtx->NCols();
289 mRet[0] = n; mRet[1] = i; mRet[2] = j;
290 mRet[3] = (*mMtx)(i,j);
291 mRet[4] = mRet[2]; mRet[5] = 0.;
292 mRet[6] = mRet[2]; mRet[7] = 0.;
293 }
294return(mRet);
295}
296
297/* --Methode-- */
298template <class T>
299string NTupInt_TMatrix<T>::VarList_C(const char* nx) const
300{
301string nomx;
302if (nx) nomx = nx;
303else nomx = "_xh_";
304string vardec = "double n,r,c,val,real,imag,mod,phas; \n";
305vardec += "n = " + nomx + "[0]; r = " + nomx + "[1]; c = " + nomx + "[2]; \n";
306vardec += "val = " + nomx + "[3]; \n";
307vardec += "real = " + nomx + "[4]; imag = " + nomx + "[5]; \n";
308vardec += "mod = " + nomx + "[6]; phas = " + nomx + "[7]; \n";
309return(vardec);
310}
311
312/* --Methode-- */
313DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
314r_8* NTupInt_TMatrix< complex<r_4> >::GetLineD(sa_size_t n) const
315{
316int i,j;
317if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
318 mRet[0] = n;
319 for(i=1; i<8; i++) mRet[i] = 0.;
320}
321else {
322 i = n/mMtx->NCols(); j = n%mMtx->NCols();
323 mRet[0] = n; mRet[1] = i; mRet[2] = j;
324 mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
325 mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
326 mRet[7] = atan2(mRet[5], mRet[4]);
327}
328return(mRet);
329}
330
331DECL_TEMP_SPEC /* equivalent a template <> , pour SGI-CC en particulier */
332r_8* NTupInt_TMatrix< complex<r_8> >::GetLineD(sa_size_t n) const
333{
334int i,j;
335if ((n < 0) || (n >= (int)(mMtx->NRows()*mMtx->NCols()) )) {
336 mRet[0] = n;
337 for(i=1; i<8; i++) mRet[i] = 0.;
338}
339else {
340 i = n/mMtx->NCols(); j = n%mMtx->NCols();
341 mRet[0] = n; mRet[1] = i; mRet[2] = j;
342 mRet[4] = (*mMtx)(i,j).real(); mRet[5] = (*mMtx)(i,j).imag();
343 mRet[3] = mRet[6] = sqrt(mRet[4]*mRet[4]+mRet[5]*mRet[5]);
344 mRet[7] = atan2(mRet[5], mRet[4]);
345}
346return(mRet);
347}
348
349
350#ifdef __CXX_PRAGMA_TEMPLATES__
351#pragma define_template NOMAdapter_TMatrix<uint_2>
352#pragma define_template NOMAdapter_TMatrix<int_2>
353#pragma define_template NOMAdapter_TMatrix<int_4>
354#pragma define_template NOMAdapter_TMatrix<int_8>
355#pragma define_template NOMAdapter_TMatrix<r_4>
356#pragma define_template NOMAdapter_TMatrix<r_8>
357#pragma define_template NOMAdapter_TMatrix< complex<r_4> >
358#pragma define_template NOMAdapter_TMatrix< complex<r_8> >
359#pragma define_template NTupInt_TMatrix<uint_2>
360#pragma define_template NTupInt_TMatrix<int_2>
361#pragma define_template NTupInt_TMatrix<int_4>
362#pragma define_template NTupInt_TMatrix<int_8>
363#pragma define_template NTupInt_TMatrix<r_4>
364#pragma define_template NTupInt_TMatrix<r_8>
365#pragma define_template NTupInt_TMatrix< complex<r_4> >
366#pragma define_template NTupInt_TMatrix< complex<r_8> >
367#endif
368
369#if defined(ANSI_TEMPLATES)
370template class NOMAdapter_TMatrix<uint_2>;
371template class NOMAdapter_TMatrix<int_2>;
372template class NOMAdapter_TMatrix<int_4>;
373template class NOMAdapter_TMatrix<int_8>;
374template class NOMAdapter_TMatrix<r_4>;
375template class NOMAdapter_TMatrix<r_8>;
376template class NOMAdapter_TMatrix< complex<r_4> >;
377template class NOMAdapter_TMatrix< complex<r_8> >;
378template class NTupInt_TMatrix<uint_2>;
379template class NTupInt_TMatrix<int_2>;
380template class NTupInt_TMatrix<int_4>;
381template class NTupInt_TMatrix<int_8>;
382template class NTupInt_TMatrix<r_4>;
383template class NTupInt_TMatrix<r_8>;
384template class NTupInt_TMatrix< complex<r_4> >;
385template class NTupInt_TMatrix< complex<r_8> >;
386#endif
Note: See TracBrowser for help on using the repository browser.