Commit aad6f74b0c852c26c99a6dbde4099e253aceb9a5
1 parent
966fb927
start implementation of table creation/saving methods
Showing
6 changed files
with
163 additions
and
54 deletions
include/GException.hpp
| ... | ... | @@ -159,6 +159,12 @@ public: |
| 159 | 159 | fits_column_not_found(string origin, string colname, int status = 0); |
| 160 | 160 | }; |
| 161 | 161 | |
| 162 | + // FITS has no data | |
| 163 | + class fits_no_data : public GExceptionHandler { | |
| 164 | + public: | |
| 165 | + fits_no_data(string origin, string message, int status = 0); | |
| 166 | + }; | |
| 167 | + | |
| 162 | 168 | // FITS HDU not found error |
| 163 | 169 | class fits_hdu_not_found : public GExceptionHandler { |
| 164 | 170 | public: | ... | ... |
include/GFitsBinTable.hpp
| ... | ... | @@ -10,12 +10,16 @@ |
| 10 | 10 | * (at your option) any later version. * |
| 11 | 11 | * * |
| 12 | 12 | ***************************************************************************/ |
| 13 | +/** | |
| 14 | + * @file GFitsBinTable.hpp | |
| 15 | + * @brief GFitsBinTable class definition. | |
| 16 | + * @author J. Knodlseder | |
| 17 | + */ | |
| 13 | 18 | |
| 14 | 19 | #ifndef GFITSBINTABLE_HPP |
| 15 | 20 | #define GFITSBINTABLE_HPP |
| 16 | 21 | |
| 17 | 22 | /* __ Includes ___________________________________________________________ */ |
| 18 | -//#include <vector> | |
| 19 | 23 | #include "GFitsCfitsio.hpp" |
| 20 | 24 | #include "GFitsData.hpp" |
| 21 | 25 | #include "GFitsTableCol.hpp" |
| ... | ... | @@ -26,8 +30,10 @@ |
| 26 | 30 | /* __ Structures _________________________________________________________ */ |
| 27 | 31 | |
| 28 | 32 | |
| 29 | -/*************************************************************************** | |
| 30 | - * GFitsBinTable class definition * | |
| 33 | +/***********************************************************************//** | |
| 34 | + * @class GFitsBinTable | |
| 35 | + * | |
| 36 | + * @brief Interface for FITS binary table | |
| 31 | 37 | ***************************************************************************/ |
| 32 | 38 | class GFitsBinTable : public GFitsData { |
| 33 | 39 | |
| ... | ... | @@ -37,6 +43,7 @@ class GFitsBinTable : public GFitsData { |
| 37 | 43 | public: |
| 38 | 44 | // Constructors and destructors |
| 39 | 45 | GFitsBinTable(); |
| 46 | + GFitsBinTable(int nrows, int ncols); | |
| 40 | 47 | GFitsBinTable(const GFitsBinTable& table); |
| 41 | 48 | virtual ~GFitsBinTable(); |
| 42 | 49 | |
| ... | ... | @@ -48,8 +55,8 @@ public: |
| 48 | 55 | void save(void); |
| 49 | 56 | void close(void); |
| 50 | 57 | GFitsBinTable* clone(void) const; |
| 51 | - GFitsTableCol* column(const std::string colname); | |
| 52 | - GFitsTableCol* column(const int colnum); | |
| 58 | + GFitsTableCol* column(const std::string& colname); | |
| 59 | + GFitsTableCol* column(const int& colnum); | |
| 53 | 60 | |
| 54 | 61 | private: |
| 55 | 62 | // Private methods |
| ... | ... | @@ -59,9 +66,9 @@ private: |
| 59 | 66 | void connect(__fitsfile* fptr); |
| 60 | 67 | |
| 61 | 68 | // Private data area |
| 62 | - int m_rows; | |
| 63 | - int m_cols; | |
| 64 | - GFitsTableCol** m_columns; | |
| 69 | + int m_rows; //!< Number of rows in table | |
| 70 | + int m_cols; //!< Number of columns in table | |
| 71 | + GFitsTableCol** m_columns; //!< Array of column pointers | |
| 65 | 72 | }; |
| 66 | 73 | |
| 67 | 74 | ... | ... |
src/GException.cpp
| ... | ... | @@ -317,6 +317,24 @@ GException::fits_column_not_found::fits_column_not_found(string origin, |
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | /***********************************************************************//** |
| 320 | + * @brief FITS error: No data | |
| 321 | + * | |
| 322 | + * @param[in] origin Method that throws the error. | |
| 323 | + * @param[in] message Error message. | |
| 324 | + * @param[in] status cfitsio status. | |
| 325 | + ***************************************************************************/ | |
| 326 | +GException::fits_no_data::fits_no_data(string origin, | |
| 327 | + string message, | |
| 328 | + int status) | |
| 329 | +{ | |
| 330 | + m_origin = origin; | |
| 331 | + m_message = message; | |
| 332 | + if (status != 0) | |
| 333 | + m_message += " (status=" + str(status) + ")"; | |
| 334 | +} | |
| 335 | + | |
| 336 | + | |
| 337 | +/***********************************************************************//** | |
| 320 | 338 | * @brief FITS error: HDU not found in FITS file |
| 321 | 339 | * |
| 322 | 340 | * @param[in] origin Method that throws the error. | ... | ... |
src/fits/GFitsBinTable.cpp
| ... | ... | @@ -26,7 +26,9 @@ |
| 26 | 26 | /* __ Namespaces _________________________________________________________ */ |
| 27 | 27 | |
| 28 | 28 | /* __ Method name definitions ____________________________________________ */ |
| 29 | -#define G_OPEN "GFitsBinTable::open(fitsfile*)" | |
| 29 | +#define G_OPEN "GFitsBinTable::open(fitsfile*)" | |
| 30 | +#define G_COLUMN1 "GFitsBinTable::column(const std::string&)" | |
| 31 | +#define G_COLUMN2 "GFitsBinTable::column(const int&)" | |
| 30 | 32 | |
| 31 | 33 | /* __ Macros _____________________________________________________________ */ |
| 32 | 34 | |
| ... | ... | @@ -41,9 +43,8 @@ |
| 41 | 43 | = = |
| 42 | 44 | ==========================================================================*/ |
| 43 | 45 | |
| 44 | -/*************************************************************************** | |
| 45 | - * Constructor * | |
| 46 | - * ----------------------------------------------------------------------- * | |
| 46 | +/***********************************************************************//** | |
| 47 | + * @brief Constructor | |
| 47 | 48 | ***************************************************************************/ |
| 48 | 49 | GFitsBinTable::GFitsBinTable() : GFitsData() |
| 49 | 50 | { |
| ... | ... | @@ -55,9 +56,43 @@ GFitsBinTable::GFitsBinTable() : GFitsData() |
| 55 | 56 | } |
| 56 | 57 | |
| 57 | 58 | |
| 58 | -/*************************************************************************** | |
| 59 | - * Copy constructor * | |
| 60 | - * ----------------------------------------------------------------------- * | |
| 59 | +/***********************************************************************//** | |
| 60 | + * @brief Constructor | |
| 61 | + * | |
| 62 | + * @param[in] nrows Number of rows in table | |
| 63 | + * @param[in] ncols Number of columns in table | |
| 64 | + ***************************************************************************/ | |
| 65 | +GFitsBinTable::GFitsBinTable(int nrows, int ncols) : GFitsData() | |
| 66 | +{ | |
| 67 | + // Initialise class members for clean destruction | |
| 68 | + init_members(); | |
| 69 | + | |
| 70 | + // Store table dimension | |
| 71 | + m_rows = nrows; | |
| 72 | + m_cols = ncols; | |
| 73 | + | |
| 74 | + // If there are columns then allocate memory for column pointers | |
| 75 | + if (m_cols > 0) { | |
| 76 | + | |
| 77 | + // Allocate pointer memory | |
| 78 | + m_columns = new GFitsTableCol*[m_cols]; | |
| 79 | + | |
| 80 | + // Initialise pointers | |
| 81 | + for (int i = 0; i < m_cols; ++i) | |
| 82 | + m_columns[i] = NULL; | |
| 83 | + | |
| 84 | + } // endfor: looped over all columns | |
| 85 | + | |
| 86 | + // Return | |
| 87 | + return; | |
| 88 | +} | |
| 89 | + | |
| 90 | + | |
| 91 | +/***********************************************************************//** | |
| 92 | + * @brief Copy constructor | |
| 93 | + * | |
| 94 | + * @param[in] table Table which will be used to construct GFitsBinTable | |
| 95 | + * instance | |
| 61 | 96 | ***************************************************************************/ |
| 62 | 97 | GFitsBinTable::GFitsBinTable(const GFitsBinTable& table) : GFitsData(table) |
| 63 | 98 | { |
| ... | ... | @@ -72,9 +107,8 @@ GFitsBinTable::GFitsBinTable(const GFitsBinTable& table) : GFitsData(table) |
| 72 | 107 | } |
| 73 | 108 | |
| 74 | 109 | |
| 75 | -/*************************************************************************** | |
| 76 | - * Destructor * | |
| 77 | - * ----------------------------------------------------------------------- * | |
| 110 | +/***********************************************************************//** | |
| 111 | + * @brief Destructor | |
| 78 | 112 | ***************************************************************************/ |
| 79 | 113 | GFitsBinTable::~GFitsBinTable() |
| 80 | 114 | { |
| ... | ... | @@ -92,9 +126,10 @@ GFitsBinTable::~GFitsBinTable() |
| 92 | 126 | = = |
| 93 | 127 | ==========================================================================*/ |
| 94 | 128 | |
| 95 | -/*************************************************************************** | |
| 96 | - * Assignment operator * | |
| 97 | - * ----------------------------------------------------------------------- * | |
| 129 | +/***********************************************************************//** | |
| 130 | + * @brief Assignment operator | |
| 131 | + * | |
| 132 | + * @param[in] table Table which will be assigned | |
| 98 | 133 | ***************************************************************************/ |
| 99 | 134 | GFitsBinTable& GFitsBinTable::operator= (const GFitsBinTable& table) |
| 100 | 135 | { |
| ... | ... | @@ -129,7 +164,11 @@ GFitsBinTable& GFitsBinTable::operator= (const GFitsBinTable& table) |
| 129 | 164 | /***********************************************************************//** |
| 130 | 165 | * @brief Open Table |
| 131 | 166 | * |
| 132 | - * @param fptr FITS file pointer | |
| 167 | + * @param[in] fptr FITS file pointer | |
| 168 | + * | |
| 169 | + * Builds a description of the binary table in memory. Columns are not loaded | |
| 170 | + * but column descriptors are allocated. The column data will only be loaded | |
| 171 | + * once it needs to be accessed. | |
| 133 | 172 | ***************************************************************************/ |
| 134 | 173 | void GFitsBinTable::open(__fitsfile* fptr) |
| 135 | 174 | { |
| ... | ... | @@ -216,6 +255,8 @@ void GFitsBinTable::open(__fitsfile* fptr) |
| 216 | 255 | |
| 217 | 256 | /***********************************************************************//** |
| 218 | 257 | * @brief Save binary table |
| 258 | + * | |
| 259 | + * NOT YET IMPLEMENTED | |
| 219 | 260 | ***************************************************************************/ |
| 220 | 261 | void GFitsBinTable::save(void) |
| 221 | 262 | { |
| ... | ... | @@ -242,12 +283,23 @@ void GFitsBinTable::close(void) |
| 242 | 283 | } |
| 243 | 284 | |
| 244 | 285 | |
| 245 | -/*************************************************************************** | |
| 246 | - * Return pointer to column with specified name * | |
| 247 | - * ----------------------------------------------------------------------- * | |
| 286 | +/***********************************************************************//** | |
| 287 | + * @brief Return pointer to column with specified name | |
| 288 | + * | |
| 289 | + * @param[in] colname Name of column which should be accessed | |
| 290 | + * | |
| 291 | + * @exception GException::fits_no_data | |
| 292 | + * There are no column data in the table or there is not data | |
| 293 | + * for this column | |
| 294 | + * @exception GException::fits_column_not_found | |
| 295 | + * Requested column has not been found in table. | |
| 248 | 296 | ***************************************************************************/ |
| 249 | -GFitsTableCol* GFitsBinTable::column(const std::string colname) | |
| 297 | +GFitsTableCol* GFitsBinTable::column(const std::string& colname) | |
| 250 | 298 | { |
| 299 | + // If there is no data then throw an exception | |
| 300 | + if (m_columns == NULL) | |
| 301 | + throw GException::fits_no_data(G_COLUMN1, "No column data in table"); | |
| 302 | + | |
| 251 | 303 | // Initialise pointer |
| 252 | 304 | GFitsTableCol* ptr = NULL; |
| 253 | 305 | |
| ... | ... | @@ -256,29 +308,48 @@ GFitsTableCol* GFitsBinTable::column(const std::string colname) |
| 256 | 308 | for (int i = 0; i < m_cols; ++i) { |
| 257 | 309 | if (m_columns[i]->name() == colname) { |
| 258 | 310 | ptr = m_columns[i]; |
| 311 | + if (ptr == NULL) | |
| 312 | + throw GException::fits_no_data(G_COLUMN1, | |
| 313 | + "No data for this column"); | |
| 259 | 314 | break; |
| 260 | 315 | } |
| 261 | 316 | } |
| 262 | 317 | } |
| 263 | 318 | |
| 319 | + // If column has not been found throw an exception | |
| 320 | + if (ptr == NULL) | |
| 321 | + throw GException::fits_column_not_found(G_COLUMN1, colname); | |
| 322 | + | |
| 264 | 323 | // Return column pointer |
| 265 | 324 | return ptr; |
| 266 | 325 | } |
| 267 | 326 | |
| 268 | 327 | |
| 269 | -/*************************************************************************** | |
| 270 | - * Return pointer to column with number * | |
| 271 | - * ----------------------------------------------------------------------- * | |
| 328 | +/***********************************************************************//** | |
| 329 | + * @brief Return pointer to column with number | |
| 330 | + * | |
| 331 | + * @param[in] colnum Number of requested column (starting from 0) | |
| 332 | + * | |
| 333 | + * @exception GException::fits_no_data | |
| 334 | + * There are no column data in the table or there is not data | |
| 335 | + * for this column | |
| 336 | + * @exception GException::out_of_range | |
| 337 | + * Requested column has not been found in table. | |
| 272 | 338 | ***************************************************************************/ |
| 273 | -GFitsTableCol* GFitsBinTable::column(const int colnum) | |
| 339 | +GFitsTableCol* GFitsBinTable::column(const int& colnum) | |
| 274 | 340 | { |
| 275 | - // Initialise pointer | |
| 276 | - GFitsTableCol* ptr = NULL; | |
| 341 | + // If there is no data then throw an exception | |
| 342 | + if (m_columns == NULL) | |
| 343 | + throw GException::fits_no_data(G_COLUMN2, "No column data in table"); | |
| 277 | 344 | |
| 278 | - // If there are columns then search for the specified name | |
| 279 | - if (m_columns != NULL) { | |
| 280 | - ptr = m_columns[colnum]; | |
| 281 | - } | |
| 345 | + // If column number is out of range then throw an exception | |
| 346 | + if (colnum < 0 || colnum >= m_cols) | |
| 347 | + throw GException::out_of_range(G_COLUMN2, colnum, 0, m_cols-1); | |
| 348 | + | |
| 349 | + // Get column pointer | |
| 350 | + GFitsTableCol* ptr = ptr = m_columns[colnum]; | |
| 351 | + if (ptr == NULL) | |
| 352 | + throw GException::fits_no_data(G_COLUMN2, "No data for this column"); | |
| 282 | 353 | |
| 283 | 354 | // Return column pointer |
| 284 | 355 | return ptr; |
| ... | ... | @@ -291,9 +362,8 @@ GFitsTableCol* GFitsBinTable::column(const int colnum) |
| 291 | 362 | = = |
| 292 | 363 | ==========================================================================*/ |
| 293 | 364 | |
| 294 | -/*************************************************************************** | |
| 295 | - * Initialise class members * | |
| 296 | - * ----------------------------------------------------------------------- * | |
| 365 | +/***********************************************************************//** | |
| 366 | + * @brief Initialise class members | |
| 297 | 367 | ***************************************************************************/ |
| 298 | 368 | void GFitsBinTable::init_members(void) |
| 299 | 369 | { |
| ... | ... | @@ -307,9 +377,10 @@ void GFitsBinTable::init_members(void) |
| 307 | 377 | } |
| 308 | 378 | |
| 309 | 379 | |
| 310 | -/*************************************************************************** | |
| 311 | - * Copy class members * | |
| 312 | - * ----------------------------------------------------------------------- * | |
| 380 | +/***********************************************************************//** | |
| 381 | + * @brief Copy class members | |
| 382 | + * | |
| 383 | + * @param[in] table Table to copy | |
| 313 | 384 | ***************************************************************************/ |
| 314 | 385 | void GFitsBinTable::copy_members(const GFitsBinTable& table) |
| 315 | 386 | { |
| ... | ... | @@ -331,9 +402,8 @@ void GFitsBinTable::copy_members(const GFitsBinTable& table) |
| 331 | 402 | } |
| 332 | 403 | |
| 333 | 404 | |
| 334 | -/*************************************************************************** | |
| 335 | - * Delete class members * | |
| 336 | - * ----------------------------------------------------------------------- * | |
| 405 | +/***********************************************************************//** | |
| 406 | + * @brief Delete class members | |
| 337 | 407 | ***************************************************************************/ |
| 338 | 408 | void GFitsBinTable::free_members(void) |
| 339 | 409 | { |
| ... | ... | @@ -354,19 +424,20 @@ void GFitsBinTable::free_members(void) |
| 354 | 424 | /***********************************************************************//** |
| 355 | 425 | * @brief Connect binary table to FITS file |
| 356 | 426 | * |
| 357 | - * @param fptr FITS file pointer to which the binary table should be connected | |
| 427 | + * @param[in] fptr FITS file pointer to which the binary table should be | |
| 428 | + * connected | |
| 358 | 429 | * |
| 359 | 430 | * The connection of the binary table is done by connecting all columns. |
| 360 | 431 | ***************************************************************************/ |
| 361 | 432 | void GFitsBinTable::connect(__fitsfile* fptr) |
| 362 | 433 | { |
| 363 | 434 | // First connect binary table |
| 364 | - | |
| 435 | + | |
| 365 | 436 | // Then connect all columns |
| 366 | 437 | for (int i = 0; i < m_cols; ++i) { |
| 367 | 438 | if (m_columns[i] != NULL) m_columns[i]->connect(fptr); |
| 368 | 439 | } |
| 369 | - | |
| 440 | + | |
| 370 | 441 | // Return |
| 371 | 442 | return; |
| 372 | 443 | } |
| ... | ... | @@ -378,9 +449,11 @@ void GFitsBinTable::connect(__fitsfile* fptr) |
| 378 | 449 | = = |
| 379 | 450 | ==========================================================================*/ |
| 380 | 451 | |
| 381 | -/*************************************************************************** | |
| 382 | - * Output operator * | |
| 383 | - * ----------------------------------------------------------------------- * | |
| 452 | +/***********************************************************************//** | |
| 453 | + * @brief Output operator | |
| 454 | + * | |
| 455 | + * @param[in] os Output stream | |
| 456 | + * @param[in] table Table to put in output stream | |
| 384 | 457 | ***************************************************************************/ |
| 385 | 458 | ostream& operator<< (ostream& os, const GFitsBinTable& table) |
| 386 | 459 | { | ... | ... |
src/fits/GFitsHDU.cpp
| ... | ... | @@ -61,8 +61,6 @@ GFitsHDU::GFitsHDU() |
| 61 | 61 | * |
| 62 | 62 | * Note that the HDU constructor copies the image, hence any change in the |
| 63 | 63 | * original object after copying will not be reflected in the copied object. |
| 64 | - * | |
| 65 | - * IMPLEMENTATION NOT YET FINISHED (NEEDS KEYWORD SETTING) | |
| 66 | 64 | ***************************************************************************/ |
| 67 | 65 | GFitsHDU::GFitsHDU(const GFitsImage& image) |
| 68 | 66 | { | ... | ... |
src/rsp/GLATResponse.cpp
| ... | ... | @@ -265,11 +265,13 @@ void GLATResponse::save(const std::string& rspname) const |
| 265 | 265 | fits.open(rspname); |
| 266 | 266 | |
| 267 | 267 | // Build PSF HDUs |
| 268 | + GFitsBinTable table_psf_bounds(1,4); | |
| 268 | 269 | int naxes_psf2[] = {m_psf_energy_num, m_psf_ctheta_num}; |
| 269 | 270 | int naxes_psf3[] = {m_psf_angle_num, m_psf_energy_num, m_psf_ctheta_num}; |
| 270 | 271 | GFitsDblImage image_psf_psf(3, naxes_psf3, m_psf); |
| 271 | 272 | GFitsDblImage image_psf_norm(2, naxes_psf2, m_norm); |
| 272 | 273 | GFitsDblImage image_psf_sigma(2, naxes_psf2, m_sigma); |
| 274 | + //TBD GFitsHDU hdu_psf_bounds(table_psf_bounds); | |
| 273 | 275 | GFitsHDU hdu_psf_psf(image_psf_psf); |
| 274 | 276 | GFitsHDU hdu_psf_norm(image_psf_norm); |
| 275 | 277 | GFitsHDU hdu_psf_sigma(image_psf_sigma); |
| ... | ... | @@ -288,7 +290,12 @@ void GLATResponse::save(const std::string& rspname) const |
| 288 | 290 | // Return |
| 289 | 291 | return; |
| 290 | 292 | } |
| 291 | - | |
| 293 | +/* | |
| 294 | + GVector v_energy_lo = get_fits_vector(hdu, "ENERG_LO"); | |
| 295 | + GVector v_energy_hi = get_fits_vector(hdu, "ENERG_HI"); | |
| 296 | + GVector v_ctheta_lo = get_fits_vector(hdu, "CTHETA_LO"); | |
| 297 | + GVector v_ctheta_hi = get_fits_vector(hdu, "CTHETA_HI"); | |
| 298 | +*/ | |
| 292 | 299 | |
| 293 | 300 | /*========================================================================== |
| 294 | 301 | = = | ... | ... |