Commit 407d81a12772a429ec8a4b0a1e287336160bedbb

Authored by Michael Mayer
1 parent a4a41902

Updated ctool.cpp and csobs2caldb to run in the latest GFilename scheme

cscripts/csobs2caldb.py
... ... @@ -141,21 +141,27 @@ class csobs2caldb(ctools.cscript):
141 141  
142 142 # retrieve response component
143 143 rsp = self.observation.response()
144   -
  144 +
145 145 # Initialise FITS file
146 146 fits = gammalib.GFits()
  147 +
  148 + # Create GFilename instances
  149 + fname_aeff = gammalib.GFilename(rsp.aeff().filename())
  150 + fname_psf = gammalib.GFilename(rsp.psf().filename())
  151 + fname_edisp = gammalib.GFilename(rsp.edisp().filename())
  152 + fname_bkg = gammalib.GFilename(rsp.background().filename())
147 153  
148 154 # Open FITS files of response components
149   - fits_aeff = gammalib.GFits(rsp.aeff().filename())
150   - fits_psf = gammalib.GFits(rsp.psf().filename())
151   - fits_edisp = gammalib.GFits(rsp.edisp().filename())
152   - fits_bkg = gammalib.GFits(rsp.background().filename())
  155 + fits_aeff = gammalib.GFits(fname_aeff.filename())
  156 + fits_psf = gammalib.GFits(fname_psf.filename())
  157 + fits_edisp = gammalib.GFits(fname_edisp.filename())
  158 + fits_bkg = gammalib.GFits(fname_bkg.filename())
153 159  
154 160 # Bundle IRFs into one file
155   - fits.append(fits_aeff["EFFECTIVE AREA"])
156   - fits.append(fits_psf["POINT SPREAD FUNCTION"])
157   - fits.append(fits_edisp["ENERGY DISPERSION"])
158   - fits.append(fits_bkg["BACKGROUND"])
  161 + fits.append(fits_aeff[fname_aeff.extname("EFFECTIVE AREA")])
  162 + fits.append(fits_psf[fname_psf.extname("POINT SPREAD FUNCTION")])
  163 + fits.append(fits_edisp[fname_edisp.extname("ENERGY DISPERSION")])
  164 + fits.append(fits_bkg[fname_bkg.extname("BACKGROUND")])
159 165  
160 166 # Return fits file
161 167 return fits
... ...
src/support/ctool.cpp
... ... @@ -414,26 +414,38 @@ GEbounds ctool::create_ebounds(void)
414 414 // Get filename
415 415 std::string ebinfile = (*this)["ebinfile"].filename();
416 416  
417   - // Open energy boundary file using the EBOUNDS or ENERGYBINS
418   - // extension. Throw an exception if opening fails.
419   - GFits file(ebinfile);
420   - if (file.contains("EBOUNDS")) {
421   - file.close();
422   - ebounds.load(ebinfile,"EBOUNDS");
423   - }
424   - else if (file.contains("ENERGYBINS")) {
425   - file.close();
426   - ebounds.load(ebinfile,"ENERGYBINS");
  417 + // Create filename instance
  418 + GFilename fname(ebinfile);
  419 +
  420 + // Check if extension name was provided
  421 + if (!fname.has_extname()) {
  422 +
  423 + // Open energy boundary file using the EBOUNDS or ENERGYBINS
  424 + // extension. Throw an exception if opening fails.
  425 + GFits file(ebinfile);
  426 + if (file.contains("EBOUNDS")) {
  427 + file.close();
  428 + ebounds.load(ebinfile);
  429 + }
  430 + else if (file.contains("ENERGYBINS")) {
  431 + file.close();
  432 + ebinfile += "[ENERGYBINS]";
  433 + ebounds.load(ebinfile);
  434 + }
  435 + else {
  436 + file.close();
  437 + std::string msg = "No extension with name \"EBOUNDS\" or"
  438 + " \"ENERGYBINS\" found in FITS file"
  439 + " \""+ebinfile+"\".\n"
  440 + "An \"EBOUNDS\" or \"ENERGYBINS\" extension"
  441 + " is required if the parameter \"ebinalg\""
  442 + " is set to \"FILE\".";
  443 + throw GException::invalid_value(G_CREATE_EBOUNDS, msg);
  444 + }
427 445 }
428 446 else {
429   - file.close();
430   - std::string msg = "No extension with name \"EBOUNDS\" or"
431   - " \"ENERGYBINS\" found in FITS file"
432   - " \""+ebinfile+"\".\n"
433   - "An \"EBOUNDS\" or \"ENERGYBINS\" extension"
434   - " is required if the parameter \"ebinalg\""
435   - " is set to \"FILE\".";
436   - throw GException::invalid_value(G_CREATE_EBOUNDS, msg);
  447 + // Load ebounds from filename including extension
  448 + ebounds.load(ebinfile);
437 449 }
438 450  
439 451 } // endif: ebinalg was "FILE"
... ...