Commit feb967a7fcad9589d689c0bad5a119292ac2140c

Authored by Jürgen Knödlseder
1 parent c095e55a

Add filename expansion for IAQ name in XML file and support empty DRB filenames

Showing 1 changed file with 40 additions and 26 deletions
inst/com/src/GCOMObservation.cpp
@@ -455,16 +455,24 @@ void GCOMObservation::read(const GXmlElement& xml) @@ -455,16 +455,24 @@ void GCOMObservation::read(const GXmlElement& xml)
455 std::string iaqname = gammalib::xml_get_attr(G_READ, xml, "IAQ", "value"); 455 std::string iaqname = gammalib::xml_get_attr(G_READ, xml, "IAQ", "value");
456 456
457 // Expand file names 457 // Expand file names
458 - drename = gammalib::xml_file_expand(xml, drename);  
459 - drbname = gammalib::xml_file_expand(xml, drbname);  
460 - drgname = gammalib::xml_file_expand(xml, drgname);  
461 - drxname = gammalib::xml_file_expand(xml, drxname); 458 + drename = gammalib::xml_file_expand(xml, drename);
  459 + drbname = gammalib::xml_file_expand(xml, drbname);
  460 + drgname = gammalib::xml_file_expand(xml, drgname);
  461 + drxname = gammalib::xml_file_expand(xml, drxname);
  462 + std::string iaqname_expanded = gammalib::xml_file_expand(xml, iaqname);
462 463
463 // Load observation 464 // Load observation
464 load(drename, drbname, drgname, drxname); 465 load(drename, drbname, drgname, drxname);
465 466
466 - // Load IAQ  
467 - response(GCaldb("cgro", "comptel"), iaqname); 467 + // Load IAQ by trying first the expanded name as a FITS file and
  468 + // otherwise the unexpanded name
  469 + GFilename filename_expanded(iaqname_expanded);
  470 + if (filename_expanded.is_fits()) {
  471 + response(GCaldb("cgro", "comptel"), iaqname_expanded);
  472 + }
  473 + else {
  474 + response(GCaldb("cgro", "comptel"), iaqname);
  475 + }
468 476
469 } // endelse: binned observation 477 } // endelse: binned observation
470 478
@@ -559,7 +567,7 @@ void GCOMObservation::write(GXmlElement& xml) const @@ -559,7 +567,7 @@ void GCOMObservation::write(GXmlElement& xml) const
559 567
560 // Set IAQ parameter 568 // Set IAQ parameter
561 par = gammalib::xml_need_par(G_WRITE, xml, "IAQ"); 569 par = gammalib::xml_need_par(G_WRITE, xml, "IAQ");
562 - par->attribute("value", m_response.rspname()); 570 + par->attribute("value", gammalib::xml_file_reduce(xml, m_response.rspname()));
563 571
564 } // endif: observation was binned 572 } // endif: observation was binned
565 573
@@ -1000,34 +1008,40 @@ void GCOMObservation::load_dre(const GFilename& drename) @@ -1000,34 +1008,40 @@ void GCOMObservation::load_dre(const GFilename& drename)
1000 * DRB data space incompatible with DRE data space. 1008 * DRB data space incompatible with DRE data space.
1001 * 1009 *
1002 * Load the background model from the primary image of the specified FITS 1010 * Load the background model from the primary image of the specified FITS
1003 - * file. 1011 + * file. Since a DRB file is optional the method does nothing if the DRB
  1012 + * filename is empty.
1004 ***************************************************************************/ 1013 ***************************************************************************/
1005 void GCOMObservation::load_drb(const GFilename& drbname) 1014 void GCOMObservation::load_drb(const GFilename& drbname)
1006 { 1015 {
1007 - // Open FITS file  
1008 - GFits fits(drbname); 1016 + // Continue only if filename is not empty
  1017 + if (!drbname.is_empty()) {
1009 1018
1010 - // Get image  
1011 - const GFitsImage& image = *fits.image("Primary"); 1019 + // Open FITS file
  1020 + GFits fits(drbname);
1012 1021
1013 - // Read background model  
1014 - m_drb.read(image); 1022 + // Get image
  1023 + const GFitsImage& image = *fits.image("Primary");
1015 1024
1016 - // Correct WCS projection (HEASARC data format kluge)  
1017 - gammalib::com_wcs_mer2car(const_cast<GSkyMap&>(m_drb.map())); 1025 + // Read background model
  1026 + m_drb.read(image);
1018 1027
1019 - // Close FITS file  
1020 - fits.close(); 1028 + // Correct WCS projection (HEASARC data format kluge)
  1029 + gammalib::com_wcs_mer2car(const_cast<GSkyMap&>(m_drb.map()));
1021 1030
1022 - // Check map dimensions  
1023 - if (!check_dri(m_drb)) {  
1024 - std::string msg = "DRB data cube \""+drbname+"\" incompatible with "  
1025 - "DRE data cube \""+m_drename+"\".";  
1026 - throw GException::invalid_value(G_LOAD_DRB, msg);  
1027 - } 1031 + // Close FITS file
  1032 + fits.close();
  1033 +
  1034 + // Check map dimensions
  1035 + if (!check_dri(m_drb)) {
  1036 + std::string msg = "DRB data cube \""+drbname+"\" incompatible with "
  1037 + "DRE data cube \""+m_drename+"\".";
  1038 + throw GException::invalid_value(G_LOAD_DRB, msg);
  1039 + }
  1040 +
  1041 + // Store DRB filename
  1042 + m_drbname = drbname;
1028 1043
1029 - // Store DRB filename  
1030 - m_drbname = drbname; 1044 + } // endif: DRB filename was empty
1031 1045
1032 // Return 1046 // Return
1033 return; 1047 return;