From a67e143b779f0e358a5b56885f4aa38eb977ab48 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 24 Feb 2016 15:28:33 +0100 Subject: [PATCH] Read filename task parameters in save() methods, and use GFilename in all classes. --- src/ctbin/ctbin.cpp | 6 +++++- src/ctbkgcube/ctbkgcube.cpp | 10 ++++++++-- src/ctbutterfly/ctbutterfly.cpp | 37 ++++++++++++++++++++++++------------- src/ctbutterfly/ctbutterfly.hpp | 7 ++++--- src/ctcubemask/ctcubemask.cpp | 18 ++++++++++++++---- src/cterror/cterror.cpp | 14 ++++++++++++-- src/ctexpcube/ctexpcube.cpp | 6 +++++- src/ctlike/ctlike.cpp | 14 ++++++++++++-- src/ctlike/ctlike.hpp | 6 +++--- src/ctmodel/ctmodel.cpp | 8 ++++++-- src/ctobssim/ctobssim.cpp | 12 ++++++++++++ src/ctpsfcube/ctpsfcube.cpp | 17 ++++++++++++++--- src/ctpsfcube/ctpsfcube.hpp | 6 +++--- src/ctselect/ctselect.cpp | 10 ++++++---- src/ctskymap/ctskymap.cpp | 7 +++++-- src/cttsmap/cttsmap.cpp | 49 +++++++++++++++++++++++++++++++------------------ 16 files changed, 164 insertions(+), 63 deletions(-) diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index fb79c0d..b169956 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -325,6 +325,9 @@ void ctbin::save(void) log.header1("Save counts cube"); } + // Get counts cube filename + m_outcube = (*this)["outcube"].filename(); + // Save only if filename is non-empty if (!m_outcube.is_empty()) { @@ -336,7 +339,8 @@ void ctbin::save(void) // Log filename if (logTerse()) { - log << "Save \""+m_outcube+"\"." << std::endl; + log << "Save counts cube into file \""+m_outcube+"\"."; + log << std::endl; } // Save cube diff --git a/src/ctbkgcube/ctbkgcube.cpp b/src/ctbkgcube/ctbkgcube.cpp index 85b613a..ad98167 100644 --- a/src/ctbkgcube/ctbkgcube.cpp +++ b/src/ctbkgcube/ctbkgcube.cpp @@ -364,12 +364,17 @@ void ctbkgcube::save(void) log.header1("Save background cube"); } + // Get background cube and model file names + m_outcube = (*this)["outcube"].filename(); + m_outmodel = (*this)["outmodel"].filename(); + // Save only if filename is non-empty if (!m_outcube.is_empty()) { // Log filename if (logTerse()) { - log << "Save \""+m_outcube+"\"." << std::endl; + log << "Save background cube into file \""+m_outcube+"\"."; + log << std::endl; } // Save background cube @@ -383,7 +388,8 @@ void ctbkgcube::save(void) // Log filename if (logTerse()) { - log << "Save \""+m_outmodel.url()+"\"." << std::endl; + log << "Save model into file \""+m_outmodel.url()+"\"."; + log << std::endl; } // Save output model for stacked analyses diff --git a/src/ctbutterfly/ctbutterfly.cpp b/src/ctbutterfly/ctbutterfly.cpp index b63d8c8..deb2a21 100644 --- a/src/ctbutterfly/ctbutterfly.cpp +++ b/src/ctbutterfly/ctbutterfly.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbutterfly - butterfly calculation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2015 by Michael Mayer * + * copyright (C) 2014-2016 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -501,25 +501,36 @@ void ctbutterfly::save(void) // Write header if (logTerse()) { log << std::endl; - log.header1("Save Butterfly to file"); + log.header1("Save Butterfly diagram"); } // Get output filename m_outfile = (*this)["outfile"].filename(); - // Create CSV table with 4 columns - GCsv table(m_energies.size(), 4); + // Save only if filename is non-empty + if (!m_outfile.is_empty()) { - // Fill CSV table - for (int i = 0; i < m_energies.size(); ++i) { - table.real(i, 0, m_energies[i]); - table.real(i, 1, m_intensities[i]); - table.real(i, 2, m_min_intensities[i]); - table.real(i, 3, m_max_intensities[i]); - } + // Log filename + if (logTerse()) { + log << "Save butterfly diagram into file \""+m_outfile+"\"."; + log << std::endl; + } + + // Create CSV table with 4 columns + GCsv table(m_energies.size(), 4); - // Save CSV table - table.save(m_outfile, " ", clobber()); + // Fill CSV table + for (int i = 0; i < m_energies.size(); ++i) { + table.real(i, 0, m_energies[i]); + table.real(i, 1, m_intensities[i]); + table.real(i, 2, m_min_intensities[i]); + table.real(i, 3, m_max_intensities[i]); + } + + // Save CSV table + table.save(m_outfile, " ", clobber()); + + } // Return return; diff --git a/src/ctbutterfly/ctbutterfly.hpp b/src/ctbutterfly/ctbutterfly.hpp index 0002f7f..a7e79c6 100644 --- a/src/ctbutterfly/ctbutterfly.hpp +++ b/src/ctbutterfly/ctbutterfly.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbutterfly - butterfly calculation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2015 by Michael Mayer * + * copyright (C) 2014-2016 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -34,7 +34,7 @@ /* __Definitions _________________________________________________________ */ #define CTBUTTERFLY_NAME "ctbutterfly" -#define CTBUTTERFLY_VERSION "1.0.0" +#define CTBUTTERFLY_VERSION "1.1.0" /***********************************************************************//** @@ -95,7 +95,7 @@ protected: bool m_apply_edisp; //!< Apply energy dispersion? bool m_fit; //!< Do fit? GEbounds m_ebounds; //!< Energy binning definition - std::string m_outfile; //!< Output ascii file + GFilename m_outfile; //!< Output ASCII file name // Protected members GOptimizerLM m_opt; //!< Optimizer @@ -107,6 +107,7 @@ protected: std::vector m_max_intensities; //!< Maximum intensities }; + /***********************************************************************//** * @brief Return observation container * diff --git a/src/ctcubemask/ctcubemask.cpp b/src/ctcubemask/ctcubemask.cpp index 0b47ec7..d390546 100644 --- a/src/ctcubemask/ctcubemask.cpp +++ b/src/ctcubemask/ctcubemask.cpp @@ -324,8 +324,16 @@ void ctcubemask::save(void) } } + // Get counts cube filename + m_outcube = (*this)["outcube"].filename(); + // Case A: Save event file(s) and XML metadata information if (m_use_xml) { + + // Get prefix + m_prefix = (*this)["prefix"].string(); + + // Save XML save_xml(); } @@ -755,9 +763,9 @@ std::string ctcubemask::set_outfile_name(const std::string& filename) const /***********************************************************************//** - * @brief Save counts map in FITS format. + * @brief Save counts cube in FITS format. * - * Save the counts map as a FITS file. The filename of the FITS file is + * Save the counts cube as a FITS file. The filename of the FITS file is * specified by the m_outfile member. ***************************************************************************/ void ctcubemask::save_fits(void) @@ -770,7 +778,8 @@ void ctcubemask::save_fits(void) // Log filename if (logTerse()) { - log << "Save \""+m_outcube+"\"." << std::endl; + log << "Save counts cube into file \""+m_outcube+"\"."; + log << std::endl; } // Save event list @@ -825,7 +834,8 @@ void ctcubemask::save_xml(void) // Log filename if (logTerse()) { - log << "Save \""+outfile+"\"." << std::endl; + log << "Save counts cube into file \""+outfile+"\"."; + log << std::endl; } // Save event list diff --git a/src/cterror/cterror.cpp b/src/cterror/cterror.cpp index 4449400..510a2a1 100644 --- a/src/cterror/cterror.cpp +++ b/src/cterror/cterror.cpp @@ -412,9 +412,19 @@ void cterror::save(void) // Get output filename m_outmodel = (*this)["outmodel"].filename(); - // Write results out as XML model - if (gammalib::toupper(m_outmodel.url()) != "NONE") { + // Save only if filename is non-empty + if (!m_outmodel.is_empty() && + gammalib::toupper(m_outmodel.url()) != "NONE") { + + // Log filename + if (logTerse()) { + log << "Save errors into file \""+m_outmodel+"\"."; + log << std::endl; + } + + // Write results out as XML model m_obs.models().save(m_outmodel); + } // Return diff --git a/src/ctexpcube/ctexpcube.cpp b/src/ctexpcube/ctexpcube.cpp index 6c2c8e8..b0e987f 100644 --- a/src/ctexpcube/ctexpcube.cpp +++ b/src/ctexpcube/ctexpcube.cpp @@ -281,12 +281,16 @@ void ctexpcube::save(void) log.header1("Save exposure cube"); } + // Get exposure cube filename + m_outcube = (*this)["outcube"].filename(); + // Save only if filename is non-empty if (!m_outcube.is_empty()) { // Log filename if (logTerse()) { - log << "Save \""+m_outcube+"\"." << std::endl; + log << "Save exposure cube into file \""+m_outcube+"\"."; + log << std::endl; } // Save exposure cube diff --git a/src/ctlike/ctlike.cpp b/src/ctlike/ctlike.cpp index 43ee690..add2241 100644 --- a/src/ctlike/ctlike.cpp +++ b/src/ctlike/ctlike.cpp @@ -353,9 +353,19 @@ void ctlike::save(void) // Get output filename m_outmodel = (*this)["outmodel"].filename(); - // Write results out as XML model - if (gammalib::toupper(m_outmodel) != "NONE") { + // Save only if filename is non-empty + if (!m_outmodel.is_empty() && + gammalib::toupper(m_outmodel.url()) != "NONE") { + + // Log filename + if (logTerse()) { + log << "Save fitted parameters into file \""+m_outmodel+"\"."; + log << std::endl; + } + + // Write results out as XML model m_obs.models().save(m_outmodel); + } // Return diff --git a/src/ctlike/ctlike.hpp b/src/ctlike/ctlike.hpp index ae3a846..7cd094e 100644 --- a/src/ctlike/ctlike.hpp +++ b/src/ctlike/ctlike.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctlike - Maximum likelihood fitting tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2015 by Juergen Knoedlseder * + * copyright (C) 2010-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -35,7 +35,7 @@ /* __Definitions _________________________________________________________ */ #define CTLIKE_NAME "ctlike" -#define CTLIKE_VERSION "1.0.0" +#define CTLIKE_VERSION "1.1.0" /***********************************************************************//** @@ -74,7 +74,7 @@ protected: // User parameters bool m_refit; //!< Refitting - std::string m_outmodel; //!< Source model output XML file + GFilename m_outmodel; //!< Source model output XML file name bool m_apply_edisp; //!< Apply energy dispersion? bool m_fix_spat_for_ts; //!< Fix spatial parameters for TS computation? diff --git a/src/ctmodel/ctmodel.cpp b/src/ctmodel/ctmodel.cpp index 266f937..45a7445 100644 --- a/src/ctmodel/ctmodel.cpp +++ b/src/ctmodel/ctmodel.cpp @@ -348,12 +348,16 @@ void ctmodel::save(void) log.header1("Save cube"); } + // Get model cube filename + m_outcube = (*this)["outcube"].filename(); + // Save only if filename is non-empty if (!m_outcube.is_empty()) { - // Dump filename + // Log filename if (logTerse()) { - log << "Save \""+m_outcube+"\"." << std::endl; + log << "Save model cube into file \""+m_outcube+"\"."; + log << std::endl; } // Save model cube into FITS file diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index 6a68812..8893fe8 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -1454,6 +1454,12 @@ void ctobssim::save_fits(void) // Get CTA observation from observation container GCTAObservation* obs = dynamic_cast(m_obs[0]); + // Log filename + if (logTerse()) { + log << "Save event list into file \""+m_outevents+"\"."; + log << std::endl; + } + // Save observation into FITS file obs->save(m_outevents, clobber()); @@ -1513,6 +1519,12 @@ void ctobssim::save_xml(void) // Store output file name in observation obs->eventfile(outfile); + // Log filename + if (logTerse()) { + log << "Save event list into file \""+outfile+"\"."; + log << std::endl; + } + // Save observation into FITS file obs->save(outfile, clobber()); diff --git a/src/ctpsfcube/ctpsfcube.cpp b/src/ctpsfcube/ctpsfcube.cpp index 31b9b56..7684358 100644 --- a/src/ctpsfcube/ctpsfcube.cpp +++ b/src/ctpsfcube/ctpsfcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctpsfcube - PSF cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2015 by Chia-Chun Lu * + * copyright (C) 2014-2016 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -276,8 +276,19 @@ void ctpsfcube::save(void) // Get output filename m_outcube = (*this)["outcube"].filename(); - // Save PSF cube - m_psfcube.save(m_outcube, clobber()); + // Save only if filename is non-empty + if (!m_outcube.is_empty()) { + + // Log filename + if (logTerse()) { + log << "Save PSF cube into file \""+m_outcube+"\"."; + log << std::endl; + } + + // Save PSF cube + m_psfcube.save(m_outcube, clobber()); + + } // Return return; diff --git a/src/ctpsfcube/ctpsfcube.hpp b/src/ctpsfcube/ctpsfcube.hpp index d17f006..55d9e49 100644 --- a/src/ctpsfcube/ctpsfcube.hpp +++ b/src/ctpsfcube/ctpsfcube.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctpsfcube - PSF cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2015 by Chia-Chun Lu * + * copyright (C) 2014-2016 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -34,7 +34,7 @@ /* __Definitions _________________________________________________________ */ #define CTPSFCUBE_NAME "ctpsfcube" -#define CTPSFCUBE_VERSION "1.0.0" +#define CTPSFCUBE_VERSION "1.1.0" /***********************************************************************//** @@ -69,7 +69,7 @@ protected: void get_parameters(void); // User parameters - std::string m_outcube; //!< Output PSF cube file + GFilename m_outcube; //!< Output PSF cube file name bool m_apply_edisp; //!< Apply energy dispersion? // Protected members diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index d73c24c..cc5d5a9 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -413,10 +413,10 @@ void ctselect::save(void) if (logTerse()) { log << std::endl; if (m_obs.size() > 1) { - log.header1("Save observations"); + log.header1("Save event lists"); } else { - log.header1("Save observation"); + log.header1("Save event list"); } } @@ -1267,7 +1267,8 @@ void ctselect::save_fits(void) // Log filename if (logTerse()) { - log << "Save \""+outfile+"\"" << std::endl; + log << "Save event list into file \""+outfile+"\"."; + log << std::endl; } // Save event list @@ -1335,7 +1336,8 @@ void ctselect::save_xml(void) // Log filename if (logTerse()) { - log << "Save \""+outfile+"\"" << std::endl; + log << "Save event list into file \""+outfile+"\"."; + log << std::endl; } // Store output file name in observation diff --git a/src/ctskymap/ctskymap.cpp b/src/ctskymap/ctskymap.cpp index 23db30d..65a5c60 100644 --- a/src/ctskymap/ctskymap.cpp +++ b/src/ctskymap/ctskymap.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctskymap - Sky mapping tool * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2015 by Juergen Knoedlseder * + * copyright (C) 2011-2016 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -314,12 +314,15 @@ void ctskymap::save(void) log.header1("Save sky map"); } + // Get sky map filename + m_outmap = (*this)["outmap"].filename(); + // Save only if filename is non-empty if (!m_outmap.is_empty()) { // Log filename if (logTerse()) { - log << "Save \""+m_outmap+"\"." << std::endl; + log << "Save sky map into file \""+m_outmap+"\"." << std::endl; } // Save sky map diff --git a/src/cttsmap/cttsmap.cpp b/src/cttsmap/cttsmap.cpp index bd13524..cca8a2a 100644 --- a/src/cttsmap/cttsmap.cpp +++ b/src/cttsmap/cttsmap.cpp @@ -391,28 +391,41 @@ void cttsmap::save(void) log.header1("Save TS map"); } - // Create fits file - GFits fits; + // Get TS map filename + m_outmap = (*this)["outmap"].filename(); - // Write the sky maps to the FITS file - m_tsmap.write(fits); - for (int i = 0; i < m_mapnames.size(); i++) { - m_maps[i].write(fits); - } + // Save only if filename is non-empty + if (!m_outmap.is_empty()) { - // Set extension name for all maps - for (int i = 0; i < m_mapnames.size(); i++) { - fits[i+1]->extname(m_mapnames[i]); - } + // Log filename + if (logTerse()) { + log << "Save TS map into file \""+m_outmap+"\"." << std::endl; + } - // Add computation log if not all bins are computed - if (m_binmin != -1 || m_binmax != -1) { - m_statusmap.write(fits); - fits[m_mapnames.size()+1]->extname("STATUS MAP"); - } + // Create fits file + GFits fits; + + // Write the sky maps to the FITS file + m_tsmap.write(fits); + for (int i = 0; i < m_mapnames.size(); i++) { + m_maps[i].write(fits); + } + + // Set extension name for all maps + for (int i = 0; i < m_mapnames.size(); i++) { + fits[i+1]->extname(m_mapnames[i]); + } + + // Add computation log if not all bins are computed + if (m_binmin != -1 || m_binmax != -1) { + m_statusmap.write(fits); + fits[m_mapnames.size()+1]->extname("STATUS MAP"); + } + + // Save FITS file + fits.saveto(m_outmap, clobber()); - // Save FITS file - fits.saveto(m_outmap, clobber()); + } // endif: TS map filename was valid // Return return; -- libgit2 0.21.4