Commit 1ddef52d43232ad3dddf68a0fb1411e5e6ff1af7

Authored by Jürgen Knödlseder
2 parents 170feb84 df221f3b

Merge branch 'enhance-comptel' into integration

include/GTools.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GTools.hpp - GammaLib tools * 2 * GTools.hpp - GammaLib tools *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2008-2015 by Juergen Knoedlseder * 4 + * copyright (C) 2008-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -115,6 +115,10 @@ namespace gammalib { @@ -115,6 +115,10 @@ namespace gammalib {
115 const GXmlElement* xml_get_par(const std::string& origin, 115 const GXmlElement* xml_get_par(const std::string& origin,
116 const GXmlElement& xml, 116 const GXmlElement& xml,
117 const std::string& name); 117 const std::string& name);
  118 + std::string xml_get_attr(const std::string& origin,
  119 + const GXmlElement& xml,
  120 + const std::string& name,
  121 + const std::string& attribute);
118 void xml_check_par(const std::string& origin, 122 void xml_check_par(const std::string& origin,
119 const std::string& name, 123 const std::string& name,
120 const int& number); 124 const int& number);
inst/com/Makefile.am
@@ -13,7 +13,6 @@ INCLUDES = -I$(top_srcdir)/include \ @@ -13,7 +13,6 @@ INCLUDES = -I$(top_srcdir)/include \
13 13
14 # Define sources for this directory 14 # Define sources for this directory
15 sources = src/GCOMSupport.cpp \ 15 sources = src/GCOMSupport.cpp \
16 - src/GCOMException.cpp \  
17 src/GCOMEventCube.cpp \ 16 src/GCOMEventCube.cpp \
18 src/GCOMEventBin.cpp \ 17 src/GCOMEventBin.cpp \
19 src/GCOMInstDir.cpp \ 18 src/GCOMInstDir.cpp \
@@ -22,8 +21,7 @@ sources = src/GCOMSupport.cpp \ @@ -22,8 +21,7 @@ sources = src/GCOMSupport.cpp \
22 src/GCOMModelDRBFitting.cpp 21 src/GCOMModelDRBFitting.cpp
23 22
24 # Define headers to be installed 23 # Define headers to be installed
25 -pkginclude_HEADERS = include/GCOMException.hpp \  
26 - include/GCOMEventCube.hpp \ 24 +pkginclude_HEADERS = include/GCOMEventCube.hpp \
27 include/GCOMEventBin.hpp \ 25 include/GCOMEventBin.hpp \
28 include/GCOMInstDir.hpp \ 26 include/GCOMInstDir.hpp \
29 include/GCOMResponse.hpp \ 27 include/GCOMResponse.hpp \
inst/com/include/GCOMException.hpp deleted
1 -/***************************************************************************  
2 - * GCOMException.hpp - COMPTEL exception handler *  
3 - * ----------------------------------------------------------------------- *  
4 - * copyright (C) 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 GCOMException.hpp  
23 - * @brief COMPTEL exception handler interface definition  
24 - * @author Juergen Knoedlseder  
25 - */  
26 -  
27 -#ifndef GCOMEXCEPTION_HPP  
28 -#define GCOMEXCEPTION_HPP  
29 -  
30 -/* __ Includes ___________________________________________________________ */  
31 -#include <string> // string  
32 -#include <sstream> // ostringstream  
33 -#include <stdexcept> // exception  
34 -  
35 -  
36 -/***********************************************************************//**  
37 - * @class GCOMExceptionHandler  
38 - *  
39 - * @brief Interface for COMPTEL exception handler  
40 - ***************************************************************************/  
41 -class GCOMExceptionHandler : public std::exception {  
42 -public:  
43 - GCOMExceptionHandler(void) { }  
44 - virtual ~GCOMExceptionHandler(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 GCOMException  
54 - *  
55 - * @brief Interface for COMPTEL exceptions  
56 - *  
57 - * This object is thrown in case of a COMPTEL exception.  
58 - ***************************************************************************/  
59 -class GCOMException : public GCOMExceptionHandler {  
60 -public:  
61 - // General exceptions  
62 - class file_open_error : public GCOMExceptionHandler {  
63 - public:  
64 - file_open_error(const std::string& origin,  
65 - const std::string& filename,  
66 - const std::string& message = "");  
67 - };  
68 -  
69 - // Event cube exceptions  
70 - class no_sky : public GCOMExceptionHandler {  
71 - public:  
72 - no_sky(const std::string& origin,  
73 - const std::string& message = "");  
74 - };  
75 - class no_ebds : public GCOMExceptionHandler {  
76 - public:  
77 - no_ebds(const std::string& origin,  
78 - const std::string& message = "");  
79 - };  
80 - class no_gti : public GCOMExceptionHandler {  
81 - public:  
82 - no_gti(const std::string& origin,  
83 - const std::string& message = "");  
84 - };  
85 - class no_dirs : public GCOMExceptionHandler {  
86 - public:  
87 - no_dirs(const std::string& origin,  
88 - const std::string& message = "");  
89 - };  
90 -  
91 - // Observation exceptions  
92 - class incompatible_dataspace : public GCOMExceptionHandler {  
93 - public:  
94 - incompatible_dataspace(const std::string& origin,  
95 - const std::string& message = "");  
96 - };  
97 -  
98 - // Response exceptions  
99 - class bad_observation_type : public GCOMExceptionHandler {  
100 - public:  
101 - bad_observation_type(const std::string& origin,  
102 - const std::string& message = "");  
103 - };  
104 - class bad_event_type : public GCOMExceptionHandler {  
105 - public:  
106 - bad_event_type(const std::string& origin,  
107 - const std::string& message = "");  
108 - };  
109 - class bad_instdir_type : public GCOMExceptionHandler {  
110 - public:  
111 - bad_instdir_type(const std::string& origin,  
112 - const std::string& message = "");  
113 - };  
114 -};  
115 -  
116 -#endif /* GCOMEXCEPTION_HPP */  
inst/com/include/GCOMObservation.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GCOMObservation.hpp - COMPTEL observation class * 2 * GCOMObservation.hpp - COMPTEL observation class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2012-2015 by Juergen Knoedlseder * 4 + * copyright (C) 2012-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -41,9 +41,11 @@ @@ -41,9 +41,11 @@
41 * 41 *
42 * @brief Interface class for COMPTEL observations 42 * @brief Interface class for COMPTEL observations
43 * 43 *
44 - * This class implements a multi-wavelength observation. A multi-wavelength  
45 - * observation contains spectral points obtained with an unspecified  
46 - * instrument. The spectral points are given in physical units. 44 + * This class implements a COMPTEL observation. Each COMPTEL observation is
  45 + * defined for a given energy range, and is composed of a DRE, DRB, DRG and
  46 + * DRX file. The DRE file contains the event data, the DRB file contains a
  47 + * background model, the DRG file contains geometry factors, and the DRX file
  48 + * contains the exposure.
47 ***************************************************************************/ 49 ***************************************************************************/
48 class GCOMObservation : public GObservation { 50 class GCOMObservation : public GObservation {
49 51
@@ -58,7 +60,7 @@ public: @@ -58,7 +60,7 @@ public:
58 virtual ~GCOMObservation(void); 60 virtual ~GCOMObservation(void);
59 61
60 // Operators 62 // Operators
61 - virtual GCOMObservation& operator= (const GCOMObservation& obs); 63 + virtual GCOMObservation& operator=(const GCOMObservation& obs);
62 64
63 // Implement pure virtual methods 65 // Implement pure virtual methods
64 virtual void clear(void); 66 virtual void clear(void);
@@ -66,10 +68,10 @@ public: @@ -66,10 +68,10 @@ public:
66 virtual std::string classname(void) const; 68 virtual std::string classname(void) const;
67 virtual void response(const GResponse& rsp); 69 virtual void response(const GResponse& rsp);
68 virtual const GCOMResponse* response(void) const; 70 virtual const GCOMResponse* response(void) const;
69 - virtual std::string instrument(void) const { return m_instrument; }  
70 - virtual double ontime(void) const { return m_ontime; }  
71 - virtual double livetime(void) const { return m_livetime; }  
72 - virtual double deadc(const GTime& time) const { return m_deadc; } 71 + virtual std::string instrument(void) const;
  72 + virtual double ontime(void) const;
  73 + virtual double livetime(void) const;
  74 + virtual double deadc(const GTime& time) const;
73 virtual void read(const GXmlElement& xml); 75 virtual void read(const GXmlElement& xml);
74 virtual void write(GXmlElement& xml) const; 76 virtual void write(GXmlElement& xml) const;
75 virtual std::string print(const GChatter& chatter = NORMAL) const; 77 virtual std::string print(const GChatter& chatter = NORMAL) const;
@@ -80,16 +82,16 @@ public: @@ -80,16 +82,16 @@ public:
80 const std::string& drgname, 82 const std::string& drgname,
81 const std::string& drxname); 83 const std::string& drxname);
82 void response(const std::string& rspname, const GCaldb& caldb); 84 void response(const std::string& rspname, const GCaldb& caldb);
83 - void obs_id(const double& id) { m_obs_id=id; }  
84 - void ontime(const double& ontime) { m_ontime=ontime; }  
85 - void livetime(const double& livetime) { m_livetime=livetime; }  
86 - void deadc(const double& deadc) { m_deadc=deadc; }  
87 - void ewidth(const double& ewidth) { m_ewidth=ewidth; }  
88 - const double& obs_id(void) const { return m_obs_id; }  
89 - const double& ewidth(void) const { return m_ewidth; }  
90 - const GSkyMap& drb(void) const { return m_drb; }  
91 - const GSkyMap& drg(void) const { return m_drg; }  
92 - const GSkyMap& drx(void) const { return m_drx; } 85 + void obs_id(const double& id);
  86 + void ontime(const double& ontime);
  87 + void livetime(const double& livetime);
  88 + void deadc(const double& deadc);
  89 + void ewidth(const double& ewidth);
  90 + const double& obs_id(void) const;
  91 + const double& ewidth(void) const;
  92 + const GSkyMap& drb(void) const;
  93 + const GSkyMap& drg(void) const;
  94 + const GSkyMap& drx(void) const;
93 95
94 protected: 96 protected:
95 // Protected methods 97 // Protected methods
@@ -147,4 +149,188 @@ const GCOMResponse* GCOMObservation::response(void) const @@ -147,4 +149,188 @@ const GCOMResponse* GCOMObservation::response(void) const
147 return &m_response; 149 return &m_response;
148 } 150 }
149 151
  152 +
  153 +/***********************************************************************//**
  154 + * @brief Return instrument
  155 + *
  156 + * @return Instrument name.
  157 + ***************************************************************************/
  158 +inline
  159 +std::string GCOMObservation::instrument(void) const
  160 +{
  161 + // Return instrument
  162 + return (m_instrument);
  163 +}
  164 +
  165 +
  166 +/***********************************************************************//**
  167 + * @brief Return ontime
  168 + *
  169 + * @return Ontime (seconds).
  170 + ***************************************************************************/
  171 +inline
  172 +double GCOMObservation::ontime(void) const
  173 +{
  174 + // Return ontime
  175 + return (m_ontime);
  176 +}
  177 +
  178 +
  179 +/***********************************************************************//**
  180 + * @brief Return livetime
  181 + *
  182 + * @return Livetime (seconds).
  183 + ***************************************************************************/
  184 +inline
  185 +double GCOMObservation::livetime(void) const
  186 +{
  187 + // Return livetime
  188 + return (m_livetime);
  189 +}
  190 +
  191 +
  192 +/***********************************************************************//**
  193 + * @brief Return deadtime correction factor
  194 + *
  195 + * @param[in] time Time.
  196 + *
  197 + * @return Deadtime correction factor.
  198 + ***************************************************************************/
  199 +inline
  200 +double GCOMObservation::deadc(const GTime& time) const
  201 +{
  202 + // Return livetime
  203 + return (m_deadc);
  204 +}
  205 +
  206 +
  207 +/***********************************************************************//**
  208 + * @brief Set observation ID
  209 + *
  210 + * @param[in] id Observation ID.
  211 + ***************************************************************************/
  212 +inline
  213 +void GCOMObservation::obs_id(const double& id)
  214 +{
  215 + m_obs_id = id;
  216 + return;
  217 +}
  218 +
  219 +
  220 +/***********************************************************************//**
  221 + * @brief Set ontime
  222 + *
  223 + * @param[in] ontime Ontime.
  224 + ***************************************************************************/
  225 +inline
  226 +void GCOMObservation::ontime(const double& ontime)
  227 +{
  228 + m_ontime = ontime;
  229 + return;
  230 +}
  231 +
  232 +
  233 +/***********************************************************************//**
  234 + * @brief Set livetime
  235 + *
  236 + * @param[in] livetime Livetime.
  237 + ***************************************************************************/
  238 +inline
  239 +void GCOMObservation::livetime(const double& livetime)
  240 +{
  241 + m_livetime = livetime;
  242 + return;
  243 +}
  244 +
  245 +
  246 +/***********************************************************************//**
  247 + * @brief Set deadtime correction factor
  248 + *
  249 + * @param[in] deadc Deadtime correction factor.
  250 + ***************************************************************************/
  251 +inline
  252 +void GCOMObservation::deadc(const double& deadc)
  253 +{
  254 + m_deadc = deadc;
  255 + return;
  256 +}
  257 +
  258 +
  259 +/***********************************************************************//**
  260 + * @brief Set energy width
  261 + *
  262 + * @param[in] ewidth Energy width (MeV).
  263 + ***************************************************************************/
  264 +inline
  265 +void GCOMObservation::ewidth(const double& ewidth)
  266 +{
  267 + m_ewidth = ewidth;
  268 + return;
  269 +}
  270 +
  271 +
  272 +/***********************************************************************//**
  273 + * @brief Return observation ID
  274 + *
  275 + * @return Observation ID.
  276 + ***************************************************************************/
  277 +inline
  278 +const double& GCOMObservation::obs_id(void) const
  279 +{
  280 + // Return observation ID
  281 + return (m_obs_id);
  282 +}
  283 +
  284 +
  285 +/***********************************************************************//**
  286 + * @brief Return energy width
  287 + *
  288 + * @return Energy width (MeV).
  289 + ***************************************************************************/
  290 +inline
  291 +const double& GCOMObservation::ewidth(void) const
  292 +{
  293 + // Return energy width
  294 + return (m_ewidth);
  295 +}
  296 +
  297 +
  298 +/***********************************************************************//**
  299 + * @brief Return background model
  300 + *
  301 + * @return Background model.
  302 + ***************************************************************************/
  303 +inline
  304 +const GSkyMap& GCOMObservation::drb(void) const
  305 +{
  306 + // Return background model
  307 + return (m_drb);
  308 +}
  309 +
  310 +
  311 +/***********************************************************************//**
  312 + * @brief Return geometry factors
  313 + *
  314 + * @return Geometry factors.
  315 + ***************************************************************************/
  316 +inline
  317 +const GSkyMap& GCOMObservation::drg(void) const
  318 +{
  319 + // Return geometry factors
  320 + return (m_drg);
  321 +}
  322 +
  323 +
  324 +/***********************************************************************//**
  325 + * @brief Return exposure
  326 + *
  327 + * @return Exposure.
  328 + ***************************************************************************/
  329 +inline
  330 +const GSkyMap& GCOMObservation::drx(void) const
  331 +{
  332 + // Return exposure
  333 + return (m_drx);
  334 +}
  335 +
150 #endif /* GCOMOBSERVATION_HPP */ 336 #endif /* GCOMOBSERVATION_HPP */
inst/com/src/GCOMEventCube.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GCOMEventCube.cpp - COMPTEL event bin container class * 2 * GCOMEventCube.cpp - COMPTEL event bin container class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2012-2015 by Juergen Knoedlseder * 4 + * copyright (C) 2012-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -28,9 +28,9 @@ @@ -28,9 +28,9 @@
28 #ifdef HAVE_CONFIG_H 28 #ifdef HAVE_CONFIG_H
29 #include <config.h> 29 #include <config.h>
30 #endif 30 #endif
  31 +#include "GException.hpp"
31 #include "GTools.hpp" 32 #include "GTools.hpp"
32 #include "GFits.hpp" 33 #include "GFits.hpp"
33 -#include "GCOMException.hpp"  
34 #include "GCOMSupport.hpp" 34 #include "GCOMSupport.hpp"
35 #include "GCOMEventCube.hpp" 35 #include "GCOMEventCube.hpp"
36 36
@@ -102,9 +102,11 @@ GCOMEventCube::GCOMEventCube(const std::string&amp; filename) : GEventCube() @@ -102,9 +102,11 @@ GCOMEventCube::GCOMEventCube(const std::string&amp; filename) : GEventCube()
102 * Construct an event cube from sky map, energy boundaries, Good Time 102 * Construct an event cube from sky map, energy boundaries, Good Time
103 * Intervals and the scatter angle minimum value and step size. 103 * Intervals and the scatter angle minimum value and step size.
104 ***************************************************************************/ 104 ***************************************************************************/
105 -GCOMEventCube::GCOMEventCube(const GSkyMap& map, const GEbounds& ebds,  
106 - const GGti& gti, const double& phimin,  
107 - const double& dphi) : GEventCube() 105 +GCOMEventCube::GCOMEventCube(const GSkyMap& map,
  106 + const GEbounds& ebds,
  107 + const GGti& gti,
  108 + const double& phimin,
  109 + const double& dphi) : GEventCube()
108 { 110 {
109 // Initialise members 111 // Initialise members
110 init_members(); 112 init_members();
@@ -174,7 +176,7 @@ GCOMEventCube::~GCOMEventCube(void) @@ -174,7 +176,7 @@ GCOMEventCube::~GCOMEventCube(void)
174 * @param[in] cube Event cube. 176 * @param[in] cube Event cube.
175 * @return Event cube. 177 * @return Event cube.
176 ***************************************************************************/ 178 ***************************************************************************/
177 -GCOMEventCube& GCOMEventCube::operator= (const GCOMEventCube& cube) 179 +GCOMEventCube& GCOMEventCube::operator=(const GCOMEventCube& cube)
178 { 180 {
179 // Execute only if object is not identical 181 // Execute only if object is not identical
180 if (this != &cube) { 182 if (this != &cube) {
@@ -680,7 +682,7 @@ void GCOMEventCube::free_members(void) @@ -680,7 +682,7 @@ void GCOMEventCube::free_members(void)
680 /***********************************************************************//** 682 /***********************************************************************//**
681 * @brief Set sky directions and solid angles of events cube 683 * @brief Set sky directions and solid angles of events cube
682 * 684 *
683 - * @exception GCOMException::no_sky 685 + * @exception GException::invalid_value
684 * No sky pixels have been defined. 686 * No sky pixels have been defined.
685 * 687 *
686 * This method computes the sky directions and solid angles for all (Chi,Psi) 688 * This method computes the sky directions and solid angles for all (Chi,Psi)
@@ -692,8 +694,10 @@ void GCOMEventCube::set_scatter_directions(void) @@ -692,8 +694,10 @@ void GCOMEventCube::set_scatter_directions(void)
692 { 694 {
693 // Throw an error if we have no sky pixels 695 // Throw an error if we have no sky pixels
694 if (npix() < 1) { 696 if (npix() < 1) {
695 - throw GCOMException::no_sky(G_SET_SCATTER_DIRECTIONS,  
696 - "Every COMPTEL event cube needs a definition of sky pixels."); 697 + std::string msg = "No sky pixels have been found in event cube. "
  698 + "Every COMPTEL event cube needs a definition of "
  699 + "sky pixels.";
  700 + throw GException::invalid_value(G_SET_SCATTER_DIRECTIONS, msg);
697 } 701 }
698 702
699 // Clear vectors 703 // Clear vectors
@@ -752,15 +756,17 @@ void GCOMEventCube::set_scatter_angles(const double&amp; phimin, const double&amp; dphi) @@ -752,15 +756,17 @@ void GCOMEventCube::set_scatter_angles(const double&amp; phimin, const double&amp; dphi)
752 /***********************************************************************//** 756 /***********************************************************************//**
753 * @brief Set log mean energy and energy width of event cube 757 * @brief Set log mean energy and energy width of event cube
754 * 758 *
755 - * @exception GCOMException::no_ebds  
756 - * No energy intervals found. 759 + * @exception GException::invalid_value
  760 + * No energy boundaries found.
757 ***************************************************************************/ 761 ***************************************************************************/
758 void GCOMEventCube::set_energies(void) 762 void GCOMEventCube::set_energies(void)
759 { 763 {
760 // Throw an error if GTI is empty 764 // Throw an error if GTI is empty
761 if (m_ebounds.size() < 1) { 765 if (m_ebounds.size() < 1) {
762 - throw GCOMException::no_ebds(G_SET_ENERGIES, "Every COMPTEL event"  
763 - " cube needs a definition of the energy boundaries."); 766 + std::string msg = "No energy boundaries have been found in event "
  767 + "cube. Every COMPTEL event cube needs a definition "
  768 + "of the energy boundaries.";
  769 + throw GException::invalid_value(G_SET_ENERGIES, msg);
764 } 770 }
765 771
766 // Compute the logarithmic mean energy 772 // Compute the logarithmic mean energy
@@ -777,7 +783,7 @@ void GCOMEventCube::set_energies(void) @@ -777,7 +783,7 @@ void GCOMEventCube::set_energies(void)
777 /***********************************************************************//** 783 /***********************************************************************//**
778 * @brief Set mean event time and ontime of event cube 784 * @brief Set mean event time and ontime of event cube
779 * 785 *
780 - * @exception GCOMException::no_gti 786 + * @exception GException::invalid_value
781 * No Good Time Intervals found. 787 * No Good Time Intervals found.
782 * 788 *
783 * Computes the mean time of the event cube by taking the mean between start 789 * Computes the mean time of the event cube by taking the mean between start
@@ -788,9 +794,10 @@ void GCOMEventCube::set_times(void) @@ -788,9 +794,10 @@ void GCOMEventCube::set_times(void)
788 { 794 {
789 // Throw an error if GTI is empty 795 // Throw an error if GTI is empty
790 if (m_gti.size() < 1) { 796 if (m_gti.size() < 1) {
791 - throw GCOMException::no_gti(G_SET_TIMES, "Every COMPTEL event cube"  
792 - " needs associated GTIs to allow the computation of the"  
793 - " ontime."); 797 + std::string msg = "No Good Time Intervals have been found in event "
  798 + "cube. Every COMPTEL event cube needs a definition "
  799 + "of the Good Time Intervals.";
  800 + throw GException::invalid_value(G_SET_TIMES, msg);
794 } 801 }
795 802
796 // Compute mean time 803 // Compute mean time
@@ -836,7 +843,7 @@ void GCOMEventCube::init_bin(void) @@ -836,7 +843,7 @@ void GCOMEventCube::init_bin(void)
836 * 843 *
837 * @exception GException::out_of_range 844 * @exception GException::out_of_range
838 * Event index is outside valid range. 845 * Event index is outside valid range.
839 - * @exception GCOMException::no_dirs 846 + * @exception GException::invalid_value
840 * Sky directions and solid angles vectors have not been set up. 847 * Sky directions and solid angles vectors have not been set up.
841 * 848 *
842 * This method provides the event attributes to the event bin. The event bin 849 * This method provides the event attributes to the event bin. The event bin
@@ -856,7 +863,10 @@ void GCOMEventCube::set_bin(const int&amp; index) @@ -856,7 +863,10 @@ void GCOMEventCube::set_bin(const int&amp; index)
856 863
857 // Check for the existence of sky directions and solid angles 864 // Check for the existence of sky directions and solid angles
858 if (m_dirs.size() != npix() || m_solidangle.size() != npix()) { 865 if (m_dirs.size() != npix() || m_solidangle.size() != npix()) {
859 - throw GCOMException::no_dirs(G_SET_BIN); 866 + std::string msg = "Sky direction vector has not been setup for "
  867 + "event cube. Every COMPTEL event cube needs an "
  868 + "internal vector of sky directions.";
  869 + throw GException::invalid_value(G_SET_BIN, msg);
860 } 870 }
861 871
862 // Get pixel and energy bin indices. 872 // Get pixel and energy bin indices.
@@ -871,7 +881,7 @@ void GCOMEventCube::set_bin(const int&amp; index) @@ -871,7 +881,7 @@ void GCOMEventCube::set_bin(const int&amp; index)
871 m_dir.phibar(m_phi[iphi]); 881 m_dir.phibar(m_phi[iphi]);
872 882
873 // Set pointers 883 // Set pointers
874 - m_bin.m_counts = const_cast<double*>(&(m_map.pixels()[index])); 884 + m_bin.m_counts = const_cast<double*>(&(m_map.pixels()[index]));
875 m_bin.m_solidangle = &(m_solidangle[ipix]); 885 m_bin.m_solidangle = &(m_solidangle[ipix]);
876 886
877 // Return 887 // Return
inst/com/src/GCOMException.cpp deleted
1 -/***************************************************************************  
2 - * GCOMException.cpp - COMPTEL exception handler *  
3 - * ----------------------------------------------------------------------- *  
4 - * copyright (C) 2012-2013 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 GCOMException.cpp  
23 - * @brief COMPTEL exception handler interface implementation  
24 - * @author Juergen Knoedlseder  
25 - */  
26 -  
27 -/* __ Includes ___________________________________________________________ */  
28 -#include "GCOMException.hpp"  
29 -#include "GTools.hpp"  
30 -  
31 -  
32 -/***********************************************************************//**  
33 - * @brief Exception message  
34 - ***************************************************************************/  
35 -const char* GCOMExceptionHandler::what() const throw()  
36 -{  
37 - // Set error message  
38 - std::string message = "*** ERROR in " + m_origin + ": " + m_message;  
39 -  
40 - // Return message as C character array  
41 - return gammalib::tochar(message);  
42 -}  
43 -  
44 -  
45 -/***********************************************************************//**  
46 - * @brief Error while opening file  
47 - *  
48 - * @param[in] origin Name of method that has thrown the exception.  
49 - * @param[in] filename Name of file that could not be opened.  
50 - * @param[in] message Optional error message.  
51 - ***************************************************************************/  
52 -GCOMException::file_open_error::file_open_error(const std::string& origin,  
53 - const std::string& filename,  
54 - const std::string& message)  
55 -{  
56 - // Set origin  
57 - m_origin = origin;  
58 -  
59 - // Set message  
60 - m_message = "Unable to open file \""+filename+"\".";  
61 -  
62 - // Append optional message  
63 - if (message.length() > 0) {  
64 - m_message += " "+message;  
65 - }  
66 -  
67 - // Return  
68 - return;  
69 -}  
70 -  
71 -  
72 -/***********************************************************************//**  
73 - * @brief No sky pixels found  
74 - *  
75 - * @param[in] origin Name of method that has thrown the exception.  
76 - * @param[in] message Optional error message.  
77 - ***************************************************************************/  
78 -GCOMException::no_sky::no_sky(const std::string& origin,  
79 - const std::string& message)  
80 -{  
81 - // Set origin  
82 - m_origin = origin;  
83 -  
84 - // Set message  
85 - m_message = "No sky pixels have been found.";  
86 -  
87 - // Append optional message  
88 - if (message.length() > 0) {  
89 - m_message += " "+message;  
90 - }  
91 -  
92 - // Return  
93 - return;  
94 -}  
95 -  
96 -  
97 -/***********************************************************************//**  
98 - * @brief No energy boundaries found  
99 - *  
100 - * @param[in] origin Name of method that has thrown the exception.  
101 - * @param[in] message Optional error message.  
102 - ***************************************************************************/  
103 -GCOMException::no_ebds::no_ebds(const std::string& origin,  
104 - const std::string& message)  
105 -{  
106 - // Set origin  
107 - m_origin = origin;  
108 -  
109 - // Set message  
110 - m_message = "No energy boundaries have been found.";  
111 -  
112 - // Append optional message  
113 - if (message.length() > 0) {  
114 - m_message += " "+message;  
115 - }  
116 -  
117 - // Return  
118 - return;  
119 -}  
120 -  
121 -  
122 -/***********************************************************************//**  
123 - * @brief No Good Time Intervals found  
124 - *  
125 - * @param[in] origin Name of method that has thrown the exception.  
126 - * @param[in] message Optional error message.  
127 - ***************************************************************************/  
128 -GCOMException::no_gti::no_gti(const std::string& origin,  
129 - const std::string& message)  
130 -{  
131 - // Set origin  
132 - m_origin = origin;  
133 -  
134 - // Set message  
135 - m_message = "No Good Time Intervals (GTIs) have been found.";  
136 -  
137 - // Append optional message  
138 - if (message.length() > 0) {  
139 - m_message += " "+message;  
140 - }  
141 -  
142 - // Return  
143 - return;  
144 -}  
145 -  
146 -  
147 -/***********************************************************************//**  
148 - * @brief No sky directions found  
149 - *  
150 - * @param[in] origin Name of method that has thrown the exception.  
151 - * @param[in] message Optional error message.  
152 - ***************************************************************************/  
153 -GCOMException::no_dirs::no_dirs(const std::string& origin,  
154 - const std::string& message)  
155 -{  
156 - // Set origin  
157 - m_origin = origin;  
158 -  
159 - // Set message  
160 - m_message = "Sky direction vector has not been setup."  
161 - " Cannot access event information.";  
162 -  
163 - // Append optional message  
164 - if (message.length() > 0) {  
165 - m_message += " "+message;  
166 - }  
167 -  
168 - // Return  
169 - return;  
170 -}  
171 -  
172 -  
173 -/***********************************************************************//**  
174 - * @brief Incompatible COMPTEL dataspace  
175 - *  
176 - * @param[in] origin Name of method that has thrown the exception.  
177 - * @param[in] message Optional error message.  
178 - ***************************************************************************/  
179 -GCOMException::incompatible_dataspace::incompatible_dataspace(const std::string& origin,  
180 - const std::string& message)  
181 -{  
182 - // Set origin  
183 - m_origin = origin;  
184 -  
185 - // Set message  
186 - m_message = "Dataspace incompatibility.";  
187 -  
188 - // Append optional message  
189 - if (message.length() > 0) {  
190 - m_message += " "+message;  
191 - }  
192 -  
193 - // Return  
194 - return;  
195 -}  
196 -  
197 -  
198 -/***********************************************************************//**  
199 - * @brief Observation is not a COMPTEL observation  
200 - *  
201 - * @param[in] origin Name of method that has thrown the exception.  
202 - * @param[in] message Optional error message.  
203 - ***************************************************************************/  
204 -GCOMException::bad_observation_type::bad_observation_type(const std::string& origin,  
205 - const std::string& message)  
206 -{  
207 - // Set origin  
208 - m_origin = origin;  
209 -  
210 - // Set message  
211 - m_message = "Observation is not of type GCOMObservation.";  
212 -  
213 - // Append optional message  
214 - if (message.length() > 0) {  
215 - m_message += " "+message;  
216 - }  
217 -  
218 - // Return  
219 - return;  
220 -}  
221 -  
222 -  
223 -/***********************************************************************//**  
224 - * @brief Event is not a COMPTEL event  
225 - *  
226 - * @param[in] origin Name of method that has thrown the exception.  
227 - * @param[in] message Optional error message.  
228 - ***************************************************************************/  
229 -GCOMException::bad_event_type::bad_event_type(const std::string& origin,  
230 - const std::string& message)  
231 -{  
232 - // Set origin  
233 - m_origin = origin;  
234 -  
235 - // Set message  
236 - m_message = "Event is not of type GCOMEventAtom or GCOMEventBin.";  
237 -  
238 - // Append optional message  
239 - if (message.length() > 0) {  
240 - m_message += " "+message;  
241 - }  
242 -  
243 - // Return  
244 - return;  
245 -}  
246 -  
247 -  
248 -  
249 -  
250 -/***********************************************************************//**  
251 - * @brief Instrument direction is not a COMPTEL instrument direction  
252 - *  
253 - * @param[in] origin Name of method that has thrown the exception.  
254 - * @param[in] message Optional error message.  
255 - ***************************************************************************/  
256 -GCOMException::bad_instdir_type::bad_instdir_type(const std::string& origin,  
257 - const std::string& message)  
258 -{  
259 - // Set origin  
260 - m_origin = origin;  
261 -  
262 - // Set message  
263 - m_message = "Instrument direction is not of type GCOMInstDir.";  
264 -  
265 - // Append optional message  
266 - if (message.length() > 0) {  
267 - m_message += " "+message;  
268 - }  
269 -  
270 - // Return  
271 - return;  
272 -}  
inst/com/src/GCOMModelDRBFitting.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GCOMModelDRBFitting.cpp - COMPTEL DRB model fitting class * 2 * GCOMModelDRBFitting.cpp - COMPTEL DRB model fitting class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2012-2013 by Juergen Knoedlseder * 4 + * copyright (C) 2012-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -28,11 +28,11 @@ @@ -28,11 +28,11 @@
28 #ifdef HAVE_CONFIG_H 28 #ifdef HAVE_CONFIG_H
29 #include <config.h> 29 #include <config.h>
30 #endif 30 #endif
  31 +#include <typeinfo>
31 #include "GException.hpp" 32 #include "GException.hpp"
32 #include "GTools.hpp" 33 #include "GTools.hpp"
33 #include "GModelRegistry.hpp" 34 #include "GModelRegistry.hpp"
34 #include "GCOMModelDRBFitting.hpp" 35 #include "GCOMModelDRBFitting.hpp"
35 -#include "GCOMException.hpp"  
36 #include "GCOMObservation.hpp" 36 #include "GCOMObservation.hpp"
37 #include "GCOMEventBin.hpp" 37 #include "GCOMEventBin.hpp"
38 38
@@ -231,9 +231,8 @@ GCOMModelDRBFitting* GCOMModelDRBFitting::clone(void) const @@ -231,9 +231,8 @@ GCOMModelDRBFitting* GCOMModelDRBFitting::clone(void) const
231 * @param[in] obs Observation. 231 * @param[in] obs Observation.
232 * @return Background model value. 232 * @return Background model value.
233 * 233 *
234 - * @exception GCOMException::bad_observation_type 234 + * @exception GException::invalid_argument
235 * Observation is not a COMPTEL observation. 235 * Observation is not a COMPTEL observation.
236 - * @exception GCOMException::bad_event_type  
237 * Event is not a COMPTEL event bin. 236 * Event is not a COMPTEL event bin.
238 * 237 *
239 * Evaluates the COMPTEL DRB fitting model. 238 * Evaluates the COMPTEL DRB fitting model.
@@ -244,13 +243,20 @@ double GCOMModelDRBFitting::eval(const GEvent&amp; event, @@ -244,13 +243,20 @@ double GCOMModelDRBFitting::eval(const GEvent&amp; event,
244 // Extract COMPTEL observation 243 // Extract COMPTEL observation
245 const GCOMObservation* observation = dynamic_cast<const GCOMObservation*>(&obs); 244 const GCOMObservation* observation = dynamic_cast<const GCOMObservation*>(&obs);
246 if (observation == NULL) { 245 if (observation == NULL) {
247 - throw GCOMException::bad_observation_type(G_EVAL); 246 + std::string cls = std::string(typeid(&obs).name());
  247 + std::string msg = "Observation of type \""+cls+"\" is not a COMPTEL "
  248 + "observations. Please specify a COMPTEL observation "
  249 + "as argument.";
  250 + throw GException::invalid_argument(G_EVAL, msg);
248 } 251 }
249 252
250 // Extract COMPTEL event bin 253 // Extract COMPTEL event bin
251 const GCOMEventBin* bin = dynamic_cast<const GCOMEventBin*>(&event); 254 const GCOMEventBin* bin = dynamic_cast<const GCOMEventBin*>(&event);
252 if (bin == NULL) { 255 if (bin == NULL) {
253 - throw GCOMException::bad_event_type(G_EVAL); 256 + std::string cls = std::string(typeid(&event).name());
  257 + std::string msg = "Event of type \""+cls+"\" is not a COMPTEL event. "
  258 + "Please specify a COMPTEL event as argument.";
  259 + throw GException::invalid_argument(G_EVAL, msg);
254 } 260 }
255 261
256 // Initialise value 262 // Initialise value
@@ -337,13 +343,20 @@ double GCOMModelDRBFitting::eval_gradients(const GEvent&amp; event, @@ -337,13 +343,20 @@ double GCOMModelDRBFitting::eval_gradients(const GEvent&amp; event,
337 // Extract COMPTEL observation 343 // Extract COMPTEL observation
338 const GCOMObservation* observation = dynamic_cast<const GCOMObservation*>(&obs); 344 const GCOMObservation* observation = dynamic_cast<const GCOMObservation*>(&obs);
339 if (observation == NULL) { 345 if (observation == NULL) {
340 - throw GCOMException::bad_observation_type(G_EVAL_GRADIENTS); 346 + std::string cls = std::string(typeid(&obs).name());
  347 + std::string msg = "Observation of type \""+cls+"\" is not a COMPTEL "
  348 + "observations. Please specify a COMPTEL observation "
  349 + "as argument.";
  350 + throw GException::invalid_argument(G_EVAL_GRADIENTS, msg);
341 } 351 }
342 352
343 // Extract COMPTEL event bin 353 // Extract COMPTEL event bin
344 const GCOMEventBin* bin = dynamic_cast<const GCOMEventBin*>(&event); 354 const GCOMEventBin* bin = dynamic_cast<const GCOMEventBin*>(&event);
345 if (bin == NULL) { 355 if (bin == NULL) {
346 - throw GCOMException::bad_event_type(G_EVAL_GRADIENTS); 356 + std::string cls = std::string(typeid(&event).name());
  357 + std::string msg = "Event of type \""+cls+"\" is not a COMPTEL event. "
  358 + "Please specify a COMPTEL event as argument.";
  359 + throw GException::invalid_argument(G_EVAL_GRADIENTS, msg);
347 } 360 }
348 361
349 // Initialise value and gradients 362 // Initialise value and gradients
@@ -491,10 +504,8 @@ GCOMEventCube* GCOMModelDRBFitting::mc(const GObservation&amp; obs, @@ -491,10 +504,8 @@ GCOMEventCube* GCOMModelDRBFitting::mc(const GObservation&amp; obs,
491 * 504 *
492 * @param[in] xml XML element. 505 * @param[in] xml XML element.
493 * 506 *
494 - * @exception GException::model_invalid_parnum  
495 - * Invalid number of model parameters found in XML element.  
496 - * @exception GException::model_invalid_parnames  
497 - * Invalid model parameter name found in XML element. 507 + * @exception GException::invalid_value
  508 + * Model definition requires at least one node.
498 * 509 *
499 * Read the COMPTEL DRB fitting model from an XML element. 510 * Read the COMPTEL DRB fitting model from an XML element.
500 * 511 *
@@ -524,9 +535,9 @@ void GCOMModelDRBFitting::read(const GXmlElement&amp; xml) @@ -524,9 +535,9 @@ void GCOMModelDRBFitting::read(const GXmlElement&amp; xml)
524 535
525 // Throw an error if there are no nodes 536 // Throw an error if there are no nodes
526 if (nodes < 1) { 537 if (nodes < 1) {
527 - std::string message = "DRB fitting model requires at least one"  
528 - " Phibar node.";  
529 - throw GException::model_invalid_parnum(G_READ, xml, message); 538 + std::string msg = "DRB fitting model requires at least one Phibar "
  539 + "node. Please correct XML format.";
  540 + throw GException::invalid_value(G_READ, msg);
530 } 541 }
531 542
532 // Loop over all nodes 543 // Loop over all nodes
@@ -539,38 +550,13 @@ void GCOMModelDRBFitting::read(const GXmlElement&amp; xml) @@ -539,38 +550,13 @@ void GCOMModelDRBFitting::read(const GXmlElement&amp; xml)
539 // Get node 550 // Get node
540 const GXmlElement* node = xml.element("node", i); 551 const GXmlElement* node = xml.element("node", i);
541 552
542 - // Verify that node XML element has exactly 2 parameters  
543 - if (node->elements() != 2 || node->elements("parameter") != 2) {  
544 - throw GException::model_invalid_parnum(G_READ, xml,  
545 - "Node requires exactly 2 parameters.");  
546 - }  
547 -  
548 - // Extract node parameters  
549 - int npar[] = {0, 0};  
550 - for (int k = 0; k < 2; ++k) {  
551 -  
552 - // Get parameter element  
553 - const GXmlElement* par = node->element("parameter", k);  
554 -  
555 - // Handle energy  
556 - if (par->attribute("name") == "Phibar") {  
557 - phibar.read(*par);  
558 - npar[0]++;  
559 - }  
560 -  
561 - // Handle intensity  
562 - else if (par->attribute("name") == "Normalization") {  
563 - normalization.read(*par);  
564 - npar[1]++;  
565 - }  
566 -  
567 - } // endfor: looped over parameters 553 + // Read Phibar parameter
  554 + const GXmlElement* par = gammalib::xml_get_par(G_READ, *node, "Phibar");
  555 + phibar.read(*par);
568 556
569 - // Verify that all parameters were found  
570 - if (npar[0] != 1 || npar[1] != 1) {  
571 - throw GException::model_invalid_parnames(G_READ, xml,  
572 - "Require \"Phibar\" and \"Normalization\" parameters.");  
573 - } 557 + // Read Normalization parameter
  558 + par = gammalib::xml_get_par(G_READ, *node, "Normalization");
  559 + normalization.read(*par);
574 560
575 // Set parameter names 561 // Set parameter names
576 std::string phibar_name = "Phibar layer "+gammalib::str(i); 562 std::string phibar_name = "Phibar layer "+gammalib::str(i);
@@ -675,8 +661,10 @@ void GCOMModelDRBFitting::write(GXmlElement&amp; xml) const @@ -675,8 +661,10 @@ void GCOMModelDRBFitting::write(GXmlElement&amp; xml) const
675 661
676 // Verify model type 662 // Verify model type
677 if (src->attribute("type") != type()) { 663 if (src->attribute("type") != type()) {
678 - throw GException::model_invalid_spectral(G_WRITE, src->attribute("type"),  
679 - "DRB fitting model is not of type \""+type()+"\"."); 664 + std::string msg = "Invalid model type \""+src->attribute("type")+"\" "
  665 + "found in XML file. Model type \""+type()+"\" "
  666 + "expected.";
  667 + throw GException::invalid_value(G_WRITE, msg);
680 } 668 }
681 669
682 // Determine number of nodes 670 // Determine number of nodes
@@ -691,9 +679,11 @@ void GCOMModelDRBFitting::write(GXmlElement&amp; xml) const @@ -691,9 +679,11 @@ void GCOMModelDRBFitting::write(GXmlElement&amp; xml) const
691 679
692 // Verify that XML element has the required number of nodes 680 // Verify that XML element has the required number of nodes
693 if (src->elements() != nodes || src->elements("node") != nodes) { 681 if (src->elements() != nodes || src->elements("node") != nodes) {
694 - std::string message = "DRB fitting model requires exactly " +  
695 - gammalib::str(nodes) + " nodes.";  
696 - throw GException::model_invalid_parnum(G_WRITE, *src, message); 682 + std::string msg = "Invalid number of nodes "+
  683 + gammalib::str(src->elements("node"))+
  684 + " found in XML file, but model requires exactly "+
  685 + gammalib::str(nodes)+" nodes.";
  686 + throw GException::invalid_value(G_WRITE, msg);
697 } 687 }
698 688
699 // Loop over all nodes 689 // Loop over all nodes
@@ -702,45 +692,13 @@ void GCOMModelDRBFitting::write(GXmlElement&amp; xml) const @@ -702,45 +692,13 @@ void GCOMModelDRBFitting::write(GXmlElement&amp; xml) const
702 // Get node 692 // Get node
703 GXmlElement* node = src->element("node", i); 693 GXmlElement* node = src->element("node", i);
704 694
705 - // If XML element has 0 leafs then append energy and intensity  
706 - // element  
707 - if (node->elements() == 0) {  
708 - node->append(GXmlElement("parameter name=\"Phibar\""));  
709 - node->append(GXmlElement("parameter name=\"Normalization\""));  
710 - }  
711 -  
712 - // Verify that node XML element has exactly 2 parameters  
713 - if (node->elements() != 2 || node->elements("parameter") != 2) {  
714 - throw GException::model_invalid_parnum(G_WRITE, *src,  
715 - "Node requires exactly 2 parameters.");  
716 - }  
717 -  
718 - // Set or update model parameter attributes  
719 - int npar[] = {0, 0};  
720 - for (int k = 0; k < 2; ++k) {  
721 -  
722 - // Get parameter element  
723 - GXmlElement* par = node->element("parameter", k); 695 + // Write Phibar parameter
  696 + GXmlElement* par = gammalib::xml_need_par(G_WRITE, *node, "Phibar");
  697 + m_phibars[i].write(*par);
724 698
725 - // Handle prefactor  
726 - if (par->attribute("name") == "Phibar") {  
727 - npar[0]++;  
728 - m_phibars[i].write(*par);  
729 - }  
730 -  
731 - // Handle index  
732 - else if (par->attribute("name") == "Normalization") {  
733 - npar[1]++;  
734 - m_values[i].write(*par);  
735 - }  
736 -  
737 - } // endfor: looped over parameters  
738 -  
739 - // Check of all required parameters are present  
740 - if (npar[0] != 1 || npar[1] != 1) {  
741 - throw GException::model_invalid_parnames(G_WRITE, *src,  
742 - "Require \"Phibar\" and \"Normalization\" parameters.");  
743 - } 699 + // Write Normalization parameter
  700 + par = gammalib::xml_need_par(G_WRITE, *node, "Normalization");
  701 + m_values[i].write(*par);
744 702
745 } // endfor: looped over nodes 703 } // endfor: looped over nodes
746 704
inst/com/src/GCOMObservation.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GCOMObservation.cpp - COMPTEL Observation class * 2 * GCOMObservation.cpp - COMPTEL Observation class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2012-2015 by Juergen Knoedlseder * 4 + * copyright (C) 2012-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -33,7 +33,6 @@ @@ -33,7 +33,6 @@
33 #include "GException.hpp" 33 #include "GException.hpp"
34 #include "GFits.hpp" 34 #include "GFits.hpp"
35 #include "GTools.hpp" 35 #include "GTools.hpp"
36 -#include "GCOMException.hpp"  
37 #include "GCOMObservation.hpp" 36 #include "GCOMObservation.hpp"
38 #include "GCOMEventCube.hpp" 37 #include "GCOMEventCube.hpp"
39 #include "GCOMSupport.hpp" 38 #include "GCOMSupport.hpp"
@@ -65,7 +64,7 @@ const GObservationRegistry g_obs_com_registry(&amp;g_obs_com_seed); @@ -65,7 +64,7 @@ const GObservationRegistry g_obs_com_registry(&amp;g_obs_com_seed);
65 /***********************************************************************//** 64 /***********************************************************************//**
66 * @brief Void constructor 65 * @brief Void constructor
67 * 66 *
68 - * Creates empty class instance. 67 + * Creates an empty COMPTEL observation.
69 ***************************************************************************/ 68 ***************************************************************************/
70 GCOMObservation::GCOMObservation(void) : GObservation() 69 GCOMObservation::GCOMObservation(void) : GObservation()
71 { 70 {
@@ -115,7 +114,7 @@ GCOMObservation::GCOMObservation(const std::string&amp; drename, @@ -115,7 +114,7 @@ GCOMObservation::GCOMObservation(const std::string&amp; drename,
115 * 114 *
116 * @param[in] obs COMPTEL observation. 115 * @param[in] obs COMPTEL observation.
117 * 116 *
118 - * Creates class instance by copying an existing COMPTEL observation. 117 + * Creates COMPTEL observation by copying an existing COMPTEL observation.
119 ***************************************************************************/ 118 ***************************************************************************/
120 GCOMObservation::GCOMObservation(const GCOMObservation& obs) : GObservation(obs) 119 GCOMObservation::GCOMObservation(const GCOMObservation& obs) : GObservation(obs)
121 { 120 {
@@ -188,7 +187,7 @@ GCOMObservation&amp; GCOMObservation::operator=(const GCOMObservation&amp; obs) @@ -188,7 +187,7 @@ GCOMObservation&amp; GCOMObservation::operator=(const GCOMObservation&amp; obs)
188 ==========================================================================*/ 187 ==========================================================================*/
189 188
190 /***********************************************************************//** 189 /***********************************************************************//**
191 - * @brief Clear instance 190 + * @brief Clear COMPTEL observation
192 ***************************************************************************/ 191 ***************************************************************************/
193 void GCOMObservation::clear(void) 192 void GCOMObservation::clear(void)
194 { 193 {
@@ -206,7 +205,7 @@ void GCOMObservation::clear(void) @@ -206,7 +205,7 @@ void GCOMObservation::clear(void)
206 205
207 206
208 /***********************************************************************//** 207 /***********************************************************************//**
209 - * @brief Clone instance 208 + * @brief Clone COMPTEL observation
210 * 209 *
211 * @return Pointer to deep copy of COMPTEL observation. 210 * @return Pointer to deep copy of COMPTEL observation.
212 ***************************************************************************/ 211 ***************************************************************************/
@@ -221,19 +220,21 @@ GCOMObservation* GCOMObservation::clone(void) const @@ -221,19 +220,21 @@ GCOMObservation* GCOMObservation::clone(void) const
221 * 220 *
222 * @param[in] rsp Response function. 221 * @param[in] rsp Response function.
223 * 222 *
224 - * @exception GException::rsp_invalid_type  
225 - * Specified response is not of type GCOMResponse. 223 + * @exception GException::invalid_argument
  224 + * Specified response is not a COMPTEL response.
226 * 225 *
227 - * Sets the response function for the observation. The argument has to be of  
228 - * type GCOMResponse, otherwise an exception is thrown. 226 + * Sets the response function for the observation.
229 ***************************************************************************/ 227 ***************************************************************************/
230 void GCOMObservation::response(const GResponse& rsp) 228 void GCOMObservation::response(const GResponse& rsp)
231 { 229 {
232 // Get pointer on COM response 230 // Get pointer on COM response
233 const GCOMResponse* comrsp = dynamic_cast<const GCOMResponse*>(&rsp); 231 const GCOMResponse* comrsp = dynamic_cast<const GCOMResponse*>(&rsp);
234 if (comrsp == NULL) { 232 if (comrsp == NULL) {
235 - throw GException::rsp_invalid_type(G_RESPONSE,  
236 - typeid(&rsp).name(), "Expected type \"GCOMResponse\"."); 233 + std::string cls = std::string(typeid(&rsp).name());
  234 + std::string msg = "Response of type \""+cls+"\" is "
  235 + "not a COMPTEL response. Please specify a COMPTEL "
  236 + "response as argument.";
  237 + throw GException::invalid_argument(G_RESPONSE, msg);
237 } 238 }
238 239
239 // Clone response function 240 // Clone response function
@@ -250,8 +251,8 @@ void GCOMObservation::response(const GResponse&amp; rsp) @@ -250,8 +251,8 @@ void GCOMObservation::response(const GResponse&amp; rsp)
250 * @param[in] rspname Name of COMPTEL response. 251 * @param[in] rspname Name of COMPTEL response.
251 * @param[in] caldb Calibration database. 252 * @param[in] caldb Calibration database.
252 * 253 *
253 - * Sets the response function by loading the response information from an  
254 - * IAQ file. 254 + * Sets the response function by loading the response information from the
  255 + * calibration database.
255 ***************************************************************************/ 256 ***************************************************************************/
256 void GCOMObservation::response(const std::string& rspname, const GCaldb& caldb) 257 void GCOMObservation::response(const std::string& rspname, const GCaldb& caldb)
257 { 258 {
@@ -274,11 +275,6 @@ void GCOMObservation::response(const std::string&amp; rspname, const GCaldb&amp; caldb) @@ -274,11 +275,6 @@ void GCOMObservation::response(const std::string&amp; rspname, const GCaldb&amp; caldb)
274 * 275 *
275 * @param[in] xml XML element. 276 * @param[in] xml XML element.
276 * 277 *
277 - * @exception GException::xml_invalid_parnum  
278 - * Invalid number of parameters found in XML element.  
279 - * @exception GException::xml_invalid_parnames  
280 - * Invalid parameter names found in XML element.  
281 - *  
282 * Reads information for a COMPTEL observation from an XML element. 278 * Reads information for a COMPTEL observation from an XML element.
283 * The expected format of the XML element is 279 * The expected format of the XML element is
284 * 280 *
@@ -287,7 +283,7 @@ void GCOMObservation::response(const std::string&amp; rspname, const GCaldb&amp; caldb) @@ -287,7 +283,7 @@ void GCOMObservation::response(const std::string&amp; rspname, const GCaldb&amp; caldb)
287 * <parameter name="DRB" file="..."/> 283 * <parameter name="DRB" file="..."/>
288 * <parameter name="DRG" file="..."/> 284 * <parameter name="DRG" file="..."/>
289 * <parameter name="DRX" file="..."/> 285 * <parameter name="DRX" file="..."/>
290 - * <parameter name="IAQ" file="..."/> 286 + * <parameter name="IAQ" value="..."/>
291 * </observation> 287 * </observation>
292 * 288 *
293 * for a binned observation. 289 * for a binned observation.
@@ -297,70 +293,15 @@ void GCOMObservation::read(const GXmlElement&amp; xml) @@ -297,70 +293,15 @@ void GCOMObservation::read(const GXmlElement&amp; xml)
297 // Clear observation 293 // Clear observation
298 clear(); 294 clear();
299 295
300 - // Initialise FITS file names  
301 - std::string drename;  
302 - std::string drbname;  
303 - std::string drgname;  
304 - std::string drxname;  
305 - std::string iaqname;  
306 -  
307 // Extract instrument name 296 // Extract instrument name
308 m_instrument = xml.attribute("instrument"); 297 m_instrument = xml.attribute("instrument");
309 298
310 - // Determine number of parameter nodes in XML element  
311 - int npars = xml.elements("parameter");  
312 -  
313 - // Verify that XML element has exactly 5 parameters  
314 - if (xml.elements() != 5 || npars != 5) {  
315 - throw GException::xml_invalid_parnum(G_READ, xml,  
316 - "COMPTEL observation requires exactly 5 parameters.");  
317 - }  
318 -  
319 - // Extract parameters  
320 - int npar[] = {0, 0, 0, 0, 0};  
321 - for (int i = 0; i < npars; ++i) {  
322 -  
323 - // Get parameter element  
324 - const GXmlElement* par = xml.element("parameter", i);  
325 -  
326 - // Handle EventList  
327 - if (par->attribute("name") == "DRE") {  
328 - drename = par->attribute("file");  
329 - npar[0]++;  
330 - }  
331 -  
332 - // Handle DRB  
333 - else if (par->attribute("name") == "DRB") {  
334 - drbname = par->attribute("file");  
335 - npar[1]++;  
336 - }  
337 -  
338 - // Handle DRG  
339 - else if (par->attribute("name") == "DRG") {  
340 - drgname = par->attribute("file");  
341 - npar[2]++;  
342 - }  
343 -  
344 - // Handle DRX  
345 - else if (par->attribute("name") == "DRX") {  
346 - drxname = par->attribute("file");  
347 - npar[3]++;  
348 - }  
349 -  
350 - // Handle IAQ  
351 - else if (par->attribute("name") == "IAQ") {  
352 - iaqname = par->attribute("file");  
353 - npar[4]++;  
354 - }  
355 -  
356 - } // endfor: looped over all parameters  
357 -  
358 - // Verify that all parameters were found  
359 - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1 || npar[3] != 1 || npar[4] != 1) {  
360 - throw GException::xml_invalid_parnames(G_READ, xml,  
361 - "Require \"DRE\", \"DRB\", \"DRG\", \"DRX\" and \"IAQ\""  
362 - " parameters.");  
363 - } 299 + // Get parameters
  300 + std::string drename = gammalib::xml_get_attr(G_READ, xml, "DRE", "file");
  301 + std::string drbname = gammalib::xml_get_attr(G_READ, xml, "DRB", "file");
  302 + std::string drgname = gammalib::xml_get_attr(G_READ, xml, "DRG", "file");
  303 + std::string drxname = gammalib::xml_get_attr(G_READ, xml, "DRX", "file");
  304 + std::string iaqname = gammalib::xml_get_attr(G_READ, xml, "IAQ", "value");
364 305
365 // Load observation 306 // Load observation
366 load(drename, drbname, drgname, drxname); 307 load(drename, drbname, drgname, drxname);
@@ -378,11 +319,6 @@ void GCOMObservation::read(const GXmlElement&amp; xml) @@ -378,11 +319,6 @@ void GCOMObservation::read(const GXmlElement&amp; xml)
378 * 319 *
379 * @param[in] xml XML element. 320 * @param[in] xml XML element.
380 * 321 *
381 - * @exception GException::xml_invalid_parnum  
382 - * Invalid number of parameters found in XML element.  
383 - * @exception GException::xml_invalid_parnames  
384 - * Invalid parameter names found in XML element.  
385 - *  
386 * Writes information for a COMPTEL observation into an XML element. The 322 * Writes information for a COMPTEL observation into an XML element. The
387 * expected format of the XML element is 323 * expected format of the XML element is
388 * 324 *
@@ -391,75 +327,35 @@ void GCOMObservation::read(const GXmlElement&amp; xml) @@ -391,75 +327,35 @@ void GCOMObservation::read(const GXmlElement&amp; xml)
391 * <parameter name="DRB" file="..."/> 327 * <parameter name="DRB" file="..."/>
392 * <parameter name="DRG" file="..."/> 328 * <parameter name="DRG" file="..."/>
393 * <parameter name="DRX" file="..."/> 329 * <parameter name="DRX" file="..."/>
394 - * <parameter name="IAQ" file="..."/> 330 + * <parameter name="IAQ" value="..."/>
395 * </observation> 331 * </observation>
396 * 332 *
397 * for a binned observation. 333 * for a binned observation.
398 ***************************************************************************/ 334 ***************************************************************************/
399 void GCOMObservation::write(GXmlElement& xml) const 335 void GCOMObservation::write(GXmlElement& xml) const
400 { 336 {
401 - // If XML element has 0 nodes then append 5 parameter nodes  
402 - if (xml.elements() == 0) {  
403 - xml.append(GXmlElement("parameter name=\"DRE\""));  
404 - xml.append(GXmlElement("parameter name=\"DRB\""));  
405 - xml.append(GXmlElement("parameter name=\"DRG\""));  
406 - xml.append(GXmlElement("parameter name=\"DRX\""));  
407 - xml.append(GXmlElement("parameter name=\"IAQ\""));  
408 - }  
409 -  
410 - // Verify that XML element has exactly 5 parameters  
411 - if (xml.elements() != 5 || xml.elements("parameter") != 5) {  
412 - throw GException::xml_invalid_parnum(G_WRITE, xml,  
413 - "COMPTEL observation requires exactly 5 parameters.");  
414 - }  
415 -  
416 - // Set or update parameter attributes  
417 - int npar[] = {0, 0, 0, 0, 0};  
418 - for (int i = 0; i < 5; ++i) {  
419 -  
420 - // Get parameter element  
421 - GXmlElement* par = xml.element("parameter", i); 337 + // Allocate XML element pointer
  338 + GXmlElement* par;
422 339
423 - // Handle DRE  
424 - if (par->attribute("name") == "DRE") {  
425 - par->attribute("file", m_drename);  
426 - npar[0]++;  
427 - }  
428 -  
429 - // Handle DRB  
430 - else if (par->attribute("name") == "DRB") {  
431 - par->attribute("file", m_drbname);  
432 - npar[1]++;  
433 - }  
434 -  
435 - // Handle DRG  
436 - else if (par->attribute("name") == "DRG") {  
437 - par->attribute("file", m_drgname);  
438 - npar[2]++;  
439 - } 340 + // Set DRE parameter
  341 + par = gammalib::xml_need_par(G_WRITE, xml, "DRE");
  342 + par->attribute("file", m_drename);
440 343
441 - // Handle DRX  
442 - else if (par->attribute("name") == "DRX") {  
443 - par->attribute("file", m_drxname);  
444 - npar[3]++;  
445 - } 344 + // Set DRB parameter
  345 + par = gammalib::xml_need_par(G_WRITE, xml, "DRB");
  346 + par->attribute("file", m_drbname);
446 347
447 - // Handle IAQ  
448 - else if (par->attribute("name") == "IAQ") {  
449 - std::string iaqname = "";  
450 - iaqname = m_response.rspname();  
451 - par->attribute("file", iaqname);  
452 - npar[4]++;  
453 - } 348 + // Set DRG parameter
  349 + par = gammalib::xml_need_par(G_WRITE, xml, "DRG");
  350 + par->attribute("file", m_drgname);
454 351
455 - } // endfor: looped over all parameters 352 + // Set DRX parameter
  353 + par = gammalib::xml_need_par(G_WRITE, xml, "DRX");
  354 + par->attribute("file", m_drxname);
456 355
457 - // Verify that all required parameters are present  
458 - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1 || npar[3] != 1 || npar[4] != 1) {  
459 - throw GException::xml_invalid_parnames(G_WRITE, xml,  
460 - "Require \"DRE\", \"DRB\", \"DRG\", \"DRX\" and \"IAQ\""  
461 - " parameters.");  
462 - } 356 + // Set IAQ parameter
  357 + par = gammalib::xml_need_par(G_WRITE, xml, "DRX");
  358 + par->attribute("value", m_response.rspname());
463 359
464 // Return 360 // Return
465 return; 361 return;
@@ -579,11 +475,11 @@ void GCOMObservation::init_members(void) @@ -579,11 +475,11 @@ void GCOMObservation::init_members(void)
579 m_drx.clear(); 475 m_drx.clear();
580 m_pointing.clear(); 476 m_pointing.clear();
581 m_response.clear(); 477 m_response.clear();
582 - m_obs_id = 0;  
583 - m_ontime = 0.0;  
584 - m_livetime = 0.0;  
585 - m_deadc = 0.0;  
586 - m_ewidth = 0.0; 478 + m_obs_id = 0;
  479 + m_ontime = 0.0;
  480 + m_livetime = 0.0;
  481 + m_deadc = 0.0;
  482 + m_ewidth = 0.0;
587 483
588 // Return 484 // Return
589 return; 485 return;
@@ -670,7 +566,7 @@ void GCOMObservation::load_dre(const std::string&amp; drename) @@ -670,7 +566,7 @@ void GCOMObservation::load_dre(const std::string&amp; drename)
670 * 566 *
671 * @param[in] drbname DRB filename. 567 * @param[in] drbname DRB filename.
672 * 568 *
673 - * @exception GCOMException::incompatible_dataspace 569 + * @exception GException::invalid_value
674 * DRB data space incompatible with DRE data space. 570 * DRB data space incompatible with DRE data space.
675 * 571 *
676 * Load the background model from the primary image of the specified FITS 572 * Load the background model from the primary image of the specified FITS
@@ -695,8 +591,9 @@ void GCOMObservation::load_drb(const std::string&amp; drbname) @@ -695,8 +591,9 @@ void GCOMObservation::load_drb(const std::string&amp; drbname)
695 591
696 // Check map dimensions 592 // Check map dimensions
697 if (!check_map(m_drb)) { 593 if (!check_map(m_drb)) {
698 - throw GCOMException::incompatible_dataspace(G_LOAD_DRB,  
699 - "DRB data cube incompatible with DRE data cube."); 594 + std::string msg = "DRB data cube \""+drbname+"\" incompatible with "
  595 + "DRE data cube \""+m_drename+"\".";
  596 + throw GException::invalid_value(G_LOAD_DRB, msg);
700 } 597 }
701 598
702 // Store DRB filename 599 // Store DRB filename
@@ -712,7 +609,7 @@ void GCOMObservation::load_drb(const std::string&amp; drbname) @@ -712,7 +609,7 @@ void GCOMObservation::load_drb(const std::string&amp; drbname)
712 * 609 *
713 * @param[in] drgname DRG filename. 610 * @param[in] drgname DRG filename.
714 * 611 *
715 - * @exception GCOMException::incompatible_dataspace 612 + * @exception GException::invalid_value
716 * DRG data space incompatible with DRE data space. 613 * DRG data space incompatible with DRE data space.
717 * 614 *
718 * Load the geometry factors from the primary image of the specified FITS 615 * Load the geometry factors from the primary image of the specified FITS
@@ -737,8 +634,9 @@ void GCOMObservation::load_drg(const std::string&amp; drgname) @@ -737,8 +634,9 @@ void GCOMObservation::load_drg(const std::string&amp; drgname)
737 634
738 // Check map dimensions 635 // Check map dimensions
739 if (!check_map(m_drg)) { 636 if (!check_map(m_drg)) {
740 - throw GCOMException::incompatible_dataspace(G_LOAD_DRG,  
741 - "DRG data cube incompatible with DRE data cube."); 637 + std::string msg = "DRG data cube \""+drgname+"\" incompatible with "
  638 + "DRE data cube \""+m_drename+"\".";
  639 + throw GException::invalid_value(G_LOAD_DRB, msg);
742 } 640 }
743 641
744 // Store DRG filename 642 // Store DRG filename
inst/com/src/GCOMResponse.cpp
1 /*************************************************************************** 1 /***************************************************************************
2 * GCOMResponse.cpp - COMPTEL Response class * 2 * GCOMResponse.cpp - COMPTEL Response class *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2012-2015 by Juergen Knoedlseder * 4 + * copyright (C) 2012-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
29 #include <config.h> 29 #include <config.h>
30 #endif 30 #endif
31 #include <string> 31 #include <string>
  32 +#include <typeinfo>
32 #include "GTools.hpp" 33 #include "GTools.hpp"
33 #include "GMath.hpp" 34 #include "GMath.hpp"
34 #include "GFits.hpp" 35 #include "GFits.hpp"
@@ -46,7 +47,6 @@ @@ -46,7 +47,6 @@
46 #include "GCOMObservation.hpp" 47 #include "GCOMObservation.hpp"
47 #include "GCOMEventBin.hpp" 48 #include "GCOMEventBin.hpp"
48 #include "GCOMInstDir.hpp" 49 #include "GCOMInstDir.hpp"
49 -#include "GCOMException.hpp"  
50 50
51 /* __ Method name definitions ____________________________________________ */ 51 /* __ Method name definitions ____________________________________________ */
52 #define G_IRF "GCOMResponse::irf(GEvent&, GSource&, GObservation&)" 52 #define G_IRF "GCOMResponse::irf(GEvent&, GSource&, GObservation&)"
@@ -230,10 +230,9 @@ GCOMResponse* GCOMResponse::clone(void) const @@ -230,10 +230,9 @@ GCOMResponse* GCOMResponse::clone(void) const
230 * @param[in] obs Observation. 230 * @param[in] obs Observation.
231 * @return Instrument response function (cm2 sr-1) 231 * @return Instrument response function (cm2 sr-1)
232 * 232 *
233 - * @exception GCOMException::bad_observation_type 233 + * @exception GException::invalid_argument
234 * Observation is not a COMPTEL observation. 234 * Observation is not a COMPTEL observation.
235 - * @exception GCOMException::bad_instdir_type  
236 - * Instrument direction is not a COMPTEL instrument direction. 235 + * Event is not a COMPTEL event bin.
237 * 236 *
238 * Returns the instrument response function for a given observed photon 237 * Returns the instrument response function for a given observed photon
239 * direction as function of the assumed true photon direction. The result 238 * direction as function of the assumed true photon direction. The result
@@ -258,13 +257,20 @@ double GCOMResponse::irf(const GEvent&amp; event, @@ -258,13 +257,20 @@ double GCOMResponse::irf(const GEvent&amp; event,
258 // Extract COMPTEL observation 257 // Extract COMPTEL observation
259 const GCOMObservation* observation = dynamic_cast<const GCOMObservation*>(&obs); 258 const GCOMObservation* observation = dynamic_cast<const GCOMObservation*>(&obs);
260 if (observation == NULL) { 259 if (observation == NULL) {
261 - throw GCOMException::bad_observation_type(G_IRF); 260 + std::string cls = std::string(typeid(&obs).name());
  261 + std::string msg = "Observation of type \""+cls+"\" is not a COMPTEL "
  262 + "observations. Please specify a COMPTEL observation "
  263 + "as argument.";
  264 + throw GException::invalid_argument(G_IRF, msg);
262 } 265 }
263 266
264 // Extract COMPTEL event bin 267 // Extract COMPTEL event bin
265 const GCOMEventBin* bin = dynamic_cast<const GCOMEventBin*>(&event); 268 const GCOMEventBin* bin = dynamic_cast<const GCOMEventBin*>(&event);
266 if (bin == NULL) { 269 if (bin == NULL) {
267 - throw GCOMException::bad_event_type(G_IRF); 270 + std::string cls = std::string(typeid(&event).name());
  271 + std::string msg = "Event of type \""+cls+"\" is not a COMPTEL event. "
  272 + "Please specify a COMPTEL event as argument.";
  273 + throw GException::invalid_argument(G_IRF, msg);
268 } 274 }
269 275
270 // Extract event parameters 276 // Extract event parameters
inst/com/test/data/obs.xml
  1 +<?xml version="1.0" standalone="no"?>
1 <observation_list title="observation library"> 2 <observation_list title="observation library">
2 <observation name="Crab" id="00001" instrument="COM"> 3 <observation name="Crab" id="00001" instrument="COM">
3 <parameter name="DRE" file="$(PACKAGE_SOURCE)/inst/com/test/data/m50439_dre.fits"/> 4 <parameter name="DRE" file="$(PACKAGE_SOURCE)/inst/com/test/data/m50439_dre.fits"/>
4 <parameter name="DRB" file="$(PACKAGE_SOURCE)/inst/com/test/data/m34997_drg.fits"/> 5 <parameter name="DRB" file="$(PACKAGE_SOURCE)/inst/com/test/data/m34997_drg.fits"/>
5 <parameter name="DRG" file="$(PACKAGE_SOURCE)/inst/com/test/data/m34997_drg.fits"/> 6 <parameter name="DRG" file="$(PACKAGE_SOURCE)/inst/com/test/data/m34997_drg.fits"/>
6 <parameter name="DRX" file="$(PACKAGE_SOURCE)/inst/com/test/data/m32171_drx.fits"/> 7 <parameter name="DRX" file="$(PACKAGE_SOURCE)/inst/com/test/data/m32171_drx.fits"/>
7 - <parameter name="IAQ" file="ENERG(1.0-3.0)MeV"/> 8 + <parameter name="IAQ" value="ENERG(1.0-3.0)MeV"/>
8 </observation> 9 </observation>
9 </observation_list> 10 </observation_list>
10 \ No newline at end of file 11 \ No newline at end of file
pyext/GTools.i
1 /*************************************************************************** 1 /***************************************************************************
2 * GTools.i - GammaLib tools * 2 * GTools.i - GammaLib tools *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2008-2015 by Juergen Knoedlseder * 4 + * copyright (C) 2008-2016 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -82,6 +82,10 @@ namespace gammalib { @@ -82,6 +82,10 @@ namespace gammalib {
82 const GXmlElement* xml_get_par(const std::string& origin, 82 const GXmlElement* xml_get_par(const std::string& origin,
83 const GXmlElement& xml, 83 const GXmlElement& xml,
84 const std::string& name); 84 const std::string& name);
  85 + std::string xml_get_attr(const std::string& origin,
  86 + const GXmlElement& xml,
  87 + const std::string& name,
  88 + const std::string& attribute);
85 void xml_check_par(const std::string& origin, 89 void xml_check_par(const std::string& origin,
86 const std::string& name, 90 const std::string& name,
87 const int& number); 91 const int& number);
src/support/GTools.cpp
@@ -1392,10 +1392,10 @@ bool gammalib::xml_has_par(const GXmlElement&amp; xml, const std::string&amp; name) @@ -1392,10 +1392,10 @@ bool gammalib::xml_has_par(const GXmlElement&amp; xml, const std::string&amp; name)
1392 * 1392 *
1393 * Returns pointer to parameter with given @p name in XML element. If the 1393 * Returns pointer to parameter with given @p name in XML element. If the
1394 * @p name is not found, a parameter with the given @p name is added. In 1394 * @p name is not found, a parameter with the given @p name is added. In
1395 - * that respect the method differs from xml_getpar which does not add a 1395 + * that respect the function differs from xml_get_par which does not add a
1396 * parameter element. 1396 * parameter element.
1397 * 1397 *
1398 - * The method checks for multiple occurences of a parameter and throws an 1398 + * The function checks for multiple occurences of a parameter and throws an
1399 * exception in case that more than one parameter with a given name is found. 1399 * exception in case that more than one parameter with a given name is found.
1400 ***************************************************************************/ 1400 ***************************************************************************/
1401 GXmlElement* gammalib::xml_need_par(const std::string& origin, 1401 GXmlElement* gammalib::xml_need_par(const std::string& origin,
@@ -1442,10 +1442,10 @@ GXmlElement* gammalib::xml_need_par(const std::string&amp; origin, @@ -1442,10 +1442,10 @@ GXmlElement* gammalib::xml_need_par(const std::string&amp; origin,
1442 * @exception GException::invalid_value 1442 * @exception GException::invalid_value
1443 * Invalid XML format encountered. 1443 * Invalid XML format encountered.
1444 * 1444 *
1445 - * Returns pointer to parameter with given @p name in XML element. The method  
1446 - * checks whether the parameter has been found and throws an exception if  
1447 - * no parameter or multiple occurences of a parameter with given @p name  
1448 - * are found. 1445 + * Returns pointer to parameter with given @p name in XML element. The
  1446 + * function checks whether the parameter has been found and throws an
  1447 + * exception if no parameter or multiple occurences of a parameter with given
  1448 + * @p name are found.
1449 ***************************************************************************/ 1449 ***************************************************************************/
1450 const GXmlElement* gammalib::xml_get_par(const std::string& origin, 1450 const GXmlElement* gammalib::xml_get_par(const std::string& origin,
1451 const GXmlElement& xml, 1451 const GXmlElement& xml,
@@ -1476,6 +1476,51 @@ const GXmlElement* gammalib::xml_get_par(const std::string&amp; origin, @@ -1476,6 +1476,51 @@ const GXmlElement* gammalib::xml_get_par(const std::string&amp; origin,
1476 1476
1477 1477
1478 /***********************************************************************//** 1478 /***********************************************************************//**
  1479 + * @brief Return attribute value for a given parameter in XML element
  1480 + *
  1481 + * @param[in] origin Method requesting parameter.
  1482 + * @param[in] xml XML element.
  1483 + * @param[in] name Parameter name.
  1484 + * @param[in] attribute Attribute name.
  1485 + * @return Value of attribute.
  1486 + *
  1487 + * @exception GException::invalid_value
  1488 + * Attribute not found.
  1489 + *
  1490 + * Returns the value of @p attribute of parameter @p name in XML element.
  1491 + * The function checks whether the parameter has been found and throws an
  1492 + * exception if no parameter or multiple occurences of a parameter with given
  1493 + * @p name are found. The function furthermore checks whether the attribute
  1494 + * exists.
  1495 + ***************************************************************************/
  1496 +std::string gammalib::xml_get_attr(const std::string& origin,
  1497 + const GXmlElement& xml,
  1498 + const std::string& name,
  1499 + const std::string& attribute)
  1500 +{
  1501 + // Initialise attribute value
  1502 + std::string value = "";
  1503 +
  1504 + // Get parameter
  1505 + const GXmlElement* par = gammalib::xml_get_par(origin, xml, name);
  1506 +
  1507 + // Throw an exception if a parameter has not the requested attribute
  1508 + if (!par->has_attribute(attribute)) {
  1509 + std::string msg = "Attribute \""+attribute+"\" not found in XML "
  1510 + "parameter \""+name+"\". Please verify the XML "
  1511 + "format.";
  1512 + throw GException::invalid_value(origin, msg);
  1513 + }
  1514 +
  1515 + // Extract attribute
  1516 + value = par->attribute(attribute);
  1517 +
  1518 + // Return attribute value
  1519 + return value;
  1520 +}
  1521 +
  1522 +
  1523 +/***********************************************************************//**
1479 * @brief Checks whether a parameter has occured once 1524 * @brief Checks whether a parameter has occured once
1480 * 1525 *
1481 * @param[in] origin Method performing the check. 1526 * @param[in] origin Method performing the check.