[2782] | 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"
|
---|
[2857] | 11 | #include "fitsinoutfile.h"
|
---|
| 12 | #include "fitsblkrw.h"
|
---|
[2782] | 13 |
|
---|
| 14 | namespace SOPHYA {
|
---|
| 15 | /*!
|
---|
| 16 | \class SOPHYA::FITSDataSwapper
|
---|
| 17 | \ingroup FitsIOServer
|
---|
[2857] | 18 | Implementation of SOPHYA::DataSwapperInterface interface on FITS files
|
---|
| 19 | (FitsInOutFile) to be used with SOPHYA::SwSegDataBlock classes.
|
---|
[2782] | 20 | */
|
---|
| 21 |
|
---|
| 22 | template <class T>
|
---|
| 23 | class FITSDataSwapper : public DataSwapperInterface<T> {
|
---|
| 24 | public:
|
---|
[2857] | 25 | FITSDataSwapper()
|
---|
| 26 | {
|
---|
| 27 | SetInOutStream(NULL, 0);
|
---|
| 28 | }
|
---|
| 29 | FITSDataSwapper(FitsInOutFile * ios, int col)
|
---|
| 30 | {
|
---|
| 31 | SetInOutStream(ios, col);
|
---|
| 32 | }
|
---|
[2782] | 33 |
|
---|
[2857] | 34 | inline FitsInOutFile * InOutStream() { return fios; }
|
---|
| 35 | void SetInOutStream(FitsInOutFile * ios, int col)
|
---|
| 36 | {
|
---|
| 37 | fios = ios;
|
---|
| 38 | fcol = col;
|
---|
| 39 | rowos = 1;
|
---|
| 40 | if ( fios != NULL) {
|
---|
| 41 | fhdu = fios->CurrentHDU();
|
---|
| 42 | if (fios->CurrentHDUType() != BINARY_TBL)
|
---|
| 43 | throw FitsIOException("FITSDataSwapper<T>::SetInOutStream() CurrHDU not a BINARY_TBL");
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
[2782] | 46 |
|
---|
| 47 | // Operateur = , on recopie les pointeurs des streams
|
---|
[2857] | 48 | FITSDataSwapper<T>& operator = (FITSDataSwapper<T> const & a)
|
---|
| 49 | {
|
---|
| 50 | fios = a.fios;
|
---|
| 51 | fcol = a.fcol;
|
---|
| 52 | rowos = a.rowos;
|
---|
| 53 | fhdu = a.fhdu;
|
---|
| 54 | }
|
---|
[2782] | 55 |
|
---|
[2857] | 56 | virtual int_8 WriteToSwap(const T * d, size_t sz, int_8 idx, int_8 oswp=0, bool osw=false)
|
---|
| 57 | {
|
---|
| 58 | if (fios == NULL)
|
---|
| 59 | FitsIOException("FITSDataSwapper<T>::ReadFromSwap() null InOutFile pointer");
|
---|
| 60 | fios->MoveAbsToHDU(fhdu);
|
---|
| 61 | long row = rowos;
|
---|
| 62 | if (osw) row = oswp;
|
---|
| 63 | FitsBlockRW<T>::WriteColumnData(*fios, fcol, row, 1, d, sz);
|
---|
| 64 | if (!osw) rowos += sz;
|
---|
| 65 | return row;
|
---|
| 66 | }
|
---|
[2782] | 67 |
|
---|
[2857] | 68 | virtual void ReadFromSwap(int_8 idx, int_8 swp, T* d, size_t sz)
|
---|
| 69 | {
|
---|
| 70 | if (fios == NULL)
|
---|
| 71 | FitsIOException("FITSDataSwapper<T>::ReadFromSwap() null InOutFile pointer");
|
---|
| 72 | FitsBlockRW<T>::ReadColumnData(*fios, fcol, swp, 1, d, sz);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[2782] | 75 | protected:
|
---|
[2857] | 76 | FitsInOutFile * fios;
|
---|
| 77 | int fcol, fhdu;
|
---|
[2782] | 78 | long rowos;
|
---|
| 79 | };
|
---|
| 80 |
|
---|
| 81 | } // Fin du namespace
|
---|
| 82 |
|
---|
| 83 | #endif
|
---|