GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GException_model.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GException_model.cpp - Model exception handlers *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2011 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_model.cpp
23  * @brief Implement exceptions for the model module
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 "GModelRegistry.hpp"
36 #include "GTools.hpp"
37 
38 
39 /***********************************************************************//**
40  * @brief Invalid model type
41  *
42  * @param[in] origin Method that throws the error.
43  * @param[in] type Model type that has been encountered.
44  * @param[in] message Optional error message.
45  ***************************************************************************/
47  std::string type,
48  std::string message)
49 {
50  // Set origin and message
51  m_origin = origin;
52  m_message = "Invalid model type \""+type+"\" encountered. " + message;
53 
54  // Add list of valid models
55  GModelRegistry registry;
56  if (registry.size() > 0) {
57  m_message += "The following models are registered: ";
58  for (int i = 0; i < registry.size(); ++i) {
59  if (i > 0)
60  m_message += ", ";
61  m_message += "\"" + registry.name(i) + "\"";
62  }
63  m_message += ".";
64  }
65  else
66  m_message += "No models are registered.";
67 
68  // Return
69  return;
70 }
71 
72 
73 /***********************************************************************//**
74  * @brief Invalid spatial model type
75  *
76  * @param[in] origin Method that throws the error.
77  * @param[in] type Spatial model type that has been encountered.
78  * @param[in] message Optional error message.
79  ***************************************************************************/
81  std::string type,
82  std::string message)
83 {
84  // Set origin and message
85  m_origin = origin;
86  m_message = "Invalid spatial model type \""+type+"\" encountered. " +
87  message;
88 
89  // Add list of valid spatial models
90  GModelSpatialRegistry registry;
91  if (registry.size() > 0) {
92  m_message += "The following models are registered: ";
93  for (int i = 0; i < registry.size(); ++i) {
94  if (i > 0)
95  m_message += ", ";
96  m_message += "\"" + registry.name(i) + "\"";
97  }
98  m_message += ".";
99  }
100  else
101  m_message += "No models are registered.";
102 
103  // Return
104  return;
105 }
106 
107 
108 /***********************************************************************//**
109  * @brief Invalid spectral model type
110  *
111  * @param[in] origin Method that throws the error.
112  * @param[in] type Spectral model type that has been encountered.
113  * @param[in] message Optional error message.
114  ***************************************************************************/
116  std::string type,
117  std::string message)
118 {
119  // Set origin and message
120  m_origin = origin;
121  m_message = "Invalid spectral model type \""+type+"\" encountered. " +
122  message;
123 
124  // Add list of valid spectral models
125  GModelSpectralRegistry registry;
126  if (registry.size() > 0) {
127  m_message += "The following models are registered: ";
128  for (int i = 0; i < registry.size(); ++i) {
129  if (i > 0)
130  m_message += ", ";
131  m_message += "\"" + registry.name(i) + "\"";
132  }
133  m_message += ".";
134  }
135  else
136  m_message += "No models are registered.";
137 
138  // Return
139  return;
140 }
141 
142 
143 /***********************************************************************//**
144  * @brief Invalid temporal model type
145  *
146  * @param[in] origin Method that throws the error.
147  * @param[in] type Temporal model type that has been encountered.
148  * @param[in] message Optional error message.
149  ***************************************************************************/
151  std::string type,
152  std::string message)
153 {
154  // Set origin and message
155  m_origin = origin;
156  m_message = "Invalid temporal model type \""+type+"\" encountered. " +
157  message;
158 
159  // Add list of valid spectral models
160  GModelTemporalRegistry registry;
161  if (registry.size() > 0) {
162  m_message += "The following models are registered: ";
163  for (int i = 0; i < registry.size(); ++i) {
164  if (i > 0)
165  m_message += ", ";
166  m_message += "\"" + registry.name(i) + "\"";
167  }
168  m_message += ".";
169  }
170  else
171  m_message += "No models are registered.";
172 
173  // Return
174  return;
175 }
176 
177 
178 /***********************************************************************//**
179  * @brief Invalid number of model parameters in XML element
180  *
181  * @param[in] origin Method that throws the error.
182  * @param[in] xml XML element.
183  * @param[in] message Optional error message.
184  ***************************************************************************/
186  GXmlElement xml,
187  std::string message)
188 {
189  // Set origin and message
190  m_origin = origin;
191  m_message = "Invalid number of model parameters found in XML element. " +
192  message;
193 
194  // Return
195  return;
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Invalid model parameter names in XML element
201  *
202  * @param[in] origin Method that throws the error.
203  * @param[in] xml XML element.
204  * @param[in] message Optional error message.
205  ***************************************************************************/
207  GXmlElement xml,
208  std::string message)
209 {
210  // Set origin and message
211  m_origin = origin;
212  m_message = "Invalid model parameter names found in XML element. " +
213  message;
214 
215  // Return
216  return;
217 }
218 
219 
220 /***********************************************************************//**
221  * @brief Invalid model parameter value in XML element
222  *
223  * @param[in] origin Method that throws the error.
224  * @param[in] xml XML element.
225  * @param[in] message Optional error message.
226  ***************************************************************************/
228  GXmlElement xml,
229  std::string message)
230 {
231  // Set origin and message
232  m_origin = origin;
233  m_message = "Invalid model parameter value found in XML element. " +
234  message;
235 
236  // Return
237  return;
238 }
239 
240 
241 /***********************************************************************//**
242  * @brief Invalid model parameter limit in XML element
243  *
244  * @param[in] origin Method that throws the error.
245  * @param[in] xml XML element.
246  * @param[in] message Optional error message.
247  ***************************************************************************/
249  GXmlElement xml,
250  std::string message)
251 {
252  // Set origin and message
253  m_origin = origin;
254  m_message = "Invalid model parameter limit found in XML element. " +
255  message;
256 
257  // Return
258  return;
259 }
260 
261 
262 /***********************************************************************//**
263  * @brief Model parameter has invalid scale
264  *
265  * @param[in] origin Method that throws the error.
266  * @param[in] scale Scale.
267  * @param[in] message Optional error message.
268  ***************************************************************************/
270  double scale,
271  std::string message)
272 {
273  // Set origin and message
274  m_origin = origin;
275  m_message = "Model parameter has invalid scale="+gammalib::str(scale)+". " +
276  message;
277 
278  // Return
279  return;
280 }
281 
282 
283 /***********************************************************************//**
284  * @brief Model parameter has invalid scale
285  *
286  * @param[in] origin Method that throws the error.
287  * @param[in] xml XML element.
288  * @param[in] message Optional error message.
289  ***************************************************************************/
291  GXmlElement xml,
292  std::string message)
293 {
294  // Set origin and message
295  m_origin = origin;
296  m_message = "Model parameter with invalid scale found in XML element. " +
297  message;
298 
299  // Return
300  return;
301 }
302 
303 
304 /***********************************************************************//**
305  * @brief Not enough nodes in file function
306  *
307  * @param[in] origin Method that throws the error.
308  * @param[in] filename File function filename.
309  * @param[in] num Number of nodes.
310  * @param[in] message Optional error message.
311  ***************************************************************************/
313  std::string filename,
314  int num,
315  std::string message)
316 {
317  // Set origin and message
318  m_origin = origin;
319  m_message = "File function \""+filename+"\" contains "+gammalib::str(num)+
320  " energy nodes while at least 2 are required to describe a"
321  " spectral shape.";
322  if (message.length() > 0) {
323  m_message += " "+message;
324  }
325 
326  // Return
327  return;
328 }
329 
330 
331 /***********************************************************************//**
332  * @brief Not enough columns in file function
333  *
334  * @param[in] origin Method that throws the error.
335  * @param[in] filename File function filename.
336  * @param[in] num Number of columns.
337  * @param[in] message Optional error message.
338  ***************************************************************************/
340  std::string filename,
341  int num,
342  std::string message)
343 {
344  // Set origin and message
345  m_origin = origin;
346  m_message = "File function \""+filename+"\" contains "+gammalib::str(num)+
347  " columns while at least 2 are required to define"
348  " energy and intensity.";
349  if (message.length() > 0) {
350  m_message += " "+message;
351  }
352 
353  // Return
354  return;
355 }
356 
357 
358 /***********************************************************************//**
359  * @brief Invalid value in file function
360  *
361  * @param[in] origin Method that throws the error.
362  * @param[in] filename File function filename.
363  * @param[in] value Number of columns.
364  * @param[in] message Optional error message.
365  ***************************************************************************/
367  std::string filename,
368  double value,
369  std::string message)
370 {
371  // Set origin and message
372  m_origin = origin;
373  m_message = "Invalid value \""+gammalib::str(value)+"\" encountered in"
374  " file function \""+filename+"\".";
375  if (message.length() > 0) {
376  m_message += " "+message;
377  }
378 
379  // Return
380  return;
381 }
382 
383 
384 /***********************************************************************//**
385  * @brief Parameter not found
386  *
387  * @param[in] origin Method that throws the error.
388  * @param[in] name Parameter name.
389  * @param[in] message Optional error message.
390  ***************************************************************************/
392  std::string name,
393  std::string message)
394 {
395  // Set origin
396  m_origin = origin;
397 
398  // Set message
399  m_message = "Parameter \""+name+"\" not found in container.";
400  if (message.length() > 0)
401  m_message += " "+message;
402 
403  // Return
404  return;
405 }
406 
407 
408 /***********************************************************************//**
409  * @brief Model not found
410  *
411  * @param[in] origin Method that throws the error.
412  * @param[in] name Model name.
413  * @param[in] message Optional error message.
414  ***************************************************************************/
416  std::string name,
417  std::string message)
418 {
419  // Set origin
420  m_origin = origin;
421 
422  // Set message
423  m_message = "Model \""+name+"\" not found in container.";
424  if (message.length() > 0)
425  m_message += " "+message;
426 
427  // Return
428  return;
429 }
430 
431 
432 /***********************************************************************//**
433  * @brief No point source model component found
434  *
435  * @param[in] origin Method that throws the error.
436  * @param[in] name Model name.
437  * @param[in] message Optional error message.
438  ***************************************************************************/
440  std::string name,
441  std::string message)
442 {
443  // Set origin
444  m_origin = origin;
445 
446  // Set message
447  m_message = "No point source model component found in model \""+name+"\".";
448  if (message.length() > 0)
449  m_message += " "+message;
450 
451  // Return
452  return;
453 }
454 
455 
456 /***********************************************************************//**
457  * @brief No extended source model component found
458  *
459  * @param[in] origin Method that throws the error.
460  * @param[in] name Model name.
461  * @param[in] message Optional error message.
462  ***************************************************************************/
464  std::string name,
465  std::string message)
466 {
467  // Set origin
468  m_origin = origin;
469 
470  // Set message
471  m_message = "No extended source model component found in model \""+name+"\".";
472  if (message.length() > 0)
473  m_message += " "+message;
474 
475  // Return
476  return;
477 }
par_not_found(std::string origin, std::string name, std::string message="")
Parameter not found.
model_invalid_temporal(std::string origin, std::string type, std::string message="")
Invalid temporal model type.
model_invalid_parnum(std::string origin, GXmlElement xml, std::string message="")
Invalid number of model parameters in XML element.
Interface definition for the model registry class.
no_extended_source(std::string origin, std::string name, std::string message="")
No extended source model component found.
no_point_source(std::string origin, std::string name, std::string message="")
No point source model component found.
model_invalid_spectral(std::string origin, std::string type, std::string message="")
Invalid spectral model type.
file_function_value(std::string origin, std::string filename, double value, std::string message="")
Invalid value in file function.
XML element node class.
Definition: GXmlElement.hpp:48
Spectral model registry class definition.
std::string name(const int &index) const
Returns model name.
Gammalib tools definition.
std::string name(const int &index) const
Returns model name.
Interface definition for the spatial model registry class.
model_invalid_parscale(std::string origin, double scale, std::string message="")
Model parameter has invalid scale.
model_invalid_spatial(std::string origin, std::string type, std::string message="")
Invalid spatial model type.
file_function_columns(std::string origin, std::string filename, int num, std::string message="")
Not enough columns in file function.
int size(void) const
Return number of registered models.
std::string name(const int &index) const
Returns model name.
model_invalid_parvalue(std::string origin, GXmlElement xml, std::string message="")
Invalid model parameter value in XML element.
int size(void) const
Return number of registered models.
Spatial model registry class definition.
int size(void) const
Return number of registered models.
std::string m_message
Definition: GException.hpp:51
Interface definition for the spectral model registry class.
Interface definition for the temporal model registry class.
int size(void) const
Return number of registered models.
Temporal model registry class definition.
Exception handler interface definition.
model_not_found(std::string origin, std::string name, std::string message="")
Model not found.
file_function_data(std::string origin, std::string filename, int num, std::string message="")
Not enough nodes in file function.
model_invalid(std::string origin, std::string type, std::string message="")
Invalid model type.
std::string m_origin
Definition: GException.hpp:50
Model registry class definition.
model_invalid_parlimit(std::string origin, GXmlElement xml, std::string message="")
Invalid model parameter limit in XML element.
model_invalid_parnames(std::string origin, GXmlElement xml, std::string message="")
Invalid model parameter names in XML element.
std::string name(const int &index) const
Returns model name.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:457