Commit db6783fbe41fafa9bebe83c65cbdb3c418f1c792
1 parent
46f728ef
Add filename() method.
The filename() method returns the file name from which information has been loaded or saved. A mutable m_filename member has been created for this that stores the file name in the GArf, GPha and GRmf classes. Tests have been added in the respective test suite to verify the correct functioning of the methods.
Showing
7 changed files
with
143 additions
and
44 deletions
include/GArf.hpp
| ... | ... | @@ -56,17 +56,18 @@ public: |
| 56 | 56 | const double& operator[](const int& index) const; |
| 57 | 57 | |
| 58 | 58 | // Methods |
| 59 | - void clear(void); | |
| 60 | - GArf* clone(void) const; | |
| 61 | - int size(void) const; | |
| 62 | - double& at(const int& index); | |
| 63 | - const double& at(const int& index) const; | |
| 64 | - const GEbounds& ebounds(void) const; | |
| 65 | - void load(const std::string& filename); | |
| 66 | - void save(const std::string& filename, const bool& clobber = false) const; | |
| 67 | - void read(const GFitsTable* hdu); | |
| 68 | - void write(GFits& fits) const; | |
| 69 | - std::string print(const GChatter& chatter = NORMAL) const; | |
| 59 | + void clear(void); | |
| 60 | + GArf* clone(void) const; | |
| 61 | + int size(void) const; | |
| 62 | + double& at(const int& index); | |
| 63 | + const double& at(const int& index) const; | |
| 64 | + const GEbounds& ebounds(void) const; | |
| 65 | + void load(const std::string& filename); | |
| 66 | + void save(const std::string& filename, const bool& clobber = false) const; | |
| 67 | + void read(const GFitsTable* hdu); | |
| 68 | + void write(GFits& fits) const; | |
| 69 | + const std::string& filename(void) const; | |
| 70 | + std::string print(const GChatter& chatter = NORMAL) const; | |
| 70 | 71 | |
| 71 | 72 | protected: |
| 72 | 73 | // Protected methods |
| ... | ... | @@ -75,6 +76,7 @@ protected: |
| 75 | 76 | void free_members(void); |
| 76 | 77 | |
| 77 | 78 | // Protected members |
| 79 | + mutable std::string m_filename; //!< Filename of origin | |
| 78 | 80 | GEbounds m_ebounds; //!< Energy boundaries |
| 79 | 81 | std::vector<double> m_specresp; //!< Spectral response |
| 80 | 82 | }; |
| ... | ... | @@ -135,4 +137,21 @@ const GEbounds& GArf::ebounds(void) const |
| 135 | 137 | return m_ebounds; |
| 136 | 138 | } |
| 137 | 139 | |
| 140 | + | |
| 141 | +/***********************************************************************//** | |
| 142 | + * @brief Return file name | |
| 143 | + * | |
| 144 | + * @return File name from which the ARF information has been read or into | |
| 145 | + * which ARF information has been saved. | |
| 146 | + * | |
| 147 | + * Returns the file name from which the ARF information has been read or into | |
| 148 | + * which ARF information has been saved. The returned string will be empty if | |
| 149 | + * no load() or save() method has been called before. | |
| 150 | + ***************************************************************************/ | |
| 151 | +inline | |
| 152 | +const std::string& GArf::filename(void) const | |
| 153 | +{ | |
| 154 | + return (m_filename); | |
| 155 | +} | |
| 156 | + | |
| 138 | 157 | #endif /* GARF_HPP */ | ... | ... |
include/GPha.hpp
| ... | ... | @@ -57,22 +57,23 @@ public: |
| 57 | 57 | const double& operator[](const int& index) const; |
| 58 | 58 | |
| 59 | 59 | // Methods |
| 60 | - void clear(void); | |
| 61 | - GPha* clone(void) const; | |
| 62 | - int size(void) const; | |
| 63 | - double& at(const int& index); | |
| 64 | - const double& at(const int& index) const; | |
| 65 | - const GEbounds& ebounds(void) const; | |
| 66 | - double counts(void) const; | |
| 67 | - const double& underflow(void) const; | |
| 68 | - const double& overflow(void) const; | |
| 69 | - const double& outflow(void) const; | |
| 70 | - void fill(const GEnergy& energy, const double& value = 1.0); | |
| 71 | - void load(const std::string& filename); | |
| 72 | - void save(const std::string& filename, const bool& clobber = false) const; | |
| 73 | - void read(const GFitsTable* hdu); | |
| 74 | - void write(GFits& fits) const; | |
| 75 | - std::string print(const GChatter& chatter = NORMAL) const; | |
| 60 | + void clear(void); | |
| 61 | + GPha* clone(void) const; | |
| 62 | + int size(void) const; | |
| 63 | + double& at(const int& index); | |
| 64 | + const double& at(const int& index) const; | |
| 65 | + const GEbounds& ebounds(void) const; | |
| 66 | + double counts(void) const; | |
| 67 | + const double& underflow(void) const; | |
| 68 | + const double& overflow(void) const; | |
| 69 | + const double& outflow(void) const; | |
| 70 | + void fill(const GEnergy& energy, const double& value = 1.0); | |
| 71 | + void load(const std::string& filename); | |
| 72 | + void save(const std::string& filename, const bool& clobber = false) const; | |
| 73 | + void read(const GFitsTable* hdu); | |
| 74 | + void write(GFits& fits) const; | |
| 75 | + const std::string& filename(void) const; | |
| 76 | + std::string print(const GChatter& chatter = NORMAL) const; | |
| 76 | 77 | |
| 77 | 78 | protected: |
| 78 | 79 | // Protected methods |
| ... | ... | @@ -81,6 +82,7 @@ protected: |
| 81 | 82 | void free_members(void); |
| 82 | 83 | |
| 83 | 84 | // Protected members |
| 85 | + mutable std::string m_filename; //!< Filename of origin | |
| 84 | 86 | GEbounds m_ebounds; //!< Energy boundaries |
| 85 | 87 | std::vector<double> m_counts; //!< Counts data |
| 86 | 88 | double m_underflow; //!< Number of underflowing events |
| ... | ... | @@ -188,4 +190,21 @@ const double& GPha::outflow(void) const |
| 188 | 190 | return m_outflow; |
| 189 | 191 | } |
| 190 | 192 | |
| 193 | + | |
| 194 | +/***********************************************************************//** | |
| 195 | + * @brief Return file name | |
| 196 | + * | |
| 197 | + * @return File name from which the PHA information has been read or into | |
| 198 | + * which PHA information has been saved. | |
| 199 | + * | |
| 200 | + * Returns the file name from which the PHA information has been read or into | |
| 201 | + * which PHA information has been saved. The returned string will be empty if | |
| 202 | + * no load() or save() method has been called before. | |
| 203 | + ***************************************************************************/ | |
| 204 | +inline | |
| 205 | +const std::string& GPha::filename(void) const | |
| 206 | +{ | |
| 207 | + return (m_filename); | |
| 208 | +} | |
| 209 | + | |
| 191 | 210 | #endif /* GPHA_HPP */ | ... | ... |
include/GRmf.hpp
| ... | ... | @@ -59,20 +59,21 @@ public: |
| 59 | 59 | const double& operator()(const int& itrue, const int& imeasured) const; |
| 60 | 60 | |
| 61 | 61 | // Methods |
| 62 | - void clear(void); | |
| 63 | - GRmf* clone(void) const; | |
| 64 | - int size(void) const; | |
| 65 | - int ntrue(void) const; | |
| 66 | - int nmeasured(void) const; | |
| 67 | - double& at(const int& itrue, const int& imeasured); | |
| 68 | - const double& at(const int& itrue, const int& imeasured) const; | |
| 69 | - const GEbounds& etrue(void) const; | |
| 70 | - const GEbounds& emeasured(void) const; | |
| 71 | - void load(const std::string& filename); | |
| 72 | - void save(const std::string& filename, const bool& clobber = false) const; | |
| 73 | - void read(const GFitsTable* hdu); | |
| 74 | - void write(GFits& fits) const; | |
| 75 | - std::string print(const GChatter& chatter = NORMAL) const; | |
| 62 | + void clear(void); | |
| 63 | + GRmf* clone(void) const; | |
| 64 | + int size(void) const; | |
| 65 | + int ntrue(void) const; | |
| 66 | + int nmeasured(void) const; | |
| 67 | + double& at(const int& itrue, const int& imeasured); | |
| 68 | + const double& at(const int& itrue, const int& imeasured) const; | |
| 69 | + const GEbounds& etrue(void) const; | |
| 70 | + const GEbounds& emeasured(void) const; | |
| 71 | + void load(const std::string& filename); | |
| 72 | + void save(const std::string& filename, const bool& clobber = false) const; | |
| 73 | + void read(const GFitsTable* hdu); | |
| 74 | + void write(GFits& fits) const; | |
| 75 | + const std::string& filename(void) const; | |
| 76 | + std::string print(const GChatter& chatter = NORMAL) const; | |
| 76 | 77 | |
| 77 | 78 | protected: |
| 78 | 79 | // Protected methods |
| ... | ... | @@ -81,9 +82,10 @@ protected: |
| 81 | 82 | void free_members(void); |
| 82 | 83 | |
| 83 | 84 | // Protected members |
| 84 | - GEbounds m_ebds_true; //!< True energy boundaries | |
| 85 | - GEbounds m_ebds_measured; //!< Measured energy boundaries | |
| 86 | - GMatrixSparse m_matrix; //!< Sparse redistribution matrix | |
| 85 | + mutable std::string m_filename; //!< Filename of origin | |
| 86 | + GEbounds m_ebds_true; //!< True energy boundaries | |
| 87 | + GEbounds m_ebds_measured; //!< Measured energy boundaries | |
| 88 | + GMatrixSparse m_matrix; //!< Sparse redistribution matrix | |
| 87 | 89 | |
| 88 | 90 | }; |
| 89 | 91 | |
| ... | ... | @@ -189,4 +191,21 @@ const GEbounds& GRmf::emeasured(void) const |
| 189 | 191 | return m_ebds_measured; |
| 190 | 192 | } |
| 191 | 193 | |
| 194 | + | |
| 195 | +/***********************************************************************//** | |
| 196 | + * @brief Return file name | |
| 197 | + * | |
| 198 | + * @return File name from which the RMF information has been read or into | |
| 199 | + * which RMF information has been saved. | |
| 200 | + * | |
| 201 | + * Returns the file name from which the RMF information has been read or into | |
| 202 | + * which RMF information has been saved. The returned string will be empty if | |
| 203 | + * no load() or save() method has been called before. | |
| 204 | + ***************************************************************************/ | |
| 205 | +inline | |
| 206 | +const std::string& GRmf::filename(void) const | |
| 207 | +{ | |
| 208 | + return (m_filename); | |
| 209 | +} | |
| 210 | + | |
| 192 | 211 | #endif /* GRMF_HPP */ | ... | ... |
src/xspec/GArf.cpp
| ... | ... | @@ -267,6 +267,9 @@ void GArf::load(const std::string& filename) |
| 267 | 267 | // Close FITS file |
| 268 | 268 | file.close(); |
| 269 | 269 | |
| 270 | + // Store filename | |
| 271 | + m_filename = filename; | |
| 272 | + | |
| 270 | 273 | // Return |
| 271 | 274 | return; |
| 272 | 275 | } |
| ... | ... | @@ -289,6 +292,9 @@ void GArf::save(const std::string& filename, const bool& clobber) const |
| 289 | 292 | // Close FITS file |
| 290 | 293 | fits.saveto(filename, clobber); |
| 291 | 294 | |
| 295 | + // Store filename | |
| 296 | + m_filename = filename; | |
| 297 | + | |
| 292 | 298 | // Return |
| 293 | 299 | return; |
| 294 | 300 | } |
| ... | ... | @@ -439,6 +445,7 @@ std::string GArf::print(const GChatter& chatter) const |
| 439 | 445 | void GArf::init_members(void) |
| 440 | 446 | { |
| 441 | 447 | // Initialise members |
| 448 | + m_filename.clear(); | |
| 442 | 449 | m_ebounds.clear(); |
| 443 | 450 | m_specresp.clear(); |
| 444 | 451 | |
| ... | ... | @@ -455,6 +462,7 @@ void GArf::init_members(void) |
| 455 | 462 | void GArf::copy_members(const GArf& arf) |
| 456 | 463 | { |
| 457 | 464 | // Copy members |
| 465 | + m_filename = arf.m_filename; | |
| 458 | 466 | m_ebounds = arf.m_ebounds; |
| 459 | 467 | m_specresp = arf.m_specresp; |
| 460 | 468 | ... | ... |
src/xspec/GPha.cpp
| ... | ... | @@ -347,6 +347,9 @@ void GPha::load(const std::string& filename) |
| 347 | 347 | // Close FITS file |
| 348 | 348 | file.close(); |
| 349 | 349 | |
| 350 | + // Store filename | |
| 351 | + m_filename = filename; | |
| 352 | + | |
| 350 | 353 | // Return |
| 351 | 354 | return; |
| 352 | 355 | } |
| ... | ... | @@ -369,6 +372,9 @@ void GPha::save(const std::string& filename, const bool& clobber) const |
| 369 | 372 | // Close FITS file |
| 370 | 373 | fits.saveto(filename, clobber); |
| 371 | 374 | |
| 375 | + // Store filename | |
| 376 | + m_filename = filename; | |
| 377 | + | |
| 372 | 378 | // Return |
| 373 | 379 | return; |
| 374 | 380 | } |
| ... | ... | @@ -523,6 +529,7 @@ std::string GPha::print(const GChatter& chatter) const |
| 523 | 529 | void GPha::init_members(void) |
| 524 | 530 | { |
| 525 | 531 | // Initialise members |
| 532 | + m_filename.clear(); | |
| 526 | 533 | m_ebounds.clear(); |
| 527 | 534 | m_counts.clear(); |
| 528 | 535 | m_underflow = 0.0; |
| ... | ... | @@ -542,6 +549,7 @@ void GPha::init_members(void) |
| 542 | 549 | void GPha::copy_members(const GPha& pha) |
| 543 | 550 | { |
| 544 | 551 | // Copy members |
| 552 | + m_filename = pha.m_filename; | |
| 545 | 553 | m_ebounds = pha.m_ebounds; |
| 546 | 554 | m_counts = pha.m_counts; |
| 547 | 555 | m_underflow = pha.m_underflow; | ... | ... |
src/xspec/GRmf.cpp
| ... | ... | @@ -284,6 +284,9 @@ void GRmf::load(const std::string& filename) |
| 284 | 284 | // Close FITS file |
| 285 | 285 | file.close(); |
| 286 | 286 | |
| 287 | + // Store filename | |
| 288 | + m_filename = filename; | |
| 289 | + | |
| 287 | 290 | // Return |
| 288 | 291 | return; |
| 289 | 292 | } |
| ... | ... | @@ -306,6 +309,9 @@ void GRmf::save(const std::string& filename, const bool& clobber) const |
| 306 | 309 | // Close FITS file |
| 307 | 310 | fits.saveto(filename, clobber); |
| 308 | 311 | |
| 312 | + // Store filename | |
| 313 | + m_filename = filename; | |
| 314 | + | |
| 309 | 315 | // Return |
| 310 | 316 | return; |
| 311 | 317 | } |
| ... | ... | @@ -549,6 +555,7 @@ std::string GRmf::print(const GChatter& chatter) const |
| 549 | 555 | void GRmf::init_members(void) |
| 550 | 556 | { |
| 551 | 557 | // Initialise members |
| 558 | + m_filename.clear(); | |
| 552 | 559 | m_ebds_true.clear(); |
| 553 | 560 | m_ebds_measured.clear(); |
| 554 | 561 | m_matrix.clear(); |
| ... | ... | @@ -566,6 +573,7 @@ void GRmf::init_members(void) |
| 566 | 573 | void GRmf::copy_members(const GRmf& rmf) |
| 567 | 574 | { |
| 568 | 575 | // Copy members |
| 576 | + m_filename = rmf.m_filename; | |
| 569 | 577 | m_ebds_true = rmf.m_ebds_true; |
| 570 | 578 | m_ebds_measured = rmf.m_ebds_measured; |
| 571 | 579 | m_matrix = rmf.m_matrix; | ... | ... |
test/test_GXspec.cpp
| ... | ... | @@ -102,7 +102,11 @@ void TestGXspec::test_GPha(void) |
| 102 | 102 | |
| 103 | 103 | // Test saving and loading |
| 104 | 104 | pha.save("pha.fits", true); |
| 105 | + test_assert(pha.filename() == "pha.fits", | |
| 106 | + "Unexpected filename \""+pha.filename()+"\"."); | |
| 105 | 107 | pha.load("pha.fits"); |
| 108 | + test_assert(pha.filename() == "pha.fits", | |
| 109 | + "Unexpected filename \""+pha.filename()+"\"."); | |
| 106 | 110 | test_value(pha[0], 5.0, 1.0e-6); |
| 107 | 111 | test_value(pha[1], 3.7, 1.0e-6); |
| 108 | 112 | test_value(pha.counts(), 11.7, 1.0e-6); |
| ... | ... | @@ -120,6 +124,8 @@ void TestGXspec::test_GPha(void) |
| 120 | 124 | |
| 121 | 125 | // Test constructing |
| 122 | 126 | GPha pha2("pha.fits"); |
| 127 | + test_assert(pha2.filename() == "pha.fits", | |
| 128 | + "Unexpected filename \""+pha2.filename()+"\"."); | |
| 123 | 129 | test_value(pha2[0], 5.0, 1.0e-6); |
| 124 | 130 | test_value(pha2[1], 3.7, 1.0e-6); |
| 125 | 131 | test_value(pha2.counts(), 11.7, 1.0e-6); |
| ... | ... | @@ -189,7 +195,11 @@ void TestGXspec::test_GArf(void) |
| 189 | 195 | |
| 190 | 196 | // Test saving and loading |
| 191 | 197 | arf.save("arf.fits", true); |
| 198 | + test_assert(arf.filename() == "arf.fits", | |
| 199 | + "Unexpected filename \""+arf.filename()+"\"."); | |
| 192 | 200 | arf.load("arf.fits"); |
| 201 | + test_assert(arf.filename() == "arf.fits", | |
| 202 | + "Unexpected filename \""+arf.filename()+"\"."); | |
| 193 | 203 | test_value(arf[0], 5.0, 1.0e-6); |
| 194 | 204 | test_value(arf[1], 3.7, 1.0e-6); |
| 195 | 205 | for (int i = 2; i < 9; i += 2) { |
| ... | ... | @@ -203,6 +213,8 @@ void TestGXspec::test_GArf(void) |
| 203 | 213 | |
| 204 | 214 | // Test constructing |
| 205 | 215 | GArf arf2("arf.fits"); |
| 216 | + test_assert(arf2.filename() == "arf.fits", | |
| 217 | + "Unexpected filename \""+arf2.filename()+"\"."); | |
| 206 | 218 | test_value(arf2[0], 5.0, 1.0e-6); |
| 207 | 219 | test_value(arf2[1], 3.7, 1.0e-6); |
| 208 | 220 | for (int i = 2; i < 9; i += 2) { |
| ... | ... | @@ -273,7 +285,11 @@ void TestGXspec::test_GRmf(void) |
| 273 | 285 | |
| 274 | 286 | // Test saving and loading |
| 275 | 287 | rmf.save("rmf.fits", true); |
| 288 | + test_assert(rmf.filename() == "rmf.fits", | |
| 289 | + "Unexpected filename \""+rmf.filename()+"\"."); | |
| 276 | 290 | rmf.load("rmf.fits"); |
| 291 | + test_assert(rmf.filename() == "rmf.fits", | |
| 292 | + "Unexpected filename \""+rmf.filename()+"\"."); | |
| 277 | 293 | /* |
| 278 | 294 | for (int i = 0; i < 9; ++i) { |
| 279 | 295 | for (int k = 0; k < 9; ++k) { |
| ... | ... | @@ -300,6 +316,8 @@ void TestGXspec::test_GRmf(void) |
| 300 | 316 | |
| 301 | 317 | // Test constructing |
| 302 | 318 | GRmf rmf2("rmf.fits"); |
| 319 | + test_assert(rmf2.filename() == "rmf.fits", | |
| 320 | + "Unexpected filename \""+rmf2.filename()+"\"."); | |
| 303 | 321 | for (int i = 0; i < 9; ++i) { |
| 304 | 322 | int k = 0; |
| 305 | 323 | for (; k < i; ++k) { | ... | ... |