GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GException_sky.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GException_sky.cpp - sky exception handlers *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2020 by Jurgen Knodlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GException_sky.cpp
23  * @brief Sky module exception classes implementation
24  * @author J. Knodlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GException.hpp"
32 #include "GTools.hpp"
33 
34 
35 /***********************************************************************//**
36  * @brief General GSkyMap error
37  *
38  * @param[in] origin Method that throws the error.
39  * @param[in] message Error message.
40  ***************************************************************************/
41 GException::skymap::skymap(std::string origin,
42  std::string message)
43 {
44  // Set origin and message
45  m_origin = origin;
46  m_message = message;
47 
48  // Return
49  return;
50 }
51 
52 
53 /***********************************************************************//**
54  * @brief Bad sky map parameter
55  *
56  * @param[in] origin Method that throws the error.
57  * @param[in] par Map parameter.
58  * @param[in] message Error message.
59  ***************************************************************************/
61  int par,
62  std::string message)
63 {
64  // Set origin and message
65  m_origin = origin;
66  m_message = "Invalid map parameter ("+gammalib::str(par)+"). " + message;
67 
68  // Return
69  return;
70 }
71 
72 
73 /***********************************************************************//**
74  * @brief Incompatible data size
75  *
76  * @param[in] origin Method that throws the error.
77  * @param[in] size Encountered data size.
78  * @param[in] expected Expected data size.
79  * @param[in] message Error message.
80  ***************************************************************************/
82  int size,
83  int expected,
84  std::string message)
85 {
86  // Set origin and message
87  m_origin = origin;
88  m_message = "Data size ("+gammalib::str(size)+") is incompatible with "
89  "expected size ("+gammalib::str(expected)+"). " + message;
90 
91  // Return
92  return;
93 }
94 
95 
96 /***********************************************************************//**
97  * @brief Incompatible ctype keywords
98  *
99  * @param[in] origin Method that throws the error.
100  * @param[in] ctype1 Encountered ctype1 keyword.
101  * @param[in] ctype2 Encountered ctype2 keyword.
102  * @param[in] message Error message.
103  ***************************************************************************/
105  std::string ctype1,
106  std::string ctype2,
107  std::string message)
108 {
109  // Set origin and message
110  m_origin = origin;
111  m_message = "CTYPE1 "+ctype1+") and CTYPE2 ("+ctype2+") header keywords"
112  " are not compatible. " + message;
113 
114  // Return
115  return;
116 }
117 
118 
119 /***********************************************************************//**
120  * @brief Bad image dimension
121  *
122  * @param[in] origin Method that throws the error.
123  * @param[in] naxis Encountered number of axes.
124  * @param[in] message Error message.
125  ***************************************************************************/
127  int naxis,
128  std::string message)
129 {
130  // Set origin and message
131  m_origin = origin;
132  m_message = "Invalid number of image dimensions (naxis="+gammalib::str(naxis)+")."
133  " " + message;
134 
135  // Return
136  return;
137 }
138 
139 
140 /***********************************************************************//**
141  * @brief General GWcs error
142  *
143  * @param[in] origin Method that throws the error.
144  * @param[in] message Error message.
145  ***************************************************************************/
146 GException::wcs::wcs(std::string origin,
147  std::string message)
148 {
149  // Set origin and message
150  m_origin = origin;
151  m_message = message;
152 
153  // Return
154  return;
155 }
156 
157 
158 /***********************************************************************//**
159  * @brief Invalid WCS code
160  *
161  * @param[in] origin Method that throws the error.
162  * @param[in] wcs WCS.
163  * @param[in] message Optional error message.
164  ***************************************************************************/
166  std::string wcs,
167  std::string message)
168 {
169  // Set origin and message
170  m_origin = origin;
171  m_message = "Invalid World Coordinate System code ("+wcs+"). " + message;
172 
173  // Return
174  return;
175 }
176 
177 
178 /***********************************************************************//**
179  * @brief Coordinate system invalid
180  *
181  * @param[in] origin Method that throws the error.
182  * @param[in] coordsys Specified coordinate system.
183  ***************************************************************************/
185  std::string coordsys)
186 {
187  // Set origin and message
188  m_origin = origin;
189  m_message = "Invalid WCS coordinate system ("+coordsys+"). "
190  "Should be one of CEL/GAL/ECL/HEL/SGL.";
191 
192  // Return
193  return;
194 }
195 
196 
197 /***********************************************************************//**
198  * @brief No projection function declared
199  *
200  * @param[in] origin Method that throws the error.
201  * @param[in] message Optional error message.
202  ***************************************************************************/
204  std::string message)
205 {
206  // Set origin and message
207  m_origin = origin;
208  m_message = "No projection function declared. " + message;
209 
210  // Return
211  return;
212 }
213 
214 
215 /***********************************************************************//**
216  * @brief Healpix resolution invalid
217  *
218  * @param[in] origin Method that throws the error.
219  * @param[in] nside Specified nside parameter.
220  ***************************************************************************/
222  int nside)
223 {
224  // Set origin and message
225  m_origin = origin;
226  m_message = "Invalid Healpix nside value ("+gammalib::str(nside)+"). "
227  "Should be one of 1,2,4,8,16,32,64,128,256,512,1024,2048,"
228  "4096,8192.";
229 
230  // Return
231  return;
232 }
233 
234 
235 /***********************************************************************//**
236  * @brief Healpix pixel ordering invalid
237  *
238  * @param[in] origin Method that throws the error.
239  * @param[in] ordering Specified pixel ordering.
240  ***************************************************************************/
242  std::string ordering)
243 {
244  // Set origin and message
245  m_origin = origin;
246  m_message = "Invalid pixel ordering ("+ordering+"). "
247  "Should be either 'RING' or 'NESTED'.";
248 
249  // Return
250  return;
251 }
252 
253 
254 /***********************************************************************//**
255  * @brief Singular matrix encountered
256  *
257  * @param[in] origin Method that throws the error.
258  * @param[in] naxis Matrix size (naxis*naxis).
259  * @param[in] mat Matrix (stored in vector).
260  ***************************************************************************/
262  int naxis,
263  const std::vector<double>& mat)
264 {
265  // Set origin and message
266  m_origin = origin;
267  m_message = "Singular matrix encountered: mat=[";
268  for (int i = 0, ij = 0; i < naxis; ++i) {
269  if (i > 0) {
270  m_message += ",";
271  }
272  m_message += "[";
273  for (int j = 0; j < naxis; ++j, ++ij) {
274  if (j > 0) {
275  m_message += ",";
276  }
277  if (ij < mat.size()) {
278  m_message += gammalib::str(mat[ij]);
279  }
280  else {
281  m_message += " ... ";
282  }
283  }
284  m_message += "]";
285  }
286  m_message += "].";
287 
288  // Return
289  return;
290 }
291 
292 
293 /***********************************************************************//**
294  * @brief Invalid WCS parameter
295  *
296  * @param[in] origin Method that throws the error.
297  * @param[in] message Optional error message.
298  ***************************************************************************/
300  std::string message)
301 {
302  // Set origin and message
303  m_origin = origin;
304  m_message = "Invalid WCS parameter encountered.";
305  if (message.length() > 0)
306  m_message += " "+message;
307 
308  // Return
309  return;
310 }
311 
312 
313 /***********************************************************************//**
314  * @brief Invalid (x,y) coordinate(s)
315  *
316  * @param[in] origin Method that throws the error.
317  * @param[in] num Number of invalid coordinates.
318  * @param[in] message Optional error message.
319  ***************************************************************************/
321  int num,
322  std::string message)
323 {
324  // Set origin and message
325  m_origin = origin;
326  m_message = gammalib::str(num)+" (x,y) coordinates were invalid.";
327  if (message.length() > 0)
328  m_message += " "+message;
329 
330  // Return
331  return;
332 }
333 
334 
335 /***********************************************************************//**
336  * @brief Invalid (phi,theta) coordinate(s)
337  *
338  * @param[in] origin Method that throws the error.
339  * @param[in] num Number of invalid coordinates.
340  * @param[in] message Optional error message.
341  ***************************************************************************/
343  int num,
344  std::string message)
345 {
346  // Set origin and message
347  m_origin = origin;
348  m_message = gammalib::str(num)+" (phi,theta) coordinates were invalid.";
349  if (message.length() > 0)
350  m_message += " "+message;
351 
352  // Return
353  return;
354 }
355 
skymap_bad_ctype(std::string origin, std::string ctype1, std::string ctype2, std::string message="")
Incompatible ctype keywords.
wcs_invalid_x_y(std::string origin, int num, std::string message="")
Invalid (x,y) coordinate(s)
wcs_bad_coords(std::string origin, std::string coordsys)
Coordinate system invalid.
skymap_bad_size(std::string origin, int size, int expected, std::string message="")
Incompatible data size.
wcs_no_proj_fct(std::string origin, std::string message="")
No projection function declared.
wcs_invalid_parameter(std::string origin, std::string message="")
Invalid WCS parameter.
Gammalib tools definition.
wcs_invalid_phi_theta(std::string origin, int num, std::string message="")
Invalid (phi,theta) coordinate(s)
skymap(std::string origin, std::string message="")
General GSkyMap error.
wcs_hpx_bad_ordering(std::string origin, std::string ordering)
Healpix pixel ordering invalid.
wcs_invalid(std::string origin, std::string wcs, std::string message="")
Invalid WCS code.
std::string m_message
Definition: GException.hpp:51
wcs_singular_matrix(std::string origin, int naxis, const std::vector< double > &mat)
Singular matrix encountered.
skymap_bad_image_dim(std::string origin, int naxis, std::string message="")
Bad image dimension.
wcs_hpx_bad_nside(std::string origin, int nside)
Healpix resolution invalid.
wcs(std::string origin, std::string message="")
General GWcs error.
Exception handler interface definition.
std::string m_origin
Definition: GException.hpp:50
skymap_bad_par(std::string origin, int par, std::string message="")
Bad sky map parameter.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:457