Commit 0921a96fcbad97b3ec05f026abd8e96fef23d4e9

Authored by Jürgen Knödlseder
1 parent 719d9e62

Check response table dimension for consistency (#1848)

ChangeLog
1 -2016-08-12 1 +2016-09-26
2 2
3 * Version 1.2.0 released 3 * Version 1.2.0 released
4 ========================= 4 =========================
5 5
  6 + Check CTA response table dimension for consistency (#1848)
6 Add GTestSuite::test_value() method with automatic precision computation 7 Add GTestSuite::test_value() method with automatic precision computation
7 Add GSkyMap::is_empty() method (#1828) 8 Add GSkyMap::is_empty() method (#1828)
8 Add GApplication access by index operator (#1838) 9 Add GApplication access by index operator (#1838)
1 New Features and Important Changes in GammaLib 1.2.0 1 New Features and Important Changes in GammaLib 1.2.0
2 2
3 -12 August 2016 3 +26 September 2016
4 4
5 5
6 1. Introduction 6 1. Introduction
@@ -191,7 +191,8 @@ None @@ -191,7 +191,8 @@ None
191 191
192 20. CTA interface 192 20. CTA interface
193 ----------------- 193 -----------------
194 -None 194 +The dimension of response tables is now checked for being consistent with the
  195 +axis dimension (#1848).
195 196
196 197
197 21. COMPTEL interface 198 21. COMPTEL interface
inst/cta/src/GCTAResponseTable.cpp
@@ -1860,6 +1860,41 @@ void GCTAResponseTable::read_tables(const GFitsTable& hdu) @@ -1860,6 +1860,41 @@ void GCTAResponseTable::read_tables(const GFitsTable& hdu)
1860 throw GException::invalid_value(G_READ_TABLES, msg); 1860 throw GException::invalid_value(G_READ_TABLES, msg);
1861 } 1861 }
1862 1862
  1863 + // Check table dimension if there is dimension information
  1864 + if (col->dim().size() > 0) {
  1865 +
  1866 + // Check that the table dimension is identical to the number of
  1867 + // axis pairs
  1868 + if (axes() != col->dim().size()) {
  1869 + std::string msg = "Table column \""+m_colname_table[i]+"\" "
  1870 + "dimension "+
  1871 + gammalib::str(col->dim().size())+" is "
  1872 + "inconsistent with "+
  1873 + gammalib::str(axes())+" axis pairs. Please "
  1874 + "check the response table for consistency.";
  1875 + throw GException::invalid_value(G_READ_TABLES, msg);
  1876 + }
  1877 +
  1878 + // Check for all axes that the length of the axis columns is
  1879 + // identical to the size of the table in that axis direction
  1880 + for (int i = 0; i < axes(); ++i) {
  1881 + if (axis_bins(i) != col->dim()[i]) {
  1882 + std::string msg = "Table column \""+m_colname_table[i]+"\" "
  1883 + "has "+gammalib::str(col->dim()[i])+
  1884 + " bins in axis "+gammalib::str(i)+
  1885 + " while corresponding axis columns \""+
  1886 + m_colname_lo[i]+"\" and \""+
  1887 + m_colname_hi[i]+"\" have a length of "+
  1888 + gammalib::str(axis_bins(i))+". Please "
  1889 + "check the response table for "
  1890 + "consistency.";
  1891 + throw GException::invalid_value(G_READ_TABLES, msg);
  1892 + }
  1893 + }
  1894 +
  1895 + } // endif: table had dimension information
  1896 +
  1897 +
1863 // Initialise table 1898 // Initialise table
1864 std::vector<double> table(num); 1899 std::vector<double> table(num);
1865 1900