Commit e95aad8c60a916646c6589ddadcc28ff9908ca45
1 parent
a35f9317
Moved iniitalisation of private XML instance from run() to constructor
Showing
2 changed files
with
8 additions
and
9 deletions
cscripts/csiactobs.py
| @@ -80,6 +80,10 @@ class csiactobs(ctools.cscript): | @@ -80,6 +80,10 @@ class csiactobs(ctools.cscript): | ||
| 80 | 80 | ||
| 81 | # Initialise application by calling the appropriate class constructor | 81 | # Initialise application by calling the appropriate class constructor |
| 82 | self._init_cscript(argv) | 82 | self._init_cscript(argv) |
| 83 | + | ||
| 84 | + # Append an observation list to XML instance | ||
| 85 | + self._xml.append(gammalib.GXmlElement('observation_list title="observation list"')) | ||
| 86 | + self._xml_obslist = self._xml.element('observation_list', 0) | ||
| 83 | 87 | ||
| 84 | # Return | 88 | # Return |
| 85 | return | 89 | return |
| @@ -555,12 +559,7 @@ class csiactobs(ctools.cscript): | @@ -555,12 +559,7 @@ class csiactobs(ctools.cscript): | ||
| 555 | 559 | ||
| 556 | # Clear models | 560 | # Clear models |
| 557 | self._models.clear() | 561 | self._models.clear() |
| 558 | - | ||
| 559 | - # Clear XML file and append an observation list | ||
| 560 | - self._xml.clear() | ||
| 561 | - self._xml.append(gammalib.GXmlElement('observation_list title="observation list"')) | ||
| 562 | - lib = self._xml.element('observation_list', 0) | ||
| 563 | - | 562 | + |
| 564 | # Log output | 563 | # Log output |
| 565 | msg = 'Looping over %d runs' % len(self._runlist) | 564 | msg = 'Looping over %d runs' % len(self._runlist) |
| 566 | self._log_header1(gammalib.TERSE, msg) | 565 | self._log_header1(gammalib.TERSE, msg) |
| @@ -709,7 +708,7 @@ class csiactobs(ctools.cscript): | @@ -709,7 +708,7 @@ class csiactobs(ctools.cscript): | ||
| 709 | run_emax.TeV())) | 708 | run_emax.TeV())) |
| 710 | 709 | ||
| 711 | # Append observation to XML and set attributes | 710 | # Append observation to XML and set attributes |
| 712 | - obs = lib.append('observation') | 711 | + obs = self._xml_obslist.append('observation') |
| 713 | obs.attribute('name', object_name) | 712 | obs.attribute('name', object_name) |
| 714 | obs.attribute('id', str(obs_id)) | 713 | obs.attribute('id', str(obs_id)) |
| 715 | obs.attribute('instrument', telescope) | 714 | obs.attribute('instrument', telescope) |
| @@ -764,7 +763,7 @@ class csiactobs(ctools.cscript): | @@ -764,7 +763,7 @@ class csiactobs(ctools.cscript): | ||
| 764 | self._write_summary() | 763 | self._write_summary() |
| 765 | 764 | ||
| 766 | # Write warning in no observation could be used from runlist | 765 | # Write warning in no observation could be used from runlist |
| 767 | - if lib.size() == 0: | 766 | + if self._xml_obslist.size() == 0: |
| 768 | self._log_string(gammalib.NORMAL, 'WARNING: No observation was ' | 767 | self._log_string(gammalib.NORMAL, 'WARNING: No observation was ' |
| 769 | 'appended from specified runlist') | 768 | 'appended from specified runlist') |
| 770 | 769 |
test/test_csiactobs.py
| @@ -147,7 +147,7 @@ class Test(test): | @@ -147,7 +147,7 @@ class Test(test): | ||
| 147 | iactobs.save() | 147 | iactobs.save() |
| 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) # See #1841 | 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) |