From 63c302a9a40780a171a89ddf59f0b45f6e5959c2 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Wed, 31 Aug 2016 13:40:43 +0200 Subject: [PATCH] Fix bug #1850 (segfault in ctbin), add unit test to test for this case in the future --- src/ctbin/ctbin.cpp | 6 +++--- test/test_ctbin.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index 1287727..49a88e2 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -523,9 +523,9 @@ void ctbin::fill_cube(GCTAObservation* obs) // Skip event if the corresponding counts cube energy bin is not // fully contained in the event list energy range. This avoids // having partially filled bins. - if (!usage[iebin]) { - num_outside_ebds++; - continue; + if (iebin == -1 || !usage[iebin]) { + num_outside_ebds++; + continue; } // Fill event in skymap diff --git a/test/test_ctbin.py b/test/test_ctbin.py index 352b1e9..3983c4a 100755 --- a/test/test_ctbin.py +++ b/test/test_ctbin.py @@ -100,6 +100,22 @@ class Test(test): # Check if execution failed self.test_assert(self._execute(cmd) != 0, 'Check invalid input file when executed from command line') + + # Setup ctbin command with different ebounds than input + cmd = ctbin+' inobs="'+self._events+'"'+ \ + ' outcube="cntmap_cmd3.fits"'+\ + ' emin=0.5 emax=20.0 enumbins=10 ebinalg="LOG"'+ \ + ' nxpix=40 nypix=40 binsz=0.1 coordsys="CEL"'+ \ + ' xref=83.63 yref=22.01 proj="CAR"'+ \ + ' logfile="ctbin_cmd3.log" chatter=3' + + # Check if execution was successful + self.test_value(self._execute(cmd), 0, + 'Check successful execution from command line') + + # Load counts cube and check content. + evt = gammalib.GCTAEventCube('cntmap_cmd3.fits') + self._check_cube(evt, 890) # Setup ctbin --help option cmd = ctbin+' --help' -- libgit2 0.21.4