From 006d9c587cc6e94df27866533a0a10e3b6894abc Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Tue, 25 Oct 2022 13:12:13 +0200
Subject: [PATCH] Datafield: Frame base c'tors -> private

---
 Device/Data/ArrayUtils.cpp              |   1 -
 Device/Data/DataUtils.cpp               |  18 +--
 Device/Data/Datafield.h                 |  16 +--
 Device/IO/ReadWriteNicos.cpp            |   6 +-
 Sim/Simulation/DepthProbeSimulation.cpp |  10 +-
 auto/Wrap/doxygenDevice.i               |  15 ---
 auto/Wrap/libBornAgainDevice.py         |   3 -
 auto/Wrap/libBornAgainDevice_wrap.cpp   | 163 +-----------------------
 8 files changed, 28 insertions(+), 204 deletions(-)

diff --git a/Device/Data/ArrayUtils.cpp b/Device/Data/ArrayUtils.cpp
index 5f3a9668ffb..46b74e1b97d 100644
--- a/Device/Data/ArrayUtils.cpp
+++ b/Device/Data/ArrayUtils.cpp
@@ -14,7 +14,6 @@
 
 #include "Device/Data/ArrayUtils.h"
 #include "Base/Axis/FixedBinAxis.h"
-#include "Base/Axis/Frame.h"
 #include "Device/Data/Datafield.h"
 #include <stdexcept>
 
diff --git a/Device/Data/DataUtils.cpp b/Device/Data/DataUtils.cpp
index d288df5115f..7c91bd062a4 100644
--- a/Device/Data/DataUtils.cpp
+++ b/Device/Data/DataUtils.cpp
@@ -111,19 +111,15 @@ DataUtils::Data::vecvecToDatafield(const std::vector<std::vector<double>>& array
     size_t nrows = array_2d.size();
     size_t ncols = array_2d[0].size();
 
-    auto frame = new Frame({new FixedBinAxis("x", nrows, 0.0, double(nrows)),
-                            new FixedBinAxis("y", ncols, 0.0, double(ncols))});
-    std::vector<double> out(frame->size());
-    std::vector<unsigned> axes_indices(2);
+    std::vector<IAxis*> axes{new FixedBinAxis("x", nrows, 0.0, double(nrows)),
+                             new FixedBinAxis("y", ncols, 0.0, double(ncols))};
+    std::vector<double> out;
+    out.reserve(nrows * ncols);
     for (unsigned row = 0; row < nrows; row++) {
-        for (unsigned col = 0; col < ncols; col++) {
-            axes_indices[0] = row;
-            axes_indices[1] = col;
-            size_t iout = frame->toGlobalIndex(axes_indices);
-            out[iout] = array_2d[row][col];
-        }
+        for (unsigned col = 0; col < ncols; col++)
+            out.push_back(array_2d[row][col]);
     }
-    return std::make_unique<Datafield>(frame, out);
+    return std::make_unique<Datafield>(axes, out);
 }
 
 std::unique_ptr<Datafield> DataUtils::Data::createFFT(const Datafield& data)
