source: Sophya/trunk/SophyaExt/FitsIOServer/fitsswapper.h@ 3128

Last change on this file since 3128 was 3069, checked in by ansari, 19 years ago

Correction plusieurs bugs lies a SwFitsDataTable - Reza 08/09/2006

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