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