From 4ce9359c4749e8d7d370b5b8fbc01c665fca53ad Mon Sep 17 00:00:00 2001
From: Simon Heybrock <simon.heybrock@esss.se>
Date: Mon, 30 May 2016 10:56:11 +0200
Subject: [PATCH] Re #16454. Deprecated getEventList for Python interface.

---
 .../mantid/api/src/Exports/IEventWorkspace.cpp   | 16 ++++++++++++++--
 .../python/mantid/api/IEventWorkspaceTest.py     |  5 +++++
 docs/source/algorithms/ChangeTimeZero-v1.rst     |  8 ++++----
 .../algorithms/CorelliCrossCorrelate-v1.rst      |  6 +++---
 docs/source/algorithms/MDNormSCD-v1.rst          |  2 +-
 docs/source/algorithms/SortEvents-v1.rst         |  4 ++--
 docs/source/concepts/EventWorkspace.rst          |  4 ++--
 7 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/Framework/PythonInterface/mantid/api/src/Exports/IEventWorkspace.cpp b/Framework/PythonInterface/mantid/api/src/Exports/IEventWorkspace.cpp
index 36edb9bc8e9..cc0473445fe 100644
--- a/Framework/PythonInterface/mantid/api/src/Exports/IEventWorkspace.cpp
+++ b/Framework/PythonInterface/mantid/api/src/Exports/IEventWorkspace.cpp
@@ -9,6 +9,19 @@ using namespace Mantid::API;
 using Mantid::PythonInterface::Registry::RegisterWorkspacePtrToPython;
 using namespace boost::python;
 
+namespace {
+/**
+ * Returns a reference to EventList and raises a deprecation warning
+ * @param self A reference to calling object
+ * @param index Workspace index
+ */
+IEventList &deprecatedGetEventList(IEventWorkspace &self, const size_t index) {
+  PyErr_Warn(PyExc_DeprecationWarning,
+             "'getEventList' is deprecated, use 'getSpectrum' instead.");
+  return self.getSpectrum(index);
+}
+}
+
 /**
  * Python exports of the Mantid::API::IEventWorkspace class.
  */
