From 6a111968c5bbea34c9f1cb3d5267473eea64d2dd Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (h)" <j.wuttke@fz-juelich.de>
Date: Sun, 16 Jan 2022 17:25:43 +0100
Subject: [PATCH] mv fct from DataUtil to HistoUtil

---
 Device/Data/DataUtils.cpp                     |  25 -----
 Device/Data/DataUtils.h                       |   4 -
 Device/Histo/HistoUtils.cpp                   |  26 ++++-
 Device/Histo/HistoUtils.h                     |   4 +
 .../Core/Consistence/CompareTwoReferences.cpp |   4 +-
 Tests/Functional/Core/Std/Check.cpp           |   4 +-
 Tests/Functional/GUI/Check.cpp                |   4 +-
 Tests/Functional/PyStd/Check.cpp              |   4 +-
 auto/Wrap/doxygenDevice.i                     |  10 +-
 auto/Wrap/libBornAgainDevice.py               |  20 ++--
 auto/Wrap/libBornAgainDevice_wrap.cpp         | 102 +++++++++---------
 11 files changed, 103 insertions(+), 104 deletions(-)

diff --git a/Device/Data/DataUtils.cpp b/Device/Data/DataUtils.cpp
index 05d9c23afbe..7002d4001ff 100644
--- a/Device/Data/DataUtils.cpp
+++ b/Device/Data/DataUtils.cpp
@@ -16,7 +16,6 @@
 #include "Base/Math/FourierTransform.h"
 #include "Base/Math/Numeric.h"
 #include "Device/Data/ArrayUtils.h"
