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