Commit 038953cc93807540d6b9cc57199e959659415081
1 parent
591cfd99
Fix ctbin::save() bug for empty observation container (#1835)
Showing
5 changed files
with
24 additions
and
9 deletions
ChangeLog
| @@ -3,6 +3,7 @@ | @@ -3,6 +3,7 @@ | ||
| 3 | * Version 1.2.0 released | 3 | * Version 1.2.0 released |
| 4 | ======================== | 4 | ======================== |
| 5 | 5 | ||
| 6 | + Fix ctbin::save() bug for empty observation container (#1835) | ||
| 6 | Fix exception when calling ctools clear() methods (#1835) | 7 | Fix exception when calling ctools clear() methods (#1835) |
| 7 | Add support modules to cscripts (#1830) | 8 | Add support modules to cscripts (#1830) |
| 8 | Fix lacking coverage measure for cscripts execution (#1827) | 9 | Fix lacking coverage measure for cscripts execution (#1827) |
NEWS
| @@ -42,6 +42,10 @@ ctbin - CTA event binning | @@ -42,6 +42,10 @@ ctbin - CTA event binning | ||
| 42 | The clear() method now calls GApplication::clear() to conserve the properties | 42 | The clear() method now calls GApplication::clear() to conserve the properties |
| 43 | of the tool (#1835). | 43 | of the tool (#1835). |
| 44 | 44 | ||
| 45 | +The save() method led to a segmentation violation in case it was applied on an | ||
| 46 | +empty ctbin instance, and specifically in case that the instance contains an | ||
| 47 | +empty observation container. This bug has been fixed (#1835). | ||
| 48 | + | ||
| 45 | 49 | ||
| 46 | ctlike - Maximum likelihood fitting | 50 | ctlike - Maximum likelihood fitting |
| 47 | ----------------------------------- | 51 | ----------------------------------- |
src/ctbin/ctbin.cpp
| @@ -304,8 +304,9 @@ void ctbin::save(void) | @@ -304,8 +304,9 @@ void ctbin::save(void) | ||
| 304 | // Get counts cube filename | 304 | // Get counts cube filename |
| 305 | m_outcube = (*this)["outcube"].filename(); | 305 | m_outcube = (*this)["outcube"].filename(); |
| 306 | 306 | ||
| 307 | - // Save only if filename is non-empty | ||
| 308 | - if (!m_outcube.is_empty()) { | 307 | + // Save only if filename is not empty and if there is at least one |
| 308 | + // observation | ||
| 309 | + if (!m_outcube.is_empty() && m_obs.size() > 0) { | ||
| 309 | 310 | ||
| 310 | // Get CTA observation from observation container | 311 | // Get CTA observation from observation container |
| 311 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[0]); | 312 | GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[0]); |
src/support/ctool.cpp
| @@ -276,7 +276,7 @@ void ctool::copy_members(const ctool& app) | @@ -276,7 +276,7 @@ void ctool::copy_members(const ctool& app) | ||
| 276 | void ctool::free_members(void) | 276 | void ctool::free_members(void) |
| 277 | { | 277 | { |
| 278 | // Write separator into logger | 278 | // Write separator into logger |
| 279 | - log_string(TERSE, "\n"); | 279 | + log_string(TERSE, ""); |
| 280 | 280 | ||
| 281 | // Return | 281 | // Return |
| 282 | return; | 282 | return; |
test/test_ctbin.py
| @@ -18,6 +18,7 @@ | @@ -18,6 +18,7 @@ | ||
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # | 19 | # |
| 20 | # ========================================================================== | 20 | # ========================================================================== |
| 21 | +import os | ||
| 21 | import gammalib | 22 | import gammalib |
| 22 | import ctools | 23 | import ctools |
| 23 | from testing import test | 24 | from testing import test |
| @@ -118,14 +119,22 @@ class Test(test): | @@ -118,14 +119,22 @@ class Test(test): | ||
| 118 | self.test_value(bin.cube().size(), 0, | 119 | self.test_value(bin.cube().size(), 0, |
| 119 | 'Check that empty ctbin has an empty counts cube') | 120 | 'Check that empty ctbin has an empty counts cube') |
| 120 | 121 | ||
| 121 | - # Check that saving and publishing does nothing | ||
| 122 | - bin['debug'] = True | 122 | + # Check that saving does not nothing |
| 123 | + bin['logfile'] = 'ctbin_py0.log' | ||
| 123 | bin['outcube'] = 'ctbin_py0.fits' | 124 | bin['outcube'] = 'ctbin_py0.fits' |
| 124 | - #bin.save() # Segfaults, see issue #1835 | ||
| 125 | - #bin.publish() # Segfaults, see issue #1835 | 125 | + bin.logFileOpen() |
| 126 | + bin.save() | ||
| 127 | + self.test_assert(not os.path.isfile('ctbin_py0.fits'), | ||
| 128 | + 'Check that no counts cube has been created') | ||
| 126 | 129 | ||
| 127 | - # Set ctbin parameters | ||
| 128 | - bin = ctools.ctbin() | 130 | + # Check that publishing does not lead to an exception or segfault |
| 131 | + bin.publish() | ||
| 132 | + | ||
| 133 | + # Check that clearing does not lead to an exception or segfault | ||
| 134 | + bin.clear() | ||
| 135 | + | ||
| 136 | + # Now set ctbin parameters | ||
| 137 | + #bin = ctools.ctbin() | ||
| 129 | bin['inobs'] = self._events | 138 | bin['inobs'] = self._events |
| 130 | bin['outcube'] = 'ctbin_py1.fits' | 139 | bin['outcube'] = 'ctbin_py1.fits' |
| 131 | bin['ebinalg'] = 'LOG' | 140 | bin['ebinalg'] = 'LOG' |