From 407d81a12772a429ec8a4b0a1e287336160bedbb Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Mon, 14 Dec 2015 11:55:52 +0100 Subject: [PATCH] Updated ctool.cpp and csobs2caldb to run in the latest GFilename scheme --- cscripts/csobs2caldb.py | 24 +++++++++++++++--------- src/support/ctool.cpp | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/cscripts/csobs2caldb.py b/cscripts/csobs2caldb.py index 13b43cc..45a85ca 100755 --- a/cscripts/csobs2caldb.py +++ b/cscripts/csobs2caldb.py @@ -141,21 +141,27 @@ class csobs2caldb(ctools.cscript): # retrieve response component rsp = self.observation.response() - + # Initialise FITS file fits = gammalib.GFits() + + # Create GFilename instances + fname_aeff = gammalib.GFilename(rsp.aeff().filename()) + fname_psf = gammalib.GFilename(rsp.psf().filename()) + fname_edisp = gammalib.GFilename(rsp.edisp().filename()) + fname_bkg = gammalib.GFilename(rsp.background().filename()) # Open FITS files of response components - fits_aeff = gammalib.GFits(rsp.aeff().filename()) - fits_psf = gammalib.GFits(rsp.psf().filename()) - fits_edisp = gammalib.GFits(rsp.edisp().filename()) - fits_bkg = gammalib.GFits(rsp.background().filename()) + fits_aeff = gammalib.GFits(fname_aeff.filename()) + fits_psf = gammalib.GFits(fname_psf.filename()) + fits_edisp = gammalib.GFits(fname_edisp.filename()) + fits_bkg = gammalib.GFits(fname_bkg.filename()) # Bundle IRFs into one file - fits.append(fits_aeff["EFFECTIVE AREA"]) - fits.append(fits_psf["POINT SPREAD FUNCTION"]) - fits.append(fits_edisp["ENERGY DISPERSION"]) - fits.append(fits_bkg["BACKGROUND"]) + fits.append(fits_aeff[fname_aeff.extname("EFFECTIVE AREA")]) + fits.append(fits_psf[fname_psf.extname("POINT SPREAD FUNCTION")]) + fits.append(fits_edisp[fname_edisp.extname("ENERGY DISPERSION")]) + fits.append(fits_bkg[fname_bkg.extname("BACKGROUND")]) # Return fits file return fits diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index 35b5267..a5c5daa 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -414,26 +414,38 @@ GEbounds ctool::create_ebounds(void) // Get filename std::string ebinfile = (*this)["ebinfile"].filename(); - // Open energy boundary file using the EBOUNDS or ENERGYBINS - // extension. Throw an exception if opening fails. - GFits file(ebinfile); - if (file.contains("EBOUNDS")) { - file.close(); - ebounds.load(ebinfile,"EBOUNDS"); - } - else if (file.contains("ENERGYBINS")) { - file.close(); - ebounds.load(ebinfile,"ENERGYBINS"); + // Create filename instance + GFilename fname(ebinfile); + + // Check if extension name was provided + if (!fname.has_extname()) { + + // Open energy boundary file using the EBOUNDS or ENERGYBINS + // extension. Throw an exception if opening fails. + GFits file(ebinfile); + if (file.contains("EBOUNDS")) { + file.close(); + ebounds.load(ebinfile); + } + else if (file.contains("ENERGYBINS")) { + file.close(); + ebinfile += "[ENERGYBINS]"; + ebounds.load(ebinfile); + } + else { + file.close(); + std::string msg = "No extension with name \"EBOUNDS\" or" + " \"ENERGYBINS\" found in FITS file" + " \""+ebinfile+"\".\n" + "An \"EBOUNDS\" or \"ENERGYBINS\" extension" + " is required if the parameter \"ebinalg\"" + " is set to \"FILE\"."; + throw GException::invalid_value(G_CREATE_EBOUNDS, msg); + } } else { - file.close(); - std::string msg = "No extension with name \"EBOUNDS\" or" - " \"ENERGYBINS\" found in FITS file" - " \""+ebinfile+"\".\n" - "An \"EBOUNDS\" or \"ENERGYBINS\" extension" - " is required if the parameter \"ebinalg\"" - " is set to \"FILE\"."; - throw GException::invalid_value(G_CREATE_EBOUNDS, msg); + // Load ebounds from filename including extension + ebounds.load(ebinfile); } } // endif: ebinalg was "FILE" -- libgit2 0.21.4