Commit 6c59bd24c09b007349ed4f878e0d5c20197ae1c8
1 parent
e21b42cd
implement vector loading
Showing
4 changed files
with
93 additions
and
79 deletions
include/GException.hpp
| ... | ... | @@ -144,7 +144,19 @@ public: |
| 144 | 144 | // FITS keyword not found error |
| 145 | 145 | class fits_key_not_found : public GExceptionHandler { |
| 146 | 146 | public: |
| 147 | - fits_key_not_found(string origin, string keyname, int status); | |
| 147 | + fits_key_not_found(string origin, string keyname, int status = 0); | |
| 148 | + }; | |
| 149 | + | |
| 150 | + // FITS column not found error | |
| 151 | + class fits_column_not_found : public GExceptionHandler { | |
| 152 | + public: | |
| 153 | + fits_column_not_found(string origin, string colname, int status = 0); | |
| 154 | + }; | |
| 155 | + | |
| 156 | + // FITS HDU not found error | |
| 157 | + class fits_hdu_not_found : public GExceptionHandler { | |
| 158 | + public: | |
| 159 | + fits_hdu_not_found(string origin, string extname, int status = 0); | |
| 148 | 160 | }; |
| 149 | 161 | |
| 150 | 162 | // FITS unknown HDU type |
| ... | ... | @@ -153,7 +165,7 @@ public: |
| 153 | 165 | fits_unknown_HDU_type(string origin, int type); |
| 154 | 166 | }; |
| 155 | 167 | |
| 156 | - // FITS unknown HDU type | |
| 168 | + // FITS HDU is not a table | |
| 157 | 169 | class fits_HDU_not_a_table : public GExceptionHandler { |
| 158 | 170 | public: |
| 159 | 171 | fits_HDU_not_a_table(string origin, int type); |
| ... | ... | @@ -165,7 +177,7 @@ public: |
| 165 | 177 | fits_invalid_type(string origin, string message); |
| 166 | 178 | }; |
| 167 | 179 | |
| 168 | - // FITS unable column type | |
| 180 | + // FITS unknown column type | |
| 169 | 181 | class fits_unknown_coltype : public GExceptionHandler { |
| 170 | 182 | public: |
| 171 | 183 | fits_unknown_coltype(string origin, int type); | ... | ... |
include/GLATResponse.hpp
| ... | ... | @@ -74,13 +74,13 @@ public: |
| 74 | 74 | |
| 75 | 75 | private: |
| 76 | 76 | // Private methods |
| 77 | - void init_members(void); | |
| 78 | - void copy_members(const GLATResponse& rsp); | |
| 79 | - void free_members(void); | |
| 80 | - void init_aeff(void); | |
| 81 | - void init_psf(void); | |
| 82 | - void init_edisp(void); | |
| 83 | - GVector get_fits_column(const GFitsHDU* hdu, const std::string& colname); | |
| 77 | + void init_members(void); | |
| 78 | + void copy_members(const GLATResponse& rsp); | |
| 79 | + void free_members(void); | |
| 80 | + void init_aeff(void); | |
| 81 | + void init_psf(void); | |
| 82 | + void init_edisp(void); | |
| 83 | + GVector get_fits_vector(const GFitsHDU* hdu, const std::string& colname, int row = 0); | |
| 84 | 84 | |
| 85 | 85 | // Private data area |
| 86 | 86 | ... | ... |
src/GException.cpp
| ... | ... | @@ -258,6 +258,26 @@ GException::fits_key_not_found::fits_key_not_found(string origin, string keyname |
| 258 | 258 | |
| 259 | 259 | |
| 260 | 260 | /*************************************************************************** |
| 261 | + * FITS column not found error * | |
| 262 | + ***************************************************************************/ | |
| 263 | +GException::fits_column_not_found::fits_column_not_found(string origin, string colname, int status) | |
| 264 | +{ | |
| 265 | + m_origin = origin; | |
| 266 | + m_message = "Column '" + colname + "' not found in table"; | |
| 267 | +} | |
| 268 | + | |
| 269 | + | |
| 270 | +/*************************************************************************** | |
| 271 | + * FITS HDU not found error * | |
| 272 | + ***************************************************************************/ | |
| 273 | +GException::fits_hdu_not_found::fits_hdu_not_found(string origin, string extname, int status) | |
| 274 | +{ | |
| 275 | + m_origin = origin; | |
| 276 | + m_message = "HDU '" + extname + "' not found in FITS file"; | |
| 277 | +} | |
| 278 | + | |
| 279 | + | |
| 280 | +/*************************************************************************** | |
| 261 | 281 | * Unknown HDU type found * |
| 262 | 282 | ***************************************************************************/ |
| 263 | 283 | GException::fits_unknown_HDU_type::fits_unknown_HDU_type(string origin, int type) | ... | ... |
src/rsp/GLATResponse.cpp
| ... | ... | @@ -13,8 +13,7 @@ |
| 13 | 13 | ***************************************************************************/ |
| 14 | 14 | |
| 15 | 15 | /* __ Includes ___________________________________________________________ */ |
| 16 | -//#include <vector> | |
| 17 | -#include <iostream> // cout, cerr | |
| 16 | +#include <iostream> | |
| 18 | 17 | #include "GException.hpp" |
| 19 | 18 | #include "GVector.hpp" |
| 20 | 19 | #include "GLATResponse.hpp" |
| ... | ... | @@ -24,6 +23,10 @@ |
| 24 | 23 | /* __ Namespaces _________________________________________________________ */ |
| 25 | 24 | |
| 26 | 25 | /* __ Method name definitions ____________________________________________ */ |
| 26 | +#define G_INIT_AEFF "GLATResponse::init_aeff()" | |
| 27 | +#define G_INIT_PSF "GLATResponse::init_psf()" | |
| 28 | +#define G_INIT_EDISP "GLATResponse::init_edisp()" | |
| 29 | +#define G_GET_FITS_VECTOR "GLATResponse::get_fits_vector(const GFitsHDU*, const std::string&, int)" | |
| 27 | 30 | |
| 28 | 31 | /* __ Macros _____________________________________________________________ */ |
| 29 | 32 | |
| ... | ... | @@ -252,26 +255,17 @@ void GLATResponse::init_aeff(void) |
| 252 | 255 | GFits file; |
| 253 | 256 | file.open(m_caldb + "/" + filename); |
| 254 | 257 | |
| 255 | - // Get pointer towards effective area HDU | |
| 258 | + // Get pointer to effective area HDU | |
| 256 | 259 | GFitsHDU* hdu = file.hdu("EFFECTIVE AREA"); |
| 257 | - if (hdu == NULL) { | |
| 258 | - cout << endl << "TEST ERROR: Unable to find HDU <EFFECTIVE AREA>." << endl; | |
| 259 | - throw; | |
| 260 | - } | |
| 261 | - | |
| 262 | - // Get pointers to data columns | |
| 263 | - GFitsTableFltCol* energ_lo = (GFitsTableFltCol*)hdu->column("ENERG_LO"); | |
| 264 | - GFitsTableFltCol* energ_hi = (GFitsTableFltCol*)hdu->column("ENERG_HI"); | |
| 265 | - GFitsTableFltCol* ctheta_lo = (GFitsTableFltCol*)hdu->column("CTHETA_LO"); | |
| 266 | - GFitsTableFltCol* ctheta_hi = (GFitsTableFltCol*)hdu->column("CTHETA_HI"); | |
| 267 | - GFitsTableFltCol* effarea = (GFitsTableFltCol*)hdu->column("EFFAREA"); | |
| 268 | - if (energ_lo == NULL || energ_hi == NULL || | |
| 269 | - ctheta_lo == NULL || ctheta_hi == NULL || effarea == NULL) { | |
| 270 | - cout << endl << "TEST ERROR: Unable to get <EFFECTIVE AREA> columns." << endl; | |
| 271 | - throw; | |
| 272 | - } | |
| 260 | + if (hdu == NULL) | |
| 261 | + throw GException::fits_hdu_not_found(G_INIT_AEFF, "EFFECTIVE AREA"); | |
| 273 | 262 | |
| 274 | - // ... | |
| 263 | + // Get the data | |
| 264 | + GVector energ_lo = get_fits_vector(hdu, "ENERG_LO"); | |
| 265 | + GVector energ_hi = get_fits_vector(hdu, "ENERG_HI"); | |
| 266 | + GVector ctheta_lo = get_fits_vector(hdu, "CTHETA_LO"); | |
| 267 | + GVector ctheta_hi = get_fits_vector(hdu, "CTHETA_HI"); | |
| 268 | + GVector effarea = get_fits_vector(hdu, "EFFAREA"); | |
| 275 | 269 | |
| 276 | 270 | // Return |
| 277 | 271 | return; |
| ... | ... | @@ -291,25 +285,20 @@ void GLATResponse::init_psf(void) |
| 291 | 285 | GFits file; |
| 292 | 286 | file.open(m_caldb + "/" + filename); |
| 293 | 287 | |
| 294 | - // Get pointer towards PSF HDU | |
| 288 | + // Get pointer to PSF HDU | |
| 295 | 289 | GFitsHDU* hdu = file.hdu("RPSF"); |
| 296 | - if (hdu == NULL) { | |
| 297 | - cout << endl << "TEST ERROR: Unable to find HDU <RPSF>." << endl; | |
| 298 | - throw; | |
| 299 | - } | |
| 300 | - | |
| 301 | - // Get data | |
| 302 | - GVector energ_lo = get_fits_column(hdu, "ENERG_LO"); | |
| 303 | -/* | |
| 304 | - GVector energ_hi = get_fits_column(hdu, "ENERG_HI"); | |
| 305 | - GVector ctheta_lo = get_fits_column(hdu, "CTHETA_LO"); | |
| 306 | - GVector ctheta_hi = get_fits_column(hdu, "CTHETA_HI"); | |
| 307 | - GVector ncore = get_fits_column(hdu, "NCORE"); | |
| 308 | - GVector sigma = get_fits_column(hdu, "SIGMA"); | |
| 309 | - GVector gcore = get_fits_column(hdu, "GCORE"); | |
| 310 | - GVector gtail = get_fits_column(hdu, "GTAIL"); | |
| 311 | -*/ | |
| 312 | - // ... | |
| 290 | + if (hdu == NULL) | |
| 291 | + throw GException::fits_hdu_not_found(G_INIT_PSF, "RPSF"); | |
| 292 | + | |
| 293 | + // Get the data | |
| 294 | + GVector energ_lo = get_fits_vector(hdu, "ENERG_LO"); | |
| 295 | + GVector energ_hi = get_fits_vector(hdu, "ENERG_HI"); | |
| 296 | + GVector ctheta_lo = get_fits_vector(hdu, "CTHETA_LO"); | |
| 297 | + GVector ctheta_hi = get_fits_vector(hdu, "CTHETA_HI"); | |
| 298 | + GVector ncore = get_fits_vector(hdu, "NCORE"); | |
| 299 | + GVector sigma = get_fits_vector(hdu, "SIGMA"); | |
| 300 | + GVector gcore = get_fits_vector(hdu, "GCORE"); | |
| 301 | + GVector gtail = get_fits_vector(hdu, "GTAIL"); | |
| 313 | 302 | |
| 314 | 303 | // Return |
| 315 | 304 | return; |
| ... | ... | @@ -331,29 +320,20 @@ void GLATResponse::init_edisp(void) |
| 331 | 320 | |
| 332 | 321 | // Get pointer towards energy dispersion HDU |
| 333 | 322 | GFitsHDU* hdu = file.hdu("ENERGY DISPERSION"); |
| 334 | - if (hdu == NULL) { | |
| 335 | - cout << endl << "TEST ERROR: Unable to find HDU <ENERGY DISPERSION>." << endl; | |
| 336 | - throw; | |
| 337 | - } | |
| 338 | - | |
| 339 | - // Get pointers to data columns | |
| 340 | - GFitsTableFltCol* energ_lo = (GFitsTableFltCol*)hdu->column("ENERG_LO"); | |
| 341 | - GFitsTableFltCol* energ_hi = (GFitsTableFltCol*)hdu->column("ENERG_HI"); | |
| 342 | - GFitsTableFltCol* ctheta_lo = (GFitsTableFltCol*)hdu->column("CTHETA_LO"); | |
| 343 | - GFitsTableFltCol* ctheta_hi = (GFitsTableFltCol*)hdu->column("CTHETA_HI"); | |
| 344 | - GFitsTableFltCol* dnorm = (GFitsTableFltCol*)hdu->column("DNORM"); | |
| 345 | - GFitsTableFltCol* ltail = (GFitsTableFltCol*)hdu->column("LTAIL"); | |
| 346 | - GFitsTableFltCol* rwidth = (GFitsTableFltCol*)hdu->column("RWIDTH"); | |
| 347 | - GFitsTableFltCol* nr2 = (GFitsTableFltCol*)hdu->column("NR2"); | |
| 348 | - GFitsTableFltCol* lt2 = (GFitsTableFltCol*)hdu->column("LT2"); | |
| 349 | - GFitsTableFltCol* rt2 = (GFitsTableFltCol*)hdu->column("RT2"); | |
| 350 | - if (energ_lo == NULL || energ_hi == NULL || | |
| 351 | - ctheta_lo == NULL || ctheta_hi == NULL || | |
| 352 | - dnorm == NULL || ltail == NULL || rwidth == NULL || | |
| 353 | - nr2 == NULL || lt2 == NULL || rt2 == NULL) { | |
| 354 | - cout << endl << "TEST ERROR: Unable to get <ENERGY DISPERSION> columns." << endl; | |
| 355 | - throw; | |
| 356 | - } | |
| 323 | + if (hdu == NULL) | |
| 324 | + throw GException::fits_hdu_not_found(G_INIT_EDISP, "ENERGY DISPERSION"); | |
| 325 | + | |
| 326 | + // Get the data | |
| 327 | + GVector energ_lo = get_fits_vector(hdu, "ENERG_LO"); | |
| 328 | + GVector energ_hi = get_fits_vector(hdu, "ENERG_HI"); | |
| 329 | + GVector ctheta_lo = get_fits_vector(hdu, "CTHETA_LO"); | |
| 330 | + GVector ctheta_hi = get_fits_vector(hdu, "CTHETA_HI"); | |
| 331 | + GVector dnorm = get_fits_vector(hdu, "DNORM"); | |
| 332 | + GVector ltail = get_fits_vector(hdu, "LTAIL"); | |
| 333 | + GVector rwidth = get_fits_vector(hdu, "RWIDTH"); | |
| 334 | + GVector nr2 = get_fits_vector(hdu, "NR2"); | |
| 335 | + GVector lt2 = get_fits_vector(hdu, "LT2"); | |
| 336 | + GVector rt2 = get_fits_vector(hdu, "RT2"); | |
| 357 | 337 | |
| 358 | 338 | // ... |
| 359 | 339 | |
| ... | ... | @@ -418,22 +398,24 @@ void GLATResponse::free_members(void) |
| 418 | 398 | |
| 419 | 399 | |
| 420 | 400 | /*************************************************************************** |
| 421 | - * Load floating point data from column into vector * | |
| 401 | + * Load floating point data from vector column into vector * | |
| 422 | 402 | * ----------------------------------------------------------------------- * |
| 403 | + * All information is stored in the first table row using vector columns. * | |
| 423 | 404 | ***************************************************************************/ |
| 424 | -GVector GLATResponse::get_fits_column(const GFitsHDU* hdu, const std::string& colname) | |
| 405 | +GVector GLATResponse::get_fits_vector(const GFitsHDU* hdu, const std::string& colname, int row) | |
| 425 | 406 | { |
| 426 | - // Get pointer on column | |
| 427 | - GFitsTableFltCol* ptr = (GFitsTableFltCol*)hdu->column(colname); | |
| 407 | + // Get pointer to | |
| 408 | + GFitsTableCol* ptr = hdu->column(colname); | |
| 428 | 409 | if (ptr == NULL) |
| 429 | - throw; | |
| 410 | + throw GException::fits_column_not_found(G_GET_FITS_VECTOR, colname); | |
| 411 | + | |
| 412 | + // Determine number of entries | |
| 413 | + int num = ptr->repeat(); | |
| 430 | 414 | |
| 431 | 415 | // Load data into vector |
| 432 | - int num = ptr->repeat(); | |
| 433 | 416 | GVector data(num); |
| 434 | 417 | for (int i = 0; i < num; ++i) |
| 435 | - data(i) = ptr->real(0,i); | |
| 436 | - cout << data << endl; | |
| 418 | + data(i) = ptr->real(row,i); | |
| 437 | 419 | |
| 438 | 420 | // Return vector |
| 439 | 421 | return data; | ... | ... |