Changeset 3395 in Sophya for trunk/SophyaExt


Ignore:
Timestamp:
Nov 23, 2007, 2:34:00 PM (18 years ago)
Author:
ansari
Message:

Correction pour faire fonction SwFitsDataTable en multi-threads - mais ne fonctionne toujours pas , Reza 23/11/2007

Location:
trunk/SophyaExt/FitsIOServer
Files:
2 edited

Legend:

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

    r3391 r3395  
    2424   In this case, the Show() method (or ostream& << operator) will compute min/max
    2525   values. This operation will take some time for large tables.
     26   - The SwFitsDataTable operation (AddRow()/GetRow() ) is NOT thread safe
    2627
    2728   \sa SOPHYA::MuTyV
     
    3738   // Create the swap stream
    3839   FitsInOutFile so("myswtable.fits", FitsInOutFile::Fits_Create);
    39    SwFitsDataTable dt(so, 16);
     40   SwFitsDataTable dt(so, 16, true);
    4041   // define table columns
    4142   dt.AddFloatColumn("X0_f");
     
    5455   {
    5556   // ---- Accessing information from a previously created table
    56    SwFitsDataTable dt;
    5757   FitsInOutFile si("myswtable.fits", FitsInOutFile::Fits_ReadOnly);
    5858   // Position the fits file on the first extension (BinTable)
    5959   si.MoveAbsToHDU(2); 
    60    // Reading in the table (initialisation)
    61    si >> dt;
     60   SwFitsDataTable dt(si, 512, false);
    6261   // Printing table info
    6362   cout << dt ;   
     
    6766//! Default constructor with optional specification of block (or segment) size
    6867SwFitsDataTable::SwFitsDataTable(sa_size_t segsz)
    69   : BaseDataTable(segsz)
    70 {
    71   mFgCreate = false;
     68  : BaseDataTable(segsz) , mFgCreate(false) , mFgDefDone(false)
     69{
    7270}
    7371/*!
     
    7977SwFitsDataTable::SwFitsDataTable(FitsInOutFile & os, sa_size_t segsz, bool fgcreate)
    8078  : BaseDataTable(segsz) ,
    81     mSwF(os) , mFgCreate(fgcreate)
     79    mSwF(os) , mFgCreate(fgcreate) , mFgDefDone(false)
    8280{
    8381  if (!fgcreate) {   // Lecture de la table
    8482    FitsHandler<BaseDataTable> fio(*this);
    8583    fio.Read(os);
     84    mFgDefDone = true;
    8685  }
    8786}
    8887
    8988/*!
    90   \brief Construcor with specification of the FITS file name.
    91   if fgcreate == false , the FITS file is opened and the table is
    92   initialized (read in) from HDU \b hdunum
    93 */
    94 SwFitsDataTable::SwFitsDataTable(string fitsname, int hdunum, sa_size_t segsz)
     89  \brief Construcor with specification of the FITS file name, as a Read-only file.
     90  The FITS file is opened and the table is initialized (read in) from HDU \b hdunum
     91*/
     92  SwFitsDataTable::SwFitsDataTable(string fitsname, int hdunum, sa_size_t segsz)
    9593  : BaseDataTable(segsz) ,
    96     mSwF(fitsname, FitsInOutFile::Fits_RO)
     94    mSwF(fitsname, FitsInOutFile::Fits_RO) , mFgCreate(false) , mFgDefDone(true)
    9795{
    9896  // Lecture de la table
     
    105103SwFitsDataTable::SwFitsDataTable(SwFitsDataTable const & a)
    106104  : BaseDataTable(a.SegmentSize()),
    107     mSwF(a.mSwF) , mFgCreate(a.mFgCreate)
    108 {
     105    mSwF(a.mSwF) , mFgCreate(a.mFgCreate) , mFgDefDone(a.mFgDefDone)
     106{
     107  // Attention(Reza Nov07): le mFgDefDone doit etre en principe partage entre les objets
    109108  Share(a);
    110109}
     
    228227  if (mThS) delete mThS;
    229228  mThS = NULL;
     229  mFgCreate = mFgDefDone = false;
    230230
    231231  mMin.clear();
     
    401401}
    402402
     403
     404/*!
     405  \brief Writes table definition (column name/type) to the FITS file
     406
     407  It is not possible to add columns once the table definition is
     408  written to the fits file. Returns number of table columns.
     409  Although AddRow() checks and perform this operation automatically,
     410  it is advised to do it explicitely, before using an SwFitsDataTable
     411  for filling in multi-thread programs.
     412*/
     413sa_size_t SwFitsDataTable::WriteTableDefinitionToFits()
     414{
     415  if (!mFgDefDone && (NRows() == 0)) { 
     416    FitsHandler<BaseDataTable> fio(*this);
     417    fio.Write(mSwF);
     418    mFgDefDone = true;
     419  }
     420  return NVar();
     421}
     422
    403423//! Adds a line (or row to the table) with r_8* input data.
    404424/*!
    405425  The min/max values for each column is updated, in addition
    406426  to the actions performed by the base class AddRow().
    407   The table is also created on the FITS file at the first call to AddRow()
     427  The table is also created on the FITS file at the first call to AddRow(),
     428  by calling WriteTableDefinitionToFits() , if not already done.
    408429*/
    409430sa_size_t SwFitsDataTable::AddRow(const r_8* data)
    410431{
    411432  if (mThS) mThS->lock();   // tread-safety
    412   if (NRows() == 0) {  // On cree la definition de la table FITS au premier appel
     433  if (!mFgDefDone && (NRows() == 0)) { // On cree la definition de la table FITS au premier appel 
    413434    FitsHandler<BaseDataTable> fio(*this);
    414435    fio.Write(mSwF);
     436    mFgDefDone = true;
    415437  }
    416438  // On est oblige de calculer les min-max lors du remplissage
     
    426448}
    427449
     450
    428451//! Adds a row (or line to the table) with input data as an array of MuTyV
    429452/*!
     
    435458{
    436459  if (mThS) mThS->lock();   // tread-safety
    437   if (NRows() == 0) {  // On cree la definition de la table FITS au premier appel
     460  if (!mFgDefDone && (NRows() == 0)) { // On cree la definition de la table FITS au premier appel 
    438461    FitsHandler<BaseDataTable> fio(*this);
    439462    fio.Write(mSwF);
     463    mFgDefDone = true;
    440464  }
    441465  // On est oblige de calculer les min-max lors du remplissage
  • trunk/SophyaExt/FitsIOServer/swfitsdtable.h

    r3069 r3395  
    2626
    2727  virtual sa_size_t AddColumn(FieldType ft, string const & cnom);
     28
     29  virtual sa_size_t WriteTableDefinitionToFits();
    2830
    2931  // Filling data structures (adding lines)
     
    7274  FitsInOutFile mSwF;   
    7375  bool mFgCreate; // true -> creation de table, false -> lecture
     76  bool mFgDefDone; // true -> Definition de bin-table effectuee
    7477};
    7578
Note: See TracChangeset for help on using the changeset viewer.