diff --git a/ChangeLog b/ChangeLog index 8dd5c6b..8235a78 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * Version 1.2.0 released ========================= + Fix GSkyMap::publish() bug for empty sky maps (#1835) Fix loss of application name and version (#1835) Add methods for logging in applications (#1828) Fix removal of Python wrappers after make clean (#1826) diff --git a/NEWS b/NEWS index 7120986..9f0ebba 100644 --- a/NEWS +++ b/NEWS @@ -38,7 +38,7 @@ The parameters for the following methods have been changed: - GApplication::log_parameters() now has a mandatory GChatter argument The return value of the following methods has been changed: -- ... +- GSkyMap::write() now returns a pointer to GFitsHDU instead of void 3. Configuration @@ -109,7 +109,10 @@ None 12. Sky module -------------- -None +The GSkyMap::write() method now returns a pointer to the written GFitsHDU +object. In case that no sky map is written, for example because none has been +defined so far, the method returns NONE. The GSkyMap::publish() method will +detect the NONE value and will do nothing if no sky map exists (#1835). 13. Support module diff --git a/include/GSkyMap.hpp b/include/GSkyMap.hpp index 9120b50..0298d49 100644 --- a/include/GSkyMap.hpp +++ b/include/GSkyMap.hpp @@ -163,7 +163,7 @@ public: void save(const GFilename& filename, const bool& clobber = false) const; void read(const GFitsHDU& hdu); - void write(GFits& file, + GFitsHDU* write(GFits& file, const std::string& extname = "") const; void publish(const std::string& name = "") const; std::string print(const GChatter& chatter = NORMAL) const; diff --git a/pyext/GSkyMap.i b/pyext/GSkyMap.i index 8b0d8ad..a7c12c1 100644 --- a/pyext/GSkyMap.i +++ b/pyext/GSkyMap.i @@ -178,7 +178,7 @@ public: void save(const GFilename& filename, const bool& clobber = false) const; void read(const GFitsHDU& hdu); - void write(GFits& file, + GFitsHDU* write(GFits& file, const std::string& extname = "") const; void publish(const std::string& name = "") const; }; diff --git a/src/sky/GSkyMap.cpp b/src/sky/GSkyMap.cpp index ca8c42d..12d5a0f 100644 --- a/src/sky/GSkyMap.cpp +++ b/src/sky/GSkyMap.cpp @@ -2072,16 +2072,22 @@ void GSkyMap::read(const GFitsHDU& hdu) * * @param[in] file FITS file pointer. * @param[in] extname Sky map extension name. + * @return Pointer to written HDU. * * Write the sky map into a FITS file. Optionally, the extension name of - * the FITS HDU can be specified using the @p extname parameter. + * the FITS HDU can be specified using the @p extname parameter. The method + * returns a pointer to the appended HDU. If no HDU has been appended, for + * example because the sky map is empty, the method will return NULL. ***************************************************************************/ -void GSkyMap::write(GFits& file, const std::string& extname) const +GFitsHDU* GSkyMap::write(GFits& file, const std::string& extname) const { + // Initialise pointer to appended HDU + GFitsHDU* hdu_appended = NULL; + // Continue only if we have data to save if (m_proj != NULL) { - // Initialise HDU pointer + // Initialise local HDU pointer GFitsHDU* hdu = NULL; // Case A: Skymap is Healpix @@ -2102,8 +2108,8 @@ void GSkyMap::write(GFits& file, const std::string& extname) const hdu->extname(extname); } - // Append HDU - file.append(*hdu); + // Append HDU and recover the pointer to the appended HDU + hdu_appended = file.append(*hdu); // Delete HDU if (hdu != NULL) delete hdu; @@ -2112,8 +2118,8 @@ void GSkyMap::write(GFits& file, const std::string& extname) const } // endif: we had data to save - // Return - return; + // Return pointer to appended HDU + return hdu_appended; } @@ -2123,27 +2129,34 @@ void GSkyMap::write(GFits& file, const std::string& extname) const * @param[in] name Name of sky map. * * Publishes the sky map on a Virtual Observatory Hub. If no Hub is currently - * active, the method will start a new Hub. + * active, the method will start a new Hub. If on sky map has been allocated + * the method does nothing. ***************************************************************************/ -void GSkyMap::publish(const std::string& name) const +void GSkyMap::publish(const std::string& name) const { // Create FITS file containing the sky map GFits fits; - write(fits); - // Get last FITS HDU - GFitsHDU* hdu = fits[fits.size()-1]; + // Write sky map into FITS file and return a pointer to the written HDU. + // This method returns a NULL pointer if no sky map projection exists, + // which typically is true for empty sky maps. + GFitsHDU* hdu = write(fits); - // Optionally set extension name - if (!name.empty()) { - hdu->extname(name); - } + // Continue only if HDU pointer is valid + if (hdu != NULL) { + + // Optionally set extension name + if (!name.empty()) { + hdu->extname(name); + } + + // Create VO Client + GVOClient client; - // Create VO Client - GVOClient client; + // Publish map using VO client + client.publish(*hdu); - // Publish map using VO client - client.publish(*hdu); + } // endif: HDU pointer was valid // Return return; @@ -2153,7 +2166,7 @@ void GSkyMap::publish(const std::string& name) const /***********************************************************************//** * @brief Print sky map * - * @param[in] chatter Chattiness (defaults to NORMAL). + * @param[in] chatter Chattiness. * @return String containing sky map information. ***************************************************************************/ std::string GSkyMap::print(const GChatter& chatter) const