Skip to content
Snippets Groups Projects
Commit 893cbe3e authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

throw -> ASSERT

parent c9141174
No related branches found
No related tags found
1 merge request!232Cleanup in context of Simulation, Computation; *Element now inherits from IElement
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "Core/Simulation/SpecularSimulation.h" #include "Core/Simulation/SpecularSimulation.h"
#include "Base/Axis/PointwiseAxis.h" #include "Base/Axis/PointwiseAxis.h"
#include "Base/Utils/Assert.h"
#include "Core/Background/IBackground.h" #include "Core/Background/IBackground.h"
#include "Core/Computation/SpecularComputation.h" #include "Core/Computation/SpecularComputation.h"
#include "Core/Element/SpecularElement.h" #include "Core/Element/SpecularElement.h"
...@@ -70,9 +71,7 @@ SpecularSimulation::~SpecularSimulation() = default; ...@@ -70,9 +71,7 @@ SpecularSimulation::~SpecularSimulation() = default;
void SpecularSimulation::prepareSimulation() void SpecularSimulation::prepareSimulation()
{ {
if (detector().dimension() != 1) // detector must have only one axis ASSERT(detector().dimension() == 1);
throw std::runtime_error("Error in SpecularSimulation::prepareSimulation: the detector was "
"not properly configured.");
instrument().initDetector(); instrument().initDetector();
ISimulation::prepareSimulation(); ISimulation::prepareSimulation();
} }
...@@ -107,9 +106,7 @@ void SpecularSimulation::setScan(const ISpecularScan& scan) ...@@ -107,9 +106,7 @@ void SpecularSimulation::setScan(const ISpecularScan& scan)
m_scan.reset(scan.clone()); m_scan.reset(scan.clone());
if (detector().dimension() > 0) ASSERT(detector().dimension() == 0); // check that axis has not been set before
throw std::runtime_error("Error in SpecularSimulation::setScan: Axis already set");
detector().addAxis(*scan.coordinateAxis()); detector().addAxis(*scan.coordinateAxis());
// TODO: remove when pointwise resolution is implemented // TODO: remove when pointwise resolution is implemented
...@@ -119,9 +116,8 @@ void SpecularSimulation::setScan(const ISpecularScan& scan) ...@@ -119,9 +116,8 @@ void SpecularSimulation::setScan(const ISpecularScan& scan)
const IAxis* SpecularSimulation::coordinateAxis() const const IAxis* SpecularSimulation::coordinateAxis() const
{ {
if (!m_scan || !m_scan->coordinateAxis()) ASSERT(m_scan);
throw std::runtime_error( ASSERT(m_scan->coordinateAxis());
"Error in SpecularSimulation::getAlphaAxis: coordinate axis was not initialized.");
return m_scan->coordinateAxis(); return m_scan->coordinateAxis();
} }
...@@ -145,8 +141,7 @@ ICoordSystem* SpecularSimulation::createCoordSystem() const ...@@ -145,8 +141,7 @@ ICoordSystem* SpecularSimulation::createCoordSystem() const
void SpecularSimulation::initElementVector() void SpecularSimulation::initElementVector()
{ {
if (!m_scan) ASSERT(m_scan);
throw std::runtime_error("Error in SpecularSimulation: beam parameters were not set.");
m_eles = generateElements(instrument(), *m_scan); m_eles = generateElements(instrument(), *m_scan);
if (!m_cache.empty()) if (!m_cache.empty())
...@@ -166,9 +161,7 @@ SpecularSimulation::createComputation(const ProcessedSample& re_sample, size_t s ...@@ -166,9 +161,7 @@ SpecularSimulation::createComputation(const ProcessedSample& re_sample, size_t s
void SpecularSimulation::checkCache() const void SpecularSimulation::checkCache() const
{ {
if (m_eles.size() != m_cache.size()) ASSERT(m_eles.size() == m_cache.size());
throw std::runtime_error("Error in SpecularSimulation: the sizes of simulation element "
"vector and of its cache are different");
} }
void SpecularSimulation::validateParametrization(const ParameterDistribution& par_distr) const void SpecularSimulation::validateParametrization(const ParameterDistribution& par_distr) const
...@@ -238,9 +231,7 @@ std::vector<double> SpecularSimulation::rawResults() const ...@@ -238,9 +231,7 @@ std::vector<double> SpecularSimulation::rawResults() const
void SpecularSimulation::setRawResults(const std::vector<double>& raw_data) void SpecularSimulation::setRawResults(const std::vector<double>& raw_data)
{ {
initElementVector(); initElementVector();
if (raw_data.size() != m_eles.size()) ASSERT(raw_data.size() == m_eles.size());
throw std::runtime_error("SpecularSimulation::setRawResults: size of vector passed as "
"argument doesn't match number of elements in this simulation");
for (unsigned i = 0; i < raw_data.size(); i++) for (unsigned i = 0; i < raw_data.size(); i++)
m_eles[i].setIntensity(raw_data[i]); m_eles[i].setIntensity(raw_data[i]);
transferResultsToIntensityMap(); transferResultsToIntensityMap();
......
...@@ -46,7 +46,7 @@ Returns IFootprintFactor object pointer. ...@@ -46,7 +46,7 @@ Returns IFootprintFactor object pointer.
Returns footprint correction factor for a range of simulation elements of size n_elements and starting from element with index i. Returns footprint correction factor for a range of simulation elements of size n_elements and starting from element with index i.
"; ";
%feature("docstring") AngularSpecScan::numberOfDiffuseElements "size_t AngularSpecScan::numberOfDiffuseElements() const override %feature("docstring") AngularSpecScan::numberOfElements "size_t AngularSpecScan::numberOfElements() const override
Returns the number of simulation elements. Returns the number of simulation elements.
"; ";
...@@ -1162,7 +1162,7 @@ Returns IFootprintFactor object pointer. ...@@ -1162,7 +1162,7 @@ Returns IFootprintFactor object pointer.
Returns footprint correction factor for a range of simulation elements of size n_elements and starting from element with index i. Returns footprint correction factor for a range of simulation elements of size n_elements and starting from element with index i.
"; ";
%feature("docstring") ISpecularScan::numberOfDiffuseElements "virtual size_t ISpecularScan::numberOfDiffuseElements() const =0 %feature("docstring") ISpecularScan::numberOfElements "virtual size_t ISpecularScan::numberOfElements() const =0
Returns the number of simulation elements. Returns the number of simulation elements.
"; ";
...@@ -1642,7 +1642,7 @@ Returns IFootprintFactor object pointer. ...@@ -1642,7 +1642,7 @@ Returns IFootprintFactor object pointer.
Returns footprint correction factor for a range of simulation elements of size n_elements and starting from element with index i. Returns footprint correction factor for a range of simulation elements of size n_elements and starting from element with index i.
"; ";
%feature("docstring") QSpecScan::numberOfDiffuseElements "size_t QSpecScan::numberOfDiffuseElements() const override %feature("docstring") QSpecScan::numberOfElements "size_t QSpecScan::numberOfElements() const override
Returns the number of simulation elements. Returns the number of simulation elements.
"; ";
......
...@@ -442,7 +442,7 @@ C++ includes: DetectorContext.h ...@@ -442,7 +442,7 @@ C++ includes: DetectorContext.h
%feature("docstring") DetectorContext::DetectorContext "DetectorContext::DetectorContext(const DetectorContext &other)=delete %feature("docstring") DetectorContext::DetectorContext "DetectorContext::DetectorContext(const DetectorContext &other)=delete
"; ";
%feature("docstring") DetectorContext::numberOfDiffuseElements "size_t DetectorContext::numberOfDiffuseElements() const %feature("docstring") DetectorContext::numberOfElements "size_t DetectorContext::numberOfElements() const
"; ";
%feature("docstring") DetectorContext::createPixel "std::unique_ptr< IPixel > DetectorContext::createPixel(size_t element_index) const %feature("docstring") DetectorContext::createPixel "std::unique_ptr< IPixel > DetectorContext::createPixel(size_t element_index) const
...@@ -1133,7 +1133,7 @@ Returns new intensity map with resolution applied, and cropped to ROI if applica ...@@ -1133,7 +1133,7 @@ Returns new intensity map with resolution applied, and cropped to ROI if applica
Return default axes units. Return default axes units.
"; ";
%feature("docstring") IDetector::numberOfDiffuseElements "size_t IDetector::numberOfDiffuseElements() const %feature("docstring") IDetector::numberOfElements "size_t IDetector::numberOfElements() const
Returns number of simulation elements. Returns number of simulation elements.
"; ";
......
...@@ -4155,15 +4155,15 @@ class IDetector(libBornAgainBase.ICloneable, libBornAgainParam.INode): ...@@ -4155,15 +4155,15 @@ class IDetector(libBornAgainBase.ICloneable, libBornAgainParam.INode):
""" """
return _libBornAgainDevice.IDetector_defaultCoords(self) return _libBornAgainDevice.IDetector_defaultCoords(self)
def numberOfDiffuseElements(self): def numberOfElements(self):
r""" r"""
numberOfDiffuseElements(IDetector self) -> size_t numberOfElements(IDetector self) -> size_t
size_t IDetector::numberOfDiffuseElements() const size_t IDetector::numberOfElements() const
Returns number of simulation elements. Returns number of simulation elements.
""" """
return _libBornAgainDevice.IDetector_numberOfDiffuseElements(self) return _libBornAgainDevice.IDetector_numberOfElements(self)
def regionOfInterestBounds(self, iAxis): def regionOfInterestBounds(self, iAxis):
r""" r"""
......
...@@ -36382,7 +36382,7 @@ fail: ...@@ -36382,7 +36382,7 @@ fail:
} }
   
   
SWIGINTERN PyObject *_wrap_IDetector_numberOfDiffuseElements(PyObject *SWIGUNUSEDPARM(self), PyObject *args) { SWIGINTERN PyObject *_wrap_IDetector_numberOfElements(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {
PyObject *resultobj = 0; PyObject *resultobj = 0;
IDetector *arg1 = (IDetector *) 0 ; IDetector *arg1 = (IDetector *) 0 ;
void *argp1 = 0 ; void *argp1 = 0 ;
...@@ -36394,10 +36394,10 @@ SWIGINTERN PyObject *_wrap_IDetector_numberOfDiffuseElements(PyObject *SWIGUNUSE ...@@ -36394,10 +36394,10 @@ SWIGINTERN PyObject *_wrap_IDetector_numberOfDiffuseElements(PyObject *SWIGUNUSE
swig_obj[0] = args; swig_obj[0] = args;
res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_IDetector, 0 | 0 ); res1 = SWIG_ConvertPtr(swig_obj[0], &argp1,SWIGTYPE_p_IDetector, 0 | 0 );
if (!SWIG_IsOK(res1)) { if (!SWIG_IsOK(res1)) {
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IDetector_numberOfDiffuseElements" "', argument " "1"" of type '" "IDetector const *""'"); SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "IDetector_numberOfElements" "', argument " "1"" of type '" "IDetector const *""'");
} }
arg1 = reinterpret_cast< IDetector * >(argp1); arg1 = reinterpret_cast< IDetector * >(argp1);
result = ((IDetector const *)arg1)->numberOfDiffuseElements(); result = ((IDetector const *)arg1)->numberOfElements();
resultobj = SWIG_From_size_t(static_cast< size_t >(result)); resultobj = SWIG_From_size_t(static_cast< size_t >(result));
return resultobj; return resultobj;
fail: fail:
...@@ -45770,9 +45770,9 @@ static PyMethodDef SwigMethods[] = { ...@@ -45770,9 +45770,9 @@ static PyMethodDef SwigMethods[] = {
"Return default axes units. \n" "Return default axes units. \n"
"\n" "\n"
""}, ""},
{ "IDetector_numberOfDiffuseElements", _wrap_IDetector_numberOfDiffuseElements, METH_O, "\n" { "IDetector_numberOfElements", _wrap_IDetector_numberOfElements, METH_O, "\n"
"IDetector_numberOfDiffuseElements(IDetector self) -> size_t\n" "IDetector_numberOfElements(IDetector self) -> size_t\n"
"size_t IDetector::numberOfDiffuseElements() const\n" "size_t IDetector::numberOfElements() const\n"
"\n" "\n"
"Returns number of simulation elements. \n" "Returns number of simulation elements. \n"
"\n" "\n"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment