source: Sophya/trunk/SophyaLib/SkyMap/fiospherethetaphi.cc@ 2016

Last change on this file since 2016 was 1967, checked in by ansari, 23 years ago

Ajout throw TypeMismatchExc ds PPersist_X::SetDataObj() ds les differents classes handler PPersist, a place du return simple, lorsque le type d'objet n'etait pas bon ... Reza 26/4/2002

File size: 4.7 KB
Line 
1// G. Le Meur 04/2000
2
3#include "fiospherethetaphi.h"
4#include "pexceptions.h"
5#include "fiondblock.h"
6#include "datatype.h"
7#include <typeinfo>
8
9///////////////////////////////////////////////////////////
10// --------------------------------------------------------
11// Les objets delegues pour la gestion de persistance
12// --------------------------------------------------------
13//////////////////////////////////////////////////////////
14
15template <class T>
16FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi()
17{
18 dobj= new SphereThetaPhi<T>;
19 ownobj= true;
20}
21
22template <class T>
23FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi(string const& filename)
24{
25 dobj= new SphereThetaPhi<T>;
26 ownobj= true;
27 Read(filename);
28}
29
30template <class T>
31FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi(const SphereThetaPhi<T>& obj)
32{
33 dobj= new SphereThetaPhi<T>(obj, true);
34 ownobj= true;
35}
36
37template <class T>
38FIO_SphereThetaPhi<T>::FIO_SphereThetaPhi(SphereThetaPhi<T>* obj)
39{
40 dobj= obj;
41 ownobj= false;
42}
43
44template <class T>
45FIO_SphereThetaPhi<T>::~FIO_SphereThetaPhi()
46{
47 if (ownobj && dobj) delete dobj;
48}
49
50template <class T>
51AnyDataObj* FIO_SphereThetaPhi<T>::DataObj()
52{
53 return(dobj);
54}
55
56
57template <class T>
58void FIO_SphereThetaPhi<T>::SetDataObj(AnyDataObj & o)
59{
60 SphereThetaPhi<T> * po = dynamic_cast< SphereThetaPhi<T> * >(&o);
61 if (po == NULL) {
62 char buff[160];
63 sprintf(buff,"FIO_SphereThetaPhi<%s>::SetDataObj(%s) - Object type error ! ",
64 DataTypeInfo<T>::getTypeName().c_str(), typeid(o).name());
65 throw TypeMismatchExc(PExcLongMessage(buff));
66 }
67
68 if (ownobj && dobj) delete dobj;
69 dobj = po; ownobj = false;
70}
71
72template <class T>
73void FIO_SphereThetaPhi<T>::ReadSelf(PInPersist& is)
74{
75
76 if(dobj == NULL)
77 {
78 dobj= new SphereThetaPhi<T>;
79 ownobj= true;
80 }
81
82 // On lit les 3 premiers uint_8
83 uint_8 itab[3];
84 is.Get(itab, 3);
85// Let's Read the SphereCoordSys object -- ATTENTIOn - $CHECK$
86 FIO_SphereCoordSys fio_scs( dobj->GetCoordSys());
87 fio_scs.Read(is);
88
89 // Pour savoir s'il y avait un DVList Info associe
90 char strg[256];
91 is.GetLine(strg, 255);
92 bool hadinfo= false;
93 if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo= true;
94 if(hadinfo)
95 { // Lecture eventuelle du DVList Info
96 is >> dobj->Info();
97 }
98
99 int_4 mNTheta;
100 is.GetI4(mNTheta);
101 int_4 mNPix;
102 is.GetI4(mNPix);
103 double mOmeg;
104 is.GetR8(mOmeg);
105 dobj->setParameters( mNTheta, mNPix, mOmeg);
106
107 // FIO_NDataBlock<int_4> fio_nd_nphi( &dobj->NPhi_);
108 // fio_nd_nphi.Read(is);
109 // FIO_NDataBlock<int_4> fio_nd_Tnphi(&dobj->TNphi_);
110 // fio_nd_Tnphi.Read(is);
111 // FIO_NDataBlock<r_8> fio_nd_Theta( &dobj->Theta_);
112 // fio_nd_Theta.Read(is);
113 // FIO_NDataBlock<T> fio_nd(&dobj->pixels_);
114 // fio_nd.Read(is);
115
116 // Reza 30/8/2000 , - Methode de lecture plus facile
117
118 is >> dobj->NPhi_ ;
119 is >> dobj->TNphi_ ;
120 is >> dobj->Theta_;
121 is >> dobj->pixels_;
122}
123
124template <class T>
125void FIO_SphereThetaPhi<T>::WriteSelf(POutPersist& os) const
126{
127
128 if(dobj == NULL)
129 {
130 cout << " WriteSelf:: dobj= null " << endl;
131 return;
132 }
133
134// On ecrit 3 uint_8
135// 0 : Numero de version, 1 : Size index, 2 reserve a l
136uint_8 itab[3];
137itab[0] = 1;
138itab[1] = dobj->SizeIndex();
139itab[2] = 0;
140os.Put(itab, 3);
141// Let's write the SphereCoordSys object
142 FIO_SphereCoordSys fio_scs( dobj->GetCoordSys());
143 fio_scs.Write(os);
144
145 char strg[256];
146 int_4 mNTheta= dobj->SizeIndex();
147 int_4 mNPix = dobj->NbPixels();
148
149 if(dobj->ptrInfo())
150 {
151 sprintf(strg,"SphereThetaPhi: NSlices=%6d NPix=%9d HasInfo",mNTheta,mNPix);
152 os.PutLine(strg);
153 os << dobj->Info();
154 }
155 else
156 {
157 sprintf(strg,"SphereThetaPhi: NSlices=%6d NPix=%9d ",mNTheta,mNPix);
158 os.PutLine(strg);
159 }
160
161 os.PutI4(mNTheta);
162 os.PutI4(mNPix);
163 os.PutR8(dobj->PixSolAngle());
164
165 // FIO_NDataBlock<int_4> fio_nd_nphi(&dobj->NPhi_);
166 // fio_nd_nphi.Write(os);
167 // FIO_NDataBlock<int_4> fio_nd_Tnphi(&dobj->TNphi_);
168 // fio_nd_Tnphi.Write(os);
169 // FIO_NDataBlock<r_8> fio_nd_Theta(&dobj->Theta_);
170 // fio_nd_Theta.Write(os);
171 // FIO_NDataBlock<T> fio_nd(&dobj->pixels_);
172 // fio_nd.Write(os);
173
174 // Reza 30/8/2000 , - Methode d'ecriture plus facile
175
176 os << dobj->NPhi_;
177 os << dobj->TNphi_;
178 os << dobj->Theta_;
179 os << dobj->pixels_;
180}
181
182#ifdef __CXX_PRAGMA_TEMPLATES__
183#pragma define_template FIO_SphereThetaPhi<r_8>
184#pragma define_template FIO_SphereThetaPhi<r_4>
185#pragma define_template FIO_SphereThetaPhi< complex<r_4> >
186#pragma define_template FIO_SphereThetaPhi< complex<r_8> >
187#endif
188#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
189template class FIO_SphereThetaPhi<r_8>;
190template class FIO_SphereThetaPhi<r_4>;
191template class FIO_SphereThetaPhi< complex<r_4> >;
192template class FIO_SphereThetaPhi< complex<r_8> >;
193#endif
Note: See TracBrowser for help on using the repository browser.