Ignore:
Timestamp:
Jan 9, 2006, 6:32:37 PM (20 years ago)
Author:
ansari
Message:

Mise au point de la classe SwFitsDataTable - Reza 9/01/2006

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaExt/FitsIOServer/swfitsdtable.cc

    r2865 r2889  
    11#include "swfitsdtable.h"
     2#include "fitshdtable.h"
    23#include "sopnamsp.h"
    34#include "pexceptions.h"
     
    1920   - It is not possible to make a complete (deep) copy of a SwFitsDataTable
    2021   Copy constructor and equal operator shares the data.
     22   - The min/max values for column data are not updated when reading from a fits file.
     23   In this case, the Show() method (or ostream& << operator) will compute min/max
     24   values. This operation will take some time for large tables.
    2125
    2226   \sa SOPHYA::MuTyV
     
    2630
    2731   \code
    28    #include "swppfdtable.h"
     32   #include "swfitsdtable.h"
    2933   // ...
    3034   {
    3135   // ---- Creation of the table
    3236   // Create the swap stream
    33    POutPersist so("myswtable.ppf");
    34    SwFitsDataTable dt(so, 64);
     37   FitsInOutFile so("myswtable.fits", FitsInOutFile::Fits_Create);
     38   SwFitsDataTable dt(so, 16);
    3539   // define table columns
    3640   dt.AddFloatColumn("X0_f");
     
    3842   dt.AddDoubleColumn("X0X0pX1X1_d");
    3943   // Fill the table
    40    MuTyV x[5];
     44   r_8 x[5];
    4145   for(int i=0; i<63; i++) {
    4246     x[0] = (i%9)-4.;  x[1] = (i/9)-3.;  x[2] = x[0]*x[0]+x[1]*x[1];
     
    4549   // Printing table info
    4650   cout << dt ;
    47    // Swap out all data and write the table structure to the PPF stream
    48    so << dt ;
    49    // ....
     51   // The destructor will Swap out  data still in memory
    5052   }
    5153   {
    5254   // ---- Accessing information from a previously created table
    5355   SwFitsDataTable dt;
    54    PInPersist si("myswtable.ppf");
     56   FitsInOutFile si("myswtable.fits", FitsInOutFile::Fits_ReadOnly);
     57   // Position the fits file on the first extension (BinTable)
     58   si.MoveAbsToHDU(2); 
     59   // Reading in the table (initialisation)
    5560   si >> dt;
    56    // Printing table info
     61   // Printing table info 
    5762   cout << dt ;   
    5863   }
     
    7277    mSwF(os) , mFgCreate(fgcreate)
    7378{
     79  if (!fgcreate) {   // Lecture de la table
     80    FitsHandler<BaseDataTable> fio(*this);
     81    fio.Read(os);
     82  }
    7483}
    7584//! copy constructor - shares the data
     
    8392SwFitsDataTable::~SwFitsDataTable()
    8493{
    85   if (mFgCreate) SwapOutAll();
     94  if (mFgCreate) {
     95    SwapOutAll();
     96    // Ecriture de SegmentSize et autre elements de DVList 
     97    mSwF.WriteHeaderRecords(Info());
     98    MuTyV mtv = SegmentSize();
     99    mSwF.WriteKey("SEGMSIZE",mtv," SOPHYA::DataTable SegmentSize");
     100    mtv = "SOPHYA::SwFitsDataTable";
     101    mSwF.WriteKey("SOPCLSNM",mtv," Object class name ");
     102  }
    86103}
    87104
     
    213230  mSCols.clear();
    214231
    215   /*
    216   mISwapper.clear();
    217   mLSwapper.clear();
    218   mFSwapper.clear();
    219   mDSwapper.clear();
    220   mYSwapper.clear();
    221   mZSwapper.clear();
    222   mSSwapper.clear();
    223   */
    224232}
    225233
     
    232240sa_size_t SwFitsDataTable::AddColumn(FieldType ft, string const & cnom)
    233241{
    234   return AddColRd(ft, cnom, NULL);
     242  return AddColRd(ft, cnom, -1, NULL);
    235243}
    236244/*!
     
    240248*/
    241249sa_size_t SwFitsDataTable::AddColRd(FieldType ft, string const & cnom,
    242                                     vector<int_8> const * swpos)
     250                                    int colidx, vector<int_8> const * swpos)
    243251{
    244252  if (NEntry() > 0)
     
    247255  sa_size_t ser;
    248256  sa_size_t idx = NVar();
     257  if (colidx < 1) colidx = idx+1;
     258
    249259  switch (ft) {
    250260  case IntegerField :
    251261  {
    252262    ser = mICols.size();
    253     FITSDataSwapper<int_4> ISwapper(mSwF, idx+1);
     263    FITSDataSwapper<int_4> ISwapper(mSwF, colidx);
    254264    if (swpos)
    255265      mICols.push_back(SwSegDataBlock<int_4>(ISwapper, *swpos, mSegSz));
     
    265275  {
    266276    ser = mLCols.size();
    267     FITSDataSwapper<int_8> LSwapper(mSwF, idx+1);
     277    FITSDataSwapper<int_8> LSwapper(mSwF, colidx);
    268278    if (swpos)   
    269279      mLCols.push_back(SwSegDataBlock<int_8>(LSwapper, *swpos, mSegSz));
     
    279289  {
    280290    ser = mFCols.size();
    281     FITSDataSwapper<r_4> FSwapper(mSwF, idx+1);
     291    FITSDataSwapper<r_4> FSwapper(mSwF, colidx);
    282292    if (swpos)   
    283293      mFCols.push_back(SwSegDataBlock<r_4>(FSwapper, *swpos, mSegSz));
     
    294304  {
    295305    ser = mDCols.size();
    296     FITSDataSwapper<r_8> DSwapper(mSwF, idx+1);
     306    FITSDataSwapper<r_8> DSwapper(mSwF, colidx);
    297307    if (swpos)   
    298308      mDCols.push_back(SwSegDataBlock<r_8>(DSwapper, *swpos, mSegSz));
     
    308318  {
    309319    ser = mYCols.size();
    310     FITSDataSwapper< complex<r_4> > YSwapper(mSwF, idx+1);
     320    FITSDataSwapper< complex<r_4> > YSwapper(mSwF, colidx);
    311321    if (swpos)   
    312322      mYCols.push_back(SwSegDataBlock< complex<r_4> >(YSwapper, *swpos, mSegSz));
     
    322332  {
    323333    ser = mZCols.size();
    324     FITSDataSwapper< complex<r_8> > ZSwapper(mSwF, idx+1);
     334    FITSDataSwapper< complex<r_8> > ZSwapper(mSwF, colidx);
    325335    if (swpos)   
    326336      mZCols.push_back(SwSegDataBlock< complex<r_8> >(ZSwapper, *swpos, mSegSz));
     
    336346  {
    337347    ser = mSCols.size();
    338     FITSDataSwapper< string > SSwapper(mSwF, idx+1);
     348    FITSDataSwapper< string > SSwapper(mSwF, colidx);
    339349    if (swpos)   
    340350      mSCols.push_back(SwSegDataBlock< string >(SSwapper, *swpos, mSegSz));
     
    368378/*!
    369379  The min/max values for each column is updated, in addition
    370   to the actions performed by the base class AddLine()
    371 */
    372 sa_size_t SwFitsDataTable::AddLine(const r_8* data)
    373 {
     380  to the actions performed by the base class AddRow()
     381*/
     382sa_size_t SwFitsDataTable::AddRow(const r_8* data)
     383{
     384  if (NRows() == 0) {  // On cree la definition de la table FITS au premier appel
     385    FitsHandler<BaseDataTable> fio(*this);
     386    fio.Write(mSwF);
     387  }
    374388  // On est oblige de calculer les min-max lors du remplissage
    375389  // On ne peut pas en effet 'relire' le swap pendant l'ecriture
     
    380394    mMinMaxNEnt[k]++;
    381395  }
    382   return BaseDataTable::AddLine(data);
    383 }
    384 
    385 //! Adds a line (or row to the table) with input data as an array of MuTyV
     396  return BaseDataTable::AddRow(data);
     397}
     398
     399//! Adds a row (or line to the table) with input data as an array of MuTyV
    386400/*!
    387401  The min/max values for each column is updated, in addition
    388   to the actions performed by the base class AddLine()
    389 */
    390 sa_size_t SwFitsDataTable::AddLine(const MuTyV * data)
    391 {
     402  to the actions performed by the base class AddRow()
     403*/
     404sa_size_t SwFitsDataTable::AddRow(const MuTyV * data)
     405{
     406  if (NRows() == 0) {  // On cree la definition de la table FITS au premier appel
     407    FitsHandler<BaseDataTable> fio(*this);
     408    fio.Write(mSwF);
     409  }
    392410  // On est oblige de calculer les min-max lors du remplissage
    393411  // On ne peut pas en effet 'relire' le swap pendant l'ecriture
     
    398416    mMinMaxNEnt[k]++;
    399417  }
    400   return BaseDataTable::AddLine(data);
    401 }
    402 
     418  return BaseDataTable::AddRow(data);
     419}
     420
Note: See TracChangeset for help on using the changeset viewer.