Commit d27eae6ae0fb84bf2bb85449aa2fd50db9aaef4a
Committed by
nkelhos
1 parent
e3fc2e23
Add GEbounds::emin() and GEbounds::emax() setter methods (#1989)
Showing
6 changed files
with
99 additions
and
13 deletions
ChangeLog
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | * Version 1.3.0 released |
| 4 | 4 | ========================= |
| 5 | 5 | |
| 6 | + Add GEbounds::emin() and GEbounds::emax() setter methods (#1989) | |
| 6 | 7 | Protect GEbounds::set_lin() and set_log() methods from invalid arguments (#1989) |
| 7 | 8 | Copy shared Python libraries instead of creating a symbolic link (#1987) |
| 8 | 9 | Added FITS image conversion operators (#1986) | ... | ... |
NEWS
| ... | ... | @@ -25,11 +25,13 @@ The following classes have been renamed: |
| 25 | 25 | - ... |
| 26 | 26 | |
| 27 | 27 | The following methods have been added: |
| 28 | -- GCTAResponseIrf::rspname | |
| 29 | -- GCTARoi::contains | |
| 30 | -- GCTAEdisp2D::fetch | |
| 31 | -- GEbounds::set | |
| 32 | -- GEnergies::set | |
| 28 | +- GCTAResponseIrf::rspname() | |
| 29 | +- GCTARoi::contains(GCTAInstDir&) | |
| 30 | +- GCTAEdisp2D::fetch() | |
| 31 | +- GEbounds::set(GEnergies&) | |
| 32 | +- GEbounds::emin(int&, GEnergy&) | |
| 33 | +- GEbounds::emax(int&, GEnergy&) | |
| 34 | +- GEnergies::set(GEbounds&) | |
| 33 | 35 | |
| 34 | 36 | The following methods have been removed: |
| 35 | 37 | - ... | ... | ... |
include/GEbounds.hpp
| ... | ... | @@ -103,6 +103,8 @@ public: |
| 103 | 103 | int index(const GEnergy& eng) const; |
| 104 | 104 | const GEnergy& emin(void) const; |
| 105 | 105 | const GEnergy& emax(void) const; |
| 106 | + void emin(const int& index, const GEnergy& energy); | |
| 107 | + void emax(const int& index, const GEnergy& energy); | |
| 106 | 108 | GEnergy emin(const int& index) const; |
| 107 | 109 | GEnergy emax(const int& index) const; |
| 108 | 110 | GEnergy emean(const int& index) const; | ... | ... |
pyext/GEbounds.i
| ... | ... | @@ -77,6 +77,8 @@ public: |
| 77 | 77 | int index(const GEnergy& eng) const; |
| 78 | 78 | const GEnergy& emin(void) const; |
| 79 | 79 | const GEnergy& emax(void) const; |
| 80 | + void emin(const int& index, const GEnergy& energy); | |
| 81 | + void emax(const int& index, const GEnergy& energy); | |
| 80 | 82 | GEnergy emin(const int& index) const; |
| 81 | 83 | GEnergy emax(const int& index) const; |
| 82 | 84 | GEnergy emean(const int& index) const; | ... | ... |
src/obs/GEbounds.cpp
| ... | ... | @@ -46,8 +46,10 @@ |
| 46 | 46 | #define G_READ_XML "GEbounds::read(GXmlElement&)" |
| 47 | 47 | #define G_WRITE_XML "GEbounds::write(GXmlElement&)" |
| 48 | 48 | #define G_REMOVE "GEbounds::remove(int&)" |
| 49 | -#define G_EMIN "GEbounds::emin(int&)" | |
| 50 | -#define G_EMAX "GEbounds::emax(int&)" | |
| 49 | +#define G_EMIN_SET "GEbounds::emin(int&, GEnergy&)" | |
| 50 | +#define G_EMAX_SET "GEbounds::emax(int&, GEnergy&)" | |
| 51 | +#define G_EMIN_GET "GEbounds::emin(int&)" | |
| 52 | +#define G_EMAX_GET "GEbounds::emax(int&)" | |
| 51 | 53 | #define G_EMEAN "GEbounds::emean(int&)" |
| 52 | 54 | #define G_ELOGMEAN "GEbounds::elogmean(int&)" |
| 53 | 55 | #define G_EWIDTH "GEbounds::ewidth(int&)" |
| ... | ... | @@ -977,6 +979,72 @@ int GEbounds::index(const GEnergy& eng) const |
| 977 | 979 | |
| 978 | 980 | |
| 979 | 981 | /***********************************************************************//** |
| 982 | + * @brief Set minimum energy for a given energy interval | |
| 983 | + * | |
| 984 | + * @param[in] index Energy interval index (0,...,size()-1). | |
| 985 | + * @param[in] energy Minimum energy of interval. | |
| 986 | + * | |
| 987 | + * @exception GException::out_of_range | |
| 988 | + * Specified index is out of range. | |
| 989 | + * | |
| 990 | + * Sets the minimum energy for the energy interval @p index. | |
| 991 | + ***************************************************************************/ | |
| 992 | +void GEbounds::emin(const int& index, const GEnergy& energy) | |
| 993 | +{ | |
| 994 | + #if defined(G_RANGE_CHECK) | |
| 995 | + // Throw an exception if index is outside valid range | |
| 996 | + if (index < 0 || index >= m_num) { | |
| 997 | + throw GException::out_of_range(G_EMIN_SET, | |
| 998 | + "Minimum energy of interval", | |
| 999 | + index, m_num); | |
| 1000 | + } | |
| 1001 | + #endif | |
| 1002 | + | |
| 1003 | + // Set minimum energy | |
| 1004 | + m_min[index] = energy; | |
| 1005 | + | |
| 1006 | + // Set attributes | |
| 1007 | + set_attributes(); | |
| 1008 | + | |
| 1009 | + // Return | |
| 1010 | + return; | |
| 1011 | +} | |
| 1012 | + | |
| 1013 | + | |
| 1014 | +/***********************************************************************//** | |
| 1015 | + * @brief Set maximum energy for a given energy interval | |
| 1016 | + * | |
| 1017 | + * @param[in] index Energy interval index (0,...,size()-1). | |
| 1018 | + * @param[in] energy Maximum energy of interval. | |
| 1019 | + * | |
| 1020 | + * @exception GException::out_of_range | |
| 1021 | + * Specified index is out of range. | |
| 1022 | + * | |
| 1023 | + * Sets the maximum energy for the energy interval @p index. | |
| 1024 | + ***************************************************************************/ | |
| 1025 | +void GEbounds::emax(const int& index, const GEnergy& energy) | |
| 1026 | +{ | |
| 1027 | + #if defined(G_RANGE_CHECK) | |
| 1028 | + // Throw an exception if index is outside valid range | |
| 1029 | + if (index < 0 || index >= m_num) { | |
| 1030 | + throw GException::out_of_range(G_EMAX_SET, | |
| 1031 | + "Maximum energy of interval", | |
| 1032 | + index, m_num); | |
| 1033 | + } | |
| 1034 | + #endif | |
| 1035 | + | |
| 1036 | + // Set maximum energy | |
| 1037 | + m_max[index] = energy; | |
| 1038 | + | |
| 1039 | + // Set attributes | |
| 1040 | + set_attributes(); | |
| 1041 | + | |
| 1042 | + // Return | |
| 1043 | + return; | |
| 1044 | +} | |
| 1045 | + | |
| 1046 | + | |
| 1047 | +/***********************************************************************//** | |
| 980 | 1048 | * @brief Returns minimum energy for a given energy interval |
| 981 | 1049 | * |
| 982 | 1050 | * @param[in] index Energy interval index (0,...,size()-1). |
| ... | ... | @@ -988,13 +1056,15 @@ int GEbounds::index(const GEnergy& eng) const |
| 988 | 1056 | GEnergy GEbounds::emin(const int& index) const |
| 989 | 1057 | { |
| 990 | 1058 | #if defined(G_RANGE_CHECK) |
| 991 | - // If index is outside boundary then throw an error | |
| 1059 | + // Throw an exception if index is outside valid range | |
| 992 | 1060 | if (index < 0 || index >= m_num) { |
| 993 | - throw GException::out_of_range(G_EMIN, index, 0, m_num-1); | |
| 1061 | + throw GException::out_of_range(G_EMIN_GET, | |
| 1062 | + "Minimum energy of interval", | |
| 1063 | + index, m_num); | |
| 994 | 1064 | } |
| 995 | 1065 | #endif |
| 996 | 1066 | |
| 997 | - // Return | |
| 1067 | + // Return minimum energy | |
| 998 | 1068 | return (m_min[index]); |
| 999 | 1069 | } |
| 1000 | 1070 | |
| ... | ... | @@ -1011,13 +1081,15 @@ GEnergy GEbounds::emin(const int& index) const |
| 1011 | 1081 | GEnergy GEbounds::emax(const int& index) const |
| 1012 | 1082 | { |
| 1013 | 1083 | #if defined(G_RANGE_CHECK) |
| 1014 | - // If index is outside boundary then throw an error | |
| 1084 | + // Throw an exception if index is outside valid range | |
| 1015 | 1085 | if (index < 0 || index >= m_num) { |
| 1016 | - throw GException::out_of_range(G_EMAX, index, 0, m_num-1); | |
| 1086 | + throw GException::out_of_range(G_EMAX_GET, | |
| 1087 | + "Maximum energy of interval", | |
| 1088 | + index, m_num); | |
| 1017 | 1089 | } |
| 1018 | 1090 | #endif |
| 1019 | 1091 | |
| 1020 | - // Return | |
| 1092 | + // Return maximum energy | |
| 1021 | 1093 | return (m_max[index]); |
| 1022 | 1094 | } |
| 1023 | 1095 | ... | ... |
test/test_GObservation.cpp
| ... | ... | @@ -356,6 +356,13 @@ void TestGObservation::test_ebounds(void) |
| 356 | 356 | test_value(ebds2.emin().MeV(), 1.0, 1.0e-10, "GEnergies constructor (1 element)"); |
| 357 | 357 | test_value(ebds2.emax().MeV(), 1.0, 1.0e-10, "GEnergies constructor (1 element)"); |
| 358 | 358 | |
| 359 | + // Check energy boundary setter method | |
| 360 | + ebds2.emin(0, GEnergy(123.0, "MeV")); | |
| 361 | + ebds2.emax(0, GEnergy(511.0, "MeV")); | |
| 362 | + test_value(ebds2.size(), 1, "Energy boundary setter"); | |
| 363 | + test_value(ebds2.emin().MeV(), 123.0, 1.0e-10, "Energy boundary setter"); | |
| 364 | + test_value(ebds2.emax().MeV(), 511.0, 1.0e-10, "Energy boundary setter"); | |
| 365 | + | |
| 359 | 366 | // Return |
| 360 | 367 | return; |
| 361 | 368 | } | ... | ... |