Commit 63c302a9a40780a171a89ddf59f0b45f6e5959c2

Authored by Michael Mayer
1 parent bb1a2031

Fix bug #1850 (segfault in ctbin), add unit test to test for this case in the future

src/ctbin/ctbin.cpp
@@ -523,9 +523,9 @@ void ctbin::fill_cube(GCTAObservation* obs) @@ -523,9 +523,9 @@ void ctbin::fill_cube(GCTAObservation* obs)
523 // Skip event if the corresponding counts cube energy bin is not 523 // Skip event if the corresponding counts cube energy bin is not
524 // fully contained in the event list energy range. This avoids 524 // fully contained in the event list energy range. This avoids
525 // having partially filled bins. 525 // having partially filled bins.
526 - if (!usage[iebin]) {  
527 - num_outside_ebds++;  
528 - continue; 526 + if (iebin == -1 || !usage[iebin]) {
  527 + num_outside_ebds++;
  528 + continue;
529 } 529 }
530 530
531 // Fill event in skymap 531 // Fill event in skymap
test/test_ctbin.py
@@ -100,6 +100,22 @@ class Test(test): @@ -100,6 +100,22 @@ class Test(test):
100 # Check if execution failed 100 # Check if execution failed
101 self.test_assert(self._execute(cmd) != 0, 101 self.test_assert(self._execute(cmd) != 0,
102 'Check invalid input file when executed from command line') 102 'Check invalid input file when executed from command line')
  103 +
  104 + # Setup ctbin command with different ebounds than input
  105 + cmd = ctbin+' inobs="'+self._events+'"'+ \
  106 + ' outcube="cntmap_cmd3.fits"'+\
  107 + ' emin=0.5 emax=20.0 enumbins=10 ebinalg="LOG"'+ \
  108 + ' nxpix=40 nypix=40 binsz=0.1 coordsys="CEL"'+ \
  109 + ' xref=83.63 yref=22.01 proj="CAR"'+ \
  110 + ' logfile="ctbin_cmd3.log" chatter=3'
  111 +
  112 + # Check if execution was successful
  113 + self.test_value(self._execute(cmd), 0,
  114 + 'Check successful execution from command line')
  115 +
  116 + # Load counts cube and check content.
  117 + evt = gammalib.GCTAEventCube('cntmap_cmd3.fits')
  118 + self._check_cube(evt, 890)
103 119
104 # Setup ctbin --help option 120 # Setup ctbin --help option
105 cmd = ctbin+' --help' 121 cmd = ctbin+' --help'