Commit 9a18f090eabb256f78bdafca3086f597fd4bcb23

Authored by Jürgen Knödlseder
1 parent 28bd0159

Fix GSkyMap::publish() bug for empty sky maps (#1835)

ChangeLog
... ... @@ -3,6 +3,7 @@
3 3 * Version 1.2.0 released
4 4 =========================
5 5  
  6 + Fix GSkyMap::publish() bug for empty sky maps (#1835)
6 7 Fix loss of application name and version (#1835)
7 8 Add methods for logging in applications (#1828)
8 9 Fix removal of Python wrappers after make clean (#1826)
... ...
... ... @@ -38,7 +38,7 @@ The parameters for the following methods have been changed:
38 38 - GApplication::log_parameters() now has a mandatory GChatter argument
39 39  
40 40 The return value of the following methods has been changed:
41   -- ...
  41 +- GSkyMap::write() now returns a pointer to GFitsHDU instead of void
42 42  
43 43  
44 44 3. Configuration
... ... @@ -109,7 +109,10 @@ None
109 109  
110 110 12. Sky module
111 111 --------------
112   -None
  112 +The GSkyMap::write() method now returns a pointer to the written GFitsHDU
  113 +object. In case that no sky map is written, for example because none has been
  114 +defined so far, the method returns NONE. The GSkyMap::publish() method will
  115 +detect the NONE value and will do nothing if no sky map exists (#1835).
113 116  
114 117  
115 118 13. Support module
... ...
include/GSkyMap.hpp
... ... @@ -163,7 +163,7 @@ public:
163 163 void save(const GFilename& filename,
164 164 const bool& clobber = false) const;
165 165 void read(const GFitsHDU& hdu);
166   - void write(GFits& file,
  166 + GFitsHDU* write(GFits& file,
167 167 const std::string& extname = "") const;
168 168 void publish(const std::string& name = "") const;
169 169 std::string print(const GChatter& chatter = NORMAL) const;
... ...
pyext/GSkyMap.i
... ... @@ -178,7 +178,7 @@ public:
178 178 void save(const GFilename& filename,
179 179 const bool& clobber = false) const;
180 180 void read(const GFitsHDU& hdu);
181   - void write(GFits& file,
  181 + GFitsHDU* write(GFits& file,
182 182 const std::string& extname = "") const;
183 183 void publish(const std::string& name = "") const;
184 184 };
... ...
src/sky/GSkyMap.cpp
... ... @@ -2072,16 +2072,22 @@ void GSkyMap::read(const GFitsHDU& hdu)
2072 2072 *
2073 2073 * @param[in] file FITS file pointer.
2074 2074 * @param[in] extname Sky map extension name.
  2075 + * @return Pointer to written HDU.
2075 2076 *
2076 2077 * Write the sky map into a FITS file. Optionally, the extension name of
2077   - * the FITS HDU can be specified using the @p extname parameter.
  2078 + * the FITS HDU can be specified using the @p extname parameter. The method
  2079 + * returns a pointer to the appended HDU. If no HDU has been appended, for
  2080 + * example because the sky map is empty, the method will return NULL.
2078 2081 ***************************************************************************/
2079   -void GSkyMap::write(GFits& file, const std::string& extname) const
  2082 +GFitsHDU* GSkyMap::write(GFits& file, const std::string& extname) const
2080 2083 {
  2084 + // Initialise pointer to appended HDU
  2085 + GFitsHDU* hdu_appended = NULL;
  2086 +
2081 2087 // Continue only if we have data to save
2082 2088 if (m_proj != NULL) {
2083 2089  
2084   - // Initialise HDU pointer
  2090 + // Initialise local HDU pointer
2085 2091 GFitsHDU* hdu = NULL;
2086 2092  
2087 2093 // Case A: Skymap is Healpix
... ... @@ -2102,8 +2108,8 @@ void GSkyMap::write(GFits& file, const std::string& extname) const
2102 2108 hdu->extname(extname);
2103 2109 }
2104 2110  
2105   - // Append HDU
2106   - file.append(*hdu);
  2111 + // Append HDU and recover the pointer to the appended HDU
  2112 + hdu_appended = file.append(*hdu);
2107 2113  
2108 2114 // Delete HDU
2109 2115 if (hdu != NULL) delete hdu;
... ... @@ -2112,8 +2118,8 @@ void GSkyMap::write(GFits& file, const std::string& extname) const
2112 2118  
2113 2119 } // endif: we had data to save
2114 2120  
2115   - // Return
2116   - return;
  2121 + // Return pointer to appended HDU
  2122 + return hdu_appended;
2117 2123 }
2118 2124  
2119 2125  
... ... @@ -2123,27 +2129,34 @@ void GSkyMap::write(GFits& file, const std::string& extname) const
2123 2129 * @param[in] name Name of sky map.
2124 2130 *
2125 2131 * Publishes the sky map on a Virtual Observatory Hub. If no Hub is currently
2126   - * active, the method will start a new Hub.
  2132 + * active, the method will start a new Hub. If on sky map has been allocated
  2133 + * the method does nothing.
2127 2134 ***************************************************************************/
2128   -void GSkyMap::publish(const std::string& name) const
  2135 +void GSkyMap::publish(const std::string& name) const
2129 2136 {
2130 2137 // Create FITS file containing the sky map
2131 2138 GFits fits;
2132   - write(fits);
2133 2139  
2134   - // Get last FITS HDU
2135   - GFitsHDU* hdu = fits[fits.size()-1];
  2140 + // Write sky map into FITS file and return a pointer to the written HDU.
  2141 + // This method returns a NULL pointer if no sky map projection exists,
  2142 + // which typically is true for empty sky maps.
  2143 + GFitsHDU* hdu = write(fits);
2136 2144  
2137   - // Optionally set extension name
2138   - if (!name.empty()) {
2139   - hdu->extname(name);
2140   - }
  2145 + // Continue only if HDU pointer is valid
  2146 + if (hdu != NULL) {
  2147 +
  2148 + // Optionally set extension name
  2149 + if (!name.empty()) {
  2150 + hdu->extname(name);
  2151 + }
  2152 +
  2153 + // Create VO Client
  2154 + GVOClient client;
2141 2155  
2142   - // Create VO Client
2143   - GVOClient client;
  2156 + // Publish map using VO client
  2157 + client.publish(*hdu);
2144 2158  
2145   - // Publish map using VO client
2146   - client.publish(*hdu);
  2159 + } // endif: HDU pointer was valid
2147 2160  
2148 2161 // Return
2149 2162 return;
... ... @@ -2153,7 +2166,7 @@ void GSkyMap::publish(const std::string& name) const
2153 2166 /***********************************************************************//**
2154 2167 * @brief Print sky map
2155 2168 *
2156   - * @param[in] chatter Chattiness (defaults to NORMAL).
  2169 + * @param[in] chatter Chattiness.
2157 2170 * @return String containing sky map information.
2158 2171 ***************************************************************************/
2159 2172 std::string GSkyMap::print(const GChatter& chatter) const
... ...