Commit 85643721b1141b15d0cdfdc01319818405a901d9

Authored by Jürgen Knödlseder
1 parent 7b096714

Replace specific by generic exceptions in LAT module (#35)

inst/lat/Makefile.am
1 1 #############################################################################
2 2 # Makefile.am for lat module #
3 3 # ------------------------------------------------------------------------- #
4   -# Copyright (C) 2016-2018 Juergen Knoedlseder #
  4 +# Copyright (C) 2016-2021 Juergen Knoedlseder #
5 5 # ------------------------------------------------------------------------- #
6 6 # #
7 7 # This program is free software: you can redistribute it and/or modify #
... ... @@ -51,8 +51,7 @@ sources = src/GLATObservation.cpp \
51 51 src/GLATInstDir.cpp \
52 52 src/GLATRoi.cpp \
53 53 src/GLATLtCube.cpp \
54   - src/GLATLtCubeMap.cpp \
55   - src/GLATException.cpp
  54 + src/GLATLtCubeMap.cpp
56 55  
57 56 # Define headers to be installed
58 57 pkginclude_HEADERS = include/GLATLib.hpp \
... ... @@ -74,8 +73,7 @@ pkginclude_HEADERS = include/GLATLib.hpp \
74 73 include/GLATInstDir.hpp \
75 74 include/GLATRoi.hpp \
76 75 include/GLATLtCube.hpp \
77   - include/GLATLtCubeMap.hpp \
78   - include/GLATException.hpp
  76 + include/GLATLtCubeMap.hpp
79 77  
80 78 # CALDB to distribute
81 79 caldb_indx = caldb/data/glast/lat/caldb.indx.gz
... ...
inst/lat/include/GLATEdisp.hpp
1 1 /***************************************************************************
2 2 * GLATEdisp.hpp - Fermi LAT energy dispersion *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2018 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -91,7 +91,7 @@ private:
91 91 void init_members(void);
92 92 void copy_members(const GLATEdisp& edisp);
93 93 void free_members(void);
94   - void read_edisp(const GFitsTable& hdu);
  94 + void read_edisp(const GFitsTable& table);
95 95 void write_edisp(GFits& file) const;
96 96  
97 97 // Protected members
... ...
inst/lat/include/GLATException.hpp deleted
1   -/***************************************************************************
2   - * GLATException.hpp - LAT 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 GLATException.hpp
23   - * @brief LAT exception handler interface definition.
24   - * @author Juergen Knoedlseder
25   - */
26   -
27   -#ifndef GLATEXCEPTION_HPP
28   -#define GLATEXCEPTION_HPP
29   -
30   -/* __ Includes ___________________________________________________________ */
31   -#include <string> // string
32   -#include <sstream> // ostringstream
33   -#include <stdexcept> // exception
34   -
35   -
36   -/***********************************************************************//**
37   - * @class GLATExceptionHandler
38   - *
39   - * @brief Interface for LAT exception handler.
40   - ***************************************************************************/
41   -class GLATExceptionHandler : public std::exception {
42   -public:
43   - GLATExceptionHandler(void) { }
44   - virtual ~GLATExceptionHandler(void) throw() { }
45   - virtual const char* what() const throw();
46   -protected:
47   - std::string m_origin;
48   - std::string m_message;
49   -};
50   -
51   -
52   -/***********************************************************************//**
53   - * @class GLATException
54   - *
55   - * @brief Interface for LAT exceptions.
56   - *
57   - * This is the object that is thrown in case of a LAT exception.
58   - ***************************************************************************/
59   -class GLATException : public GLATExceptionHandler {
60   -public:
61   - // Exceptions
62   - class file_open_error : public GLATExceptionHandler {
63   - public:
64   - file_open_error(std::string origin, std::string filename,
65   - std::string message = "");
66   - };
67   - class no_member : public GLATExceptionHandler {
68   - public:
69   - no_member(const std::string& origin, const std::string& message);
70   - };
71   - class no_sky : public GLATExceptionHandler {
72   - public:
73   - no_sky(std::string origin, std::string message = "");
74   - };
75   - class no_ebds : public GLATExceptionHandler {
76   - public:
77   - no_ebds(std::string origin, std::string message = "");
78   - };
79   - class no_gti : public GLATExceptionHandler {
80   - public:
81   - no_gti(std::string origin, std::string message = "");
82   - };
83   - class no_ltcube : public GLATExceptionHandler {
84   - public:
85   - no_ltcube(std::string origin, std::string message = "");
86   - };
87   - class no_energies : public GLATExceptionHandler {
88   - public:
89   - no_energies(std::string origin, std::string message = "");
90   - };
91   - class no_dirs : public GLATExceptionHandler {
92   - public:
93   - no_dirs(std::string origin, std::string message = "");
94   - };
95   - class bad_roi_type : public GLATExceptionHandler {
96   - public:
97   - bad_roi_type(std::string origin, std::string message = "");
98   - };
99   - class bad_instdir_type : public GLATExceptionHandler {
100   - public:
101   - bad_instdir_type(std::string origin, std::string message = "");
102   - };
103   - class invalid_response : public GLATExceptionHandler {
104   - public:
105   - invalid_response(std::string origin, std::string message = "");
106   - };
107   - class wcs_incompatible : public GLATExceptionHandler {
108   - public:
109   - wcs_incompatible(std::string origin, std::string name,
110   - std::string message = "");
111   - };
112   - class diffuse_not_found : public GLATExceptionHandler {
113   - public:
114   - diffuse_not_found(std::string origin, std::string name,
115   - std::string message = "");
116   - };
117   - class inconsistent_response : public GLATExceptionHandler {
118   - public:
119   - inconsistent_response(std::string origin, int size, int expect,
120   - std::string message = "");
121   - };
122   - class bad_response_type : public GLATExceptionHandler {
123   - public:
124   - bad_response_type(std::string origin, std::string message = "");
125   - };
126   -};
127   -
128   -#endif /* GLATEXCEPTION_HPP */
inst/lat/include/GLATLib.hpp
1 1 /***************************************************************************
2 2 * GLATLib.hpp - Fermi/LAT Support Header files *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2013 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -33,11 +33,11 @@
33 33 /* __ Fermi/LAT specific headers _________________________________________ */
34 34 #include "GLATAeff.hpp"
35 35 #include "GLATEdisp.hpp"
  36 +#include "GLATEfficiency.hpp"
36 37 #include "GLATEventAtom.hpp"
37 38 #include "GLATEventBin.hpp"
38 39 #include "GLATEventCube.hpp"
39 40 #include "GLATEventList.hpp"
40   -#include "GLATException.hpp"
41 41 #include "GLATInstDir.hpp"
42 42 #include "GLATLtCube.hpp"
43 43 #include "GLATLtCubeMap.hpp"
... ...
inst/lat/src/GLATAeff.cpp
1 1 /***************************************************************************
2 2 * GLATAeff.cpp - Fermi LAT effective area *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2018 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -38,7 +38,6 @@
38 38 #include "GFitsTableCol.hpp"
39 39 #include "GFitsTableFloatCol.hpp"
40 40 #include "GLATAeff.hpp"
41   -#include "GLATException.hpp"
42 41  
43 42 /* __ Method name definitions ____________________________________________ */
44 43 #define G_READ_AEFF "GLATAeff::read_aeff(GFitsTable&)"
... ... @@ -554,7 +553,7 @@ void GLATAeff::free_members(void)
554 553 *
555 554 * @param[in] hdu FITS table.
556 555 *
557   - * @exception GLATException::inconsistent_response
  556 + * @exception GException::invalid_argument
558 557 * Inconsistent response table encountered
559 558 *
560 559 * The effective area is converted into units of cm2.
... ... @@ -583,7 +582,13 @@ void GLATAeff::read_aeff(const GFitsTable&amp; hdu)
583 582 // Check consistency of effective area table
584 583 int num = ptr->number();
585 584 if (num != size) {
586   - throw GLATException::inconsistent_response(G_READ_AEFF, num, size);
  585 + std::string msg = "Number of elements in response table ("+
  586 + gammalib::str(num)+") does not correspond to "
  587 + "the expectation according to the number of "
  588 + "energy and cos theta bins ("+gammalib::str(size)+
  589 + "). Please specify a consistent effective area "
  590 + "response.";
  591 + throw GException::invalid_argument(G_READ_AEFF, msg);
587 592 }
588 593  
589 594 // Copy data and convert from m2 into cm2
... ...
inst/lat/src/GLATEdisp.cpp
1 1 /***************************************************************************
2 2 * GLATEdisp.cpp - Fermi LAT energy dispersion *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2020 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -28,6 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
  31 +#include "GException.hpp"
31 32 #include "GTools.hpp"
32 33 #include "GFilename.hpp"
33 34 #include "GFits.hpp"
... ... @@ -35,7 +36,6 @@
35 36 #include "GFitsBinTable.hpp"
36 37 #include "GFitsTableFloatCol.hpp"
37 38 #include "GLATEdisp.hpp"
38   -#include "GLATException.hpp"
39 39  
40 40 /* __ Method name definitions ____________________________________________ */
41 41 #define G_READ "GLATEdisp::read(GFits&)"
... ... @@ -371,19 +371,21 @@ void GLATEdisp::free_members(void)
371 371 /***********************************************************************//**
372 372 * @brief Read energy dispersion from FITS table
373 373 *
374   - * @param[in] hdu FITS table pointer.
  374 + * @param[in] table FITS table.
375 375 *
376   - * @exception GLATException::inconsistent_response
  376 + * @exception GException::invalid_argument
377 377 * Inconsistent response table encountered
  378 + *
  379 + * @todo Implement reading of energy dispersion table
378 380 ***************************************************************************/
379   -void GLATEdisp::read_edisp(const GFitsTable& hdu)
  381 +void GLATEdisp::read_edisp(const GFitsTable& table)
380 382 {
381 383 // Clear arrays
382 384 m_norm.clear();
383 385 m_ls1.clear();
384 386  
385 387 // Get energy and cos theta binning
386   - m_edisp_bins.read(hdu);
  388 + m_edisp_bins.read(table);
387 389  
388 390 // Continue only if there are bins
389 391 int size = m_edisp_bins.size();
... ... @@ -394,17 +396,25 @@ void GLATEdisp::read_edisp(const GFitsTable&amp; hdu)
394 396 m_ls1.reserve(size);
395 397  
396 398 // Get pointer to columns
397   - const GFitsTableCol* norm = hdu["NORM"];
398   - const GFitsTableCol* ls1 = hdu["LS1"];
  399 + const GFitsTableCol* norm = table["NORM"];
  400 + const GFitsTableCol* ls1 = table["LS1"];
399 401  
400 402 // Check consistency of columns
401 403 if (norm->number() != size) {
402   - throw GLATException::inconsistent_response(G_READ_EDISP,
403   - norm->number(), size);
  404 + std::string msg = "Number of elements in \"NORM\" column ("+
  405 + gammalib::str(norm->number())+") is incompatible "
  406 + "with the expected size ("+
  407 + gammalib::str(size)+"). Please specify a valid "
  408 + "point spread function table.";
  409 + throw GException::invalid_argument(G_READ, msg);
404 410 }
405 411 if (ls1->number() != size) {
406   - throw GLATException::inconsistent_response(G_READ_EDISP,
407   - ls1->number(), size);
  412 + std::string msg = "Number of elements in \"LS1\" column ("+
  413 + gammalib::str(ls1->number())+") is incompatible "
  414 + "with the expected size ("+
  415 + gammalib::str(size)+"). Please specify a valid "
  416 + "point spread function table.";
  417 + throw GException::invalid_argument(G_READ, msg);
408 418 }
409 419  
410 420 // Copy data
... ...
inst/lat/src/GLATEventAtom.cpp
1 1 /***************************************************************************
2 2 * GLATEventAtom.cpp - LAT event atom class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2009-2013 by Juergen Knoedlseder *
  4 + * copyright (C) 2009-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -29,9 +29,8 @@
29 29 #include <config.h>
30 30 #endif
31 31 #include <string>
32   -#include "GLATEventAtom.hpp"
33   -#include "GLATException.hpp"
34 32 #include "GTools.hpp"
  33 +#include "GLATEventAtom.hpp"
35 34  
36 35 /* __ Method name definitions ____________________________________________ */
37 36  
... ...
inst/lat/src/GLATEventBin.cpp
1 1 /***************************************************************************
2 2 * GLATEventBin.cpp - Fermi/LAT event bin class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2009-2013 by Juergen Knoedlseder *
  4 + * copyright (C) 2009-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -30,9 +30,9 @@
30 30 #endif
31 31 #include <string>
32 32 #include <cmath>
33   -#include "GLATEventBin.hpp"
34   -#include "GLATException.hpp"
  33 +#include "GException.hpp"
35 34 #include "GTools.hpp"
  35 +#include "GLATEventBin.hpp"
36 36  
37 37 /* __ Method name definitions ____________________________________________ */
38 38 #define G_DIR "GLATEventBin::dir()"
... ... @@ -201,8 +201,8 @@ double GLATEventBin::size(void) const
201 201 *
202 202 * @return Instrument direction of event bin.
203 203 *
204   - * @exception GLATException::no_member
205   - * Invalid instrument direction pointer.
  204 + * @exception GException::invalid_value
  205 + * Invalid instrument direction pointer encountered.
206 206 *
207 207 * Returns reference to the instrument direction of the event bin.
208 208 ***************************************************************************/
... ... @@ -210,8 +210,9 @@ const GLATInstDir&amp; GLATEventBin::dir(void) const
210 210 {
211 211 // Throw an exception if instrument direction pointer is not valid
212 212 if (m_dir == NULL) {
213   - throw GLATException::no_member(G_DIR,
214   - "Invalid instrument direction pointer.");
  213 + std::string msg = "Invalid instrument direction pointer encountered. "
  214 + "Please set up the event bin correctly.";
  215 + throw GException::invalid_value(G_DIR, msg);
215 216 }
216 217  
217 218 // Return instrument direction
... ... @@ -224,8 +225,8 @@ const GLATInstDir&amp; GLATEventBin::dir(void) const
224 225 *
225 226 * @return Energy of event bin.
226 227 *
227   - * @exception GLATException::no_member
228   - * Invalid energy pointer.
  228 + * @exception GException::invalid_value
  229 + * Invalid energy pointer encountered.
229 230 *
230 231 * Returns reference to the energy of the event bin.
231 232 ***************************************************************************/
... ... @@ -233,8 +234,9 @@ const GEnergy&amp; GLATEventBin::energy(void) const
233 234 {
234 235 // Throw an exception if energy pointer is not valid
235 236 if (m_energy == NULL) {
236   - throw GLATException::no_member(G_ENERGY,
237   - "Invalid energy pointer.");
  237 + std::string msg = "Invalid energy pointer encountered. Please set up "
  238 + "the event bin correctly.";
  239 + throw GException::invalid_value(G_ENERGY, msg);
238 240 }
239 241  
240 242 // Return energy
... ... @@ -247,8 +249,8 @@ const GEnergy&amp; GLATEventBin::energy(void) const
247 249 *
248 250 * @return Time of event bin.
249 251 *
250   - * @exception GLATException::no_member
251   - * Invalid time pointer.
  252 + * @exception GException::invalid_value
  253 + * Invalid time pointer encountered.
252 254 *
253 255 * Returns reference to the time of the event bin.
254 256 ***************************************************************************/
... ... @@ -256,8 +258,9 @@ const GTime&amp; GLATEventBin::time(void) const
256 258 {
257 259 // Throw an exception if time pointer is not valid
258 260 if (m_time == NULL) {
259   - throw GLATException::no_member(G_TIME,
260   - "Invalid time pointer.");
  261 + std::string msg = "Invalid time pointer encountered. Please set up "
  262 + "the event bin correctly.";
  263 + throw GException::invalid_value(G_TIME, msg);
261 264 }
262 265  
263 266 // Return time
... ... @@ -279,8 +282,9 @@ double GLATEventBin::counts(void) const
279 282 {
280 283 // Throw an exception if counts pointer is not valid
281 284 if (m_counts == NULL) {
282   - throw GLATException::no_member(G_COUNTS_GET,
283   - "Invalid counts pointer.");
  285 + std::string msg = "Invalid counts pointer encountered. Please set up "
  286 + "the event bin correctly.";
  287 + throw GException::invalid_value(G_COUNTS_GET, msg);
284 288 }
285 289  
286 290 // Return counts
... ... @@ -293,8 +297,8 @@ double GLATEventBin::counts(void) const
293 297 *
294 298 * @param[in] counts Number of counts.
295 299 *
296   - * @exception GLATException::no_member
297   - * Invalid counts pointer.
  300 + * @exception GException::invalid_value
  301 + * Invalid counts pointer encountered.
298 302 *
299 303 * Set the number of counts in the event bin.
300 304 ***************************************************************************/
... ... @@ -302,8 +306,9 @@ void GLATEventBin::counts(const double&amp; counts)
302 306 {
303 307 // Throw an exception if counts pointer is not valid
304 308 if (m_counts == NULL) {
305   - throw GLATException::no_member(G_COUNTS_SET,
306   - "Invalid counts pointer.");
  309 + std::string msg = "Invalid counts pointer encountered. Please set up "
  310 + "the event bin correctly.";
  311 + throw GException::invalid_value(G_COUNTS_SET, msg);
307 312 }
308 313  
309 314 // Set number of counts in event bin
... ... @@ -342,8 +347,8 @@ double GLATEventBin::error(void) const
342 347 *
343 348 * @return Solid angle of event bin.
344 349 *
345   - * @exception GLATException::no_member
346   - * Invalid solid angle pointer.
  350 + * @exception GException::invalid_value
  351 + * Invalid solid angle pointer encountered.
347 352 *
348 353 * Returns reference to the solid angle of the event bin.
349 354 ***************************************************************************/
... ... @@ -351,8 +356,9 @@ const double&amp; GLATEventBin::solidangle(void) const
351 356 {
352 357 // Throw an exception if solid angle pointer is not valid
353 358 if (m_solidangle == NULL) {
354   - throw GLATException::no_member(G_SOLIDANGLE,
355   - "Invalid solid angle pointer.");
  359 + std::string msg = "Invalid solid angle pointer encountered. Please "
  360 + "set up the event bin correctly.";
  361 + throw GException::invalid_value(G_SOLIDANGLE, msg);
356 362 }
357 363  
358 364 // Return solid angle
... ... @@ -365,8 +371,8 @@ const double&amp; GLATEventBin::solidangle(void) const
365 371 *
366 372 * @return Energy width of event bin.
367 373 *
368   - * @exception GLATException::no_member
369   - * Invalid energy width pointer.
  374 + * @exception GException::invalid_value
  375 + * Invalid energy width pointer encountered.
370 376 *
371 377 * Returns reference to the energy width of the event bin.
372 378 ***************************************************************************/
... ... @@ -374,8 +380,9 @@ const GEnergy&amp; GLATEventBin::ewidth(void) const
374 380 {
375 381 // Throw an exception if energy width pointer is not valid
376 382 if (m_ewidth == NULL) {
377   - throw GLATException::no_member(G_EWIDTH,
378   - "Invalid energy width pointer.");
  383 + std::string msg = "Invalid energy width pointer encountered. Please "
  384 + "set up the event bin correctly.";
  385 + throw GException::invalid_value(G_EWIDTH, msg);
379 386 }
380 387  
381 388 // Return energy width
... ... @@ -388,8 +395,8 @@ const GEnergy&amp; GLATEventBin::ewidth(void) const
388 395 *
389 396 * @return Ontime of event bin.
390 397 *
391   - * @exception GLATException::no_member
392   - * Invalid ontime pointer.
  398 + * @exception GException::invalid_value
  399 + * Invalid ontime pointer encountered.
393 400 *
394 401 * Returns reference to the ontime of the event bin.
395 402 ***************************************************************************/
... ... @@ -397,8 +404,9 @@ const double&amp; GLATEventBin::ontime(void) const
397 404 {
398 405 // Throw an exception if ontime pointer is not valid
399 406 if (m_ontime == NULL) {
400   - throw GLATException::no_member(G_ONTIME,
401   - "Invalid ontime pointer.");
  407 + std::string msg = "Invalid ontime pointer encountered. Please set up "
  408 + "the event bin correctly.";
  409 + throw GException::invalid_value(G_ONTIME, msg);
402 410 }
403 411  
404 412 // Return ontime
... ... @@ -409,7 +417,7 @@ const double&amp; GLATEventBin::ontime(void) const
409 417 /***********************************************************************//**
410 418 * @brief Print event information
411 419 *
412   - * @param[in] chatter Chattiness (defaults to NORMAL).
  420 + * @param[in] chatter Chattiness.
413 421 * @return String containing number of counts in event bin.
414 422 ***************************************************************************/
415 423 std::string GLATEventBin::print(const GChatter& chatter) const
... ...
inst/lat/src/GLATEventCube.cpp
1 1 /***************************************************************************
2 2 * GLATEventCube.cpp - Fermi/LAT event cube class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2009-2019 by Juergen Knoedlseder *
  4 + * copyright (C) 2009-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -28,12 +28,12 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
  31 +#include "GException.hpp"
31 32 #include "GTools.hpp"
32 33 #include "GFilename.hpp"
33 34 #include "GFitsImage.hpp"
34 35 #include "GFitsTable.hpp"
35 36 #include "GLATEventCube.hpp"
36   -#include "GLATException.hpp"
37 37  
38 38 /* __ Method name definitions ____________________________________________ */
39 39 #define G_NAXIS "GLATEventCube::naxis(int)"
... ... @@ -280,7 +280,8 @@ int GLATEventCube::naxis(const int&amp; axis) const
280 280 // Optionally check if the axis is valid
281 281 #if defined(G_RANGE_CHECK)
282 282 if (axis < 0 || axis >= dim()) {
283   - throw GException::out_of_range(G_NAXIS, "LAT event cube axis", axis, dim());
  283 + throw GException::out_of_range(G_NAXIS, "LAT event cube axis",
  284 + axis, dim());
284 285 }
285 286 #endif
286 287  
... ... @@ -486,7 +487,7 @@ void GLATEventCube::map(const GSkyMap&amp; map)
486 487 /***********************************************************************//**
487 488 * @brief Print event cube information
488 489 *
489   - * @param[in] chatter Chattiness (defaults to NORMAL).
  490 + * @param[in] chatter Chattiness.
490 491 * @return String containing event cube information.
491 492 ***************************************************************************/
492 493 std::string GLATEventCube::print(const GChatter& chatter) const
... ... @@ -578,7 +579,8 @@ std::string GLATEventCube::diffname(const int&amp; index) const
578 579 // Optionally check if the index is valid
579 580 #if defined(G_RANGE_CHECK)
580 581 if (index < 0 || index >= ndiffrsp()) {
581   - throw GException::out_of_range(G_DIFFNAME, index, 0, ndiffrsp()-1);
  582 + throw GException::out_of_range(G_DIFFNAME, "Diffuse model index",
  583 + index, ndiffrsp());
582 584 }
583 585 #endif
584 586  
... ... @@ -603,7 +605,8 @@ GSkyMap* GLATEventCube::diffrsp(const int&amp; index) const
603 605 // Optionally check if the index is valid
604 606 #if defined(G_RANGE_CHECK)
605 607 if (index < 0 || index >= ndiffrsp()) {
606   - throw GException::out_of_range(G_DIFFRSP, index, 0, ndiffrsp()-1);
  608 + throw GException::out_of_range(G_DIFFRSP, "Diffuse model index",
  609 + index, ndiffrsp());
607 610 }
608 611 #endif
609 612  
... ... @@ -786,8 +789,8 @@ void GLATEventCube::read_cntmap(const GFitsImage&amp; hdu)
786 789 *
787 790 * @param[in] hdu Image HDU.
788 791 *
789   - * @exception GLATException::wcs_incompatible
790   - * Source map not compatible with sky map
  792 + * @exception GException::invalid_argument
  793 + * Source map in @p hdu is not compatible with event cube.
791 794 *
792 795 * This method reads a LAT source map from a FITS image. The source map is
793 796 * stored in a GSkyMap object and is given in units of counts/pixel/MeV.
... ... @@ -803,19 +806,34 @@ void GLATEventCube::read_srcmap(const GFitsImage&amp; hdu)
803 806 // Check that source map sky projection is consistent with counts
804 807 // map sky projection
805 808 if (*(m_map.projection()) != *(map->projection())) {
806   - throw GLATException::wcs_incompatible(G_READ_SRCMAP, hdu.extname());
  809 + std::string msg = "Specified source map projection in HDU \""+
  810 + hdu.extname()+"\" is incompatible with map projection "
  811 + "of the event cube. Please specify a compatible "
  812 + "map projection.";
  813 + throw GException::invalid_argument(G_READ_SRCMAP, msg);
807 814 }
808 815  
809 816 // Check that source map dimension is consistent with counts map
810 817 // dimension
811 818 if (m_map.nx() != map->nx() ||
812 819 m_map.ny() != map->ny()) {
813   - throw GLATException::wcs_incompatible(G_READ_SRCMAP, hdu.extname());
  820 + std::string msg = "Number of pixels ("+gammalib::str(map->nx())+","+
  821 + gammalib::str(map->ny())+") in source map in HDU \""+
  822 + hdu.extname()+"\" is not compatible with number of "
  823 + "pixels ("+gammalib::str(m_map.nx())+","+
  824 + gammalib::str(m_map.ny())+") in the event cube. "
  825 + "Please specify a source map of compatible size.";
  826 + throw GException::invalid_argument(G_READ_SRCMAP, msg);
814 827 }
815 828  
816 829 // Check that source map has required number of energy bins
817 830 if (m_map.nmaps()+1 != map->nmaps()) {
818   - throw GLATException::wcs_incompatible(G_READ_SRCMAP, hdu.extname());
  831 + std::string msg = "Number of maps ("+gammalib::str(map->nmaps())+")"+
  832 + " in source map in HDU \""+hdu.extname()+"\" is not "
  833 + "compatible with number of energy bin boundaries ("+
  834 + gammalib::str(m_map.nmaps()+1)+") of the event cube. "
  835 + "Please specify a source map of compatible size.";
  836 + throw GException::invalid_argument(G_READ_SRCMAP, msg);
819 837 }
820 838  
821 839 // Append source map to list of maps
... ... @@ -897,7 +915,7 @@ void GLATEventCube::read_gti(const GFitsTable&amp; hdu)
897 915 /***********************************************************************//**
898 916 * @brief Set sky directions and solid angles of events cube.
899 917 *
900   - * @exception GLATException::no_sky
  918 + * @exception GException::invalid_value
901 919 * No sky pixels found in event cube.
902 920 *
903 921 * This method computes the sky directions and solid angles for all event
... ... @@ -906,10 +924,11 @@ void GLATEventCube::read_gti(const GFitsTable&amp; hdu)
906 924 ***************************************************************************/
907 925 void GLATEventCube::set_directions(void)
908 926 {
909   - // Throw an error if we have no sky pixels
  927 + // Throw an exception if we have no sky pixels
910 928 if (npix() < 1) {
911   - throw GLATException::no_sky(G_SET_DIRECTIONS, "Every LAT event cube"
912   - " needs a definition of the sky pixels.");
  929 + std::string msg = "LAT event cube contains no sky pixels. Please "
  930 + "provide a valid LAT event cube.";
  931 + throw GException::invalid_value(G_SET_DIRECTIONS, msg);
913 932 }
914 933  
915 934 // Clear old pixel directions and solid angle
... ... @@ -937,7 +956,7 @@ void GLATEventCube::set_directions(void)
937 956 /***********************************************************************//**
938 957 * @brief Set log mean energies and energy widths of event cube.
939 958 *
940   - * @exception GLATException::no_ebds
  959 + * @exception GException::invalid_value
941 960 * No energy boundaries found in event cube.
942 961 *
943 962 * This method computes the log mean energies and the energy widths of the
... ... @@ -948,8 +967,9 @@ void GLATEventCube::set_energies(void)
948 967 {
949 968 // Throw an error if we have no energy bins
950 969 if (ebins() < 1) {
951   - throw GLATException::no_ebds(G_SET_ENERGIES, "Every LAT event cube"
952   - " needs a definition of the energy boundaries.");
  970 + std::string msg = "LAT event cube contains no energy bins. Please "
  971 + "provide a valid LAT event cube.";
  972 + throw GException::invalid_value(G_SET_ENERGIES, msg);
953 973 }
954 974  
955 975 // Clear old bin energies and energy widths
... ... @@ -1016,9 +1036,8 @@ void GLATEventCube::set_times(void)
1016 1036 *
1017 1037 * @exception GException::out_of_range
1018 1038 * Event index is outside valid range.
1019   - * @exception GLATException::no_energies
  1039 + * @exception GException::invalid_value
1020 1040 * Energy vectors have not been set up.
1021   - * @exception GLATException::no_dirs
1022 1041 * Sky directions and solid angles vectors have not been set up.
1023 1042 *
1024 1043 * This method provides the event attributes to the event bin. The event bin
... ... @@ -1038,12 +1057,24 @@ void GLATEventCube::set_bin(const int&amp; index)
1038 1057  
1039 1058 // Check for the existence of energies and energy widths
1040 1059 if (m_energies.size() != ebins() || m_ewidth.size() != ebins()) {
1041   - throw GLATException::no_energies(G_SET_BIN);
  1060 + std::string msg = "Number of energy bins ("+gammalib::str(ebins())+
  1061 + ") is incompatible with size of energies ("+
  1062 + gammalib::str(m_energies.size())+") an/or size of "
  1063 + "energy widths ("+gammalib::str(m_ewidth.size())+
  1064 + "). Please provide an correctly initialised event "
  1065 + "cube.";
  1066 + throw GException::invalid_value(G_SET_BIN, msg);
1042 1067 }
1043 1068  
1044 1069 // Check for the existence of sky directions and solid angles
1045 1070 if (m_dirs.size() != npix() || m_solidangle.size() != npix()) {
1046   - throw GLATException::no_dirs(G_SET_BIN);
  1071 + std::string msg = "Number of sky pixels ("+gammalib::str(npix())+
  1072 + ") is incompatible with size of sky directions ("+
  1073 + gammalib::str(m_dirs.size())+") and/or size of "
  1074 + "solid angles ("+gammalib::str(m_solidangle.size())+
  1075 + "). Please provide an correctly initialised event "
  1076 + "cube.";
  1077 + throw GException::invalid_value(G_SET_BIN, msg);
1047 1078 }
1048 1079  
1049 1080 // Get pixel and energy bin indices.
... ...
inst/lat/src/GLATEventList.cpp
1 1 /***************************************************************************
2 2 * GLATEventList.cpp - Fermi/LAT event list class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2009-2020 by Juergen Knoedlseder *
  4 + * copyright (C) 2009-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -38,7 +38,6 @@
38 38 #include "GFitsTableLongCol.hpp"
39 39 #include "GFitsTableShortCol.hpp"
40 40 #include "GLATEventList.hpp"
41   -#include "GLATException.hpp"
42 41  
43 42 /* __ Method name definitions ____________________________________________ */
44 43 #define G_OPERATOR "GLATEventList::operator[](int&)"
... ... @@ -358,25 +357,28 @@ void GLATEventList::write(GFits&amp; file) const
358 357  
359 358  
360 359 /***********************************************************************//**
361   - * @brief Set region of interest
  360 + * @brief Set Region of Interest
362 361 *
363   - * @param[in] roi Region of interest.
  362 + * @param[in] roi Region of Interest.
364 363 *
365   - * @exception GLATException::bad_roi_type
366   - * ROI is not of type GLATRoi.
  364 + * @exception GException::invalid_argument
  365 + * Region of Interest @p roi in not a LAT Region of Interest.
367 366 ***************************************************************************/
368 367 void GLATEventList::roi(const GRoi& roi)
369 368 {
370   - // Cast ROI dynamically
371   - const GLATRoi* ptr = dynamic_cast<const GLATRoi*>(&roi);
372   -
373   - // Throw exception if ROI is not of correct type
374   - if (ptr == NULL) {
375   - throw GLATException::bad_roi_type(G_ROI);
  369 + // Cast RoI dynamically
  370 + const GLATRoi* latroi = dynamic_cast<const GLATRoi*>(&roi);
  371 +
  372 + // Throw exception if RoI is not of correct type
  373 + if (latroi == NULL) {
  374 + std::string cls = std::string(typeid(&roi).name());
  375 + std::string msg = "Invalid RoI type \""+cls+"\" specified. Please "
  376 + "specify a \"GLATRoi\" instance as argument.";
  377 + throw GException::invalid_argument(G_ROI, msg);
376 378 }
377 379  
378   - // Set ROI
379   - m_roi = *ptr;
  380 + // Copy RoI
  381 + m_roi = *latroi;
380 382  
381 383 // Return
382 384 return;
... ...
inst/lat/src/GLATException.cpp deleted
1   -/***************************************************************************
2   - * GLATException.cpp - LAT exception handler *
3   - * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2011 by Jurgen Knodlseder *
5   - * ----------------------------------------------------------------------- *
6   - * This program is free software: you can redistribute it and/or modify *
7   - * it under the terms of the GNU General Public License as published by *
8   - * the Free Software Foundation, either version 3 of the License, or *
9   - * (at your option) any later version. *
10   - * *
11   - * This program is distributed in the hope that it will be useful, *
12   - * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14   - * GNU General Public License for more details. *
15   - * *
16   - * You should have received a copy of the GNU General Public License *
17   - * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18   - * *
19   - ***************************************************************************/
20   -/**
21   - * @file GLATException.cpp
22   - * @brief LAT exception handler interface implementation.
23   - * @author J. Knodlseder
24   - */
25   -
26   -/* __ Includes ___________________________________________________________ */
27   -#include "GLATException.hpp"
28   -#include "GTools.hpp"
29   -
30   -
31   -/***********************************************************************//**
32   - * @brief Exception message.
33   - ***************************************************************************/
34   -const char* GLATExceptionHandler::what() const throw()
35   -{
36   - // Set error message
37   - std::string message = "*** ERROR in " + m_origin + ": " + m_message;
38   -
39   - // Return message as C character array
40   - return gammalib::tochar(message);
41   -}
42   -
43   -
44   -/***********************************************************************//**
45   - * @brief Error while opening file.
46   - *
47   - * @param[in] origin Name of method that has thrown the exception.
48   - * @param[in] filename Name of file that could not be opened.
49   - * @param[in] message Optional error message.
50   - ***************************************************************************/
51   -GLATException::file_open_error::file_open_error(std::string origin,
52   - std::string filename,
53   - std::string message)
54   -{
55   - m_origin = origin;
56   - m_message = "Unable to open file '"+filename+"'. "+message;
57   - return;
58   -}
59   -
60   -
61   -/***********************************************************************//**
62   - * @brief Member not set.
63   - *
64   - * @param[in] origin Name of method that has thrown the exception.
65   - * @param[in] message Error message.
66   - ***************************************************************************/
67   -GLATException::no_member::no_member(const std::string& origin,
68   - const std::string& message)
69   -{
70   - // Set origin and message
71   - m_origin = origin;
72   - m_message = message;
73   -
74   - // Return
75   - return;
76   -}
77   -
78   -
79   -/***********************************************************************//**
80   - * @brief No sky pixels found.
81   - *
82   - * @param[in] origin Name of method that has thrown the exception.
83   - * @param[in] message Optional error message.
84   - ***************************************************************************/
85   -GLATException::no_sky::no_sky(std::string origin, std::string message)
86   -{
87   - m_origin = origin;
88   - m_message = "No sky pixels have been found. "+message;
89   - return;
90   -}
91   -
92   -
93   -/***********************************************************************//**
94   - * @brief No energy boundary information found.
95   - *
96   - * @param[in] origin Name of method that has thrown the exception.
97   - * @param[in] message Optional error message.
98   - ***************************************************************************/
99   -GLATException::no_ebds::no_ebds(std::string origin, std::string message)
100   -{
101   - m_origin = origin;
102   - m_message = "No energy boundaries have been found. "+message;
103   - return;
104   -}
105   -
106   -
107   -/***********************************************************************//**
108   - * @brief No Good Time Intervals found.
109   - *
110   - * @param[in] origin Name of method that has thrown the exception.
111   - * @param[in] message Optional error message.
112   - ***************************************************************************/
113   -GLATException::no_gti::no_gti(std::string origin, std::string message)
114   -{
115   - m_origin = origin;
116   - m_message = "No Good Time Intervals (GTIs) have been found. "+message;
117   - return;
118   -}
119   -
120   -
121   -/***********************************************************************//**
122   - * @brief No Livetime Cube found.
123   - *
124   - * @param[in] origin Name of method that has thrown the exception.
125   - * @param[in] message Optional error message.
126   - ***************************************************************************/
127   -GLATException::no_ltcube::no_ltcube(std::string origin, std::string message)
128   -{
129   - m_origin = origin;
130   - m_message = "No Livetime Cube have been found. "+message;
131   - return;
132   -}
133   -
134   -
135   -/***********************************************************************//**
136   - * @brief No energies set
137   - *
138   - * @param[in] origin Name of method that has thrown the exception.
139   - * @param[in] message Optional error message.
140   - ***************************************************************************/
141   -GLATException::no_energies::no_energies(std::string origin, std::string message)
142   -{
143   - // Set origin
144   - m_origin = origin;
145   -
146   - // Set message
147   - m_message = "Energy vector has not been setup."
148   - " Cannot access event information.";
149   - if (message.length() > 0)
150   - m_message += " "+message;
151   -
152   - // Return
153   - return;
154   -}
155   -
156   -
157   -/***********************************************************************//**
158   - * @brief No sky directions set
159   - *
160   - * @param[in] origin Name of method that has thrown the exception.
161   - * @param[in] message Optional error message.
162   - ***************************************************************************/
163   -GLATException::no_dirs::no_dirs(std::string origin, std::string message)
164   -{
165   - // Set origin
166   - m_origin = origin;
167   -
168   - // Set message
169   - m_message = "Sky direction vector has not been setup."
170   - " Cannot access event information.";
171   - if (message.length() > 0)
172   - m_message += " "+message;
173   -
174   - // Return
175   - return;
176   -}
177   -
178   -
179   -/***********************************************************************//**
180   - * @brief ROI is not a LAT ROI
181   - *
182   - * @param[in] origin Name of method that has thrown the exception.
183   - * @param[in] message Optional error message.
184   - ***************************************************************************/
185   -GLATException::bad_roi_type::bad_roi_type(std::string origin, std::string message)
186   -{
187   - // Set origin
188   - m_origin = origin;
189   -
190   - // Set message
191   - m_message = "Specified ROI is not of type GLATRoi.";
192   - if (message.length() > 0)
193   - m_message += " "+message;
194   -
195   - // Return
196   - return;
197   -}
198   -
199   -
200   -/***********************************************************************//**
201   - * @brief Instrument direction is not a CTA instrument direction
202   - *
203   - * @param[in] origin Name of method that has thrown the exception.
204   - * @param[in] message Optional error message.
205   - ***************************************************************************/
206   -GLATException::bad_instdir_type::bad_instdir_type(std::string origin,
207   - std::string message)
208   -{
209   - // Set origin
210   - m_origin = origin;
211   -
212   - // Set message
213   - m_message = "Instrument direction is not of type GLATInstDir.";
214   - if (message.length() > 0)
215   - m_message += " "+message;
216   -
217   - // Return
218   - return;
219   -}
220   -
221   -
222   -/***********************************************************************//**
223   - * @brief Invalid response found
224   - *
225   - * @param[in] origin Name of method that has thrown the exception.
226   - * @param[in] message Optional error message.
227   - ***************************************************************************/
228   -GLATException::invalid_response::invalid_response(std::string origin,
229   - std::string message)
230   -{
231   - m_origin = origin;
232   - m_message = "Invalid response encountered. " + message;
233   - return;
234   -}
235   -
236   -
237   -/***********************************************************************//**
238   - * @brief Incompatible source map
239   - *
240   - * @param[in] origin Name of method that has thrown the exception.
241   - * @param[in] name Map name.
242   - * @param[in] message Optional error message.
243   - ***************************************************************************/
244   -GLATException::wcs_incompatible::wcs_incompatible(std::string origin,
245   - std::string name,
246   - std::string message)
247   -{
248   - m_origin = origin;
249   - m_message = "Source map \""+name+"\" incompatible with counts map. " +
250   - message;
251   - return;
252   -}
253   -
254   -
255   -/***********************************************************************//**
256   - * @brief Diffuse model not found
257   - *
258   - * @param[in] origin Name of method that has thrown the exception.
259   - * @param[in] name Diffuse model.
260   - * @param[in] message Optional error message.
261   - ***************************************************************************/
262   -GLATException::diffuse_not_found::diffuse_not_found(std::string origin,
263   - std::string name,
264   - std::string message)
265   -{
266   - m_origin = origin;
267   - m_message = "Diffuse model \""+name+"\" not found. " +
268   - message;
269   - return;
270   -}
271   -
272   -
273   -/***********************************************************************//**
274   - * @brief Inconsistent response table
275   - *
276   - * @param[in] origin Name of method that has thrown the exception.
277   - * @param[in] size Size.
278   - * @param[in] expect Expected size.
279   - * @param[in] message Optional error message.
280   - ***************************************************************************/
281   -GLATException::inconsistent_response::inconsistent_response(std::string origin,
282   - int size,
283   - int expect,
284   - std::string message)
285   -{
286   - m_origin = origin;
287   - m_message = "Inconsistent response table found. Expected "+gammalib::str(expect)+
288   - " elements, found "+gammalib::str(size)+". " + message;
289   - return;
290   -}
291   -
292   -
293   -/***********************************************************************//**
294   - * @brief Response is not a LAT response
295   - *
296   - * @param[in] origin Name of method that has thrown the exception.
297   - * @param[in] message Optional error message.
298   - ***************************************************************************/
299   -GLATException::bad_response_type::bad_response_type(std::string origin,
300   - std::string message)
301   -{
302   - // Set origin
303   - m_origin = origin;
304   -
305   - // Set message
306   - m_message = "Response is not of type GLATResponse.";
307   - if (message.length() > 0)
308   - m_message += " "+message;
309   -
310   - // Return
311   - return;
312   -}
inst/lat/src/GLATMeanPsf.cpp
1 1 /***************************************************************************
2 2 * GLATMeanPsf.cpp - Fermi/LAT mean PSF class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -29,14 +29,14 @@
29 29 #include <config.h>
30 30 #endif
31 31 #include <cmath>
32   -#include "GLATMeanPsf.hpp"
  32 +#include "GException.hpp"
33 33 #include "GTools.hpp"
34 34 #include "GMath.hpp"
35 35 #include "GLATAeff.hpp"
36 36 #include "GLATPsf.hpp"
37 37 #include "GLATObservation.hpp"
38 38 #include "GLATEventCube.hpp"
39   -#include "GLATException.hpp"
  39 +#include "GLATMeanPsf.hpp"
40 40  
41 41 /* __ Method name definitions ____________________________________________ */
42 42 #define G_SET "GLATMeanPsf::set(GSkyDir&, GLATObservation&)"
... ... @@ -287,8 +287,8 @@ GLATMeanPsf* GLATMeanPsf::clone(void) const
287 287 * @param[in] dir Source location.
288 288 * @param[in] obs LAT observation.
289 289 *
290   - * @exception GLATException::no_ltcube
291   - * Livetime cube has not been defined.
  290 + * @exception GException::invalid_argument
  291 + * No livetime cube found in observation.
292 292 *
293 293 * Computes the mean PSF and the energy dependent exposure for a source at
294 294 * a given sky location. The PSF is computed for all bin boundaries of the
... ... @@ -308,7 +308,10 @@ void GLATMeanPsf::set(const GSkyDir&amp; dir, const GLATObservation&amp; obs)
308 308 // Get pointer on livetime cube
309 309 const GLATLtCube* ltcube = obs.ltcube();
310 310 if (ltcube == NULL) {
311   - throw GLATException::no_ltcube(G_SET);
  311 + std::string msg = "Observation does not contain a livetime cube. "
  312 + "Please specify an observation containing a livetime "
  313 + "cube.";
  314 + throw GException::invalid_argument(G_SET, msg);
312 315 }
313 316  
314 317 // Get energy boundaries
... ...
inst/lat/src/GLATObservation.cpp
1 1 /***************************************************************************
2 2 * GLATObservation.cpp - Fermi LAT observation class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2020 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -34,7 +34,6 @@
34 34 #include "GLATEventList.hpp"
35 35 #include "GLATEventCube.hpp"
36 36 #include "GLATRoi.hpp"
37   -#include "GLATException.hpp"
38 37 #include "GFits.hpp"
39 38 #include "GTools.hpp"
40 39 #include "GEnergy.hpp"
... ... @@ -202,8 +201,8 @@ GLATObservation* GLATObservation::clone(void) const
202 201 *
203 202 * @param[in] rsp Response function.
204 203 *
205   - * @exception GLATException::bad_response_type
206   - * Specified response in not of type GLATResponse.
  204 + * @exception GException::invalid_argument
  205 + * Response @p rsp in not a LAT response.
207 206 *
208 207 * Sets the response function for the observation. The argument has to be of
209 208 * type GLATResponse, otherwise an exception is thrown.
... ... @@ -212,8 +211,14 @@ void GLATObservation::response(const GResponse&amp; rsp)
212 211 {
213 212 // Get pointer on LAT response
214 213 const GLATResponse* latrsp = dynamic_cast<const GLATResponse*>(&rsp);
  214 +
  215 + // If pointer is not valid then throw an exception
215 216 if (latrsp == NULL) {
216   - throw GLATException::bad_response_type(G_RESPONSE);
  217 + std::string cls = std::string(typeid(&rsp).name());
  218 + std::string msg = "Invalid response type \""+cls+"\" specified. "
  219 + "Please specify a \"GLATResponse\" instance as "
  220 + "argument.";
  221 + throw GException::invalid_argument(G_RESPONSE, msg);
217 222 }
218 223  
219 224 // Copy response function
... ...
inst/lat/src/GLATPsf.cpp
1 1 /***************************************************************************
2 2 * GLATPsf.cpp - Fermi LAT point spread function *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2018 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -28,6 +28,7 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
  31 +#include "GException.hpp"
31 32 #include "GTools.hpp"
32 33 #include "GFilename.hpp"
33 34 #include "GFits.hpp"
... ... @@ -36,7 +37,6 @@
36 37 #include "GLATPsf.hpp"
37 38 #include "GLATPsfV1.hpp"
38 39 #include "GLATPsfV3.hpp"
39   -#include "GLATException.hpp"
40 40  
41 41 /* __ Method name definitions ____________________________________________ */
42 42 #define G_READ "GLATPsf::read(GFits&)"
... ... @@ -271,8 +271,8 @@ void GLATPsf::save(const GFilename&amp; filename, const bool&amp; clobber)
271 271 * @param[in] fits FITS file.
272 272 * @param[in] evtype Event type.
273 273 *
274   - * @exception GException::invalid_response
275   - * Invalid response type or unsupported response version found.
  274 + * @exception GException::invalid_value
  275 + * Unsupported response version found.
276 276 *
277 277 * Reads the Fermi LAT point spread function from FITS file. The method
278 278 * determines the PSF version from the information found in the FITS file
... ... @@ -332,8 +332,10 @@ void GLATPsf::read(const GFits&amp; fits, const std::string&amp; evtype)
332 332 m_psf = new GLATPsfV3;
333 333 break;
334 334 default:
335   - throw GLATException::invalid_response(G_READ,
336   - "Unsupported response function version "+gammalib::str(version)+".");
  335 + std::string msg = "Unsupported response function version "+
  336 + gammalib::str(version)+". Please specify either a "
  337 + "version 1 or 3 point spread function.";
  338 + throw GException::invalid_value(G_READ, msg);
337 339 break;
338 340 }
339 341  
... ...
inst/lat/src/GLATPsfBase.cpp
1 1 /***************************************************************************
2 2 * GLATPsfBase.cpp - Abstract Fermi LAT point spread function base class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012-2016 by Juergen Knoedlseder *
  4 + * copyright (C) 2012-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -28,11 +28,10 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include "GLATPsfBase.hpp"
32   -#include "GLATException.hpp"
33 31 #include "GTools.hpp"
34 32 #include "GFitsBinTable.hpp"
35 33 #include "GFitsTableFloatCol.hpp"
  34 +#include "GLATPsfBase.hpp"
36 35  
37 36 /* __ Method name definitions ____________________________________________ */
38 37 #define G_READ_SCALE "GLATPsfBase::read_scale(GFitsTable&)"
... ...
inst/lat/src/GLATPsfV1.cpp
1 1 /***************************************************************************
2 2 * GLATPsfV1.cpp - Fermi/LAT point spread function version 1 class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012-2018 by Juergen Knoedlseder *
  4 + * copyright (C) 2012-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -28,12 +28,12 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include "GLATPsfV1.hpp"
32   -#include "GLATException.hpp"
  31 +#include "GException.hpp"
33 32 #include "GMath.hpp"
34 33 #include "GFitsBinTable.hpp"
35 34 #include "GFitsTableFloatCol.hpp"
36 35 #include "GIntegral.hpp"
  36 +#include "GLATPsfV1.hpp"
37 37  
38 38 /* __ Method name definitions ____________________________________________ */
39 39 #define G_READ "GLATPsfV1::read(GFitsTable&)"
... ... @@ -174,7 +174,7 @@ GLATPsfV1* GLATPsfV1::clone(void) const
174 174 *
175 175 * @param[in] table FITS table.
176 176 *
177   - * @exception GLATException::inconsistent_response
  177 + * @exception GException::invalid_argument
178 178 * Inconsistent response table encountered
179 179 *
180 180 * Reads point spread function information from FITS HDU. In addition to the
... ... @@ -213,20 +213,36 @@ void GLATPsfV1::read(const GFitsTable&amp; table)
213 213  
214 214 // Check consistency of columns
215 215 if (ncore->number() != size) {
216   - throw GLATException::inconsistent_response(G_READ,
217   - ncore->number(), size);
  216 + std::string msg = "Number of elements in \"NCORE\" column ("+
  217 + gammalib::str(ncore->number())+") is incompatible "
  218 + "with the expected size ("+
  219 + gammalib::str(size)+"). Please specify a valid "
  220 + "point spread function table.";
  221 + throw GException::invalid_argument(G_READ, msg);
218 222 }
219 223 if (sigma->number() != size) {
220   - throw GLATException::inconsistent_response(G_READ,
221   - sigma->number(), size);
  224 + std::string msg = "Number of elements in \"SIGMA\" column ("+
  225 + gammalib::str(sigma->number())+") is incompatible "
  226 + "with the expected size ("+
  227 + gammalib::str(size)+"). Please specify a valid "
  228 + "point spread function table.";
  229 + throw GException::invalid_argument(G_READ, msg);
222 230 }
223 231 if (gcore->number() != size) {
224   - throw GLATException::inconsistent_response(G_READ,
225   - gcore->number(), size);
  232 + std::string msg = "Number of elements in \"GCORE\" column ("+
  233 + gammalib::str(gcore->number())+") is incompatible "
  234 + "with the expected size ("+
  235 + gammalib::str(size)+"). Please specify a valid "
  236 + "point spread function table.";
  237 + throw GException::invalid_argument(G_READ, msg);
226 238 }
227 239 if (gtail->number() != size) {
228   - throw GLATException::inconsistent_response(G_READ,
229   - gtail->number(), size);
  240 + std::string msg = "Number of elements in \"GTAIL\" column ("+
  241 + gammalib::str(gtail->number())+") is incompatible "
  242 + "with the expected size ("+
  243 + gammalib::str(size)+"). Please specify a valid "
  244 + "point spread function table.";
  245 + throw GException::invalid_argument(G_READ, msg);
230 246 }
231 247  
232 248 // Copy data
... ...
inst/lat/src/GLATPsfV3.cpp
1 1 /***************************************************************************
2 2 * GLATPsfV3.cpp - Fermi/LAT point spread function version 3 class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012-2018 by Juergen Knoedlseder *
  4 + * copyright (C) 2012-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -28,12 +28,12 @@
28 28 #ifdef HAVE_CONFIG_H
29 29 #include <config.h>
30 30 #endif
31   -#include "GLATPsfV3.hpp"
32   -#include "GLATException.hpp"
  31 +#include "GException.hpp"
33 32 #include "GMath.hpp"
34 33 #include "GFitsBinTable.hpp"
35 34 #include "GFitsTableFloatCol.hpp"
36 35 #include "GIntegral.hpp"
  36 +#include "GLATPsfV3.hpp"
37 37  
38 38 /* __ Method name definitions ____________________________________________ */
39 39 #define G_READ "GLATPsfV3::read(GFitsTable&)"
... ... @@ -175,7 +175,7 @@ GLATPsfV3* GLATPsfV3::clone(void) const
175 175 *
176 176 * @param[in] table FITS table.
177 177 *
178   - * @exception GLATException::inconsistent_response
  178 + * @exception GException::invalid_argument
179 179 * Inconsistent response table encountered
180 180 *
181 181 * Reads point spread function information from FITS HDU. In addition to the
... ... @@ -224,28 +224,52 @@ void GLATPsfV3::read(const GFitsTable&amp; table)
224 224  
225 225 // Check consistency of columns
226 226 if (ncore->number() != size) {
227   - throw GLATException::inconsistent_response(G_READ,
228   - ncore->number(), size);
  227 + std::string msg = "Number of elements in \"NCORE\" column ("+
  228 + gammalib::str(ncore->number())+") is incompatible "
  229 + "with the expected size ("+
  230 + gammalib::str(size)+"). Please specify a valid "
  231 + "point spread function table.";
  232 + throw GException::invalid_argument(G_READ, msg);
229 233 }
230 234 if (ntail->number() != size) {
231   - throw GLATException::inconsistent_response(G_READ,
232   - ntail->number(), size);
  235 + std::string msg = "Number of elements in \"NTAIL\" column ("+
  236 + gammalib::str(ntail->number())+") is incompatible "
  237 + "with the expected size ("+
  238 + gammalib::str(size)+"). Please specify a valid "
  239 + "point spread function table.";
  240 + throw GException::invalid_argument(G_READ, msg);
233 241 }
234 242 if (score->number() != size) {
235   - throw GLATException::inconsistent_response(G_READ,
236   - score->number(), size);
  243 + std::string msg = "Number of elements in \"SCORE\" column ("+
  244 + gammalib::str(score->number())+") is incompatible "
  245 + "with the expected size ("+
  246 + gammalib::str(size)+"). Please specify a valid "
  247 + "point spread function table.";
  248 + throw GException::invalid_argument(G_READ, msg);
237 249 }
238 250 if (stail->number() != size) {
239   - throw GLATException::inconsistent_response(G_READ,
240   - stail->number(), size);
  251 + std::string msg = "Number of elements in \"STAIL\" column ("+
  252 + gammalib::str(stail->number())+") is incompatible "
  253 + "with the expected size ("+
  254 + gammalib::str(size)+"). Please specify a valid "
  255 + "point spread function table.";
  256 + throw GException::invalid_argument(G_READ, msg);
241 257 }
242 258 if (gcore->number() != size) {
243   - throw GLATException::inconsistent_response(G_READ,
244   - gcore->number(), size);
  259 + std::string msg = "Number of elements in \"GCORE\" column ("+
  260 + gammalib::str(gcore->number())+") is incompatible "
  261 + "with the expected size ("+
  262 + gammalib::str(size)+"). Please specify a valid "
  263 + "point spread function table.";
  264 + throw GException::invalid_argument(G_READ, msg);
245 265 }
246 266 if (gtail->number() != size) {
247   - throw GLATException::inconsistent_response(G_READ,
248   - gtail->number(), size);
  267 + std::string msg = "Number of elements in \"GTAIL\" column ("+
  268 + gammalib::str(gtail->number())+") is incompatible "
  269 + "with the expected size ("+
  270 + gammalib::str(size)+"). Please specify a valid "
  271 + "point spread function table.";
  272 + throw GException::invalid_argument(G_READ, msg);
249 273 }
250 274  
251 275 // Copy data
... ...
inst/lat/src/GLATResponse.cpp
1 1 /***************************************************************************
2 2 * GLATResponse.cpp - Fermi LAT response class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2008-2020 by Juergen Knoedlseder *
  4 + * copyright (C) 2008-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -43,7 +43,6 @@
43 43 #include "GLATEventAtom.hpp"
44 44 #include "GLATEventBin.hpp"
45 45 #include "GLATEventCube.hpp"
46   -#include "GLATException.hpp"
47 46  
48 47 /* __ Method name definitions ____________________________________________ */
49 48 #define G_CALDB "GLATResponse::caldb(std::string&)"
... ... @@ -53,6 +52,7 @@
53 52 #define G_NROI "GLATResponse::nroi(GModelSky&, GEnergy&, GTime&, "\
54 53 "GObservation&)"
55 54 #define G_EBOUNDS "GLATResponse::ebounds(GEnergy&)"
  55 +#define G_SAVE "GLATResponse::save(std::string&)"
56 56 #define G_AEFF "GLATResponse::aeff(int&)"
57 57 #define G_PSF "GLATResponse::psf(int&)"
58 58 #define G_EDISP "GLATResponse::edisp(int&)"
... ... @@ -200,7 +200,7 @@ GLATResponse* GLATResponse::clone(void) const
200 200 * @param[in] photon Incident photon.
201 201 * @param[in] obs Observation.
202 202 *
203   - * @exception GLATException::bad_instdir_type
  203 + * @exception GException::invalid_argument
204 204 * Instrument direction is not a valid LAT instrument direction.
205 205 *
206 206 * @todo The IRF value is not divided by ontime of the event, but it is
... ... @@ -212,8 +212,14 @@ double GLATResponse::irf(const GEvent&amp; event,
212 212 {
213 213 // Get pointer to LAT instrument direction
214 214 const GLATInstDir* dir = dynamic_cast<const GLATInstDir*>(&(event.dir()));
  215 +
  216 + // If pointer is not valid then throw an exception
215 217 if (dir == NULL) {
216   - throw GLATException::bad_instdir_type(G_IRF);
  218 + std::string cls = std::string(typeid(&(event.dir())).name());
  219 + std::string msg = "Invalid instrument direction type \""+cls+
  220 + "\" specified. Please specify a \"GLATInstDir\" "
  221 + "instance as argument.";
  222 + throw GException::invalid_argument(G_IRF, msg);
217 223 }
218 224  
219 225 // Get photon attributes
... ... @@ -326,15 +332,14 @@ double GLATResponse::irf_spatial_atom(const GLATEventAtom&amp; event,
326 332 * @param[in] source Source.
327 333 * @param[in] obs Observation.
328 334 *
329   - * @exception GLATException::diffuse_not_found
  335 + * @exception GException::invalid_value
330 336 * Diffuse model not found.
331 337 *
332 338 * This method first searches for a corresponding source map, and if found,
333 339 * computes the response from the source map. If no source map is present
334 340 * it checks if the source is a point source. If this is the case a mean
335 341 * PSF is allocated for the source and the response is computed from the
336   - * mean PSF. Otherwise an GLATException::diffuse_not_found exception is
337   - * thrown.
  342 + * mean PSF. Otherwise an GException::invalid_value exception is thrown.
338 343 *
339 344 * @todo Extract event cube from observation. We do not need the cube
340 345 * pointer in the event anymore.
... ... @@ -484,7 +489,11 @@ double GLATResponse::irf_spatial_bin(const GLATEventBin&amp; event,
484 489  
485 490 // ... otherwise throw an exception
486 491 if ((idiff == -1) && ptsrc == NULL) {
487   - throw GLATException::diffuse_not_found(G_IRF_BIN, source.name());
  492 + std::string msg = "No diffuse source with name \""+source.name()+
  493 + "\" found and source is not a point source. So far "
  494 + "the LAT module can only handle diffuse sources and "
  495 + "point sources. Please adapt your model accordingly.";
  496 + throw GException::invalid_value(G_IRF_BIN, msg);
488 497 }
489 498  
490 499 // Return IRF value
... ... @@ -686,6 +695,10 @@ void GLATResponse::load(const std::string&amp; rspname)
686 695 ***************************************************************************/
687 696 void GLATResponse::save(const std::string& rspname) const
688 697 {
  698 + // Throw an exception
  699 + std::string msg = "Saving of LAT response not implemented.";
  700 + throw GException::feature_not_implemented(G_SAVE, msg);
  701 +
689 702 // Return
690 703 return;
691 704 }
... ... @@ -713,14 +726,15 @@ GLATAeff* GLATResponse::aeff(const int&amp; index) const
713 726 /***********************************************************************//**
714 727 * @brief Return pointer on point spread function
715 728 *
716   - * @param[in] index Response index (starting from 0).
  729 + * @param[in] index Response index [0,...,m_psf.size()-1].
717 730 ***************************************************************************/
718 731 GLATPsf* GLATResponse::psf(const int& index) const
719 732 {
720 733 // Optionally check if the index is valid
721 734 #if defined(G_RANGE_CHECK)
722 735 if (index < 0 || index >= m_psf.size()) {
723   - throw GException::out_of_range(G_PSF, index, 0, m_psf.size()-1);
  736 + throw GException::out_of_range(G_PSF, "Response index", index,
  737 + m_psf.size());
724 738 }
725 739 #endif
726 740  
... ... @@ -732,14 +746,15 @@ GLATPsf* GLATResponse::psf(const int&amp; index) const
732 746 /***********************************************************************//**
733 747 * @brief Return pointer on energy dispersion
734 748 *
735   - * @param[in] index Response index (starting from 0).
  749 + * @param[in] index Response index [0,...,m_edisp.size()-1].
736 750 ***************************************************************************/
737 751 GLATEdisp* GLATResponse::edisp(const int& index) const
738 752 {
739 753 // Optionally check if the index is valid
740 754 #if defined(G_RANGE_CHECK)
741 755 if (index < 0 || index >= m_edisp.size()) {
742   - throw GException::out_of_range(G_EDISP, index, 0, m_edisp.size()-1);
  756 + throw GException::out_of_range(G_EDISP, "Response index", index,
  757 + m_edisp.size());
743 758 }
744 759 #endif
745 760  
... ...
inst/lat/test/test_LAT.cpp
1 1 /***************************************************************************
2 2 * test_LAT.cpp - test Fermi/LAT classes *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2010-2018 by Juergen Knoedlseder *
  4 + * copyright (C) 2010-2021 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -359,12 +359,15 @@ void TestGLATResponse::test_one_response(const std::string&amp; irf)
359 359 test_try_failure(e);
360 360 }
361 361  
362   - // Try saving the response
  362 + // Try saving the response (not implemented)
363 363 test_try("Test saving the response");
364 364 try {
365 365 GLATResponse rsp;
366 366 rsp.load(irf);
367 367 rsp.save(fitsfile);
  368 + test_try_failure();
  369 + }
  370 + catch (GException::feature_not_implemented &e) {
368 371 test_try_success();
369 372 }
370 373 catch (std::exception &e) {
... ...