GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GException_obs.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GException_obs.cpp - observations exception handlers *
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 GException_obs.cpp
23  * @brief Observation exception handler interface implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GException.hpp"
32 #include "GTools.hpp"
33 #include "GObservationRegistry.hpp"
34 
35 
36 /***********************************************************************//**
37  * @brief No valid instrument response found
38  *
39  * @param[in] origin Name of method that has thrown the exception.
40  * @param[in] message Optional error message.
41  ***************************************************************************/
42 GException::no_response::no_response(std::string origin, std::string message)
43 {
44  // Set method name
45  m_origin = origin;
46 
47  // Set error message
48  m_message = "No valid instrument response found in observation."
49  " Set event container before using this method.";
50  if (message.length() > 0) {
51  m_message += " " + message;
52  }
53 
54  // Return
55  return;
56 }
57 
58 
59 /***********************************************************************//**
60  * @brief No valid event container found
61  *
62  * @param[in] origin Method that throws the error.
63  * @param[in] message Optional error message.
64  ***************************************************************************/
65 GException::no_events::no_events(std::string origin, std::string message)
66 {
67  // Set method name
68  m_origin = origin;
69 
70  // Set error message
71  m_message = "No valid event container found in observation."
72  " Set event container before using this method.";
73  if (message.length() > 0) {
74  m_message += " " + message;
75  }
76 
77  // Return
78  return;
79 }
80 
81 
82 /***********************************************************************//**
83  * @brief No valid event list found
84  *
85  * @param[in] origin Method that throws the error.
86  * @param[in] message Optional error message.
87  ***************************************************************************/
88 GException::no_list::no_list(std::string origin, std::string message)
89 {
90  // Set method name
91  m_origin = origin;
92 
93  // Set error message
94  m_message = "No valid event list found in observation."
95  " Set event list before using this method.";
96  if (message.length() > 0) {
97  m_message += " " + message;
98  }
99 
100  // Return
101  return;
102 }
103 
104 
105 /***********************************************************************//**
106  * @brief No valid event cube found
107  *
108  * @param[in] origin Method that throws the error.
109  * @param[in] message Optional error message.
110  ***************************************************************************/
111 GException::no_cube::no_cube(std::string origin, std::string message)
112 {
113  // Set method name
114  m_origin = origin;
115 
116  // Set error message
117  m_message = "No valid event cube found in observation."
118  " Set event cube before using this method.";
119  if (message.length() > 0) {
120  m_message += " " + message;
121  }
122 
123  // Return
124  return;
125 }
126 
127 
128 /***********************************************************************//**
129  * @brief No valid region of interest found
130  *
131  * @param[in] origin Method that throws the error.
132  * @param[in] message Optional error message.
133  ***************************************************************************/
134 GException::no_roi::no_roi(std::string origin, std::string message)
135 {
136  // Set method name
137  m_origin = origin;
138 
139  // Set error message
140  m_message = "No valid region of interest (ROI) found in observation."
141  " Set region of interest before using this method.";
142  if (message.length() > 0) {
143  m_message += " " + message;
144  }
145 
146  // Return
147  return;
148 }
149 
150 
151 /***********************************************************************//**
152  * @brief Mismatch between gradient vector and number of model parameters
153  *
154  * @param[in] origin Method that throws the error.
155  * @param[in] nsize Gradient vector size.
156  * @param[in] npars Number of parameters in model.
157  ***************************************************************************/
159  int nsize,
160  int npars)
161 {
162  // Set method name
163  m_origin = origin;
164 
165  // Set error message
166  m_message = "Gradient vector size "+gammalib::str(nsize)+
167  " mismatches number "+gammalib::str(npars)+" of model parameters.";
168 
169  // Return
170  return;
171 }
172 
173 
174 /***********************************************************************//**
175  * @brief Calibration database directory not found
176  *
177  * @param[in] origin Name of method that has thrown the exception.
178  * @param[in] caldb Name of calibration database.
179  * @param[in] message Optional error message.
180  ***************************************************************************/
182  std::string caldb,
183  std::string message)
184 {
185  // Set method name
186  m_origin = origin;
187 
188  // Set error message
189  m_message = "Calibration database \""+caldb+"\" not found.";
190  if (message.length() > 0) {
191  m_message += " " + message;
192  }
193 
194  // Return
195  return;
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Response error: invalid response type specified
201  *
202  * @param[in] origin Method that throws the error.
203  * @param[in] type Specified response type.
204  * @param[in] message Optional error message.
205  ***************************************************************************/
207  std::string type,
208  std::string message)
209 {
210  // Set method name
211  m_origin = origin;
212 
213  // Set error message
214  m_message = "Invalid response type \""+type+"\" specified.";
215  if (message.length() > 0) {
216  m_message += " " + message;
217  }
218 
219  // Return
220  return;
221 }
222 
223 
224 /***********************************************************************//**
225  * @brief Invalid Good Time Interval found
226  *
227  * @param[in] origin Method that throws the error.
228  * @param[in] tstart Good Time Interval start time.
229  * @param[in] tstop Good Time Interval stop time.
230  * @param[in] message Optional error message.
231  ***************************************************************************/
232 GException::gti_invalid::gti_invalid(std::string origin, GTime tstart,
233  GTime tstop, std::string message)
234 {
235  // Set method name
236  m_origin = origin;
237 
238  // Set error message
239  m_message = "Invalid Good Time Interval (" + tstart.print() + "-" +
240  tstop.print() + ") specified.";
241  if (message.length() > 0) {
242  m_message += " " + message;
243  }
244 
245  // Return
246  return;
247 }
248 
249 
250 /***********************************************************************//**
251  * @brief Invalid energy range found
252  *
253  * @param[in] origin Method that throws the error.
254  * @param[in] emin Minimum energy in MeV.
255  * @param[in] emax Maximum energy in MeV.
256  * @param[in] message Optional error message.
257  ***************************************************************************/
258 GException::erange_invalid::erange_invalid(std::string origin, double emin,
259  double emax, std::string message)
260 {
261  // Set method name
262  m_origin = origin;
263 
264  // Set error message
265  m_message = "Invalid energy range (Emin="+gammalib::str(emin)+" MeV, Emax="+
266  gammalib::str(emax)+" MeV) specified.";
267  if (message.length() > 0) {
268  m_message += " " + message;
269  }
270 
271  // Return
272  return;
273 }
274 
275 
276 /***********************************************************************//**
277  * @brief Invalid optimization statistics
278  *
279  * @param[in] origin Method that throws the error.
280  * @param[in] statistics Encountered statistics.
281  * @param[in] message Optional error message.
282  ***************************************************************************/
284  std::string statistics,
285  std::string message)
286 {
287  // Set method name
288  m_origin = origin;
289 
290  // Set error message
291  m_message = "Invalid optimization statistics \""+statistics+
292  "\" specified.";
293  if (message.length() > 0) {
294  m_message += " " + message;
295  }
296 
297  // Return
298  return;
299 }
300 
301 
302 /***********************************************************************//**
303  * @brief Invalid instrument encountered
304  *
305  * @param[in] origin Method that throws the error.
306  * @param[in] instrument Encountered instrument.
307  * @param[in] message Optional error message.
308  ***************************************************************************/
310  std::string instrument,
311  std::string message)
312 {
313  // Set origin and message
314  m_origin = origin;
315  m_message = "Invalid instrument \""+instrument+"\" encountered.";
316  if (message.length() > 0) {
317  m_message += " " + message;
318  }
319 
320  // Add list of valid instruments
321  GObservationRegistry registry;
322  if (registry.size() > 0) {
323  m_message += " The following instruments are registered: ";
324  for (int i = 0; i < registry.size(); ++i) {
325  if (i > 0) {
326  m_message += ", ";
327  }
328  m_message += "\"" + registry.name(i) + "\"";
329  }
330  m_message += ".";
331  }
332  else {
333  m_message += "No instruments are registered.";
334  }
335 
336  // Return
337  return;
338 }
339 
340 
341 /***********************************************************************//**
342  * @brief Invalid time unit encountered
343  *
344  * @param[in] origin Method that throws the error.
345  * @param[in] unit Time unit.
346  * @param[in] message Optional error message.
347  ***************************************************************************/
349  const std::string& unit,
350  const std::string& message)
351 {
352  // Set origin and message
353  m_origin = origin;
354  m_message = "Invalid time unit \""+unit+"\" encountered.";
355  if (message.length() > 0) {
356  m_message += " " + message;
357  }
358 
359  // Return
360  return;
361 }
362 
363 
364 /***********************************************************************//**
365  * @brief No valid reference MJD found
366  *
367  * @param[in] origin Method that throws the error.
368  * @param[in] message Optional error message.
369  ***************************************************************************/
371  const std::string& message)
372 {
373  // Set origin and message
374  m_origin = origin;
375  m_message = "No valid time reference Modified Julian Day found.";
376  if (message.length() > 0) {
377  m_message += " " + message;
378  }
379 
380  // Return
381  return;
382 }
no_events(std::string origin, std::string message="")
No valid event container found.
rsp_invalid_type(std::string origin, std::string type, std::string message="")
Response error: invalid response type specified.
Time class.
Definition: GTime.hpp:54
Gammalib tools definition.
no_response(std::string origin, std::string message="")
No valid instrument response found.
gradient_par_mismatch(std::string origin, int nsize, int npars)
Mismatch between gradient vector and number of model parameters.
int size(void) const
Return number of registered observations.
invalid_statistics(std::string origin, std::string statistics, std::string message="")
Invalid optimization statistics.
invalid_instrument(std::string origin, std::string instrument, std::string message="")
Invalid instrument encountered.
Interface definition for the observation registry class.
time_invalid_unit(const std::string &origin, const std::string &unit, const std::string &message="")
Invalid time unit encountered.
Observation registry class definition.
std::string name(const int &index) const
Returns instrument name for a specific registered observation.
std::string m_message
Definition: GException.hpp:51
erange_invalid(std::string origin, double emin, double emax, std::string message="")
Invalid energy range found.
std::string print(const GChatter &chatter=NORMAL) const
Print time.
Definition: GTime.cpp:1161
no_list(std::string origin, std::string message="")
No valid event list found.
caldb_not_found(std::string origin, std::string home, std::string message="")
Calibration database directory not found.
no_roi(std::string origin, std::string message="")
No valid region of interest found.
gti_invalid(std::string origin, GTime tstart, GTime tstop, std::string message="")
Invalid Good Time Interval found.
Exception handler interface definition.
no_cube(std::string origin, std::string message="")
No valid event cube found.
std::string m_origin
Definition: GException.hpp:50
no_valid_time_ref(const std::string &origin, const std::string &message="")
No valid reference MJD found.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:413