diff --git a/Device/Data/Datafield.h b/Device/Data/Datafield.h
index c7d9c7ae150..2a1c277be70 100644
--- a/Device/Data/Datafield.h
+++ b/Device/Data/Datafield.h
@@ -29,14 +29,6 @@ class Frame;
 
 class Datafield {
 public:
-    //! Constructor that takes ownership of supplied frame.
-    Datafield(const Frame* frame);
-    //! Constructor that takes ownership of supplied frame and initializes values.
-    Datafield(const Frame* frame, const std::vector<double>& values);
-    //! Constructor that takes ownership of supplied frame and initializes values and errorbars
-    Datafield(const Frame* frame, const std::vector<double>& values,
-              const std::vector<double>& errSigmas);
-
     //! Constructor that takes ownership of supplied axes.
     Datafield(const std::vector<IAxis*>& axes);
     //! Constructor that takes ownership of supplied axes and initializes values.
@@ -138,6 +130,14 @@ public:
     Datafield* yProjection(double xlow, double xup) const;
 
 private:
+    //! Constructor that takes ownership of supplied frame.
+    Datafield(const Frame* frame);
+    //! Constructor that takes ownership of supplied frame and initializes values.
+    Datafield(const Frame* frame, const std::vector<double>& values);
+    //! Constructor that takes ownership of supplied frame and initializes values and errorbars
+    Datafield(const Frame* frame, const std::vector<double>& values,
+              const std::vector<double>& errSigmas);
+
     //! Creates projection along X. The projections is made by collecting the data in the range
     //! between [ybinlow, ybinup].
     Datafield* create_xProjection(int ybinlow, int ybinup) const;
diff --git a/Device/IO/ReadWriteNicos.cpp b/Device/IO/ReadWriteNicos.cpp
index 3be6b57da44..6337621a4f2 100644
--- a/Device/IO/ReadWriteNicos.cpp
+++ b/Device/IO/ReadWriteNicos.cpp
@@ -101,9 +101,9 @@ Datafield* IO::readNicosData(std::istream& input_stream)
     if (height == 0)
         throw std::runtime_error("Could not find 'DataSizeY' value");
 
-    auto frame = new Frame(
-        {new FixedBinAxis("x", width, 0.0, width), new FixedBinAxis("y", height, 0.0, height)});
-    auto result = std::make_unique<Datafield>(frame);
+    std::vector<IAxis*> axes{new FixedBinAxis("x", width, 0.0, width),
+                             new FixedBinAxis("y", height, 0.0, height)};
+    auto result = std::make_unique<Datafield>(axes);
 
     // -- read data
     bool inCountSection = false;
diff --git a/Sim/Simulation/DepthProbeSimulation.cpp b/Sim/Simulation/DepthProbeSimulation.cpp
index f53c9b05948..1405e65490a 100644
--- a/Sim/Simulation/DepthProbeSimulation.cpp
+++ b/Sim/Simulation/DepthProbeSimulation.cpp
@@ -82,13 +82,13 @@ SimulationResult DepthProbeSimulation::pack_result() const
 {
     validityCheck();
 
-    auto frame = new Frame({alphaAxis()->clone(), zAxis()->clone()});
-    std::vector<double> out(frame->size());
-    size_t iout = 0;
+    const std::vector<IAxis*> axes{alphaAxis()->clone(), zAxis()->clone()};
+    std::vector<double> out;
+    out.reserve(axes[0]->size() * axes[1]->size());
     for (size_t i = 0, size = m_depth_eles.size(); i < size; ++i)
         for (const double v : m_depth_eles[i].getIntensities())
-            out[iout++] = v;
-    auto data = std::make_unique<Datafield>(frame, out);
+            out.push_back(v);
+    auto data = std::make_unique<Datafield>(axes, out);
 
     std::unique_ptr<const ICoordSystem> coordsSystem(createCoordSystem());
     return {*data, *coordsSystem};
diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i
index 4cd0d7a469d..e19ada495b2 100644
--- a/auto/Wrap/doxygenDevice.i
+++ b/auto/Wrap/doxygenDevice.i
@@ -86,21 +86,6 @@ Stores radiation power per bin.
 C++ includes: Datafield.h
 ";
 
-%feature("docstring")  Datafield::Datafield "Datafield::Datafield(const Frame *frame)
-Datafield::Datafield
-Constructor that takes ownership of supplied frame. 
-";
-
-%feature("docstring")  Datafield::Datafield "Datafield::Datafield(const Frame *frame, const std::vector< double > &values)
-Datafield::Datafield
-Constructor that takes ownership of supplied frame and initializes values. 
-";
-
-%feature("docstring")  Datafield::Datafield "Datafield::Datafield(const Frame *frame, const std::vector< double > &values, const std::vector< double > &errSigmas)
-Datafield::Datafield
-Constructor that takes ownership of supplied frame and initializes values and errorbars. 
-";
-
 %feature("docstring")  Datafield::Datafield "Datafield::Datafield(const std::vector< IAxis * > &axes)
 Datafield::Datafield
 Constructor that takes ownership of supplied axes. 
diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py
index c5f995c0286..825d7290899 100644
--- a/auto/Wrap/libBornAgainDevice.py
+++ b/auto/Wrap/libBornAgainDevice.py
@@ -2057,9 +2057,6 @@ class Datafield(object):
 
     def __init__(self, *args):
         r"""
-        __init__(Datafield self, Frame frame) -> Datafield
-        __init__(Datafield self, Frame frame, vdouble1d_t values) -> Datafield
-        __init__(Datafield self, Frame frame, vdouble1d_t values, vdouble1d_t errSigmas) -> Datafield
         __init__(Datafield self, std::vector< IAxis *,std::allocator< IAxis * > > const & axes) -> Datafield
         __init__(Datafield self, std::vector< IAxis *,std::allocator< IAxis * > > const & axes, vdouble1d_t values) -> Datafield
         __init__(Datafield self, std::vector< IAxis *,std::allocator< IAxis * > > const & axes, vdouble1d_t values, vdouble1d_t errSigmas) -> Datafield
diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp
index d12e6060be5..c3dd4621ea5 100644
--- a/auto/Wrap/libBornAgainDevice_wrap.cpp
+++ b/auto/Wrap/libBornAgainDevice_wrap.cpp
@@ -26979,114 +26979,6 @@ SWIGINTERN PyObject *vector_R3_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject
 }
 
 SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
-  PyObject *resultobj = 0;
-  Frame *arg1 = (Frame *) 0 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  Datafield *result = 0 ;
-  
-  if ((nobjs < 1) || (nobjs > 1)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Frame, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Datafield" "', argument " "1"" of type '" "Frame const *""'"); 
-  }
-  arg1 = reinterpret_cast< Frame * >(argp1);
-  result = (Datafield *)new Datafield((Frame const *)arg1);
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Datafield, SWIG_POINTER_NEW |  0 );
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
-SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
-  PyObject *resultobj = 0;
-  Frame *arg1 = (Frame *) 0 ;
-  std::vector< double,std::allocator< double > > *arg2 = 0 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  int res2 = SWIG_OLDOBJ ;
-  Datafield *result = 0 ;
-  
-  if ((nobjs < 2) || (nobjs > 2)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Frame, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Datafield" "', argument " "1"" of type '" "Frame const *""'"); 
-  }
-  arg1 = reinterpret_cast< Frame * >(argp1);
-  {
-    std::vector< double,std::allocator< double > > *ptr = (std::vector< double,std::allocator< double > > *)0;
-    res2 = swig::asptr(swig_obj[1], &ptr);
-    if (!SWIG_IsOK(res2)) {
-      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_Datafield" "', argument " "2"" of type '" "std::vector< double,std::allocator< double > > const &""'"); 
-    }
-    if (!ptr) {
-      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_Datafield" "', argument " "2"" of type '" "std::vector< double,std::allocator< double > > const &""'"); 
-    }
-    arg2 = ptr;
-  }
-  result = (Datafield *)new Datafield((Frame const *)arg1,(std::vector< double,std::allocator< double > > const &)*arg2);
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Datafield, SWIG_POINTER_NEW |  0 );
-  if (SWIG_IsNewObj(res2)) delete arg2;
-  return resultobj;
-fail:
-  if (SWIG_IsNewObj(res2)) delete arg2;
-  return NULL;
-}
-
-
-SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_2(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
-  PyObject *resultobj = 0;
-  Frame *arg1 = (Frame *) 0 ;
-  std::vector< double,std::allocator< double > > *arg2 = 0 ;
-  std::vector< double,std::allocator< double > > *arg3 = 0 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  int res2 = SWIG_OLDOBJ ;
-  int res3 = SWIG_OLDOBJ ;
-  Datafield *result = 0 ;
-  
-  if ((nobjs < 3) || (nobjs > 3)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_Frame, 0 |  0 );
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "new_Datafield" "', argument " "1"" of type '" "Frame const *""'"); 
-  }
-  arg1 = reinterpret_cast< Frame * >(argp1);
-  {
-    std::vector< double,std::allocator< double > > *ptr = (std::vector< double,std::allocator< double > > *)0;
-    res2 = swig::asptr(swig_obj[1], &ptr);
-    if (!SWIG_IsOK(res2)) {
-      SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "new_Datafield" "', argument " "2"" of type '" "std::vector< double,std::allocator< double > > const &""'"); 
-    }
-    if (!ptr) {
-      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_Datafield" "', argument " "2"" of type '" "std::vector< double,std::allocator< double > > const &""'"); 
-    }
-    arg2 = ptr;
-  }
-  {
-    std::vector< double,std::allocator< double > > *ptr = (std::vector< double,std::allocator< double > > *)0;
-    res3 = swig::asptr(swig_obj[2], &ptr);
-    if (!SWIG_IsOK(res3)) {
-      SWIG_exception_fail(SWIG_ArgError(res3), "in method '" "new_Datafield" "', argument " "3"" of type '" "std::vector< double,std::allocator< double > > const &""'"); 
-    }
-    if (!ptr) {
-      SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "new_Datafield" "', argument " "3"" of type '" "std::vector< double,std::allocator< double > > const &""'"); 
-    }
-    arg3 = ptr;
-  }
-  result = (Datafield *)new Datafield((Frame const *)arg1,(std::vector< double,std::allocator< double > > const &)*arg2,(std::vector< double,std::allocator< double > > const &)*arg3);
-  resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Datafield, SWIG_POINTER_NEW |  0 );
-  if (SWIG_IsNewObj(res2)) delete arg2;
-  if (SWIG_IsNewObj(res3)) delete arg3;
-  return resultobj;
-fail:
-  if (SWIG_IsNewObj(res2)) delete arg2;
-  if (SWIG_IsNewObj(res3)) delete arg3;
-  return NULL;
-}
-
-
-SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_3(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   std::vector< IAxis *,std::allocator< IAxis * > > *arg1 = 0 ;
   void *argp1 = 0 ;
@@ -27110,7 +27002,7 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_4(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
+SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   std::vector< IAxis *,std::allocator< IAxis * > > *arg1 = 0 ;
   std::vector< double,std::allocator< double > > *arg2 = 0 ;
@@ -27149,7 +27041,7 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_5(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
+SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_2(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   std::vector< IAxis *,std::allocator< IAxis * > > *arg1 = 0 ;
   std::vector< double,std::allocator< double > > *arg2 = 0 ;
@@ -27203,7 +27095,7 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_6(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
+SWIGINTERN PyObject *_wrap_new_Datafield__SWIG_3(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   Datafield *arg1 = 0 ;
   void *argp1 = 0 ;
@@ -27235,21 +27127,12 @@ SWIGINTERN PyObject *_wrap_new_Datafield(PyObject *self, PyObject *args) {
   
   if (!(argc = SWIG_Python_UnpackTuple(args, "new_Datafield", 0, 3, argv))) SWIG_fail;
   --argc;
-  if (argc == 1) {
-    int _v;
-    void *vptr = 0;
-    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_Frame, 0);
-    _v = SWIG_CheckState(res);
-    if (_v) {
-      return _wrap_new_Datafield__SWIG_0(self, argc, argv);
-    }
-  }
   if (argc == 1) {
     int _v;
     int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__vectorT_IAxis_p_std__allocatorT_IAxis_p_t_t, SWIG_POINTER_NO_NULL | 0);
     _v = SWIG_CheckState(res);
     if (_v) {
-      return _wrap_new_Datafield__SWIG_3(self, argc, argv);
+      return _wrap_new_Datafield__SWIG_0(self, argc, argv);
     }
   }
   if (argc == 1) {
@@ -27258,26 +27141,13 @@ SWIGINTERN PyObject *_wrap_new_Datafield(PyObject *self, PyObject *args) {
     int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_Datafield, SWIG_POINTER_NO_NULL);
     _v = SWIG_CheckState(res);
     if (_v) {
-      return _wrap_new_Datafield__SWIG_6(self, argc, argv);
+      return _wrap_new_Datafield__SWIG_3(self, argc, argv);
     }
   }
   if (argc == 2) {
     int _v;
     int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__vectorT_IAxis_p_std__allocatorT_IAxis_p_t_t, SWIG_POINTER_NO_NULL | 0);
     _v = SWIG_CheckState(res);
-    if (_v) {
-      int res = swig::asptr(argv[1], (std::vector< double,std::allocator< double > >**)(0));
-      _v = SWIG_CheckState(res);
-      if (_v) {
-        return _wrap_new_Datafield__SWIG_4(self, argc, argv);
-      }
-    }
-  }
-  if (argc == 2) {
-    int _v;
-    void *vptr = 0;
-    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_Frame, 0);
-    _v = SWIG_CheckState(res);
     if (_v) {
       int res = swig::asptr(argv[1], (std::vector< double,std::allocator< double > >**)(0));
       _v = SWIG_CheckState(res);
@@ -27290,23 +27160,6 @@ SWIGINTERN PyObject *_wrap_new_Datafield(PyObject *self, PyObject *args) {
     int _v;
     int res = SWIG_ConvertPtr(argv[0], 0, SWIGTYPE_p_std__vectorT_IAxis_p_std__allocatorT_IAxis_p_t_t, SWIG_POINTER_NO_NULL | 0);
     _v = SWIG_CheckState(res);
-    if (_v) {
-      int res = swig::asptr(argv[1], (std::vector< double,std::allocator< double > >**)(0));
-      _v = SWIG_CheckState(res);
-      if (_v) {
-        int res = swig::asptr(argv[2], (std::vector< double,std::allocator< double > >**)(0));
-        _v = SWIG_CheckState(res);
-        if (_v) {
-          return _wrap_new_Datafield__SWIG_5(self, argc, argv);
-        }
-      }
-    }
-  }
-  if (argc == 3) {
-    int _v;
-    void *vptr = 0;
-    int res = SWIG_ConvertPtr(argv[0], &vptr, SWIGTYPE_p_Frame, 0);
-    _v = SWIG_CheckState(res);
     if (_v) {
       int res = swig::asptr(argv[1], (std::vector< double,std::allocator< double > >**)(0));
       _v = SWIG_CheckState(res);
@@ -27323,9 +27176,6 @@ SWIGINTERN PyObject *_wrap_new_Datafield(PyObject *self, PyObject *args) {
 fail:
   SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_Datafield'.\n"
     "  Possible C/C++ prototypes are:\n"
-    "    Datafield::Datafield(Frame const *)\n"
-    "    Datafield::Datafield(Frame const *,std::vector< double,std::allocator< double > > const &)\n"
-    "    Datafield::Datafield(Frame const *,std::vector< double,std::allocator< double > > const &,std::vector< double,std::allocator< double > > const &)\n"
     "    Datafield::Datafield(std::vector< IAxis *,std::allocator< IAxis * > > const &)\n"
     "    Datafield::Datafield(std::vector< IAxis *,std::allocator< IAxis * > > const &,std::vector< double,std::allocator< double > > const &)\n"
     "    Datafield::Datafield(std::vector< IAxis *,std::allocator< IAxis * > > const &,std::vector< double,std::allocator< double > > const &,std::vector< double,std::allocator< double > > const &)\n"
@@ -38080,9 +37930,6 @@ static PyMethodDef SwigMethods[] = {
 	 { "vector_R3_swigregister", vector_R3_swigregister, METH_O, NULL},
 	 { "vector_R3_swiginit", vector_R3_swiginit, METH_VARARGS, NULL},
 	 { "new_Datafield", _wrap_new_Datafield, METH_VARARGS, "\n"
-		"Datafield(Frame frame)\n"
-		"Datafield(Frame frame, vdouble1d_t values)\n"
-		"Datafield(Frame frame, vdouble1d_t values, vdouble1d_t errSigmas)\n"
 		"Datafield(std::vector< IAxis *,std::allocator< IAxis * > > const & axes)\n"
 		"Datafield(std::vector< IAxis *,std::allocator< IAxis * > > const & axes, vdouble1d_t values)\n"
 		"Datafield(std::vector< IAxis *,std::allocator< IAxis * > > const & axes, vdouble1d_t values, vdouble1d_t errSigmas)\n"
-- 
GitLab