Commit 9f5239ad3d34608fc0ca30dbbb8670ae41d57ded
1 parent
ea0c1ea3
add no_list() and no_cube() exceptions
Showing
2 changed files
with
133 additions
and
30 deletions
include/GException.hpp
| @@ -397,6 +397,14 @@ public: | @@ -397,6 +397,14 @@ public: | ||
| 397 | public: | 397 | public: |
| 398 | no_roi(std::string origin, std::string message = ""); | 398 | no_roi(std::string origin, std::string message = ""); |
| 399 | }; | 399 | }; |
| 400 | + class no_list : public GExceptionHandler { | ||
| 401 | + public: | ||
| 402 | + no_list(std::string origin, std::string message = ""); | ||
| 403 | + }; | ||
| 404 | + class no_cube : public GExceptionHandler { | ||
| 405 | + public: | ||
| 406 | + no_cube(std::string origin, std::string message = ""); | ||
| 407 | + }; | ||
| 400 | class gradient_par_mismatch : public GExceptionHandler { | 408 | class gradient_par_mismatch : public GExceptionHandler { |
| 401 | public: | 409 | public: |
| 402 | gradient_par_mismatch(std::string origin, int nsize, int npars); | 410 | gradient_par_mismatch(std::string origin, int nsize, int npars); |
src/obs/GException_obs.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * GException_obs.cpp - observations exception handlers * | 2 | * GException_obs.cpp - observations exception handlers * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010 by Jurgen Knodlseder * | 4 | + * copyright (C) 2010-2011 by Jurgen Knodlseder * |
| 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 * |
| @@ -25,33 +25,89 @@ | @@ -25,33 +25,89 @@ | ||
| 25 | 25 | ||
| 26 | 26 | ||
| 27 | /***********************************************************************//** | 27 | /***********************************************************************//** |
| 28 | - * @brief No valid instrument response. | 28 | + * @brief No valid instrument response found |
| 29 | * | 29 | * |
| 30 | * @param[in] origin Name of method that has thrown the exception. | 30 | * @param[in] origin Name of method that has thrown the exception. |
| 31 | * @param[in] message Optional error message. | 31 | * @param[in] message Optional error message. |
| 32 | ***************************************************************************/ | 32 | ***************************************************************************/ |
| 33 | GException::no_response::no_response(std::string origin, std::string message) | 33 | GException::no_response::no_response(std::string origin, std::string message) |
| 34 | { | 34 | { |
| 35 | - m_origin = origin; | ||
| 36 | - m_message = "Instrument response not defined." | ||
| 37 | - " Define instrument response before using this method."+ | ||
| 38 | - message; | 35 | + // Set method name |
| 36 | + m_origin = origin; | ||
| 37 | + | ||
| 38 | + // Set error message | ||
| 39 | + m_message = "No valid instrument response found in observation." \ | ||
| 40 | + " Set instrument response before using this method."; | ||
| 41 | + if (message.length() > 0) | ||
| 42 | + m_message += " " + message; | ||
| 43 | + | ||
| 44 | + // Return | ||
| 39 | return; | 45 | return; |
| 40 | } | 46 | } |
| 41 | 47 | ||
| 42 | 48 | ||
| 43 | /***********************************************************************//** | 49 | /***********************************************************************//** |
| 44 | - * @brief No valid region of interest. | 50 | + * @brief No valid event list found |
| 51 | + * | ||
| 52 | + * @param[in] origin Method that throws the error. | ||
| 53 | + * @param[in] message Optional error message. | ||
| 54 | + ***************************************************************************/ | ||
| 55 | +GException::no_list::no_list(std::string origin, std::string message) | ||
| 56 | +{ | ||
| 57 | + // Set method name | ||
| 58 | + m_origin = origin; | ||
| 59 | + | ||
| 60 | + // Set error message | ||
| 61 | + m_message = "No valid event list found in observation." \ | ||
| 62 | + " Set event list before using this method."; | ||
| 63 | + if (message.length() > 0) | ||
| 64 | + m_message += " " + message; | ||
| 65 | + | ||
| 66 | + // Return | ||
| 67 | + return; | ||
| 68 | +} | ||
| 69 | + | ||
| 70 | + | ||
| 71 | +/***********************************************************************//** | ||
| 72 | + * @brief No valid event cube found | ||
| 73 | + * | ||
| 74 | + * @param[in] origin Method that throws the error. | ||
| 75 | + * @param[in] message Optional error message. | ||
| 76 | + ***************************************************************************/ | ||
| 77 | +GException::no_cube::no_cube(std::string origin, std::string message) | ||
| 78 | +{ | ||
| 79 | + // Set method name | ||
| 80 | + m_origin = origin; | ||
| 81 | + | ||
| 82 | + // Set error message | ||
| 83 | + m_message = "No valid event cube found in observation." \ | ||
| 84 | + " Set event cube before using this method."; | ||
| 85 | + if (message.length() > 0) | ||
| 86 | + m_message += " " + message; | ||
| 87 | + | ||
| 88 | + // Return | ||
| 89 | + return; | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | + | ||
| 93 | +/***********************************************************************//** | ||
| 94 | + * @brief No valid region of interest found | ||
| 45 | * | 95 | * |
| 46 | * @param[in] origin Method that throws the error. | 96 | * @param[in] origin Method that throws the error. |
| 47 | * @param[in] message Optional error message. | 97 | * @param[in] message Optional error message. |
| 48 | ***************************************************************************/ | 98 | ***************************************************************************/ |
| 49 | GException::no_roi::no_roi(std::string origin, std::string message) | 99 | GException::no_roi::no_roi(std::string origin, std::string message) |
| 50 | { | 100 | { |
| 51 | - m_origin = origin; | ||
| 52 | - m_message = "Region of interest not defined." | ||
| 53 | - " Define region of interest before using this method."+ | ||
| 54 | - message; | 101 | + // Set method name |
| 102 | + m_origin = origin; | ||
| 103 | + | ||
| 104 | + // Set error message | ||
| 105 | + m_message = "No valid region of interest (ROI) found in observation." \ | ||
| 106 | + " Set region of interest before using this method."; | ||
| 107 | + if (message.length() > 0) | ||
| 108 | + m_message += " " + message; | ||
| 109 | + | ||
| 110 | + // Return | ||
| 55 | return; | 111 | return; |
| 56 | } | 112 | } |
| 57 | 113 | ||
| @@ -67,14 +123,20 @@ GException::gradient_par_mismatch::gradient_par_mismatch(std::string origin, | @@ -67,14 +123,20 @@ GException::gradient_par_mismatch::gradient_par_mismatch(std::string origin, | ||
| 67 | int nsize, | 123 | int nsize, |
| 68 | int npars) | 124 | int npars) |
| 69 | { | 125 | { |
| 70 | - m_origin = origin; | 126 | + // Set method name |
| 127 | + m_origin = origin; | ||
| 128 | + | ||
| 129 | + // Set error message | ||
| 71 | m_message = "Gradient vector size "+str(nsize)+ | 130 | m_message = "Gradient vector size "+str(nsize)+ |
| 72 | " mismatches number "+str(npars)+" of model parameters."; | 131 | " mismatches number "+str(npars)+" of model parameters."; |
| 132 | + | ||
| 133 | + // Return | ||
| 134 | + return; | ||
| 73 | } | 135 | } |
| 74 | 136 | ||
| 75 | 137 | ||
| 76 | /***********************************************************************//** | 138 | /***********************************************************************//** |
| 77 | - * @brief Calibration database directory not found. | 139 | + * @brief Calibration database directory not found |
| 78 | * | 140 | * |
| 79 | * @param[in] origin Name of method that has thrown the exception. | 141 | * @param[in] origin Name of method that has thrown the exception. |
| 80 | * @param[in] caldb Name of calibration database. | 142 | * @param[in] caldb Name of calibration database. |
| @@ -84,8 +146,15 @@ GException::caldb_not_found::caldb_not_found(std::string origin, | @@ -84,8 +146,15 @@ GException::caldb_not_found::caldb_not_found(std::string origin, | ||
| 84 | std::string caldb, | 146 | std::string caldb, |
| 85 | std::string message) | 147 | std::string message) |
| 86 | { | 148 | { |
| 87 | - m_origin = origin; | ||
| 88 | - m_message = "Calibration database \""+caldb+"\" not found. "+message; | 149 | + // Set method name |
| 150 | + m_origin = origin; | ||
| 151 | + | ||
| 152 | + // Set error message | ||
| 153 | + m_message = "Calibration database \""+caldb+"\" not found."; | ||
| 154 | + if (message.length() > 0) | ||
| 155 | + m_message += " " + message; | ||
| 156 | + | ||
| 157 | + // Return | ||
| 89 | return; | 158 | return; |
| 90 | } | 159 | } |
| 91 | 160 | ||
| @@ -99,13 +168,19 @@ GException::caldb_not_found::caldb_not_found(std::string origin, | @@ -99,13 +168,19 @@ GException::caldb_not_found::caldb_not_found(std::string origin, | ||
| 99 | GException::rsp_invalid_type::rsp_invalid_type(std::string origin, | 168 | GException::rsp_invalid_type::rsp_invalid_type(std::string origin, |
| 100 | std::string type) | 169 | std::string type) |
| 101 | { | 170 | { |
| 102 | - m_origin = origin; | ||
| 103 | - m_message = "Invalid response type '"+type+"' specified."; | 171 | + // Set method name |
| 172 | + m_origin = origin; | ||
| 173 | + | ||
| 174 | + // Set error message | ||
| 175 | + m_message = "Invalid response type \""+type+"\" specified."; | ||
| 176 | + | ||
| 177 | + // Return | ||
| 178 | + return; | ||
| 104 | } | 179 | } |
| 105 | 180 | ||
| 106 | 181 | ||
| 107 | /***********************************************************************//** | 182 | /***********************************************************************//** |
| 108 | - * @brief Good Time Intervals are not valid. | 183 | + * @brief Invalid Good Time Interval found |
| 109 | * | 184 | * |
| 110 | * @param[in] origin Method that throws the error. | 185 | * @param[in] origin Method that throws the error. |
| 111 | * @param[in] start Good Time Interval start time. | 186 | * @param[in] start Good Time Interval start time. |
| @@ -115,18 +190,22 @@ GException::rsp_invalid_type::rsp_invalid_type(std::string origin, | @@ -115,18 +190,22 @@ GException::rsp_invalid_type::rsp_invalid_type(std::string origin, | ||
| 115 | GException::gti_invalid::gti_invalid(std::string origin, GTime tstart, | 190 | GException::gti_invalid::gti_invalid(std::string origin, GTime tstart, |
| 116 | GTime tstop, std::string message) | 191 | GTime tstop, std::string message) |
| 117 | { | 192 | { |
| 118 | - std::ostringstream s_tstart; | ||
| 119 | - std::ostringstream s_tstop; | ||
| 120 | - s_tstart << tstart; | ||
| 121 | - s_tstop << tstop; | ||
| 122 | - m_origin = origin; | ||
| 123 | - m_message = "Invalid Good Time Interval ("+s_tstart.str()+"-"+ | ||
| 124 | - s_tstop.str()+") specified. "+message; | 193 | + // Set method name |
| 194 | + m_origin = origin; | ||
| 195 | + | ||
| 196 | + // Set error message | ||
| 197 | + m_message = "Invalid Good Time Interval (" + tstart.print() + "-" + | ||
| 198 | + tstop.print() + ") specified."; | ||
| 199 | + if (message.length() > 0) | ||
| 200 | + m_message += " " + message; | ||
| 201 | + | ||
| 202 | + // Return | ||
| 203 | + return; | ||
| 125 | } | 204 | } |
| 126 | 205 | ||
| 127 | 206 | ||
| 128 | /***********************************************************************//** | 207 | /***********************************************************************//** |
| 129 | - * @brief Energy range is not valid. | 208 | + * @brief Invalid energy range found |
| 130 | * | 209 | * |
| 131 | * @param[in] origin Method that throws the error. | 210 | * @param[in] origin Method that throws the error. |
| 132 | * @param[in] emin Minimum energy in MeV. | 211 | * @param[in] emin Minimum energy in MeV. |
| @@ -136,9 +215,17 @@ GException::gti_invalid::gti_invalid(std::string origin, GTime tstart, | @@ -136,9 +215,17 @@ GException::gti_invalid::gti_invalid(std::string origin, GTime tstart, | ||
| 136 | GException::erange_invalid::erange_invalid(std::string origin, double emin, | 215 | GException::erange_invalid::erange_invalid(std::string origin, double emin, |
| 137 | double emax, std::string message) | 216 | double emax, std::string message) |
| 138 | { | 217 | { |
| 139 | - m_origin = origin; | 218 | + // Set method name |
| 219 | + m_origin = origin; | ||
| 220 | + | ||
| 221 | + // Set error message | ||
| 140 | m_message = "Invalid energy range (Emin="+str(emin)+" MeV, Emax="+ | 222 | m_message = "Invalid energy range (Emin="+str(emin)+" MeV, Emax="+ |
| 141 | - str(emax)+" MeV. "+message; | 223 | + str(emax)+" MeV specified."; |
| 224 | + if (message.length() > 0) | ||
| 225 | + m_message += " " + message; | ||
| 226 | + | ||
| 227 | + // Return | ||
| 228 | + return; | ||
| 142 | } | 229 | } |
| 143 | 230 | ||
| 144 | 231 | ||
| @@ -153,7 +240,15 @@ GException::invalid_statistics::invalid_statistics(std::string origin, | @@ -153,7 +240,15 @@ GException::invalid_statistics::invalid_statistics(std::string origin, | ||
| 153 | std::string statistics, | 240 | std::string statistics, |
| 154 | std::string message) | 241 | std::string message) |
| 155 | { | 242 | { |
| 156 | - m_origin = origin; | 243 | + // Set method name |
| 244 | + m_origin = origin; | ||
| 245 | + | ||
| 246 | + // Set error message | ||
| 157 | m_message = "Invalid optimization statistics \""+statistics+ | 247 | m_message = "Invalid optimization statistics \""+statistics+ |
| 158 | - "\" encountered. "+message; | 248 | + "\" specified."; |
| 249 | + if (message.length() > 0) | ||
| 250 | + m_message += " " + message; | ||
| 251 | + | ||
| 252 | + // Return | ||
| 253 | + return; | ||
| 159 | } | 254 | } |