diff --git a/inst/lat/Makefile.am b/inst/lat/Makefile.am
index b077827..82d47b7 100644
--- a/inst/lat/Makefile.am
+++ b/inst/lat/Makefile.am
@@ -1,7 +1,7 @@
#############################################################################
# Makefile.am for lat module #
# ------------------------------------------------------------------------- #
-# Copyright (C) 2016-2018 Juergen Knoedlseder #
+# Copyright (C) 2016-2021 Juergen Knoedlseder #
# ------------------------------------------------------------------------- #
# #
# This program is free software: you can redistribute it and/or modify #
@@ -51,8 +51,7 @@ sources = src/GLATObservation.cpp \
src/GLATInstDir.cpp \
src/GLATRoi.cpp \
src/GLATLtCube.cpp \
- src/GLATLtCubeMap.cpp \
- src/GLATException.cpp
+ src/GLATLtCubeMap.cpp
# Define headers to be installed
pkginclude_HEADERS = include/GLATLib.hpp \
@@ -74,8 +73,7 @@ pkginclude_HEADERS = include/GLATLib.hpp \
include/GLATInstDir.hpp \
include/GLATRoi.hpp \
include/GLATLtCube.hpp \
- include/GLATLtCubeMap.hpp \
- include/GLATException.hpp
+ include/GLATLtCubeMap.hpp
# CALDB to distribute
caldb_indx = caldb/data/glast/lat/caldb.indx.gz
diff --git a/inst/lat/include/GLATEdisp.hpp b/inst/lat/include/GLATEdisp.hpp
index 249030f..ad313b7 100644
--- a/inst/lat/include/GLATEdisp.hpp
+++ b/inst/lat/include/GLATEdisp.hpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATEdisp.hpp - Fermi LAT energy dispersion *
* ----------------------------------------------------------------------- *
- * copyright (C) 2010-2018 by Juergen Knoedlseder *
+ * copyright (C) 2010-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -91,7 +91,7 @@ private:
void init_members(void);
void copy_members(const GLATEdisp& edisp);
void free_members(void);
- void read_edisp(const GFitsTable& hdu);
+ void read_edisp(const GFitsTable& table);
void write_edisp(GFits& file) const;
// Protected members
diff --git a/inst/lat/include/GLATException.hpp b/inst/lat/include/GLATException.hpp
deleted file mode 100644
index 87141af..0000000
--- a/inst/lat/include/GLATException.hpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/***************************************************************************
- * GLATException.hpp - LAT exception handler *
- * ----------------------------------------------------------------------- *
- * copyright (C) 2010-2012 by Juergen Knoedlseder *
- * ----------------------------------------------------------------------- *
- * *
- * This program is free software: you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see . *
- * *
- ***************************************************************************/
-/**
- * @file GLATException.hpp
- * @brief LAT exception handler interface definition.
- * @author Juergen Knoedlseder
- */
-
-#ifndef GLATEXCEPTION_HPP
-#define GLATEXCEPTION_HPP
-
-/* __ Includes ___________________________________________________________ */
-#include // string
-#include // ostringstream
-#include // exception
-
-
-/***********************************************************************//**
- * @class GLATExceptionHandler
- *
- * @brief Interface for LAT exception handler.
- ***************************************************************************/
-class GLATExceptionHandler : public std::exception {
-public:
- GLATExceptionHandler(void) { }
- virtual ~GLATExceptionHandler(void) throw() { }
- virtual const char* what() const throw();
-protected:
- std::string m_origin;
- std::string m_message;
-};
-
-
-/***********************************************************************//**
- * @class GLATException
- *
- * @brief Interface for LAT exceptions.
- *
- * This is the object that is thrown in case of a LAT exception.
- ***************************************************************************/
-class GLATException : public GLATExceptionHandler {
-public:
- // Exceptions
- class file_open_error : public GLATExceptionHandler {
- public:
- file_open_error(std::string origin, std::string filename,
- std::string message = "");
- };
- class no_member : public GLATExceptionHandler {
- public:
- no_member(const std::string& origin, const std::string& message);
- };
- class no_sky : public GLATExceptionHandler {
- public:
- no_sky(std::string origin, std::string message = "");
- };
- class no_ebds : public GLATExceptionHandler {
- public:
- no_ebds(std::string origin, std::string message = "");
- };
- class no_gti : public GLATExceptionHandler {
- public:
- no_gti(std::string origin, std::string message = "");
- };
- class no_ltcube : public GLATExceptionHandler {
- public:
- no_ltcube(std::string origin, std::string message = "");
- };
- class no_energies : public GLATExceptionHandler {
- public:
- no_energies(std::string origin, std::string message = "");
- };
- class no_dirs : public GLATExceptionHandler {
- public:
- no_dirs(std::string origin, std::string message = "");
- };
- class bad_roi_type : public GLATExceptionHandler {
- public:
- bad_roi_type(std::string origin, std::string message = "");
- };
- class bad_instdir_type : public GLATExceptionHandler {
- public:
- bad_instdir_type(std::string origin, std::string message = "");
- };
- class invalid_response : public GLATExceptionHandler {
- public:
- invalid_response(std::string origin, std::string message = "");
- };
- class wcs_incompatible : public GLATExceptionHandler {
- public:
- wcs_incompatible(std::string origin, std::string name,
- std::string message = "");
- };
- class diffuse_not_found : public GLATExceptionHandler {
- public:
- diffuse_not_found(std::string origin, std::string name,
- std::string message = "");
- };
- class inconsistent_response : public GLATExceptionHandler {
- public:
- inconsistent_response(std::string origin, int size, int expect,
- std::string message = "");
- };
- class bad_response_type : public GLATExceptionHandler {
- public:
- bad_response_type(std::string origin, std::string message = "");
- };
-};
-
-#endif /* GLATEXCEPTION_HPP */
diff --git a/inst/lat/include/GLATLib.hpp b/inst/lat/include/GLATLib.hpp
index f12727a..a901729 100644
--- a/inst/lat/include/GLATLib.hpp
+++ b/inst/lat/include/GLATLib.hpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATLib.hpp - Fermi/LAT Support Header files *
* ----------------------------------------------------------------------- *
- * copyright (C) 2010-2013 by Juergen Knoedlseder *
+ * copyright (C) 2010-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -33,11 +33,11 @@
/* __ Fermi/LAT specific headers _________________________________________ */
#include "GLATAeff.hpp"
#include "GLATEdisp.hpp"
+#include "GLATEfficiency.hpp"
#include "GLATEventAtom.hpp"
#include "GLATEventBin.hpp"
#include "GLATEventCube.hpp"
#include "GLATEventList.hpp"
-#include "GLATException.hpp"
#include "GLATInstDir.hpp"
#include "GLATLtCube.hpp"
#include "GLATLtCubeMap.hpp"
diff --git a/inst/lat/src/GLATAeff.cpp b/inst/lat/src/GLATAeff.cpp
index 8c080d8..a96c5ab 100644
--- a/inst/lat/src/GLATAeff.cpp
+++ b/inst/lat/src/GLATAeff.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATAeff.cpp - Fermi LAT effective area *
* ----------------------------------------------------------------------- *
- * copyright (C) 2008-2018 by Juergen Knoedlseder *
+ * copyright (C) 2008-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -38,7 +38,6 @@
#include "GFitsTableCol.hpp"
#include "GFitsTableFloatCol.hpp"
#include "GLATAeff.hpp"
-#include "GLATException.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_READ_AEFF "GLATAeff::read_aeff(GFitsTable&)"
@@ -554,7 +553,7 @@ void GLATAeff::free_members(void)
*
* @param[in] hdu FITS table.
*
- * @exception GLATException::inconsistent_response
+ * @exception GException::invalid_argument
* Inconsistent response table encountered
*
* The effective area is converted into units of cm2.
@@ -583,7 +582,13 @@ void GLATAeff::read_aeff(const GFitsTable& hdu)
// Check consistency of effective area table
int num = ptr->number();
if (num != size) {
- throw GLATException::inconsistent_response(G_READ_AEFF, num, size);
+ std::string msg = "Number of elements in response table ("+
+ gammalib::str(num)+") does not correspond to "
+ "the expectation according to the number of "
+ "energy and cos theta bins ("+gammalib::str(size)+
+ "). Please specify a consistent effective area "
+ "response.";
+ throw GException::invalid_argument(G_READ_AEFF, msg);
}
// Copy data and convert from m2 into cm2
diff --git a/inst/lat/src/GLATEdisp.cpp b/inst/lat/src/GLATEdisp.cpp
index c6ea42d..de08896 100644
--- a/inst/lat/src/GLATEdisp.cpp
+++ b/inst/lat/src/GLATEdisp.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATEdisp.cpp - Fermi LAT energy dispersion *
* ----------------------------------------------------------------------- *
- * copyright (C) 2008-2020 by Juergen Knoedlseder *
+ * copyright (C) 2008-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -28,6 +28,7 @@
#ifdef HAVE_CONFIG_H
#include
#endif
+#include "GException.hpp"
#include "GTools.hpp"
#include "GFilename.hpp"
#include "GFits.hpp"
@@ -35,7 +36,6 @@
#include "GFitsBinTable.hpp"
#include "GFitsTableFloatCol.hpp"
#include "GLATEdisp.hpp"
-#include "GLATException.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_READ "GLATEdisp::read(GFits&)"
@@ -371,19 +371,21 @@ void GLATEdisp::free_members(void)
/***********************************************************************//**
* @brief Read energy dispersion from FITS table
*
- * @param[in] hdu FITS table pointer.
+ * @param[in] table FITS table.
*
- * @exception GLATException::inconsistent_response
+ * @exception GException::invalid_argument
* Inconsistent response table encountered
+ *
+ * @todo Implement reading of energy dispersion table
***************************************************************************/
-void GLATEdisp::read_edisp(const GFitsTable& hdu)
+void GLATEdisp::read_edisp(const GFitsTable& table)
{
// Clear arrays
m_norm.clear();
m_ls1.clear();
// Get energy and cos theta binning
- m_edisp_bins.read(hdu);
+ m_edisp_bins.read(table);
// Continue only if there are bins
int size = m_edisp_bins.size();
@@ -394,17 +396,25 @@ void GLATEdisp::read_edisp(const GFitsTable& hdu)
m_ls1.reserve(size);
// Get pointer to columns
- const GFitsTableCol* norm = hdu["NORM"];
- const GFitsTableCol* ls1 = hdu["LS1"];
+ const GFitsTableCol* norm = table["NORM"];
+ const GFitsTableCol* ls1 = table["LS1"];
// Check consistency of columns
if (norm->number() != size) {
- throw GLATException::inconsistent_response(G_READ_EDISP,
- norm->number(), size);
+ std::string msg = "Number of elements in \"NORM\" column ("+
+ gammalib::str(norm->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (ls1->number() != size) {
- throw GLATException::inconsistent_response(G_READ_EDISP,
- ls1->number(), size);
+ std::string msg = "Number of elements in \"LS1\" column ("+
+ gammalib::str(ls1->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
// Copy data
diff --git a/inst/lat/src/GLATEventAtom.cpp b/inst/lat/src/GLATEventAtom.cpp
index 378d8dd..5bd8538 100644
--- a/inst/lat/src/GLATEventAtom.cpp
+++ b/inst/lat/src/GLATEventAtom.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATEventAtom.cpp - LAT event atom class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2009-2013 by Juergen Knoedlseder *
+ * copyright (C) 2009-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -29,9 +29,8 @@
#include
#endif
#include
-#include "GLATEventAtom.hpp"
-#include "GLATException.hpp"
#include "GTools.hpp"
+#include "GLATEventAtom.hpp"
/* __ Method name definitions ____________________________________________ */
diff --git a/inst/lat/src/GLATEventBin.cpp b/inst/lat/src/GLATEventBin.cpp
index edfd71a..e3b41b2 100644
--- a/inst/lat/src/GLATEventBin.cpp
+++ b/inst/lat/src/GLATEventBin.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATEventBin.cpp - Fermi/LAT event bin class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2009-2013 by Juergen Knoedlseder *
+ * copyright (C) 2009-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -30,9 +30,9 @@
#endif
#include
#include
-#include "GLATEventBin.hpp"
-#include "GLATException.hpp"
+#include "GException.hpp"
#include "GTools.hpp"
+#include "GLATEventBin.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_DIR "GLATEventBin::dir()"
@@ -201,8 +201,8 @@ double GLATEventBin::size(void) const
*
* @return Instrument direction of event bin.
*
- * @exception GLATException::no_member
- * Invalid instrument direction pointer.
+ * @exception GException::invalid_value
+ * Invalid instrument direction pointer encountered.
*
* Returns reference to the instrument direction of the event bin.
***************************************************************************/
@@ -210,8 +210,9 @@ const GLATInstDir& GLATEventBin::dir(void) const
{
// Throw an exception if instrument direction pointer is not valid
if (m_dir == NULL) {
- throw GLATException::no_member(G_DIR,
- "Invalid instrument direction pointer.");
+ std::string msg = "Invalid instrument direction pointer encountered. "
+ "Please set up the event bin correctly.";
+ throw GException::invalid_value(G_DIR, msg);
}
// Return instrument direction
@@ -224,8 +225,8 @@ const GLATInstDir& GLATEventBin::dir(void) const
*
* @return Energy of event bin.
*
- * @exception GLATException::no_member
- * Invalid energy pointer.
+ * @exception GException::invalid_value
+ * Invalid energy pointer encountered.
*
* Returns reference to the energy of the event bin.
***************************************************************************/
@@ -233,8 +234,9 @@ const GEnergy& GLATEventBin::energy(void) const
{
// Throw an exception if energy pointer is not valid
if (m_energy == NULL) {
- throw GLATException::no_member(G_ENERGY,
- "Invalid energy pointer.");
+ std::string msg = "Invalid energy pointer encountered. Please set up "
+ "the event bin correctly.";
+ throw GException::invalid_value(G_ENERGY, msg);
}
// Return energy
@@ -247,8 +249,8 @@ const GEnergy& GLATEventBin::energy(void) const
*
* @return Time of event bin.
*
- * @exception GLATException::no_member
- * Invalid time pointer.
+ * @exception GException::invalid_value
+ * Invalid time pointer encountered.
*
* Returns reference to the time of the event bin.
***************************************************************************/
@@ -256,8 +258,9 @@ const GTime& GLATEventBin::time(void) const
{
// Throw an exception if time pointer is not valid
if (m_time == NULL) {
- throw GLATException::no_member(G_TIME,
- "Invalid time pointer.");
+ std::string msg = "Invalid time pointer encountered. Please set up "
+ "the event bin correctly.";
+ throw GException::invalid_value(G_TIME, msg);
}
// Return time
@@ -279,8 +282,9 @@ double GLATEventBin::counts(void) const
{
// Throw an exception if counts pointer is not valid
if (m_counts == NULL) {
- throw GLATException::no_member(G_COUNTS_GET,
- "Invalid counts pointer.");
+ std::string msg = "Invalid counts pointer encountered. Please set up "
+ "the event bin correctly.";
+ throw GException::invalid_value(G_COUNTS_GET, msg);
}
// Return counts
@@ -293,8 +297,8 @@ double GLATEventBin::counts(void) const
*
* @param[in] counts Number of counts.
*
- * @exception GLATException::no_member
- * Invalid counts pointer.
+ * @exception GException::invalid_value
+ * Invalid counts pointer encountered.
*
* Set the number of counts in the event bin.
***************************************************************************/
@@ -302,8 +306,9 @@ void GLATEventBin::counts(const double& counts)
{
// Throw an exception if counts pointer is not valid
if (m_counts == NULL) {
- throw GLATException::no_member(G_COUNTS_SET,
- "Invalid counts pointer.");
+ std::string msg = "Invalid counts pointer encountered. Please set up "
+ "the event bin correctly.";
+ throw GException::invalid_value(G_COUNTS_SET, msg);
}
// Set number of counts in event bin
@@ -342,8 +347,8 @@ double GLATEventBin::error(void) const
*
* @return Solid angle of event bin.
*
- * @exception GLATException::no_member
- * Invalid solid angle pointer.
+ * @exception GException::invalid_value
+ * Invalid solid angle pointer encountered.
*
* Returns reference to the solid angle of the event bin.
***************************************************************************/
@@ -351,8 +356,9 @@ const double& GLATEventBin::solidangle(void) const
{
// Throw an exception if solid angle pointer is not valid
if (m_solidangle == NULL) {
- throw GLATException::no_member(G_SOLIDANGLE,
- "Invalid solid angle pointer.");
+ std::string msg = "Invalid solid angle pointer encountered. Please "
+ "set up the event bin correctly.";
+ throw GException::invalid_value(G_SOLIDANGLE, msg);
}
// Return solid angle
@@ -365,8 +371,8 @@ const double& GLATEventBin::solidangle(void) const
*
* @return Energy width of event bin.
*
- * @exception GLATException::no_member
- * Invalid energy width pointer.
+ * @exception GException::invalid_value
+ * Invalid energy width pointer encountered.
*
* Returns reference to the energy width of the event bin.
***************************************************************************/
@@ -374,8 +380,9 @@ const GEnergy& GLATEventBin::ewidth(void) const
{
// Throw an exception if energy width pointer is not valid
if (m_ewidth == NULL) {
- throw GLATException::no_member(G_EWIDTH,
- "Invalid energy width pointer.");
+ std::string msg = "Invalid energy width pointer encountered. Please "
+ "set up the event bin correctly.";
+ throw GException::invalid_value(G_EWIDTH, msg);
}
// Return energy width
@@ -388,8 +395,8 @@ const GEnergy& GLATEventBin::ewidth(void) const
*
* @return Ontime of event bin.
*
- * @exception GLATException::no_member
- * Invalid ontime pointer.
+ * @exception GException::invalid_value
+ * Invalid ontime pointer encountered.
*
* Returns reference to the ontime of the event bin.
***************************************************************************/
@@ -397,8 +404,9 @@ const double& GLATEventBin::ontime(void) const
{
// Throw an exception if ontime pointer is not valid
if (m_ontime == NULL) {
- throw GLATException::no_member(G_ONTIME,
- "Invalid ontime pointer.");
+ std::string msg = "Invalid ontime pointer encountered. Please set up "
+ "the event bin correctly.";
+ throw GException::invalid_value(G_ONTIME, msg);
}
// Return ontime
@@ -409,7 +417,7 @@ const double& GLATEventBin::ontime(void) const
/***********************************************************************//**
* @brief Print event information
*
- * @param[in] chatter Chattiness (defaults to NORMAL).
+ * @param[in] chatter Chattiness.
* @return String containing number of counts in event bin.
***************************************************************************/
std::string GLATEventBin::print(const GChatter& chatter) const
diff --git a/inst/lat/src/GLATEventCube.cpp b/inst/lat/src/GLATEventCube.cpp
index cafcfa6..fdadbdd 100644
--- a/inst/lat/src/GLATEventCube.cpp
+++ b/inst/lat/src/GLATEventCube.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATEventCube.cpp - Fermi/LAT event cube class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2009-2019 by Juergen Knoedlseder *
+ * copyright (C) 2009-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -28,12 +28,12 @@
#ifdef HAVE_CONFIG_H
#include
#endif
+#include "GException.hpp"
#include "GTools.hpp"
#include "GFilename.hpp"
#include "GFitsImage.hpp"
#include "GFitsTable.hpp"
#include "GLATEventCube.hpp"
-#include "GLATException.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_NAXIS "GLATEventCube::naxis(int)"
@@ -280,7 +280,8 @@ int GLATEventCube::naxis(const int& axis) const
// Optionally check if the axis is valid
#if defined(G_RANGE_CHECK)
if (axis < 0 || axis >= dim()) {
- throw GException::out_of_range(G_NAXIS, "LAT event cube axis", axis, dim());
+ throw GException::out_of_range(G_NAXIS, "LAT event cube axis",
+ axis, dim());
}
#endif
@@ -486,7 +487,7 @@ void GLATEventCube::map(const GSkyMap& map)
/***********************************************************************//**
* @brief Print event cube information
*
- * @param[in] chatter Chattiness (defaults to NORMAL).
+ * @param[in] chatter Chattiness.
* @return String containing event cube information.
***************************************************************************/
std::string GLATEventCube::print(const GChatter& chatter) const
@@ -578,7 +579,8 @@ std::string GLATEventCube::diffname(const int& index) const
// Optionally check if the index is valid
#if defined(G_RANGE_CHECK)
if (index < 0 || index >= ndiffrsp()) {
- throw GException::out_of_range(G_DIFFNAME, index, 0, ndiffrsp()-1);
+ throw GException::out_of_range(G_DIFFNAME, "Diffuse model index",
+ index, ndiffrsp());
}
#endif
@@ -603,7 +605,8 @@ GSkyMap* GLATEventCube::diffrsp(const int& index) const
// Optionally check if the index is valid
#if defined(G_RANGE_CHECK)
if (index < 0 || index >= ndiffrsp()) {
- throw GException::out_of_range(G_DIFFRSP, index, 0, ndiffrsp()-1);
+ throw GException::out_of_range(G_DIFFRSP, "Diffuse model index",
+ index, ndiffrsp());
}
#endif
@@ -786,8 +789,8 @@ void GLATEventCube::read_cntmap(const GFitsImage& hdu)
*
* @param[in] hdu Image HDU.
*
- * @exception GLATException::wcs_incompatible
- * Source map not compatible with sky map
+ * @exception GException::invalid_argument
+ * Source map in @p hdu is not compatible with event cube.
*
* This method reads a LAT source map from a FITS image. The source map is
* stored in a GSkyMap object and is given in units of counts/pixel/MeV.
@@ -803,19 +806,34 @@ void GLATEventCube::read_srcmap(const GFitsImage& hdu)
// Check that source map sky projection is consistent with counts
// map sky projection
if (*(m_map.projection()) != *(map->projection())) {
- throw GLATException::wcs_incompatible(G_READ_SRCMAP, hdu.extname());
+ std::string msg = "Specified source map projection in HDU \""+
+ hdu.extname()+"\" is incompatible with map projection "
+ "of the event cube. Please specify a compatible "
+ "map projection.";
+ throw GException::invalid_argument(G_READ_SRCMAP, msg);
}
// Check that source map dimension is consistent with counts map
// dimension
if (m_map.nx() != map->nx() ||
m_map.ny() != map->ny()) {
- throw GLATException::wcs_incompatible(G_READ_SRCMAP, hdu.extname());
+ std::string msg = "Number of pixels ("+gammalib::str(map->nx())+","+
+ gammalib::str(map->ny())+") in source map in HDU \""+
+ hdu.extname()+"\" is not compatible with number of "
+ "pixels ("+gammalib::str(m_map.nx())+","+
+ gammalib::str(m_map.ny())+") in the event cube. "
+ "Please specify a source map of compatible size.";
+ throw GException::invalid_argument(G_READ_SRCMAP, msg);
}
// Check that source map has required number of energy bins
if (m_map.nmaps()+1 != map->nmaps()) {
- throw GLATException::wcs_incompatible(G_READ_SRCMAP, hdu.extname());
+ std::string msg = "Number of maps ("+gammalib::str(map->nmaps())+")"+
+ " in source map in HDU \""+hdu.extname()+"\" is not "
+ "compatible with number of energy bin boundaries ("+
+ gammalib::str(m_map.nmaps()+1)+") of the event cube. "
+ "Please specify a source map of compatible size.";
+ throw GException::invalid_argument(G_READ_SRCMAP, msg);
}
// Append source map to list of maps
@@ -897,7 +915,7 @@ void GLATEventCube::read_gti(const GFitsTable& hdu)
/***********************************************************************//**
* @brief Set sky directions and solid angles of events cube.
*
- * @exception GLATException::no_sky
+ * @exception GException::invalid_value
* No sky pixels found in event cube.
*
* This method computes the sky directions and solid angles for all event
@@ -906,10 +924,11 @@ void GLATEventCube::read_gti(const GFitsTable& hdu)
***************************************************************************/
void GLATEventCube::set_directions(void)
{
- // Throw an error if we have no sky pixels
+ // Throw an exception if we have no sky pixels
if (npix() < 1) {
- throw GLATException::no_sky(G_SET_DIRECTIONS, "Every LAT event cube"
- " needs a definition of the sky pixels.");
+ std::string msg = "LAT event cube contains no sky pixels. Please "
+ "provide a valid LAT event cube.";
+ throw GException::invalid_value(G_SET_DIRECTIONS, msg);
}
// Clear old pixel directions and solid angle
@@ -937,7 +956,7 @@ void GLATEventCube::set_directions(void)
/***********************************************************************//**
* @brief Set log mean energies and energy widths of event cube.
*
- * @exception GLATException::no_ebds
+ * @exception GException::invalid_value
* No energy boundaries found in event cube.
*
* This method computes the log mean energies and the energy widths of the
@@ -948,8 +967,9 @@ void GLATEventCube::set_energies(void)
{
// Throw an error if we have no energy bins
if (ebins() < 1) {
- throw GLATException::no_ebds(G_SET_ENERGIES, "Every LAT event cube"
- " needs a definition of the energy boundaries.");
+ std::string msg = "LAT event cube contains no energy bins. Please "
+ "provide a valid LAT event cube.";
+ throw GException::invalid_value(G_SET_ENERGIES, msg);
}
// Clear old bin energies and energy widths
@@ -1016,9 +1036,8 @@ void GLATEventCube::set_times(void)
*
* @exception GException::out_of_range
* Event index is outside valid range.
- * @exception GLATException::no_energies
+ * @exception GException::invalid_value
* Energy vectors have not been set up.
- * @exception GLATException::no_dirs
* Sky directions and solid angles vectors have not been set up.
*
* This method provides the event attributes to the event bin. The event bin
@@ -1038,12 +1057,24 @@ void GLATEventCube::set_bin(const int& index)
// Check for the existence of energies and energy widths
if (m_energies.size() != ebins() || m_ewidth.size() != ebins()) {
- throw GLATException::no_energies(G_SET_BIN);
+ std::string msg = "Number of energy bins ("+gammalib::str(ebins())+
+ ") is incompatible with size of energies ("+
+ gammalib::str(m_energies.size())+") an/or size of "
+ "energy widths ("+gammalib::str(m_ewidth.size())+
+ "). Please provide an correctly initialised event "
+ "cube.";
+ throw GException::invalid_value(G_SET_BIN, msg);
}
// Check for the existence of sky directions and solid angles
if (m_dirs.size() != npix() || m_solidangle.size() != npix()) {
- throw GLATException::no_dirs(G_SET_BIN);
+ std::string msg = "Number of sky pixels ("+gammalib::str(npix())+
+ ") is incompatible with size of sky directions ("+
+ gammalib::str(m_dirs.size())+") and/or size of "
+ "solid angles ("+gammalib::str(m_solidangle.size())+
+ "). Please provide an correctly initialised event "
+ "cube.";
+ throw GException::invalid_value(G_SET_BIN, msg);
}
// Get pixel and energy bin indices.
diff --git a/inst/lat/src/GLATEventList.cpp b/inst/lat/src/GLATEventList.cpp
index a2e136f..791d38f 100644
--- a/inst/lat/src/GLATEventList.cpp
+++ b/inst/lat/src/GLATEventList.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATEventList.cpp - Fermi/LAT event list class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2009-2020 by Juergen Knoedlseder *
+ * copyright (C) 2009-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -38,7 +38,6 @@
#include "GFitsTableLongCol.hpp"
#include "GFitsTableShortCol.hpp"
#include "GLATEventList.hpp"
-#include "GLATException.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_OPERATOR "GLATEventList::operator[](int&)"
@@ -358,25 +357,28 @@ void GLATEventList::write(GFits& file) const
/***********************************************************************//**
- * @brief Set region of interest
+ * @brief Set Region of Interest
*
- * @param[in] roi Region of interest.
+ * @param[in] roi Region of Interest.
*
- * @exception GLATException::bad_roi_type
- * ROI is not of type GLATRoi.
+ * @exception GException::invalid_argument
+ * Region of Interest @p roi in not a LAT Region of Interest.
***************************************************************************/
void GLATEventList::roi(const GRoi& roi)
{
- // Cast ROI dynamically
- const GLATRoi* ptr = dynamic_cast(&roi);
-
- // Throw exception if ROI is not of correct type
- if (ptr == NULL) {
- throw GLATException::bad_roi_type(G_ROI);
+ // Cast RoI dynamically
+ const GLATRoi* latroi = dynamic_cast(&roi);
+
+ // Throw exception if RoI is not of correct type
+ if (latroi == NULL) {
+ std::string cls = std::string(typeid(&roi).name());
+ std::string msg = "Invalid RoI type \""+cls+"\" specified. Please "
+ "specify a \"GLATRoi\" instance as argument.";
+ throw GException::invalid_argument(G_ROI, msg);
}
- // Set ROI
- m_roi = *ptr;
+ // Copy RoI
+ m_roi = *latroi;
// Return
return;
diff --git a/inst/lat/src/GLATException.cpp b/inst/lat/src/GLATException.cpp
deleted file mode 100644
index 162c315..0000000
--- a/inst/lat/src/GLATException.cpp
+++ /dev/null
@@ -1,312 +0,0 @@
-/***************************************************************************
- * GLATException.cpp - LAT exception handler *
- * ----------------------------------------------------------------------- *
- * copyright (C) 2010-2011 by Jurgen Knodlseder *
- * ----------------------------------------------------------------------- *
- * This program is free software: you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation, either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with this program. If not, see . *
- * *
- ***************************************************************************/
-/**
- * @file GLATException.cpp
- * @brief LAT exception handler interface implementation.
- * @author J. Knodlseder
- */
-
-/* __ Includes ___________________________________________________________ */
-#include "GLATException.hpp"
-#include "GTools.hpp"
-
-
-/***********************************************************************//**
- * @brief Exception message.
- ***************************************************************************/
-const char* GLATExceptionHandler::what() const throw()
-{
- // Set error message
- std::string message = "*** ERROR in " + m_origin + ": " + m_message;
-
- // Return message as C character array
- return gammalib::tochar(message);
-}
-
-
-/***********************************************************************//**
- * @brief Error while opening file.
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] filename Name of file that could not be opened.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::file_open_error::file_open_error(std::string origin,
- std::string filename,
- std::string message)
-{
- m_origin = origin;
- m_message = "Unable to open file '"+filename+"'. "+message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief Member not set.
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Error message.
- ***************************************************************************/
-GLATException::no_member::no_member(const std::string& origin,
- const std::string& message)
-{
- // Set origin and message
- m_origin = origin;
- m_message = message;
-
- // Return
- return;
-}
-
-
-/***********************************************************************//**
- * @brief No sky pixels found.
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::no_sky::no_sky(std::string origin, std::string message)
-{
- m_origin = origin;
- m_message = "No sky pixels have been found. "+message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief No energy boundary information found.
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::no_ebds::no_ebds(std::string origin, std::string message)
-{
- m_origin = origin;
- m_message = "No energy boundaries have been found. "+message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief No Good Time Intervals found.
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::no_gti::no_gti(std::string origin, std::string message)
-{
- m_origin = origin;
- m_message = "No Good Time Intervals (GTIs) have been found. "+message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief No Livetime Cube found.
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::no_ltcube::no_ltcube(std::string origin, std::string message)
-{
- m_origin = origin;
- m_message = "No Livetime Cube have been found. "+message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief No energies set
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::no_energies::no_energies(std::string origin, std::string message)
-{
- // Set origin
- m_origin = origin;
-
- // Set message
- m_message = "Energy vector has not been setup."
- " Cannot access event information.";
- if (message.length() > 0)
- m_message += " "+message;
-
- // Return
- return;
-}
-
-
-/***********************************************************************//**
- * @brief No sky directions set
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::no_dirs::no_dirs(std::string origin, std::string message)
-{
- // Set origin
- m_origin = origin;
-
- // Set message
- m_message = "Sky direction vector has not been setup."
- " Cannot access event information.";
- if (message.length() > 0)
- m_message += " "+message;
-
- // Return
- return;
-}
-
-
-/***********************************************************************//**
- * @brief ROI is not a LAT ROI
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::bad_roi_type::bad_roi_type(std::string origin, std::string message)
-{
- // Set origin
- m_origin = origin;
-
- // Set message
- m_message = "Specified ROI is not of type GLATRoi.";
- if (message.length() > 0)
- m_message += " "+message;
-
- // Return
- return;
-}
-
-
-/***********************************************************************//**
- * @brief Instrument direction is not a CTA instrument direction
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::bad_instdir_type::bad_instdir_type(std::string origin,
- std::string message)
-{
- // Set origin
- m_origin = origin;
-
- // Set message
- m_message = "Instrument direction is not of type GLATInstDir.";
- if (message.length() > 0)
- m_message += " "+message;
-
- // Return
- return;
-}
-
-
-/***********************************************************************//**
- * @brief Invalid response found
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::invalid_response::invalid_response(std::string origin,
- std::string message)
-{
- m_origin = origin;
- m_message = "Invalid response encountered. " + message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief Incompatible source map
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] name Map name.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::wcs_incompatible::wcs_incompatible(std::string origin,
- std::string name,
- std::string message)
-{
- m_origin = origin;
- m_message = "Source map \""+name+"\" incompatible with counts map. " +
- message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief Diffuse model not found
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] name Diffuse model.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::diffuse_not_found::diffuse_not_found(std::string origin,
- std::string name,
- std::string message)
-{
- m_origin = origin;
- m_message = "Diffuse model \""+name+"\" not found. " +
- message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief Inconsistent response table
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] size Size.
- * @param[in] expect Expected size.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::inconsistent_response::inconsistent_response(std::string origin,
- int size,
- int expect,
- std::string message)
-{
- m_origin = origin;
- m_message = "Inconsistent response table found. Expected "+gammalib::str(expect)+
- " elements, found "+gammalib::str(size)+". " + message;
- return;
-}
-
-
-/***********************************************************************//**
- * @brief Response is not a LAT response
- *
- * @param[in] origin Name of method that has thrown the exception.
- * @param[in] message Optional error message.
- ***************************************************************************/
-GLATException::bad_response_type::bad_response_type(std::string origin,
- std::string message)
-{
- // Set origin
- m_origin = origin;
-
- // Set message
- m_message = "Response is not of type GLATResponse.";
- if (message.length() > 0)
- m_message += " "+message;
-
- // Return
- return;
-}
diff --git a/inst/lat/src/GLATMeanPsf.cpp b/inst/lat/src/GLATMeanPsf.cpp
index dc7e177..6f87ada 100644
--- a/inst/lat/src/GLATMeanPsf.cpp
+++ b/inst/lat/src/GLATMeanPsf.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATMeanPsf.cpp - Fermi/LAT mean PSF class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2010-2016 by Juergen Knoedlseder *
+ * copyright (C) 2010-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -29,14 +29,14 @@
#include
#endif
#include
-#include "GLATMeanPsf.hpp"
+#include "GException.hpp"
#include "GTools.hpp"
#include "GMath.hpp"
#include "GLATAeff.hpp"
#include "GLATPsf.hpp"
#include "GLATObservation.hpp"
#include "GLATEventCube.hpp"
-#include "GLATException.hpp"
+#include "GLATMeanPsf.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_SET "GLATMeanPsf::set(GSkyDir&, GLATObservation&)"
@@ -287,8 +287,8 @@ GLATMeanPsf* GLATMeanPsf::clone(void) const
* @param[in] dir Source location.
* @param[in] obs LAT observation.
*
- * @exception GLATException::no_ltcube
- * Livetime cube has not been defined.
+ * @exception GException::invalid_argument
+ * No livetime cube found in observation.
*
* Computes the mean PSF and the energy dependent exposure for a source at
* a given sky location. The PSF is computed for all bin boundaries of the
@@ -308,7 +308,10 @@ void GLATMeanPsf::set(const GSkyDir& dir, const GLATObservation& obs)
// Get pointer on livetime cube
const GLATLtCube* ltcube = obs.ltcube();
if (ltcube == NULL) {
- throw GLATException::no_ltcube(G_SET);
+ std::string msg = "Observation does not contain a livetime cube. "
+ "Please specify an observation containing a livetime "
+ "cube.";
+ throw GException::invalid_argument(G_SET, msg);
}
// Get energy boundaries
diff --git a/inst/lat/src/GLATObservation.cpp b/inst/lat/src/GLATObservation.cpp
index 259eef0..f0e5778 100644
--- a/inst/lat/src/GLATObservation.cpp
+++ b/inst/lat/src/GLATObservation.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATObservation.cpp - Fermi LAT observation class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2008-2020 by Juergen Knoedlseder *
+ * copyright (C) 2008-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -34,7 +34,6 @@
#include "GLATEventList.hpp"
#include "GLATEventCube.hpp"
#include "GLATRoi.hpp"
-#include "GLATException.hpp"
#include "GFits.hpp"
#include "GTools.hpp"
#include "GEnergy.hpp"
@@ -202,8 +201,8 @@ GLATObservation* GLATObservation::clone(void) const
*
* @param[in] rsp Response function.
*
- * @exception GLATException::bad_response_type
- * Specified response in not of type GLATResponse.
+ * @exception GException::invalid_argument
+ * Response @p rsp in not a LAT response.
*
* Sets the response function for the observation. The argument has to be of
* type GLATResponse, otherwise an exception is thrown.
@@ -212,8 +211,14 @@ void GLATObservation::response(const GResponse& rsp)
{
// Get pointer on LAT response
const GLATResponse* latrsp = dynamic_cast(&rsp);
+
+ // If pointer is not valid then throw an exception
if (latrsp == NULL) {
- throw GLATException::bad_response_type(G_RESPONSE);
+ std::string cls = std::string(typeid(&rsp).name());
+ std::string msg = "Invalid response type \""+cls+"\" specified. "
+ "Please specify a \"GLATResponse\" instance as "
+ "argument.";
+ throw GException::invalid_argument(G_RESPONSE, msg);
}
// Copy response function
diff --git a/inst/lat/src/GLATPsf.cpp b/inst/lat/src/GLATPsf.cpp
index c4f0dfe..79175c1 100644
--- a/inst/lat/src/GLATPsf.cpp
+++ b/inst/lat/src/GLATPsf.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATPsf.cpp - Fermi LAT point spread function *
* ----------------------------------------------------------------------- *
- * copyright (C) 2008-2018 by Juergen Knoedlseder *
+ * copyright (C) 2008-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -28,6 +28,7 @@
#ifdef HAVE_CONFIG_H
#include
#endif
+#include "GException.hpp"
#include "GTools.hpp"
#include "GFilename.hpp"
#include "GFits.hpp"
@@ -36,7 +37,6 @@
#include "GLATPsf.hpp"
#include "GLATPsfV1.hpp"
#include "GLATPsfV3.hpp"
-#include "GLATException.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_READ "GLATPsf::read(GFits&)"
@@ -271,8 +271,8 @@ void GLATPsf::save(const GFilename& filename, const bool& clobber)
* @param[in] fits FITS file.
* @param[in] evtype Event type.
*
- * @exception GException::invalid_response
- * Invalid response type or unsupported response version found.
+ * @exception GException::invalid_value
+ * Unsupported response version found.
*
* Reads the Fermi LAT point spread function from FITS file. The method
* determines the PSF version from the information found in the FITS file
@@ -332,8 +332,10 @@ void GLATPsf::read(const GFits& fits, const std::string& evtype)
m_psf = new GLATPsfV3;
break;
default:
- throw GLATException::invalid_response(G_READ,
- "Unsupported response function version "+gammalib::str(version)+".");
+ std::string msg = "Unsupported response function version "+
+ gammalib::str(version)+". Please specify either a "
+ "version 1 or 3 point spread function.";
+ throw GException::invalid_value(G_READ, msg);
break;
}
diff --git a/inst/lat/src/GLATPsfBase.cpp b/inst/lat/src/GLATPsfBase.cpp
index 98f77e6..57de0da 100644
--- a/inst/lat/src/GLATPsfBase.cpp
+++ b/inst/lat/src/GLATPsfBase.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATPsfBase.cpp - Abstract Fermi LAT point spread function base class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2012-2016 by Juergen Knoedlseder *
+ * copyright (C) 2012-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -28,11 +28,10 @@
#ifdef HAVE_CONFIG_H
#include
#endif
-#include "GLATPsfBase.hpp"
-#include "GLATException.hpp"
#include "GTools.hpp"
#include "GFitsBinTable.hpp"
#include "GFitsTableFloatCol.hpp"
+#include "GLATPsfBase.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_READ_SCALE "GLATPsfBase::read_scale(GFitsTable&)"
diff --git a/inst/lat/src/GLATPsfV1.cpp b/inst/lat/src/GLATPsfV1.cpp
index 5d643ab..b6174a7 100644
--- a/inst/lat/src/GLATPsfV1.cpp
+++ b/inst/lat/src/GLATPsfV1.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATPsfV1.cpp - Fermi/LAT point spread function version 1 class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2012-2018 by Juergen Knoedlseder *
+ * copyright (C) 2012-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -28,12 +28,12 @@
#ifdef HAVE_CONFIG_H
#include
#endif
-#include "GLATPsfV1.hpp"
-#include "GLATException.hpp"
+#include "GException.hpp"
#include "GMath.hpp"
#include "GFitsBinTable.hpp"
#include "GFitsTableFloatCol.hpp"
#include "GIntegral.hpp"
+#include "GLATPsfV1.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_READ "GLATPsfV1::read(GFitsTable&)"
@@ -174,7 +174,7 @@ GLATPsfV1* GLATPsfV1::clone(void) const
*
* @param[in] table FITS table.
*
- * @exception GLATException::inconsistent_response
+ * @exception GException::invalid_argument
* Inconsistent response table encountered
*
* Reads point spread function information from FITS HDU. In addition to the
@@ -213,20 +213,36 @@ void GLATPsfV1::read(const GFitsTable& table)
// Check consistency of columns
if (ncore->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- ncore->number(), size);
+ std::string msg = "Number of elements in \"NCORE\" column ("+
+ gammalib::str(ncore->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (sigma->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- sigma->number(), size);
+ std::string msg = "Number of elements in \"SIGMA\" column ("+
+ gammalib::str(sigma->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (gcore->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- gcore->number(), size);
+ std::string msg = "Number of elements in \"GCORE\" column ("+
+ gammalib::str(gcore->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (gtail->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- gtail->number(), size);
+ std::string msg = "Number of elements in \"GTAIL\" column ("+
+ gammalib::str(gtail->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
// Copy data
diff --git a/inst/lat/src/GLATPsfV3.cpp b/inst/lat/src/GLATPsfV3.cpp
index 396bb99..e32488e 100644
--- a/inst/lat/src/GLATPsfV3.cpp
+++ b/inst/lat/src/GLATPsfV3.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATPsfV3.cpp - Fermi/LAT point spread function version 3 class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2012-2018 by Juergen Knoedlseder *
+ * copyright (C) 2012-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -28,12 +28,12 @@
#ifdef HAVE_CONFIG_H
#include
#endif
-#include "GLATPsfV3.hpp"
-#include "GLATException.hpp"
+#include "GException.hpp"
#include "GMath.hpp"
#include "GFitsBinTable.hpp"
#include "GFitsTableFloatCol.hpp"
#include "GIntegral.hpp"
+#include "GLATPsfV3.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_READ "GLATPsfV3::read(GFitsTable&)"
@@ -175,7 +175,7 @@ GLATPsfV3* GLATPsfV3::clone(void) const
*
* @param[in] table FITS table.
*
- * @exception GLATException::inconsistent_response
+ * @exception GException::invalid_argument
* Inconsistent response table encountered
*
* Reads point spread function information from FITS HDU. In addition to the
@@ -224,28 +224,52 @@ void GLATPsfV3::read(const GFitsTable& table)
// Check consistency of columns
if (ncore->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- ncore->number(), size);
+ std::string msg = "Number of elements in \"NCORE\" column ("+
+ gammalib::str(ncore->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (ntail->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- ntail->number(), size);
+ std::string msg = "Number of elements in \"NTAIL\" column ("+
+ gammalib::str(ntail->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (score->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- score->number(), size);
+ std::string msg = "Number of elements in \"SCORE\" column ("+
+ gammalib::str(score->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (stail->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- stail->number(), size);
+ std::string msg = "Number of elements in \"STAIL\" column ("+
+ gammalib::str(stail->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (gcore->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- gcore->number(), size);
+ std::string msg = "Number of elements in \"GCORE\" column ("+
+ gammalib::str(gcore->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
if (gtail->number() != size) {
- throw GLATException::inconsistent_response(G_READ,
- gtail->number(), size);
+ std::string msg = "Number of elements in \"GTAIL\" column ("+
+ gammalib::str(gtail->number())+") is incompatible "
+ "with the expected size ("+
+ gammalib::str(size)+"). Please specify a valid "
+ "point spread function table.";
+ throw GException::invalid_argument(G_READ, msg);
}
// Copy data
diff --git a/inst/lat/src/GLATResponse.cpp b/inst/lat/src/GLATResponse.cpp
index 81cd76b..71b90f8 100644
--- a/inst/lat/src/GLATResponse.cpp
+++ b/inst/lat/src/GLATResponse.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* GLATResponse.cpp - Fermi LAT response class *
* ----------------------------------------------------------------------- *
- * copyright (C) 2008-2020 by Juergen Knoedlseder *
+ * copyright (C) 2008-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -43,7 +43,6 @@
#include "GLATEventAtom.hpp"
#include "GLATEventBin.hpp"
#include "GLATEventCube.hpp"
-#include "GLATException.hpp"
/* __ Method name definitions ____________________________________________ */
#define G_CALDB "GLATResponse::caldb(std::string&)"
@@ -53,6 +52,7 @@
#define G_NROI "GLATResponse::nroi(GModelSky&, GEnergy&, GTime&, "\
"GObservation&)"
#define G_EBOUNDS "GLATResponse::ebounds(GEnergy&)"
+#define G_SAVE "GLATResponse::save(std::string&)"
#define G_AEFF "GLATResponse::aeff(int&)"
#define G_PSF "GLATResponse::psf(int&)"
#define G_EDISP "GLATResponse::edisp(int&)"
@@ -200,7 +200,7 @@ GLATResponse* GLATResponse::clone(void) const
* @param[in] photon Incident photon.
* @param[in] obs Observation.
*
- * @exception GLATException::bad_instdir_type
+ * @exception GException::invalid_argument
* Instrument direction is not a valid LAT instrument direction.
*
* @todo The IRF value is not divided by ontime of the event, but it is
@@ -212,8 +212,14 @@ double GLATResponse::irf(const GEvent& event,
{
// Get pointer to LAT instrument direction
const GLATInstDir* dir = dynamic_cast(&(event.dir()));
+
+ // If pointer is not valid then throw an exception
if (dir == NULL) {
- throw GLATException::bad_instdir_type(G_IRF);
+ std::string cls = std::string(typeid(&(event.dir())).name());
+ std::string msg = "Invalid instrument direction type \""+cls+
+ "\" specified. Please specify a \"GLATInstDir\" "
+ "instance as argument.";
+ throw GException::invalid_argument(G_IRF, msg);
}
// Get photon attributes
@@ -326,15 +332,14 @@ double GLATResponse::irf_spatial_atom(const GLATEventAtom& event,
* @param[in] source Source.
* @param[in] obs Observation.
*
- * @exception GLATException::diffuse_not_found
+ * @exception GException::invalid_value
* Diffuse model not found.
*
* This method first searches for a corresponding source map, and if found,
* computes the response from the source map. If no source map is present
* it checks if the source is a point source. If this is the case a mean
* PSF is allocated for the source and the response is computed from the
- * mean PSF. Otherwise an GLATException::diffuse_not_found exception is
- * thrown.
+ * mean PSF. Otherwise an GException::invalid_value exception is thrown.
*
* @todo Extract event cube from observation. We do not need the cube
* pointer in the event anymore.
@@ -484,7 +489,11 @@ double GLATResponse::irf_spatial_bin(const GLATEventBin& event,
// ... otherwise throw an exception
if ((idiff == -1) && ptsrc == NULL) {
- throw GLATException::diffuse_not_found(G_IRF_BIN, source.name());
+ std::string msg = "No diffuse source with name \""+source.name()+
+ "\" found and source is not a point source. So far "
+ "the LAT module can only handle diffuse sources and "
+ "point sources. Please adapt your model accordingly.";
+ throw GException::invalid_value(G_IRF_BIN, msg);
}
// Return IRF value
@@ -686,6 +695,10 @@ void GLATResponse::load(const std::string& rspname)
***************************************************************************/
void GLATResponse::save(const std::string& rspname) const
{
+ // Throw an exception
+ std::string msg = "Saving of LAT response not implemented.";
+ throw GException::feature_not_implemented(G_SAVE, msg);
+
// Return
return;
}
@@ -713,14 +726,15 @@ GLATAeff* GLATResponse::aeff(const int& index) const
/***********************************************************************//**
* @brief Return pointer on point spread function
*
- * @param[in] index Response index (starting from 0).
+ * @param[in] index Response index [0,...,m_psf.size()-1].
***************************************************************************/
GLATPsf* GLATResponse::psf(const int& index) const
{
// Optionally check if the index is valid
#if defined(G_RANGE_CHECK)
if (index < 0 || index >= m_psf.size()) {
- throw GException::out_of_range(G_PSF, index, 0, m_psf.size()-1);
+ throw GException::out_of_range(G_PSF, "Response index", index,
+ m_psf.size());
}
#endif
@@ -732,14 +746,15 @@ GLATPsf* GLATResponse::psf(const int& index) const
/***********************************************************************//**
* @brief Return pointer on energy dispersion
*
- * @param[in] index Response index (starting from 0).
+ * @param[in] index Response index [0,...,m_edisp.size()-1].
***************************************************************************/
GLATEdisp* GLATResponse::edisp(const int& index) const
{
// Optionally check if the index is valid
#if defined(G_RANGE_CHECK)
if (index < 0 || index >= m_edisp.size()) {
- throw GException::out_of_range(G_EDISP, index, 0, m_edisp.size()-1);
+ throw GException::out_of_range(G_EDISP, "Response index", index,
+ m_edisp.size());
}
#endif
diff --git a/inst/lat/test/test_LAT.cpp b/inst/lat/test/test_LAT.cpp
index d406d52..62786ef 100644
--- a/inst/lat/test/test_LAT.cpp
+++ b/inst/lat/test/test_LAT.cpp
@@ -1,7 +1,7 @@
/***************************************************************************
* test_LAT.cpp - test Fermi/LAT classes *
* ----------------------------------------------------------------------- *
- * copyright (C) 2010-2018 by Juergen Knoedlseder *
+ * copyright (C) 2010-2021 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
@@ -359,12 +359,15 @@ void TestGLATResponse::test_one_response(const std::string& irf)
test_try_failure(e);
}
- // Try saving the response
+ // Try saving the response (not implemented)
test_try("Test saving the response");
try {
GLATResponse rsp;
rsp.load(irf);
rsp.save(fitsfile);
+ test_try_failure();
+ }
+ catch (GException::feature_not_implemented &e) {
test_try_success();
}
catch (std::exception &e) {