Commit 41d44301df1e83c03932b6469c33a22b37500951
1 parent
567ba6c9
Use relative file names in XML files (#1808)
Showing
30 changed files
with
164 additions
and
182 deletions
inst/com/src/GCOMObservation.cpp
| ... | ... | @@ -279,15 +279,24 @@ void GCOMObservation::response(const std::string& rspname, const GCaldb& caldb) |
| 279 | 279 | * Reads information for a COMPTEL observation from an XML element. |
| 280 | 280 | * The expected format of the XML element is |
| 281 | 281 | * |
| 282 | - * <observation name="..." id="..." instrument="..."> | |
| 283 | - * <parameter name="DRE" file="..."/> | |
| 284 | - * <parameter name="DRB" file="..."/> | |
| 285 | - * <parameter name="DRG" file="..."/> | |
| 286 | - * <parameter name="DRX" file="..."/> | |
| 287 | - * <parameter name="IAQ" value="..."/> | |
| 282 | + * <observation name="Crab" id="00001" instrument="COM"> | |
| 283 | + * <parameter name="DRE" file="dre.fits"/> | |
| 284 | + * <parameter name="DRB" file="drb.fits"/> | |
| 285 | + * <parameter name="DRG" file="drg.fits"/> | |
| 286 | + * <parameter name="DRX" file="drx.fits"/> | |
| 287 | + * <parameter name="IAQ" value="ENERG(1.0-3.0)MeV"/> | |
| 288 | 288 | * </observation> |
| 289 | 289 | * |
| 290 | - * for a binned observation. | |
| 290 | + * for a binned observation. The @p file attribute provide either absolute | |
| 291 | + * or relative file name. If a file name includes no access path it is | |
| 292 | + * assumed that the file resides in the same location as the XML file. | |
| 293 | + * | |
| 294 | + * The value of the @p IAQ attribute should be one of | |
| 295 | + * | |
| 296 | + * ENERG(0.75-1.0)MeV | |
| 297 | + * ENERG(1.0-3.0)MeV | |
| 298 | + * ENERG(3.0-10.0)MeV | |
| 299 | + * ENERG(10.0-30.0)MeV | |
| 291 | 300 | ***************************************************************************/ |
| 292 | 301 | void GCOMObservation::read(const GXmlElement& xml) |
| 293 | 302 | { |
| ... | ... | @@ -304,6 +313,12 @@ void GCOMObservation::read(const GXmlElement& xml) |
| 304 | 313 | std::string drxname = gammalib::xml_get_attr(G_READ, xml, "DRX", "file"); |
| 305 | 314 | std::string iaqname = gammalib::xml_get_attr(G_READ, xml, "IAQ", "value"); |
| 306 | 315 | |
| 316 | + // Expand file names | |
| 317 | + drename = gammalib::xml_file_expand(xml, drename); | |
| 318 | + drbname = gammalib::xml_file_expand(xml, drbname); | |
| 319 | + drgname = gammalib::xml_file_expand(xml, drgname); | |
| 320 | + drxname = gammalib::xml_file_expand(xml, drxname); | |
| 321 | + | |
| 307 | 322 | // Load observation |
| 308 | 323 | load(drename, drbname, drgname, drxname); |
| 309 | 324 | |
| ... | ... | @@ -321,17 +336,26 @@ void GCOMObservation::read(const GXmlElement& xml) |
| 321 | 336 | * @param[in] xml XML element. |
| 322 | 337 | * |
| 323 | 338 | * Writes information for a COMPTEL observation into an XML element. The |
| 324 | - * expected format of the XML element is | |
| 325 | - * | |
| 326 | - * <observation name="..." id="..." instrument="..."> | |
| 327 | - * <parameter name="DRE" file="..."/> | |
| 328 | - * <parameter name="DRB" file="..."/> | |
| 329 | - * <parameter name="DRG" file="..."/> | |
| 330 | - * <parameter name="DRX" file="..."/> | |
| 331 | - * <parameter name="IAQ" value="..."/> | |
| 339 | + * format of the XML element is | |
| 340 | + * | |
| 341 | + * <observation name="Crab" id="00001" instrument="COM"> | |
| 342 | + * <parameter name="DRE" file="dre.fits"/> | |
| 343 | + * <parameter name="DRB" file="drb.fits"/> | |
| 344 | + * <parameter name="DRG" file="drg.fits"/> | |
| 345 | + * <parameter name="DRX" file="drx.fits"/> | |
| 346 | + * <parameter name="IAQ" value="ENERG(1.0-3.0)MeV"/> | |
| 332 | 347 | * </observation> |
| 333 | 348 | * |
| 334 | - * for a binned observation. | |
| 349 | + * for a binned observation. The @p file attribute provide either absolute | |
| 350 | + * or relative file name. If a file name includes no access path it is | |
| 351 | + * assumed that the file resides in the same location as the XML file. | |
| 352 | + * | |
| 353 | + * The value of the @p IAQ attribute will be one of | |
| 354 | + * | |
| 355 | + * ENERG(0.75-1.0)MeV | |
| 356 | + * ENERG(1.0-3.0)MeV | |
| 357 | + * ENERG(3.0-10.0)MeV | |
| 358 | + * ENERG(10.0-30.0)MeV | |
| 335 | 359 | ***************************************************************************/ |
| 336 | 360 | void GCOMObservation::write(GXmlElement& xml) const |
| 337 | 361 | { |
| ... | ... | @@ -340,19 +364,19 @@ void GCOMObservation::write(GXmlElement& xml) const |
| 340 | 364 | |
| 341 | 365 | // Set DRE parameter |
| 342 | 366 | par = gammalib::xml_need_par(G_WRITE, xml, "DRE"); |
| 343 | - par->attribute("file", m_drename); | |
| 367 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_drename)); | |
| 344 | 368 | |
| 345 | 369 | // Set DRB parameter |
| 346 | 370 | par = gammalib::xml_need_par(G_WRITE, xml, "DRB"); |
| 347 | - par->attribute("file", m_drbname); | |
| 371 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_drbname)); | |
| 348 | 372 | |
| 349 | 373 | // Set DRG parameter |
| 350 | 374 | par = gammalib::xml_need_par(G_WRITE, xml, "DRG"); |
| 351 | - par->attribute("file", m_drgname); | |
| 375 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_drgname)); | |
| 352 | 376 | |
| 353 | 377 | // Set DRX parameter |
| 354 | 378 | par = gammalib::xml_need_par(G_WRITE, xml, "DRX"); |
| 355 | - par->attribute("file", m_drxname); | |
| 379 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_drxname)); | |
| 356 | 380 | |
| 357 | 381 | // Set IAQ parameter |
| 358 | 382 | par = gammalib::xml_need_par(G_WRITE, xml, "DRX"); | ... | ... |
inst/com/test/data/obs.xml
| 1 | 1 | <?xml version="1.0" standalone="no"?> |
| 2 | 2 | <observation_list title="observation library"> |
| 3 | 3 | <observation name="Crab" id="00001" instrument="COM"> |
| 4 | - <parameter name="DRE" file="$(PACKAGE_SOURCE)/inst/com/test/data/m50439_dre.fits"/> | |
| 5 | - <parameter name="DRB" file="$(PACKAGE_SOURCE)/inst/com/test/data/m34997_drg.fits"/> | |
| 6 | - <parameter name="DRG" file="$(PACKAGE_SOURCE)/inst/com/test/data/m34997_drg.fits"/> | |
| 7 | - <parameter name="DRX" file="$(PACKAGE_SOURCE)/inst/com/test/data/m32171_drx.fits"/> | |
| 4 | + <parameter name="DRE" file="m50439_dre.fits"/> | |
| 5 | + <parameter name="DRB" file="m34997_drg.fits"/> | |
| 6 | + <parameter name="DRG" file="m34997_drg.fits"/> | |
| 7 | + <parameter name="DRX" file="m32171_drx.fits"/> | |
| 8 | 8 | <parameter name="IAQ" value="ENERG(1.0-3.0)MeV"/> |
| 9 | 9 | </observation> |
| 10 | 10 | </observation_list> |
| 11 | 11 | \ No newline at end of file | ... | ... |
inst/cta/src/GCTAObservation.cpp
| ... | ... | @@ -681,7 +681,8 @@ void GCTAObservation::read(const GXmlElement& xml) |
| 681 | 681 | (par->attribute("name") == "CountsCube")) { |
| 682 | 682 | |
| 683 | 683 | // Read eventlist file name |
| 684 | - std::string filename = par->attribute("file"); | |
| 684 | + std::string filename = gammalib::xml_file_expand(xml, | |
| 685 | + par->attribute("file")); | |
| 685 | 686 | |
| 686 | 687 | // Load events |
| 687 | 688 | load(filename); |
| ... | ... | @@ -694,7 +695,7 @@ void GCTAObservation::read(const GXmlElement& xml) |
| 694 | 695 | else if (par->attribute("name") == "Background") { |
| 695 | 696 | |
| 696 | 697 | // Read background file name |
| 697 | - m_bgdfile = par->attribute("file"); | |
| 698 | + m_bgdfile = gammalib::xml_file_expand(xml, par->attribute("file")); | |
| 698 | 699 | |
| 699 | 700 | } |
| 700 | 701 | |
| ... | ... | @@ -952,7 +953,7 @@ void GCTAObservation::write(GXmlElement& xml) const |
| 952 | 953 | |
| 953 | 954 | // Write event file name |
| 954 | 955 | GXmlElement* par = gammalib::xml_need_par(G_WRITE, xml, evttype); |
| 955 | - par->attribute("file", m_eventfile.url()); | |
| 956 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_eventfile.url())); | |
| 956 | 957 | |
| 957 | 958 | } |
| 958 | 959 | ... | ... |
inst/cta/src/GCTAOnOffObservation.cpp
| ... | ... | @@ -334,7 +334,7 @@ void GCTAOnOffObservation::read(const GXmlElement& xml) |
| 334 | 334 | // Extract instrument name |
| 335 | 335 | m_instrument = xml.attribute("instrument"); |
| 336 | 336 | |
| 337 | - // Get parameters | |
| 337 | + // Get file names | |
| 338 | 338 | std::string pha_on = gammalib::xml_get_attr(G_READ, xml, "Pha_on", "file"); |
| 339 | 339 | std::string pha_off = gammalib::xml_get_attr(G_READ, xml, "Pha_off", "file"); |
| 340 | 340 | std::string reg_on = gammalib::xml_get_attr(G_READ, xml, "Regions_on", "file"); |
| ... | ... | @@ -342,6 +342,14 @@ void GCTAOnOffObservation::read(const GXmlElement& xml) |
| 342 | 342 | std::string arf = gammalib::xml_get_attr(G_READ, xml, "Arf", "file"); |
| 343 | 343 | std::string rmf = gammalib::xml_get_attr(G_READ, xml, "Rmf", "file"); |
| 344 | 344 | |
| 345 | + // Expand file names | |
| 346 | + pha_on = gammalib::xml_file_expand(xml, pha_on); | |
| 347 | + pha_off = gammalib::xml_file_expand(xml, pha_off); | |
| 348 | + reg_on = gammalib::xml_file_expand(xml, reg_on); | |
| 349 | + reg_off = gammalib::xml_file_expand(xml, reg_off); | |
| 350 | + arf = gammalib::xml_file_expand(xml, arf); | |
| 351 | + rmf = gammalib::xml_file_expand(xml, rmf); | |
| 352 | + | |
| 345 | 353 | // Load files |
| 346 | 354 | m_on_spec.load(pha_on); |
| 347 | 355 | m_off_spec.load(pha_off); |
| ... | ... | @@ -381,27 +389,27 @@ void GCTAOnOffObservation::write(GXmlElement& xml) const |
| 381 | 389 | |
| 382 | 390 | // Set Pha_on parameter |
| 383 | 391 | par = gammalib::xml_need_par(G_WRITE, xml, "Pha_on"); |
| 384 | - par->attribute("file", m_on_spec.filename()); | |
| 392 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_on_spec.filename())); | |
| 385 | 393 | |
| 386 | 394 | // Set Pha_off parameter |
| 387 | 395 | par = gammalib::xml_need_par(G_WRITE, xml, "Pha_off"); |
| 388 | - par->attribute("file", m_off_spec.filename()); | |
| 396 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_off_spec.filename())); | |
| 389 | 397 | |
| 390 | 398 | // Set Regions_on parameter |
| 391 | 399 | par = gammalib::xml_need_par(G_WRITE, xml, "Regions_on"); |
| 392 | - par->attribute("file", m_on_regions.filename()); | |
| 400 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_on_regions.filename())); | |
| 393 | 401 | |
| 394 | 402 | // Set Regions_off parameter |
| 395 | 403 | par = gammalib::xml_need_par(G_WRITE, xml, "Regions_off"); |
| 396 | - par->attribute("file", m_off_regions.filename()); | |
| 404 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_off_regions.filename())); | |
| 397 | 405 | |
| 398 | 406 | // Set Arf parameter |
| 399 | 407 | par = gammalib::xml_need_par(G_WRITE, xml, "Arf"); |
| 400 | - par->attribute("file", m_arf.filename()); | |
| 408 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_arf.filename())); | |
| 401 | 409 | |
| 402 | 410 | // Set Rmf parameter |
| 403 | 411 | par = gammalib::xml_need_par(G_WRITE, xml, "Rmf"); |
| 404 | - par->attribute("file", m_rmf.filename()); | |
| 412 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_rmf.filename())); | |
| 405 | 413 | |
| 406 | 414 | // Return |
| 407 | 415 | return; | ... | ... |
inst/cta/src/GCTAResponseCube.cpp
| ... | ... | @@ -512,15 +512,18 @@ void GCTAResponseCube::read(const GXmlElement& xml) |
| 512 | 512 | |
| 513 | 513 | // Get exposure cube information and load cube |
| 514 | 514 | const GXmlElement* exppar = gammalib::xml_get_par(G_READ, xml, "ExposureCube"); |
| 515 | - std::string expname = gammalib::strip_whitespace(exppar->attribute("file")); | |
| 515 | + std::string expname = gammalib::xml_file_expand(xml, | |
| 516 | + exppar->attribute("file")); | |
| 516 | 517 | |
| 517 | 518 | // Get PSF cube information and load cube |
| 518 | 519 | const GXmlElement* psfpar = gammalib::xml_get_par(G_READ, xml, "PsfCube"); |
| 519 | - std::string psfname = gammalib::strip_whitespace(psfpar->attribute("file")); | |
| 520 | + std::string psfname = gammalib::xml_file_expand(xml, | |
| 521 | + psfpar->attribute("file")); | |
| 520 | 522 | |
| 521 | 523 | // Get background cube information and load cube |
| 522 | 524 | const GXmlElement* bkgpar = gammalib::xml_get_par(G_READ, xml, "BkgCube"); |
| 523 | - std::string bkgname = gammalib::strip_whitespace(bkgpar->attribute("file")); | |
| 525 | + std::string bkgname = gammalib::xml_file_expand(xml, | |
| 526 | + bkgpar->attribute("file")); | |
| 524 | 527 | |
| 525 | 528 | // Load cubes |
| 526 | 529 | m_exposure.load(expname); |
| ... | ... | @@ -530,7 +533,8 @@ void GCTAResponseCube::read(const GXmlElement& xml) |
| 530 | 533 | // Optionally load energy dispersion cube |
| 531 | 534 | if (gammalib::xml_has_par(xml, "EdispCube")) { |
| 532 | 535 | const GXmlElement* edisppar = gammalib::xml_get_par(G_READ, xml, "EdispCube"); |
| 533 | - std::string edispname = gammalib::strip_whitespace(edisppar->attribute("file")); | |
| 536 | + std::string edispname = gammalib::xml_file_expand(xml, | |
| 537 | + edisppar->attribute("file")); | |
| 534 | 538 | m_edisp.load(edispname); |
| 535 | 539 | m_has_edisp = true; |
| 536 | 540 | } |
| ... | ... | @@ -561,14 +565,14 @@ void GCTAResponseCube::read(const GXmlElement& xml) |
| 561 | 565 | void GCTAResponseCube::write(GXmlElement& xml) const |
| 562 | 566 | { |
| 563 | 567 | // Add exposure cube filename |
| 564 | - std::string filename = gammalib::strip_whitespace(m_exposure.filename()); | |
| 568 | + std::string filename = gammalib::xml_file_reduce(xml, m_exposure.filename()); | |
| 565 | 569 | if (!(filename.empty())) { |
| 566 | 570 | GXmlElement* par = gammalib::xml_need_par(G_WRITE, xml, "ExposureCube"); |
| 567 | 571 | par->attribute("file", filename); |
| 568 | 572 | } |
| 569 | 573 | |
| 570 | 574 | // Add PSF cube filename |
| 571 | - filename = gammalib::strip_whitespace(m_psf.filename()); | |
| 575 | + filename = gammalib::xml_file_reduce(xml, m_psf.filename()); | |
| 572 | 576 | if (!(filename.empty())) { |
| 573 | 577 | GXmlElement* par = gammalib::xml_need_par(G_WRITE, xml, "PsfCube"); |
| 574 | 578 | par->attribute("file", filename); |
| ... | ... | @@ -576,7 +580,7 @@ void GCTAResponseCube::write(GXmlElement& xml) const |
| 576 | 580 | |
| 577 | 581 | // Optionally add energy dispersions cube filename |
| 578 | 582 | if (m_has_edisp) { |
| 579 | - filename = gammalib::strip_whitespace(m_edisp.filename()); | |
| 583 | + filename = gammalib::xml_file_reduce(xml, m_edisp.filename()); | |
| 580 | 584 | if (!(filename.empty())) { |
| 581 | 585 | GXmlElement* par = gammalib::xml_need_par(G_WRITE, xml, "EdispCube"); |
| 582 | 586 | par->attribute("file", filename); |
| ... | ... | @@ -584,7 +588,7 @@ void GCTAResponseCube::write(GXmlElement& xml) const |
| 584 | 588 | } |
| 585 | 589 | |
| 586 | 590 | // Add background cube filename |
| 587 | - filename = gammalib::strip_whitespace(m_background.filename()); | |
| 591 | + filename = gammalib::xml_file_reduce(xml, m_background.filename()); | |
| 588 | 592 | if (!(filename.empty())) { |
| 589 | 593 | GXmlElement* par = gammalib::xml_need_par(G_WRITE, xml, "BkgCube"); |
| 590 | 594 | par->attribute("file", filename); | ... | ... |
inst/cta/test/data/cena_lobes_parkes.fits.gz
0 → 100644
No preview for this file type
inst/cta/test/data/irf_1dc.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="000001" instrument="CTA"> |
| 3 | - <parameter name="CountsCube" file="$(PACKAGE_SOURCE)/inst/cta/test/data/crab_cntmap.fits"/> | |
| 3 | + <parameter name="CountsCube" file="crab_cntmap.fits"/> | |
| 4 | 4 | <parameter name="EffectiveArea" file="$(PACKAGE_SOURCE)/inst/cta/test/caldb/dc1/arf.fits"/> |
| 5 | 5 | <parameter name="PointSpreadFunction" file="$(PACKAGE_SOURCE)/inst/cta/test/caldb/dc1/psf_magic.fits"/> |
| 6 | 6 | <parameter name="EnergyDispersion" file="$(PACKAGE_SOURCE)/inst/cta/test/caldb/dc1/rmf.fits"/> | ... | ... |
inst/cta/test/data/irf_binned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="000001" instrument="CTA"> |
| 3 | - <parameter name="CountsCube" file="$(PACKAGE_SOURCE)/inst/cta/test/data/crab_cntmap.fits"/> | |
| 3 | + <parameter name="CountsCube" file="crab_cntmap.fits"/> | |
| 4 | 4 | <parameter name="EffectiveArea" file="$(PACKAGE_SOURCE)/inst/cta/caldb/data/cta/e/bcf/IFAE20120510_50h/irf_file.fits"/> |
| 5 | 5 | <parameter name="PointSpreadFunction" file="$(PACKAGE_SOURCE)/inst/cta/caldb/data/cta/e/bcf/IFAE20120510_50h/irf_file.fits"/> |
| 6 | 6 | <parameter name="EnergyDispersion" file="$(PACKAGE_SOURCE)/inst/cta/caldb/data/cta/e/bcf/IFAE20120510_50h/irf_file.fits"/> | ... | ... |
inst/cta/test/data/irf_unbinned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="000001" instrument="CTA"> |
| 3 | - <parameter name="EventList" file="$(PACKAGE_SOURCE)/inst/cta/test/data/crab_events.fits"/> | |
| 3 | + <parameter name="EventList" file="crab_events.fits"/> | |
| 4 | 4 | <parameter name="EffectiveArea" file="$(PACKAGE_SOURCE)/inst/cta/test/caldb/cta_dummy_irf.dat"/> |
| 5 | 5 | <parameter name="PointSpreadFunction" file="$(PACKAGE_SOURCE)/inst/cta/test/caldb/cta_dummy_irf.dat"/> |
| 6 | 6 | <parameter name="EnergyDispersion" file="$(PACKAGE_SOURCE)/inst/cta/test/caldb/cta_dummy_irf.dat"/> | ... | ... |
inst/cta/test/data/obs_binned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="CTA"> |
| 3 | - <parameter name="CountsCube" file="$(PACKAGE_SOURCE)/inst/cta/test/data/crab_cntmap.fits"/> | |
| 3 | + <parameter name="CountsCube" file="crab_cntmap.fits"/> | |
| 4 | 4 | </observation> |
| 5 | 5 | </observation_list> | ... | ... |
inst/cta/test/data/obs_unbinned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="CTA"> |
| 3 | - <parameter name="EventList" file="$(PACKAGE_SOURCE)/inst/cta/test/data/crab_events.fits"/> | |
| 3 | + <parameter name="EventList" file="crab_events.fits"/> | |
| 4 | 4 | </observation> |
| 5 | 5 | </observation_list> | ... | ... |
inst/cta/test/data/onoff_obs.xml
| 1 | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | 2 | <observation_list title="observation list"> |
| 3 | 3 | <observation name="Crab" id="00001" instrument="CTAOnOff"> |
| 4 | - <parameter name="Pha_on" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_pha_on.fits" /> | |
| 5 | - <parameter name="Pha_off" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_pha_off.fits" /> | |
| 6 | - <parameter name="Regions_on" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_region_on.reg" /> | |
| 7 | - <parameter name="Regions_off" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_region_off.reg" /> | |
| 8 | - <parameter name="Arf" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_arf.fits" /> | |
| 9 | - <parameter name="Rmf" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_rmf.fits" /> | |
| 4 | + <parameter name="Pha_on" file="onoff_pha_on.fits" /> | |
| 5 | + <parameter name="Pha_off" file="onoff_pha_off.fits" /> | |
| 6 | + <parameter name="Regions_on" file="onoff_region_on.reg" /> | |
| 7 | + <parameter name="Regions_off" file="onoff_region_off.reg" /> | |
| 8 | + <parameter name="Arf" file="onoff_arf.fits" /> | |
| 9 | + <parameter name="Rmf" file="onoff_rmf.fits" /> | |
| 10 | 10 | </observation> |
| 11 | 11 | </observation_list> | ... | ... |
inst/cta/test/data/rsp_models.xml
| ... | ... | @@ -6,7 +6,7 @@ |
| 6 | 6 | <parameter scale="1.0" name="Index" min="-5.0" max="+5.0" value="-2.1" free="1"/> |
| 7 | 7 | <parameter scale="1.0" name="Scale" min="10.0" max="1000000.0" value="100.0" free="0"/> |
| 8 | 8 | </spectrum> |
| 9 | - <spatialModel type="SpatialMap" file="data/cena_lobes_parkes.fits"> | |
| 9 | + <spatialModel type="SpatialMap" file="cena_lobes_parkes.fits"> | |
| 10 | 10 | <parameter scale="1" name="Prefactor" min="0.001" max="1000.0" value="1" free="0"/> |
| 11 | 11 | </spatialModel> |
| 12 | 12 | </source> | ... | ... |
inst/cta/test/data/stacked_obs.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="CTA"> |
| 3 | - <parameter name="CountsCube" file="$(PACKAGE_SOURCE)/inst/cta/test/data/stacked_cntcube.fits"/> | |
| 4 | - <parameter name="ExposureCube" file="$(PACKAGE_SOURCE)/inst/cta/test/data/stacked_expcube.fits"/> | |
| 5 | - <parameter name="PsfCube" file="$(PACKAGE_SOURCE)/inst/cta/test/data/stacked_psfcube.fits"/> | |
| 6 | - <parameter name="BkgCube" file="$(PACKAGE_SOURCE)/inst/cta/test/data/stacked_bkgcube.fits"/> | |
| 3 | + <parameter name="CountsCube" file="stacked_cntcube.fits"/> | |
| 4 | + <parameter name="ExposureCube" file="stacked_expcube.fits"/> | |
| 5 | + <parameter name="PsfCube" file="stacked_psfcube.fits"/> | |
| 6 | + <parameter name="BkgCube" file="stacked_bkgcube.fits"/> | |
| 7 | 7 | </observation> |
| 8 | 8 | </observation_list> | ... | ... |
inst/lat/src/GLATObservation.cpp
| ... | ... | @@ -340,9 +340,23 @@ void GLATObservation::read(const GXmlElement& xml) |
| 340 | 340 | |
| 341 | 341 | // Load data |
| 342 | 342 | if (unbin_ok) { |
| 343 | + | |
| 344 | + // Expand file names | |
| 345 | + ft1file = gammalib::xml_file_expand(xml, ft1file); | |
| 346 | + ft2file = gammalib::xml_file_expand(xml, ft2file); | |
| 347 | + ltfile = gammalib::xml_file_expand(xml, ltfile); | |
| 348 | + | |
| 349 | + // Load files | |
| 343 | 350 | load_unbinned(ft1file, ft2file, ltfile); |
| 344 | 351 | } |
| 345 | 352 | else { |
| 353 | + | |
| 354 | + // Expand file names | |
| 355 | + cntfile = gammalib::xml_file_expand(xml, cntfile); | |
| 356 | + expfile = gammalib::xml_file_expand(xml, expfile); | |
| 357 | + ltfile = gammalib::xml_file_expand(xml, ltfile); | |
| 358 | + | |
| 359 | + // Load files | |
| 346 | 360 | load_binned(cntfile, expfile, ltfile); |
| 347 | 361 | } |
| 348 | 362 | |
| ... | ... | @@ -434,31 +448,31 @@ void GLATObservation::write(GXmlElement& xml) const |
| 434 | 448 | |
| 435 | 449 | // Handle FT1 |
| 436 | 450 | if (par->attribute("name") == "FT1") { |
| 437 | - par->attribute("file", m_ft1file); | |
| 451 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_ft1file)); | |
| 438 | 452 | npar[0]++; |
| 439 | 453 | } |
| 440 | 454 | |
| 441 | 455 | // Handle CountsMap |
| 442 | 456 | else if (par->attribute("name") == "CountsMap") { |
| 443 | - par->attribute("file", m_cntfile); | |
| 457 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_cntfile)); | |
| 444 | 458 | npar[0]++; |
| 445 | 459 | } |
| 446 | 460 | |
| 447 | 461 | // Handle FT2 |
| 448 | 462 | else if (par->attribute("name") == "FT2") { |
| 449 | - par->attribute("file", m_ft2file); | |
| 463 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_ft2file)); | |
| 450 | 464 | npar[1]++; |
| 451 | 465 | } |
| 452 | 466 | |
| 453 | 467 | // Handle ExposureMap |
| 454 | 468 | else if (par->attribute("name") == "ExposureMap") { |
| 455 | - par->attribute("file", m_expfile); | |
| 469 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_expfile)); | |
| 456 | 470 | npar[1]++; |
| 457 | 471 | } |
| 458 | 472 | |
| 459 | 473 | // Handle LiveTimeCube |
| 460 | 474 | else if (par->attribute("name") == "LiveTimeCube") { |
| 461 | - par->attribute("file", m_ltfile); | |
| 475 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_ltfile)); | |
| 462 | 476 | npar[2]++; |
| 463 | 477 | } |
| 464 | 478 | ... | ... |
inst/lat/test/data/p6v3/obs_binned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="LAT"> |
| 3 | - <parameter name="CountsMap" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p6v3/srcmap.fits"/> | |
| 4 | - <parameter name="ExposureMap" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p6v3/binned_expmap.fits"/> | |
| 5 | - <parameter name="LiveTimeCube" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p6v3/ltcube.fits"/> | |
| 3 | + <parameter name="CountsMap" file="srcmap.fits"/> | |
| 4 | + <parameter name="ExposureMap" file="binned_expmap.fits"/> | |
| 5 | + <parameter name="LiveTimeCube" file="ltcube.fits"/> | |
| 6 | 6 | <parameter name="IRF" value="P6_V3_DIFFUSE"/> |
| 7 | 7 | </observation> |
| 8 | 8 | </observation_list> | ... | ... |
inst/lat/test/data/p6v3/obs_unbinned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="LAT"> |
| 3 | - <parameter name="FT1" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p6v3/ft1.fits"/> | |
| 4 | - <parameter name="FT2" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p6v3/ft2.fits"/> | |
| 5 | - <parameter name="LiveTimeCube" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p6v3/ltcube.fits"/> | |
| 3 | + <parameter name="FT1" file="ft1.fits"/> | |
| 4 | + <parameter name="FT2" file="ft2.fits"/> | |
| 5 | + <parameter name="LiveTimeCube" file="ltcube.fits"/> | |
| 6 | 6 | <parameter name="IRF" value="P6_V3_DIFFUSE"/> |
| 7 | 7 | </observation> |
| 8 | 8 | </observation_list> | ... | ... |
inst/lat/test/data/p6v3/source_model.xml
| 1 | 1 | <source_library title="source library"> |
| 2 | 2 | <source type="DiffuseSource" name="Extragal_diffuse"> |
| 3 | - <spectrum type="FileFunction" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p6v3/isotropic_iem_v02.txt"> | |
| 3 | + <spectrum type="FileFunction" file="isotropic_iem_v02.txt"> | |
| 4 | 4 | <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/> |
| 5 | 5 | </spectrum> |
| 6 | 6 | <spatialModel type="ConstantValue"> |
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | <spectrum type="ConstantValue"> |
| 12 | 12 | <parameter scale="1.0" name="Value" min="0.0" max="1000.0" value="1.0" free="1"/> |
| 13 | 13 | </spectrum> |
| 14 | - <spatialModel type="MapCubeFunction" file="$(PACKAGE_SOURCE)/test/data/test_cube.fits"> | |
| 14 | + <spatialModel type="MapCubeFunction" file="test_cube.fits"> | |
| 15 | 15 | <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/> |
| 16 | 16 | </spatialModel> |
| 17 | 17 | </source> | ... | ... |
inst/lat/test/data/p7repv15/Crab.xml
| 1 | 1 | <source_library title="source library"> |
| 2 | 2 | <source name="iso_source_v05" type="DiffuseSource"> |
| 3 | - <spectrum file="$(PACKAGE_SOURCE)/inst/lat/test/data/p7repv15/iso_source_v05.txt" type="FileFunction"> | |
| 3 | + <spectrum file="iso_source_v05.txt" type="FileFunction"> | |
| 4 | 4 | <parameter free="1" max="10" min="0" name="Normalization" scale="1" value="1.0" /> |
| 5 | 5 | </spectrum> |
| 6 | 6 | <spatialModel type="ConstantValue"> |
| ... | ... | @@ -13,7 +13,7 @@ |
| 13 | 13 | <parameter free="1" max="1" min="-1" name="Index" scale="1" value="0." /> |
| 14 | 14 | <parameter free="0" max="2000" min="50" name="Scale" scale="1" value="100" /> |
| 15 | 15 | </spectrum> |
| 16 | - <spatialModel type="MapCubeFunction" file="$(PACKAGE_SOURCE)/test/data/test_cube.fits"> | |
| 16 | + <spatialModel type="MapCubeFunction" file="test_cube.fits"> | |
| 17 | 17 | <parameter free="0" max="1000" min="0.001" name="Normalization" scale="1" value="1" /> |
| 18 | 18 | </spatialModel> |
| 19 | 19 | </source> | ... | ... |
inst/lat/test/data/p7repv15/crab_results_ctools.xml
| 1 | 1 | <?xml version="1.0" encoding="UTF-8" standalone="no"?> |
| 2 | 2 | <source_library title="source library"> |
| 3 | 3 | <source name="iso_source_v05" type="DiffuseSource"> |
| 4 | - <spectrum type="FileFunction" file="/Users/schulz/software/gammalib/inst/lat/test/data/p7repv15/iso_source_v05.txt"> | |
| 4 | + <spectrum type="FileFunction" file="iso_source_v05.txt"> | |
| 5 | 5 | <parameter name="Normalization" value="3.48618" error="0.694252" scale="1" min="0" max="10" free="1" /> |
| 6 | 6 | </spectrum> |
| 7 | 7 | <spatialModel type="ConstantValue"> |
| ... | ... | @@ -14,7 +14,7 @@ |
| 14 | 14 | <parameter name="Index" value="0.0695083" error="0.0745843" scale="1" min="-1" max="1" free="1" /> |
| 15 | 15 | <parameter name="Scale" value="100" scale="1" min="50" max="2000" free="0" /> |
| 16 | 16 | </spectrum> |
| 17 | - <spatialModel type="MapCubeFunction" file="/Users/schulz/software/gammalib/inst/lat/test/data/p7repv15/gll_iem_v05.fit"> | |
| 17 | + <spatialModel type="MapCubeFunction" file="gll_iem_v05.fit"> | |
| 18 | 18 | <parameter name="Normalization" value="1" scale="1" min="0.001" max="1000" free="0" /> |
| 19 | 19 | </spatialModel> |
| 20 | 20 | </source> | ... | ... |
inst/lat/test/data/p7repv15/crab_results_sciencetools.xml
| ... | ... | @@ -18,12 +18,12 @@ |
| 18 | 18 | <parameter error="0.0716234477" free="1" max="1" min="-1" name="Index" scale="1" value="0.08682762462" /> |
| 19 | 19 | <parameter free="0" max="2000" min="50" name="Scale" scale="1" value="100" /> |
| 20 | 20 | </spectrum> |
| 21 | - <spatialModel file="/lustre/fs8/group/hess/user/aschulz/lat_data/fssc_files/diffuse/p7rep/gll_iem_v05.fit" type="MapCubeFunction"> | |
| 21 | + <spatialModel file="gll_iem_v05.fit" type="MapCubeFunction"> | |
| 22 | 22 | <parameter free="0" max="1000" min="0.001" name="Normalization" scale="1" value="1" /> |
| 23 | 23 | </spatialModel> |
| 24 | 24 | </source> |
| 25 | 25 | <source name="iso_source_v05" type="DiffuseSource"> |
| 26 | - <spectrum file="/lustre/fs8/group/hess/user/aschulz/lat_data/fssc_files/diffuse/p7rep/iso_source_v05.txt" type="FileFunction"> | |
| 26 | + <spectrum file="iso_source_v05.txt" type="FileFunction"> | |
| 27 | 27 | <parameter error="0.6855552052" free="1" max="10" min="0" name="Normalization" scale="1" value="2.875818636" /> |
| 28 | 28 | </spectrum> |
| 29 | 29 | <spatialModel type="ConstantValue"> | ... | ... |
inst/lat/test/data/p7v6/crab_model.xml
| 1 | 1 | <source_library title="source library"> |
| 2 | 2 | <source type="DiffuseSource" name="Extragal_diffuse"> |
| 3 | - <spectrum type="FileFunction" file="data/p7v6/isotrop_2year_P76_source_v0.txt"> | |
| 3 | + <spectrum type="FileFunction" file="isotrop_2year_P76_source_v0.txt"> | |
| 4 | 4 | <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/> |
| 5 | 5 | </spectrum> |
| 6 | 6 | <spatialModel type="ConstantValue"> |
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | <spectrum type="ConstantValue"> |
| 12 | 12 | <parameter scale="1.0" name="Value" min="0.0" max="1000.0" value="1.0" free="1"/> |
| 13 | 13 | </spectrum> |
| 14 | - <spatialModel type="MapCubeFunction" file="../../../test/data/test_cube.fits"> | |
| 14 | + <spatialModel type="MapCubeFunction" file="test_cube.fits"> | |
| 15 | 15 | <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/> |
| 16 | 16 | </spatialModel> |
| 17 | 17 | </source> | ... | ... |
inst/lat/test/data/p7v6/obs_binned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="LAT"> |
| 3 | - <parameter name="CountsMap" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p7v6/srcmap.fits"/> | |
| 4 | - <parameter name="ExposureMap" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p7v6/binned_expmap.fits"/> | |
| 5 | - <parameter name="LiveTimeCube" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p7v6/ltcube.fits"/> | |
| 3 | + <parameter name="CountsMap" file="srcmap.fits"/> | |
| 4 | + <parameter name="ExposureMap" file="binned_expmap.fits"/> | |
| 5 | + <parameter name="LiveTimeCube" file="ltcube.fits"/> | |
| 6 | 6 | <parameter name="IRF" value="P7SOURCE_V6"/> |
| 7 | 7 | </observation> |
| 8 | 8 | </observation_list> | ... | ... |
inst/lat/test/data/p7v6/obs_unbinned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="LAT"> |
| 3 | - <parameter name="FT1" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p7v6/ft1.fits"/> | |
| 4 | - <parameter name="FT2" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p7v6/ft2.fits"/> | |
| 5 | - <parameter name="LiveTimeCube" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p7v6/ltcube.fits"/> | |
| 3 | + <parameter name="FT1" file="ft1.fits"/> | |
| 4 | + <parameter name="FT2" file="ft2.fits"/> | |
| 5 | + <parameter name="LiveTimeCube" file="ltcube.fits"/> | |
| 6 | 6 | <parameter name="IRF" value="P7SOURCE_V6"/> |
| 7 | 7 | </observation> |
| 8 | 8 | </observation_list> | ... | ... |
inst/lat/test/data/p7v6/source_model.xml
| 1 | 1 | <source_library title="source library"> |
| 2 | 2 | <source type="DiffuseSource" name="Extragal_diffuse"> |
| 3 | - <spectrum type="FileFunction" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p7v6/isotrop_2year_P76_source_v0.txt"> | |
| 3 | + <spectrum type="FileFunction" file="isotrop_2year_P76_source_v0.txt"> | |
| 4 | 4 | <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/> |
| 5 | 5 | </spectrum> |
| 6 | 6 | <spatialModel type="ConstantValue"> |
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | <spectrum type="ConstantValue"> |
| 12 | 12 | <parameter scale="1.0" name="Value" min="0.0" max="1000.0" value="1.0" free="1"/> |
| 13 | 13 | </spectrum> |
| 14 | - <spatialModel type="MapCubeFunction" file="$(PACKAGE_SOURCE)/test/data/test_cube.fits"> | |
| 14 | + <spatialModel type="MapCubeFunction" file="test_cube.fits"> | |
| 15 | 15 | <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/> |
| 16 | 16 | </spatialModel> |
| 17 | 17 | </source> | ... | ... |
inst/lat/test/data/p8v2/obs_binned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="LAT"> |
| 3 | - <parameter name="CountsMap" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p8v2/srcmap.fits"/> | |
| 4 | - <parameter name="ExposureMap" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p8v2/binned_expmap.fits"/> | |
| 5 | - <parameter name="LiveTimeCube" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p8v2/ltcube.fits"/> | |
| 3 | + <parameter name="CountsMap" file="srcmap.fits"/> | |
| 4 | + <parameter name="ExposureMap" file="binned_expmap.fits"/> | |
| 5 | + <parameter name="LiveTimeCube" file="ltcube.fits"/> | |
| 6 | 6 | <parameter name="IRF" value="P8R2_SOURCE_V6"/> |
| 7 | 7 | </observation> |
| 8 | 8 | </observation_list> | ... | ... |
inst/lat/test/data/p8v2/obs_unbinned.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="LAT"> |
| 3 | - <parameter name="FT1" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p8v2/ft1.fits"/> | |
| 4 | - <parameter name="FT2" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p8v2/ft2.fits"/> | |
| 5 | - <parameter name="LiveTimeCube" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p8v2/ltcube.fits"/> | |
| 3 | + <parameter name="FT1" file="ft1.fits"/> | |
| 4 | + <parameter name="FT2" file="ft2.fits"/> | |
| 5 | + <parameter name="LiveTimeCube" file="ltcube.fits"/> | |
| 6 | 6 | <parameter name="IRF" value="P8R2_SOURCE_V6"/> |
| 7 | 7 | </observation> |
| 8 | 8 | </observation_list> | ... | ... |
inst/lat/test/data/p8v2/source_model.xml
| 1 | 1 | <source_library title="source library"> |
| 2 | 2 | <source type="DiffuseSource" name="Extragal_diffuse"> |
| 3 | - <spectrum type="FileFunction" file="$(PACKAGE_SOURCE)/inst/lat/test/data/p8v2/iso_P8R2_SOURCE_V6_v06.txt"> | |
| 3 | + <spectrum type="FileFunction" file="iso_P8R2_SOURCE_V6_v06.txt"> | |
| 4 | 4 | <parameter scale="1.0" name="Normalization" min="0.0" max="1000.0" value="1.0" free="1"/> |
| 5 | 5 | </spectrum> |
| 6 | 6 | <spatialModel type="ConstantValue"> |
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | <spectrum type="ConstantValue"> |
| 12 | 12 | <parameter scale="1.0" name="Value" min="0.0" max="1000.0" value="1.0" free="1"/> |
| 13 | 13 | </spectrum> |
| 14 | - <spatialModel type="MapCubeFunction" file="$(PACKAGE_SOURCE)/test/data/test_cube.fits"> | |
| 14 | + <spatialModel type="MapCubeFunction" file="test_cube.fits"> | |
| 15 | 15 | <parameter scale="1" name="Normalization" min="0.001" max="1000.0" value="1" free="0"/> |
| 16 | 16 | </spatialModel> |
| 17 | 17 | </source> | ... | ... |
inst/mwl/src/GMWLObservation.cpp
| ... | ... | @@ -232,11 +232,6 @@ void GMWLObservation::response(const GResponse& rsp) |
| 232 | 232 | * |
| 233 | 233 | * @param[in] xml XML element. |
| 234 | 234 | * |
| 235 | - * @exception GException::xml_invalid_parnum | |
| 236 | - * Invalid number of parameters found in XML element. | |
| 237 | - * @exception GException::xml_invalid_parnames | |
| 238 | - * Invalid parameter names found in XML element. | |
| 239 | - * | |
| 240 | 235 | * Reads information for a multi-wavelength observation from an XML element. |
| 241 | 236 | * The expected format of the XML element is |
| 242 | 237 | * |
| ... | ... | @@ -255,52 +250,15 @@ void GMWLObservation::read(const GXmlElement& xml) |
| 255 | 250 | // Clear observation |
| 256 | 251 | clear(); |
| 257 | 252 | |
| 258 | - // Determine number of parameter nodes in XML element | |
| 259 | - int npars = xml.elements("parameter"); | |
| 260 | - | |
| 261 | - // Verify that XML element has exactly 2 parameters | |
| 262 | - if (xml.elements() != 2 || npars != 2) { | |
| 263 | - throw GException::xml_invalid_parnum(G_READ, xml, | |
| 264 | - "MWL observation requires exactly 2 parameters."); | |
| 265 | - } | |
| 266 | - | |
| 267 | - // Extract parameters | |
| 268 | - int npar[2] = {0, 0}; | |
| 269 | - for (int i = 0; i < npars; ++i) { | |
| 270 | - | |
| 271 | - // Get parameter element | |
| 272 | - const GXmlElement* par = xml.element("parameter", i); | |
| 253 | + // Get parameters | |
| 254 | + m_instrument = gammalib::xml_get_attr(G_READ, xml, "Instrument", "value"); | |
| 255 | + std::string filename = gammalib::xml_get_attr(G_READ, xml, "Data", "file"); | |
| 273 | 256 | |
| 274 | - // Handle Instrument name | |
| 275 | - if (par->attribute("name") == "Instrument") { | |
| 276 | - | |
| 277 | - // Read instrument name | |
| 278 | - m_instrument = par->attribute("value"); | |
| 279 | - | |
| 280 | - // Increment parameter counter | |
| 281 | - npar[0]++; | |
| 282 | - } | |
| 257 | + // Expand file names | |
| 258 | + filename = gammalib::xml_file_expand(xml, filename); | |
| 283 | 259 | |
| 284 | - // Handle data filename | |
| 285 | - else if (par->attribute("name") == "Data") { | |
| 286 | - | |
| 287 | - // Read filename | |
| 288 | - GFilename filename = par->attribute("file"); | |
| 289 | - | |
| 290 | - // Load file | |
| 291 | - load(filename); | |
| 292 | - | |
| 293 | - // Increment parameter counter | |
| 294 | - npar[1]++; | |
| 295 | - } | |
| 296 | - | |
| 297 | - } // endfor: looped over all parameters | |
| 298 | - | |
| 299 | - // Verify that all parameters were found | |
| 300 | - if (npar[0] != 1 || npar[1] != 1) { | |
| 301 | - throw GException::xml_invalid_parnames(G_READ, xml, | |
| 302 | - "Require \"Instrument\" and \"Data\" parameters."); | |
| 303 | - } | |
| 260 | + // Load file | |
| 261 | + load(filename); | |
| 304 | 262 | |
| 305 | 263 | // Return |
| 306 | 264 | return; |
| ... | ... | @@ -327,43 +285,16 @@ void GMWLObservation::read(const GXmlElement& xml) |
| 327 | 285 | ***************************************************************************/ |
| 328 | 286 | void GMWLObservation::write(GXmlElement& xml) const |
| 329 | 287 | { |
| 330 | - // If XML element has 0 nodes then append 2 parameter nodes | |
| 331 | - if (xml.elements() == 0) { | |
| 332 | - xml.append(GXmlElement("parameter name=\"Instrument\"")); | |
| 333 | - xml.append(GXmlElement("parameter name=\"Data\"")); | |
| 334 | - } | |
| 335 | - | |
| 336 | - // Verify that XML element has exactly 2 parameters | |
| 337 | - if (xml.elements() != 2 || xml.elements("parameter") != 2) { | |
| 338 | - throw GException::xml_invalid_parnum(G_WRITE, xml, | |
| 339 | - "MWL observation requires exactly 2 parameters."); | |
| 340 | - } | |
| 341 | - | |
| 342 | - // Set or update parameter attributes | |
| 343 | - int npar[] = {0, 0}; | |
| 344 | - for (int i = 0; i < 2; ++i) { | |
| 345 | - | |
| 346 | - // Get parameter element | |
| 347 | - GXmlElement* par = xml.element("parameter", i); | |
| 348 | - | |
| 349 | - // Handle Instrument | |
| 350 | - if (par->attribute("name") == "Instrument") { | |
| 351 | - npar[0]++; | |
| 352 | - par->attribute("value", m_instrument); | |
| 353 | - } | |
| 354 | - | |
| 355 | - // Handle Data | |
| 356 | - else if (par->attribute("name") == "Data") { | |
| 357 | - npar[1]++; | |
| 358 | - par->attribute("file", m_filename); | |
| 359 | - } | |
| 288 | + // Allocate XML element pointer | |
| 289 | + GXmlElement* par; | |
| 360 | 290 | |
| 361 | - } // endfor: looped over all parameters | |
| 291 | + // Set Instrument parameter | |
| 292 | + par = gammalib::xml_need_par(G_WRITE, xml, "Instrument"); | |
| 293 | + par->attribute("value", gammalib::xml_file_reduce(xml, m_instrument)); | |
| 362 | 294 | |
| 363 | - // Check of all required parameters are present | |
| 364 | - if (npar[0] != 1 || npar[1] != 1) | |
| 365 | - throw GException::xml_invalid_parnames(G_WRITE, xml, | |
| 366 | - "Require \"Instrument\" and \"Data\" parameters."); | |
| 295 | + // Set Data parameter | |
| 296 | + par = gammalib::xml_need_par(G_WRITE, xml, "Data"); | |
| 297 | + par->attribute("file", gammalib::xml_file_reduce(xml, m_filename)); | |
| 367 | 298 | |
| 368 | 299 | // Return |
| 369 | 300 | return; | ... | ... |
inst/mwl/test/data/obs_mwl.xml
| 1 | 1 | <observation_list title="observation library"> |
| 2 | 2 | <observation name="Crab" id="00001" instrument="MWL"> |
| 3 | 3 | <parameter name="Instrument" value="COMPTEL"/> |
| 4 | - <parameter name="Data" file="$(PACKAGE_SOURCE)/inst/mwl/test/data/crab_mwl.fits[COMPTEL]"/> | |
| 4 | + <parameter name="Data" file="crab_mwl.fits[COMPTEL]"/> | |
| 5 | 5 | </observation> |
| 6 | 6 | <observation name="Crab" id="00002" instrument="MWL"> |
| 7 | 7 | <parameter name="Instrument" value="LAT"/> |
| 8 | - <parameter name="Data" file="$(PACKAGE_SOURCE)/inst/mwl/test/data/crab_mwl.fits[LAT]"/> | |
| 8 | + <parameter name="Data" file="crab_mwl.fits[LAT]"/> | |
| 9 | 9 | </observation> |
| 10 | 10 | <observation name="Crab" id="00003" instrument="MWL"> |
| 11 | 11 | <parameter name="Instrument" value="HESS"/> |
| 12 | - <parameter name="Data" file="$(PACKAGE_SOURCE)/inst/mwl/test/data/crab_mwl.fits[HESS]"/> | |
| 12 | + <parameter name="Data" file="crab_mwl.fits[HESS]"/> | |
| 13 | 13 | </observation> |
| 14 | 14 | </observation_list> | ... | ... |