| 1 | /* | 
|---|
| 2 | --- SOPHYA software - FitsIOServer module --- | 
|---|
| 3 | R. Ansari,  C. Magneville,   Mai 2005 | 
|---|
| 4 | (C) UPS+LAL IN2P3/CNRS     (C) DAPNIA-SPP/CEA | 
|---|
| 5 | */ | 
|---|
| 6 | #ifndef FITSSWAPPER_H | 
|---|
| 7 | #define FITSSWAPPER_H | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 | #include "machdefs.h" | 
|---|
| 11 | #include "swsegdb.h" | 
|---|
| 12 | #include "fitsinoutfile.h" | 
|---|
| 13 | #include "fitsblkrw.h" | 
|---|
| 14 |  | 
|---|
| 15 | #include "basedtable.h" | 
|---|
| 16 |  | 
|---|
| 17 | /*! | 
|---|
| 18 | \class SOPHYA::FITSDataSwapper | 
|---|
| 19 | \ingroup FitsIOServer | 
|---|
| 20 | Implementation of SOPHYA::DataSwapperInterface interface on FITS files | 
|---|
| 21 | (FitsInOutFile) to be used with SOPHYA::SwSegDataBlock classes. | 
|---|
| 22 | */ | 
|---|
| 23 |  | 
|---|
| 24 | namespace SOPHYA { | 
|---|
| 25 |  | 
|---|
| 26 | template <class T> | 
|---|
| 27 | class FITSDataSwapper : public DataSwapperInterface<T> { | 
|---|
| 28 | public: | 
|---|
| 29 | FITSDataSwapper() | 
|---|
| 30 | : fcol(0) , rowos(1) , dtp(NULL) | 
|---|
| 31 | { | 
|---|
| 32 | } | 
|---|
| 33 | FITSDataSwapper(FitsInOutFile & ios, int col, BaseDataTable* dt=NULL) | 
|---|
| 34 | : fios(ios) , fcol(col), rowos(1) , dtp(dt) | 
|---|
| 35 | { | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 | inline FitsInOutFile & InOutStream() { return fios; } | 
|---|
| 39 |  | 
|---|
| 40 | void SetInOutStream(FitsInOutFile & ios, int col) | 
|---|
| 41 | { | 
|---|
| 42 | fios = ios; | 
|---|
| 43 | fcol = col; | 
|---|
| 44 | rowos = 1; | 
|---|
| 45 | /*  On ne fait pas de check sur type HDU - Reza , 30/12/2005 | 
|---|
| 46 | if ( fios != NULL) { | 
|---|
| 47 | fhdu = fios->CurrentHDU(); | 
|---|
| 48 | if (fios->CurrentHDUType() != BINARY_TBL) | 
|---|
| 49 | throw FitsIOException("FITSDataSwapper<T>::SetInOutStream() CurrHDU not a BINARY_TBL"); | 
|---|
| 50 | }    */ | 
|---|
| 51 | } | 
|---|
| 52 |  | 
|---|
| 53 | // Operateur = , on recopie les pointeurs des streams | 
|---|
| 54 | FITSDataSwapper<T>& operator = (FITSDataSwapper<T> const & a) | 
|---|
| 55 | { | 
|---|
| 56 | fios = a.fios; | 
|---|
| 57 | fcol = a.fcol; | 
|---|
| 58 | rowos = a.rowos; | 
|---|
| 59 | dtp = a.dtp; | 
|---|
| 60 | } | 
|---|
| 61 |  | 
|---|
| 62 | virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false) | 
|---|
| 63 | { | 
|---|
| 64 | /* fios->MoveAbsToHDU(fhdu);  On suppose qu'on est sur le bon HDU - Reza 30/12/2005 */ | 
|---|
| 65 | LONGLONG row = rowos; | 
|---|
| 66 | if (osw)  row = oswp; | 
|---|
| 67 | if (dtp != NULL) | 
|---|
| 68 | if ((row+sz-1) > dtp->NRows() )  sz = dtp->NRows()-row+1; | 
|---|
| 69 | FitsBlockRW<T>::WriteColumnData(fios, fcol, row, 1, d, sz); | 
|---|
| 70 | if (!osw) rowos += sz; | 
|---|
| 71 | return row; | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | virtual void  ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz) | 
|---|
| 75 | { | 
|---|
| 76 | int_8 nrows = fios.GetNbRows(); | 
|---|
| 77 | size_t szi = sz; | 
|---|
| 78 | if ((swp+sz-1) > nrows) sz = nrows-swp+1; | 
|---|
| 79 | FitsBlockRW<T>::ReadColumnData(fios, fcol, swp, 1, d, sz); | 
|---|
| 80 | if (sz < szi) { | 
|---|
| 81 | T zz = d[sz-1]; | 
|---|
| 82 | for(size_t k=sz; k<szi; k++)  d[k] = zz; | 
|---|
| 83 | } | 
|---|
| 84 | } | 
|---|
| 85 |  | 
|---|
| 86 | virtual DataSwapperInterface<T>* Clone() | 
|---|
| 87 | { | 
|---|
| 88 | FITSDataSwapper<T> * rsw = new FITSDataSwapper<T>(fios, fcol, dtp) ; | 
|---|
| 89 | rsw->rowos = rowos; | 
|---|
| 90 | rsw->dtp = dtp; | 
|---|
| 91 | return rsw; | 
|---|
| 92 | } | 
|---|
| 93 |  | 
|---|
| 94 | protected: | 
|---|
| 95 | FitsInOutFile fios; | 
|---|
| 96 | int fcol; | 
|---|
| 97 | LONGLONG rowos; | 
|---|
| 98 | BaseDataTable* dtp; | 
|---|
| 99 | }; | 
|---|
| 100 |  | 
|---|
| 101 | } // Fin du namespace | 
|---|
| 102 |  | 
|---|
| 103 | #endif | 
|---|