diff --git a/AUTHORS b/AUTHORS index e0cc24b..6fe0a5f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,4 +12,3 @@ Michael Mayer (michael.mayer@physik.hu-berlin.de) Ellis Owen (Ellis.Owen@mpi-hd.mpg.de) Anneli Schulz (anneli.schulz@desy.de) Hubert Siejkowski (h.siejkowski@cyfronet.pl) - diff --git a/ChangeLog b/ChangeLog index 36decb1..e47e9b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,9 +1,10 @@ -2015-01-14 Juergen Knoedlseder +2015-01-30 Juergen Knoedlseder * Bug fix version 0.9.2 released ================================ Use URL path informtion in GVOClient connection to Hub + Ignore empty string parameters in GModel::is_valid() Add some constructors diff --git a/NEWS b/NEWS index 1404818..dc38956 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 00-09-02 Author(s) : Juergen Knoedlseder -14 January 2015 +30 January 2015 1. Introduction @@ -43,7 +43,12 @@ None 8. Model module --------------- -None +The GModel::is_valid() method now allows specifying empty strings for the +instrument and id parameters that will skip the specific model validity +check. This allows to check for models of a given identifier whatever the +instrument, or for models for a given instrument, whatever the identifier. + +Added unit tests for GModel base class methods. 9. Numerics module diff --git a/src/model/GModel.cpp b/src/model/GModel.cpp index c6defa9..0d5a224 100644 --- a/src/model/GModel.cpp +++ b/src/model/GModel.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GModel.cpp - Abstract virtual model base class * * ----------------------------------------------------------------------- * - * copyright (C) 2009-2014 by Juergen Knoedlseder * + * copyright (C) 2009-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -493,6 +493,12 @@ void GModel::ids(const std::string& ids) * If the list of applicable instruments is empty, the model applies to all * possible instruments. If the list of applicable observation identifiers * is empty, the model applies to all identifiers. + * + * If an empty string is provided as @p instrument parameter, the check for + * instrument validity will be skipped. Similarily, if an empty string is + * provided as @p id parameter, the identifier check will be skipped. This + * allows for example to check for models of a given identifier whatever the + * instrument, or for models for a given instrument, whatever the identifier. ***************************************************************************/ bool GModel::is_valid(const std::string& instrument, const std::string& id) const @@ -501,7 +507,7 @@ bool GModel::is_valid(const std::string& instrument, bool valid = true; // Check if model applies to instrument - if (!m_instruments.empty()) { + if (!m_instruments.empty() && !instrument.empty()) { // Initialise validity flag valid = false; @@ -517,7 +523,7 @@ bool GModel::is_valid(const std::string& instrument, } // Check if model applies to observation identifier - if (valid && !m_ids.empty()) { + if (valid && !m_ids.empty() && !id.empty()) { // Initialise validity flag valid = false; diff --git a/test/test_GModel.cpp b/test/test_GModel.cpp index bfd96d4..e4c2f1f 100644 --- a/test/test_GModel.cpp +++ b/test/test_GModel.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * test_GModel.cpp - test GModel class * * ----------------------------------------------------------------------- * - * copyright (C) 2009-2014 by Juergen Knoedlseder * + * copyright (C) 2009-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -97,6 +97,9 @@ void TestGModel::set(void) // Append temporal model tests append(static_cast(&TestGModel::test_temp_const), "Test GModelTemporalConst"); + // Append genereric model tests + append(static_cast(&TestGModel::test_model), "Test GModel"); + // Append model container tests append(static_cast(&TestGModel::test_models), "Test GModels"); @@ -2136,6 +2139,71 @@ void TestGModel::test_spectral_model(void) /***********************************************************************//** + * @brief Test model base class functions + ***************************************************************************/ +void TestGModel::test_model(void) +{ + // Setup some models (use the sky model for that) + GModelSky model; + + // Test instruments setting + model.instruments("CTA"); + test_assert(model.instruments() == "CTA", + "Expected \"CTA\" instruments, found \""+ + model.instruments()+"\"."); + test_assert(model.is_valid("CTA", ""), "Model is not a \"CTA\" model."); + test_assert(model.is_valid("CTA", "123"), "Model ID selection error."); + model.instruments("CTA,LAT"); + test_assert(model.instruments() == "CTA,LAT", + "Expected \"CTA,LAT\" instruments, found \""+ + model.instruments()+"\"."); + test_assert(model.is_valid("CTA", ""), "Model is not a \"CTA\" model."); + test_assert(model.is_valid("LAT", ""), "Model is not a \"LAT\" model."); + test_assert(model.is_valid("CTA", "123"), "Model ID selection error."); + test_assert(model.is_valid("LAT", "123"), "Model ID selection error."); + + // Test ID setting + model.clear(); + model.ids("123"); + test_assert(model.ids() == "123", + "Expected ID \"123\" instruments, found \""+model.ids()+"\"."); + test_assert(model.is_valid("", "123"), "Model ID is not \"123\"."); + test_assert(model.is_valid("CTA", "123"), "Model instrument selection error."); + model.ids("123,456"); + test_assert(model.ids() == "123,456", + "Expected ID \"123,456\" instruments, found \""+ + model.ids()+"\"."); + test_assert(model.is_valid("", "123"), "Model ID is not \"123\"."); + test_assert(model.is_valid("", "456"), "Model ID is not \"456\"."); + test_assert(model.is_valid("CTA", "123"), "Model instrument selection error."); + test_assert(model.is_valid("CTA", "456"), "Model instrument selection error."); + + // Test instrument and ID setting + model.clear(); + model.instruments("CTA"); + model.ids("123"); + test_assert(model.instruments() == "CTA", + "Expected \"CTA\" instruments, found \""+ + model.instruments()+"\"."); + test_assert(model.ids() == "123", + "Expected ID \"123\" instruments, found \""+model.ids()+"\"."); + test_assert(model.is_valid("CTA", "123"), "Test model instrument and ID."); + test_assert(!model.is_valid("CTAx", "123"), "Test failure mode."); + test_assert(!model.is_valid("CTA", "123x"), "Test failure mode."); + model.instruments("CTA,LAT"); + model.ids("123,456"); + test_assert(model.is_valid("", ""), "Test model instrument and ID."); + test_assert(model.is_valid("CTA", "123"), "Test model instrument and ID."); + test_assert(model.is_valid("LAT", "123"), "Test model instrument and ID."); + test_assert(model.is_valid("CTA", "456"), "Test model instrument and ID."); + test_assert(model.is_valid("LAT", "456"), "Test model instrument and ID."); + + // Return + return; +} + + +/***********************************************************************//** * @brief Test model container handling ***************************************************************************/ void TestGModel::test_models(void) diff --git a/test/test_GModel.hpp b/test/test_GModel.hpp index 01155f0..231b7f1 100644 --- a/test/test_GModel.hpp +++ b/test/test_GModel.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * test_GModel.hpp - Test model module * * ----------------------------------------------------------------------- * - * copyright (C) 2012-2014 by Jean-Baptiste Cayrou * + * copyright (C) 2012-2015 by Jean-Baptiste Cayrou * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -70,6 +70,7 @@ public: void test_filefct(void); void test_spectral_model(void); void test_temp_const(void); + void test_model(void); void test_models(void); void test_model_registry(void);