Commit 376dca090c04a21e1bf070e34bf853a4c4e8f702
1 parent
8e99b211
Correctly strip .gz suffix from output file names (#2287)
Showing
6 changed files
with
38 additions
and
63 deletions
ChangeLog
| 1 | -2017-11-28 | |
| 1 | +2018-01-09 | |
| 2 | 2 | |
| 3 | 3 | * Version 1.5.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Correctly strip .gz suffix from output filenames (#2287) | |
| 6 | 7 | Support On/Off analysis in cslightcrv and csphasecrv (#2273) |
| 7 | 8 | Add tutorial for classical analysis (#2267) |
| 8 | 9 | Fix chatter level handling in ctpsfcube (#2262) | ... | ... |
NEWS
| 1 | 1 | New Features and Important Changes in ctools 1.5.0 |
| 2 | 2 | |
| 3 | -28 November 2017 | |
| 3 | +9 January 2018 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | Introduction |
| ... | ... | @@ -103,6 +103,9 @@ The chatter level is now correctly forwarded to the PSF cube fill method (#2262) |
| 103 | 103 | |
| 104 | 104 | ctselect - CTA event selection |
| 105 | 105 | ------------------------------ |
| 106 | +Any .gz suffix is now correctly stripped from the event filenames when creating | |
| 107 | +the output filenames (#2287). | |
| 108 | + | |
| 106 | 109 | Use t-type parameters for "tmin" and "tmax" to all specifying times in various |
| 107 | 110 | formats (#1864). |
| 108 | 111 | ... | ... |
doc/source/admin/release_history/1.5.rst
| ... | ... | @@ -17,6 +17,8 @@ In particular, this release provides: |
| 17 | 17 | Bug fixes |
| 18 | 18 | --------- |
| 19 | 19 | |
| 20 | +* [`2287 <https://cta-redmine.irap.omp.eu/issues/2287>`_] - | |
| 21 | + Correctly strip .gz suffix from output filenames | |
| 20 | 22 | * [`2262 <https://cta-redmine.irap.omp.eu/issues/2262>`_] - |
| 21 | 23 | Fix chatter level handling in :ref:`ctpsfcube` |
| 22 | 24 | ... | ... |
src/ctselect/ctselect.cpp
| ... | ... | @@ -367,7 +367,7 @@ void ctselect::run(void) |
| 367 | 367 | * |
| 368 | 368 | * If m_use_xml is true, all selected event list(s) will be saved into FITS |
| 369 | 369 | * files, where the output filenames are constructued from the input |
| 370 | - * filenames by prepending the m_prefix string to name. Any path information | |
| 370 | + * filenames by prepending the @a prefix string to name. Any path information | |
| 371 | 371 | * will be stripped form the input name, hence event files will be written |
| 372 | 372 | * into the local working directory (unless some path information is present |
| 373 | 373 | * in the prefix). In addition, an XML file will be created that gathers |
| ... | ... | @@ -465,7 +465,6 @@ void ctselect::init_members(void) |
| 465 | 465 | { |
| 466 | 466 | // Initialise parameters |
| 467 | 467 | m_outobs.clear(); |
| 468 | - m_prefix.clear(); | |
| 469 | 468 | m_gti.clear(); |
| 470 | 469 | m_emin = 0.0; |
| 471 | 470 | m_emax = 0.0; |
| ... | ... | @@ -497,7 +496,6 @@ void ctselect::copy_members(const ctselect& app) |
| 497 | 496 | { |
| 498 | 497 | // Copy parameters |
| 499 | 498 | m_outobs = app.m_outobs; |
| 500 | - m_prefix = app.m_prefix; | |
| 501 | 499 | m_gti = app.m_gti; |
| 502 | 500 | m_emin = app.m_emin; |
| 503 | 501 | m_emax = app.m_emax; |
| ... | ... | @@ -653,7 +651,7 @@ void ctselect::get_parameters(void) |
| 653 | 651 | // dumped into the log file |
| 654 | 652 | if (read_ahead()) { |
| 655 | 653 | m_outobs = (*this)["outobs"].filename(); |
| 656 | - m_prefix = (*this)["prefix"].string(); | |
| 654 | + (*this)["prefix"].string(); | |
| 657 | 655 | } |
| 658 | 656 | |
| 659 | 657 | // Set time interval with input times given in CTA reference |
| ... | ... | @@ -1253,35 +1251,6 @@ std::string ctselect::check_infile(const std::string& filename, |
| 1253 | 1251 | |
| 1254 | 1252 | |
| 1255 | 1253 | /***********************************************************************//** |
| 1256 | - * @brief Set output file name. | |
| 1257 | - * | |
| 1258 | - * @param[in] filename Input file name. | |
| 1259 | - * | |
| 1260 | - * Converts an input file name into an output filename by prepending the | |
| 1261 | - * prefix stored in the member m_prefix to the input file name. Any path as | |
| 1262 | - * well as extension will be stripped from the input file name. Also a | |
| 1263 | - * trailing ".gz" will be stripped as one cannot write into gzipped files. | |
| 1264 | - ***************************************************************************/ | |
| 1265 | -std::string ctselect::set_outfile_name(const std::string& filename) const | |
| 1266 | -{ | |
| 1267 | - // Create filename | |
| 1268 | - GFilename fname(filename); | |
| 1269 | - | |
| 1270 | - // Split input filename without any extensions into path elements | |
| 1271 | - std::vector<std::string> elements = gammalib::split(fname.url(), "/"); | |
| 1272 | - | |
| 1273 | - // The last path element is the filename | |
| 1274 | - std::string outname = m_prefix + elements[elements.size()-1]; | |
| 1275 | - | |
| 1276 | - // Strip any ".gz" | |
| 1277 | - outname = gammalib::strip_chars(outname, ".gz"); | |
| 1278 | - | |
| 1279 | - // Return output filename | |
| 1280 | - return outname; | |
| 1281 | -} | |
| 1282 | - | |
| 1283 | - | |
| 1284 | -/***********************************************************************//** | |
| 1285 | 1254 | * @brief Save event list in FITS format. |
| 1286 | 1255 | * |
| 1287 | 1256 | * 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) |
| 1351 | 1320 | { |
| 1352 | 1321 | // Get output filename and prefix |
| 1353 | 1322 | m_outobs = (*this)["outobs"].filename(); |
| 1354 | - m_prefix = (*this)["prefix"].string(); | |
| 1355 | 1323 | |
| 1356 | 1324 | // Issue warning if output filename has no .xml suffix |
| 1357 | 1325 | log_string(TERSE, warn_xml_suffix(m_outobs)); | ... | ... |
src/ctselect/ctselect.hpp
| ... | ... | @@ -76,13 +76,11 @@ protected: |
| 76 | 76 | const GEbounds& ebounds) const; |
| 77 | 77 | std::string check_infile(const std::string& filename, |
| 78 | 78 | const std::string& evtname) const; |
| 79 | - std::string set_outfile_name(const std::string& filename) const; | |
| 80 | 79 | void save_fits(void); |
| 81 | 80 | void save_xml(void); |
| 82 | 81 | |
| 83 | 82 | // User parameters |
| 84 | 83 | std::string m_outobs; //!< Output event list or XML file |
| 85 | - std::string m_prefix; //!< Prefix for multiple event lists | |
| 86 | 84 | GGti m_gti; //!< Time selection |
| 87 | 85 | double m_emin; //!< Lower energy |
| 88 | 86 | double m_emax; //!< Upper energy | ... | ... |
src/support/ctool.cpp
| ... | ... | @@ -958,14 +958,14 @@ void ctool::log_models(const GChatter& chatter, |
| 958 | 958 | * @param[in] pnt Pointing direction. |
| 959 | 959 | * @return Region of Interest. |
| 960 | 960 | * |
| 961 | - * Returns Region of Interest (RoI) from the User parameters "ra", "dec" and | |
| 962 | - * "rad". If any of the parameters "ra", "dec" or "rad" is not valid an | |
| 961 | + * Returns Region of Interest (RoI) from the User parameters `ra`, `dec` and | |
| 962 | + * `rad`. If any of the parameters `ra`, `dec` or `rad` is not valid an | |
| 963 | 963 | * invalid RoI is returned. |
| 964 | 964 | * |
| 965 | - * If the "usepnt" parameter exists and is set to "yes", the RoI centre will | |
| 966 | - * be taken from the specified pointing direction instead of the "ra" and | |
| 967 | - * "dec" parameters. Make sure to provide a valid pointing direction in case | |
| 968 | - * that you want to use the "usepnt" User parameter. | |
| 965 | + * If the `usepnt` parameter exists and is set to `yes`, the RoI centre will | |
| 966 | + * be taken from the specified pointing direction instead of the `ra` and | |
| 967 | + * `dec` parameters. Make sure to provide a valid pointing direction in case | |
| 968 | + * that you want to use the `usepnt` User parameter. | |
| 969 | 969 | ***************************************************************************/ |
| 970 | 970 | GCTARoi ctool::get_roi(const GCTAPointing& pnt) |
| 971 | 971 | { |
| ... | ... | @@ -1016,9 +1016,9 @@ GCTARoi ctool::get_roi(const GCTAPointing& pnt) |
| 1016 | 1016 | * |
| 1017 | 1017 | * @return Energy boundaries. |
| 1018 | 1018 | * |
| 1019 | - * Returns energy boundaries from the User parameters "emin" and "emax". If | |
| 1020 | - * one of "emin" or "emax" is not valid, an empty energy boundaries object | |
| 1021 | - * is returned. If "emin" is not valid, "emax" is not queried. | |
| 1019 | + * Returns energy boundaries from the User parameters `emin` and `emax`. If | |
| 1020 | + * one of `emin` or `emax` is not valid, an empty energy boundaries object | |
| 1021 | + * is returned. If `emin` is not valid, `emax` is not queried. | |
| 1022 | 1022 | ***************************************************************************/ |
| 1023 | 1023 | GEbounds ctool::get_ebounds(void) |
| 1024 | 1024 | { |
| ... | ... | @@ -1051,10 +1051,10 @@ GEbounds ctool::get_ebounds(void) |
| 1051 | 1051 | * |
| 1052 | 1052 | * @return Good Time Intervals. |
| 1053 | 1053 | * |
| 1054 | - * Returns Good Time Intervals from the User parameters "tmin" and "tmax", | |
| 1054 | + * Returns Good Time Intervals from the User parameters `tmin` and `tmax`, | |
| 1055 | 1055 | * taking into account the transformation into the CTA reference time system. |
| 1056 | - * If one of "tmin" or "tmax" is not valid, an empty Good Time Interval | |
| 1057 | - * object is returned. If "tmin" is not valid, "tmax" is not queried. | |
| 1056 | + * If one of `tmin` or `tmax` is not valid, an empty Good Time Interval | |
| 1057 | + * object is returned. If `tmin` is not valid, `tmax` is not queried. | |
| 1058 | 1058 | ***************************************************************************/ |
| 1059 | 1059 | GGti ctool::get_gti(void) |
| 1060 | 1060 | { |
| ... | ... | @@ -1083,7 +1083,7 @@ GGti ctool::get_gti(void) |
| 1083 | 1083 | * |
| 1084 | 1084 | * @return CTA pointing. |
| 1085 | 1085 | * |
| 1086 | - * Returns CTA pointing from the User parameters "ra" and "dec". | |
| 1086 | + * Returns CTA pointing from the User parameters `ra` and `dec`. | |
| 1087 | 1087 | ***************************************************************************/ |
| 1088 | 1088 | GCTAPointing ctool::get_pointing(void) |
| 1089 | 1089 | { |
| ... | ... | @@ -1103,7 +1103,7 @@ GCTAPointing ctool::get_pointing(void) |
| 1103 | 1103 | * |
| 1104 | 1104 | * @return Sky direction. |
| 1105 | 1105 | * |
| 1106 | - * Returns sky direction from the User parameters "ra" and "dec". | |
| 1106 | + * Returns sky direction from the User parameters `ra` and `dec`. | |
| 1107 | 1107 | ***************************************************************************/ |
| 1108 | 1108 | GSkyDir ctool::get_skydir(void) |
| 1109 | 1109 | { |
| ... | ... | @@ -1124,9 +1124,7 @@ GSkyDir ctool::get_skydir(void) |
| 1124 | 1124 | * @brief Set output file name. |
| 1125 | 1125 | * |
| 1126 | 1126 | * @param[in] filename Input file name. |
| 1127 | - * | |
| 1128 | - * Required user parameters: | |
| 1129 | - * prefix | |
| 1127 | + * @return Output file name. | |
| 1130 | 1128 | * |
| 1131 | 1129 | * Converts an input file name into an output filename by prepending the |
| 1132 | 1130 | * 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) |
| 1145 | 1143 | std::vector<std::string> elements = gammalib::split(fname.url(), "/"); |
| 1146 | 1144 | |
| 1147 | 1145 | // The last path element is the filename |
| 1148 | - std::string outname = prefix + elements[elements.size()-1]; | |
| 1149 | - | |
| 1150 | - // Strip any ".gz" | |
| 1151 | - outname = gammalib::strip_chars(outname, ".gz"); | |
| 1146 | + std::string outname = (elements.size() > 0) ? | |
| 1147 | + prefix + elements[elements.size()-1] : ""; | |
| 1148 | + | |
| 1149 | + // Strip any ".gz" from the outname | |
| 1150 | + std::string strip = ".gz"; | |
| 1151 | + std::string::size_type i_start = outname.find(strip); | |
| 1152 | + if (i_start != std::string::npos) { | |
| 1153 | + outname.erase(i_start, strip.length()); | |
| 1154 | + } | |
| 1152 | 1155 | |
| 1153 | 1156 | // Return output filename |
| 1154 | 1157 | return outname; |
| ... | ... | @@ -1160,10 +1163,10 @@ std::string ctool::set_outfile_name(const std::string& filename) |
| 1160 | 1163 | * |
| 1161 | 1164 | * @return True if a stacked analysis should be done. |
| 1162 | 1165 | * |
| 1163 | - * Queries the user parameters "emin", "emax" and "enumbins", and if | |
| 1164 | - * "enumbins" is positive, signal that a stacked analysis is requested. In | |
| 1165 | - * that case, also the "coordsys", "proj", "xref", "yref", "nxpix", "nypix" | |
| 1166 | - * and "binsz" parameters are queried. | |
| 1166 | + * Queries the user parameters `emin`, `emax` and `enumbins`, and if | |
| 1167 | + * `enumbins` is positive, signal that a stacked analysis is requested. In | |
| 1168 | + * that case, also the `coordsys`, `proj`, `xref`, `yref`, `nxpix`, `nypix` | |
| 1169 | + * and `binsz` parameters are queried. | |
| 1167 | 1170 | * |
| 1168 | 1171 | * Using this method assures that the parameters are always queried in the |
| 1169 | 1172 | * same order. | ... | ... |