source: Sophya/trunk/SophyaLib/SkyMap/fiolocalmap.cc@ 1967

Last change on this file since 1967 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.3 KB
Line 
1// G. Le Meur 04/2000
2
3#include "fiolocalmap.h"
4#include "pexceptions.h"
5#include "fiondblock.h"
6#include "datatype.h"
7#include <typeinfo>
8
9//*******************************************************************
10// class FIO_LocalMap<T>
11// Les objets delegues pour la gestion de persistance
12//*******************************************************************
13
14//++
15template <class T>
16FIO_LocalMap<T>::FIO_LocalMap()
17//
18//--
19{
20 dobj= new LocalMap<T>;
21 ownobj= true;
22}
23//++
24template <class T>
25FIO_LocalMap<T>::FIO_LocalMap(string const& filename)
26//
27//--
28{
29 dobj= new LocalMap<T>;
30 ownobj= true;
31 Read(filename);
32}
33
34//++
35template <class T>
36FIO_LocalMap<T>::FIO_LocalMap(const LocalMap<T>& obj)
37//
38//--
39{
40 dobj= new LocalMap<T>(obj, true);
41 ownobj= true;
42}
43
44template <class T>
45FIO_LocalMap<T>::FIO_LocalMap(LocalMap<T>* obj)
46{
47 dobj= obj;
48 ownobj= false;
49}
50
51//++
52template <class T>
53FIO_LocalMap<T>::~FIO_LocalMap()
54//
55//--
56{
57 if (ownobj && dobj) delete dobj;
58}
59
60//++
61template <class T>
62AnyDataObj* FIO_LocalMap<T>::DataObj()
63//
64//--
65{
66 return(dobj);
67}
68
69//++
70template <class T>
71void FIO_LocalMap<T>::SetDataObj(AnyDataObj & o)
72//
73//--
74{
75 LocalMap<T> * po = dynamic_cast< LocalMap<T> * >(&o);
76 if (po == NULL) {
77 char buff[160];
78 sprintf(buff,"FIO_LocalMap<%s>::SetDataObj(%s) - Object type error ! ",
79 DataTypeInfo<T>::getTypeName().c_str(), typeid(o).name());
80 throw TypeMismatchExc(PExcLongMessage(buff));
81 }
82 if (ownobj && dobj) delete dobj;
83 dobj = po; ownobj = false;
84}
85
86//++
87template <class T>
88void FIO_LocalMap<T>::ReadSelf(PInPersist& is)
89//
90//--
91{
92
93 if(dobj == NULL)
94 {
95 dobj= new LocalMap<T>;
96 ownobj= true;
97 }
98
99 // Pour savoir s'il y avait un DVList Info associe
100 char strg[256];
101 is.GetLine(strg, 255);
102 bool hadinfo= false;
103 if(strncmp(strg+strlen(strg)-7, "HasInfo", 7) == 0) hadinfo= true;
104 if(hadinfo)
105 { // Lecture eventuelle du DVList Info
106 is >> dobj->Info();
107 }
108
109 int_4 nSzX;
110 is.GetI4(nSzX);
111 // dobj->setSize_x(nSzX);
112
113 int_4 nSzY;
114 is.GetI4(nSzY);
115 // dobj->setSize_y(nSzY);
116
117 int_4 nPix;
118 is.GetI4(nPix);
119 // dobj->setNbPixels(nPix);
120 dobj->ReSize(nSzX, nSzY);
121 string ss("local mapping is done");
122 string sso;
123 is.GetStr(sso);
124 if(sso == ss)
125 {
126 cout<<" ReadSelf:: local mapping"<<endl;
127 int_4 x0, y0;
128 double theta, phi, angle;
129 is.GetI4(x0);
130 is.GetI4(y0);
131 is.GetR8(theta);
132 is.GetR8(phi);
133 is.GetR8(angle);
134 dobj->SetOrigin(theta, phi, x0, y0, angle);
135
136 double angleX, angleY;
137 is.GetR8(angleX);
138 is.GetR8(angleY);
139 dobj->SetSize(angleX, angleY);
140 }
141
142// On lit le DataBlock;
143 FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
144 fio_nd.Read(is);
145}
146
147//++
148template <class T>
149void FIO_LocalMap<T>::WriteSelf(POutPersist& os) const
150//
151//--
152{
153 if(dobj == NULL)
154 {
155 cout << " FIO_LocalMap::WriteSelf:: dobj= null " << endl;
156 return;
157 }
158
159 char strg[256];
160 int_4 nSzX= dobj->Size_x();
161 int_4 nSzY= dobj->Size_y();
162 int_4 nPix= dobj->NbPixels();
163
164 if(dobj->ptrInfo())
165 {
166 sprintf(strg,"LocalMap: NPixX=%6d NPixY=%9d HasInfo",nSzX,nSzY);
167 os.PutLine(strg);
168 os << dobj->Info();
169 }
170 else
171 {
172 sprintf(strg,"LocalMap: NPixX=%6d NPixY=%9d ",nSzX,nSzY);
173 os.PutLine(strg);
174 }
175
176 os.PutI4(nSzX);
177 os.PutI4(nSzY);
178 os.PutI4(nPix);
179
180 if(dobj->LocalMap_isDone())
181 {
182 string ss("local mapping is done");
183 os.PutStr(ss);
184 int_4 x0, y0;
185 double theta, phi, angle;
186 dobj->Origin(theta, phi, x0, y0, angle);
187 os.PutI4(x0);
188 os.PutI4(y0);
189 os.PutR8(theta);
190 os.PutR8(phi);
191 os.PutR8(angle);
192
193 double angleX, angleY;
194 dobj->Aperture(angleX, angleY);
195 os.PutR8(angleX);
196 os.PutR8(angleY);
197 }
198 else
199 {
200 string ss("no local mapping");
201 os.PutStr(ss);
202 }
203
204// On ecrit le dataBlock
205 FIO_NDataBlock<T> fio_nd(&dobj->DataBlock());
206 fio_nd.Write(os);
207}
208
209#ifdef __CXX_PRAGMA_TEMPLATES__
210#pragma define_template FIO_LocalMap<r_8>
211#pragma define_template FIO_LocalMap<r_4>
212#pragma define_template FIO_LocalMap< complex<r_4> >
213#pragma define_template FIO_LocalMap< complex<r_8> >
214#endif
215#if defined(ANSI_TEMPLATES) || defined(GNU_TEMPLATES)
216template class FIO_LocalMap<r_8>;
217template class FIO_LocalMap<r_4>;
218template class FIO_LocalMap< complex<r_4> >;
219template class FIO_LocalMap< complex<r_8> >;
220#endif
Note: See TracBrowser for help on using the repository browser.