Commit c20468ce08351c5741831f8ef2c690e19696632e
1 parent
c34c6ce6
Replace specific by generic exceptions in model module (#35)
Showing
62 changed files
with
671 additions
and
2028 deletions
include/GException.hpp
| ... | ... | @@ -135,140 +135,10 @@ public: |
| 135 | 135 | const std::string& message = ""); |
| 136 | 136 | }; |
| 137 | 137 | |
| 138 | - // --- OLD EXCEPTIONS --- | |
| 139 | - | |
| 140 | - | |
| 141 | - | |
| 142 | - | |
| 143 | - // Invalid type conversion | |
| 144 | - class bad_type : public GExceptionHandler { | |
| 145 | - public: | |
| 146 | - bad_type(std::string origin, | |
| 147 | - std::string message = ""); | |
| 148 | - }; | |
| 149 | - | |
| 150 | - // Environment variable not found | |
| 151 | - class env_not_found : public GExceptionHandler { | |
| 152 | - public: | |
| 153 | - env_not_found(std::string origin, | |
| 154 | - std::string envname, | |
| 155 | - std::string message = ""); | |
| 156 | - }; | |
| 157 | - | |
| 158 | - // Memory allocation exception class | |
| 159 | - class mem_alloc : public GExceptionHandler { | |
| 160 | - public: | |
| 161 | - mem_alloc(std::string origin, unsigned num); | |
| 162 | - }; | |
| 163 | - | |
| 164 | - // Not enough nodes | |
| 165 | - class not_enough_nodes : public GExceptionHandler { | |
| 166 | - public: | |
| 167 | - not_enough_nodes(std::string origin, int num); | |
| 168 | - }; | |
| 169 | - | |
| 170 | - // File not found | |
| 171 | - class file_not_found : public GExceptionHandler { | |
| 172 | - public: | |
| 173 | - file_not_found(std::string origin, | |
| 174 | - std::string filename, | |
| 175 | - std::string message = ""); | |
| 176 | - }; | |
| 177 | - | |
| 178 | - // File open error | |
| 179 | - class file_open_error : public GExceptionHandler { | |
| 180 | - public: | |
| 181 | - file_open_error(std::string origin, | |
| 182 | - std::string filename, | |
| 183 | - std::string message = ""); | |
| 184 | - }; | |
| 185 | - | |
| 186 | - // Directory not found | |
| 187 | - class directory_not_found : public GExceptionHandler { | |
| 188 | - public: | |
| 189 | - directory_not_found(std::string origin, | |
| 190 | - std::string dirname, | |
| 191 | - std::string message = ""); | |
| 192 | - }; | |
| 193 | - | |
| 194 | - // Directory not accessible | |
| 195 | - class directory_not_accessible : public GExceptionHandler { | |
| 196 | - public: | |
| 197 | - directory_not_accessible(std::string origin, | |
| 198 | - std::string dirname, | |
| 199 | - std::string message = ""); | |
| 200 | - }; | |
| 201 | - | |
| 202 | - // Empty object exception class | |
| 203 | - /* | |
| 204 | - class empty : public GExceptionHandler { | |
| 205 | - public: | |
| 206 | - empty(std::string origin); | |
| 207 | - }; | |
| 208 | - | |
| 209 | - // Vector - Vector mismatch | |
| 210 | - class vector_mismatch : public GExceptionHandler { | |
| 211 | - public: | |
| 212 | - vector_mismatch(std::string origin, int size1, int size2); | |
| 213 | - }; | |
| 214 | - | |
| 215 | - // Cross product only defined for 3-element vectors | |
| 216 | - class vector_bad_cross_dim : public GExceptionHandler { | |
| 217 | - public: | |
| 218 | - vector_bad_cross_dim(std::string origin, int elements); | |
| 219 | - }; | |
| 220 | - | |
| 221 | - // Vector - Matrix mismatch | |
| 222 | - class matrix_vector_mismatch : public GExceptionHandler { | |
| 223 | - public: | |
| 224 | - matrix_vector_mismatch(std::string origin, int num, int rows, int cols); | |
| 225 | - }; | |
| 226 | - | |
| 227 | - // Matrix dimensions mismatch | |
| 228 | - class matrix_mismatch : public GExceptionHandler { | |
| 229 | - public: | |
| 230 | - matrix_mismatch(std::string origin, int rows1, int cols1, int rows2, | |
| 231 | - int cols2); | |
| 232 | - }; | |
| 233 | - | |
| 234 | - // Matrix not square | |
| 235 | - class matrix_not_square : public GExceptionHandler { | |
| 236 | - public: | |
| 237 | - matrix_not_square(std::string origin, int rows, int cols); | |
| 238 | - }; | |
| 239 | - | |
| 240 | - // Matrix not positive definite | |
| 241 | - class matrix_not_pos_definite : public GExceptionHandler { | |
| 242 | - public: | |
| 243 | - matrix_not_pos_definite(std::string origin, int row, double sum); | |
| 244 | - }; | |
| 245 | 138 | |
| 246 | - // Matrix not symmetric | |
| 247 | - class matrix_not_symmetric : public GExceptionHandler { | |
| 248 | - public: | |
| 249 | - matrix_not_symmetric(std::string origin, int cols, int rows); | |
| 250 | - }; | |
| 251 | 139 | |
| 252 | - // Matrix not factorised | |
| 253 | - class matrix_not_factorised : public GExceptionHandler { | |
| 254 | - public: | |
| 255 | - matrix_not_factorised(std::string origin, std::string type); | |
| 256 | - }; | |
| 257 | - | |
| 258 | - // All matrix elements are zero | |
| 259 | - class matrix_zero : public GExceptionHandler { | |
| 260 | - public: | |
| 261 | - matrix_zero(std::string origin); | |
| 262 | - }; | |
| 263 | - | |
| 264 | - // Invalid ordering scheme | |
| 265 | - class invalid_order : public GExceptionHandler { | |
| 266 | - public: | |
| 267 | - invalid_order(std::string origin, int order, int min_order, | |
| 268 | - int max_order); | |
| 269 | - }; | |
| 270 | - */ | |
| 271 | 140 | |
| 141 | + // --- OLD EXCEPTIONS --- | |
| 272 | 142 | |
| 273 | 143 | // GSkyMap exceptions |
| 274 | 144 | class skymap : public GExceptionHandler { |
| ... | ... | @@ -439,96 +309,6 @@ public: |
| 439 | 309 | std::string message = ""); |
| 440 | 310 | }; |
| 441 | 311 | |
| 442 | - | |
| 443 | - // Model exceptions | |
| 444 | - class model_invalid : public GExceptionHandler { | |
| 445 | - public: | |
| 446 | - model_invalid(std::string origin, std::string type, | |
| 447 | - std::string message = ""); | |
| 448 | - }; | |
| 449 | - class model_invalid_spatial : public GExceptionHandler { | |
| 450 | - public: | |
| 451 | - model_invalid_spatial(std::string origin, std::string type, | |
| 452 | - std::string message = ""); | |
| 453 | - }; | |
| 454 | - class model_invalid_spectral : public GExceptionHandler { | |
| 455 | - public: | |
| 456 | - model_invalid_spectral(std::string origin, std::string type, | |
| 457 | - std::string message = ""); | |
| 458 | - }; | |
| 459 | - class model_invalid_temporal : public GExceptionHandler { | |
| 460 | - public: | |
| 461 | - model_invalid_temporal(std::string origin, std::string type, | |
| 462 | - std::string message = ""); | |
| 463 | - }; | |
| 464 | - class model_invalid_parnum : public GExceptionHandler { | |
| 465 | - public: | |
| 466 | - model_invalid_parnum(std::string origin, GXmlElement xml, | |
| 467 | - std::string message = ""); | |
| 468 | - }; | |
| 469 | - class model_invalid_nodenum : public GExceptionHandler { | |
| 470 | - public: | |
| 471 | - model_invalid_nodenum(std::string origin, GXmlElement xml, | |
| 472 | - std::string message = ""); | |
| 473 | - }; | |
| 474 | - class model_invalid_parnames : public GExceptionHandler { | |
| 475 | - public: | |
| 476 | - model_invalid_parnames(std::string origin, GXmlElement xml, | |
| 477 | - std::string message = ""); | |
| 478 | - }; | |
| 479 | - class model_invalid_parvalue : public GExceptionHandler { | |
| 480 | - public: | |
| 481 | - model_invalid_parvalue(std::string origin, GXmlElement xml, | |
| 482 | - std::string message = ""); | |
| 483 | - }; | |
| 484 | - class model_invalid_parlimit : public GExceptionHandler { | |
| 485 | - public: | |
| 486 | - model_invalid_parlimit(std::string origin, GXmlElement xml, | |
| 487 | - std::string message = ""); | |
| 488 | - }; | |
| 489 | - class model_invalid_parscale : public GExceptionHandler { | |
| 490 | - public: | |
| 491 | - model_invalid_parscale(std::string origin, double scale, | |
| 492 | - std::string message = ""); | |
| 493 | - model_invalid_parscale(std::string origin, GXmlElement xml, | |
| 494 | - std::string message = ""); | |
| 495 | - }; | |
| 496 | - class file_function_data : public GExceptionHandler { | |
| 497 | - public: | |
| 498 | - file_function_data(std::string origin, std::string filename, | |
| 499 | - int num, std::string message = ""); | |
| 500 | - }; | |
| 501 | - class file_function_columns : public GExceptionHandler { | |
| 502 | - public: | |
| 503 | - file_function_columns(std::string origin, std::string filename, | |
| 504 | - int num, std::string message = ""); | |
| 505 | - }; | |
| 506 | - class file_function_value : public GExceptionHandler { | |
| 507 | - public: | |
| 508 | - file_function_value(std::string origin, std::string filename, | |
| 509 | - double value, std::string message = ""); | |
| 510 | - }; | |
| 511 | - class par_not_found : public GExceptionHandler { | |
| 512 | - public: | |
| 513 | - par_not_found(std::string origin, std::string name, | |
| 514 | - std::string message = ""); | |
| 515 | - }; | |
| 516 | - class model_not_found : public GExceptionHandler { | |
| 517 | - public: | |
| 518 | - model_not_found(std::string origin, std::string name, | |
| 519 | - std::string message = ""); | |
| 520 | - }; | |
| 521 | - class no_point_source : public GExceptionHandler { | |
| 522 | - public: | |
| 523 | - no_point_source(std::string origin, std::string name, | |
| 524 | - std::string message = ""); | |
| 525 | - }; | |
| 526 | - class no_extended_source : public GExceptionHandler { | |
| 527 | - public: | |
| 528 | - no_extended_source(std::string origin, std::string name, | |
| 529 | - std::string message = ""); | |
| 530 | - }; | |
| 531 | - | |
| 532 | 312 | // CSV exceptions |
| 533 | 313 | class csv_bad_columns : public GExceptionHandler { |
| 534 | 314 | public: | ... | ... |
include/GTools.hpp
| ... | ... | @@ -133,6 +133,12 @@ namespace gammalib { |
| 133 | 133 | const GXmlElement& xml, |
| 134 | 134 | const std::string& name, |
| 135 | 135 | const std::string& attribute); |
| 136 | + void xml_check_parnum(const std::string& origin, | |
| 137 | + const GXmlElement& xml, | |
| 138 | + const int& number); | |
| 139 | + void xml_check_type(const std::string& origin, | |
| 140 | + GXmlElement& xml, | |
| 141 | + const std::string& type); | |
| 136 | 142 | void xml_check_par(const std::string& origin, |
| 137 | 143 | const std::string& name, |
| 138 | 144 | const int& number); | ... | ... |
inst/cta/src/GCTABackgroundPerfTable.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTABackgroundPerfTable.cpp - CTA performance table background class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2014-2018 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2014-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -258,7 +258,10 @@ void GCTABackgroundPerfTable::load(const GFilename& filename) |
| 258 | 258 | // Open performance table readonly |
| 259 | 259 | FILE* fptr = std::fopen(filename.url().c_str(), "r"); |
| 260 | 260 | if (fptr == NULL) { |
| 261 | - throw GException::file_open_error(G_LOAD, filename.url()); | |
| 261 | + std::string msg = "Unable to open file \""+filename.url()+"\" for " | |
| 262 | + "read access. Please provide the name of a readable " | |
| 263 | + "file."; | |
| 264 | + throw GException::file_error(G_LOAD, msg); | |
| 262 | 265 | } |
| 263 | 266 | |
| 264 | 267 | // Read lines | ... | ... |
inst/cta/src/GCTAModelRadialGauss.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAModelRadialGauss.cpp - Radial Gaussian CTA model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2018 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -405,60 +405,23 @@ double GCTAModelRadialGauss::omega(void) const |
| 405 | 405 | * |
| 406 | 406 | * @param[in] xml XML element. |
| 407 | 407 | * |
| 408 | - * @exception GException::model_invalid_parnum | |
| 409 | - * Invalid number of model parameters found in XML element. | |
| 410 | - * @exception GException::model_invalid_parvalue | |
| 411 | - * Non-positive parameter value found. | |
| 412 | - * @exception GException::model_invalid_parlimit | |
| 413 | - * Missing or non-positive minimum parameter boundary. | |
| 414 | - * @exception GException::model_invalid_parnames | |
| 415 | - * Invalid model parameter names found in XML element. | |
| 408 | + * Read the Gaussian radial model information from an XML element in the | |
| 409 | + * following format | |
| 416 | 410 | * |
| 417 | - * Read the Gaussian radial model information from an XML element. The XML | |
| 418 | - * element is required to have one parameter named "Sigma". | |
| 411 | + * <radialModel type="..."> | |
| 412 | + * <parameter name="Sigma" scale="1.0" value="3.0" min="0.01" max="10.0" free="1"/> | |
| 413 | + * </radialModel> | |
| 419 | 414 | ***************************************************************************/ |
| 420 | 415 | void GCTAModelRadialGauss::read(const GXmlElement& xml) |
| 421 | 416 | { |
| 422 | 417 | // Verify that XML element has exactly 1 parameter |
| 423 | - if (xml.elements() != 1 || xml.elements("parameter") != 1) { | |
| 424 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 425 | - "Radial Gaussian model requires exactly 1 parameter."); | |
| 426 | - } | |
| 418 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 427 | 419 | |
| 428 | - // Extract model parameters | |
| 429 | - int npar[] = {0}; | |
| 430 | - for (int i = 0; i < 1; ++i) { | |
| 431 | - | |
| 432 | - // Get parameter element | |
| 433 | - const GXmlElement* par = xml.element("parameter", i); | |
| 434 | - | |
| 435 | - // Handle Sigma | |
| 436 | - if (par->attribute("name") == "Sigma") { | |
| 437 | - | |
| 438 | - // Read parameter | |
| 439 | - m_sigma.read(*par); | |
| 440 | - | |
| 441 | - // Check parameter | |
| 442 | - if (m_sigma.value() <= 0.0) { | |
| 443 | - throw GException::model_invalid_parvalue(G_READ, xml, | |
| 444 | - "\"Sigma\" parameter is required to be positive."); | |
| 445 | - } | |
| 446 | - if (!m_sigma.has_min() || m_sigma.min() <= 0.0) { | |
| 447 | - throw GException::model_invalid_parlimit(G_READ, xml, | |
| 448 | - "\"Sigma\" parameter requires positive minimum boundary."); | |
| 449 | - } | |
| 450 | - | |
| 451 | - // Increment parameter counter | |
| 452 | - npar[0]++; | |
| 453 | - } | |
| 420 | + // Get parameters | |
| 421 | + const GXmlElement* sigma = gammalib::xml_get_par(G_READ, xml, m_sigma.name()); | |
| 454 | 422 | |
| 455 | - } // endfor: looped over all parameters | |
| 456 | - | |
| 457 | - // Verify that all parameters were found | |
| 458 | - if (npar[0] != 1) { | |
| 459 | - throw GException::model_invalid_parnames(G_READ, xml, | |
| 460 | - "Radial Gaussian model requires \"Sigma\" parameter."); | |
| 461 | - } | |
| 423 | + // Read parameters | |
| 424 | + m_sigma.read(*sigma); | |
| 462 | 425 | |
| 463 | 426 | // Return |
| 464 | 427 | return; |
| ... | ... | @@ -470,60 +433,23 @@ void GCTAModelRadialGauss::read(const GXmlElement& xml) |
| 470 | 433 | * |
| 471 | 434 | * @param[in] xml XML element. |
| 472 | 435 | * |
| 473 | - * @exception GException::model_invalid_spatial | |
| 474 | - * Existing XML element is not of type 'GaussFunction' | |
| 475 | - * @exception GException::model_invalid_parnum | |
| 476 | - * Invalid number of model parameters found in XML element. | |
| 477 | - * @exception GException::model_invalid_parnames | |
| 478 | - * Invalid model parameter names found in XML element. | |
| 436 | + * Write the Gaussian radial model information into an XML element in the | |
| 437 | + * following format | |
| 479 | 438 | * |
| 480 | - * Write the Gaussian radial model information into an XML element. The XML | |
| 481 | - * element will have one parameter leaf named "Sigma". | |
| 439 | + * <radialModel type="..."> | |
| 440 | + * <parameter name="Sigma" scale="1.0" value="3.0" min="0.01" max="10.0" free="1"/> | |
| 441 | + * </radialModel> | |
| 482 | 442 | ***************************************************************************/ |
| 483 | 443 | void GCTAModelRadialGauss::write(GXmlElement& xml) const |
| 484 | 444 | { |
| 485 | - // Set model type | |
| 486 | - if (xml.attribute("type") == "") { | |
| 487 | - xml.attribute("type", type()); | |
| 488 | - } | |
| 445 | + // Check model type | |
| 446 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 489 | 447 | |
| 490 | - // Verify model type | |
| 491 | - if (xml.attribute("type") != type()) { | |
| 492 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 493 | - "Radial Gaussian model is not of type \""+type()+"\"."); | |
| 494 | - } | |
| 495 | - | |
| 496 | - // If XML element has 0 nodes then append 1 parameter node | |
| 497 | - if (xml.elements() == 0) { | |
| 498 | - xml.append(GXmlElement("parameter name=\"Sigma\"")); | |
| 499 | - } | |
| 448 | + // Get or create parameter | |
| 449 | + GXmlElement* sigma = gammalib::xml_need_par(G_WRITE, xml, m_sigma.name()); | |
| 500 | 450 | |
| 501 | - // Verify that XML element has exactly 1 parameter | |
| 502 | - if (xml.elements() != 1 || xml.elements("parameter") != 1) { | |
| 503 | - throw GException::model_invalid_parnum(G_WRITE, xml, | |
| 504 | - "Radial Gaussian model requires exactly 1 parameter."); | |
| 505 | - } | |
| 506 | - | |
| 507 | - // Set or update model parameter attributes | |
| 508 | - int npar[] = {0}; | |
| 509 | - for (int i = 0; i < 1; ++i) { | |
| 510 | - | |
| 511 | - // Get parameter element | |
| 512 | - GXmlElement* par = xml.element("parameter", i); | |
| 513 | - | |
| 514 | - // Handle sigma | |
| 515 | - if (par->attribute("name") == "Sigma") { | |
| 516 | - m_sigma.write(*par); | |
| 517 | - npar[0]++; | |
| 518 | - } | |
| 519 | - | |
| 520 | - } // endfor: looped over all parameters | |
| 521 | - | |
| 522 | - // Check of all required parameters are present | |
| 523 | - if (npar[0] != 1) { | |
| 524 | - throw GException::model_invalid_parnames(G_WRITE, xml, | |
| 525 | - "Radial Gaussian model requires \"Sigma\" parameter."); | |
| 526 | - } | |
| 451 | + // Write parameter | |
| 452 | + m_sigma.write(*sigma); | |
| 527 | 453 | |
| 528 | 454 | // Return |
| 529 | 455 | return; | ... | ... |
inst/cta/src/GCTAModelRadialPolynom.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAModelRadialPolynom.cpp - Radial Polynom CTA model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2018 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -469,14 +469,18 @@ double GCTAModelRadialPolynom::omega(void) const |
| 469 | 469 | * |
| 470 | 470 | * @param[in] xml XML element. |
| 471 | 471 | * |
| 472 | - * @exception GException::model_invalid_parnum | |
| 473 | - * Invalid number of model parameters found in XML element. | |
| 474 | - * @exception GException::model_invalid_parnames | |
| 475 | - * Invalid model parameter names found in XML element. | |
| 472 | + * @exception GException::invalid_value | |
| 473 | + * Invalid XML format encountered. | |
| 476 | 474 | * |
| 477 | - * Read the radial Polynom model information from an XML element. The XML | |
| 478 | - * element is required to have at least one parameter. Parameters are named | |
| 479 | - * "CoeffX", where "X" starts from "0". | |
| 475 | + * Read the radial Polynom model information from an XML element in the | |
| 476 | + * following format | |
| 477 | + * | |
| 478 | + * <radialModel type="..."> | |
| 479 | + * <parameter name="Coeff0" scale="1.0" value="1.5" min="0.1" max="10.0" free="1"/> | |
| 480 | + * <parameter name="Coeff1" scale="1.0" value="3.0" min="1.0" max="10.0" free="1"/> | |
| 481 | + * <parameter name="Coeff2" scale="1.0" value="5.0" min="1.0" max="10.0" free="1"/> | |
| 482 | + * ... | |
| 483 | + * </radialModel> | |
| 480 | 484 | * |
| 481 | 485 | * @todo Implement a test of the coefficient boundaries. |
| 482 | 486 | ***************************************************************************/ |
| ... | ... | @@ -490,9 +494,9 @@ void GCTAModelRadialPolynom::read(const GXmlElement& xml) |
| 490 | 494 | |
| 491 | 495 | // Throw an error if no parameters were found |
| 492 | 496 | if (max_coeffs < 1) { |
| 493 | - std::string message = "Radial polynomial model requires at least" | |
| 494 | - " one coefficient."; | |
| 495 | - throw GException::model_invalid_parnum(G_READ, xml, message); | |
| 497 | + std::string msg = "Radial polynomial model requires at least one " | |
| 498 | + "coefficient. Please verify the XML format."; | |
| 499 | + throw GException::invalid_value(G_READ, msg); | |
| 496 | 500 | } |
| 497 | 501 | |
| 498 | 502 | // Verify XML file consistency and determine number of coefficients |
| ... | ... | @@ -506,8 +510,10 @@ void GCTAModelRadialPolynom::read(const GXmlElement& xml) |
| 506 | 510 | |
| 507 | 511 | // Verify that parameter is indeed a coefficient |
| 508 | 512 | if (par->attribute("name").compare(0,5,"Coeff") != 0) { |
| 509 | - throw GException::model_invalid_parnames(G_READ, xml, | |
| 510 | - par->attribute("name")); | |
| 513 | + std::string msg = "Invalid parameter \""+par->attribute("name")+ | |
| 514 | + "\" encountered. Parameter name needs to start " | |
| 515 | + "with \"Coeff\". Please verify the XML format."; | |
| 516 | + throw GException::invalid_value(G_READ, msg); | |
| 511 | 517 | } |
| 512 | 518 | |
| 513 | 519 | // Verify that parameter coefficient has index in valid range |
| ... | ... | @@ -517,20 +523,24 @@ void GCTAModelRadialPolynom::read(const GXmlElement& xml) |
| 517 | 523 | index = gammalib::toint(par->attribute("name").substr(5, nchars)); |
| 518 | 524 | } |
| 519 | 525 | else { |
| 520 | - throw GException::model_invalid_parnames(G_READ, xml, | |
| 521 | - "Radial polynomial \"Coeff\" parameter has no index."); | |
| 526 | + std::string msg = "Radial polynomial \"Coeff\" parameter has no " | |
| 527 | + "index. Please verify the XML format."; | |
| 528 | + throw GException::invalid_value(G_READ, msg); | |
| 522 | 529 | } |
| 523 | 530 | if (index < 0) { |
| 524 | - throw GException::model_invalid_parnames(G_READ, xml, | |
| 525 | - "Radial polynomial \"Coeff\" parameter index < 0."); | |
| 531 | + std::string msg = "Radial polynomial \"Coeff\" parameter has " | |
| 532 | + "negative index "+gammalib::str(index)+". Please " | |
| 533 | + "verify the XML format."; | |
| 534 | + throw GException::invalid_value(G_READ, msg); | |
| 526 | 535 | } |
| 527 | 536 | if (index >= max_coeffs) { |
| 528 | - std::string message = "There are "+gammalib::str(max_coeffs)+" parameters," | |
| 529 | - " hence polynomial coefficients are expected" | |
| 530 | - " to run from 0 to "+gammalib::str(max_coeffs-1)+", yet" | |
| 531 | - " a coefficient with index "+gammalib::str(index)+" was" | |
| 532 | - " encountered."; | |
| 533 | - throw GException::model_invalid_parnames(G_READ, xml, message); | |
| 537 | + std::string msg = "There are "+gammalib::str(max_coeffs)+ | |
| 538 | + " parameters, hence polynomial coefficients are " | |
| 539 | + "expected to run from 0 to "+ | |
| 540 | + gammalib::str(max_coeffs-1)+", yet a coefficient " | |
| 541 | + "with index "+gammalib::str(index)+" was " | |
| 542 | + "encountered. Please verify the XML format."; | |
| 543 | + throw GException::invalid_value(G_READ, msg); | |
| 534 | 544 | } |
| 535 | 545 | |
| 536 | 546 | // Increment parameter counter |
| ... | ... | @@ -545,22 +555,25 @@ void GCTAModelRadialPolynom::read(const GXmlElement& xml) |
| 545 | 555 | |
| 546 | 556 | // Verify that the number of coefficients is between 1 and max_coeffs |
| 547 | 557 | if (ncoeffs < 0 || ncoeffs > max_coeffs) { |
| 548 | - std::string message = "Radial polynomial model requires at between" | |
| 549 | - " 1 and "+gammalib::str(max_coeffs)+" parameters."; | |
| 550 | - throw GException::model_invalid_parnum(G_READ, xml, message); | |
| 558 | + std::string msg = "Radial polynomial model requires between 1 and "+ | |
| 559 | + gammalib::str(max_coeffs)+" parameters. Please " | |
| 560 | + "verify the XML format."; | |
| 561 | + throw GException::invalid_value(G_READ, msg); | |
| 551 | 562 | } |
| 552 | 563 | |
| 553 | 564 | // Verify that all parameters were found |
| 554 | 565 | for (int i = 0; i < ncoeffs; ++i) { |
| 555 | 566 | if (npar[i] == 0) { |
| 556 | - std::string message = "Parameter \"Coeff"+gammalib::str(i)+"\" required," | |
| 557 | - " but not found in XML file."; | |
| 558 | - throw GException::model_invalid_parnames(G_READ, xml, message); | |
| 567 | + std::string msg = "Parameter \"Coeff"+gammalib::str(i)+ | |
| 568 | + "\" not found in XML file. Please verify the " | |
| 569 | + "XML format."; | |
| 570 | + throw GException::invalid_value(G_READ, msg); | |
| 559 | 571 | } |
| 560 | 572 | else if (npar[i] > 1) { |
| 561 | - std::string message = "Multiple parameters \"Coeff"+gammalib::str(i)+"\"" | |
| 562 | - " found in XML file."; | |
| 563 | - throw GException::model_invalid_parnames(G_READ, xml, message); | |
| 573 | + std::string msg = "Multiple parameters \"Coeff"+gammalib::str(i)+ | |
| 574 | + "\" found in XML file. Please verify the XML " | |
| 575 | + "format."; | |
| 576 | + throw GException::invalid_value(G_READ, msg); | |
| 564 | 577 | } |
| 565 | 578 | } |
| 566 | 579 | |
| ... | ... | @@ -583,8 +596,9 @@ void GCTAModelRadialPolynom::read(const GXmlElement& xml) |
| 583 | 596 | // Make sure that we really have one (just a double check, this should |
| 584 | 597 | // never fail) |
| 585 | 598 | if (par == NULL) { |
| 586 | - std::string message = "Required parameter \""+name+"\" not found."; | |
| 587 | - throw GException::model_invalid_parnames(G_READ, xml, message); | |
| 599 | + std::string msg = "Required parameter \""+name+"\" not found. " | |
| 600 | + "Please verify the XML format."; | |
| 601 | + throw GException::invalid_value(G_READ, msg); | |
| 588 | 602 | } |
| 589 | 603 | |
| 590 | 604 | // Now read that parameter ... |
| ... | ... | @@ -615,90 +629,38 @@ void GCTAModelRadialPolynom::read(const GXmlElement& xml) |
| 615 | 629 | * |
| 616 | 630 | * @param[in] xml XML element. |
| 617 | 631 | * |
| 618 | - * @exception GException::model_invalid_spatial | |
| 619 | - * Existing XML element is not of type 'Polynom' | |
| 620 | - * @exception GException::model_invalid_parnum | |
| 621 | - * Invalid number of model parameters found in XML element. | |
| 622 | - * @exception GException::model_invalid_parnames | |
| 623 | - * Invalid model parameter names found in XML element. | |
| 632 | + * Write the polynomial radial model information into an XML element in the | |
| 633 | + * following format | |
| 624 | 634 | * |
| 625 | - * Write the polynomial radial model information into an XML element. The XML | |
| 626 | - * element will have 1-10 parameter leafs named "CoeffX", where X runs from | |
| 627 | - * 0 to 9. | |
| 635 | + * <radialModel type="..."> | |
| 636 | + * <parameter name="Coeff0" scale="1.0" value="1.5" min="0.1" max="10.0" free="1"/> | |
| 637 | + * <parameter name="Coeff1" scale="1.0" value="3.0" min="1.0" max="10.0" free="1"/> | |
| 638 | + * <parameter name="Coeff2" scale="1.0" value="5.0" min="1.0" max="10.0" free="1"/> | |
| 639 | + * ... | |
| 640 | + * </radialModel> | |
| 628 | 641 | ***************************************************************************/ |
| 629 | 642 | void GCTAModelRadialPolynom::write(GXmlElement& xml) const |
| 630 | 643 | { |
| 631 | 644 | // Determine number of coefficients |
| 632 | 645 | int ncoeffs = m_coeffs.size(); |
| 633 | 646 | |
| 634 | - // Set model type | |
| 635 | - if (xml.attribute("type") == "") { | |
| 636 | - xml.attribute("type", type()); | |
| 637 | - } | |
| 638 | - | |
| 639 | - // Verify model type | |
| 640 | - if (xml.attribute("type") != type()) { | |
| 641 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 642 | - "Radial polynomial model is not of type \""+type()+"\"."); | |
| 643 | - } | |
| 644 | - | |
| 645 | - // If XML element has 0 nodes then append nodes for coefficients | |
| 646 | - if (xml.elements() == 0) { | |
| 647 | - for (int i = 0; i < ncoeffs; ++i) { | |
| 648 | - std::string name = "parameter name=\"Coeff"+gammalib::str(i)+"\""; | |
| 649 | - xml.append(GXmlElement(name)); | |
| 650 | - } | |
| 651 | - } | |
| 647 | + // Check model type | |
| 648 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 652 | 649 | |
| 653 | - // Verify that XML element has one parameter per coefficient | |
| 654 | - if (xml.elements() != ncoeffs || xml.elements("parameter") != ncoeffs) { | |
| 655 | - std::string message = "Radial polynomial model requires exactly " + | |
| 656 | - gammalib::str(ncoeffs) + " parameters."; | |
| 657 | - throw GException::model_invalid_parnum(G_WRITE, xml, message); | |
| 658 | - } | |
| 659 | - | |
| 660 | - // Set or update model parameter attributes | |
| 661 | - std::vector<int> npar; | |
| 662 | - npar.assign(ncoeffs, 0); | |
| 650 | + // Write model parameters | |
| 663 | 651 | for (int i = 0; i < ncoeffs; ++i) { |
| 664 | 652 | |
| 665 | 653 | // Set parameter name |
| 666 | 654 | std::string name = "Coeff"+gammalib::str(i); |
| 667 | 655 | |
| 668 | - // Get corresponding parameter element | |
| 669 | - GXmlElement* par = NULL; | |
| 670 | - for (int k = 0; k < ncoeffs; ++k) { | |
| 671 | - GXmlElement* element = xml.element("parameter", k); | |
| 672 | - if (element->attribute("name") == name) { | |
| 673 | - par = element; | |
| 674 | - break; | |
| 675 | - } | |
| 676 | - } | |
| 677 | - | |
| 678 | - // Make sure that we really have one (just a double check, this should | |
| 679 | - // never fail) | |
| 680 | - if (par == NULL) { | |
| 681 | - std::string message = "Required parameter \""+name+"\" not found."; | |
| 682 | - throw GException::model_invalid_parnames(G_WRITE, xml, message); | |
| 683 | - } | |
| 656 | + // Get or create parameter | |
| 657 | + GXmlElement* coeff = gammalib::xml_need_par(G_WRITE, xml, name); | |
| 684 | 658 | |
| 685 | 659 | // Write parameter |
| 686 | - m_coeffs[i].write(*par); | |
| 687 | - | |
| 688 | - // Increment parameter counter | |
| 689 | - npar[i]++; | |
| 660 | + m_coeffs[i].write(*coeff); | |
| 690 | 661 | |
| 691 | 662 | } // endfor: looped over all parameters |
| 692 | 663 | |
| 693 | - // Verify that all parameters were present | |
| 694 | - for (int i = 0; i < ncoeffs; ++i) { | |
| 695 | - if (npar[i] != 1) { | |
| 696 | - std::string message = "Parameter \"Coeff"+gammalib::str(i)+"\" required," | |
| 697 | - " but not found in XML file."; | |
| 698 | - throw GException::model_invalid_parnames(G_WRITE, xml, message); | |
| 699 | - } | |
| 700 | - } | |
| 701 | - | |
| 702 | 664 | // Return |
| 703 | 665 | return; |
| 704 | 666 | } | ... | ... |
inst/cta/src/GCTAModelRadialProfile.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAModelRadialProfile.cpp - Radial Profile CTA model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2018 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -409,82 +409,29 @@ double GCTAModelRadialProfile::omega(void) const |
| 409 | 409 | * |
| 410 | 410 | * @param[in] xml XML element. |
| 411 | 411 | * |
| 412 | - * @exception GException::model_invalid_parnum | |
| 413 | - * Invalid number of model parameters found in XML element. | |
| 414 | - * @exception GException::model_invalid_parvalue | |
| 415 | - * Non-positive parameter value found. | |
| 416 | - * @exception GException::model_invalid_parlimit | |
| 417 | - * Missing or non-positive minimum parameter boundary. | |
| 418 | - * @exception GException::model_invalid_parnames | |
| 419 | - * Invalid model parameter names found in XML element. | |
| 412 | + * Read the Profile radial model information from an XML element in the | |
| 413 | + * following format | |
| 420 | 414 | * |
| 421 | - * Read the Profile radial model information from an XML element. The XML | |
| 422 | - * element is required to have 3 parameter named "Width", "Core", and "Tail". | |
| 415 | + * <radialModel type="..."> | |
| 416 | + * <parameter name="Width" scale="1.0" value="1.5" min="0.1" max="10.0" free="1"/> | |
| 417 | + * <parameter name="Core" scale="1.0" value="3.0" min="1.0" max="10.0" free="1"/> | |
| 418 | + * <parameter name="Tail" scale="1.0" value="5.0" min="1.0" max="10.0" free="1"/> | |
| 419 | + * </radialModel> | |
| 423 | 420 | ***************************************************************************/ |
| 424 | 421 | void GCTAModelRadialProfile::read(const GXmlElement& xml) |
| 425 | 422 | { |
| 426 | - // Verify that XML element has exactly 3 parameter | |
| 427 | - if (xml.elements() != 3 || xml.elements("parameter") != 3) { | |
| 428 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 429 | - "Radial Profile model requires exactly 3 parameters."); | |
| 430 | - } | |
| 431 | - | |
| 432 | - // Extract model parameters | |
| 433 | - int npar[] = {0, 0, 0}; | |
| 434 | - for (int i = 0; i < 3; ++i) { | |
| 435 | - | |
| 436 | - // Get parameter element | |
| 437 | - const GXmlElement* par = xml.element("parameter", i); | |
| 438 | - | |
| 439 | - // Handle Width | |
| 440 | - if (par->attribute("name") == "Width") { | |
| 441 | - m_width.read(*par); | |
| 442 | - if (m_width.value() <= 0.0) { | |
| 443 | - throw GException::model_invalid_parvalue(G_READ, xml, | |
| 444 | - "\"Width\" parameter is required to be positive."); | |
| 445 | - } | |
| 446 | - if (!m_width.has_min() || m_width.min() <= 0.0) { | |
| 447 | - throw GException::model_invalid_parlimit(G_READ, xml, | |
| 448 | - "\"Width\" parameter requires positive minimum boundary."); | |
| 449 | - } | |
| 450 | - npar[0]++; | |
| 451 | - } | |
| 452 | - | |
| 453 | - // Handle Core | |
| 454 | - if (par->attribute("name") == "Core") { | |
| 455 | - m_core.read(*par); | |
| 456 | - if (m_core.value() <= 0.0) { | |
| 457 | - throw GException::model_invalid_parvalue(G_READ, xml, | |
| 458 | - "\"Core\" parameter is required to be positive."); | |
| 459 | - } | |
| 460 | - if (!m_core.has_min() || m_core.min() <= 0.0) { | |
| 461 | - throw GException::model_invalid_parlimit(G_READ, xml, | |
| 462 | - "\"Core\" parameter requires positive minimum boundary."); | |
| 463 | - } | |
| 464 | - npar[1]++; | |
| 465 | - } | |
| 466 | - | |
| 467 | - // Handle Tail | |
| 468 | - if (par->attribute("name") == "Tail") { | |
| 469 | - m_tail.read(*par); | |
| 470 | - if (m_tail.value() <= 0.0) { | |
| 471 | - throw GException::model_invalid_parvalue(G_READ, xml, | |
| 472 | - "\"Tail\" parameter is required to be positive."); | |
| 473 | - } | |
| 474 | - if (!m_tail.has_min() || m_tail.min() <= 0.0) { | |
| 475 | - throw GException::model_invalid_parlimit(G_READ, xml, | |
| 476 | - "\"Tail\" parameter requires positive minimum boundary."); | |
| 477 | - } | |
| 478 | - npar[2]++; | |
| 479 | - } | |
| 423 | + // Verify that XML element has exactly 3 parameters | |
| 424 | + gammalib::xml_check_parnum(G_READ, xml, 3); | |
| 480 | 425 | |
| 481 | - } // endfor: looped over all parameters | |
| 426 | + // Get parameters | |
| 427 | + const GXmlElement* width = gammalib::xml_get_par(G_READ, xml, m_width.name()); | |
| 428 | + const GXmlElement* core = gammalib::xml_get_par(G_READ, xml, m_core.name()); | |
| 429 | + const GXmlElement* tail = gammalib::xml_get_par(G_READ, xml, m_tail.name()); | |
| 482 | 430 | |
| 483 | - // Verify that all parameters were found | |
| 484 | - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1) { | |
| 485 | - throw GException::model_invalid_parnames(G_READ, xml, | |
| 486 | - "Require \"Width\", \"Core\" and \"Tail\" parameters."); | |
| 487 | - } | |
| 431 | + // Read parameters | |
| 432 | + m_width.read(*width); | |
| 433 | + m_core.read(*core); | |
| 434 | + m_tail.read(*tail); | |
| 488 | 435 | |
| 489 | 436 | // Return |
| 490 | 437 | return; |
| ... | ... | @@ -496,74 +443,29 @@ void GCTAModelRadialProfile::read(const GXmlElement& xml) |
| 496 | 443 | * |
| 497 | 444 | * @param[in] xml XML element. |
| 498 | 445 | * |
| 499 | - * @exception GException::model_invalid_spatial | |
| 500 | - * Existing XML element is not of type 'ProfileFunction' | |
| 501 | - * @exception GException::model_invalid_parnum | |
| 502 | - * Invalid number of model parameters found in XML element. | |
| 503 | - * @exception GException::model_invalid_parnames | |
| 504 | - * Invalid model parameter names found in XML element. | |
| 446 | + * Write the radial Profile model information into an XML element in the | |
| 447 | + * following format | |
| 505 | 448 | * |
| 506 | - * Write the radial Profile model information into an XML element. The XML | |
| 507 | - * element will have 3 parameter leafs named "Width", "Core" and "Tail". | |
| 449 | + * <radialModel type="..."> | |
| 450 | + * <parameter name="Width" scale="1.0" value="1.5" min="0.1" max="10.0" free="1"/> | |
| 451 | + * <parameter name="Core" scale="1.0" value="3.0" min="1.0" max="10.0" free="1"/> | |
| 452 | + * <parameter name="Tail" scale="1.0" value="5.0" min="1.0" max="10.0" free="1"/> | |
| 453 | + * </radialModel> | |
| 508 | 454 | ***************************************************************************/ |
| 509 | 455 | void GCTAModelRadialProfile::write(GXmlElement& xml) const |
| 510 | 456 | { |
| 511 | - // Set model type | |
| 512 | - if (xml.attribute("type") == "") { | |
| 513 | - xml.attribute("type", type()); | |
| 514 | - } | |
| 515 | - | |
| 516 | - // Verify model type | |
| 517 | - if (xml.attribute("type") != type()) { | |
| 518 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 519 | - "Radial Profile model is not of type \""+type()+"\"."); | |
| 520 | - } | |
| 521 | - | |
| 522 | - // If XML element has 0 nodes then append 3 parameter nodes | |
| 523 | - if (xml.elements() == 0) { | |
| 524 | - xml.append(GXmlElement("parameter name=\"Width\"")); | |
| 525 | - xml.append(GXmlElement("parameter name=\"Core\"")); | |
| 526 | - xml.append(GXmlElement("parameter name=\"Tail\"")); | |
| 527 | - } | |
| 528 | - | |
| 529 | - // Verify that XML element has exactly 3 parameters | |
| 530 | - if (xml.elements() != 3 || xml.elements("parameter") != 3) { | |
| 531 | - throw GException::model_invalid_parnum(G_WRITE, xml, | |
| 532 | - "Radial Profile model requires exactly 3 parameters."); | |
| 533 | - } | |
| 457 | + // Check model type | |
| 458 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 534 | 459 | |
| 535 | - // Set or update model parameter attributes | |
| 536 | - int npar[] = {0, 0, 0}; | |
| 537 | - for (int i = 0; i < 3; ++i) { | |
| 538 | - | |
| 539 | - // Get parameter element | |
| 540 | - GXmlElement* par = xml.element("parameter", i); | |
| 541 | - | |
| 542 | - // Handle prefactor | |
| 543 | - if (par->attribute("name") == "Width") { | |
| 544 | - m_width.write(*par); | |
| 545 | - npar[0]++; | |
| 546 | - } | |
| 460 | + // Get or create parameters | |
| 461 | + GXmlElement* width = gammalib::xml_need_par(G_WRITE, xml, m_width.name()); | |
| 462 | + GXmlElement* core = gammalib::xml_need_par(G_WRITE, xml, m_core.name()); | |
| 463 | + GXmlElement* tail = gammalib::xml_need_par(G_WRITE, xml, m_tail.name()); | |
| 547 | 464 | |
| 548 | - // Handle index | |
| 549 | - else if (par->attribute("name") == "Core") { | |
| 550 | - m_core.write(*par); | |
| 551 | - npar[1]++; | |
| 552 | - } | |
| 553 | - | |
| 554 | - // Handle pivot energy | |
| 555 | - else if (par->attribute("name") == "Tail") { | |
| 556 | - m_tail.write(*par); | |
| 557 | - npar[2]++; | |
| 558 | - } | |
| 559 | - | |
| 560 | - } // endfor: looped over all parameters | |
| 561 | - | |
| 562 | - // Check of all required parameters are present | |
| 563 | - if (npar[0] != 1 || npar[1] != 1 || npar[2] != 1) { | |
| 564 | - throw GException::model_invalid_parnames(G_WRITE, xml, | |
| 565 | - "Require \"Width\", \"Core\" and \"Tail\" parameters."); | |
| 566 | - } | |
| 465 | + // Write parameters | |
| 466 | + m_width.write(*width); | |
| 467 | + m_core.write(*core); | |
| 468 | + m_tail.write(*tail); | |
| 567 | 469 | |
| 568 | 470 | // Return |
| 569 | 471 | return; |
| ... | ... | @@ -573,7 +475,7 @@ void GCTAModelRadialProfile::write(GXmlElement& xml) const |
| 573 | 475 | /***********************************************************************//** |
| 574 | 476 | * @brief Print point source information |
| 575 | 477 | * |
| 576 | - * @param[in] chatter Chattiness (defaults to NORMAL). | |
| 478 | + * @param[in] chatter Chattiness. | |
| 577 | 479 | * @return String containing point source information. |
| 578 | 480 | ***************************************************************************/ |
| 579 | 481 | std::string GCTAModelRadialProfile::print(const GChatter& chatter) const | ... | ... |
inst/cta/src/GCTAModelSpatialGradient.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCTAModelSpatialGradient.cpp - Spatial gradient CTA model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2018 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2018-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -353,24 +353,12 @@ void GCTAModelSpatialGradient::read(const GXmlElement& xml) |
| 353 | 353 | * |
| 354 | 354 | * @param[in] xml XML element. |
| 355 | 355 | * |
| 356 | - * @exception GException::invalid_value | |
| 357 | - * Spatial model is not of valid type. | |
| 358 | - * | |
| 359 | 356 | * Write the gradient spatial model information into an XML element. |
| 360 | 357 | ***************************************************************************/ |
| 361 | 358 | void GCTAModelSpatialGradient::write(GXmlElement& xml) const |
| 362 | 359 | { |
| 363 | - // Set model type | |
| 364 | - if (xml.attribute("type") == "") { | |
| 365 | - xml.attribute("type", type()); | |
| 366 | - } | |
| 367 | - | |
| 368 | - // Verify model type | |
| 369 | - if (xml.attribute("type") != type()) { | |
| 370 | - std::string msg = "Spatial model \""+xml.attribute("type")+ | |
| 371 | - "\" is not of type \""+type()+"\"."; | |
| 372 | - throw GException::invalid_value(G_WRITE, msg); | |
| 373 | - } | |
| 360 | + // Check model type | |
| 361 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 374 | 362 | |
| 375 | 363 | // Get XML parameters |
| 376 | 364 | GXmlElement* detx = gammalib::xml_need_par(G_WRITE, xml, m_detx_gradient.name()); | ... | ... |
inst/cta/src/GCTAModelSpatialMultiplicative.cpp
| ... | ... | @@ -361,24 +361,12 @@ void GCTAModelSpatialMultiplicative::read(const GXmlElement& xml) |
| 361 | 361 | * |
| 362 | 362 | * @param[in] xml XML element. |
| 363 | 363 | * |
| 364 | - * @exception GException::invalid_value | |
| 365 | - * Existing XML element is not of the expected type. | |
| 366 | - * | |
| 367 | 364 | * Writes the spatial information into an XML element. |
| 368 | 365 | ***************************************************************************/ |
| 369 | 366 | void GCTAModelSpatialMultiplicative::write(GXmlElement& xml) const |
| 370 | 367 | { |
| 371 | - // Set model type | |
| 372 | - if (xml.attribute("type") == "") { | |
| 373 | - xml.attribute("type", type()); | |
| 374 | - } | |
| 375 | - | |
| 376 | - // Verify model type | |
| 377 | - if (xml.attribute("type") != type()) { | |
| 378 | - std::string msg = "Spatial model \""+xml.attribute("type")+"\" is " | |
| 379 | - "not of expected type \""+type()+"\"."; | |
| 380 | - throw GException::invalid_value(G_WRITE, msg); | |
| 381 | - } | |
| 368 | + // Check model type | |
| 369 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 382 | 370 | |
| 383 | 371 | // Loop over model components |
| 384 | 372 | for (int i = 0; i < m_spatial.size(); i++) { | ... | ... |
pyext/GFitsTableCol.i
| ... | ... | @@ -132,7 +132,7 @@ public: |
| 132 | 132 | (*col)(GTuple1D2D[1], GTuple1D2D[2]) = value; |
| 133 | 133 | } |
| 134 | 134 | else { |
| 135 | - throw GException::bad_type("GFitsTableCol::__setitem__", | |
| 135 | + throw GException::invalid_argument("GFitsTableCol::__setitem__", | |
| 136 | 136 | "Column type does not support string setting."); |
| 137 | 137 | } |
| 138 | 138 | } |
| ... | ... | @@ -210,7 +210,7 @@ public: |
| 210 | 210 | (*col)(GTuple1D2D[1], GTuple1D2D[2]) = (float)value; |
| 211 | 211 | } |
| 212 | 212 | else { |
| 213 | - throw GException::bad_type("GFitsTableCol::__setitem__", | |
| 213 | + throw GException::invalid_argument("GFitsTableCol::__setitem__", | |
| 214 | 214 | "Column type does not support integer setting."); |
| 215 | 215 | } |
| 216 | 216 | } |
| ... | ... | @@ -233,7 +233,7 @@ public: |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | else { |
| 236 | - throw GException::bad_type("GFitsTableCol::__setitem__", | |
| 236 | + throw GException::invalid_argument("GFitsTableCol::__setitem__", | |
| 237 | 237 | "Column type does not support floating point setting."); |
| 238 | 238 | } |
| 239 | 239 | } | ... | ... |
src/model/GException_model.cpp deleted
| 1 | -/*************************************************************************** | |
| 2 | - * GException_model.cpp - Model exception handlers * | |
| 3 | - * ----------------------------------------------------------------------- * | |
| 4 | - * copyright (C) 2010-2011 by Jurgen Knodlseder * | |
| 5 | - * ----------------------------------------------------------------------- * | |
| 6 | - * * | |
| 7 | - * This program is free software: you can redistribute it and/or modify * | |
| 8 | - * it under the terms of the GNU General Public License as published by * | |
| 9 | - * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | - * (at your option) any later version. * | |
| 11 | - * * | |
| 12 | - * This program is distributed in the hope that it will be useful, * | |
| 13 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | - * GNU General Public License for more details. * | |
| 16 | - * * | |
| 17 | - * You should have received a copy of the GNU General Public License * | |
| 18 | - * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | - * * | |
| 20 | - ***************************************************************************/ | |
| 21 | -/** | |
| 22 | - * @file GException_model.cpp | |
| 23 | - * @brief Implement exceptions for the model module | |
| 24 | - * @author J. Knodlseder | |
| 25 | - */ | |
| 26 | - | |
| 27 | -/* __ Includes ___________________________________________________________ */ | |
| 28 | -#ifdef HAVE_CONFIG_H | |
| 29 | -#include <config.h> | |
| 30 | -#endif | |
| 31 | -#include "GException.hpp" | |
| 32 | -#include "GModelRegistry.hpp" | |
| 33 | -#include "GModelSpatialRegistry.hpp" | |
| 34 | -#include "GModelSpectralRegistry.hpp" | |
| 35 | -#include "GModelTemporalRegistry.hpp" | |
| 36 | -#include "GTools.hpp" | |
| 37 | - | |
| 38 | - | |
| 39 | -/***********************************************************************//** | |
| 40 | - * @brief Invalid model type | |
| 41 | - * | |
| 42 | - * @param[in] origin Method that throws the error. | |
| 43 | - * @param[in] type Model type that has been encountered. | |
| 44 | - * @param[in] message Optional error message. | |
| 45 | - ***************************************************************************/ | |
| 46 | -GException::model_invalid::model_invalid(std::string origin, | |
| 47 | - std::string type, | |
| 48 | - std::string message) | |
| 49 | -{ | |
| 50 | - // Set origin and message | |
| 51 | - m_origin = origin; | |
| 52 | - m_message = "Invalid model type \""+type+"\" encountered. " + message; | |
| 53 | - | |
| 54 | - // Add list of valid models | |
| 55 | - GModelRegistry registry; | |
| 56 | - if (registry.size() > 0) { | |
| 57 | - m_message += "The following models are registered: "; | |
| 58 | - for (int i = 0; i < registry.size(); ++i) { | |
| 59 | - if (i > 0) | |
| 60 | - m_message += ", "; | |
| 61 | - m_message += "\"" + registry.name(i) + "\""; | |
| 62 | - } | |
| 63 | - m_message += "."; | |
| 64 | - } | |
| 65 | - else | |
| 66 | - m_message += "No models are registered."; | |
| 67 | - | |
| 68 | - // Return | |
| 69 | - return; | |
| 70 | -} | |
| 71 | - | |
| 72 | - | |
| 73 | -/***********************************************************************//** | |
| 74 | - * @brief Invalid spatial model type | |
| 75 | - * | |
| 76 | - * @param[in] origin Method that throws the error. | |
| 77 | - * @param[in] type Spatial model type that has been encountered. | |
| 78 | - * @param[in] message Optional error message. | |
| 79 | - ***************************************************************************/ | |
| 80 | -GException::model_invalid_spatial::model_invalid_spatial(std::string origin, | |
| 81 | - std::string type, | |
| 82 | - std::string message) | |
| 83 | -{ | |
| 84 | - // Set origin and message | |
| 85 | - m_origin = origin; | |
| 86 | - m_message = "Invalid spatial model type \""+type+"\" encountered. " + | |
| 87 | - message; | |
| 88 | - | |
| 89 | - // Add list of valid spatial models | |
| 90 | - GModelSpatialRegistry registry; | |
| 91 | - if (registry.size() > 0) { | |
| 92 | - m_message += "The following models are registered: "; | |
| 93 | - for (int i = 0; i < registry.size(); ++i) { | |
| 94 | - if (i > 0) | |
| 95 | - m_message += ", "; | |
| 96 | - m_message += "\"" + registry.name(i) + "\""; | |
| 97 | - } | |
| 98 | - m_message += "."; | |
| 99 | - } | |
| 100 | - else | |
| 101 | - m_message += "No models are registered."; | |
| 102 | - | |
| 103 | - // Return | |
| 104 | - return; | |
| 105 | -} | |
| 106 | - | |
| 107 | - | |
| 108 | -/***********************************************************************//** | |
| 109 | - * @brief Invalid spectral model type | |
| 110 | - * | |
| 111 | - * @param[in] origin Method that throws the error. | |
| 112 | - * @param[in] type Spectral model type that has been encountered. | |
| 113 | - * @param[in] message Optional error message. | |
| 114 | - ***************************************************************************/ | |
| 115 | -GException::model_invalid_spectral::model_invalid_spectral(std::string origin, | |
| 116 | - std::string type, | |
| 117 | - std::string message) | |
| 118 | -{ | |
| 119 | - // Set origin and message | |
| 120 | - m_origin = origin; | |
| 121 | - m_message = "Invalid spectral model type \""+type+"\" encountered. " + | |
| 122 | - message; | |
| 123 | - | |
| 124 | - // Add list of valid spectral models | |
| 125 | - GModelSpectralRegistry registry; | |
| 126 | - if (registry.size() > 0) { | |
| 127 | - m_message += "The following models are registered: "; | |
| 128 | - for (int i = 0; i < registry.size(); ++i) { | |
| 129 | - if (i > 0) | |
| 130 | - m_message += ", "; | |
| 131 | - m_message += "\"" + registry.name(i) + "\""; | |
| 132 | - } | |
| 133 | - m_message += "."; | |
| 134 | - } | |
| 135 | - else | |
| 136 | - m_message += "No models are registered."; | |
| 137 | - | |
| 138 | - // Return | |
| 139 | - return; | |
| 140 | -} | |
| 141 | - | |
| 142 | - | |
| 143 | -/***********************************************************************//** | |
| 144 | - * @brief Invalid temporal model type | |
| 145 | - * | |
| 146 | - * @param[in] origin Method that throws the error. | |
| 147 | - * @param[in] type Temporal model type that has been encountered. | |
| 148 | - * @param[in] message Optional error message. | |
| 149 | - ***************************************************************************/ | |
| 150 | -GException::model_invalid_temporal::model_invalid_temporal(std::string origin, | |
| 151 | - std::string type, | |
| 152 | - std::string message) | |
| 153 | -{ | |
| 154 | - // Set origin and message | |
| 155 | - m_origin = origin; | |
| 156 | - m_message = "Invalid temporal model type \""+type+"\" encountered. " + | |
| 157 | - message; | |
| 158 | - | |
| 159 | - // Add list of valid spectral models | |
| 160 | - GModelTemporalRegistry registry; | |
| 161 | - if (registry.size() > 0) { | |
| 162 | - m_message += "The following models are registered: "; | |
| 163 | - for (int i = 0; i < registry.size(); ++i) { | |
| 164 | - if (i > 0) | |
| 165 | - m_message += ", "; | |
| 166 | - m_message += "\"" + registry.name(i) + "\""; | |
| 167 | - } | |
| 168 | - m_message += "."; | |
| 169 | - } | |
| 170 | - else | |
| 171 | - m_message += "No models are registered."; | |
| 172 | - | |
| 173 | - // Return | |
| 174 | - return; | |
| 175 | -} | |
| 176 | - | |
| 177 | - | |
| 178 | -/***********************************************************************//** | |
| 179 | - * @brief Invalid number of model parameters in XML element | |
| 180 | - * | |
| 181 | - * @param[in] origin Method that throws the error. | |
| 182 | - * @param[in] xml XML element. | |
| 183 | - * @param[in] message Optional error message. | |
| 184 | - ***************************************************************************/ | |
| 185 | -GException::model_invalid_parnum::model_invalid_parnum(std::string origin, | |
| 186 | - GXmlElement xml, | |
| 187 | - std::string message) | |
| 188 | -{ | |
| 189 | - // Set origin and message | |
| 190 | - m_origin = origin; | |
| 191 | - m_message = "Invalid number of model parameters found in XML element. " + | |
| 192 | - message; | |
| 193 | - | |
| 194 | - // Return | |
| 195 | - return; | |
| 196 | -} | |
| 197 | - | |
| 198 | - | |
| 199 | -/***********************************************************************//** | |
| 200 | - * @brief Invalid model parameter names in XML element | |
| 201 | - * | |
| 202 | - * @param[in] origin Method that throws the error. | |
| 203 | - * @param[in] xml XML element. | |
| 204 | - * @param[in] message Optional error message. | |
| 205 | - ***************************************************************************/ | |
| 206 | -GException::model_invalid_parnames::model_invalid_parnames(std::string origin, | |
| 207 | - GXmlElement xml, | |
| 208 | - std::string message) | |
| 209 | -{ | |
| 210 | - // Set origin and message | |
| 211 | - m_origin = origin; | |
| 212 | - m_message = "Invalid model parameter names found in XML element. " + | |
| 213 | - message; | |
| 214 | - | |
| 215 | - // Return | |
| 216 | - return; | |
| 217 | -} | |
| 218 | - | |
| 219 | - | |
| 220 | -/***********************************************************************//** | |
| 221 | - * @brief Invalid model parameter value in XML element | |
| 222 | - * | |
| 223 | - * @param[in] origin Method that throws the error. | |
| 224 | - * @param[in] xml XML element. | |
| 225 | - * @param[in] message Optional error message. | |
| 226 | - ***************************************************************************/ | |
| 227 | -GException::model_invalid_parvalue::model_invalid_parvalue(std::string origin, | |
| 228 | - GXmlElement xml, | |
| 229 | - std::string message) | |
| 230 | -{ | |
| 231 | - // Set origin and message | |
| 232 | - m_origin = origin; | |
| 233 | - m_message = "Invalid model parameter value found in XML element. " + | |
| 234 | - message; | |
| 235 | - | |
| 236 | - // Return | |
| 237 | - return; | |
| 238 | -} | |
| 239 | - | |
| 240 | - | |
| 241 | -/***********************************************************************//** | |
| 242 | - * @brief Invalid model parameter limit in XML element | |
| 243 | - * | |
| 244 | - * @param[in] origin Method that throws the error. | |
| 245 | - * @param[in] xml XML element. | |
| 246 | - * @param[in] message Optional error message. | |
| 247 | - ***************************************************************************/ | |
| 248 | -GException::model_invalid_parlimit::model_invalid_parlimit(std::string origin, | |
| 249 | - GXmlElement xml, | |
| 250 | - std::string message) | |
| 251 | -{ | |
| 252 | - // Set origin and message | |
| 253 | - m_origin = origin; | |
| 254 | - m_message = "Invalid model parameter limit found in XML element. " + | |
| 255 | - message; | |
| 256 | - | |
| 257 | - // Return | |
| 258 | - return; | |
| 259 | -} | |
| 260 | - | |
| 261 | - | |
| 262 | -/***********************************************************************//** | |
| 263 | - * @brief Model parameter has invalid scale | |
| 264 | - * | |
| 265 | - * @param[in] origin Method that throws the error. | |
| 266 | - * @param[in] scale Scale. | |
| 267 | - * @param[in] message Optional error message. | |
| 268 | - ***************************************************************************/ | |
| 269 | -GException::model_invalid_parscale::model_invalid_parscale(std::string origin, | |
| 270 | - double scale, | |
| 271 | - std::string message) | |
| 272 | -{ | |
| 273 | - // Set origin and message | |
| 274 | - m_origin = origin; | |
| 275 | - m_message = "Model parameter has invalid scale="+gammalib::str(scale)+". " + | |
| 276 | - message; | |
| 277 | - | |
| 278 | - // Return | |
| 279 | - return; | |
| 280 | -} | |
| 281 | - | |
| 282 | - | |
| 283 | -/***********************************************************************//** | |
| 284 | - * @brief Model parameter has invalid scale | |
| 285 | - * | |
| 286 | - * @param[in] origin Method that throws the error. | |
| 287 | - * @param[in] xml XML element. | |
| 288 | - * @param[in] message Optional error message. | |
| 289 | - ***************************************************************************/ | |
| 290 | -GException::model_invalid_parscale::model_invalid_parscale(std::string origin, | |
| 291 | - GXmlElement xml, | |
| 292 | - std::string message) | |
| 293 | -{ | |
| 294 | - // Set origin and message | |
| 295 | - m_origin = origin; | |
| 296 | - m_message = "Model parameter with invalid scale found in XML element. " + | |
| 297 | - message; | |
| 298 | - | |
| 299 | - // Return | |
| 300 | - return; | |
| 301 | -} | |
| 302 | - | |
| 303 | - | |
| 304 | -/***********************************************************************//** | |
| 305 | - * @brief Not enough nodes in file function | |
| 306 | - * | |
| 307 | - * @param[in] origin Method that throws the error. | |
| 308 | - * @param[in] filename File function filename. | |
| 309 | - * @param[in] num Number of nodes. | |
| 310 | - * @param[in] message Optional error message. | |
| 311 | - ***************************************************************************/ | |
| 312 | -GException::file_function_data::file_function_data(std::string origin, | |
| 313 | - std::string filename, | |
| 314 | - int num, | |
| 315 | - std::string message) | |
| 316 | -{ | |
| 317 | - // Set origin and message | |
| 318 | - m_origin = origin; | |
| 319 | - m_message = "File function \""+filename+"\" contains "+gammalib::str(num)+ | |
| 320 | - " energy nodes while at least 2 are required to describe a" | |
| 321 | - " spectral shape."; | |
| 322 | - if (message.length() > 0) { | |
| 323 | - m_message += " "+message; | |
| 324 | - } | |
| 325 | - | |
| 326 | - // Return | |
| 327 | - return; | |
| 328 | -} | |
| 329 | - | |
| 330 | - | |
| 331 | -/***********************************************************************//** | |
| 332 | - * @brief Not enough columns in file function | |
| 333 | - * | |
| 334 | - * @param[in] origin Method that throws the error. | |
| 335 | - * @param[in] filename File function filename. | |
| 336 | - * @param[in] num Number of columns. | |
| 337 | - * @param[in] message Optional error message. | |
| 338 | - ***************************************************************************/ | |
| 339 | -GException::file_function_columns::file_function_columns(std::string origin, | |
| 340 | - std::string filename, | |
| 341 | - int num, | |
| 342 | - std::string message) | |
| 343 | -{ | |
| 344 | - // Set origin and message | |
| 345 | - m_origin = origin; | |
| 346 | - m_message = "File function \""+filename+"\" contains "+gammalib::str(num)+ | |
| 347 | - " columns while at least 2 are required to define" | |
| 348 | - " energy and intensity."; | |
| 349 | - if (message.length() > 0) { | |
| 350 | - m_message += " "+message; | |
| 351 | - } | |
| 352 | - | |
| 353 | - // Return | |
| 354 | - return; | |
| 355 | -} | |
| 356 | - | |
| 357 | - | |
| 358 | -/***********************************************************************//** | |
| 359 | - * @brief Invalid value in file function | |
| 360 | - * | |
| 361 | - * @param[in] origin Method that throws the error. | |
| 362 | - * @param[in] filename File function filename. | |
| 363 | - * @param[in] value Number of columns. | |
| 364 | - * @param[in] message Optional error message. | |
| 365 | - ***************************************************************************/ | |
| 366 | -GException::file_function_value::file_function_value(std::string origin, | |
| 367 | - std::string filename, | |
| 368 | - double value, | |
| 369 | - std::string message) | |
| 370 | -{ | |
| 371 | - // Set origin and message | |
| 372 | - m_origin = origin; | |
| 373 | - m_message = "Invalid value \""+gammalib::str(value)+"\" encountered in" | |
| 374 | - " file function \""+filename+"\"."; | |
| 375 | - if (message.length() > 0) { | |
| 376 | - m_message += " "+message; | |
| 377 | - } | |
| 378 | - | |
| 379 | - // Return | |
| 380 | - return; | |
| 381 | -} | |
| 382 | - | |
| 383 | - | |
| 384 | -/***********************************************************************//** | |
| 385 | - * @brief Parameter not found | |
| 386 | - * | |
| 387 | - * @param[in] origin Method that throws the error. | |
| 388 | - * @param[in] name Parameter name. | |
| 389 | - * @param[in] message Optional error message. | |
| 390 | - ***************************************************************************/ | |
| 391 | -GException::par_not_found::par_not_found(std::string origin, | |
| 392 | - std::string name, | |
| 393 | - std::string message) | |
| 394 | -{ | |
| 395 | - // Set origin | |
| 396 | - m_origin = origin; | |
| 397 | - | |
| 398 | - // Set message | |
| 399 | - m_message = "Parameter \""+name+"\" not found in container."; | |
| 400 | - if (message.length() > 0) | |
| 401 | - m_message += " "+message; | |
| 402 | - | |
| 403 | - // Return | |
| 404 | - return; | |
| 405 | -} | |
| 406 | - | |
| 407 | - | |
| 408 | -/***********************************************************************//** | |
| 409 | - * @brief Model not found | |
| 410 | - * | |
| 411 | - * @param[in] origin Method that throws the error. | |
| 412 | - * @param[in] name Model name. | |
| 413 | - * @param[in] message Optional error message. | |
| 414 | - ***************************************************************************/ | |
| 415 | -GException::model_not_found::model_not_found(std::string origin, | |
| 416 | - std::string name, | |
| 417 | - std::string message) | |
| 418 | -{ | |
| 419 | - // Set origin | |
| 420 | - m_origin = origin; | |
| 421 | - | |
| 422 | - // Set message | |
| 423 | - m_message = "Model \""+name+"\" not found in container."; | |
| 424 | - if (message.length() > 0) | |
| 425 | - m_message += " "+message; | |
| 426 | - | |
| 427 | - // Return | |
| 428 | - return; | |
| 429 | -} | |
| 430 | - | |
| 431 | - | |
| 432 | -/***********************************************************************//** | |
| 433 | - * @brief No point source model component found | |
| 434 | - * | |
| 435 | - * @param[in] origin Method that throws the error. | |
| 436 | - * @param[in] name Model name. | |
| 437 | - * @param[in] message Optional error message. | |
| 438 | - ***************************************************************************/ | |
| 439 | -GException::no_point_source::no_point_source(std::string origin, | |
| 440 | - std::string name, | |
| 441 | - std::string message) | |
| 442 | -{ | |
| 443 | - // Set origin | |
| 444 | - m_origin = origin; | |
| 445 | - | |
| 446 | - // Set message | |
| 447 | - m_message = "No point source model component found in model \""+name+"\"."; | |
| 448 | - if (message.length() > 0) | |
| 449 | - m_message += " "+message; | |
| 450 | - | |
| 451 | - // Return | |
| 452 | - return; | |
| 453 | -} | |
| 454 | - | |
| 455 | - | |
| 456 | -/***********************************************************************//** | |
| 457 | - * @brief No extended source model component found | |
| 458 | - * | |
| 459 | - * @param[in] origin Method that throws the error. | |
| 460 | - * @param[in] name Model name. | |
| 461 | - * @param[in] message Optional error message. | |
| 462 | - ***************************************************************************/ | |
| 463 | -GException::no_extended_source::no_extended_source(std::string origin, | |
| 464 | - std::string name, | |
| 465 | - std::string message) | |
| 466 | -{ | |
| 467 | - // Set origin | |
| 468 | - m_origin = origin; | |
| 469 | - | |
| 470 | - // Set message | |
| 471 | - m_message = "No extended source model component found in model \""+name+"\"."; | |
| 472 | - if (message.length() > 0) | |
| 473 | - m_message += " "+message; | |
| 474 | - | |
| 475 | - // Return | |
| 476 | - return; | |
| 477 | -} |
src/model/GModel.cpp
| ... | ... | @@ -156,8 +156,8 @@ GModel& GModel::operator=(const GModel& model) |
| 156 | 156 | * @param[in] name Parameter name. |
| 157 | 157 | * @return Reference to model parameter. |
| 158 | 158 | * |
| 159 | - * @exception GException::par_not_found | |
| 160 | - * Parameter with specified name not found in container. | |
| 159 | + * @exception GException::invalid_argument | |
| 160 | + * Parameter with specified name not found. | |
| 161 | 161 | * |
| 162 | 162 | * Returns a reference to the model parameter of the specified @p name. |
| 163 | 163 | * Throws an exception if no parameter with @p name is found. |
| ... | ... | @@ -174,7 +174,9 @@ GModelPar& GModel::operator[](const std::string& name) |
| 174 | 174 | |
| 175 | 175 | // Throw exception if parameter name was not found |
| 176 | 176 | if (index >= size()) { |
| 177 | - throw GException::par_not_found(G_ACCESS, name); | |
| 177 | + std::string msg = "Model parameter \""+name+"\" not found in model. " | |
| 178 | + "Please specify a valid model parameter name."; | |
| 179 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 178 | 180 | } |
| 179 | 181 | |
| 180 | 182 | // Return reference |
| ... | ... | @@ -188,8 +190,8 @@ GModelPar& GModel::operator[](const std::string& name) |
| 188 | 190 | * @param[in] name Parameter name. |
| 189 | 191 | * @return Reference to model parameter. |
| 190 | 192 | * |
| 191 | - * @exception GException::par_not_found | |
| 192 | - * Parameter with specified name not found in container. | |
| 193 | + * @exception GException::invalid_argument | |
| 194 | + * Parameter with specified name not found. | |
| 193 | 195 | * |
| 194 | 196 | * Returns a const reference to the model parameter of the specified |
| 195 | 197 | * @p name. Throws an exception if no parameter with @p name is found. |
| ... | ... | @@ -206,7 +208,9 @@ const GModelPar& GModel::operator[](const std::string& name) const |
| 206 | 208 | |
| 207 | 209 | // Throw exception if parameter name was not found |
| 208 | 210 | if (index >= size()) { |
| 209 | - throw GException::par_not_found(G_ACCESS, name); | |
| 211 | + std::string msg = "Model parameter \""+name+"\" not found in model. " | |
| 212 | + "Please specify a valid model parameter name."; | |
| 213 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 210 | 214 | } |
| 211 | 215 | |
| 212 | 216 | // Return reference |
| ... | ... | @@ -879,7 +883,7 @@ void GModel::read_scales(const GXmlElement& xml) |
| 879 | 883 | * |
| 880 | 884 | * @param[in] xml XML source element. |
| 881 | 885 | * |
| 882 | - * @exception GException::model_invalid_parnum | |
| 886 | + * @exception GException::invalid_value | |
| 883 | 887 | * Invalid number of instrument tags found in XML element. |
| 884 | 888 | * |
| 885 | 889 | * If there are instrument scale factors then add a tag with the following |
| ... | ... | @@ -915,10 +919,21 @@ void GModel::write_scales(GXmlElement& xml) const |
| 915 | 919 | scale = xml.element("scaling", 0); |
| 916 | 920 | } |
| 917 | 921 | |
| 918 | - // Verify that scaling tag has the required number of instruments | |
| 919 | - if (scale->elements() != num || scale->elements("instrument") != num) { | |
| 920 | - throw GException::model_invalid_parnum(G_WRITE_SCALES, *scale, | |
| 921 | - "Instrument scaling needs "+gammalib::str(num)+" instrument tags."); | |
| 922 | + // Verify that scaling tag has the required number of instruments | |
| 923 | + if (scale->elements() != num) { | |
| 924 | + std::string msg = "Number of "+gammalib::str(scale->elements())+ | |
| 925 | + " scale elements in XML file does not correspond " | |
| 926 | + "to expected number of "+gammalib::str(num)+ | |
| 927 | + " elements. Please verify the XML format."; | |
| 928 | + throw GException::invalid_value(G_WRITE_SCALES, msg); | |
| 929 | + } | |
| 930 | + int npars = scale->elements("instrument"); | |
| 931 | + if (npars != num) { | |
| 932 | + std::string msg = "Number of "+gammalib::str(npars)+" \"instrument\" " | |
| 933 | + "scale elements in XML file does not correspond to " | |
| 934 | + "expected number of "+gammalib::str(num)+ | |
| 935 | + " elements. Please verify the XML format."; | |
| 936 | + throw GException::invalid_value(G_WRITE_SCALES, msg); | |
| 922 | 937 | } |
| 923 | 938 | |
| 924 | 939 | // Write all instruments | ... | ... |
src/model/GModelSpatial.cpp
| ... | ... | @@ -136,8 +136,8 @@ GModelSpatial& GModelSpatial::operator=(const GModelSpatial& model) |
| 136 | 136 | * @param[in] name Parameter name. |
| 137 | 137 | * @return Model parameter reference. |
| 138 | 138 | * |
| 139 | - * @exception GException::par_not_found | |
| 140 | - * Parameter with specified name not found in container. | |
| 139 | + * @exception GException::invalid_argument | |
| 140 | + * Parameter with specified name not found. | |
| 141 | 141 | * |
| 142 | 142 | * Returns reference to the model parameter of specified @p name. |
| 143 | 143 | ***************************************************************************/ |
| ... | ... | @@ -153,7 +153,9 @@ GModelPar& GModelSpatial::operator[](const std::string& name) |
| 153 | 153 | |
| 154 | 154 | // Throw exception if parameter name was not found |
| 155 | 155 | if (index >= size()) { |
| 156 | - throw GException::par_not_found(G_ACCESS, name); | |
| 156 | + std::string msg = "Model parameter \""+name+"\" not found in model. " | |
| 157 | + "Please specify a valid model parameter name."; | |
| 158 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 157 | 159 | } |
| 158 | 160 | |
| 159 | 161 | // Return reference |
| ... | ... | @@ -167,8 +169,8 @@ GModelPar& GModelSpatial::operator[](const std::string& name) |
| 167 | 169 | * @param[in] name Parameter name. |
| 168 | 170 | * @return Model parameter reference. |
| 169 | 171 | * |
| 170 | - * @exception GException::par_not_found | |
| 171 | - * Parameter with specified name not found in container. | |
| 172 | + * @exception GException::invalid_argument | |
| 173 | + * Parameter with specified name not found. | |
| 172 | 174 | * |
| 173 | 175 | * Returns reference to the model parameter of specified @p name. |
| 174 | 176 | ***************************************************************************/ |
| ... | ... | @@ -184,7 +186,9 @@ const GModelPar& GModelSpatial::operator[](const std::string& name) const |
| 184 | 186 | |
| 185 | 187 | // Throw exception if parameter name was not found |
| 186 | 188 | if (index >= size()) { |
| 187 | - throw GException::par_not_found(G_ACCESS, name); | |
| 189 | + std::string msg = "Model parameter \""+name+"\" not found in model. " | |
| 190 | + "Please specify a valid model parameter name."; | |
| 191 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 188 | 192 | } |
| 189 | 193 | |
| 190 | 194 | // Return reference | ... | ... |
src/model/GModelSpatialComposite.cpp
| ... | ... | @@ -419,27 +419,12 @@ void GModelSpatialComposite::read(const GXmlElement& xml) |
| 419 | 419 | * |
| 420 | 420 | * @param[in] xml XML element into which model information is written. |
| 421 | 421 | * |
| 422 | - * @exception GException::model_invalid_spatial | |
| 423 | - * Existing XML element is not of appropriate type | |
| 424 | - * @exception GException::model_invalid_parnum | |
| 425 | - * Invalid number of model parameters found in XML element. | |
| 426 | - * @exception GException::model_invalid_parnames | |
| 427 | - * Invalid model parameter names found in XML element. | |
| 428 | - * | |
| 429 | 422 | * Write the spatial information into an XML element. |
| 430 | 423 | ***************************************************************************/ |
| 431 | 424 | void GModelSpatialComposite::write(GXmlElement& xml) const |
| 432 | 425 | { |
| 433 | - // Set model type | |
| 434 | - if (xml.attribute("type") == "") { | |
| 435 | - xml.attribute("type", type()); | |
| 436 | - } | |
| 437 | - | |
| 438 | 426 | // Verify model type |
| 439 | - if (xml.attribute("type") != type()) { | |
| 440 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 441 | - "Spatial model is not of type \""+type()+"\"."); | |
| 442 | - } | |
| 427 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 443 | 428 | |
| 444 | 429 | // Write all model components |
| 445 | 430 | for (int i = 0; i < m_components.size(); ++i) { | ... | ... |
src/model/GModelSpatialDiffuseConst.cpp
| ... | ... | @@ -421,6 +421,9 @@ double GModelSpatialDiffuseConst::mc_norm(const GSkyDir& dir, |
| 421 | 421 | ***************************************************************************/ |
| 422 | 422 | void GModelSpatialDiffuseConst::read(const GXmlElement& xml) |
| 423 | 423 | { |
| 424 | + // Verify number of model parameters | |
| 425 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 426 | + | |
| 424 | 427 | // Get value parameter |
| 425 | 428 | const GXmlElement* par = gammalib::xml_get_par(G_READ, xml, m_value.name()); |
| 426 | 429 | |
| ... | ... | @@ -437,9 +440,6 @@ void GModelSpatialDiffuseConst::read(const GXmlElement& xml) |
| 437 | 440 | * |
| 438 | 441 | * @param[in] xml XML element. |
| 439 | 442 | * |
| 440 | - * @exception GException::model_invalid_spatial | |
| 441 | - * Existing XML element is not of type "ConstantValue" | |
| 442 | - * | |
| 443 | 443 | * Write the isotropic source model information into an XML element. The XML |
| 444 | 444 | * element will have the following format: |
| 445 | 445 | * |
| ... | ... | @@ -450,16 +450,8 @@ void GModelSpatialDiffuseConst::read(const GXmlElement& xml) |
| 450 | 450 | ***************************************************************************/ |
| 451 | 451 | void GModelSpatialDiffuseConst::write(GXmlElement& xml) const |
| 452 | 452 | { |
| 453 | - // Set model type | |
| 454 | - if (xml.attribute("type") == "") { | |
| 455 | - xml.attribute("type", type()); | |
| 456 | - } | |
| 457 | - | |
| 458 | 453 | // Verify model type |
| 459 | - if (xml.attribute("type") != type()) { | |
| 460 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 461 | - "Spatial model is not of type \""+type()+"\"."); | |
| 462 | - } | |
| 454 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 463 | 455 | |
| 464 | 456 | // Get or create Value parameter |
| 465 | 457 | GXmlElement* par = gammalib::xml_need_par(G_WRITE, xml, m_value.name()); | ... | ... |
src/model/GModelSpatialDiffuseCube.cpp
| ... | ... | @@ -559,6 +559,9 @@ bool GModelSpatialDiffuseCube::contains(const GSkyDir& dir, |
| 559 | 559 | ***************************************************************************/ |
| 560 | 560 | void GModelSpatialDiffuseCube::read(const GXmlElement& xml) |
| 561 | 561 | { |
| 562 | + // Verify number of model parameters | |
| 563 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 564 | + | |
| 562 | 565 | // If "Normalization" parameter exists then read parameter from this |
| 563 | 566 | // XML element |
| 564 | 567 | if (gammalib::xml_has_par(xml, "Normalization")) { |
| ... | ... | @@ -599,13 +602,6 @@ void GModelSpatialDiffuseCube::read(const GXmlElement& xml) |
| 599 | 602 | * |
| 600 | 603 | * @param[in] xml XML element. |
| 601 | 604 | * |
| 602 | - * @exception GException::model_invalid_spatial | |
| 603 | - * Existing XML element is not of type "MapCubeFunction" | |
| 604 | - * @exception GException::model_invalid_parnum | |
| 605 | - * Invalid number of model parameters found in XML element. | |
| 606 | - * @exception GException::model_invalid_parnames | |
| 607 | - * Invalid model parameter names found in XML element. | |
| 608 | - * | |
| 609 | 605 | * Write the map cube information into an XML element. The XML element will |
| 610 | 606 | * have either the format |
| 611 | 607 | * |
| ... | ... | @@ -623,44 +619,14 @@ void GModelSpatialDiffuseCube::read(const GXmlElement& xml) |
| 623 | 619 | ***************************************************************************/ |
| 624 | 620 | void GModelSpatialDiffuseCube::write(GXmlElement& xml) const |
| 625 | 621 | { |
| 626 | - // Set model type | |
| 627 | - if (xml.attribute("type") == "") { | |
| 628 | - xml.attribute("type", type()); | |
| 629 | - } | |
| 630 | - | |
| 631 | 622 | // Verify model type |
| 632 | - if (xml.attribute("type") != type()) { | |
| 633 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 634 | - "Spatial model is not of type \""+type()+"\"."); | |
| 635 | - } | |
| 623 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 636 | 624 | |
| 637 | - // If XML element has 0 nodes then append parameter node. The name | |
| 638 | - // of the node is "Normalization" as this is the Fermi-LAT standard. | |
| 639 | - // We thus assure that the XML files will be compatible with | |
| 640 | - // Fermi-LAT. | |
| 641 | - if (xml.elements() == 0) { | |
| 642 | - xml.append(GXmlElement("parameter name=\"Normalization\"")); | |
| 643 | - } | |
| 625 | + // Get or create parameter | |
| 626 | + GXmlElement* value = gammalib::xml_need_par(G_WRITE, xml, m_value.name()); | |
| 644 | 627 | |
| 645 | - // Verify that XML element has exactly 1 parameter | |
| 646 | - if (xml.elements() != 1 || xml.elements("parameter") != 1) { | |
| 647 | - throw GException::model_invalid_parnum(G_WRITE, xml, | |
| 648 | - "Map cube spatial model requires exactly 1 parameter."); | |
| 649 | - } | |
| 650 | - | |
| 651 | - // Get pointers on model parameter | |
| 652 | - GXmlElement* par = xml.element("parameter", 0); | |
| 653 | - | |
| 654 | - // Set or update parameter | |
| 655 | - if (par->attribute("name") == "Normalization" || | |
| 656 | - par->attribute("name") == "Value") { | |
| 657 | - m_value.write(*par); | |
| 658 | - } | |
| 659 | - else { | |
| 660 | - throw GException::model_invalid_parnames(G_WRITE, xml, | |
| 661 | - "Map cube spatial model requires either \"Value\" or" | |
| 662 | - " \"Normalization\" parameter."); | |
| 663 | - } | |
| 628 | + // Write parameter | |
| 629 | + m_value.write(*value); | |
| 664 | 630 | |
| 665 | 631 | // Set filename |
| 666 | 632 | xml.attribute("file", gammalib::xml_file_reduce(xml, m_filename)); | ... | ... |
src/model/GModelSpatialDiffuseMap.cpp
| ... | ... | @@ -520,6 +520,9 @@ bool GModelSpatialDiffuseMap::contains(const GSkyDir& dir, |
| 520 | 520 | ***************************************************************************/ |
| 521 | 521 | void GModelSpatialDiffuseMap::read(const GXmlElement& xml) |
| 522 | 522 | { |
| 523 | + // Verify number of model parameters | |
| 524 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 525 | + | |
| 523 | 526 | // If "Normalization" parameter exists then read parameter from this |
| 524 | 527 | // XML element |
| 525 | 528 | if (gammalib::xml_has_par(xml, "Normalization")) { |
| ... | ... | @@ -596,47 +599,17 @@ void GModelSpatialDiffuseMap::read(const GXmlElement& xml) |
| 596 | 599 | ***************************************************************************/ |
| 597 | 600 | void GModelSpatialDiffuseMap::write(GXmlElement& xml) const |
| 598 | 601 | { |
| 599 | - // Set model type | |
| 600 | - if (xml.attribute("type") == "") { | |
| 601 | - xml.attribute("type", type()); | |
| 602 | - } | |
| 603 | - | |
| 604 | 602 | // Verify model type |
| 605 | - if (xml.attribute("type") != type()) { | |
| 606 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 607 | - "Spatial model is not of type \""+type()+"\"."); | |
| 608 | - } | |
| 609 | - | |
| 610 | - // Set sky map file name | |
| 611 | - xml.attribute("file", gammalib::xml_file_reduce(xml, m_filename)); | |
| 603 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 612 | 604 | |
| 613 | - // If XML element has 0 nodes then append parameter node. The name | |
| 614 | - // of the node is "Prefactor" as this is the Fermi/LAT standard. | |
| 615 | - // We thus assure that the XML files will be compatible with | |
| 616 | - // Fermi/LAT. | |
| 617 | - if (xml.elements() == 0) { | |
| 618 | - xml.append(GXmlElement("parameter name=\"Prefactor\"")); | |
| 619 | - } | |
| 620 | - | |
| 621 | - // Verify that XML element has exactly 1 parameter | |
| 622 | - if (xml.elements() != 1 || xml.elements("parameter") != 1) { | |
| 623 | - throw GException::model_invalid_parnum(G_WRITE, xml, | |
| 624 | - "Spatial map model requires exactly 1 parameter."); | |
| 625 | - } | |
| 605 | + // Get or create parameter | |
| 606 | + GXmlElement* value = gammalib::xml_need_par(G_WRITE, xml, m_value.name()); | |
| 626 | 607 | |
| 627 | - // Get pointer on model parameter | |
| 628 | - GXmlElement* par = xml.element("parameter", 0); | |
| 608 | + // Write parameters | |
| 609 | + m_value.write(*value); | |
| 629 | 610 | |
| 630 | - // Set or update parameter | |
| 631 | - if (par->attribute("name") == "Normalization" || | |
| 632 | - par->attribute("name") == "Prefactor") { | |
| 633 | - m_value.write(*par); | |
| 634 | - } | |
| 635 | - else { | |
| 636 | - throw GException::model_invalid_parnames(G_WRITE, xml, | |
| 637 | - "Spatial map model requires either \"Prefactor\" or" | |
| 638 | - " \"Normalization\" parameter."); | |
| 639 | - } | |
| 611 | + // Set sky map file name | |
| 612 | + xml.attribute("file", gammalib::xml_file_reduce(xml, m_filename)); | |
| 640 | 613 | |
| 641 | 614 | // Set optional normalization attribute |
| 642 | 615 | if (m_has_normalize || !m_normalize) { | ... | ... |
src/model/GModelSpatialElliptical.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialElliptical.cpp - Abstract elliptical spatial model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2013-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -191,11 +191,6 @@ double GModelSpatialElliptical::eval(const GPhoton& photon, |
| 191 | 191 | * |
| 192 | 192 | * @param[in] xml XML element. |
| 193 | 193 | * |
| 194 | - * @exception GException::model_invalid_parnum | |
| 195 | - * Invalid number of model parameters found in XML element. | |
| 196 | - * @exception GException::model_invalid_parnames | |
| 197 | - * Invalid model parameter names found in XML element. | |
| 198 | - * | |
| 199 | 194 | * Reads the elliptical source location and position angle information from |
| 200 | 195 | * an XML element in the following format |
| 201 | 196 | * |
| ... | ... | @@ -270,13 +265,6 @@ void GModelSpatialElliptical::read(const GXmlElement& xml) |
| 270 | 265 | * |
| 271 | 266 | * @param[in] xml XML element into which model information is written. |
| 272 | 267 | * |
| 273 | - * @exception GException::model_invalid_spatial | |
| 274 | - * Existing XML element is not of requested type. | |
| 275 | - * @exception GException::model_invalid_parnum | |
| 276 | - * Invalid number of model parameters found in XML element. | |
| 277 | - * @exception GException::model_invalid_parnames | |
| 278 | - * Invalid model parameter names found in XML element. | |
| 279 | - * | |
| 280 | 268 | * Writes the elliptical source location and position angle information into |
| 281 | 269 | * an XML element in the following format |
| 282 | 270 | * |
| ... | ... | @@ -292,16 +280,8 @@ void GModelSpatialElliptical::read(const GXmlElement& xml) |
| 292 | 280 | ***************************************************************************/ |
| 293 | 281 | void GModelSpatialElliptical::write(GXmlElement& xml) const |
| 294 | 282 | { |
| 295 | - // Set model type | |
| 296 | - if (xml.attribute("type") == "") { | |
| 297 | - xml.attribute("type", type()); | |
| 298 | - } | |
| 299 | - | |
| 300 | 283 | // Verify model type |
| 301 | - if (xml.attribute("type") != type()) { | |
| 302 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 303 | - "Elliptical model is not of type \""+type()+"\"."); | |
| 304 | - } | |
| 284 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 305 | 285 | |
| 306 | 286 | // Get or create parameters |
| 307 | 287 | GXmlElement* ra = gammalib::xml_need_par(G_WRITE, xml, m_ra.name()); | ... | ... |
src/model/GModelSpatialEllipticalDisk.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialEllipticalDisk.cpp - Elliptical disk source model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2020 by Michael Mayer * | |
| 4 | + * copyright (C) 2013-2021 by Michael Mayer * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -459,14 +459,8 @@ double GModelSpatialEllipticalDisk::theta_max(void) const |
| 459 | 459 | ***************************************************************************/ |
| 460 | 460 | void GModelSpatialEllipticalDisk::read(const GXmlElement& xml) |
| 461 | 461 | { |
| 462 | - // Determine number of parameter nodes in XML element | |
| 463 | - int npars = xml.elements("parameter"); | |
| 464 | - | |
| 465 | - // Verify that XML element has exactly 5 parameters | |
| 466 | - if (xml.elements() != 5 || npars != 5) { | |
| 467 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 468 | - "Elliptical disk model requires exactly 5 parameters."); | |
| 469 | - } | |
| 462 | + // Verify number of model parameters | |
| 463 | + gammalib::xml_check_parnum(G_READ, xml, 5); | |
| 470 | 464 | |
| 471 | 465 | // Read disk location |
| 472 | 466 | GModelSpatialElliptical::read(xml); |
| ... | ... | @@ -489,11 +483,6 @@ void GModelSpatialEllipticalDisk::read(const GXmlElement& xml) |
| 489 | 483 | * |
| 490 | 484 | * @param[in] xml XML element into which model information is written. |
| 491 | 485 | * |
| 492 | - * @exception GException::model_invalid_parnum | |
| 493 | - * Invalid number of model parameters found in XML element. | |
| 494 | - * @exception GException::model_invalid_parnames | |
| 495 | - * Invalid model parameter names found in XML element. | |
| 496 | - * | |
| 497 | 486 | * Write the elliptical disk model information into an XML element. The XML |
| 498 | 487 | * element will have the format |
| 499 | 488 | * |
| ... | ... | @@ -508,6 +497,9 @@ void GModelSpatialEllipticalDisk::read(const GXmlElement& xml) |
| 508 | 497 | ***************************************************************************/ |
| 509 | 498 | void GModelSpatialEllipticalDisk::write(GXmlElement& xml) const |
| 510 | 499 | { |
| 500 | + // Verify model type | |
| 501 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 502 | + | |
| 511 | 503 | // Write disk location |
| 512 | 504 | GModelSpatialElliptical::write(xml); |
| 513 | 505 | ... | ... |
src/model/GModelSpatialEllipticalGauss.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialEllipticalGauss.cpp - Elliptical gauss source model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2015-2020 by Michael Mayer * | |
| 4 | + * copyright (C) 2015-2021 by Michael Mayer * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -498,11 +498,6 @@ double GModelSpatialEllipticalGauss::theta_max(void) const |
| 498 | 498 | * |
| 499 | 499 | * @param[in] xml XML element. |
| 500 | 500 | * |
| 501 | - * @exception GException::model_invalid_parnum | |
| 502 | - * Invalid number of model parameters found in XML element. | |
| 503 | - * @exception GException::model_invalid_parnames | |
| 504 | - * Invalid model parameter names found in XML element. | |
| 505 | - * | |
| 506 | 501 | * Reads the elliptical gauss model information from an XML element. The XML |
| 507 | 502 | * element shall have either the format |
| 508 | 503 | * |
| ... | ... | @@ -529,14 +524,8 @@ double GModelSpatialEllipticalGauss::theta_max(void) const |
| 529 | 524 | ***************************************************************************/ |
| 530 | 525 | void GModelSpatialEllipticalGauss::read(const GXmlElement& xml) |
| 531 | 526 | { |
| 532 | - // Determine number of parameter nodes in XML element | |
| 533 | - int npars = xml.elements("parameter"); | |
| 534 | - | |
| 535 | - // Verify that XML element has exactly 5 parameters | |
| 536 | - if (xml.elements() != 5 || npars != 5) { | |
| 537 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 538 | - "Elliptical gauss model requires exactly 5 parameters."); | |
| 539 | - } | |
| 527 | + // Verify number of model parameters | |
| 528 | + gammalib::xml_check_parnum(G_READ, xml, 5); | |
| 540 | 529 | |
| 541 | 530 | // Read gauss location |
| 542 | 531 | GModelSpatialElliptical::read(xml); |
| ... | ... | @@ -559,11 +548,6 @@ void GModelSpatialEllipticalGauss::read(const GXmlElement& xml) |
| 559 | 548 | * |
| 560 | 549 | * @param[in] xml XML element into which model information is written. |
| 561 | 550 | * |
| 562 | - * @exception GException::model_invalid_parnum | |
| 563 | - * Invalid number of model parameters found in XML element. | |
| 564 | - * @exception GException::model_invalid_parnames | |
| 565 | - * Invalid model parameter names found in XML element. | |
| 566 | - * | |
| 567 | 551 | * Write the elliptical gauss model information into an XML element. The XML |
| 568 | 552 | * element will have the format |
| 569 | 553 | * |
| ... | ... | @@ -578,6 +562,9 @@ void GModelSpatialEllipticalGauss::read(const GXmlElement& xml) |
| 578 | 562 | ***************************************************************************/ |
| 579 | 563 | void GModelSpatialEllipticalGauss::write(GXmlElement& xml) const |
| 580 | 564 | { |
| 565 | + // Verify model type | |
| 566 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 567 | + | |
| 581 | 568 | // Write disk location |
| 582 | 569 | GModelSpatialElliptical::write(xml); |
| 583 | 570 | ... | ... |
src/model/GModelSpatialPointSource.cpp
| ... | ... | @@ -348,11 +348,6 @@ bool GModelSpatialPointSource::contains(const GSkyDir& dir, |
| 348 | 348 | * |
| 349 | 349 | * @param[in] xml XML element containing point source model information. |
| 350 | 350 | * |
| 351 | - * @exception GException::model_invalid_parnum | |
| 352 | - * Invalid number of model parameters found in XML element. | |
| 353 | - * @exception GException::model_invalid_parnames | |
| 354 | - * Invalid model parameter names found in XML element. | |
| 355 | - * | |
| 356 | 351 | * Read the point source information from an XML element with the following |
| 357 | 352 | * format |
| 358 | 353 | * |
| ... | ... | @@ -371,6 +366,9 @@ bool GModelSpatialPointSource::contains(const GSkyDir& dir, |
| 371 | 366 | ***************************************************************************/ |
| 372 | 367 | void GModelSpatialPointSource::read(const GXmlElement& xml) |
| 373 | 368 | { |
| 369 | + // Verify number of model parameters | |
| 370 | + gammalib::xml_check_parnum(G_READ, xml, 2); | |
| 371 | + | |
| 374 | 372 | // Read RA/DEC parameters |
| 375 | 373 | if (gammalib::xml_has_par(xml, "RA") && gammalib::xml_has_par(xml, "DEC")) { |
| 376 | 374 | |
| ... | ... | @@ -417,13 +415,6 @@ void GModelSpatialPointSource::read(const GXmlElement& xml) |
| 417 | 415 | * |
| 418 | 416 | * @param[in] xml XML element into which model information is written. |
| 419 | 417 | * |
| 420 | - * @exception GException::model_invalid_spatial | |
| 421 | - * Existing XML element is not of type 'SkyDirFunction' | |
| 422 | - * @exception GException::model_invalid_parnum | |
| 423 | - * Invalid number of model parameters found in XML element. | |
| 424 | - * @exception GException::model_invalid_parnames | |
| 425 | - * Invalid model parameter names found in XML element. | |
| 426 | - * | |
| 427 | 418 | * Write the point source information into an XML element with the following |
| 428 | 419 | * format |
| 429 | 420 | * |
| ... | ... | @@ -437,16 +428,8 @@ void GModelSpatialPointSource::read(const GXmlElement& xml) |
| 437 | 428 | ***************************************************************************/ |
| 438 | 429 | void GModelSpatialPointSource::write(GXmlElement& xml) const |
| 439 | 430 | { |
| 440 | - // Set model type | |
| 441 | - if (xml.attribute("type") == "") { | |
| 442 | - xml.attribute("type", type()); | |
| 443 | - } | |
| 444 | - | |
| 445 | 431 | // Verify model type |
| 446 | - if (xml.attribute("type") != type()) { | |
| 447 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 448 | - "Spatial model is not of type \""+type()+"\"."); | |
| 449 | - } | |
| 432 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 450 | 433 | |
| 451 | 434 | // Get or create parameters |
| 452 | 435 | GXmlElement* ra = gammalib::xml_need_par(G_WRITE, xml, m_ra.name()); | ... | ... |
src/model/GModelSpatialRadial.cpp
| ... | ... | @@ -282,16 +282,8 @@ void GModelSpatialRadial::read(const GXmlElement& xml) |
| 282 | 282 | ***************************************************************************/ |
| 283 | 283 | void GModelSpatialRadial::write(GXmlElement& xml) const |
| 284 | 284 | { |
| 285 | - // Set model type | |
| 286 | - if (xml.attribute("type") == "") { | |
| 287 | - xml.attribute("type", type()); | |
| 288 | - } | |
| 289 | - | |
| 290 | - // Verify model type | |
| 291 | - if (xml.attribute("type") != type()) { | |
| 292 | - throw GException::model_invalid_spatial(G_WRITE, xml.attribute("type"), | |
| 293 | - "Radial model is not of type \""+type()+"\"."); | |
| 294 | - } | |
| 285 | + // Check model type | |
| 286 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 295 | 287 | |
| 296 | 288 | // Get or create parameters |
| 297 | 289 | GXmlElement* ra = gammalib::xml_need_par(G_WRITE, xml, m_ra.name()); | ... | ... |
src/model/GModelSpatialRadialDisk.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialRadialDisk.cpp - Radial disk source model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2020 by Christoph Deil * | |
| 4 | + * copyright (C) 2011-2021 by Christoph Deil * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -409,14 +409,8 @@ double GModelSpatialRadialDisk::theta_max(void) const |
| 409 | 409 | ***************************************************************************/ |
| 410 | 410 | void GModelSpatialRadialDisk::read(const GXmlElement& xml) |
| 411 | 411 | { |
| 412 | - // Determine number of parameter nodes in XML element | |
| 413 | - int npars = xml.elements("parameter"); | |
| 414 | - | |
| 415 | 412 | // Verify that XML element has exactly 3 parameters |
| 416 | - if (xml.elements() != 3 || npars != 3) { | |
| 417 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 418 | - "Disk model requires exactly 3 parameters."); | |
| 419 | - } | |
| 413 | + gammalib::xml_check_parnum(G_READ, xml, 3); | |
| 420 | 414 | |
| 421 | 415 | // Read disk location |
| 422 | 416 | GModelSpatialRadial::read(xml); |
| ... | ... | @@ -454,6 +448,9 @@ void GModelSpatialRadialDisk::read(const GXmlElement& xml) |
| 454 | 448 | ***************************************************************************/ |
| 455 | 449 | void GModelSpatialRadialDisk::write(GXmlElement& xml) const |
| 456 | 450 | { |
| 451 | + // Verify model type | |
| 452 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 453 | + | |
| 457 | 454 | // Write disk location |
| 458 | 455 | GModelSpatialRadial::write(xml); |
| 459 | 456 | ... | ... |
src/model/GModelSpatialRadialGauss.cpp
| ... | ... | @@ -450,11 +450,6 @@ double GModelSpatialRadialGauss::theta_max(void) const |
| 450 | 450 | * |
| 451 | 451 | * @param[in] xml XML element. |
| 452 | 452 | * |
| 453 | - * @exception GException::model_invalid_parnum | |
| 454 | - * Invalid number of model parameters found in XML element. | |
| 455 | - * @exception GException::model_invalid_parnames | |
| 456 | - * Invalid model parameter names found in XML element. | |
| 457 | - * | |
| 458 | 453 | * Reads the radial Gauss model information from an XML element. The XML |
| 459 | 454 | * element shall have either the format |
| 460 | 455 | * |
| ... | ... | @@ -477,14 +472,8 @@ double GModelSpatialRadialGauss::theta_max(void) const |
| 477 | 472 | ***************************************************************************/ |
| 478 | 473 | void GModelSpatialRadialGauss::read(const GXmlElement& xml) |
| 479 | 474 | { |
| 480 | - // Determine number of parameter nodes in XML element | |
| 481 | - int npars = xml.elements("parameter"); | |
| 482 | - | |
| 483 | - // Verify that XML element has exactly 3 parameters | |
| 484 | - if (xml.elements() != 3 || npars != 3) { | |
| 485 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 486 | - "Gaussian source model requires exactly 3 parameters."); | |
| 487 | - } | |
| 475 | + // Verify number of model parameters | |
| 476 | + gammalib::xml_check_parnum(G_READ, xml, 3); | |
| 488 | 477 | |
| 489 | 478 | // Read Gaussian location |
| 490 | 479 | GModelSpatialRadial::read(xml); |
| ... | ... | @@ -505,13 +494,6 @@ void GModelSpatialRadialGauss::read(const GXmlElement& xml) |
| 505 | 494 | * |
| 506 | 495 | * @param[in] xml XML element into which model information is written. |
| 507 | 496 | * |
| 508 | - * @exception GException::model_invalid_spatial | |
| 509 | - * Existing XML element is not of type 'GaussFunction' | |
| 510 | - * @exception GException::model_invalid_parnum | |
| 511 | - * Invalid number of model parameters found in XML element. | |
| 512 | - * @exception GException::model_invalid_parnames | |
| 513 | - * Invalid model parameter names found in XML element. | |
| 514 | - * | |
| 515 | 497 | * Writes the radial disk model information into an XML element. The XML |
| 516 | 498 | * element will have the format |
| 517 | 499 | * |
| ... | ... | @@ -541,7 +523,7 @@ void GModelSpatialRadialGauss::write(GXmlElement& xml) const |
| 541 | 523 | /***********************************************************************//** |
| 542 | 524 | * @brief Print Gaussian source information |
| 543 | 525 | * |
| 544 | - * @param[in] chatter Chattiness (defaults to NORMAL). | |
| 526 | + * @param[in] chatter Chattiness. | |
| 545 | 527 | * @return String containing model information. |
| 546 | 528 | ***************************************************************************/ |
| 547 | 529 | std::string GModelSpatialRadialGauss::print(const GChatter& chatter) const | ... | ... |
src/model/GModelSpatialRadialProfileDMBurkert.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialRadialProfileDMBurkert.cpp - Burkert radial profile class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2020 by Nathan Kelley-Hoskins * | |
| 4 | + * copyright (C) 2016-2021 by Nathan Kelley-Hoskins * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -288,6 +288,9 @@ double GModelSpatialRadialProfileDMBurkert::theta_max(void) const |
| 288 | 288 | ***************************************************************************/ |
| 289 | 289 | void GModelSpatialRadialProfileDMBurkert::read(const GXmlElement& xml) |
| 290 | 290 | { |
| 291 | + // Verify number of model parameters | |
| 292 | + gammalib::xml_check_parnum(G_READ, xml, 8); | |
| 293 | + | |
| 291 | 294 | // Read DMBurkert location |
| 292 | 295 | GModelSpatialRadial::read(xml); |
| 293 | 296 | |
| ... | ... | @@ -335,6 +338,9 @@ void GModelSpatialRadialProfileDMBurkert::read(const GXmlElement& xml) |
| 335 | 338 | ***************************************************************************/ |
| 336 | 339 | void GModelSpatialRadialProfileDMBurkert::write(GXmlElement& xml) const |
| 337 | 340 | { |
| 341 | + // Verify model type | |
| 342 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 343 | + | |
| 338 | 344 | // Write DMBurkert location |
| 339 | 345 | GModelSpatialRadial::write(xml); |
| 340 | 346 | ... | ... |
src/model/GModelSpatialRadialProfileDMEinasto.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialRadialProfileDMEinasto.cpp - Einasto radial profile class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2020 by Nathan Kelley-Hoskins * | |
| 4 | + * copyright (C) 2016-2021 by Nathan Kelley-Hoskins * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -291,6 +291,9 @@ double GModelSpatialRadialProfileDMEinasto::theta_max(void) const |
| 291 | 291 | ***************************************************************************/ |
| 292 | 292 | void GModelSpatialRadialProfileDMEinasto::read(const GXmlElement& xml) |
| 293 | 293 | { |
| 294 | + // Verify number of model parameters | |
| 295 | + gammalib::xml_check_parnum(G_READ, xml, 9); | |
| 296 | + | |
| 294 | 297 | // Read DMEinasto location |
| 295 | 298 | GModelSpatialRadial::read(xml); |
| 296 | 299 | |
| ... | ... | @@ -349,6 +352,9 @@ void GModelSpatialRadialProfileDMEinasto::read(const GXmlElement& xml) |
| 349 | 352 | ***************************************************************************/ |
| 350 | 353 | void GModelSpatialRadialProfileDMEinasto::write(GXmlElement& xml) const |
| 351 | 354 | { |
| 355 | + // Verify model type | |
| 356 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 357 | + | |
| 352 | 358 | // Write DMEinasto location |
| 353 | 359 | GModelSpatialRadial::write(xml); |
| 354 | 360 | ... | ... |
src/model/GModelSpatialRadialProfileDMZhao.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialRadialProfileDMZhao.cpp - Zhao radial profile class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2020 by Nathan Kelley-Hoskins * | |
| 4 | + * copyright (C) 2016-2021 by Nathan Kelley-Hoskins * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -291,6 +291,9 @@ double GModelSpatialRadialProfileDMZhao::theta_max(void) const |
| 291 | 291 | ***************************************************************************/ |
| 292 | 292 | void GModelSpatialRadialProfileDMZhao::read(const GXmlElement& xml) |
| 293 | 293 | { |
| 294 | + // Verify number of model parameters | |
| 295 | + gammalib::xml_check_parnum(G_READ, xml, 11); | |
| 296 | + | |
| 294 | 297 | // Read halo sky coordinate |
| 295 | 298 | GModelSpatialRadial::read(xml); |
| 296 | 299 | |
| ... | ... | @@ -359,6 +362,9 @@ void GModelSpatialRadialProfileDMZhao::read(const GXmlElement& xml) |
| 359 | 362 | ***************************************************************************/ |
| 360 | 363 | void GModelSpatialRadialProfileDMZhao::write(GXmlElement& xml) const |
| 361 | 364 | { |
| 365 | + // Verify model type | |
| 366 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 367 | + | |
| 362 | 368 | // Write DMZhao location |
| 363 | 369 | GModelSpatialRadial::write(xml); |
| 364 | 370 | ... | ... |
src/model/GModelSpatialRadialProfileGauss.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialRadialProfileGauss.cpp - Gaussian radial profile class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2016-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -286,6 +286,9 @@ double GModelSpatialRadialProfileGauss::theta_max(void) const |
| 286 | 286 | ***************************************************************************/ |
| 287 | 287 | void GModelSpatialRadialProfileGauss::read(const GXmlElement& xml) |
| 288 | 288 | { |
| 289 | + // Verify number of model parameters | |
| 290 | + gammalib::xml_check_parnum(G_READ, xml, 3); | |
| 291 | + | |
| 289 | 292 | // Read Gaussian location |
| 290 | 293 | GModelSpatialRadial::read(xml); |
| 291 | 294 | |
| ... | ... | @@ -314,6 +317,9 @@ void GModelSpatialRadialProfileGauss::read(const GXmlElement& xml) |
| 314 | 317 | ***************************************************************************/ |
| 315 | 318 | void GModelSpatialRadialProfileGauss::write(GXmlElement& xml) const |
| 316 | 319 | { |
| 320 | + // Verify model type | |
| 321 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 322 | + | |
| 317 | 323 | // Write Gaussian location |
| 318 | 324 | GModelSpatialRadial::write(xml); |
| 319 | 325 | ... | ... |
src/model/GModelSpatialRadialRing.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialRadialRing.cpp - Radial ring source model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2020 by Pierrick Martin * | |
| 4 | + * copyright (C) 2020-2021 by Pierrick Martin * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -386,11 +386,6 @@ double GModelSpatialRadialRing::theta_max(void) const |
| 386 | 386 | * |
| 387 | 387 | * @param[in] xml XML element. |
| 388 | 388 | * |
| 389 | - * @exception GException::model_invalid_parnum | |
| 390 | - * Invalid number of model parameters found in XML element. | |
| 391 | - * @exception GException::model_invalid_parnames | |
| 392 | - * Invalid model parameter names found in XML element. | |
| 393 | - * | |
| 394 | 389 | * Reads the radial ring model information from an XML element. The XML |
| 395 | 390 | * element shall have either the format |
| 396 | 391 | * |
| ... | ... | @@ -415,14 +410,8 @@ double GModelSpatialRadialRing::theta_max(void) const |
| 415 | 410 | ***************************************************************************/ |
| 416 | 411 | void GModelSpatialRadialRing::read(const GXmlElement& xml) |
| 417 | 412 | { |
| 418 | - // Determine number of parameter nodes in XML element | |
| 419 | - int npars = xml.elements("parameter"); | |
| 420 | - | |
| 421 | - // Verify that XML element has exactly 4 parameters | |
| 422 | - if (xml.elements() != 4 || npars != 4) { | |
| 423 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 424 | - "Ring model requires exactly 4 parameters."); | |
| 425 | - } | |
| 413 | + // Verify number of model parameters | |
| 414 | + gammalib::xml_check_parnum(G_READ, xml, 4); | |
| 426 | 415 | |
| 427 | 416 | // Read ring center location |
| 428 | 417 | GModelSpatialRadial::read(xml); |
| ... | ... | @@ -445,11 +434,6 @@ void GModelSpatialRadialRing::read(const GXmlElement& xml) |
| 445 | 434 | * |
| 446 | 435 | * @param[in] xml XML element into which model information is written. |
| 447 | 436 | * |
| 448 | - * @exception GException::model_invalid_parnum | |
| 449 | - * Invalid number of model parameters found in XML element. | |
| 450 | - * @exception GException::model_invalid_parnames | |
| 451 | - * Invalid model parameter names found in XML element. | |
| 452 | - * | |
| 453 | 437 | * Writes the radial ring model information into an XML element. The XML |
| 454 | 438 | * element will have the format |
| 455 | 439 | * |
| ... | ... | @@ -463,6 +447,9 @@ void GModelSpatialRadialRing::read(const GXmlElement& xml) |
| 463 | 447 | ***************************************************************************/ |
| 464 | 448 | void GModelSpatialRadialRing::write(GXmlElement& xml) const |
| 465 | 449 | { |
| 450 | + // Verify model type | |
| 451 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 452 | + | |
| 466 | 453 | // Write ring center location |
| 467 | 454 | GModelSpatialRadial::write(xml); |
| 468 | 455 | ... | ... |
src/model/GModelSpatialRadialShell.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpatialRadialShell.cpp - Radial shell source model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2020 by Christoph Deil * | |
| 4 | + * copyright (C) 2011-2021 by Christoph Deil * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -435,11 +435,6 @@ double GModelSpatialRadialShell::theta_max(void) const |
| 435 | 435 | * |
| 436 | 436 | * @param[in] xml XML element. |
| 437 | 437 | * |
| 438 | - * @exception GException::model_invalid_parnum | |
| 439 | - * Invalid number of model parameters found in XML element. | |
| 440 | - * @exception GException::model_invalid_parnames | |
| 441 | - * Invalid model parameter names found in XML element. | |
| 442 | - * | |
| 443 | 438 | * Reads the radial shell model information from an XML element. The XML |
| 444 | 439 | * element shall have either the format |
| 445 | 440 | * |
| ... | ... | @@ -465,14 +460,8 @@ double GModelSpatialRadialShell::theta_max(void) const |
| 465 | 460 | ***************************************************************************/ |
| 466 | 461 | void GModelSpatialRadialShell::read(const GXmlElement& xml) |
| 467 | 462 | { |
| 468 | - // Determine number of parameter nodes in XML element | |
| 469 | - int npars = xml.elements("parameter"); | |
| 470 | - | |
| 471 | - // Verify that XML element has exactly 4 parameters | |
| 472 | - if (xml.elements() != 4 || npars != 4) { | |
| 473 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 474 | - "Shell model requires exactly 4 parameters."); | |
| 475 | - } | |
| 463 | + // Verify number of model parameters | |
| 464 | + gammalib::xml_check_parnum(G_READ, xml, 4); | |
| 476 | 465 | |
| 477 | 466 | // Read shell location |
| 478 | 467 | GModelSpatialRadial::read(xml); |
| ... | ... | @@ -495,13 +484,6 @@ void GModelSpatialRadialShell::read(const GXmlElement& xml) |
| 495 | 484 | * |
| 496 | 485 | * @param[in] xml XML element into which model information is written. |
| 497 | 486 | * |
| 498 | - * @exception GException::model_invalid_spatial | |
| 499 | - * Existing XML element is not of type 'GaussFunction' | |
| 500 | - * @exception GException::model_invalid_parnum | |
| 501 | - * Invalid number of model parameters found in XML element. | |
| 502 | - * @exception GException::model_invalid_parnames | |
| 503 | - * Invalid model parameter names found in XML element. | |
| 504 | - * | |
| 505 | 487 | * Writes the radial shell model information into an XML element. The XML |
| 506 | 488 | * element will have the format |
| 507 | 489 | * |
| ... | ... | @@ -515,6 +497,9 @@ void GModelSpatialRadialShell::read(const GXmlElement& xml) |
| 515 | 497 | ***************************************************************************/ |
| 516 | 498 | void GModelSpatialRadialShell::write(GXmlElement& xml) const |
| 517 | 499 | { |
| 500 | + // Verify model type | |
| 501 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 502 | + | |
| 518 | 503 | // Write shell location |
| 519 | 504 | GModelSpatialRadial::write(xml); |
| 520 | 505 | ... | ... |
src/model/GModelSpectral.cpp
| ... | ... | @@ -131,8 +131,8 @@ GModelSpectral& GModelSpectral::operator=(const GModelSpectral& model) |
| 131 | 131 | * |
| 132 | 132 | * @param[in] name Parameter name. |
| 133 | 133 | * |
| 134 | - * @exception GException::par_not_found | |
| 135 | - * Parameter with specified name not found in container. | |
| 134 | + * @exception GException::invalid_argument | |
| 135 | + * Parameter with specified name not found. | |
| 136 | 136 | ***************************************************************************/ |
| 137 | 137 | GModelPar& GModelSpectral::operator[](const std::string& name) |
| 138 | 138 | { |
| ... | ... | @@ -146,7 +146,9 @@ GModelPar& GModelSpectral::operator[](const std::string& name) |
| 146 | 146 | |
| 147 | 147 | // Throw exception if parameter name was not found |
| 148 | 148 | if (index >= size()) { |
| 149 | - throw GException::par_not_found(G_ACCESS, name); | |
| 149 | + std::string msg = "Model parameter \""+name+"\" not found in model. " | |
| 150 | + "Please specify a valid model parameter name."; | |
| 151 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 150 | 152 | } |
| 151 | 153 | |
| 152 | 154 | // Return reference |
| ... | ... | @@ -159,8 +161,8 @@ GModelPar& GModelSpectral::operator[](const std::string& name) |
| 159 | 161 | * |
| 160 | 162 | * @param[in] name Parameter name. |
| 161 | 163 | * |
| 162 | - * @exception GException::par_not_found | |
| 163 | - * Parameter with specified name not found in container. | |
| 164 | + * @exception GException::invalid_argument | |
| 165 | + * Parameter with specified name not found. | |
| 164 | 166 | ***************************************************************************/ |
| 165 | 167 | const GModelPar& GModelSpectral::operator[](const std::string& name) const |
| 166 | 168 | { |
| ... | ... | @@ -174,7 +176,9 @@ const GModelPar& GModelSpectral::operator[](const std::string& name) const |
| 174 | 176 | |
| 175 | 177 | // Throw exception if parameter name was not found |
| 176 | 178 | if (index >= size()) { |
| 177 | - throw GException::par_not_found(G_ACCESS, name); | |
| 179 | + std::string msg = "Model parameter \""+name+"\" not found in model. " | |
| 180 | + "Please specify a valid model parameter name."; | |
| 181 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | 184 | // Return reference | ... | ... |
src/model/GModelSpectralBins.cpp
| ... | ... | @@ -668,17 +668,8 @@ void GModelSpectralBins::read(const GXmlElement& xml) |
| 668 | 668 | ***************************************************************************/ |
| 669 | 669 | void GModelSpectralBins::write(GXmlElement& xml) const |
| 670 | 670 | { |
| 671 | - // Set model type | |
| 672 | - if (xml.attribute("type") == "") { | |
| 673 | - xml.attribute("type", type()); | |
| 674 | - } | |
| 675 | - | |
| 676 | 671 | // Verify model type |
| 677 | - if (xml.attribute("type") != type()) { | |
| 678 | - std::string msg = "Spectral model type \""+xml.attribute("type")+"\" " | |
| 679 | - "is not of type \""+type()+"\"."; | |
| 680 | - throw GException::invalid_value(G_WRITE, msg); | |
| 681 | - } | |
| 672 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 682 | 673 | |
| 683 | 674 | // Get index parameter |
| 684 | 675 | GXmlElement* index = gammalib::xml_need_par(G_WRITE, xml, m_index.name()); | ... | ... |
src/model/GModelSpectralBrokenPlaw.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralBrokenPlaw.cpp - Broken power law spectrum class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2017 by Anneli Schulz * | |
| 4 | + * copyright (C) 2013-2021 by Anneli Schulz * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -616,6 +616,9 @@ GEnergy GModelSpectralBrokenPlaw::mc(const GEnergy& emin, |
| 616 | 616 | ***************************************************************************/ |
| 617 | 617 | void GModelSpectralBrokenPlaw::read(const GXmlElement& xml) |
| 618 | 618 | { |
| 619 | + // Verify number of model parameters | |
| 620 | + gammalib::xml_check_parnum(G_READ, xml, 4); | |
| 621 | + | |
| 619 | 622 | // Get remaining XML parameters |
| 620 | 623 | const GXmlElement* prefactor = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 621 | 624 | const GXmlElement* index1 = gammalib::xml_get_par(G_READ, xml, m_index1.name()); |
| ... | ... | @@ -638,23 +641,12 @@ void GModelSpectralBrokenPlaw::read(const GXmlElement& xml) |
| 638 | 641 | * |
| 639 | 642 | * @param[in] xml XML element. |
| 640 | 643 | * |
| 641 | - * @exception GException::model_invalid_spectral | |
| 642 | - * Existing XML element is not of the expected type. | |
| 643 | - * | |
| 644 | 644 | * Writes the spectral information into an XML element. |
| 645 | 645 | ***************************************************************************/ |
| 646 | 646 | void GModelSpectralBrokenPlaw::write(GXmlElement& xml) const |
| 647 | 647 | { |
| 648 | - // Set model type | |
| 649 | - if (xml.attribute("type") == "") { | |
| 650 | - xml.attribute("type", type()); | |
| 651 | - } | |
| 652 | - | |
| 653 | 648 | // Verify model type |
| 654 | - if (xml.attribute("type") != type()) { | |
| 655 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 656 | - "Spectral model is not of type \""+type()+"\"."); | |
| 657 | - } | |
| 649 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 658 | 650 | |
| 659 | 651 | // Get XML parameters |
| 660 | 652 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelSpectralComposite.cpp
| ... | ... | @@ -423,23 +423,12 @@ void GModelSpectralComposite::read(const GXmlElement& xml) |
| 423 | 423 | * |
| 424 | 424 | * @param[in] xml XML element. |
| 425 | 425 | * |
| 426 | - * @exception GException::model_invalid_spectral | |
| 427 | - * Existing XML element is not of the expected type. | |
| 428 | - * | |
| 429 | 426 | * Writes the spectral information into an XML element. |
| 430 | 427 | ***************************************************************************/ |
| 431 | 428 | void GModelSpectralComposite::write(GXmlElement& xml) const |
| 432 | 429 | { |
| 433 | - // Set model type | |
| 434 | - if (xml.attribute("type") == "") { | |
| 435 | - xml.attribute("type", type()); | |
| 436 | - } | |
| 437 | - | |
| 438 | 430 | // Verify model type |
| 439 | - if (xml.attribute("type") != type()) { | |
| 440 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 441 | - "Spectral model is not of type \""+type()+"\"."); | |
| 442 | - } | |
| 431 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 443 | 432 | |
| 444 | 433 | // Loop over model components |
| 445 | 434 | for (int i = 0; i < m_spectral.size(); i++) { | ... | ... |
src/model/GModelSpectralConst.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralConst.cpp - Spectral constant model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2009-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -424,6 +424,9 @@ GEnergy GModelSpectralConst::mc(const GEnergy& emin, |
| 424 | 424 | ***************************************************************************/ |
| 425 | 425 | void GModelSpectralConst::read(const GXmlElement& xml) |
| 426 | 426 | { |
| 427 | + // Verify number of model parameters | |
| 428 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 429 | + | |
| 427 | 430 | // Get parameter pointers |
| 428 | 431 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 429 | 432 | |
| ... | ... | @@ -440,23 +443,12 @@ void GModelSpectralConst::read(const GXmlElement& xml) |
| 440 | 443 | * |
| 441 | 444 | * @param[in] xml XML element. |
| 442 | 445 | * |
| 443 | - * @exception GException::model_invalid_spectral | |
| 444 | - * Existing XML element is not of type "ConstantValue" | |
| 445 | - * | |
| 446 | 446 | * Writes the spectral information into an XML element. |
| 447 | 447 | ***************************************************************************/ |
| 448 | 448 | void GModelSpectralConst::write(GXmlElement& xml) const |
| 449 | 449 | { |
| 450 | - // Set model type | |
| 451 | - if (xml.attribute("type") == "") { | |
| 452 | - xml.attribute("type", type()); | |
| 453 | - } | |
| 454 | - | |
| 455 | 450 | // Verify model type |
| 456 | - if (xml.attribute("type") != type()) { | |
| 457 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 458 | - "Spectral model is not of type \""+type()+"\"."); | |
| 459 | - } | |
| 451 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 460 | 452 | |
| 461 | 453 | // Get normalisation parameter |
| 462 | 454 | GXmlElement* par = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelSpectralExpInvPlaw.cpp
| ... | ... | @@ -630,6 +630,9 @@ GEnergy GModelSpectralExpInvPlaw::mc(const GEnergy& emin, |
| 630 | 630 | ***************************************************************************/ |
| 631 | 631 | void GModelSpectralExpInvPlaw::read(const GXmlElement& xml) |
| 632 | 632 | { |
| 633 | + // Verify number of model parameters | |
| 634 | + gammalib::xml_check_parnum(G_READ, xml, 4); | |
| 635 | + | |
| 633 | 636 | // Get parameter pointers |
| 634 | 637 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 635 | 638 | const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, m_index.name()); |
| ... | ... | @@ -652,23 +655,12 @@ void GModelSpectralExpInvPlaw::read(const GXmlElement& xml) |
| 652 | 655 | * |
| 653 | 656 | * @param[in] xml XML element into which model information is written. |
| 654 | 657 | * |
| 655 | - * @exception GException::model_invalid_spectral | |
| 656 | - * Existing XML element is not of the expected type. | |
| 657 | - * | |
| 658 | 658 | * Writes the spectral information into an XML element. |
| 659 | 659 | ***************************************************************************/ |
| 660 | 660 | void GModelSpectralExpInvPlaw::write(GXmlElement& xml) const |
| 661 | 661 | { |
| 662 | - // Set model type | |
| 663 | - if (xml.attribute("type") == "") { | |
| 664 | - xml.attribute("type", type()); | |
| 665 | - } | |
| 666 | - | |
| 667 | 662 | // Verify model type |
| 668 | - if (xml.attribute("type") != type()) { | |
| 669 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 670 | - "Spectral model is not of type \""+type()+"\"."); | |
| 671 | - } | |
| 663 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 672 | 664 | |
| 673 | 665 | // Get XML parameters |
| 674 | 666 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelSpectralExpPlaw.cpp
| ... | ... | @@ -600,6 +600,9 @@ GEnergy GModelSpectralExpPlaw::mc(const GEnergy& emin, |
| 600 | 600 | ***************************************************************************/ |
| 601 | 601 | void GModelSpectralExpPlaw::read(const GXmlElement& xml) |
| 602 | 602 | { |
| 603 | + // Verify number of model parameters | |
| 604 | + gammalib::xml_check_parnum(G_READ, xml, 4); | |
| 605 | + | |
| 603 | 606 | // Get parameter pointers |
| 604 | 607 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 605 | 608 | const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, m_index.name()); |
| ... | ... | @@ -622,23 +625,12 @@ void GModelSpectralExpPlaw::read(const GXmlElement& xml) |
| 622 | 625 | * |
| 623 | 626 | * @param[in] xml XML element. |
| 624 | 627 | * |
| 625 | - * @exception GException::model_invalid_spectral | |
| 626 | - * Existing XML element is not of the expected type. | |
| 627 | - * | |
| 628 | 628 | * Writes the spectral information into an XML element. |
| 629 | 629 | ***************************************************************************/ |
| 630 | 630 | void GModelSpectralExpPlaw::write(GXmlElement& xml) const |
| 631 | 631 | { |
| 632 | - // Set model type | |
| 633 | - if (xml.attribute("type") == "") { | |
| 634 | - xml.attribute("type", type()); | |
| 635 | - } | |
| 636 | - | |
| 637 | 632 | // Verify model type |
| 638 | - if (xml.attribute("type") != type()) { | |
| 639 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 640 | - "Spectral model is not of type \""+type()+"\"."); | |
| 641 | - } | |
| 633 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 642 | 634 | |
| 643 | 635 | // Get XML parameters |
| 644 | 636 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelSpectralExponential.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralExponential.cpp - Exponential spectral model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2018-2020 by Luigi Tibaldo * | |
| 4 | + * copyright (C) 2018-2021 by Luigi Tibaldo * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -463,9 +463,6 @@ void GModelSpectralExponential::read(const GXmlElement& xml) |
| 463 | 463 | * |
| 464 | 464 | * @param[in] xml XML element. |
| 465 | 465 | * |
| 466 | - * @exception GException::model_invalid_spectral | |
| 467 | - * Existing XML element is not of the expected type. | |
| 468 | - * | |
| 469 | 466 | * Writes the spectral information into an XML element. The XML element |
| 470 | 467 | * will have the following format: |
| 471 | 468 | * |
| ... | ... | @@ -484,16 +481,8 @@ void GModelSpectralExponential::read(const GXmlElement& xml) |
| 484 | 481 | ***************************************************************************/ |
| 485 | 482 | void GModelSpectralExponential::write(GXmlElement& xml) const |
| 486 | 483 | { |
| 487 | - // Set model type | |
| 488 | - if (xml.attribute("type") == "") { | |
| 489 | - xml.attribute("type", type()); | |
| 490 | - } | |
| 491 | - | |
| 492 | 484 | // Verify model type |
| 493 | - if (xml.attribute("type") != type()) { | |
| 494 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 495 | - "Spectral model is not of type \""+type()+"\"."); | |
| 496 | - } | |
| 485 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 497 | 486 | |
| 498 | 487 | // Create a spectrum node |
| 499 | 488 | xml.append(GXmlElement("spectrum")); | ... | ... |
src/model/GModelSpectralFunc.cpp
| ... | ... | @@ -584,11 +584,6 @@ GEnergy GModelSpectralFunc::mc(const GEnergy& emin, |
| 584 | 584 | * |
| 585 | 585 | * @param[in] xml XML element containing power law model information. |
| 586 | 586 | * |
| 587 | - * @exception GException::model_invalid_parnum | |
| 588 | - * Invalid number of model parameters found in XML element. | |
| 589 | - * @exception GException::model_invalid_parnames | |
| 590 | - * Invalid model parameter name found in XML element. | |
| 591 | - * | |
| 592 | 587 | * Reads the spectral information from an XML element. The format of the XML |
| 593 | 588 | * elements is |
| 594 | 589 | * |
| ... | ... | @@ -598,23 +593,14 @@ GEnergy GModelSpectralFunc::mc(const GEnergy& emin, |
| 598 | 593 | ***************************************************************************/ |
| 599 | 594 | void GModelSpectralFunc::read(const GXmlElement& xml) |
| 600 | 595 | { |
| 601 | - // Verify that XML element has exactly 1 parameter | |
| 602 | - if (xml.elements() != 1 || xml.elements("parameter") != 1) { | |
| 603 | - throw GException::model_invalid_parnum(G_READ, xml, | |
| 604 | - "Spectral function requires exactly 1 parameter."); | |
| 605 | - } | |
| 596 | + // Verify number of model parameters | |
| 597 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 606 | 598 | |
| 607 | - // Get parameter element | |
| 608 | - const GXmlElement* par = xml.element("parameter", 0); | |
| 599 | + // Get parameter | |
| 600 | + const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); | |
| 609 | 601 | |
| 610 | - // Get value | |
| 611 | - if (par->attribute("name") == "Normalization") { | |
| 612 | - m_norm.read(*par); | |
| 613 | - } | |
| 614 | - else { | |
| 615 | - throw GException::model_invalid_parnames(G_READ, xml, | |
| 616 | - "Require \"Normalization\" parameter."); | |
| 617 | - } | |
| 602 | + // Read parameter | |
| 603 | + m_norm.read(*norm); | |
| 618 | 604 | |
| 619 | 605 | // Load nodes from file |
| 620 | 606 | load_nodes(gammalib::xml_file_expand(xml, xml.attribute("file"))); |
| ... | ... | @@ -629,13 +615,6 @@ void GModelSpectralFunc::read(const GXmlElement& xml) |
| 629 | 615 | * |
| 630 | 616 | * @param[in] xml XML element into which model information is written. |
| 631 | 617 | * |
| 632 | - * @exception GException::model_invalid_spectral | |
| 633 | - * Existing XML element is not of type "FileFunction" | |
| 634 | - * @exception GException::model_invalid_parnum | |
| 635 | - * Invalid number of model parameters or nodes found in XML element. | |
| 636 | - * @exception GException::model_invalid_parnames | |
| 637 | - * Invalid model parameter names found in XML element. | |
| 638 | - * | |
| 639 | 618 | * Writes the spectral information into an XML element. The format of the XML |
| 640 | 619 | * element is |
| 641 | 620 | * |
| ... | ... | @@ -648,39 +627,14 @@ void GModelSpectralFunc::read(const GXmlElement& xml) |
| 648 | 627 | ***************************************************************************/ |
| 649 | 628 | void GModelSpectralFunc::write(GXmlElement& xml) const |
| 650 | 629 | { |
| 651 | - // Set model type | |
| 652 | - if (xml.attribute("type") == "") { | |
| 653 | - xml.attribute("type", "FileFunction"); | |
| 654 | - } | |
| 655 | - | |
| 656 | 630 | // Verify model type |
| 657 | - if (xml.attribute("type") != "FileFunction") { | |
| 658 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 659 | - "Spectral model is not of type \"FileFunction\"."); | |
| 660 | - } | |
| 661 | - | |
| 662 | - // If XML element has 0 nodes then append 1 parameter node | |
| 663 | - if (xml.elements() == 0) { | |
| 664 | - xml.append(GXmlElement("parameter name=\"Normalization\"")); | |
| 665 | - } | |
| 666 | - | |
| 667 | - // Verify that XML element has exactly 1 parameter | |
| 668 | - if (xml.elements() != 1 || xml.elements("parameter") != 1) { | |
| 669 | - throw GException::model_invalid_parnum(G_WRITE, xml, | |
| 670 | - "Spectral function requires exactly 1 parameter."); | |
| 671 | - } | |
| 631 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 672 | 632 | |
| 673 | - // Get parameter element | |
| 674 | - GXmlElement* par = xml.element("parameter", 0); | |
| 633 | + // Get or create parameter | |
| 634 | + GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | |
| 675 | 635 | |
| 676 | - // Set parameter | |
| 677 | - if (par->attribute("name") == "Normalization") { | |
| 678 | - m_norm.write(*par); | |
| 679 | - } | |
| 680 | - else { | |
| 681 | - throw GException::model_invalid_parnames(G_WRITE, xml, | |
| 682 | - "Require \"Normalization\" parameter."); | |
| 683 | - } | |
| 636 | + // Write parameter | |
| 637 | + m_norm.write(*norm); | |
| 684 | 638 | |
| 685 | 639 | // Set file attribute |
| 686 | 640 | xml.attribute("file", gammalib::xml_file_reduce(xml, m_filename)); |
| ... | ... | @@ -1209,12 +1163,8 @@ void GModelSpectralFunc::free_members(void) |
| 1209 | 1163 | * |
| 1210 | 1164 | * @param[in] filename File name. |
| 1211 | 1165 | * |
| 1212 | - * @exception GException::file_function_data | |
| 1213 | - * File contains less than 2 nodes | |
| 1214 | - * @exception GException::file_function_columns | |
| 1215 | - * File contains less than 2 columns | |
| 1216 | - * @exception GException::file_function_value | |
| 1217 | - * File contains invalid value | |
| 1166 | + * @exception GException::invalid_value | |
| 1167 | + * Invalid file function ASCII file. | |
| 1218 | 1168 | * |
| 1219 | 1169 | * The file function is stored as a column separated value table (CSV) in an |
| 1220 | 1170 | * ASCII file with (at least) 2 columns. The first column specifies the |
| ... | ... | @@ -1245,14 +1195,22 @@ void GModelSpectralFunc::load_nodes(const GFilename& filename) |
| 1245 | 1195 | |
| 1246 | 1196 | // Check if there are at least 2 nodes |
| 1247 | 1197 | if (csv.nrows() < 2) { |
| 1248 | - throw GException::file_function_data(G_LOAD_NODES, filename.url(), | |
| 1249 | - csv.nrows()); | |
| 1198 | + std::string msg = "File function ASCII file \""+filename.url()+ | |
| 1199 | + "\" contains "+gammalib::str(csv.nrows())+ | |
| 1200 | + " rows but at least 2 rows are required. Please " | |
| 1201 | + "specify a file function ASCII file with at " | |
| 1202 | + "least two rows."; | |
| 1203 | + throw GException::invalid_value(G_LOAD_NODES, msg); | |
| 1250 | 1204 | } |
| 1251 | 1205 | |
| 1252 | 1206 | // Check if there are at least 2 columns |
| 1253 | 1207 | if (csv.ncols() < 2) { |
| 1254 | - throw GException::file_function_columns(G_LOAD_NODES, filename.url(), | |
| 1255 | - csv.ncols()); | |
| 1208 | + std::string msg = "File function ASCII file \""+filename.url()+ | |
| 1209 | + "\" contains "+gammalib::str(csv.ncols())+ | |
| 1210 | + " columns but at least 2 columns are required. " | |
| 1211 | + "Please specify a file function ASCII file with " | |
| 1212 | + "at least two columns."; | |
| 1213 | + throw GException::invalid_value(G_LOAD_NODES, msg); | |
| 1256 | 1214 | } |
| 1257 | 1215 | |
| 1258 | 1216 | // Setup nodes |
| ... | ... | @@ -1262,25 +1220,39 @@ void GModelSpectralFunc::load_nodes(const GFilename& filename) |
| 1262 | 1220 | // Get log10 of node energy and value. Make sure they are valid. |
| 1263 | 1221 | double log10energy; |
| 1264 | 1222 | double log10value; |
| 1265 | - if (csv.real(i,0) > 0) { | |
| 1223 | + if (csv.real(i,0) > 0.0) { | |
| 1266 | 1224 | log10energy = std::log10(csv.real(i,0)); |
| 1267 | 1225 | } |
| 1268 | 1226 | else { |
| 1269 | - throw GException::file_function_value(G_LOAD_NODES, filename.url(), | |
| 1270 | - csv.real(i,0), "Energy value must be positive."); | |
| 1227 | + std::string msg = "Non-positive energy "+ | |
| 1228 | + gammalib::str(csv.real(i,0))+" encountered " | |
| 1229 | + "in row "+gammalib::str(i)+" of file " | |
| 1230 | + "function ASCII file. Please specify only " | |
| 1231 | + "positive energies in file function."; | |
| 1232 | + throw GException::invalid_value(G_LOAD_NODES, msg); | |
| 1271 | 1233 | } |
| 1272 | - if (csv.real(i,1) > 0) { | |
| 1234 | + if (csv.real(i,1) > 0.0) { | |
| 1273 | 1235 | log10value = std::log10(csv.real(i,1)); |
| 1274 | 1236 | } |
| 1275 | 1237 | else { |
| 1276 | - throw GException::file_function_value(G_LOAD_NODES, filename.url(), | |
| 1277 | - csv.real(i,1), "Intensity value must be positive."); | |
| 1238 | + std::string msg = "Non-positive intensity "+ | |
| 1239 | + gammalib::str(csv.real(i,1))+" encountered " | |
| 1240 | + "in row "+gammalib::str(i)+" of file " | |
| 1241 | + "function ASCII file. Please specify only " | |
| 1242 | + "positive intensities in file function."; | |
| 1243 | + throw GException::invalid_value(G_LOAD_NODES, msg); | |
| 1278 | 1244 | } |
| 1279 | 1245 | |
| 1280 | 1246 | // Make sure that energies are increasing |
| 1281 | 1247 | if (csv.real(i,0) <= last_energy) { |
| 1282 | - throw GException::file_function_value(G_LOAD_NODES, filename.url(), | |
| 1283 | - csv.real(i,0), "Energy values must be monotonically increasing."); | |
| 1248 | + std::string msg = "Energy "+gammalib::str(csv.real(i,0))+ | |
| 1249 | + "in row "+gammalib::str(i)+" of file " | |
| 1250 | + "function ASCII file is equal or smaller " | |
| 1251 | + "than preceding energy "+ | |
| 1252 | + gammalib::str(last_energy)+". Please specify " | |
| 1253 | + "monotonically increasing energies in the " | |
| 1254 | + "file function ASCII file."; | |
| 1255 | + throw GException::invalid_value(G_LOAD_NODES, msg); | |
| 1284 | 1256 | } |
| 1285 | 1257 | |
| 1286 | 1258 | // Append log10 of node energy and value | ... | ... |
src/model/GModelSpectralGauss.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralGauss.cpp - Spectral Gaussian model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2014-2019 by Christoph Deil & Ellis Owen * | |
| 4 | + * copyright (C) 2014-2021 by Christoph Deil & Ellis Owen * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -485,11 +485,6 @@ GEnergy GModelSpectralGauss::mc(const GEnergy& emin, |
| 485 | 485 | * |
| 486 | 486 | * @param[in] xml XML element containing Gaussian model information. |
| 487 | 487 | * |
| 488 | - * @exception GException::model_invalid_parnum | |
| 489 | - * Invalid number of model parameters found in XML element. | |
| 490 | - * @exception GException::model_invalid_parnames | |
| 491 | - * Invalid model parameter name found in XML element. | |
| 492 | - * | |
| 493 | 488 | * Read the spectral Gaussian information from an XML element. |
| 494 | 489 | * The format of the XML elements is: |
| 495 | 490 | * |
| ... | ... | @@ -502,6 +497,9 @@ GEnergy GModelSpectralGauss::mc(const GEnergy& emin, |
| 502 | 497 | ***************************************************************************/ |
| 503 | 498 | void GModelSpectralGauss::read(const GXmlElement& xml) |
| 504 | 499 | { |
| 500 | + // Verify number of model parameters | |
| 501 | + gammalib::xml_check_parnum(G_READ, xml, 3); | |
| 502 | + | |
| 505 | 503 | // Get parameters |
| 506 | 504 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 507 | 505 | const GXmlElement* mean = gammalib::xml_get_par(G_READ, xml, m_mean.name()); |
| ... | ... | @@ -522,13 +520,6 @@ void GModelSpectralGauss::read(const GXmlElement& xml) |
| 522 | 520 | * |
| 523 | 521 | * @param[in] xml XML element into which model information is written. |
| 524 | 522 | * |
| 525 | - * @exception GException::model_invalid_spectral | |
| 526 | - * Existing XML element is not of type "Gaussian" | |
| 527 | - * @exception GException::model_invalid_parnum | |
| 528 | - * Invalid number of model parameters or nodes found in XML element. | |
| 529 | - * @exception GException::model_invalid_parnames | |
| 530 | - * Invalid model parameter names found in XML element. | |
| 531 | - * | |
| 532 | 523 | * Writes the spectral information into an XML element. The format of the XML |
| 533 | 524 | * element is |
| 534 | 525 | * |
| ... | ... | @@ -540,16 +531,8 @@ void GModelSpectralGauss::read(const GXmlElement& xml) |
| 540 | 531 | ***************************************************************************/ |
| 541 | 532 | void GModelSpectralGauss::write(GXmlElement& xml) const |
| 542 | 533 | { |
| 543 | - // Set model type | |
| 544 | - if (xml.attribute("type") == "") { | |
| 545 | - xml.attribute("type", type()); | |
| 546 | - } | |
| 547 | - | |
| 548 | 534 | // Verify model type |
| 549 | - if (xml.attribute("type") != type()) { | |
| 550 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 551 | - "Spectral model is not of type \""+type()+"\"."); | |
| 552 | - } | |
| 535 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 553 | 536 | |
| 554 | 537 | // Get XML parameters |
| 555 | 538 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelSpectralLogParabola.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralLogParabola.cpp - Log parabola spectral model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2012-2016 by Michael Mayer * | |
| 4 | + * copyright (C) 2012-2021 by Michael Mayer * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -578,6 +578,9 @@ GEnergy GModelSpectralLogParabola::mc(const GEnergy& emin, |
| 578 | 578 | ***************************************************************************/ |
| 579 | 579 | void GModelSpectralLogParabola::read(const GXmlElement& xml) |
| 580 | 580 | { |
| 581 | + // Verify number of model parameters | |
| 582 | + gammalib::xml_check_parnum(G_READ, xml, 4); | |
| 583 | + | |
| 581 | 584 | // Get parameter pointers |
| 582 | 585 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 583 | 586 | const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, m_index.name()); |
| ... | ... | @@ -612,23 +615,12 @@ void GModelSpectralLogParabola::read(const GXmlElement& xml) |
| 612 | 615 | * |
| 613 | 616 | * @param[in] xml XML element. |
| 614 | 617 | * |
| 615 | - * @exception GException::model_invalid_spectral | |
| 616 | - * Existing XML element is not of type "LogParabola" | |
| 617 | - * | |
| 618 | 618 | * Write the LogParabola model information into an XML element. |
| 619 | 619 | ***************************************************************************/ |
| 620 | 620 | void GModelSpectralLogParabola::write(GXmlElement& xml) const |
| 621 | 621 | { |
| 622 | - // Set model type | |
| 623 | - if (xml.attribute("type") == "") { | |
| 624 | - xml.attribute("type", type()); | |
| 625 | - } | |
| 626 | - | |
| 627 | 622 | // Verify model type |
| 628 | - if (xml.attribute("type") != type()) { | |
| 629 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 630 | - "Spectral model is not of type \""+type()+"\"."); | |
| 631 | - } | |
| 623 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 632 | 624 | |
| 633 | 625 | // Check if parameters are Fermi/LAT style and need to be negated |
| 634 | 626 | GModelPar inx = m_index; | ... | ... |
src/model/GModelSpectralMultiplicative.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralMultiplicative.cpp - Multiplicative spectral model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2020 by Michael Mayer * | |
| 4 | + * copyright (C) 2016-2021 by Michael Mayer * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -469,23 +469,12 @@ void GModelSpectralMultiplicative::read(const GXmlElement& xml) |
| 469 | 469 | * |
| 470 | 470 | * @param[in] xml XML element. |
| 471 | 471 | * |
| 472 | - * @exception GException::model_invalid_spectral | |
| 473 | - * Existing XML element is not of the expected type. | |
| 474 | - * | |
| 475 | 472 | * Writes the spectral information into an XML element. |
| 476 | 473 | ***************************************************************************/ |
| 477 | 474 | void GModelSpectralMultiplicative::write(GXmlElement& xml) const |
| 478 | 475 | { |
| 479 | - // Set model type | |
| 480 | - if (xml.attribute("type") == "") { | |
| 481 | - xml.attribute("type", type()); | |
| 482 | - } | |
| 483 | - | |
| 484 | 476 | // Verify model type |
| 485 | - if (xml.attribute("type") != type()) { | |
| 486 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 487 | - "Spectral model is not of type \""+type()+"\"."); | |
| 488 | - } | |
| 477 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 489 | 478 | |
| 490 | 479 | // Loop over model components |
| 491 | 480 | for (int i = 0; i < m_spectral.size(); i++) { |
| ... | ... | @@ -630,6 +619,9 @@ const GModelSpectral* GModelSpectralMultiplicative::component(const int& index) |
| 630 | 619 | * @param[in] name Name of spectral component. |
| 631 | 620 | * @return Pointer to spectral model. |
| 632 | 621 | * |
| 622 | + * @exception GException::invalid_argument | |
| 623 | + * Model component not found. | |
| 624 | + * | |
| 633 | 625 | * Returns a component of the multiplicative spectral model by @p name. |
| 634 | 626 | ***************************************************************************/ |
| 635 | 627 | const GModelSpectral* GModelSpectralMultiplicative::component(const std::string& name) const |
| ... | ... | @@ -645,7 +637,9 @@ const GModelSpectral* GModelSpectralMultiplicative::component(const std::string& |
| 645 | 637 | |
| 646 | 638 | // Check if component name was found |
| 647 | 639 | if (index == -1) { |
| 648 | - throw GException::model_not_found(G_COMPONENT_NAME, name); | |
| 640 | + std::string msg = "Model component \""+name+"\" not found. Please " | |
| 641 | + "specify a valid model component name."; | |
| 642 | + throw GException::invalid_argument(G_COMPONENT_NAME, msg); | |
| 649 | 643 | } |
| 650 | 644 | |
| 651 | 645 | // Return spectral component | ... | ... |
src/model/GModelSpectralNodes.cpp
| ... | ... | @@ -598,10 +598,8 @@ GEnergy GModelSpectralNodes::mc(const GEnergy& emin, |
| 598 | 598 | * |
| 599 | 599 | * @param[in] xml XML element. |
| 600 | 600 | * |
| 601 | - * @exception GException::model_invalid_parnum | |
| 602 | - * Invalid number of model parameters found in XML element. | |
| 603 | - * @exception GException::model_invalid_parnames | |
| 604 | - * Invalid model parameter name found in XML element. | |
| 601 | + * @exception GException::invalid_value | |
| 602 | + * Not enough nodes in node function. | |
| 605 | 603 | * @exception GException::invalid_value |
| 606 | 604 | * Energy or intensity are not positive. |
| 607 | 605 | * |
| ... | ... | @@ -622,6 +620,7 @@ GEnergy GModelSpectralNodes::mc(const GEnergy& emin, |
| 622 | 620 | * |
| 623 | 621 | * @todo Check that nodes are ordered |
| 624 | 622 | * @todo Check that energy boundaries are not overlapping |
| 623 | + * @todo Check whether we require at least one or two nodes | |
| 625 | 624 | ***************************************************************************/ |
| 626 | 625 | void GModelSpectralNodes::read(const GXmlElement& xml) |
| 627 | 626 | { |
| ... | ... | @@ -634,9 +633,10 @@ void GModelSpectralNodes::read(const GXmlElement& xml) |
| 634 | 633 | |
| 635 | 634 | // Throw an error if there not at least two nodes |
| 636 | 635 | if (nodes < 1) { |
| 637 | - std::string message = "Node function model requires at least two" | |
| 638 | - " nodes."; | |
| 639 | - throw GException::model_invalid_parnum(G_READ, xml, message); | |
| 636 | + std::string msg = "Node function model contains "+gammalib::str(nodes)+ | |
| 637 | + " but requires at least one node. Please specify at " | |
| 638 | + "least one node."; | |
| 639 | + throw GException::invalid_value(G_READ, msg); | |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | // Loop over all nodes |
| ... | ... | @@ -710,10 +710,8 @@ void GModelSpectralNodes::read(const GXmlElement& xml) |
| 710 | 710 | * |
| 711 | 711 | * @param[in] xml XML element into which model information is written. |
| 712 | 712 | * |
| 713 | - * @exception GException::model_invalid_spectral | |
| 714 | - * Existing XML element is not of required type | |
| 715 | - * @exception GException::model_invalid_parnum | |
| 716 | - * Invalid number of model parameters or nodes found in XML element. | |
| 713 | + * @exception GException::invalid_value | |
| 714 | + * Invalid number of nodes found in XML element. | |
| 717 | 715 | * |
| 718 | 716 | * Writes the spectral information into an XML element. The format of the XML |
| 719 | 717 | * element is |
| ... | ... | @@ -735,16 +733,8 @@ void GModelSpectralNodes::write(GXmlElement& xml) const |
| 735 | 733 | // Determine number of nodes |
| 736 | 734 | int nodes = m_energies.size(); |
| 737 | 735 | |
| 738 | - // Set model type | |
| 739 | - if (xml.attribute("type") == "") { | |
| 740 | - xml.attribute("type", type()); | |
| 741 | - } | |
| 742 | - | |
| 743 | 736 | // Verify model type |
| 744 | - if (xml.attribute("type") != type()) { | |
| 745 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 746 | - "Spectral model is not of type \""+type()+"\"."); | |
| 747 | - } | |
| 737 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 748 | 738 | |
| 749 | 739 | // If XML element has 0 nodes then append nodes |
| 750 | 740 | if (xml.elements() == 0) { |
| ... | ... | @@ -754,10 +744,20 @@ void GModelSpectralNodes::write(GXmlElement& xml) const |
| 754 | 744 | } |
| 755 | 745 | |
| 756 | 746 | // Verify that XML element has the required number of nodes |
| 757 | - if (xml.elements() != nodes || xml.elements("node") != nodes) { | |
| 758 | - std::string message = "Spectral model requires exactly " + | |
| 759 | - gammalib::str(nodes) + " nodes."; | |
| 760 | - throw GException::model_invalid_parnum(G_WRITE, xml, message); | |
| 747 | + if (xml.elements() != nodes) { | |
| 748 | + std::string msg = "Number of "+gammalib::str(xml.elements())+ | |
| 749 | + " child elements in XML file does not correspond " | |
| 750 | + "to expected number of "+gammalib::str(nodes)+ | |
| 751 | + " elements. Please verify the XML format."; | |
| 752 | + throw GException::invalid_value(G_WRITE, msg); | |
| 753 | + } | |
| 754 | + int npars = xml.elements("node"); | |
| 755 | + if (npars != nodes) { | |
| 756 | + std::string msg = "Number of "+gammalib::str(npars)+" \"node\" " | |
| 757 | + "child elements in XML file does not correspond to " | |
| 758 | + "expected number of "+gammalib::str(nodes)+ | |
| 759 | + " elements. Please verify the XML format."; | |
| 760 | + throw GException::invalid_value(G_WRITE, msg); | |
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | // Loop over all nodes | ... | ... |
src/model/GModelSpectralPlaw.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralPlaw.cpp - Spectral power law model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2009-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -513,6 +513,9 @@ GEnergy GModelSpectralPlaw::mc(const GEnergy& emin, |
| 513 | 513 | ***************************************************************************/ |
| 514 | 514 | void GModelSpectralPlaw::read(const GXmlElement& xml) |
| 515 | 515 | { |
| 516 | + // Verify number of model parameters | |
| 517 | + gammalib::xml_check_parnum(G_READ, xml, 3); | |
| 518 | + | |
| 516 | 519 | // Get parameter pointers |
| 517 | 520 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 518 | 521 | const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, m_index.name()); |
| ... | ... | @@ -533,23 +536,12 @@ void GModelSpectralPlaw::read(const GXmlElement& xml) |
| 533 | 536 | * |
| 534 | 537 | * @param[in] xml XML element. |
| 535 | 538 | * |
| 536 | - * @exception GException::model_invalid_spectral | |
| 537 | - * Existing XML element is not of the expected type. | |
| 538 | - * | |
| 539 | 539 | * Writes the spectral information into an XML element. |
| 540 | 540 | ***************************************************************************/ |
| 541 | 541 | void GModelSpectralPlaw::write(GXmlElement& xml) const |
| 542 | 542 | { |
| 543 | - // Set model type | |
| 544 | - if (xml.attribute("type") == "") { | |
| 545 | - xml.attribute("type", type()); | |
| 546 | - } | |
| 547 | - | |
| 548 | 543 | // Verify model type |
| 549 | - if (xml.attribute("type") != type()) { | |
| 550 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 551 | - "Spectral model is not of type \""+type()+"\"."); | |
| 552 | - } | |
| 544 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 553 | 545 | |
| 554 | 546 | // Get XML parameters |
| 555 | 547 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelSpectralPlawEnergyFlux.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralPlawEnergyFlux.cpp - Spectral power law model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2016-2020 by Michael Mayer * | |
| 4 | + * copyright (C) 2016-2021 by Michael Mayer * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -567,6 +567,9 @@ GEnergy GModelSpectralPlawEnergyFlux::mc(const GEnergy& emin, |
| 567 | 567 | ***************************************************************************/ |
| 568 | 568 | void GModelSpectralPlawEnergyFlux::read(const GXmlElement& xml) |
| 569 | 569 | { |
| 570 | + // Verify number of model parameters | |
| 571 | + gammalib::xml_check_parnum(G_READ, xml, 4); | |
| 572 | + | |
| 570 | 573 | // Get parameter pointers |
| 571 | 574 | const GXmlElement* eflux = gammalib::xml_get_par(G_READ, xml, m_eflux.name()); |
| 572 | 575 | const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, m_index.name()); |
| ... | ... | @@ -589,23 +592,12 @@ void GModelSpectralPlawEnergyFlux::read(const GXmlElement& xml) |
| 589 | 592 | * |
| 590 | 593 | * @param[in] xml XML element. |
| 591 | 594 | * |
| 592 | - * @exception GException::model_invalid_spectral | |
| 593 | - * Existing XML element is not of type "PowerLaw" | |
| 594 | - * | |
| 595 | 595 | * Writes the spectral information into an XML element. |
| 596 | 596 | ***************************************************************************/ |
| 597 | 597 | void GModelSpectralPlawEnergyFlux::write(GXmlElement& xml) const |
| 598 | 598 | { |
| 599 | - // Set model type | |
| 600 | - if (xml.attribute("type") == "") { | |
| 601 | - xml.attribute("type", type()); | |
| 602 | - } | |
| 603 | - | |
| 604 | 599 | // Verify model type |
| 605 | - if (xml.attribute("type") != type()) { | |
| 606 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 607 | - "Spectral model is not of type \""+type()+"\"."); | |
| 608 | - } | |
| 600 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 609 | 601 | |
| 610 | 602 | // Get XML parameters |
| 611 | 603 | GXmlElement* eflux = gammalib::xml_need_par(G_WRITE, xml, m_eflux.name()); | ... | ... |
src/model/GModelSpectralPlawPhotonFlux.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelSpectralPlawPhotonFlux.cpp - Spectral power law model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -577,6 +577,9 @@ GEnergy GModelSpectralPlawPhotonFlux::mc(const GEnergy& emin, |
| 577 | 577 | ***************************************************************************/ |
| 578 | 578 | void GModelSpectralPlawPhotonFlux::read(const GXmlElement& xml) |
| 579 | 579 | { |
| 580 | + // Verify number of model parameters | |
| 581 | + gammalib::xml_check_parnum(G_READ, xml, 4); | |
| 582 | + | |
| 580 | 583 | // Get parameter pointers |
| 581 | 584 | const GXmlElement* flux = gammalib::xml_get_par(G_READ, xml, m_flux.name()); |
| 582 | 585 | const GXmlElement* index = gammalib::xml_get_par(G_READ, xml, m_index.name()); |
| ... | ... | @@ -599,23 +602,12 @@ void GModelSpectralPlawPhotonFlux::read(const GXmlElement& xml) |
| 599 | 602 | * |
| 600 | 603 | * @param[in] xml XML element. |
| 601 | 604 | * |
| 602 | - * @exception GException::model_invalid_spectral | |
| 603 | - * Existing XML element is not of type "PowerLaw" | |
| 604 | - * | |
| 605 | 605 | * Writes the spectral information into an XML element. |
| 606 | 606 | ***************************************************************************/ |
| 607 | 607 | void GModelSpectralPlawPhotonFlux::write(GXmlElement& xml) const |
| 608 | 608 | { |
| 609 | - // Set model type | |
| 610 | - if (xml.attribute("type") == "") { | |
| 611 | - xml.attribute("type", type()); | |
| 612 | - } | |
| 613 | - | |
| 614 | 609 | // Verify model type |
| 615 | - if (xml.attribute("type") != type()) { | |
| 616 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 617 | - "Spectral model is not of type \""+type()+"\"."); | |
| 618 | - } | |
| 610 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 619 | 611 | |
| 620 | 612 | // Get XML parameters |
| 621 | 613 | GXmlElement* flux = gammalib::xml_need_par(G_WRITE, xml, m_flux.name()); | ... | ... |
src/model/GModelSpectralSmoothBrokenPlaw.cpp
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | * GModelSpectralSmoothBrokenPlaw.cpp * |
| 3 | 3 | * Smoothly broken power law spectrum class * |
| 4 | 4 | * ----------------------------------------------------------------------- * |
| 5 | - * copyright (C) 2017-2018 by Joshua Cardenzana * | |
| 5 | + * copyright (C) 2017-2021 by Joshua Cardenzana * | |
| 6 | 6 | * ----------------------------------------------------------------------- * |
| 7 | 7 | * * |
| 8 | 8 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -623,6 +623,9 @@ GEnergy GModelSpectralSmoothBrokenPlaw::mc(const GEnergy& emin, |
| 623 | 623 | ***************************************************************************/ |
| 624 | 624 | void GModelSpectralSmoothBrokenPlaw::read(const GXmlElement& xml) |
| 625 | 625 | { |
| 626 | + // Verify number of model parameters | |
| 627 | + gammalib::xml_check_parnum(G_READ, xml, 6); | |
| 628 | + | |
| 626 | 629 | // Get remaining XML parameters |
| 627 | 630 | const GXmlElement* prefactor = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 628 | 631 | const GXmlElement* index1 = gammalib::xml_get_par(G_READ, xml, m_index1.name()); |
| ... | ... | @@ -649,24 +652,13 @@ void GModelSpectralSmoothBrokenPlaw::read(const GXmlElement& xml) |
| 649 | 652 | * |
| 650 | 653 | * @param[in] xml XML element. |
| 651 | 654 | * |
| 652 | - * @exception GException::model_invalid_spectral | |
| 653 | - * Existing XML element is not of the expected type. | |
| 654 | - * | |
| 655 | 655 | * Writes the spectral information into an XML element. |
| 656 | 656 | ***************************************************************************/ |
| 657 | 657 | void GModelSpectralSmoothBrokenPlaw::write(GXmlElement& xml) const |
| 658 | 658 | { |
| 659 | - // Set model type | |
| 660 | - if (xml.attribute("type") == "") { | |
| 661 | - xml.attribute("type", type()); | |
| 662 | - } | |
| 663 | - | |
| 664 | 659 | // Verify model type |
| 665 | - if (xml.attribute("type") != type()) { | |
| 666 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 667 | - "Spectral model is not of type \""+type()+"\"."); | |
| 668 | - } | |
| 669 | - | |
| 660 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 661 | + | |
| 670 | 662 | // Get XML parameters |
| 671 | 663 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); |
| 672 | 664 | GXmlElement* index1 = gammalib::xml_need_par(G_WRITE, xml, m_index1.name()); | ... | ... |
src/model/GModelSpectralSuperExpPlaw.cpp
| ... | ... | @@ -625,6 +625,9 @@ GEnergy GModelSpectralSuperExpPlaw::mc(const GEnergy& emin, |
| 625 | 625 | ***************************************************************************/ |
| 626 | 626 | void GModelSpectralSuperExpPlaw::read(const GXmlElement& xml) |
| 627 | 627 | { |
| 628 | + // Verify number of model parameters | |
| 629 | + gammalib::xml_check_parnum(G_READ, xml, 5); | |
| 630 | + | |
| 628 | 631 | // Get parameter pointers |
| 629 | 632 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 630 | 633 | const GXmlElement* index1 = gammalib::xml_get_par(G_READ, xml, m_index1.name()); |
| ... | ... | @@ -649,23 +652,12 @@ void GModelSpectralSuperExpPlaw::read(const GXmlElement& xml) |
| 649 | 652 | * |
| 650 | 653 | * @param[in] xml XML element. |
| 651 | 654 | * |
| 652 | - * @exception GException::model_invalid_spectral | |
| 653 | - * Existing XML element is not of the expected type. | |
| 654 | - * | |
| 655 | 655 | * Writes the spectral information into an XML element. |
| 656 | 656 | ***************************************************************************/ |
| 657 | 657 | void GModelSpectralSuperExpPlaw::write(GXmlElement& xml) const |
| 658 | 658 | { |
| 659 | - // Set model type | |
| 660 | - if (xml.attribute("type") == "") { | |
| 661 | - xml.attribute("type", type()); | |
| 662 | - } | |
| 663 | - | |
| 664 | 659 | // Verify model type |
| 665 | - if (xml.attribute("type") != type()) { | |
| 666 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 667 | - "Spectral model is not of type \""+type()+"\"."); | |
| 668 | - } | |
| 660 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 669 | 661 | |
| 670 | 662 | // Get XML parameters |
| 671 | 663 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelSpectralTable.cpp
| ... | ... | @@ -704,11 +704,6 @@ GEnergy GModelSpectralTable::mc(const GEnergy& emin, |
| 704 | 704 | * |
| 705 | 705 | * @param[in] xml XML element containing power law model information. |
| 706 | 706 | * |
| 707 | - * @exception GException::model_invalid_parnum | |
| 708 | - * Invalid number of model parameters found in XML element. | |
| 709 | - * @exception GException::model_invalid_parnames | |
| 710 | - * Invalid model parameter name found in XML element. | |
| 711 | - * | |
| 712 | 707 | * Reads the spectral information from an XML element. The format of the XML |
| 713 | 708 | * elements is |
| 714 | 709 | * |
| ... | ... | @@ -749,13 +744,6 @@ void GModelSpectralTable::read(const GXmlElement& xml) |
| 749 | 744 | * |
| 750 | 745 | * @param[in] xml XML element into which model information is written. |
| 751 | 746 | * |
| 752 | - * @exception GException::model_invalid_spectral | |
| 753 | - * Existing XML element is not of type "FileFunction" | |
| 754 | - * @exception GException::model_invalid_parnum | |
| 755 | - * Invalid number of model parameters or nodes found in XML element. | |
| 756 | - * @exception GException::model_invalid_parnames | |
| 757 | - * Invalid model parameter names found in XML element. | |
| 758 | - * | |
| 759 | 747 | * Writes the spectral information into an XML element. The format of the XML |
| 760 | 748 | * element is |
| 761 | 749 | * |
| ... | ... | @@ -771,16 +759,8 @@ void GModelSpectralTable::read(const GXmlElement& xml) |
| 771 | 759 | ***************************************************************************/ |
| 772 | 760 | void GModelSpectralTable::write(GXmlElement& xml) const |
| 773 | 761 | { |
| 774 | - // Set model type | |
| 775 | - if (xml.attribute("type") == "") { | |
| 776 | - xml.attribute("type", type()); | |
| 777 | - } | |
| 778 | - | |
| 779 | 762 | // Verify model type |
| 780 | - if (xml.attribute("type") != type()) { | |
| 781 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 782 | - "Spectral model is not of type \""+type()+"\"."); | |
| 783 | - } | |
| 763 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 784 | 764 | |
| 785 | 765 | // Get normalisation parameter |
| 786 | 766 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelTemporal.cpp
| ... | ... | @@ -130,21 +130,25 @@ GModelTemporal& GModelTemporal::operator=(const GModelTemporal& model) |
| 130 | 130 | * |
| 131 | 131 | * @param[in] name Parameter name. |
| 132 | 132 | * |
| 133 | - * @exception GException::par_not_found | |
| 134 | - * Parameter with specified name not found in container. | |
| 133 | + * @exception GException::invalid_argument | |
| 134 | + * Parameter with specified name not found. | |
| 135 | 135 | ***************************************************************************/ |
| 136 | 136 | GModelPar& GModelTemporal::operator[](const std::string& name) |
| 137 | 137 | { |
| 138 | 138 | // Get parameter index |
| 139 | 139 | int index = 0; |
| 140 | 140 | for (; index < size(); ++index) { |
| 141 | - if (m_pars[index]->name() == name) | |
| 141 | + if (m_pars[index]->name() == name) { | |
| 142 | 142 | break; |
| 143 | + } | |
| 143 | 144 | } |
| 144 | 145 | |
| 145 | 146 | // Throw exception if parameter name was not found |
| 146 | - if (index >= size()) | |
| 147 | - throw GException::par_not_found(G_ACCESS, name); | |
| 147 | + if (index >= size()) { | |
| 148 | + std::string msg = "Model parameter \""+name+"\" not found in model. " | |
| 149 | + "Please specify a valid model parameter name."; | |
| 150 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 151 | + } | |
| 148 | 152 | |
| 149 | 153 | // Return reference |
| 150 | 154 | return *(m_pars[index]); |
| ... | ... | @@ -156,21 +160,25 @@ GModelPar& GModelTemporal::operator[](const std::string& name) |
| 156 | 160 | * |
| 157 | 161 | * @param[in] name Parameter name. |
| 158 | 162 | * |
| 159 | - * @exception GException::par_not_found | |
| 160 | - * Parameter with specified name not found in container. | |
| 163 | + * @exception GException::invalid_argument | |
| 164 | + * Parameter with specified name not found. | |
| 161 | 165 | ***************************************************************************/ |
| 162 | 166 | const GModelPar& GModelTemporal::operator[](const std::string& name) const |
| 163 | 167 | { |
| 164 | 168 | // Get parameter index |
| 165 | 169 | int index = 0; |
| 166 | 170 | for (; index < size(); ++index) { |
| 167 | - if (m_pars[index]->name() == name) | |
| 171 | + if (m_pars[index]->name() == name) { | |
| 168 | 172 | break; |
| 173 | + } | |
| 169 | 174 | } |
| 170 | 175 | |
| 171 | 176 | // Throw exception if parameter name was not found |
| 172 | - if (index >= size()) | |
| 173 | - throw GException::par_not_found(G_ACCESS, name); | |
| 177 | + if (index >= size()) { | |
| 178 | + std::string msg = "Model parameter \""+name+"\" not found in model. " | |
| 179 | + "Please specify a valid model parameter name."; | |
| 180 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 181 | + } | |
| 174 | 182 | |
| 175 | 183 | // Return reference |
| 176 | 184 | return *(m_pars[index]); | ... | ... |
src/model/GModelTemporalConst.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelTemporalConst.cpp - Temporal constant model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2009-2018 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2009-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -315,9 +315,6 @@ GTimes GModelTemporalConst::mc(const double& rate, const GTime& tmin, |
| 315 | 315 | * |
| 316 | 316 | * @param[in] xml XML element. |
| 317 | 317 | * |
| 318 | - * @exception GExpection::invalid_value | |
| 319 | - * Invalid XML format encountered. | |
| 320 | - * | |
| 321 | 318 | * Writes the temporal information from an XML element having the format |
| 322 | 319 | * |
| 323 | 320 | * <temporal type="Constant"> |
| ... | ... | @@ -326,6 +323,9 @@ GTimes GModelTemporalConst::mc(const double& rate, const GTime& tmin, |
| 326 | 323 | ***************************************************************************/ |
| 327 | 324 | void GModelTemporalConst::read(const GXmlElement& xml) |
| 328 | 325 | { |
| 326 | + // Verify number of model parameters | |
| 327 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 328 | + | |
| 329 | 329 | // Get parameter pointers |
| 330 | 330 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 331 | 331 | |
| ... | ... | @@ -342,9 +342,6 @@ void GModelTemporalConst::read(const GXmlElement& xml) |
| 342 | 342 | * |
| 343 | 343 | * @param[in] xml XML element. |
| 344 | 344 | * |
| 345 | - * @exception GExpection::invalid_value | |
| 346 | - * Invalid XML format encountered. | |
| 347 | - * | |
| 348 | 345 | * Writes the temporal information into an XML element in the format |
| 349 | 346 | * |
| 350 | 347 | * <temporal type="Constant"> |
| ... | ... | @@ -353,16 +350,8 @@ void GModelTemporalConst::read(const GXmlElement& xml) |
| 353 | 350 | ***************************************************************************/ |
| 354 | 351 | void GModelTemporalConst::write(GXmlElement& xml) const |
| 355 | 352 | { |
| 356 | - // Set model type | |
| 357 | - if (xml.attribute("type") == "") { | |
| 358 | - xml.attribute("type", type()); | |
| 359 | - } | |
| 360 | - | |
| 361 | 353 | // Verify model type |
| 362 | - if (xml.attribute("type") != type()) { | |
| 363 | - throw GException::model_invalid_spectral(G_WRITE, xml.attribute("type"), | |
| 364 | - "Temporal model is not of type \""+type()+"\"."); | |
| 365 | - } | |
| 354 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 366 | 355 | |
| 367 | 356 | // Get XML parameters |
| 368 | 357 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelTemporalLightCurve.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GModelTemporalLightCurve.cpp - Temporal light curve model class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2017-2020 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2017-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -373,6 +373,9 @@ GTimes GModelTemporalLightCurve::mc(const double& rate, const GTime& tmin, |
| 373 | 373 | ***************************************************************************/ |
| 374 | 374 | void GModelTemporalLightCurve::read(const GXmlElement& xml) |
| 375 | 375 | { |
| 376 | + // Verify number of model parameters | |
| 377 | + gammalib::xml_check_parnum(G_READ, xml, 1); | |
| 378 | + | |
| 376 | 379 | // Get parameter pointers |
| 377 | 380 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 378 | 381 | |
| ... | ... | @@ -392,9 +395,6 @@ void GModelTemporalLightCurve::read(const GXmlElement& xml) |
| 392 | 395 | * |
| 393 | 396 | * @param[in] xml XML element. |
| 394 | 397 | * |
| 395 | - * @exception GExpection::invalid_value | |
| 396 | - * Invalid XML format encountered. | |
| 397 | - * | |
| 398 | 398 | * Writes the temporal information into an XML element in the format |
| 399 | 399 | * |
| 400 | 400 | * <temporalModel type="LightCurve" file=".."> |
| ... | ... | @@ -403,17 +403,8 @@ void GModelTemporalLightCurve::read(const GXmlElement& xml) |
| 403 | 403 | ***************************************************************************/ |
| 404 | 404 | void GModelTemporalLightCurve::write(GXmlElement& xml) const |
| 405 | 405 | { |
| 406 | - // Set model type | |
| 407 | - if (xml.attribute("type") == "") { | |
| 408 | - xml.attribute("type", type()); | |
| 409 | - } | |
| 410 | - | |
| 411 | 406 | // Verify model type |
| 412 | - if (xml.attribute("type") != type()) { | |
| 413 | - std::string msg = "Temporal model of type "+xml.attribute("type")+ | |
| 414 | - " encountered while \""+type()+"\" was expected."; | |
| 415 | - throw GException::invalid_value(G_WRITE, msg); | |
| 416 | - } | |
| 407 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 417 | 408 | |
| 418 | 409 | // Get XML parameters |
| 419 | 410 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModelTemporalPhaseCurve.cpp
| ... | ... | @@ -375,6 +375,9 @@ GTimes GModelTemporalPhaseCurve::mc(const double& rate, const GTime& tmin, |
| 375 | 375 | ***************************************************************************/ |
| 376 | 376 | void GModelTemporalPhaseCurve::read(const GXmlElement& xml) |
| 377 | 377 | { |
| 378 | + // Verify number of model parameters | |
| 379 | + gammalib::xml_check_parnum(G_READ, xml, 6); | |
| 380 | + | |
| 378 | 381 | // Get parameter pointers |
| 379 | 382 | const GXmlElement* norm = gammalib::xml_get_par(G_READ, xml, m_norm.name()); |
| 380 | 383 | const GXmlElement* mjd = gammalib::xml_get_par(G_READ, xml, m_mjd.name()); |
| ... | ... | @@ -415,9 +418,6 @@ void GModelTemporalPhaseCurve::read(const GXmlElement& xml) |
| 415 | 418 | * |
| 416 | 419 | * @param[in] xml XML element. |
| 417 | 420 | * |
| 418 | - * @exception GExpection::invalid_value | |
| 419 | - * Invalid XML format encountered. | |
| 420 | - * | |
| 421 | 421 | * Writes the temporal information into an XML element. The XML element will |
| 422 | 422 | * have the format |
| 423 | 423 | * |
| ... | ... | @@ -432,17 +432,8 @@ void GModelTemporalPhaseCurve::read(const GXmlElement& xml) |
| 432 | 432 | ***************************************************************************/ |
| 433 | 433 | void GModelTemporalPhaseCurve::write(GXmlElement& xml) const |
| 434 | 434 | { |
| 435 | - // Set model type | |
| 436 | - if (xml.attribute("type") == "") { | |
| 437 | - xml.attribute("type", type()); | |
| 438 | - } | |
| 439 | - | |
| 440 | 435 | // Verify model type |
| 441 | - if (xml.attribute("type") != type()) { | |
| 442 | - std::string msg = "Temporal model of type "+xml.attribute("type")+ | |
| 443 | - " encountered while \""+type()+"\" was expected."; | |
| 444 | - throw GException::invalid_value(G_WRITE, msg); | |
| 445 | - } | |
| 436 | + gammalib::xml_check_type(G_WRITE, xml, type()); | |
| 446 | 437 | |
| 447 | 438 | // Get XML parameters |
| 448 | 439 | GXmlElement* norm = gammalib::xml_need_par(G_WRITE, xml, m_norm.name()); | ... | ... |
src/model/GModels.cpp
| ... | ... | @@ -170,7 +170,7 @@ GModels& GModels::operator=(const GModels& models) |
| 170 | 170 | * |
| 171 | 171 | * @param[in] name Model name. |
| 172 | 172 | * |
| 173 | - * @exception GException::model_not_found | |
| 173 | + * @exception GException::invalid_argument | |
| 174 | 174 | * Model with specified name not found in container. |
| 175 | 175 | * |
| 176 | 176 | * Returns a pointer to the model with the specified @p name. |
| ... | ... | @@ -182,7 +182,9 @@ GModel* GModels::operator[](const std::string& name) |
| 182 | 182 | |
| 183 | 183 | // Throw exception if model name was not found |
| 184 | 184 | if (index == -1) { |
| 185 | - throw GException::model_not_found(G_ACCESS, name); | |
| 185 | + std::string msg = "Model \""+name+"\" not found in model container. " | |
| 186 | + "Please specify the name of an available model."; | |
| 187 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 186 | 188 | } |
| 187 | 189 | |
| 188 | 190 | // Return pointer |
| ... | ... | @@ -195,7 +197,7 @@ GModel* GModels::operator[](const std::string& name) |
| 195 | 197 | * |
| 196 | 198 | * @param[in] name Model name. |
| 197 | 199 | * |
| 198 | - * @exception GException::model_not_found | |
| 200 | + * @exception GException::invalid_argument | |
| 199 | 201 | * Model with specified name not found in container. |
| 200 | 202 | * |
| 201 | 203 | * Returns a const pointer to the model with the specified @p name. |
| ... | ... | @@ -207,7 +209,9 @@ const GModel* GModels::operator[](const std::string& name) const |
| 207 | 209 | |
| 208 | 210 | // Throw exception if model name was not found |
| 209 | 211 | if (index == -1) { |
| 210 | - throw GException::model_not_found(G_ACCESS, name); | |
| 212 | + std::string msg = "Model \""+name+"\" not found in model container. " | |
| 213 | + "Please specify the name of an available model."; | |
| 214 | + throw GException::invalid_argument(G_ACCESS, msg); | |
| 211 | 215 | } |
| 212 | 216 | |
| 213 | 217 | // Return pointer |
| ... | ... | @@ -356,7 +360,7 @@ GModel* GModels::set(const int& index, const GModel& model) |
| 356 | 360 | * @param[in] model Model pointer. |
| 357 | 361 | * @return Pointer to deep copy of model. |
| 358 | 362 | * |
| 359 | - * @exception GException::model_not_found | |
| 363 | + * @exception GException::invalid_argument | |
| 360 | 364 | * Model with specified name not found in container. |
| 361 | 365 | * @exception GException::invalid_value |
| 362 | 366 | * Name of model exists already in container. |
| ... | ... | @@ -370,7 +374,9 @@ GModel* GModels::set(const std::string& name, const GModel& model) |
| 370 | 374 | |
| 371 | 375 | // Throw exception if parameter name was not found |
| 372 | 376 | if (index == -1) { |
| 373 | - throw GException::model_not_found(G_SET2, name); | |
| 377 | + std::string msg = "Model \""+name+"\" not found in model container. " | |
| 378 | + "Please specify the name of an available model."; | |
| 379 | + throw GException::invalid_argument(G_SET2, msg); | |
| 374 | 380 | } |
| 375 | 381 | |
| 376 | 382 | // Check if a model with specified name does not yet exist |
| ... | ... | @@ -498,7 +504,7 @@ GModel* GModels::insert(const int& index, const GModel& model) |
| 498 | 504 | * @param[in] model Model. |
| 499 | 505 | * @return Pointer to deep copy of model. |
| 500 | 506 | * |
| 501 | - * @exception GException::model_not_found | |
| 507 | + * @exception GException::invalid_argument | |
| 502 | 508 | * Model with specified name not found in container. |
| 503 | 509 | * @exception GException::invalid_value |
| 504 | 510 | * Name of model exists already in container. |
| ... | ... | @@ -513,7 +519,9 @@ GModel* GModels::insert(const std::string& name, const GModel& model) |
| 513 | 519 | |
| 514 | 520 | // Throw exception if parameter name was not found |
| 515 | 521 | if (index == -1) { |
| 516 | - throw GException::model_not_found(G_INSERT2, name); | |
| 522 | + std::string msg = "Model \""+name+"\" not found in model container. " | |
| 523 | + "Please specify the name of an available model."; | |
| 524 | + throw GException::invalid_argument(G_INSERT2, msg); | |
| 517 | 525 | } |
| 518 | 526 | |
| 519 | 527 | // Check if a model with specified name does not yet exist |
| ... | ... | @@ -575,7 +583,7 @@ void GModels::remove(const int& index) |
| 575 | 583 | * |
| 576 | 584 | * @param[in] name Model name. |
| 577 | 585 | * |
| 578 | - * @exception GException::model_not_found | |
| 586 | + * @exception GException::invalid_argument | |
| 579 | 587 | * Model with specified name not found in container. |
| 580 | 588 | * |
| 581 | 589 | * Remove model of specified @p name from container. |
| ... | ... | @@ -587,7 +595,9 @@ void GModels::remove(const std::string& name) |
| 587 | 595 | |
| 588 | 596 | // Throw exception if parameter name was not found |
| 589 | 597 | if (index == -1) { |
| 590 | - throw GException::model_not_found(G_REMOVE2, name); | |
| 598 | + std::string msg = "Model \""+name+"\" not found in model container. " | |
| 599 | + "Please specify the name of an available model."; | |
| 600 | + throw GException::invalid_argument(G_REMOVE2, msg); | |
| 591 | 601 | } |
| 592 | 602 | |
| 593 | 603 | // Delete model |
| ... | ... | @@ -739,7 +749,7 @@ void GModels::save(const GFilename& filename) const |
| 739 | 749 | * |
| 740 | 750 | * @param[in] xml XML document. |
| 741 | 751 | * |
| 742 | - * @exception GException::model_invalid | |
| 752 | + * @exception GException::invalid_value | |
| 743 | 753 | * Invalid model type encountered. |
| 744 | 754 | * |
| 745 | 755 | * Read models from the first source library found in the XML document. The |
| ... | ... | @@ -786,7 +796,17 @@ void GModels::read(const GXml& xml) |
| 786 | 796 | |
| 787 | 797 | // ... otherwise throw an exception |
| 788 | 798 | else { |
| 789 | - throw GException::model_invalid(G_READ, type); | |
| 799 | + std::string msg = "No model of type \""+type+"\" found in model " | |
| 800 | + "registry. Please specify one of the following " | |
| 801 | + "model types:"; | |
| 802 | + for (int i = 0; i < registry.size(); ++i) { | |
| 803 | + if (i != 0) { | |
| 804 | + msg += ","; | |
| 805 | + } | |
| 806 | + msg += " \""+registry.name(i)+"\""; | |
| 807 | + } | |
| 808 | + msg += "."; | |
| 809 | + throw GException::invalid_value(G_READ, msg); | |
| 790 | 810 | } |
| 791 | 811 | |
| 792 | 812 | // Append model | ... | ... |
src/model/Makefile.am
| ... | ... | @@ -80,8 +80,7 @@ sources = GModelPar.cpp \ |
| 80 | 80 | GModelTemporalRegistry.cpp \ |
| 81 | 81 | GModelTemporalConst.cpp \ |
| 82 | 82 | GModelTemporalLightCurve.cpp \ |
| 83 | - GModelTemporalPhaseCurve.cpp \ | |
| 84 | - GException_model.cpp | |
| 83 | + GModelTemporalPhaseCurve.cpp | |
| 85 | 84 | |
| 86 | 85 | # Build libtool library |
| 87 | 86 | noinst_LTLIBRARIES = libmodel.la | ... | ... |
src/obs/GCaldb.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GCaldb.cpp - Calibration database class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2011-2016 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2011-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -242,10 +242,8 @@ int GCaldb::size(void) const |
| 242 | 242 | /***********************************************************************//** |
| 243 | 243 | * @brief Return path to CALDB root directory |
| 244 | 244 | * |
| 245 | - * @exception GException::directory_not_found | |
| 246 | - * Calibration directory not found. | |
| 247 | - * @exception GException::directory_not_accessible | |
| 248 | - * No read permission granted to calibration directory. | |
| 245 | + * @exception GException::invalid_value | |
| 246 | + * CALDB environment variable not set | |
| 249 | 247 | * |
| 250 | 248 | * The calibration directory path is given by one of the following |
| 251 | 249 | * |
| ... | ... | @@ -271,10 +269,10 @@ std::string GCaldb::rootdir(void) const |
| 271 | 269 | |
| 272 | 270 | // Throw an exception if non of the environment variables was set |
| 273 | 271 | if (ptr1 == NULL) { |
| 274 | - throw GException::env_not_found(G_GET_ROOTDIR, | |
| 275 | - "CALDB", | |
| 276 | - "Please set the CALDB environment" | |
| 277 | - " variable to a valid calibration database root directory."); | |
| 272 | + std::string msg = "CALDB environment value not found. Please set " | |
| 273 | + "the CALDB environment variable to a valid " | |
| 274 | + "calibration database root directory."; | |
| 275 | + throw GException::invalid_value(G_GET_ROOTDIR, msg); | |
| 278 | 276 | } |
| 279 | 277 | |
| 280 | 278 | // If CALDB was set then check whether the directory exists |
| ... | ... | @@ -296,9 +294,9 @@ std::string GCaldb::rootdir(void) const |
| 296 | 294 | * |
| 297 | 295 | * @param[in] pathname Calibration database root directory. |
| 298 | 296 | * |
| 299 | - * @exception GException::directory_not_found | |
| 297 | + * @exception GException::invalid_argument | |
| 300 | 298 | * Calibration database root directory not found. |
| 301 | - * @exception GException::directory_not_accessible | |
| 299 | + * @exception GException::invalid_value | |
| 302 | 300 | * No read permission granted for calibration database root |
| 303 | 301 | * directory. |
| 304 | 302 | * |
| ... | ... | @@ -312,13 +310,19 @@ void GCaldb::rootdir(const std::string& pathname) |
| 312 | 310 | |
| 313 | 311 | // Verify that specified root directory exists |
| 314 | 312 | if (!gammalib::dir_exists(rootdir)) { |
| 315 | - throw GException::directory_not_found(G_SET_ROOTDIR, rootdir); | |
| 313 | + std::string msg = "Calibration database root directory \""+ | |
| 314 | + rootdir+"\" not found. Please specify a valid " | |
| 315 | + "root directory name."; | |
| 316 | + throw GException::invalid_argument(G_SET_ROOTDIR, msg); | |
| 316 | 317 | } |
| 317 | 318 | |
| 318 | 319 | // Verify that specified root directory allows read access |
| 319 | 320 | if (access(rootdir.c_str(), R_OK) != 0) { |
| 320 | - throw GException::directory_not_accessible(G_SET_ROOTDIR, rootdir, | |
| 321 | - "Requested read permission not granted."); | |
| 321 | + std::string msg = "Calibration database root directory \""+ | |
| 322 | + rootdir+"\" is not accessible for read access. " | |
| 323 | + "Please provide read access to the calibration " | |
| 324 | + "database root directory."; | |
| 325 | + throw GException::invalid_value(G_SET_ROOTDIR, msg); | |
| 322 | 326 | } |
| 323 | 327 | |
| 324 | 328 | // Set calibration database root directory |
| ... | ... | @@ -335,9 +339,9 @@ void GCaldb::rootdir(const std::string& pathname) |
| 335 | 339 | * @param[in] mission Mission name (case insensitive). |
| 336 | 340 | * @param[in] instrument Instrument name (case insensitive; optional). |
| 337 | 341 | * |
| 338 | - * @exception GException::directory_not_found | |
| 342 | + * @exception GException::invalid_argument | |
| 339 | 343 | * Calibration directory not found. |
| 340 | - * @exception GException::directory_not_accessible | |
| 344 | + * @exception GException::invalid_value | |
| 341 | 345 | * No read permission granted to calibration directory. |
| 342 | 346 | * |
| 343 | 347 | * The calibration directory path is given by one of the following |
| ... | ... | @@ -354,14 +358,19 @@ std::string GCaldb::path(const std::string& mission, const std::string& instrume |
| 354 | 358 | // Verify that mission name is valid and directory is accessible |
| 355 | 359 | std::string path = rootdir() + "/data/" + gammalib::tolower(mission); |
| 356 | 360 | if (!gammalib::dir_exists(path)) { |
| 357 | - throw GException::directory_not_found(G_PATH, path, | |
| 358 | - "Requested mission \""+gammalib::toupper(mission)+"\" not found in" | |
| 359 | - " calibration database."); | |
| 361 | + std::string msg = "Requested mission \""+gammalib::toupper(mission)+ | |
| 362 | + "\" not found in calibration database. Please " | |
| 363 | + "specify an available mission or add mission to " | |
| 364 | + "calibration database."; | |
| 365 | + throw GException::invalid_argument(G_PATH, msg); | |
| 360 | 366 | } |
| 361 | 367 | if (access(path.c_str(), R_OK) != 0) { |
| 362 | - throw GException::directory_not_accessible(G_PATH, path, | |
| 363 | - "Requested read permission not granted for mission \""+ | |
| 364 | - gammalib::toupper(mission)+"\"."); | |
| 368 | + std::string msg = "Calibration database directory \""+path+"\" for " | |
| 369 | + " mission \""+gammalib::toupper(mission)+"\" is " | |
| 370 | + "not accessible for read access. Please provide " | |
| 371 | + "read access to the calibration database " | |
| 372 | + "directory."; | |
| 373 | + throw GException::invalid_value(G_PATH, msg); | |
| 365 | 374 | } |
| 366 | 375 | |
| 367 | 376 | // If an instrument has been specified, verify that instrument name is |
| ... | ... | @@ -373,16 +382,24 @@ std::string GCaldb::path(const std::string& mission, const std::string& instrume |
| 373 | 382 | |
| 374 | 383 | // Verify path |
| 375 | 384 | if (!gammalib::dir_exists(path)) { |
| 376 | - throw GException::directory_not_found(G_PATH, path, | |
| 377 | - "Requested instrument \""+gammalib::toupper(instrument)+"\" on" | |
| 378 | - " mission \""+gammalib::toupper(mission)+"\" not found in" | |
| 379 | - " calibration database."); | |
| 385 | + std::string msg = "Requested instrument \""+ | |
| 386 | + gammalib::toupper(instrument)+ | |
| 387 | + "\" on mission \""+ | |
| 388 | + gammalib::toupper(mission)+"\" not found in " | |
| 389 | + "calibration database. Please specify an " | |
| 390 | + "available instrument or add instrument to " | |
| 391 | + "calibration database."; | |
| 392 | + throw GException::invalid_argument(G_PATH, msg); | |
| 380 | 393 | } |
| 381 | 394 | if (access(path.c_str(), R_OK) != 0) { |
| 382 | - throw GException::directory_not_accessible(G_PATH, path, | |
| 383 | - "Requested read permission not granted for instrument \""+ | |
| 384 | - gammalib::toupper(instrument)+"\" on mission \""+gammalib::toupper(mission)+ | |
| 385 | - "\"."); | |
| 395 | + std::string msg = "Calibration database directory \""+path+"\" for " | |
| 396 | + "instrument \""+gammalib::toupper(instrument)+ | |
| 397 | + "\" on mission \""+ | |
| 398 | + gammalib::toupper(mission)+"\" is not " | |
| 399 | + "accessible for read access. Please provide " | |
| 400 | + "read access to the calibration database " | |
| 401 | + "directory."; | |
| 402 | + throw GException::invalid_value(G_PATH, msg); | |
| 386 | 403 | } |
| 387 | 404 | |
| 388 | 405 | } // endif: instrument has been specified | ... | ... |
src/sky/GSkyRegions.cpp
| ... | ... | @@ -506,8 +506,8 @@ bool GSkyRegions::overlaps(const GSkyRegions& regions) const |
| 506 | 506 | * |
| 507 | 507 | * @param[in] filename DS9 region filename. |
| 508 | 508 | * |
| 509 | - * @exception GException::file_open_error | |
| 510 | - * File could not be opened. | |
| 509 | + * @exception GException::file_error | |
| 510 | + * Unable to open file. | |
| 511 | 511 | * |
| 512 | 512 | * Loads all regions from a DS9 region file. |
| 513 | 513 | ***************************************************************************/ |
| ... | ... | @@ -604,7 +604,9 @@ void GSkyRegions::load(const GFilename& filename) |
| 604 | 604 | |
| 605 | 605 | // File could not be opened |
| 606 | 606 | else { |
| 607 | - throw GException::file_open_error(G_LOAD, filename.url()); | |
| 607 | + std::string msg = "Unable to open file \""+filename.url()+"\". Please " | |
| 608 | + "specify a valid file name."; | |
| 609 | + throw GException::file_error(G_LOAD, msg); | |
| 608 | 610 | } |
| 609 | 611 | |
| 610 | 612 | // Return |
| ... | ... | @@ -617,8 +619,8 @@ void GSkyRegions::load(const GFilename& filename) |
| 617 | 619 | * |
| 618 | 620 | * @param[in] filename DS9 region filename. |
| 619 | 621 | * |
| 620 | - * @exception GException::file_open_error | |
| 621 | - * File could not be opened. | |
| 622 | + * @exception GException::file_error | |
| 623 | + * Unable to open file. | |
| 622 | 624 | * |
| 623 | 625 | * Saves all regions in the container into a DS9 region file. |
| 624 | 626 | ***************************************************************************/ |
| ... | ... | @@ -652,7 +654,9 @@ void GSkyRegions::save(const GFilename& filename) const |
| 652 | 654 | |
| 653 | 655 | // ... otherwise, if file could not be opened then throw an exception |
| 654 | 656 | else { |
| 655 | - throw GException::file_open_error(G_SAVE, filename.url()); | |
| 657 | + std::string msg = "Unable to open file \""+filename.url()+"\". Please " | |
| 658 | + "specify a valid file name."; | |
| 659 | + throw GException::file_error(G_SAVE, msg); | |
| 656 | 660 | } |
| 657 | 661 | |
| 658 | 662 | // Return | ... | ... |
src/support/GCsv.cpp
| ... | ... | @@ -412,7 +412,7 @@ void GCsv::integer(const int& row, const int& col, const int& value) |
| 412 | 412 | * @param[in] filename Filename. |
| 413 | 413 | * @param[in] sep Column separator (default is whitespace). |
| 414 | 414 | * |
| 415 | - * @exception GException::file_not_found | |
| 415 | + * @exception GException::file_error | |
| 416 | 416 | * CSV table file not found. |
| 417 | 417 | * @exception GException::csv_bad_columns |
| 418 | 418 | * Inconsistent columns encountered in CSV table file. |
| ... | ... | @@ -435,7 +435,9 @@ void GCsv::load(const GFilename& filename, const std::string& sep) |
| 435 | 435 | // Open CSV table (read-only) |
| 436 | 436 | FILE* fptr = std::fopen(fname.c_str(), "r"); |
| 437 | 437 | if (fptr == NULL) { |
| 438 | - throw GException::file_not_found(G_LOAD, fname); | |
| 438 | + std::string msg = "Unable to open file \""+fname+"\" for read access. " | |
| 439 | + "Please specify a readable file."; | |
| 440 | + throw GException::file_error(G_LOAD, msg); | |
| 439 | 441 | } |
| 440 | 442 | |
| 441 | 443 | // Read lines |
| ... | ... | @@ -475,8 +477,12 @@ void GCsv::load(const GFilename& filename, const std::string& sep) |
| 475 | 477 | else { |
| 476 | 478 | // Check table consistency |
| 477 | 479 | if (m_cols != elements.size()) { |
| 478 | - throw GException::csv_bad_columns(G_LOAD, fname, | |
| 479 | - iline, m_cols, elements.size()); | |
| 480 | + std::string msg = "Number of "+gammalib::str(elements.size())+ | |
| 481 | + " columns in row "+gammalib::str(iline)+ | |
| 482 | + " is not consistent with number of "+ | |
| 483 | + gammalib::str(m_cols)+" in first row. Please " | |
| 484 | + "specify a correctly formatted CSV file."; | |
| 485 | + throw GException::invalid_value(G_LOAD, msg); | |
| 480 | 486 | } |
| 481 | 487 | |
| 482 | 488 | // Append elements | ... | ... |
src/support/GException.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GException.cpp - exception handlers * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2006-2017 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2006-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -90,6 +90,35 @@ GException::invalid_argument::invalid_argument(const std::string& origin, |
| 90 | 90 | |
| 91 | 91 | |
| 92 | 92 | /***********************************************************************//** |
| 93 | + * @brief Invalid argument | |
| 94 | + * | |
| 95 | + * @param[in] origin Name of method that has thrown the exception. | |
| 96 | + * @param[in] argument Argument name. | |
| 97 | + * @param[in] message Optional message. | |
| 98 | + * | |
| 99 | + * This exception signals that a specified argument was not valid. | |
| 100 | + ***************************************************************************/ | |
| 101 | +GException::invalid_argument::invalid_argument(const std::string& origin, | |
| 102 | + const std::string& argument, | |
| 103 | + const std::string& message) | |
| 104 | +{ | |
| 105 | + // Set origin | |
| 106 | + m_origin = origin; | |
| 107 | + | |
| 108 | + // Set message string | |
| 109 | + m_message = "Invalid argument \""+argument+"\" value."; | |
| 110 | + | |
| 111 | + // Add optional error message | |
| 112 | + if (message.length() > 0) { | |
| 113 | + m_message += (" " + message); | |
| 114 | + } | |
| 115 | + | |
| 116 | + // Return | |
| 117 | + return; | |
| 118 | +} | |
| 119 | + | |
| 120 | + | |
| 121 | +/***********************************************************************//** | |
| 93 | 122 | * @brief Invalid return value |
| 94 | 123 | * |
| 95 | 124 | * @param[in] origin Name of method that has thrown the exception. |
| ... | ... | @@ -199,7 +228,7 @@ GException::fits_error::fits_error(const std::string& origin, |
| 199 | 228 | |
| 200 | 229 | // Add optional error message |
| 201 | 230 | if (message.length() > 0) { |
| 202 | - m_message += " " + message; | |
| 231 | + m_message += (" " + message); | |
| 203 | 232 | } |
| 204 | 233 | |
| 205 | 234 | // Return |
| ... | ... | @@ -261,245 +290,3 @@ GException::feature_not_implemented::feature_not_implemented(const std::string& |
| 261 | 290 | // Return |
| 262 | 291 | return; |
| 263 | 292 | } |
| 264 | - | |
| 265 | - | |
| 266 | -/***********************************************************************//** | |
| 267 | - * @brief Invalid argument | |
| 268 | - * | |
| 269 | - * @param[in] origin Name of method that has thrown the exception. | |
| 270 | - * @param[in] argument Argument name. | |
| 271 | - * @param[in] message Optional message. | |
| 272 | - * | |
| 273 | - * This exception signals that a specified argument was not valid. | |
| 274 | - ***************************************************************************/ | |
| 275 | -GException::invalid_argument::invalid_argument(const std::string& origin, | |
| 276 | - const std::string& argument, | |
| 277 | - const std::string& message) | |
| 278 | -{ | |
| 279 | - // Set origin | |
| 280 | - m_origin = origin; | |
| 281 | - | |
| 282 | - // Set message string | |
| 283 | - m_message = "Invalid argument \""+argument+"\" value."; | |
| 284 | - | |
| 285 | - // Add optional error message | |
| 286 | - if (message.length() > 0) { | |
| 287 | - m_message += " " + message; | |
| 288 | - } | |
| 289 | - | |
| 290 | - // Return | |
| 291 | - return; | |
| 292 | -} | |
| 293 | - | |
| 294 | - | |
| 295 | -/***********************************************************************//** | |
| 296 | - * @brief Invalid type conversion | |
| 297 | - * | |
| 298 | - * @param[in] origin Name of method that has thrown the exception. | |
| 299 | - * @param[in] message Optional message. | |
| 300 | - ***************************************************************************/ | |
| 301 | -GException::bad_type::bad_type(std::string origin, std::string message) | |
| 302 | -{ | |
| 303 | - // Set origin | |
| 304 | - m_origin = origin; | |
| 305 | - | |
| 306 | - // Set message string | |
| 307 | - m_message = "Invalid type conversion."; | |
| 308 | - if (message.length() > 0) { | |
| 309 | - m_message += " " + message; | |
| 310 | - } | |
| 311 | - | |
| 312 | - // Return | |
| 313 | - return; | |
| 314 | -} | |
| 315 | - | |
| 316 | - | |
| 317 | -/***********************************************************************//** | |
| 318 | - * @brief Environment variable not found | |
| 319 | - * | |
| 320 | - * @param[in] origin Name of method that has thrown the exception. | |
| 321 | - * @param[in] envname Name of environment variable. | |
| 322 | - * @param[in] message Optional message. | |
| 323 | - * | |
| 324 | - * This exception signals that are required environment variable was not | |
| 325 | - * found. | |
| 326 | - ***************************************************************************/ | |
| 327 | -GException::env_not_found::env_not_found(std::string origin, | |
| 328 | - std::string envname, | |
| 329 | - std::string message) | |
| 330 | -{ | |
| 331 | - // Set origin | |
| 332 | - m_origin = origin; | |
| 333 | - | |
| 334 | - // Set message string | |
| 335 | - m_message = "Environment variable \""+envname+"\" not found."; | |
| 336 | - if (message.length() > 0) { | |
| 337 | - m_message += " " + message; | |
| 338 | - } | |
| 339 | - | |
| 340 | - // Return | |
| 341 | - return; | |
| 342 | -} | |
| 343 | - | |
| 344 | - | |
| 345 | -/***********************************************************************//** | |
| 346 | - * @brief Memory allocation exception. | |
| 347 | - * | |
| 348 | - * @param[in] origin Name of method that has thrown the exception. | |
| 349 | - * @param[in] num Requested amount of memory. | |
| 350 | - ***************************************************************************/ | |
| 351 | -GException::mem_alloc::mem_alloc(std::string origin, unsigned num) | |
| 352 | -{ | |
| 353 | - // Set origin | |
| 354 | - m_origin = origin; | |
| 355 | - | |
| 356 | - // Set message string | |
| 357 | - m_message = "Memory allocation error (" + gammalib::str((int)num) + " elements)"; | |
| 358 | - | |
| 359 | - // Return | |
| 360 | - return; | |
| 361 | -} | |
| 362 | - | |
| 363 | - | |
| 364 | -/***********************************************************************//** | |
| 365 | - * @brief Not enough nodes in node array | |
| 366 | - * | |
| 367 | - * @param[in] origin Name of method that has thrown the exception. | |
| 368 | - * @param[in] num Number of nodes in node array. | |
| 369 | - ***************************************************************************/ | |
| 370 | -GException::not_enough_nodes::not_enough_nodes(std::string origin, int num) | |
| 371 | -{ | |
| 372 | - // Set origin | |
| 373 | - m_origin = origin; | |
| 374 | - | |
| 375 | - // Set message string | |
| 376 | - m_message = "Not enough nodes in node array (" + gammalib::str(num) + " nodes)."; | |
| 377 | - | |
| 378 | - // Return | |
| 379 | - return; | |
| 380 | -} | |
| 381 | - | |
| 382 | - | |
| 383 | -/***********************************************************************//** | |
| 384 | - * @brief File not found | |
| 385 | - * | |
| 386 | - * @param[in] origin Name of method that has thrown the exception. | |
| 387 | - * @param[in] filename Filename. | |
| 388 | - * @param[in] message Optional message. | |
| 389 | - ***************************************************************************/ | |
| 390 | -GException::file_not_found::file_not_found(std::string origin, | |
| 391 | - std::string filename, | |
| 392 | - std::string message) | |
| 393 | -{ | |
| 394 | - // Set origin | |
| 395 | - m_origin = origin; | |
| 396 | - | |
| 397 | - // Set message string | |
| 398 | - m_message = "File \"" + filename +"\" not found."; | |
| 399 | - if (message.length() > 0) { | |
| 400 | - m_message += " " + message; | |
| 401 | - } | |
| 402 | - | |
| 403 | - // Return | |
| 404 | - return; | |
| 405 | -} | |
| 406 | - | |
| 407 | - | |
| 408 | -/***********************************************************************//** | |
| 409 | - * @brief File open error | |
| 410 | - * | |
| 411 | - * @param[in] origin Name of method that has thrown the exception. | |
| 412 | - * @param[in] filename Filename. | |
| 413 | - * @param[in] message Optional message. | |
| 414 | - ***************************************************************************/ | |
| 415 | -GException::file_open_error::file_open_error(std::string origin, | |
| 416 | - std::string filename, | |
| 417 | - std::string message) | |
| 418 | -{ | |
| 419 | - // Set origin | |
| 420 | - m_origin = origin; | |
| 421 | - | |
| 422 | - // Set message string | |
| 423 | - m_message = "Unable to open file \"" + filename +"\""; | |
| 424 | - if (message.length() > 0) { | |
| 425 | - m_message += " " + message; | |
| 426 | - } | |
| 427 | - | |
| 428 | - // Return | |
| 429 | - return; | |
| 430 | -} | |
| 431 | - | |
| 432 | - | |
| 433 | -/***********************************************************************//** | |
| 434 | - * @brief Directory not found | |
| 435 | - * | |
| 436 | - * @param[in] origin Name of method that has thrown the exception. | |
| 437 | - * @param[in] dirname Directory name. | |
| 438 | - * @param[in] message Optional message. | |
| 439 | - ***************************************************************************/ | |
| 440 | -GException::directory_not_found::directory_not_found(std::string origin, | |
| 441 | - std::string dirname, | |
| 442 | - std::string message) | |
| 443 | -{ | |
| 444 | - // Set origin | |
| 445 | - m_origin = origin; | |
| 446 | - | |
| 447 | - // Set message string | |
| 448 | - m_message = "Directory \"" + dirname +"\" not found."; | |
| 449 | - if (message.length() > 0) { | |
| 450 | - m_message += " " + message; | |
| 451 | - } | |
| 452 | - | |
| 453 | - // Return | |
| 454 | - return; | |
| 455 | -} | |
| 456 | - | |
| 457 | - | |
| 458 | -/***********************************************************************//** | |
| 459 | - * @brief Directory not accessible | |
| 460 | - * | |
| 461 | - * @param[in] origin Name of method that has thrown the exception. | |
| 462 | - * @param[in] dirname Directory name. | |
| 463 | - * @param[in] message Optional message. | |
| 464 | - ***************************************************************************/ | |
| 465 | -GException::directory_not_accessible::directory_not_accessible(std::string origin, | |
| 466 | - std::string dirname, | |
| 467 | - std::string message) | |
| 468 | -{ | |
| 469 | - // Set origin | |
| 470 | - m_origin = origin; | |
| 471 | - | |
| 472 | - // Set message string | |
| 473 | - m_message = "Directory \"" + dirname +"\" not accessible."; | |
| 474 | - if (message.length() > 0) { | |
| 475 | - m_message += " " + message; | |
| 476 | - } | |
| 477 | - | |
| 478 | - // Return | |
| 479 | - return; | |
| 480 | -} | |
| 481 | - | |
| 482 | - | |
| 483 | -/***********************************************************************//** | |
| 484 | - * @brief Bad CSV columns encountered | |
| 485 | - * | |
| 486 | - * @param[in] origin Name of method that has thrown the exception. | |
| 487 | - * @param[in] filename Filename. | |
| 488 | - * @param[in] row CSV file row. | |
| 489 | - * @param[in] cols Expected number of columns. | |
| 490 | - * @param[in] elements Found number of columns. | |
| 491 | - * @param[in] message Optional message. | |
| 492 | - ***************************************************************************/ | |
| 493 | -GException::csv_bad_columns::csv_bad_columns(std::string origin, | |
| 494 | - std::string filename, | |
| 495 | - int row, | |
| 496 | - int cols, | |
| 497 | - int elements, | |
| 498 | - std::string message) | |
| 499 | -{ | |
| 500 | - m_origin = origin; | |
| 501 | - m_message = "Inconsistent number of columns found in row "+gammalib::str(row)+ | |
| 502 | - " of file \""+filename+"\" ("+gammalib::str(cols)+" expected, "+ | |
| 503 | - gammalib::str(elements)+" encountered). "+message; | |
| 504 | - return; | |
| 505 | -} | ... | ... |
src/support/GNodeArray.cpp
| ... | ... | @@ -525,7 +525,7 @@ void GNodeArray::nodes(const std::vector<double>& vector) |
| 525 | 525 | * @param[in] value Value \f$x\f$ at which interpolation should be done. |
| 526 | 526 | * @param[in] vector Vector \f$y_i\f$ that should be interpolated. |
| 527 | 527 | * |
| 528 | - * @exception GException::not_enough_nodes | |
| 528 | + * @exception GException::invalid_value | |
| 529 | 529 | * Not enough nodes for interpolation in node array. |
| 530 | 530 | * @exception GException::invalid_argument |
| 531 | 531 | * Size of node vector does not match the size of vector argument. |
| ... | ... | @@ -538,7 +538,11 @@ double GNodeArray::interpolate(const double& value, |
| 538 | 538 | { |
| 539 | 539 | // Throw exception if there are not enough nodes |
| 540 | 540 | if (m_node.size() < 2) { |
| 541 | - throw GException::not_enough_nodes(G_INTERPOLATE, m_node.size()); | |
| 541 | + std::string msg = "There are "+gammalib::str(m_node.size())+" nodes " | |
| 542 | + "in node array, yet at least 2 nodes are required " | |
| 543 | + "for interpolation. Please specify more nodes " | |
| 544 | + "before calling the method."; | |
| 545 | + throw GException::invalid_value(G_INTERPOLATE, msg); | |
| 542 | 546 | } |
| 543 | 547 | |
| 544 | 548 | // Throw exception if vectors have not the same size | ... | ... |
src/support/GTools.cpp
| ... | ... | @@ -1695,6 +1695,82 @@ std::string gammalib::xml_get_attr(const std::string& origin, |
| 1695 | 1695 | |
| 1696 | 1696 | |
| 1697 | 1697 | /***********************************************************************//** |
| 1698 | + * @brief Checks number of parameters | |
| 1699 | + * | |
| 1700 | + * @param[in] origin Method performing the check. | |
| 1701 | + * @param[in] xml XML element. | |
| 1702 | + * @param[in] number Expected number of parameters. | |
| 1703 | + * | |
| 1704 | + * @exception GException::invalid_value | |
| 1705 | + * Invalid XML format encountered. | |
| 1706 | + * | |
| 1707 | + * Checks the number of parameter in an XML element. | |
| 1708 | + ***************************************************************************/ | |
| 1709 | +void gammalib::xml_check_parnum(const std::string& origin, | |
| 1710 | + const GXmlElement& xml, | |
| 1711 | + const int& number) | |
| 1712 | +{ | |
| 1713 | + // Throw exception if number of elements does not correspond to the | |
| 1714 | + // expected number | |
| 1715 | + if (xml.elements() != number) { | |
| 1716 | + std::string msg = "Number of "+gammalib::str(xml.elements())+ | |
| 1717 | + " child elements in XML file does not correspond " | |
| 1718 | + "to expected number of "+gammalib::str(number)+ | |
| 1719 | + " elements. Please verify the XML format."; | |
| 1720 | + throw GException::invalid_value(origin, msg); | |
| 1721 | + } | |
| 1722 | + | |
| 1723 | + // Throw exception if number of "parameter" elements does not correspond | |
| 1724 | + // to the xpected number | |
| 1725 | + int npars = xml.elements("parameter"); | |
| 1726 | + if (npars != number) { | |
| 1727 | + std::string msg = "Number of "+gammalib::str(npars)+" \"parameter\" " | |
| 1728 | + "child elements in XML file does not correspond to " | |
| 1729 | + "expected number of "+gammalib::str(number)+ | |
| 1730 | + " elements. Please verify the XML format."; | |
| 1731 | + throw GException::invalid_value(origin, msg); | |
| 1732 | + } | |
| 1733 | + | |
| 1734 | + // Return | |
| 1735 | + return; | |
| 1736 | +} | |
| 1737 | + | |
| 1738 | + | |
| 1739 | +/***********************************************************************//** | |
| 1740 | + * @brief Checks the model type | |
| 1741 | + * | |
| 1742 | + * @param[in] origin Method performing the check. | |
| 1743 | + * @param[in,out] xml XML element. | |
| 1744 | + * @param[in] type Expected model typeN. | |
| 1745 | + * | |
| 1746 | + * @exception GException::invalid_value | |
| 1747 | + * Invalid XML format encountered. | |
| 1748 | + * | |
| 1749 | + * Checks the number of parameter in an XML element. | |
| 1750 | + ***************************************************************************/ | |
| 1751 | +void gammalib::xml_check_type(const std::string& origin, | |
| 1752 | + GXmlElement& xml, | |
| 1753 | + const std::string& type) | |
| 1754 | +{ | |
| 1755 | + // If XML element has no model type then set model type | |
| 1756 | + if (xml.attribute("type") == "") { | |
| 1757 | + xml.attribute("type", type); | |
| 1758 | + } | |
| 1759 | + | |
| 1760 | + // Throw an exception if the model type is not the expected one | |
| 1761 | + if (xml.attribute("type") != type) { | |
| 1762 | + std::string msg = "Model type \""+xml.attribute("type")+"\" is not " | |
| 1763 | + "the expected type \""+type+"\". Please verify " | |
| 1764 | + "the XML format."; | |
| 1765 | + throw GException::invalid_value(origin, msg); | |
| 1766 | + } | |
| 1767 | + | |
| 1768 | + // Return | |
| 1769 | + return; | |
| 1770 | +} | |
| 1771 | + | |
| 1772 | + | |
| 1773 | +/***********************************************************************//** | |
| 1698 | 1774 | * @brief Checks whether a parameter has occured once |
| 1699 | 1775 | * |
| 1700 | 1776 | * @param[in] origin Method performing the check. | ... | ... |
src/support/GUrlFile.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GUrlFile.cpp - File URL class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013-2015 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2013-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -195,7 +195,7 @@ GUrlFile* GUrlFile::clone(void) const |
| 195 | 195 | * @param[in] url File name. |
| 196 | 196 | * @param[in] mode File mode. |
| 197 | 197 | * |
| 198 | - * @exception GException::file_open_error | |
| 198 | + * @exception GException::file_error | |
| 199 | 199 | * Unable to open file. |
| 200 | 200 | * |
| 201 | 201 | * Opens a file @p url in the specified @p mode. Any environment variable |
| ... | ... | @@ -214,7 +214,9 @@ void GUrlFile::open(const std::string& url, const std::string& mode) |
| 214 | 214 | // Try opening file. Throw an exception if opening failed. |
| 215 | 215 | m_fptr = std::fopen(filename.c_str(), mode.c_str()); |
| 216 | 216 | if (m_fptr == NULL) { |
| 217 | - throw GException::file_open_error(G_OPEN, filename); | |
| 217 | + std::string msg = "Unable to open file \""+filename+"\" in mode \""+ | |
| 218 | + mode+"\". Please specify an accessible file."; | |
| 219 | + throw GException::file_error(G_OPEN, msg); | |
| 218 | 220 | } |
| 219 | 221 | |
| 220 | 222 | // Store URL and mode | ... | ... |
src/xml/GXml.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GXml.cpp - XML class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2018 by Juergen Knoedlseder * | |
| 4 | + * copyright (C) 2010-2021 by Juergen Knoedlseder * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -524,6 +524,9 @@ const GXmlElement* GXml::element(const std::string& name, const int& index) cons |
| 524 | 524 | * |
| 525 | 525 | * @param[in] filename File name. |
| 526 | 526 | * |
| 527 | + * @exception GException::file_error | |
| 528 | + * Unable to open file. | |
| 529 | + * | |
| 527 | 530 | * Loads a XML document from a file by reading from the file's Unified |
| 528 | 531 | * Resource Locator (URL). The read() method is invoked for this purpose. |
| 529 | 532 | * |
| ... | ... | @@ -538,7 +541,9 @@ void GXml::load(const GFilename& filename) |
| 538 | 541 | { |
| 539 | 542 | // Throw an exception if file does not exist |
| 540 | 543 | if (!filename.exists()) { |
| 541 | - throw GException::file_open_error(G_LOAD, filename); | |
| 544 | + std::string msg = "Unable to open file \""+filename.url()+"\". Please " | |
| 545 | + "specify a valid file name."; | |
| 546 | + throw GException::file_error(G_LOAD, msg); | |
| 542 | 547 | } |
| 543 | 548 | |
| 544 | 549 | // Open XML URL as file for reading | ... | ... |