GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAException.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAException.cpp - CTA exception handler *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2012 by Juergen Knoedlseder *
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 GCTAException.cpp
23  * @brief CTA exception handler interface implementation.
24  * @author J. Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #include "GCTAException.hpp"
29 #include "GTools.hpp"
31 
32 
33 /***********************************************************************//**
34  * @brief Exception message.
35  ***************************************************************************/
36 const char* GCTAExceptionHandler::what() const throw()
37 {
38  // Set error message
39  std::string message = "*** ERROR in " + m_origin + ": " + m_message;
40 
41  // Return message as C character array
42  return gammalib::tochar(message);
43 }
44 
45 
46 /***********************************************************************//**
47  * @brief Error while opening file.
48  *
49  * @param[in] origin Name of method that has thrown the exception.
50  * @param[in] filename Name of file that could not be opened.
51  * @param[in] message Optional error message.
52  ***************************************************************************/
54  std::string filename,
55  std::string message)
56 {
57  m_origin = origin;
58  m_message = "Unable to open file '"+filename+"'. "+message;
59  return;
60 }
61 
62 
63 /***********************************************************************//**
64  * @brief Member not set.
65  *
66  * @param[in] origin Name of method that has thrown the exception.
67  * @param[in] message Error message.
68  ***************************************************************************/
69 GCTAException::no_member::no_member(const std::string& origin,
70  const std::string& message)
71 {
72  // Set origin and message
73  m_origin = origin;
74  m_message = message;
75 
76  // Return
77  return;
78 }
79 
80 
81 
82 
83 /***********************************************************************//**
84  * @brief Pointing not set.
85  *
86  * @param[in] origin Name of method that has thrown the exception.
87  * @param[in] message Optional error message.
88  ***************************************************************************/
89 GCTAException::no_pointing::no_pointing(std::string origin, std::string message)
90 {
91  m_origin = origin;
92  m_message = "No pointing found in CTA observation. "+message;
93  return;
94 }
95 
96 
97 /***********************************************************************//**
98  * @brief Instrument response not set.
99  *
100  * @param[in] origin Name of method that has thrown the exception.
101  * @param[in] message Optional error message.
102  ***************************************************************************/
103 GCTAException::no_response::no_response(std::string origin, std::string message)
104 {
105  m_origin = origin;
106  m_message = "Attempt to use CTA response, but no response function"
107  " has been found. Use GCTAObservation::response() method"
108  " to set response function. "+message;
109  return;
110 }
111 
112 
113 /***********************************************************************//**
114  * @brief No sky pixels found.
115  *
116  * @param[in] origin Name of method that has thrown the exception.
117  * @param[in] message Optional error message.
118  ***************************************************************************/
119 GCTAException::no_sky::no_sky(std::string origin, std::string message)
120 {
121  m_origin = origin;
122  m_message = "No sky pixels have been found. "+message;
123  return;
124 }
125 
126 
127 /***********************************************************************//**
128  * @brief No energy boundary information found.
129  *
130  * @param[in] origin Name of method that has thrown the exception.
131  * @param[in] message Optional error message.
132  ***************************************************************************/
133 GCTAException::no_ebds::no_ebds(std::string origin, std::string message)
134 {
135  m_origin = origin;
136  m_message = "No energy boundaries have been found. "+message;
137  return;
138 }
139 
140 
141 /***********************************************************************//**
142  * @brief No Good Time Intervals found.
143  *
144  * @param[in] origin Name of method that has thrown the exception.
145  * @param[in] message Optional error message.
146  ***************************************************************************/
147 GCTAException::no_gti::no_gti(std::string origin, std::string message)
148 {
149  m_origin = origin;
150  m_message = "No Good Time Intervals (GTIs) have been found. "+message;
151  return;
152 }
153 
154 
155 /***********************************************************************//**
156  * @brief No energies set
157  *
158  * @param[in] origin Name of method that has thrown the exception.
159  * @param[in] message Optional error message.
160  ***************************************************************************/
161 GCTAException::no_energies::no_energies(std::string origin, std::string message)
162 {
163  // Set origin
164  m_origin = origin;
165 
166  // Set message
167  m_message = "Energy vector has not been setup."
168  " Cannot access event information.";
169  if (message.length() > 0)
170  m_message += " "+message;
171 
172  // Return
173  return;
174 }
175 
176 
177 /***********************************************************************//**
178  * @brief No sky directions set
179  *
180  * @param[in] origin Name of method that has thrown the exception.
181  * @param[in] message Optional error message.
182  ***************************************************************************/
183 GCTAException::no_dirs::no_dirs(std::string origin, std::string message)
184 {
185  // Set origin
186  m_origin = origin;
187 
188  // Set message
189  m_message = "Sky direction vector has not been setup."
190  " Cannot access event information.";
191  if (message.length() > 0)
192  m_message += " "+message;
193 
194  // Return
195  return;
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Observation is not a CTA observation
201  *
202  * @param[in] origin Name of method that has thrown the exception.
203  * @param[in] message Optional error message.
204  ***************************************************************************/
206  std::string message)
207 {
208  // Set origin
209  m_origin = origin;
210 
211  // Set message
212  m_message = "Observation is not of type GCTAObservation.";
213  if (message.length() > 0)
214  m_message += " "+message;
215 
216  // Return
217  return;
218 }
219 
220 
221 /***********************************************************************//**
222  * @brief Event is not a CTA event
223  *
224  * @param[in] origin Name of method that has thrown the exception.
225  * @param[in] message Optional error message.
226  ***************************************************************************/
227 GCTAException::bad_event_type::bad_event_type(std::string origin, std::string message)
228 {
229  // Set origin
230  m_origin = origin;
231 
232  // Set message
233  m_message = "Event is not of type GCTAEventAtom or GCTAEventBin.";
234  if (message.length() > 0)
235  m_message += " "+message;
236 
237  // Return
238  return;
239 }
240 
241 
242 /***********************************************************************//**
243  * @brief ROI is not a CTA ROI
244  *
245  * @param[in] origin Name of method that has thrown the exception.
246  * @param[in] message Optional error message.
247  ***************************************************************************/
248 GCTAException::bad_roi_type::bad_roi_type(std::string origin, std::string message)
249 {
250  // Set origin
251  m_origin = origin;
252 
253  // Set message
254  m_message = "ROI is not of type GCTARoi.";
255  if (message.length() > 0)
256  m_message += " "+message;
257 
258  // Return
259  return;
260 }
261 
262 
263 /***********************************************************************//**
264  * @brief Instrument direction is not a CTA instrument direction
265  *
266  * @param[in] origin Name of method that has thrown the exception.
267  * @param[in] message Optional error message.
268  ***************************************************************************/
270  std::string message)
271 {
272  // Set origin
273  m_origin = origin;
274 
275  // Set message
276  m_message = "Instrument direction is not of type GCTAInstDir.";
277  if (message.length() > 0)
278  m_message += " "+message;
279 
280  // Return
281  return;
282 }
283 
284 
285 /***********************************************************************//**
286  * @brief Pointing is not a CTA pointing
287  *
288  * @param[in] origin Name of method that has thrown the exception.
289  * @param[in] message Optional error message.
290  ***************************************************************************/
292  std::string message)
293 {
294  // Set origin
295  m_origin = origin;
296 
297  // Set message
298  m_message = "Pointing is not of type GCTAPointing.";
299  if (message.length() > 0)
300  m_message += " "+message;
301 
302  // Return
303  return;
304 }
305 
306 
307 /***********************************************************************//**
308  * @brief Response is not a CTA response
309  *
310  * @param[in] origin Name of method that has thrown the exception.
311  * @param[in] message Optional error message.
312  ***************************************************************************/
314  std::string message)
315 {
316  // Set origin
317  m_origin = origin;
318 
319  // Set message
320  m_message = "Response is not of type GCTAResponse.";
321  if (message.length() > 0)
322  m_message += " "+message;
323 
324  // Return
325  return;
326 }
327 
328 
329 /***********************************************************************//**
330  * @brief Invalid radial model type
331  *
332  * @param[in] origin Method that throws the error.
333  * @param[in] type Radial model type that has been encountered.
334  * @param[in] message Optional error message.
335  ***************************************************************************/
337  std::string type,
338  std::string message)
339 {
340  // Set origin and message
341  m_origin = origin;
342  m_message = "Invalid radial CTA model type \""+type+"\" encountered. " +
343  message;
344 
345  // Add list of valid spatial models
346  GCTAModelRadialRegistry registry;
347  if (registry.size() > 0) {
348  m_message += "The following models are registered: ";
349  for (int i = 0; i < registry.size(); ++i) {
350  if (i > 0) {
351  m_message += ", ";
352  }
353  m_message += "\"" + registry.name(i) + "\"";
354  }
355  m_message += ".";
356  }
357  else {
358  m_message += "No models are registered.";
359  }
360 
361  // Return
362  return;
363 }
364 
365 
366 /***********************************************************************//**
367  * @brief Response is not a CTA response
368  *
369  * @param[in] origin Name of method that has thrown the exception.
370  * @param[in] message Optional error message.
371  ***************************************************************************/
373  const std::string& message)
374 {
375  // Set origin
376  m_origin = origin;
377 
378  // Set message
379  m_message = "Model is not of expected type.";
380 
381  // Optional message
382  if (message.length() > 0) {
383  m_message += " "+message;
384  }
385 
386  // Return
387  return;
388 }
389 
390 
391 /***********************************************************************//**
392  * @brief Bad response table dimension
393  *
394  * @param[in] origin Name of method that has thrown the exception.
395  * @param[in] found Found table dimension.
396  * @param[in] expected Expected table dimension.
397  * @param[in] message Optional error message.
398  ***************************************************************************/
400  int found,
401  int expected,
402  std::string message)
403 {
404  // Set origin
405  m_origin = origin;
406 
407  // Set message
408  m_message = "Response table dimension "+
409  gammalib::str(found)+
410  " is smaller than the expected dimension "+
411  gammalib::str(expected)+
412  ".";
413  if (message.length() > 0) {
414  m_message += " "+message;
415  }
416 
417  // Return
418  return;
419 }
420 
421 
422 /***********************************************************************//**
423  * @brief Bad response table format
424  *
425  * @param[in] origin Name of method that has thrown the exception.
426  * @param[in] message Optional error message.
427  ***************************************************************************/
429  std::string message)
430 {
431  // Set origin
432  m_origin = origin;
433 
434  // Set message
435  m_message = "Response table has invalid format.";
436  if (message.length() > 0) {
437  m_message += " "+message;
438  }
439 
440  // Return
441  return;
442 }
virtual const char * what() const
Exception message.
file_open_error(std::string origin, std::string filename, std::string message="")
Error while opening file.
bad_instdir_type(std::string origin, std::string message="")
Instrument direction is not a CTA instrument direction.
no_gti(std::string origin, std::string message="")
No Good Time Intervals found.
no_energies(std::string origin, std::string message="")
No energies set.
Gammalib tools definition.
CTA radial model registry class definition.
no_ebds(std::string origin, std::string message="")
No energy boundary information found.
no_dirs(std::string origin, std::string message="")
No sky directions set.
std::string name(const int &index) const
Returns model name.
bad_model_type(const std::string &origin, const std::string &message="")
Response is not a CTA response.
bad_rsp_table_format(std::string origin, std::string message="")
Bad response table format.
char * tochar(const std::string &arg)
Convert string to C string.
Definition: GTools.cpp:699
bad_response_type(std::string origin, std::string message="")
Response is not a CTA response.
no_member(const std::string &origin, const std::string &message)
Member not set.
bad_observation_type(std::string origin, std::string message="")
Observation is not a CTA observation.
no_sky(std::string origin, std::string message="")
No sky pixels found.
no_response(std::string origin, std::string message="")
Instrument response not set.
model_invalid_radial(std::string origin, std::string type, std::string message="")
Invalid radial model type.
CTA exception handler interface definition.
int size(void) const
Return number of registered models.
bad_rsp_table_dim(std::string origin, int table_dim, int expected_dim, std::string message="")
Bad response table dimension.
Interface definition for the CTA radial model registry class.
bad_roi_type(std::string origin, std::string message="")
ROI is not a CTA ROI.
bad_event_type(std::string origin, std::string message="")
Event is not a CTA event.
no_pointing(std::string origin, std::string message="")
Pointing not set.
bad_pointing_type(std::string origin, std::string message="")
Pointing is not a CTA pointing.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:457