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