-#include "Device/Histo/IHistogram.h"
 #include <iostream>
 
 namespace {
@@ -48,30 +47,6 @@ double DataUtils::Data::relativeDataDifference(const OutputData<double>& dat,
     return diff;
 }
 
-//! Returns true is relative difference is below threshold; prints informative output
-bool DataUtils::Data::checkRelativeDifference(const OutputData<double>& dat,
-                                              const OutputData<double>& ref, const double threshold)
-{
-    const std::unique_ptr<const IHistogram> histo(IHistogram::createHistogram(dat));
-    if (histo->getMinimum() == 0 && histo->getMaximum() == 0) {
-        std::cerr << "FAILED: simulated data set is empty" << std::endl;
-        return false;
-    }
-
-    const double diff = relativeDataDifference(dat, ref);
-    if (diff > threshold) {
-        std::cerr << "FAILED: relative deviation of dat from ref is " << diff
-                  << ", above given threshold " << threshold << std::endl;
-        return false;
-    }
-    if (diff)
-        std::cerr << "- OK: relative deviation of dat from ref is " << diff
-                  << ", within given threshold " << threshold << std::endl;
-    else
-        std::cout << "- OK: dat = ref\n";
-    return true;
-}
-
 std::unique_ptr<OutputData<double>>
 DataUtils::Data::createRelativeDifferenceData(const OutputData<double>& data,
                                               const OutputData<double>& reference)
diff --git a/Device/Data/DataUtils.h b/Device/Data/DataUtils.h
index 1145edb22a9..0f19301306b 100644
--- a/Device/Data/DataUtils.h
+++ b/Device/Data/DataUtils.h
@@ -23,10 +23,6 @@ namespace DataUtils::Data {
 //! Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
 double relativeDataDifference(const OutputData<double>& dat, const OutputData<double>& ref);
 
-//! Returns true is relative difference is below threshold; prints informative output
-bool checkRelativeDifference(const OutputData<double>& dat, const OutputData<double>& ref,
-                             double threshold);
-
 //! Transforms coordinate on axis into the bin-fraction-coordinate.
 double coordinateToBinf(double coordinate, const IAxis& axis);
 
diff --git a/Device/Histo/HistoUtils.cpp b/Device/Histo/HistoUtils.cpp
index 226a1265dfb..89cd850ab0f 100644
--- a/Device/Histo/HistoUtils.cpp
+++ b/Device/Histo/HistoUtils.cpp
@@ -79,6 +79,30 @@ double DataUtils::Histo::getRelativeDifference(const IHistogram& dat, const IHis
         *std::unique_ptr<OutputData<double>>(ref.getData().meanValues()));
 }
 
+//! Returns true is relative difference is below threshold; prints informative output
+bool DataUtils::Histo::checkRelativeDifference(const OutputData<double>& dat,
+                                              const OutputData<double>& ref, const double threshold)
+{
+    const std::unique_ptr<const IHistogram> histo(IHistogram::createHistogram(dat));
+    if (histo->getMinimum() == 0 && histo->getMaximum() == 0) {
+        std::cerr << "FAILED: simulated data set is empty" << std::endl;
+        return false;
+    }
+
+    const double diff = DataUtils::Data::relativeDataDifference(dat, ref);
+    if (diff > threshold) {
+        std::cerr << "FAILED: relative deviation of dat from ref is " << diff
+                  << ", above given threshold " << threshold << std::endl;
+        return false;
+    }
+    if (diff)
+        std::cerr << "- OK: relative deviation of dat from ref is " << diff
+                  << ", within given threshold " << threshold << std::endl;
+    else
+        std::cout << "- OK: dat = ref\n";
+    return true;
+}
+
 bool DataUtils::Histo::agreesWithReference(const SimulationResult& dat,
                                            const std::string& refFileName, double tol)
 {
@@ -88,5 +112,5 @@ bool DataUtils::Histo::agreesWithReference(const SimulationResult& dat,
         return false;
     }
     std::unique_ptr<OutputData<double>> datDat(dat.data());
-    return DataUtils::Data::checkRelativeDifference(*datDat, *refDat, tol);
+    return DataUtils::Histo::checkRelativeDifference(*datDat, *refDat, tol);
 }
diff --git a/Device/Histo/HistoUtils.h b/Device/Histo/HistoUtils.h
index 4056e845651..55353555f94 100644
--- a/Device/Histo/HistoUtils.h
+++ b/Device/Histo/HistoUtils.h
@@ -39,6 +39,10 @@ double RelativeDifference(const SimulationResult& dat, const SimulationResult& r
 
 double getRelativeDifference(const IHistogram& dat, const IHistogram& ref);
 
+//! Returns true is relative difference is below threshold; prints informative output
+bool checkRelativeDifference(const OutputData<double>& dat, const OutputData<double>& ref,
+                             double threshold);
+
 //! Returns true if SimulatioResult agrees with data from reference file
 bool agreesWithReference(const SimulationResult& dat, const std::string& refFileName, double tol);
 
diff --git a/Tests/Functional/Core/Consistence/CompareTwoReferences.cpp b/Tests/Functional/Core/Consistence/CompareTwoReferences.cpp
index dabbe078071..7a17e987777 100644
--- a/Tests/Functional/Core/Consistence/CompareTwoReferences.cpp
+++ b/Tests/Functional/Core/Consistence/CompareTwoReferences.cpp
@@ -14,7 +14,7 @@
 
 #include "BATesting.h"
 #include "Base/Util/FileSystemUtils.h"
-#include "Device/Data/DataUtils.h"
+#include "Device/Histo/HistoUtils.h"
 #include "Device/Histo/IntensityDataIOFactory.h"
 #include <iostream>
 
@@ -44,5 +44,5 @@ int compareTwoReferences(const std::string& name0, const std::string& name1, con
     std::unique_ptr<OutputData<double>> data0 = load(name0);
     std::unique_ptr<OutputData<double>> data1 = load(name1);
 
-    return DataUtils::Data::checkRelativeDifference(*data0, *data1, limit);
+    return DataUtils::Histo::checkRelativeDifference(*data0, *data1, limit);
 }
diff --git a/Tests/Functional/Core/Std/Check.cpp b/Tests/Functional/Core/Std/Check.cpp
index 69ea2c80df4..2557a6a3dcf 100644
--- a/Tests/Functional/Core/Std/Check.cpp
+++ b/Tests/Functional/Core/Std/Check.cpp
@@ -16,7 +16,7 @@
 #include "BATesting.h"
 #include "Base/Util/FileSystemUtils.h"
 #include "Core/Simulation/ISimulation.h"
-#include "Device/Data/DataUtils.h"
+#include "Device/Histo/HistoUtils.h"
 #include "Device/Histo/IntensityDataIOFactory.h"
 #include "Device/Histo/SimulationResult.h"
 #include <iostream>
@@ -45,7 +45,7 @@ bool checkSimulation(const std::string& name, const ISimulation& direct_simulati
     // Compare with reference if available.
     if (reference) {
         std::cout << "- check diff" << std::endl;
-        if (DataUtils::Data::checkRelativeDifference(*result_data, *reference, limit)) {
+        if (DataUtils::Histo::checkRelativeDifference(*result_data, *reference, limit)) {
             std::cout << "- success" << std::endl;
             return true; // regular exit
         }
diff --git a/Tests/Functional/GUI/Check.cpp b/Tests/Functional/GUI/Check.cpp
index 5fc4cd7fa44..39c0ccd934e 100644
--- a/Tests/Functional/GUI/Check.cpp
+++ b/Tests/Functional/GUI/Check.cpp
@@ -16,7 +16,7 @@
 #include "BATesting.h"
 #include "Base/Util/FileSystemUtils.h"
 #include "Core/Simulation/ISimulation.h"
-#include "Device/Data/DataUtils.h"
+#include "Device/Histo/HistoUtils.h"
 #include "Device/Histo/IntensityDataIOFactory.h"
 #include "Device/Histo/SimulationResult.h"
 #include "GUI/Model/Instrument/InstrumentItems.h"
@@ -63,7 +63,7 @@ bool checkSimulation(const std::string& name, const ISimulation& direct_simulati
 
     const std::unique_ptr<OutputData<double>> ref_data = direct_simulation.result().data();
 
-    bool ok = DataUtils::Data::checkRelativeDifference(*domain_data, *ref_data, limit);
+    bool ok = DataUtils::Histo::checkRelativeDifference(*domain_data, *ref_data, limit);
 
     if (ok)
         return true;
diff --git a/Tests/Functional/PyStd/Check.cpp b/Tests/Functional/PyStd/Check.cpp
index 7ea323df1d5..f8b5dc1260f 100644
--- a/Tests/Functional/PyStd/Check.cpp
+++ b/Tests/Functional/PyStd/Check.cpp
@@ -17,7 +17,7 @@
 #include "Base/Util/FileSystemUtils.h"
 #include "Core/Export/ExportToPython.h"
 #include "Core/Simulation/ISimulation.h"
-#include "Device/Data/DataUtils.h"
+#include "Device/Histo/HistoUtils.h"
 #include "Device/Histo/IntensityDataIOFactory.h"
 #include "Device/Histo/SimulationResult.h"
 #include <fstream>
@@ -79,5 +79,5 @@ bool checkSimulation(const std::string& name, const ISimulation& direct_simulati
     const std::unique_ptr<OutputData<double>> ref_data = direct_simulation.result().data();
     std::cout << "- ran simulation" << std::endl;
 
-    return DataUtils::Data::checkRelativeDifference(*domain_data, *ref_data, limit);
+    return DataUtils::Histo::checkRelativeDifference(*domain_data, *ref_data, limit);
 }
diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i
index b91a5c26c7c..f62ff478e02 100644
--- a/auto/Wrap/doxygenDevice.i
+++ b/auto/Wrap/doxygenDevice.i
@@ -2789,11 +2789,6 @@ Creates 2D vector from  OutputData.
 Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). 
 ";
 
-%feature("docstring")  DataUtils::Data::checkRelativeDifference "bool DataUtils::Data::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, double threshold)
-
-Returns true is relative difference is below threshold; prints informative output. 
-";
-
 %feature("docstring")  DataUtils::Data::coordinateToBinf "double DataUtils::Data::coordinateToBinf(double coordinate, const IAxis &axis)
 
 Transforms coordinate on axis into the bin-fraction-coordinate. 
@@ -2928,6 +2923,11 @@ Returns sum of relative differences between each pair of elements: (a, b) -> 2*a
 %feature("docstring")  DataUtils::Histo::getRelativeDifference "double DataUtils::Histo::getRelativeDifference(const IHistogram &dat, const IHistogram &ref)
 ";
 
+%feature("docstring")  DataUtils::Histo::checkRelativeDifference "bool DataUtils::Histo::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, double threshold)
+
+Returns true is relative difference is below threshold; prints informative output. 
+";
+
 %feature("docstring")  DataUtils::Histo::agreesWithReference "bool DataUtils::Histo::agreesWithReference(const SimulationResult &dat, const std::string &refFileName, double tol)
 
 Returns true if SimulatioResult agrees with data from reference file. 
diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py
index 1cbd2b213ad..bb7a451e2e9 100644
--- a/auto/Wrap/libBornAgainDevice.py
+++ b/auto/Wrap/libBornAgainDevice.py
@@ -2865,16 +2865,6 @@ def relativeDataDifference(dat, ref):
     """
     return _libBornAgainDevice.relativeDataDifference(dat, ref)
 
-def checkRelativeDifference(dat, ref, threshold):
-    r"""
-    checkRelativeDifference(IntensityData dat, IntensityData ref, double threshold) -> bool
-    bool DataUtils::Data::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, double threshold)
-
-    Returns true is relative difference is below threshold; prints informative output. 
-
-    """
-    return _libBornAgainDevice.checkRelativeDifference(dat, ref, threshold)
-
 def coordinateToBinf(*args):
     r"""
     coordinateToBinf(double coordinate, IAxis axis) -> double
@@ -4945,6 +4935,16 @@ def getRelativeDifference(dat, ref):
     """
     return _libBornAgainDevice.getRelativeDifference(dat, ref)
 
+def checkRelativeDifference(dat, ref, threshold):
+    r"""
+    checkRelativeDifference(IntensityData dat, IntensityData ref, double threshold) -> bool
+    bool DataUtils::Histo::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, double threshold)
+
+    Returns true is relative difference is below threshold; prints informative output. 
+
+    """
+    return _libBornAgainDevice.checkRelativeDifference(dat, ref, threshold)
+
 def agreesWithReference(dat, refFileName, tol):
     r"""
     agreesWithReference(SimulationResult dat, std::string const & refFileName, double tol) -> bool
diff --git a/auto/Wrap/libBornAgainDevice_wrap.cpp b/auto/Wrap/libBornAgainDevice_wrap.cpp
index a65732d3e08..104df8f773c 100644
--- a/auto/Wrap/libBornAgainDevice_wrap.cpp
+++ b/auto/Wrap/libBornAgainDevice_wrap.cpp
@@ -33177,50 +33177,6 @@ fail:
 }
 
 
-SWIGINTERN PyObject *_wrap_checkRelativeDifference(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
-  PyObject *resultobj = 0;
-  OutputData< double > *arg1 = 0 ;
-  OutputData< double > *arg2 = 0 ;
-  double arg3 ;
-  void *argp1 = 0 ;
-  int res1 = 0 ;
-  void *argp2 = 0 ;
-  int res2 = 0 ;
-  double val3 ;
-  int ecode3 = 0 ;
-  PyObject *swig_obj[3] ;
-  bool result;
-  
-  if (!SWIG_Python_UnpackTuple(args, "checkRelativeDifference", 3, 3, swig_obj)) SWIG_fail;
-  res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_OutputDataT_double_t,  0  | 0);
-  if (!SWIG_IsOK(res1)) {
-    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "checkRelativeDifference" "', argument " "1"" of type '" "OutputData< double > const &""'"); 
-  }
-  if (!argp1) {
-    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "checkRelativeDifference" "', argument " "1"" of type '" "OutputData< double > const &""'"); 
-  }
-  arg1 = reinterpret_cast< OutputData< double > * >(argp1);
-  res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_OutputDataT_double_t,  0  | 0);
-  if (!SWIG_IsOK(res2)) {
-    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "checkRelativeDifference" "', argument " "2"" of type '" "OutputData< double > const &""'"); 
-  }
-  if (!argp2) {
-    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "checkRelativeDifference" "', argument " "2"" of type '" "OutputData< double > const &""'"); 
-  }
-  arg2 = reinterpret_cast< OutputData< double > * >(argp2);
-  ecode3 = SWIG_AsVal_double(swig_obj[2], &val3);
-  if (!SWIG_IsOK(ecode3)) {
-    SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "checkRelativeDifference" "', argument " "3"" of type '" "double""'");
-  } 
-  arg3 = static_cast< double >(val3);
-  result = (bool)DataUtils::Data::checkRelativeDifference((OutputData< double > const &)*arg1,(OutputData< double > const &)*arg2,arg3);
-  resultobj = SWIG_From_bool(static_cast< bool >(result));
-  return resultobj;
-fail:
-  return NULL;
-}
-
-
 SWIGINTERN PyObject *_wrap_coordinateToBinf__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
   PyObject *resultobj = 0;
   double arg1 ;
