From 27f0166ed46629efefb5a0cbac06323b6194426c Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Fri, 15 Nov 2019 11:43:00 +0100 Subject: [PATCH] Fix log file header repetition in some cscripts (#3066) --- ChangeLog | 3 ++- NEWS | 9 +++++++-- doc/source/admin/release_history/1.7.rst | 2 ++ pyext/ctlikelihood.i | 4 +--- pyext/ctobservation.i | 2 -- pyext/ctool.i | 18 ++++++++---------- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4c1c610..a4ff45f 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2019-11-14 +2019-11-15 * Version 1.7.0 released ======================== + Fix log file header repetition in some cscripts (#3066) Add Moon constraints to csviscube (#3065) Remove response cache before source testing in cttsmap (#2973) Enabling running of example scripts from objects in memory (#2925) diff --git a/NEWS b/NEWS index 511ddbc..04913d5 100755 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.7.0 -14 November 2019 +15 November 2019 Introduction @@ -31,7 +31,12 @@ None Base classes ------------ -None +The headers in the log files created by cscripts that were derived from the +ctools.cscript base class were repeated. This repetition was not present in +the other base classes due to a reopening of the log file in those classes. +The logic was changed so that the cscripts now behave like the ctools. A log +file is not written by default in Python, the logFileOpen() method needs to +be called for that. And the header is only written once in the log file (#3066). ctbin - CTA event binning diff --git a/doc/source/admin/release_history/1.7.rst b/doc/source/admin/release_history/1.7.rst index e6aa840..c71cb95 100644 --- a/doc/source/admin/release_history/1.7.rst +++ b/doc/source/admin/release_history/1.7.rst @@ -17,6 +17,8 @@ In particular, this release provides: Bug fixes --------- +* [`3066 `_] - + Fix log file header repetition in some cscripts Improvements diff --git a/pyext/ctlikelihood.i b/pyext/ctlikelihood.i index 5b7332f..761421a 100755 --- a/pyext/ctlikelihood.i +++ b/pyext/ctlikelihood.i @@ -1,7 +1,7 @@ /*************************************************************************** * ctlikelihood - Base class for likelihood tools * * ----------------------------------------------------------------------- * - * copyright (C) 2016-2018 by Juergen Knoedlseder * + * copyright (C) 2016-2019 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -187,13 +187,11 @@ def _init_cslikelihood(self, name, version, argv): else: cslikelihood.__init__(self, name, version) # Set logger properties - self._log_header() self._log.date(True) cslikelihood._init_cslikelihood = _init_cslikelihood # Execute the script def _execute(self): - self.logFileOpen() self._read_ahead(True) self.run() self.save() diff --git a/pyext/ctobservation.i b/pyext/ctobservation.i index 6fc50c2..f5415e2 100755 --- a/pyext/ctobservation.i +++ b/pyext/ctobservation.i @@ -202,7 +202,6 @@ def _init_csobservation(self, name, version, argv): else: csobservation.__init__(self, name, version) # Set logger properties - self._log_header() self._log.date(True) csobservation._init_csobservation = _init_csobservation @@ -217,7 +216,6 @@ cscript._unbinned_observations = _unbinned_observations # Execute the script def _execute(self): - self.logFileOpen() self._read_ahead(True) self.run() self.save() diff --git a/pyext/ctool.i b/pyext/ctool.i index 7961122..58dc2ce 100755 --- a/pyext/ctool.i +++ b/pyext/ctool.i @@ -198,7 +198,7 @@ public: * handling. ***************************************************************************/ class cscript : public ctool { -public: +public: // Constructors and destructors cscript(const std::string& name, const std::string& version); @@ -276,23 +276,21 @@ def _set_input_obs(self, argv): if len(argv) > 0 and isinstance(argv[0],gammalib.GObservations): obs = argv[0] argv = argv[1:] - else: + else: obs = gammalib.GObservations() return (obs, argv) cscript._set_input_obs = _set_input_obs # Initialise application by calling the appropriate class constructor def _init_cscript(self, name, version, argv): - if len(argv) == 0: - cscript.__init__(self, name, version) - elif len(argv) == 1: - cscript.__init__(self, name, version, *argv) - elif len(argv) == 3: - cscript.__init__(self, name, version, argv[2]) + if len(argv) > 0: + if len(argv) == 3 and argv[0] == name and argv[1] == version: + cscript.__init__(self, name, version, argv[2]) + else: + cscript.__init__(self, name, version, *argv) else: - raise TypeError('Invalid number of arguments given.') + cscript.__init__(self, name, version) # Set logger properties - self._log_header() self._log.date(True) cscript._init_cscript = _init_cscript -- libgit2 0.21.4