Commit 27f0166ed46629efefb5a0cbac06323b6194426c

Authored by Jürgen Knödlseder
1 parent 77a829e9

Fix log file header repetition in some cscripts (#3066)

ChangeLog
1 -2019-11-14 1 +2019-11-15
2 2
3 * Version 1.7.0 released 3 * Version 1.7.0 released
4 ======================== 4 ========================
5 5
  6 + Fix log file header repetition in some cscripts (#3066)
6 Add Moon constraints to csviscube (#3065) 7 Add Moon constraints to csviscube (#3065)
7 Remove response cache before source testing in cttsmap (#2973) 8 Remove response cache before source testing in cttsmap (#2973)
8 Enabling running of example scripts from objects in memory (#2925) 9 Enabling running of example scripts from objects in memory (#2925)
1 New Features and Important Changes in ctools 1.7.0 1 New Features and Important Changes in ctools 1.7.0
2 2
3 -14 November 2019 3 +15 November 2019
4 4
5 5
6 Introduction 6 Introduction
@@ -31,7 +31,12 @@ None @@ -31,7 +31,12 @@ None
31 31
32 Base classes 32 Base classes
33 ------------ 33 ------------
34 -None 34 +The headers in the log files created by cscripts that were derived from the
  35 +ctools.cscript base class were repeated. This repetition was not present in
  36 +the other base classes due to a reopening of the log file in those classes.
  37 +The logic was changed so that the cscripts now behave like the ctools. A log
  38 +file is not written by default in Python, the logFileOpen() method needs to
  39 +be called for that. And the header is only written once in the log file (#3066).
35 40
36 41
37 ctbin - CTA event binning 42 ctbin - CTA event binning
doc/source/admin/release_history/1.7.rst
@@ -17,6 +17,8 @@ In particular, this release provides: @@ -17,6 +17,8 @@ In particular, this release provides:
17 Bug fixes 17 Bug fixes
18 --------- 18 ---------
19 19
  20 +* [`3066 <https://cta-redmine.irap.omp.eu/issues/3066>`_] -
  21 + Fix log file header repetition in some cscripts
20 22
21 23
22 Improvements 24 Improvements
pyext/ctlikelihood.i
1 /*************************************************************************** 1 /***************************************************************************
2 * ctlikelihood - Base class for likelihood tools * 2 * ctlikelihood - Base class for likelihood tools *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2016-2018 by Juergen Knoedlseder * 4 + * copyright (C) 2016-2019 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -187,13 +187,11 @@ def _init_cslikelihood(self, name, version, argv): @@ -187,13 +187,11 @@ def _init_cslikelihood(self, name, version, argv):
187 else: 187 else:
188 cslikelihood.__init__(self, name, version) 188 cslikelihood.__init__(self, name, version)
189 # Set logger properties 189 # Set logger properties
190 - self._log_header()  
191 self._log.date(True) 190 self._log.date(True)
192 cslikelihood._init_cslikelihood = _init_cslikelihood 191 cslikelihood._init_cslikelihood = _init_cslikelihood
193 192
194 # Execute the script 193 # Execute the script
195 def _execute(self): 194 def _execute(self):
196 - self.logFileOpen()  
197 self._read_ahead(True) 195 self._read_ahead(True)
198 self.run() 196 self.run()
199 self.save() 197 self.save()
pyext/ctobservation.i
@@ -202,7 +202,6 @@ def _init_csobservation(self, name, version, argv): @@ -202,7 +202,6 @@ def _init_csobservation(self, name, version, argv):
202 else: 202 else:
203 csobservation.__init__(self, name, version) 203 csobservation.__init__(self, name, version)
204 # Set logger properties 204 # Set logger properties
205 - self._log_header()  
206 self._log.date(True) 205 self._log.date(True)
207 csobservation._init_csobservation = _init_csobservation 206 csobservation._init_csobservation = _init_csobservation
208 207
@@ -217,7 +216,6 @@ cscript._unbinned_observations = _unbinned_observations @@ -217,7 +216,6 @@ cscript._unbinned_observations = _unbinned_observations
217 216
218 # Execute the script 217 # Execute the script
219 def _execute(self): 218 def _execute(self):
220 - self.logFileOpen()  
221 self._read_ahead(True) 219 self._read_ahead(True)
222 self.run() 220 self.run()
223 self.save() 221 self.save()
pyext/ctool.i
@@ -198,7 +198,7 @@ public: @@ -198,7 +198,7 @@ public:
198 * handling. 198 * handling.
199 ***************************************************************************/ 199 ***************************************************************************/
200 class cscript : public ctool { 200 class cscript : public ctool {
201 -public: 201 +public:
202 // Constructors and destructors 202 // Constructors and destructors
203 cscript(const std::string& name, 203 cscript(const std::string& name,
204 const std::string& version); 204 const std::string& version);
@@ -276,23 +276,21 @@ def _set_input_obs(self, argv): @@ -276,23 +276,21 @@ def _set_input_obs(self, argv):
276 if len(argv) > 0 and isinstance(argv[0],gammalib.GObservations): 276 if len(argv) > 0 and isinstance(argv[0],gammalib.GObservations):
277 obs = argv[0] 277 obs = argv[0]
278 argv = argv[1:] 278 argv = argv[1:]
279 - else: 279 + else:
280 obs = gammalib.GObservations() 280 obs = gammalib.GObservations()
281 return (obs, argv) 281 return (obs, argv)
282 cscript._set_input_obs = _set_input_obs 282 cscript._set_input_obs = _set_input_obs
283 283
284 # Initialise application by calling the appropriate class constructor 284 # Initialise application by calling the appropriate class constructor
285 def _init_cscript(self, name, version, argv): 285 def _init_cscript(self, name, version, argv):
286 - if len(argv) == 0:  
287 - cscript.__init__(self, name, version)  
288 - elif len(argv) == 1:  
289 - cscript.__init__(self, name, version, *argv)  
290 - elif len(argv) == 3:  
291 - cscript.__init__(self, name, version, argv[2]) 286 + if len(argv) > 0:
  287 + if len(argv) == 3 and argv[0] == name and argv[1] == version:
  288 + cscript.__init__(self, name, version, argv[2])
  289 + else:
  290 + cscript.__init__(self, name, version, *argv)
292 else: 291 else:
293 - raise TypeError('Invalid number of arguments given.') 292 + cscript.__init__(self, name, version)
294 # Set logger properties 293 # Set logger properties
295 - self._log_header()  
296 self._log.date(True) 294 self._log.date(True)
297 cscript._init_cscript = _init_cscript 295 cscript._init_cscript = _init_cscript
298 296