Commit 038953cc93807540d6b9cc57199e959659415081

Authored by Jürgen Knödlseder
1 parent 591cfd99

Fix ctbin::save() bug for empty observation container (#1835)

ChangeLog
... ... @@ -3,6 +3,7 @@
3 3 * Version 1.2.0 released
4 4 ========================
5 5  
  6 + Fix ctbin::save() bug for empty observation container (#1835)
6 7 Fix exception when calling ctools clear() methods (#1835)
7 8 Add support modules to cscripts (#1830)
8 9 Fix lacking coverage measure for cscripts execution (#1827)
... ...
... ... @@ -42,6 +42,10 @@ ctbin - CTA event binning
42 42 The clear() method now calls GApplication::clear() to conserve the properties
43 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 50 ctlike - Maximum likelihood fitting
47 51 -----------------------------------
... ...
src/ctbin/ctbin.cpp
... ... @@ -304,8 +304,9 @@ void ctbin::save(void)
304 304 // Get counts cube filename
305 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 311 // Get CTA observation from observation container
311 312 GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[0]);
... ...
src/support/ctool.cpp
... ... @@ -276,7 +276,7 @@ void ctool::copy_members(const ctool&amp; app)
276 276 void ctool::free_members(void)
277 277 {
278 278 // Write separator into logger
279   - log_string(TERSE, "\n");
  279 + log_string(TERSE, "");
280 280  
281 281 // Return
282 282 return;
... ...
test/test_ctbin.py
... ... @@ -18,6 +18,7 @@
18 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19 #
20 20 # ==========================================================================
  21 +import os
21 22 import gammalib
22 23 import ctools
23 24 from testing import test
... ... @@ -118,14 +119,22 @@ class Test(test):
118 119 self.test_value(bin.cube().size(), 0,
119 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 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 138 bin['inobs'] = self._events
130 139 bin['outcube'] = 'ctbin_py1.fits'
131 140 bin['ebinalg'] = 'LOG'
... ...