Commit 14aba06c682e868bede182988d420df8c48ddcfb
1 parent
fbe73421
Integrate code.
Showing
9 changed files
with
118 additions
and
83 deletions
ChangeLog
| 1 | -2016-08-06 | |
| 1 | +2016-08-09 | |
| 2 | 2 | |
| 3 | 3 | * Version 1.2.0 released |
| 4 | 4 | ========================= |
| 5 | 5 | |
| 6 | + Add GApplication access by index operator (#1838) | |
| 6 | 7 | Add GApplication::pars() and GApplicationPar::current_value() methods (#1838) |
| 7 | 8 | Add GLog is_open(), is_empty() and written_size() methods (#1837) |
| 8 | 9 | Fix invalid pointer problem in GLog copies (#1823) | ... | ... |
NEWS
| 1 | 1 | New Features and Important Changes in GammaLib 1.2.0 |
| 2 | 2 | |
| 3 | -6 August 2016 | |
| 3 | +9 August 2016 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | 1. Introduction |
| ... | ... | @@ -27,6 +27,7 @@ The following methods have been added: |
| 27 | 27 | - GApplication::log_header1() |
| 28 | 28 | - GApplication::log_header2() |
| 29 | 29 | - GApplication::log_header3() |
| 30 | +- GApplication::operator[](const int& index) | |
| 30 | 31 | - GApplication::pars() |
| 31 | 32 | - GApplicationPar::current_value() |
| 32 | 33 | - GLog::is_open() |
| ... | ... | @@ -90,6 +91,9 @@ application parameters. The GApplicationPar::current_value() method has been |
| 90 | 91 | added to retrieve the current parameter value without querying for the parameter |
| 91 | 92 | (#1838). |
| 92 | 93 | |
| 94 | +Operators have been added to GApplication that allow the access of application | |
| 95 | +parameters by index (#1838). | |
| 96 | + | |
| 93 | 97 | |
| 94 | 98 | 5. Base module |
| 95 | 99 | -------------- | ... | ... |
README.md
| 1 | 1 | GammaLib information |
| 2 | 2 | ==================== |
| 3 | -* Version: 1.2.0.dev1 (6 August 2016) | |
| 3 | +* Version: 1.2.0.dev1 (9 August 2016) | |
| 4 | 4 | * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) |
| 5 | 5 | |
| 6 | 6 | [](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) | ... | ... |
include/GApplication.hpp
| ... | ... | @@ -149,6 +149,9 @@ std::string GApplication::classname(void) const |
| 149 | 149 | * @brief Parameter access operator |
| 150 | 150 | * |
| 151 | 151 | * @param[in] name Parameter name. |
| 152 | + * @return Reference to application parameter. | |
| 153 | + * | |
| 154 | + * Returns a reference to the application parameter with the given @p name. | |
| 152 | 155 | ***************************************************************************/ |
| 153 | 156 | inline |
| 154 | 157 | GApplicationPar& GApplication::operator[](const std::string& name) |
| ... | ... | @@ -161,6 +164,10 @@ GApplicationPar& GApplication::operator[](const std::string& name) |
| 161 | 164 | * @brief Parameter access operator (const version) |
| 162 | 165 | * |
| 163 | 166 | * @param[in] name Parameter name. |
| 167 | + * @return Constant reference to application parameter | |
| 168 | + * | |
| 169 | + * Returns a const reference to the application parameter with the given | |
| 170 | + * @p name. | |
| 164 | 171 | ***************************************************************************/ |
| 165 | 172 | inline |
| 166 | 173 | const GApplicationPar& GApplication::operator[](const std::string& name) const |
| ... | ... | @@ -170,6 +177,38 @@ const GApplicationPar& GApplication::operator[](const std::string& name) const |
| 170 | 177 | |
| 171 | 178 | |
| 172 | 179 | /***********************************************************************//** |
| 180 | + * @brief Parameter access operator | |
| 181 | + * | |
| 182 | + * @param[in] index Parameter index [0,...,pars().size()-1]. | |
| 183 | + * @return Reference to application parameter | |
| 184 | + * | |
| 185 | + * Returns a reference to the application parameter with the given @p index. | |
| 186 | + * No range checking is performed for the index. | |
| 187 | + ***************************************************************************/ | |
| 188 | +inline | |
| 189 | +GApplicationPar& GApplication::operator[](const int& index) | |
| 190 | +{ | |
| 191 | + return (m_pars[index]); | |
| 192 | +} | |
| 193 | + | |
| 194 | + | |
| 195 | +/***********************************************************************//** | |
| 196 | + * @brief Parameter access operator (const version) | |
| 197 | + * | |
| 198 | + * @param[in] index Parameter index [0,...,pars().size()-1]. | |
| 199 | + * @return Constant reference to application parameter | |
| 200 | + * | |
| 201 | + * Returns a const reference to the application parameter with the given | |
| 202 | + * @p index. No range checking is performed for the index. | |
| 203 | + ***************************************************************************/ | |
| 204 | +inline | |
| 205 | +const GApplicationPar& GApplication::operator[](const int& index) const | |
| 206 | +{ | |
| 207 | + return (m_pars[index]); | |
| 208 | +} | |
| 209 | + | |
| 210 | + | |
| 211 | +/***********************************************************************//** | |
| 173 | 212 | * @brief Return application name |
| 174 | 213 | * |
| 175 | 214 | * @return Application name. |
| ... | ... | @@ -272,28 +311,4 @@ void GApplication::pars(const GApplicationPars& pars) |
| 272 | 311 | return; |
| 273 | 312 | } |
| 274 | 313 | |
| 275 | - | |
| 276 | -/***********************************************************************//** | |
| 277 | - * @brief Parameter access operator | |
| 278 | - * | |
| 279 | - * @param[in] name Parameter name. | |
| 280 | - ***************************************************************************/ | |
| 281 | -inline | |
| 282 | -GApplicationPar& GApplication::operator[](const int& index) | |
| 283 | -{ | |
| 284 | - return (m_pars[index]); | |
| 285 | -} | |
| 286 | - | |
| 287 | - | |
| 288 | -/***********************************************************************//** | |
| 289 | - * @brief Parameter access operator (const version) | |
| 290 | - * | |
| 291 | - * @param[in] name Parameter name. | |
| 292 | - ***************************************************************************/ | |
| 293 | -inline | |
| 294 | -const GApplicationPar& GApplication::operator[](const int& index) const | |
| 295 | -{ | |
| 296 | - return (m_pars[index]); | |
| 297 | -} | |
| 298 | - | |
| 299 | 314 | #endif /* GAPPLICATION_HPP */ | ... | ... |
pyext/GApplication.i
| ... | ... | @@ -222,7 +222,8 @@ GApplication._log_value = _log_value |
| 222 | 222 | return (*self)[index]; |
| 223 | 223 | } |
| 224 | 224 | else { |
| 225 | - throw GException::out_of_range("__getitem__(int)", "Application parameter index", | |
| 225 | + throw GException::out_of_range("__getitem__(int)", "Application " | |
| 226 | + "parameter index", | |
| 226 | 227 | index, self->pars().size()); |
| 227 | 228 | } |
| 228 | 229 | } |
| ... | ... | @@ -232,7 +233,8 @@ GApplication._log_value = _log_value |
| 232 | 233 | return; |
| 233 | 234 | } |
| 234 | 235 | else { |
| 235 | - throw GException::out_of_range("__setitem__(int)", "Application parameter index", | |
| 236 | + throw GException::out_of_range("__setitem__(int)", "Application " | |
| 237 | + "parameter index", | |
| 236 | 238 | index, self->pars().size()); |
| 237 | 239 | } |
| 238 | 240 | } | ... | ... |
pyext/GModelSky.i
pyext/Makefile.am
| ... | ... | @@ -116,7 +116,9 @@ testscripts = gammalib/tests/__init__.py \ |
| 116 | 116 | # Test data to be distributed in $(pyexecdir)/gammalib/tests/data |
| 117 | 117 | testdata = $(top_srcdir)/test/data/initial_coords.txt \ |
| 118 | 118 | $(top_srcdir)/test/data/fk5_to_galactic.txt \ |
| 119 | - $(top_srcdir)/test/data/file.fits.gz | |
| 119 | + $(top_srcdir)/test/data/file.fits.gz \ | |
| 120 | + $(top_srcdir)/test/data/test_GApplication.par \ | |
| 121 | + $(top_srcdir)/test/data/model_point_plaw.xml | |
| 120 | 122 | |
| 121 | 123 | # Distribute scripts |
| 122 | 124 | testscriptsdir = $(pyexecdir)/gammalib/tests | ... | ... |
test/test_GApplication.py
| ... | ... | @@ -85,15 +85,15 @@ class Test(gammalib.GPythonTestSuite): |
| 85 | 85 | |
| 86 | 86 | # Append tests |
| 87 | 87 | self.append(self.test_log, 'Test GLog') |
| 88 | + self.append(self.test_app, 'Test GApplication') | |
| 88 | 89 | self.append(self.test_pars, 'Test GApplicationPars') |
| 89 | - self.append(self.test_par_iteration, 'Test GApplication parameter iteration') | |
| 90 | 90 | |
| 91 | 91 | # Return |
| 92 | 92 | return |
| 93 | 93 | |
| 94 | 94 | def test_log(self): |
| 95 | 95 | """ |
| 96 | - Test GLog | |
| 96 | + Test GLog class | |
| 97 | 97 | """ |
| 98 | 98 | # Allocate logger |
| 99 | 99 | log = gammalib.GLog(self._logfile, True) |
| ... | ... | @@ -192,47 +192,51 @@ class Test(gammalib.GPythonTestSuite): |
| 192 | 192 | # Return |
| 193 | 193 | return |
| 194 | 194 | |
| 195 | - def test_pars(self): | |
| 195 | + def test_app(self): | |
| 196 | 196 | """ |
| 197 | - Test GApplicationPars | |
| 197 | + Test GApplication class | |
| 198 | 198 | """ |
| 199 | - # Test GApplicationPars constructor with bad filename. | |
| 200 | - self.test_try('Test GApplicationPars constructor with bad filename') | |
| 201 | - try: | |
| 202 | - pars = gammalib.GApplicationPars('testme.par') | |
| 203 | - self.test_try_failure('Exception not thrown') | |
| 204 | - except: | |
| 205 | - self.test_try_success() | |
| 206 | - else: | |
| 207 | - self.test_try_failure('This should never happen') | |
| 208 | - | |
| 209 | - def test_par_iteration(self): | |
| 210 | - | |
| 211 | - | |
| 212 | - # Set PFILES environment temporary | |
| 199 | + # Set PFILES environment variable | |
| 213 | 200 | os.environ['PFILES'] = os.environ['PWD']+'/data' |
| 214 | 201 | |
| 215 | - # Test GApplicationPars from par file | |
| 216 | - app = gammalib.GApplication('test_GApplication','1.1.0') | |
| 202 | + # Allocate test application | |
| 203 | + app = gammalib.GApplication('test_GApplication', '1.1.0') | |
| 217 | 204 | |
| 218 | - # Test for proper reading of par file | |
| 219 | - self.test_assert(app._version() == '1.1.0', 'Test for proper application version') | |
| 220 | - self.test_assert(app.pars().size() == 5, 'Test number of parameters') | |
| 205 | + # Check proper allocation of test application | |
| 206 | + self.test_value(app._name(), 'test_GApplication', 'Check application name') | |
| 207 | + self.test_value(app._version(), '1.1.0', 'Check application version') | |
| 208 | + self.test_value(app.pars().size(), 5, 'Check number of parameters') | |
| 221 | 209 | |
| 222 | - # Loop over parameters | |
| 210 | + # Check that we properly can loop over all parameters. The npars | |
| 211 | + # variable counts the number of iterations. If the parameter "chatter" | |
| 212 | + # is encounter then set the chattiness to 4 | |
| 223 | 213 | npars = 0 |
| 224 | 214 | for par in app: |
| 225 | - | |
| 226 | - # Increment counter | |
| 227 | 215 | npars += 1 |
| 228 | - | |
| 229 | - # Set chatter parameter to test persistence | |
| 230 | 216 | if par.name() == 'chatter': |
| 231 | 217 | par.integer(4) |
| 232 | 218 | |
| 233 | - # Test outcome of iteration | |
| 234 | - self.test_assert(npars == 5, 'Test number of parameters in iterative loop') | |
| 235 | - self.test_assert(app['chatter'].integer() == 4, 'Test if parameter could be stored correctly') | |
| 236 | - | |
| 219 | + # Check outcome of loop | |
| 220 | + self.test_value(npars, 5, 'Check number of parameters in loop') | |
| 221 | + self.test_value(app['chatter'].integer(), 4, 'Check that "chatter" ' | |
| 222 | + 'parameter could be stored correctly') | |
| 223 | + | |
| 224 | + # Return | |
| 225 | + return | |
| 226 | + | |
| 227 | + def test_pars(self): | |
| 228 | + """ | |
| 229 | + Test GApplicationPars class | |
| 230 | + """ | |
| 231 | + # Test GApplicationPars constructor with bad filename | |
| 232 | + self.test_try('Test GApplicationPars constructor with bad filename') | |
| 233 | + try: | |
| 234 | + pars = gammalib.GApplicationPars('testme.par') | |
| 235 | + self.test_try_failure('Exception not thrown') | |
| 236 | + except: | |
| 237 | + self.test_try_success() | |
| 238 | + else: | |
| 239 | + self.test_try_failure('This should never happen') | |
| 240 | + | |
| 237 | 241 | # Return |
| 238 | 242 | return | ... | ... |
test/test_GModel.py
| 1 | 1 | # ========================================================================== |
| 2 | -# This module performs unit tests for the GammaLib model module. | |
| 2 | +# This module performs unit tests for the GammaLib model module | |
| 3 | 3 | # |
| 4 | -# Copyright (C) 2012-2015 Juergen Knoedlseder | |
| 4 | +# Copyright (C) 2012-2016 Juergen Knoedlseder | |
| 5 | 5 | # |
| 6 | 6 | # This program is free software: you can redistribute it and/or modify |
| 7 | 7 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -25,12 +25,12 @@ import gammalib |
| 25 | 25 | # ==================================== # |
| 26 | 26 | class Test(gammalib.GPythonTestSuite): |
| 27 | 27 | """ |
| 28 | - Test class for GammaLib model module. | |
| 28 | + Test class for GammaLib model module | |
| 29 | 29 | """ |
| 30 | 30 | # Constructor |
| 31 | 31 | def __init__(self): |
| 32 | 32 | """ |
| 33 | - Constructor. | |
| 33 | + Constructor | |
| 34 | 34 | """ |
| 35 | 35 | # Call base class constructor |
| 36 | 36 | gammalib.GPythonTestSuite.__init__(self) |
| ... | ... | @@ -41,42 +41,46 @@ class Test(gammalib.GPythonTestSuite): |
| 41 | 41 | # Set test functions |
| 42 | 42 | def set(self): |
| 43 | 43 | """ |
| 44 | - Set all test functions. | |
| 44 | + Set all test functions | |
| 45 | 45 | """ |
| 46 | 46 | # Set test name |
| 47 | - self.name("model") | |
| 47 | + self.name('model') | |
| 48 | 48 | |
| 49 | 49 | # Append tests |
| 50 | - self.append(self.test_iterator, "Test Model iterator") | |
| 50 | + self.append(self.test_models, 'Test GModels') | |
| 51 | 51 | |
| 52 | 52 | # Return |
| 53 | 53 | return |
| 54 | 54 | |
| 55 | 55 | # Test function |
| 56 | - def test_iterator(self): | |
| 56 | + def test_models(self): | |
| 57 | 57 | """ |
| 58 | - Test function. | |
| 58 | + Test GModels class | |
| 59 | 59 | """ |
| 60 | - | |
| 61 | - # Initialise model container | |
| 60 | + # Read model container and create a copy of its first model (the | |
| 61 | + # copy is needed since the model container will go out of scope | |
| 62 | + # later) | |
| 63 | + models = gammalib.GModels('data/model_point_plaw.xml') | |
| 64 | + model = models[0].copy() | |
| 65 | + name = model.name() | |
| 66 | + | |
| 67 | + # Create an empty model container | |
| 62 | 68 | models = gammalib.GModels() |
| 63 | - | |
| 64 | - # Read model container | |
| 65 | - models_test = gammalib.GModels('data/model_point_plaw.xml') | |
| 66 | - model = models_test[0] | |
| 67 | - name = model.name() | |
| 68 | - | |
| 69 | + | |
| 70 | + # Append 10 identical models to model container | |
| 69 | 71 | for i in range(10): |
| 70 | 72 | model.name(name+'_'+str(i)) |
| 71 | 73 | models.append(model) |
| 72 | 74 | |
| 73 | - size = models.size() | |
| 75 | + # Loop over all models using the container iterator and count the | |
| 76 | + # number of iterations | |
| 74 | 77 | nmodels = 0 |
| 75 | 78 | for model in models: |
| 76 | 79 | nmodels += 1 |
| 77 | - | |
| 78 | - self.test_assert(size == 10, 'Test model container size') | |
| 79 | - self.test_assert(nmodels == 10, 'Test model iterator') | |
| 80 | + | |
| 81 | + # Check that looping was successful | |
| 82 | + self.test_value(models.size(), 10, 'Check model container size') | |
| 83 | + self.test_value(nmodels, 10, 'Check model iterator') | |
| 80 | 84 | |
| 81 | 85 | # Return |
| 82 | 86 | return | ... | ... |