@@ -23,8 +36,7 @@ void export_IEventWorkspace() {
       .def("getTofMax", &IEventWorkspace::getTofMax, args("self"),
            "Returns the maximum TOF value (in microseconds) held by the "
            "workspace")
-      .def("getEventList", (IEventList & (IEventWorkspace::*)(const size_t)) &
-                               IEventWorkspace::getSpectrum,
+      .def("getEventList", &deprecatedGetEventList,
            return_internal_reference<>(), args("self", "workspace_index"),
            "Return the event list managing the events at the given workspace "
            "index")
diff --git a/Framework/PythonInterface/test/python/mantid/api/IEventWorkspaceTest.py b/Framework/PythonInterface/test/python/mantid/api/IEventWorkspaceTest.py
index d5dec2ba8f1..842c6b26c08 100644
--- a/Framework/PythonInterface/test/python/mantid/api/IEventWorkspaceTest.py
+++ b/Framework/PythonInterface/test/python/mantid/api/IEventWorkspaceTest.py
@@ -60,6 +60,11 @@ class IEventWorkspaceTest(unittest.TestCase):
         self.assertAlmostEquals(weightErrorList[0], 1.0) #first value
         self.assertAlmostEquals(weightErrorList[len(weightErrorList)-1], 1.0) #last value
 
+    def test_deprecated_getEventList(self):
+        el = self._test_ws.getEventList(0)
+        self.assertTrue(isinstance(el, IEventList))
+        self.assertEquals(el.getNumberEvents(), 200)
+
 
 if __name__ == '__main__':
     unittest.main()
diff --git a/docs/source/algorithms/ChangeTimeZero-v1.rst b/docs/source/algorithms/ChangeTimeZero-v1.rst
index 2496f234725..23e6e6f02ab 100644
--- a/docs/source/algorithms/ChangeTimeZero-v1.rst
+++ b/docs/source/algorithms/ChangeTimeZero-v1.rst
@@ -42,8 +42,8 @@ Usage
    shifted_proton_charge = shifted_ws .getRun()['proton_charge']
 
    # Check some events
-   original_pulse_times = original_ws.getEventList(7).getPulseTimes()
-   shifted_pulse_times = shifted_ws.getEventList(7).getPulseTimes()
+   original_pulse_times = original_ws.getSpectrum(7).getPulseTimes()
+   shifted_pulse_times = shifted_ws.getSpectrum(7).getPulseTimes()
 
    print "Original proton_charge time: ", original_proton_charge.nthTime(0), ", ", original_proton_charge.nthTime(1), ", ..."
    print "Shifted proton_charge time: ", shifted_proton_charge.nthTime(0), ", ", shifted_proton_charge.nthTime(1),  ", ..."
@@ -83,8 +83,8 @@ Output:
    shifted_proton_charge = shifted_ws .getRun()['proton_charge']
 
    # Check some events
-   original_pulse_times = original_ws.getEventList(7).getPulseTimes()
-   shifted_pulse_times = shifted_ws.getEventList(7).getPulseTimes()
+   original_pulse_times = original_ws.getSpectrum(7).getPulseTimes()
+   shifted_pulse_times = shifted_ws.getSpectrum(7).getPulseTimes()
 
    print "Original proton_charge time: ", original_proton_charge.nthTime(0), ", ", original_proton_charge.nthTime(1), ", ..."
    print "Shifted proton_charge time: ", shifted_proton_charge.nthTime(0), ", ", shifted_proton_charge.nthTime(1),  ", ..."
diff --git a/docs/source/algorithms/CorelliCrossCorrelate-v1.rst b/docs/source/algorithms/CorelliCrossCorrelate-v1.rst
index 43735f309b7..f9b667b4825 100644
--- a/docs/source/algorithms/CorelliCrossCorrelate-v1.rst
+++ b/docs/source/algorithms/CorelliCrossCorrelate-v1.rst
@@ -34,9 +34,9 @@ Usage
     # Run the cross-correlation. This is using a TDC timing offset of 56000ns.
     wsOut = CorelliCrossCorrelate(ws,56000)
 
-    print 'The detector 172305 has ' + str(ws.getEventList(172305).getNumberEvents()) + ' events.'
-    print 'The event weights before cross-correlation are ' + str(ws.getEventList(172305).getWeights())
-    print 'The event weights after  cross-correlation are ' + str(wsOut.getEventList(172305).getWeights())
+    print 'The detector 172305 has ' + str(ws.getSpectrum(172305).getNumberEvents()) + ' events.'
+    print 'The event weights before cross-correlation are ' + str(ws.getSpectrum(172305).getWeights())
+    print 'The event weights after  cross-correlation are ' + str(wsOut.getSpectrum(172305).getWeights())
 
 Output:
 
diff --git a/docs/source/algorithms/MDNormSCD-v1.rst b/docs/source/algorithms/MDNormSCD-v1.rst
index 1e6f4afa223..925e3f505c2 100644
--- a/docs/source/algorithms/MDNormSCD-v1.rst
+++ b/docs/source/algorithms/MDNormSCD-v1.rst
@@ -45,7 +45,7 @@ Usage
     flux=CompressEvents(InputWorkspace=flux,Tolerance=1e-4)
     flux=Rebin(InputWorkspace=flux,Params='1.85,10,10')
     for i in range(flux.getNumberHistograms()):
-        el=flux.getEventList(i)
+        el=flux.getSpectrum(i)
         el.divide(flux.readY(i)[0],0)
     flux=Rebin(InputWorkspace=flux,Params='1.85,10,10')
     flux=IntegrateFlux(flux)
diff --git a/docs/source/algorithms/SortEvents-v1.rst b/docs/source/algorithms/SortEvents-v1.rst
index b64ae954274..1201168d28f 100644
--- a/docs/source/algorithms/SortEvents-v1.rst
+++ b/docs/source/algorithms/SortEvents-v1.rst
@@ -29,7 +29,7 @@ Usage
   SortEvents(InputWorkspace='TestEventWS', SortBy="X Value")
 
   ws = mtd["TestEventWS"]
-  ev1 = ws.getEventList(1)
+  ev1 = ws.getSpectrum(1)
   ptimes = ev1.getPulseTimes()
   tofs = ev1.getTofs()
   for eindex in xrange(10):
@@ -62,7 +62,7 @@ Output:
   SortEvents(InputWorkspace='TestEventWS',SortBy='Pulse Time + TOF')
 
   ws = mtd["TestEventWS"]
-  ev1 = ws.getEventList(1)
+  ev1 = ws.getSpectrum(1)
   ptimes = ev1.getPulseTimes()
   tofs = ev1.getTofs()
   for eindex in xrange(10):
diff --git a/docs/source/concepts/EventWorkspace.rst b/docs/source/concepts/EventWorkspace.rst
index 68a82b6804f..ac8cc10ddde 100644
--- a/docs/source/concepts/EventWorkspace.rst
+++ b/docs/source/concepts/EventWorkspace.rst
@@ -101,7 +101,7 @@ Event Workspaces store their data in event lists, one per spectrum.  You can acc
    evListCount = eventWS.getNumberHistograms()
 
    # Get the first event list
-   evList = eventWS.getEventList(0)
+   evList = eventWS.getSpectrum(0)
 
    # Get some basic information
    print "Number of events in event List 0:", evList.getNumberEvents()
@@ -151,7 +151,7 @@ Please note these should only be done as part of a Python Algorithm, otherwise t
    import math
    eventWS = CreateSampleWorkspace(WorkspaceType="Event")
    # Get the first event list
-   evList = eventWS.getEventList(0)
+   evList = eventWS.getSpectrum(0)
 
    # Add an offset to the pulsetime (wall-clock time) of each event in the list.
    print "First pulse time before addPulsetime:", evList.getPulseTimes()[0]
-- 
GitLab