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