Commit a499351c3afdd40ee6d2fe7c6fe2d4cc7ecbd212

Authored by Jürgen Knödlseder
1 parent 2298bda9

Attach response via XML element creation.

Showing 1 changed file with 19 additions and 10 deletions
scripts/csobsdef.py
@@ -227,12 +227,7 @@ class csobsdef(ctools.cscript): @@ -227,12 +227,7 @@ class csobsdef(ctools.cscript):
227 irf = pntdef[row, header.index("irf")] 227 irf = pntdef[row, header.index("irf")]
228 else: 228 else:
229 irf = self["irf"].string() 229 irf = self["irf"].string()
230 - cal = gammalib.GCaldb()  
231 - if gammalib.dir_exists(caldb):  
232 - cal.rootdir(caldb)  
233 - else:  
234 - cal.open("cta", caldb)  
235 - obs.response(irf, cal); 230 + obs = self.__set_response(obs, caldb, irf)
236 231
237 # Set deadtime correction factor 232 # Set deadtime correction factor
238 if "deadc" in header: 233 if "deadc" in header:
@@ -290,12 +285,26 @@ class csobsdef(ctools.cscript): @@ -290,12 +285,26 @@ class csobsdef(ctools.cscript):
290 # Return 285 # Return
291 return 286 return
292 287
293 - def __define_observation(self, header, pntdef, ipnt): 288 + def __set_response(self, obs, caldb, irf):
294 """ 289 """
295 - Define one oberservation. 290 + Set response for an observation. We create an XML element for that
  291 + so that the response XML writer will write the database and response
  292 + name into the observation definition file.
296 """ 293 """
297 - # Create CTA observation  
298 - obs = gammalib.GCTAObservation() 294 + # Create XML element
  295 + xml = gammalib.GXmlElement()
  296 +
  297 + # Append parameter
  298 + parameter = "parameter name=\"Calibration\" database=\""+\
  299 + caldb+"\" response=\""+irf+"\""
  300 + xml.append(gammalib.GXmlElement(parameter))
  301 +
  302 + # Create CTA response
  303 + response = gammalib.GCTAResponseIrf()
  304 + response.read(xml)
  305 +
  306 + # Attach response to observation
  307 + obs.response(response)
299 308
300 # Return observation 309 # Return observation
301 return obs 310 return obs