From 376dca090c04a21e1bf070e34bf853a4c4e8f702 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 9 Jan 2018 09:49:59 +0100 Subject: [PATCH] Correctly strip .gz suffix from output file names (#2287) --- ChangeLog | 3 ++- NEWS | 5 ++++- doc/source/admin/release_history/1.5.rst | 2 ++ src/ctselect/ctselect.cpp | 36 ++---------------------------------- src/ctselect/ctselect.hpp | 2 -- src/support/ctool.cpp | 53 ++++++++++++++++++++++++++++------------------------- 6 files changed, 38 insertions(+), 63 deletions(-) diff --git a/ChangeLog b/ChangeLog index e0d47a6..fb95ce9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2017-11-28 +2018-01-09 * Version 1.5.0 released ======================== + Correctly strip .gz suffix from output filenames (#2287) Support On/Off analysis in cslightcrv and csphasecrv (#2273) Add tutorial for classical analysis (#2267) Fix chatter level handling in ctpsfcube (#2262) diff --git a/NEWS b/NEWS index 6f2e36c..6cc5cd4 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.5.0 -28 November 2017 +9 January 2018 Introduction @@ -103,6 +103,9 @@ The chatter level is now correctly forwarded to the PSF cube fill method (#2262) ctselect - CTA event selection ------------------------------ +Any .gz suffix is now correctly stripped from the event filenames when creating +the output filenames (#2287). + Use t-type parameters for "tmin" and "tmax" to all specifying times in various formats (#1864). diff --git a/doc/source/admin/release_history/1.5.rst b/doc/source/admin/release_history/1.5.rst index 56d2c13..b23d1f9 100644 --- a/doc/source/admin/release_history/1.5.rst +++ b/doc/source/admin/release_history/1.5.rst @@ -17,6 +17,8 @@ In particular, this release provides: Bug fixes --------- +* [`2287 `_] - + Correctly strip .gz suffix from output filenames * [`2262 `_] - Fix chatter level handling in :ref:`ctpsfcube` diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index 47b3e30..a344ea7 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -367,7 +367,7 @@ void ctselect::run(void) * * If m_use_xml is true, all selected event list(s) will be saved into FITS * files, where the output filenames are constructued from the input - * filenames by prepending the m_prefix string to name. Any path information + * filenames by prepending the @a prefix string to name. Any path information * will be stripped form the input name, hence event files will be written * into the local working directory (unless some path information is present * in the prefix). In addition, an XML file will be created that gathers @@ -465,7 +465,6 @@ void ctselect::init_members(void) { // Initialise parameters m_outobs.clear(); - m_prefix.clear(); m_gti.clear(); m_emin = 0.0; m_emax = 0.0; @@ -497,7 +496,6 @@ void ctselect::copy_members(const ctselect& app) { // Copy parameters m_outobs = app.m_outobs; - m_prefix = app.m_prefix; m_gti = app.m_gti; m_emin = app.m_emin; m_emax = app.m_emax; @@ -653,7 +651,7 @@ void ctselect::get_parameters(void) // dumped into the log file if (read_ahead()) { m_outobs = (*this)["outobs"].filename(); - m_prefix = (*this)["prefix"].string(); + (*this)["prefix"].string(); } // Set time interval with input times given in CTA reference @@ -1253,35 +1251,6 @@ std::string ctselect::check_infile(const std::string& filename, /***********************************************************************//** - * @brief Set output file name. - * - * @param[in] filename Input file name. - * - * Converts an input file name into an output filename by prepending the - * prefix stored in the member m_prefix to the input file name. Any path as - * well as extension will be stripped from the input file name. Also a - * trailing ".gz" will be stripped as one cannot write into gzipped files. - ***************************************************************************/ -std::string ctselect::set_outfile_name(const std::string& filename) const -{ - // Create filename - GFilename fname(filename); - - // Split input filename without any extensions into path elements - std::vector elements = gammalib::split(fname.url(), "/"); - - // The last path element is the filename - std::string outname = m_prefix + elements[elements.size()-1]; - - // Strip any ".gz" - outname = gammalib::strip_chars(outname, ".gz"); - - // Return output filename - return outname; -} - - -/***********************************************************************//** * @brief Save event list in FITS format. * * Save the event list as a FITS file. The file name of the FITS file is @@ -1351,7 +1320,6 @@ void ctselect::save_xml(void) { // Get output filename and prefix m_outobs = (*this)["outobs"].filename(); - m_prefix = (*this)["prefix"].string(); // Issue warning if output filename has no .xml suffix log_string(TERSE, warn_xml_suffix(m_outobs)); diff --git a/src/ctselect/ctselect.hpp b/src/ctselect/ctselect.hpp index de3a264..decc450 100644 --- a/src/ctselect/ctselect.hpp +++ b/src/ctselect/ctselect.hpp @@ -76,13 +76,11 @@ protected: const GEbounds& ebounds) const; std::string check_infile(const std::string& filename, const std::string& evtname) const; - std::string set_outfile_name(const std::string& filename) const; void save_fits(void); void save_xml(void); // User parameters std::string m_outobs; //!< Output event list or XML file - std::string m_prefix; //!< Prefix for multiple event lists GGti m_gti; //!< Time selection double m_emin; //!< Lower energy double m_emax; //!< Upper energy diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index bd6922a..027d386 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -958,14 +958,14 @@ void ctool::log_models(const GChatter& chatter, * @param[in] pnt Pointing direction. * @return Region of Interest. * - * Returns Region of Interest (RoI) from the User parameters "ra", "dec" and - * "rad". If any of the parameters "ra", "dec" or "rad" is not valid an + * Returns Region of Interest (RoI) from the User parameters `ra`, `dec` and + * `rad`. If any of the parameters `ra`, `dec` or `rad` is not valid an * invalid RoI is returned. * - * If the "usepnt" parameter exists and is set to "yes", the RoI centre will - * be taken from the specified pointing direction instead of the "ra" and - * "dec" parameters. Make sure to provide a valid pointing direction in case - * that you want to use the "usepnt" User parameter. + * If the `usepnt` parameter exists and is set to `yes`, the RoI centre will + * be taken from the specified pointing direction instead of the `ra` and + * `dec` parameters. Make sure to provide a valid pointing direction in case + * that you want to use the `usepnt` User parameter. ***************************************************************************/ GCTARoi ctool::get_roi(const GCTAPointing& pnt) { @@ -1016,9 +1016,9 @@ GCTARoi ctool::get_roi(const GCTAPointing& pnt) * * @return Energy boundaries. * - * Returns energy boundaries from the User parameters "emin" and "emax". If - * one of "emin" or "emax" is not valid, an empty energy boundaries object - * is returned. If "emin" is not valid, "emax" is not queried. + * Returns energy boundaries from the User parameters `emin` and `emax`. If + * one of `emin` or `emax` is not valid, an empty energy boundaries object + * is returned. If `emin` is not valid, `emax` is not queried. ***************************************************************************/ GEbounds ctool::get_ebounds(void) { @@ -1051,10 +1051,10 @@ GEbounds ctool::get_ebounds(void) * * @return Good Time Intervals. * - * Returns Good Time Intervals from the User parameters "tmin" and "tmax", + * Returns Good Time Intervals from the User parameters `tmin` and `tmax`, * taking into account the transformation into the CTA reference time system. - * If one of "tmin" or "tmax" is not valid, an empty Good Time Interval - * object is returned. If "tmin" is not valid, "tmax" is not queried. + * If one of `tmin` or `tmax` is not valid, an empty Good Time Interval + * object is returned. If `tmin` is not valid, `tmax` is not queried. ***************************************************************************/ GGti ctool::get_gti(void) { @@ -1083,7 +1083,7 @@ GGti ctool::get_gti(void) * * @return CTA pointing. * - * Returns CTA pointing from the User parameters "ra" and "dec". + * Returns CTA pointing from the User parameters `ra` and `dec`. ***************************************************************************/ GCTAPointing ctool::get_pointing(void) { @@ -1103,7 +1103,7 @@ GCTAPointing ctool::get_pointing(void) * * @return Sky direction. * - * Returns sky direction from the User parameters "ra" and "dec". + * Returns sky direction from the User parameters `ra` and `dec`. ***************************************************************************/ GSkyDir ctool::get_skydir(void) { @@ -1124,9 +1124,7 @@ GSkyDir ctool::get_skydir(void) * @brief Set output file name. * * @param[in] filename Input file name. - * - * Required user parameters: - * prefix + * @return Output file name. * * Converts an input file name into an output filename by prepending the * prefix specified by the `prefix` parameter to the input file name. Any @@ -1145,10 +1143,15 @@ std::string ctool::set_outfile_name(const std::string& filename) std::vector elements = gammalib::split(fname.url(), "/"); // The last path element is the filename - std::string outname = prefix + elements[elements.size()-1]; - - // Strip any ".gz" - outname = gammalib::strip_chars(outname, ".gz"); + std::string outname = (elements.size() > 0) ? + prefix + elements[elements.size()-1] : ""; + + // Strip any ".gz" from the outname + std::string strip = ".gz"; + std::string::size_type i_start = outname.find(strip); + if (i_start != std::string::npos) { + outname.erase(i_start, strip.length()); + } // Return output filename return outname; @@ -1160,10 +1163,10 @@ std::string ctool::set_outfile_name(const std::string& filename) * * @return True if a stacked analysis should be done. * - * Queries the user parameters "emin", "emax" and "enumbins", and if - * "enumbins" is positive, signal that a stacked analysis is requested. In - * that case, also the "coordsys", "proj", "xref", "yref", "nxpix", "nypix" - * and "binsz" parameters are queried. + * Queries the user parameters `emin`, `emax` and `enumbins`, and if + * `enumbins` is positive, signal that a stacked analysis is requested. In + * that case, also the `coordsys`, `proj`, `xref`, `yref`, `nxpix`, `nypix` + * and `binsz` parameters are queried. * * Using this method assures that the parameters are always queried in the * same order. -- libgit2 0.21.4