@@ -41667,6 +41623,50 @@ fail:
 }
 
 
+SWIGINTERN PyObject *_wrap_checkRelativeDifference(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
+  PyObject *resultobj = 0;
+  OutputData< double > *arg1 = 0 ;
+  OutputData< double > *arg2 = 0 ;
+  double arg3 ;
+  void *argp1 = 0 ;
+  int res1 = 0 ;
+  void *argp2 = 0 ;
+  int res2 = 0 ;
+  double val3 ;
+  int ecode3 = 0 ;
+  PyObject *swig_obj[3] ;
+  bool result;
+  
+  if (!SWIG_Python_UnpackTuple(args, "checkRelativeDifference", 3, 3, swig_obj)) SWIG_fail;
+  res1 = SWIG_ConvertPtr(swig_obj[0], &argp1, SWIGTYPE_p_OutputDataT_double_t,  0  | 0);
+  if (!SWIG_IsOK(res1)) {
+    SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "checkRelativeDifference" "', argument " "1"" of type '" "OutputData< double > const &""'"); 
+  }
+  if (!argp1) {
+    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "checkRelativeDifference" "', argument " "1"" of type '" "OutputData< double > const &""'"); 
+  }
+  arg1 = reinterpret_cast< OutputData< double > * >(argp1);
+  res2 = SWIG_ConvertPtr(swig_obj[1], &argp2, SWIGTYPE_p_OutputDataT_double_t,  0  | 0);
+  if (!SWIG_IsOK(res2)) {
+    SWIG_exception_fail(SWIG_ArgError(res2), "in method '" "checkRelativeDifference" "', argument " "2"" of type '" "OutputData< double > const &""'"); 
+  }
+  if (!argp2) {
+    SWIG_exception_fail(SWIG_ValueError, "invalid null reference " "in method '" "checkRelativeDifference" "', argument " "2"" of type '" "OutputData< double > const &""'"); 
+  }
+  arg2 = reinterpret_cast< OutputData< double > * >(argp2);
+  ecode3 = SWIG_AsVal_double(swig_obj[2], &val3);
+  if (!SWIG_IsOK(ecode3)) {
+    SWIG_exception_fail(SWIG_ArgError(ecode3), "in method '" "checkRelativeDifference" "', argument " "3"" of type '" "double""'");
+  } 
+  arg3 = static_cast< double >(val3);
+  result = (bool)DataUtils::Histo::checkRelativeDifference((OutputData< double > const &)*arg1,(OutputData< double > const &)*arg2,arg3);
+  resultobj = SWIG_From_bool(static_cast< bool >(result));
+  return resultobj;
+fail:
+  return NULL;
+}
+
+
 SWIGINTERN PyObject *_wrap_agreesWithReference(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
   PyObject *resultobj = 0;
   SimulationResult *arg1 = 0 ;
@@ -47740,13 +47740,6 @@ static PyMethodDef SwigMethods[] = {
 		"Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]). \n"
 		"\n"
 		""},
-	 { "checkRelativeDifference", _wrap_checkRelativeDifference, METH_VARARGS, "\n"
-		"checkRelativeDifference(IntensityData dat, IntensityData ref, double threshold) -> bool\n"
-		"bool DataUtils::Data::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, double threshold)\n"
-		"\n"
-		"Returns true is relative difference is below threshold; prints informative output. \n"
-		"\n"
-		""},
 	 { "coordinateToBinf", _wrap_coordinateToBinf, METH_VARARGS, "\n"
 		"coordinateToBinf(double coordinate, IAxis axis) -> double\n"
 		"coordinateToBinf(double & x, double & y, IntensityData data)\n"
@@ -48964,6 +48957,13 @@ static PyMethodDef SwigMethods[] = {
 		"double DataUtils::Histo::getRelativeDifference(const IHistogram &dat, const IHistogram &ref)\n"
 		"\n"
 		""},
+	 { "checkRelativeDifference", _wrap_checkRelativeDifference, METH_VARARGS, "\n"
+		"checkRelativeDifference(IntensityData dat, IntensityData ref, double threshold) -> bool\n"
+		"bool DataUtils::Histo::checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, double threshold)\n"
+		"\n"
+		"Returns true is relative difference is below threshold; prints informative output. \n"
+		"\n"
+		""},
 	 { "agreesWithReference", _wrap_agreesWithReference, METH_VARARGS, "\n"
 		"agreesWithReference(SimulationResult dat, std::string const & refFileName, double tol) -> bool\n"
 		"bool DataUtils::Histo::agreesWithReference(const SimulationResult &dat, const std::string &refFileName, double tol)\n"
-- 
GitLab