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