diff --git a/Base/Py/PyObject.h b/Base/Py/PyObject.h index b8d6ef2545cd8753ade7cbd65b174716d7aedf1e..52e56f1d519dcb507d99e53a8a8eb7c80f488d96 100644 --- a/Base/Py/PyObject.h +++ b/Base/Py/PyObject.h @@ -3,7 +3,7 @@ // BornAgain: simulate and fit reflection and scattering // //! @file Base/Py/PyObject.h -//! @brief PyObvject forward declaration. +//! @brief PyObject forward declaration. //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) diff --git a/Device/Data/OutputData.cpp b/Device/Data/OutputData.cpp index 2d8b6fd256393cd552b73d43470ef74dbbb81e06..a2a9d6ff166a38d8d0e969628d0e0f01fca51ab3 100644 --- a/Device/Data/OutputData.cpp +++ b/Device/Data/OutputData.cpp @@ -38,8 +38,7 @@ template <> PyObject* OutputData<double>::getArray() const // creating standalone numpy array PyObject* pyarray = PyArray_SimpleNew(ndim_numpy, ndimsizes_numpy, NPY_DOUBLE); delete[] ndimsizes_numpy; - if (pyarray == nullptr) - throw std::runtime_error("ExportOutputData() -> Panic in PyArray_SimpleNew"); + ASSERT(pyarray); // getting pointer to data buffer of numpy array double* array_buffer = (double*)PyArray_DATA((PyArrayObject*)pyarray); diff --git a/Device/Data/OutputData.h b/Device/Data/OutputData.h index 5964545cde0389322534bf250ef4a28fd6c19362..49a670dcfd41dd5abe1dd664101406c75affb55d 100644 --- a/Device/Data/OutputData.h +++ b/Device/Data/OutputData.h @@ -26,7 +26,8 @@ using std::size_t; -//! Templated class to store data of type double or CumulativeValue in multi-dimensional space. +//! Templated class to store data in multi-dimensional space. +//! Used with type T = double, CumulativeValue, bool //! @ingroup tools template <class T> class OutputData { @@ -292,10 +293,7 @@ template <class T> OutputData<double>* OutputData<T>::meanValues() const template <class T> void OutputData<T>::addAxis(const IAxis& new_axis) { - if (axisNameExists(new_axis.axisName())) - throw std::runtime_error("OutputData<T>::addAxis(const IAxis& new_axis) -> " - "Error! Attempt to add axis with already existing name '" - + new_axis.axisName() + "'"); + ASSERT(!axisNameExists(new_axis.axisName())); if (new_axis.size() > 0) { m_axes.push_back(new_axis.clone()); allocate(); @@ -305,10 +303,7 @@ template <class T> void OutputData<T>::addAxis(const IAxis& new_axis) template <class T> void OutputData<T>::addAxis(const std::string& name, size_t size, double start, double end) { - if (axisNameExists(name)) - throw std::runtime_error("OutputData<T>::addAxis(std::string name) -> " - "Error! Attempt to add axis with already existing name '" - + name + "'"); + ASSERT(!axisNameExists(name)); FixedBinAxis new_axis(name, size, start, end); addAxis(new_axis); } @@ -376,8 +371,7 @@ size_t OutputData<T>::getAxisBinIndex(size_t global_index, size_t i_selected_axi return result; remainder /= m_axes[i_axis]->size(); } - throw std::runtime_error("OutputData<T>::getAxisBinIndex() -> " - "Error! No axis with given number"); + ASSERT(0); } template <class T> @@ -390,20 +384,11 @@ template <class T> size_t OutputData<T>::toGlobalIndex(const std::vector<unsigned>& axes_indices) const { ASSERT(m_ll_data); - if (axes_indices.size() != m_ll_data->rank()) - throw std::runtime_error("size_t OutputData<T>::toGlobalIndex() -> " - "Error! Number of coordinates must match rank of data structure"); + ASSERT(axes_indices.size() == m_ll_data->rank()); size_t result = 0; size_t step_size = 1; for (size_t i = m_ll_data->rank(); i > 0; --i) { - if (axes_indices[i - 1] >= m_axes[i - 1]->size()) { - std::ostringstream message; - message << "size_t OutputData<T>::toGlobalIndex() -> Error. Index "; - message << axes_indices[i - 1] << " is out of range. Axis "; - message << m_axes[i - 1]->axisName(); - message << " size " << m_axes[i - 1]->size() << ".\n"; - throw std::runtime_error(message.str()); - } + ASSERT(axes_indices[i - 1] < m_axes[i - 1]->size()); result += axes_indices[i - 1] * step_size; step_size *= m_axes[i - 1]->size(); } @@ -414,9 +399,7 @@ template <class T> size_t OutputData<T>::findGlobalIndex(const std::vector<double>& coordinates) const { ASSERT(m_ll_data); - if (coordinates.size() != m_ll_data->rank()) - throw std::runtime_error("OutputData<T>::findClosestIndex() -> " - "Error! Number of coordinates must match rank of data structure"); + ASSERT(coordinates.size() == m_ll_data->rank()); std::vector<unsigned> axes_indexes; axes_indexes.resize(m_ll_data->rank()); for (size_t i = 0; i < m_ll_data->rank(); ++i) @@ -473,9 +456,7 @@ template <class T> void OutputData<T>::clear() template <class T> void OutputData<T>::setAllTo(const T& value) { - if (!m_ll_data) - throw std::runtime_error( - "OutputData::setAllTo() -> Error! Low-level data object was not yet initialized."); + ASSERT(m_ll_data); m_ll_data->setAll(value); } @@ -544,10 +525,7 @@ template <class T> void OutputData<T>::allocate() template <class T> inline void OutputData<T>::setRawDataVector(const std::vector<T>& data_vector) { - if (data_vector.size() != getAllocatedSize()) - throw std::runtime_error( - "OutputData<T>::setRawDataVector() -> Error! " - "setRawDataVector can only be called with a data vector of the correct size."); + ASSERT(data_vector.size() == getAllocatedSize()); for (size_t i = 0; i < getAllocatedSize(); ++i) (*m_ll_data)[i] = data_vector[i]; } @@ -600,9 +578,7 @@ template <class T> size_t OutputData<T>::getAxisIndex(const std::string& axis_na for (size_t i = 0; i < m_axes.size(); ++i) if (m_axes[i]->axisName() == axis_name) return i; - throw std::runtime_error("OutputData<T>::getAxisIndex() -> " - "Error! Axis with given name not found '" - + axis_name + "'"); + ASSERT(0); } template <class T> bool OutputData<T>::axisNameExists(const std::string& axis_name) const diff --git a/auto/Wrap/doxygenDevice.i b/auto/Wrap/doxygenDevice.i index 7afac3407d83ea6c7caaa2537a63166139323d29..b60c988fe0456b9356e856705ba76e687e73954f 100644 --- a/auto/Wrap/doxygenDevice.i +++ b/auto/Wrap/doxygenDevice.i @@ -1737,7 +1737,7 @@ C++ includes: CoordSystem2D.h // File: classOutputData.xml %feature("docstring") OutputData " -Templated class to store data of type double or CumulativeValue in multi-dimensional space. +Templated class to store data in multi-dimensional space. Used with type T = double, CumulativeValue, bool C++ includes: OutputData.h "; diff --git a/auto/Wrap/libBornAgainDevice.py b/auto/Wrap/libBornAgainDevice.py index 17d72d219dab775d0cc1e31128430b2e8ae3aa82..4014d89f18712f2638c683757ef12bc999c5c94e 100644 --- a/auto/Wrap/libBornAgainDevice.py +++ b/auto/Wrap/libBornAgainDevice.py @@ -2217,7 +2217,7 @@ class IntensityData(object): r""" - Templated class to store data of type double or CumulativeValue in multi-dimensional space. + Templated class to store data in multi-dimensional space. Used with type T = double, CumulativeValue, bool C++ includes: OutputData.h