Commit bf2d5cb7c0df122f5b17c7af914710cd18e4f153

Authored by Jürgen Knödlseder
2 parents c5362de9 d4ce3358

Merge branch '1841-csiactobs-handle-empty-observations' into integration

# Conflicts:
#	test/test_csiactobs.py
cscripts/csiactobs.py
@@ -85,6 +85,10 @@ class csiactobs(ctools.cscript): @@ -85,6 +85,10 @@ class csiactobs(ctools.cscript):
85 # Initialise application by calling the appropriate class constructor 85 # Initialise application by calling the appropriate class constructor
86 self._init_cscript(argv) 86 self._init_cscript(argv)
87 87
  88 + # Append an observation list to XML instance
  89 + self._xml.append(gammalib.GXmlElement('observation_list title="observation list"'))
  90 + self._xml_obslist = self._xml.element('observation_list', 0)
  91 +
88 # Return 92 # Return
89 return 93 return
90 94
@@ -559,12 +563,7 @@ class csiactobs(ctools.cscript): @@ -559,12 +563,7 @@ class csiactobs(ctools.cscript):
559 563
560 # Clear models 564 # Clear models
561 self._models.clear() 565 self._models.clear()
562 -  
563 - # Clear XML file and append an observation list  
564 - self._xml.clear()  
565 - self._xml.append(gammalib.GXmlElement('observation_list title="observation list"'))  
566 - lib = self._xml.element('observation_list', 0)  
567 - 566 +
568 # Log output 567 # Log output
569 msg = 'Looping over %d runs' % len(self._runlist) 568 msg = 'Looping over %d runs' % len(self._runlist)
570 self._log_header1(gammalib.TERSE, msg) 569 self._log_header1(gammalib.TERSE, msg)
@@ -713,7 +712,7 @@ class csiactobs(ctools.cscript): @@ -713,7 +712,7 @@ class csiactobs(ctools.cscript):
713 run_emax.TeV())) 712 run_emax.TeV()))
714 713
715 # Append observation to XML and set attributes 714 # Append observation to XML and set attributes
716 - obs = lib.append('observation') 715 + obs = self._xml_obslist.append('observation')
717 obs.attribute('name', object_name) 716 obs.attribute('name', object_name)
718 obs.attribute('id', str(obs_id)) 717 obs.attribute('id', str(obs_id))
719 obs.attribute('instrument', telescope) 718 obs.attribute('instrument', telescope)
@@ -768,7 +767,7 @@ class csiactobs(ctools.cscript): @@ -768,7 +767,7 @@ class csiactobs(ctools.cscript):
768 self._write_summary() 767 self._write_summary()
769 768
770 # Write warning in no observation could be used from runlist 769 # Write warning in no observation could be used from runlist
771 - if lib.size() == 0: 770 + if self._xml_obslist.size() == 0:
772 self._log_string(gammalib.NORMAL, 'WARNING: No observation was ' 771 self._log_string(gammalib.NORMAL, 'WARNING: No observation was '
773 'appended from specified runlist') 772 'appended from specified runlist')
774 773
test/test_csiactobs.py
@@ -148,7 +148,7 @@ class Test(test): @@ -148,7 +148,7 @@ class Test(test):
148 148
149 # Check empty observation definition XML file 149 # Check empty observation definition XML file
150 self._check_obsdef('csiactobs_obs_py0.xml', 0) 150 self._check_obsdef('csiactobs_obs_py0.xml', 0)
151 - 151 +
152 # Check empty model definition XML file 152 # Check empty model definition XML file
153 self._check_moddef('csiactobs_bgd_py0.xml', 0) 153 self._check_moddef('csiactobs_bgd_py0.xml', 0)
154 154