Changeset 3395 in Sophya for trunk/SophyaExt
- Timestamp:
- Nov 23, 2007, 2:34:00 PM (18 years ago)
- Location:
- trunk/SophyaExt/FitsIOServer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaExt/FitsIOServer/swfitsdtable.cc
r3391 r3395 24 24 In this case, the Show() method (or ostream& << operator) will compute min/max 25 25 values. This operation will take some time for large tables. 26 - The SwFitsDataTable operation (AddRow()/GetRow() ) is NOT thread safe 26 27 27 28 \sa SOPHYA::MuTyV … … 37 38 // Create the swap stream 38 39 FitsInOutFile so("myswtable.fits", FitsInOutFile::Fits_Create); 39 SwFitsDataTable dt(so, 16 );40 SwFitsDataTable dt(so, 16, true); 40 41 // define table columns 41 42 dt.AddFloatColumn("X0_f"); … … 54 55 { 55 56 // ---- Accessing information from a previously created table 56 SwFitsDataTable dt;57 57 FitsInOutFile si("myswtable.fits", FitsInOutFile::Fits_ReadOnly); 58 58 // Position the fits file on the first extension (BinTable) 59 59 si.MoveAbsToHDU(2); 60 // Reading in the table (initialisation) 61 si >> dt; 60 SwFitsDataTable dt(si, 512, false); 62 61 // Printing table info 63 62 cout << dt ; … … 67 66 //! Default constructor with optional specification of block (or segment) size 68 67 SwFitsDataTable::SwFitsDataTable(sa_size_t segsz) 69 : BaseDataTable(segsz) 70 { 71 mFgCreate = false; 68 : BaseDataTable(segsz) , mFgCreate(false) , mFgDefDone(false) 69 { 72 70 } 73 71 /*! … … 79 77 SwFitsDataTable::SwFitsDataTable(FitsInOutFile & os, sa_size_t segsz, bool fgcreate) 80 78 : BaseDataTable(segsz) , 81 mSwF(os) , mFgCreate(fgcreate) 79 mSwF(os) , mFgCreate(fgcreate) , mFgDefDone(false) 82 80 { 83 81 if (!fgcreate) { // Lecture de la table 84 82 FitsHandler<BaseDataTable> fio(*this); 85 83 fio.Read(os); 84 mFgDefDone = true; 86 85 } 87 86 } 88 87 89 88 /*! 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) 95 93 : BaseDataTable(segsz) , 96 mSwF(fitsname, FitsInOutFile::Fits_RO) 94 mSwF(fitsname, FitsInOutFile::Fits_RO) , mFgCreate(false) , mFgDefDone(true) 97 95 { 98 96 // Lecture de la table … … 105 103 SwFitsDataTable::SwFitsDataTable(SwFitsDataTable const & a) 106 104 : 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 109 108 Share(a); 110 109 } … … 228 227 if (mThS) delete mThS; 229 228 mThS = NULL; 229 mFgCreate = mFgDefDone = false; 230 230 231 231 mMin.clear(); … … 401 401 } 402 402 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 */ 413 sa_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 403 423 //! Adds a line (or row to the table) with r_8* input data. 404 424 /*! 405 425 The min/max values for each column is updated, in addition 406 426 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. 408 429 */ 409 430 sa_size_t SwFitsDataTable::AddRow(const r_8* data) 410 431 { 411 432 if (mThS) mThS->lock(); // tread-safety 412 if ( NRows() == 0) { // On cree la definition de la table FITS au premier appel433 if (!mFgDefDone && (NRows() == 0)) { // On cree la definition de la table FITS au premier appel 413 434 FitsHandler<BaseDataTable> fio(*this); 414 435 fio.Write(mSwF); 436 mFgDefDone = true; 415 437 } 416 438 // On est oblige de calculer les min-max lors du remplissage … … 426 448 } 427 449 450 428 451 //! Adds a row (or line to the table) with input data as an array of MuTyV 429 452 /*! … … 435 458 { 436 459 if (mThS) mThS->lock(); // tread-safety 437 if ( NRows() == 0) { // On cree la definition de la table FITS au premier appel460 if (!mFgDefDone && (NRows() == 0)) { // On cree la definition de la table FITS au premier appel 438 461 FitsHandler<BaseDataTable> fio(*this); 439 462 fio.Write(mSwF); 463 mFgDefDone = true; 440 464 } 441 465 // On est oblige de calculer les min-max lors du remplissage -
trunk/SophyaExt/FitsIOServer/swfitsdtable.h
r3069 r3395 26 26 27 27 virtual sa_size_t AddColumn(FieldType ft, string const & cnom); 28 29 virtual sa_size_t WriteTableDefinitionToFits(); 28 30 29 31 // Filling data structures (adding lines) … … 72 74 FitsInOutFile mSwF; 73 75 bool mFgCreate; // true -> creation de table, false -> lecture 76 bool mFgDefDone; // true -> Definition de bin-table effectuee 74 77 }; 75 78
Note:
See TracChangeset
for help on using the changeset viewer.