Unverified Commit bba6c826 authored by Whitfield, Ross's avatar Whitfield, Ross Committed by GitHub
Browse files

Merge pull request #30882 from rosswhitfield/LeanPeaksWorkspace

New LeanElasticPeaksWorkspace class
parents 49345629 f85203cb
...@@ -118,6 +118,14 @@ public: ...@@ -118,6 +118,14 @@ public:
createPeak(const Mantid::Kernel::V3D &position, createPeak(const Mantid::Kernel::V3D &position,
const Mantid::Kernel::SpecialCoordinateSystem &frame) const = 0; const Mantid::Kernel::SpecialCoordinateSystem &frame) const = 0;
//---------------------------------------------------------------------------------------------
/** Create an instance of a Peak
* @param position :: enter of the peak in the sample frame
* @return a pointer to a new Peak object.
*/
virtual std::unique_ptr<Mantid::Geometry::IPeak>
createPeakQSample(const Mantid::Kernel::V3D &position) const = 0;
/** /**
* Create an instance of a peak using a V3D * Create an instance of a peak using a V3D
* @param HKL V3D * @param HKL V3D
...@@ -126,6 +134,12 @@ public: ...@@ -126,6 +134,12 @@ public:
virtual std::unique_ptr<Geometry::IPeak> virtual std::unique_ptr<Geometry::IPeak>
createPeakHKL(const Mantid::Kernel::V3D &HKL) const = 0; createPeakHKL(const Mantid::Kernel::V3D &HKL) const = 0;
/**
* Create an instance of a peak using default constructor
* @return a pointer to a new Peak object.
*/
virtual std::unique_ptr<Geometry::IPeak> createPeak() const = 0;
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
/** Determine if the workspace has been integrated using a peaks integration /** Determine if the workspace has been integrated using a peaks integration
* algorithm. * algorithm.
......
...@@ -38,6 +38,7 @@ set(SRC_FILES ...@@ -38,6 +38,7 @@ set(SRC_FILES
src/PeakShapeSpherical.cpp src/PeakShapeSpherical.cpp
src/PeakShapeSphericalFactory.cpp src/PeakShapeSphericalFactory.cpp
src/PeaksWorkspace.cpp src/PeaksWorkspace.cpp
src/LeanElasticPeaksWorkspace.cpp
src/PropertyWithValue.cpp src/PropertyWithValue.cpp
src/RebinnedOutput.cpp src/RebinnedOutput.cpp
src/ReflectometryTransform.cpp src/ReflectometryTransform.cpp
...@@ -121,6 +122,7 @@ set(INC_FILES ...@@ -121,6 +122,7 @@ set(INC_FILES
inc/MantidDataObjects/PeakShapeSpherical.h inc/MantidDataObjects/PeakShapeSpherical.h
inc/MantidDataObjects/PeakShapeSphericalFactory.h inc/MantidDataObjects/PeakShapeSphericalFactory.h
inc/MantidDataObjects/PeaksWorkspace.h inc/MantidDataObjects/PeaksWorkspace.h
inc/MantidDataObjects/LeanElasticPeaksWorkspace.h
inc/MantidDataObjects/RebinnedOutput.h inc/MantidDataObjects/RebinnedOutput.h
inc/MantidDataObjects/ReflectometryTransform.h inc/MantidDataObjects/ReflectometryTransform.h
inc/MantidDataObjects/ScanningWorkspaceBuilder.h inc/MantidDataObjects/ScanningWorkspaceBuilder.h
...@@ -181,6 +183,7 @@ set(TEST_FILES ...@@ -181,6 +183,7 @@ set(TEST_FILES
PeakTest.h PeakTest.h
LeanElasticPeakTest.h LeanElasticPeakTest.h
PeaksWorkspaceTest.h PeaksWorkspaceTest.h
LeanElasticPeaksWorkspaceTest.h
RebinnedOutputTest.h RebinnedOutputTest.h
RefAxisTest.h RefAxisTest.h
ReflectometryTransformTest.h ReflectometryTransformTest.h
......
...@@ -32,9 +32,6 @@ namespace DataObjects { ...@@ -32,9 +32,6 @@ namespace DataObjects {
*/ */
class DLLExport BasePeak : public Geometry::IPeak { class DLLExport BasePeak : public Geometry::IPeak {
public: public:
/// Allow PeakColumn class to directly access members.
friend class PeakColumn;
BasePeak(); BasePeak();
BasePeak(const Mantid::Kernel::Matrix<double> &goniometer); BasePeak(const Mantid::Kernel::Matrix<double> &goniometer);
/// Copy constructor /// Copy constructor
......
...@@ -30,9 +30,6 @@ namespace DataObjects { ...@@ -30,9 +30,6 @@ namespace DataObjects {
*/ */
class DLLExport LeanElasticPeak : public BasePeak { class DLLExport LeanElasticPeak : public BasePeak {
public: public:
/// Allow PeakColumn class to directly access members.
friend class PeakColumn;
LeanElasticPeak(); LeanElasticPeak();
LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame); LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame);
LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame, LeanElasticPeak(const Mantid::Kernel::V3D &QSampleFrame,
......
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidDataObjects/DllConfig.h"
#include "MantidDataObjects/LeanElasticPeak.h"
#include "MantidDataObjects/PeakColumn.h"
#include "MantidGeometry/Crystal/IPeak.h"
#include "MantidKernel/SpecialCoordinateSystem.h"
#include "MantidKernel/V3D.h"
// IsamplePosition should be IsampleOrientation
namespace Mantid {
//----------------------------------------------------------------------
// Forward declarations
//----------------------------------------------------------------------
namespace Kernel {
class Logger;
}
namespace DataObjects {
//==========================================================================================
/** @class Mantid::DataObjects::LeanElasticPeaksWorkspace
The class LeanElasticPeaksWorkspace stores information about a set of SCD
lean peaks.
@author Ruth Mikkelson, SNS ORNL
@date 3/10/2010
*/
class MANTID_DATAOBJECTS_DLL LeanElasticPeaksWorkspace
: public Mantid::API::IPeaksWorkspace {
public:
using ColumnAndDirection = std::pair<std::string, bool>;
public:
const std::string id() const override { return "LeanElasticPeaksWorkspace"; }
LeanElasticPeaksWorkspace();
LeanElasticPeaksWorkspace &
operator=(const LeanElasticPeaksWorkspace &other) = delete;
/** Get access to shared pointer containing workspace porperties. This
function is there to provide common interface of iTableWorkspace
* Despite it is non-constant method, one should be very carefull using it to
change the log values when cloning of a table workspace can occur
as the changes may depend on the order of PeakWorkspace cloning & changes
applyed through this pointer.
* See PeakWorkspaceTest (test_getSetLogAccess) -- for example of this
behaviour.
* Use mutableRun interface to change log values rather then this method.
**/
API::LogManager_sptr logs() override;
API::LogManager_const_sptr getLogs() const override;
/// Returns a clone of the workspace
std::unique_ptr<LeanElasticPeaksWorkspace> clone() const {
return std::unique_ptr<LeanElasticPeaksWorkspace>(doClone());
}
/// Returns a default-initialized clone of the workspace
std::unique_ptr<LeanElasticPeaksWorkspace> cloneEmpty() const {
return std::unique_ptr<LeanElasticPeaksWorkspace>(doCloneEmpty());
}
void appendFile(std::string filename, Geometry::Instrument_sptr inst);
/** @return true because this type of the workspace needs custom sorting calls
*/
bool customSort() const override { return true; }
void sort(std::vector<ColumnAndDirection> &criteria) override;
int getNumberPeaks() const override;
std::string getConvention() const override;
void removePeak(int peakNum) override;
void removePeaks(std::vector<int> badPeaks) override;
void addPeak(const Geometry::IPeak &peak) override;
/// Move a peak object into this peaks workspace
void addPeak(LeanElasticPeak &&peak);
void addPeak(const Kernel::V3D &position,
const Kernel::SpecialCoordinateSystem &frame) override;
LeanElasticPeak &getPeak(int peakNum) override;
const LeanElasticPeak &getPeak(int peakNum) const override;
std::unique_ptr<Geometry::IPeak> createPeak(
const Kernel::V3D &QLabFrame,
boost::optional<double> detectorDistance = boost::none) const override;
std::unique_ptr<Geometry::IPeak>
createPeak(const Kernel::V3D &Position,
const Kernel::SpecialCoordinateSystem &frame) const override;
std::unique_ptr<Geometry::IPeak>
createPeakQSample(const Kernel::V3D &position) const override;
std::vector<std::pair<std::string, std::string>>
peakInfo(const Kernel::V3D &qFrame, bool labCoords) const override;
std::unique_ptr<Geometry::IPeak>
createPeakHKL(const Kernel::V3D &HKL) const override;
std::unique_ptr<Geometry::IPeak> createPeak() const override;
int peakInfoNumber(const Kernel::V3D &qFrame, bool labCoords) const override;
std::vector<LeanElasticPeak> &getPeaks();
const std::vector<LeanElasticPeak> &getPeaks() const;
bool hasIntegratedPeaks() const override;
size_t getMemorySize() const override;
/// Creates a new TableWorkspace giving the IDs of the detectors that
/// contribute to the
/// peaks within the workspace
API::ITableWorkspace_sptr createDetectorTable() const override;
/// Set the special coordinate system.
void setCoordinateSystem(
const Kernel::SpecialCoordinateSystem coordinateSystem) override;
/// Get the special coordinate system.
Kernel::SpecialCoordinateSystem getSpecialCoordinateSystem() const override;
// ====================================== ITableWorkspace Methods
// ==================================
/// Number of columns in the workspace.
size_t columnCount() const override {
return static_cast<int>(m_columns.size());
}
/// Number of rows in the workspace.
size_t rowCount() const override { return getNumberPeaks(); }
/// Gets the shared pointer to a column by name.
std::shared_ptr<Mantid::API::Column>
getColumn(const std::string &name) override {
return getColumn(getColumnIndex(name));
}
/// Gets the shared pointer to a column by name.
std::shared_ptr<const Mantid::API::Column>
getColumn(const std::string &name) const override {
return getColumn(getColumnIndex(name));
}
/// @return the index of the column with the given name.
virtual size_t getColumnIndex(const std::string &name) const;
/// Gets the shared pointer to a column by index.
std::shared_ptr<Mantid::API::Column> getColumn(size_t index) override;
/// Gets the shared pointer to a column by index - return none-modifyable
/// column.
API::Column_const_sptr getColumn(size_t index) const override;
// ====================================== End ITableWorkspace Methods
// ==================================
//---------------------------------------------------------------------------------------------
/// Returns a vector of all column names.
std::vector<std::string> getColumnNames() const override {
return this->m_columnNames;
}
/// This is always threadsafe
bool threadSafe() const override { return true; }
// --- Nexus Methods ---
// Save to Nexus
void saveNexus(::NeXus::File *file) const;
protected:
/// Protected copy constructor. May be used by childs for cloning.
LeanElasticPeaksWorkspace(const LeanElasticPeaksWorkspace &other);
private:
LeanElasticPeaksWorkspace *doClone() const override {
return new LeanElasticPeaksWorkspace(*this);
}
LeanElasticPeaksWorkspace *doCloneEmpty() const override {
return new LeanElasticPeaksWorkspace();
}
ITableWorkspace *
doCloneColumns(const std::vector<std::string> &colNames) const override;
/// Initialize the table structure
void initColumns();
/// Adds a new PeakColumn of the given type
void addPeakColumn(const std::string &name);
// ====================================== ITableWorkspace Methods
// ==================================
// ===== Methods that are not implemented (read-only table) ==========
API::Column_sptr addColumn(const std::string & /*type*/,
const std::string & /*name*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace structure is read-only. Cannot add column.");
}
bool addColumns(const std::string & /*type*/, const std::string & /*name*/,
size_t /*n*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace structure is read-only. Cannot add "
"columns.");
}
void removeColumn(const std::string & /*name*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace structure is read-only. Cannot remove "
"column.");
}
void setRowCount(size_t /*count*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace structure is read-only. Cannot setRowCount");
}
size_t insertRow(size_t /*index*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace structure is read-only. Cannot insertRow");
}
void removeRow(size_t /*index*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace structure is read-only. Cannot removeRow.");
}
/// find method to get the index of integer cell value in a table workspace
void find(size_t /*value*/, size_t & /*row*/,
const size_t & /*col*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace::find() not implemented.");
}
/// find method to get the index of double cell value in a table workspace
void find(double /*value*/, size_t & /*row*/,
const size_t & /*col*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace::find() not implemented.");
}
/// find method to get the index of float cell value in a table workspace
void find(float /*value*/, size_t & /*row*/,
const size_t & /*col*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace::find() not implemented.");
}
/// find method to get the index of API::Boolean value cell in a table
/// workspace
void find(API::Boolean /*value*/, size_t & /*row*/,
const size_t & /*col*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace::find() not implemented.");
}
/// find method to get the index of cellstd::string value in a table
/// workspace
void find(std::string /*value*/, size_t & /*row*/,
const size_t & /*col*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace::find() not implemented.");
}
/// find method to get the index of Mantid::Kernel::V3D cell value in a table
/// workspace
void find(Mantid::Kernel::V3D /*value*/, size_t & /*row*/,
const size_t & /*col*/) override {
throw Mantid::Kernel::Exception::NotImplementedError(
"LeanElasticPeaksWorkspace::find() not implemented.");
}
// ====================================== End ITableWorkspace Methods
// ==================================
/** Vector of Peak contained within. */
std::vector<LeanElasticPeak> m_peaks;
/** Column shared pointers. */
std::vector<std::shared_ptr<Mantid::DataObjects::PeakColumn<LeanElasticPeak>>>
m_columns;
/** Column names */
std::vector<std::string> m_columnNames;
/// Coordinates
Kernel::SpecialCoordinateSystem m_coordSystem;
};
/// Typedef for a shared pointer to a peaks workspace.
using LeanElasticPeaksWorkspace_sptr =
std::shared_ptr<LeanElasticPeaksWorkspace>;
/// Typedef for a shared pointer to a const peaks workspace.
using LeanElasticPeaksWorkspace_const_sptr =
std::shared_ptr<const LeanElasticPeaksWorkspace>;
} // namespace DataObjects
} // namespace Mantid
...@@ -35,9 +35,6 @@ namespace DataObjects { ...@@ -35,9 +35,6 @@ namespace DataObjects {
*/ */
class DLLExport Peak : public BasePeak { class DLLExport Peak : public BasePeak {
public: public:
/// Allow PeakColumn class to directly access members.
friend class PeakColumn;
Peak(); Peak();
Peak(const Geometry::Instrument_const_sptr &m_inst, Peak(const Geometry::Instrument_const_sptr &m_inst,
const Mantid::Kernel::V3D &QLabFrame, const Mantid::Kernel::V3D &QLabFrame,
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#pragma once #pragma once
#include "MantidAPI/Column.h" #include "MantidAPI/Column.h"
#include "MantidDataObjects/LeanElasticPeak.h"
#include "MantidDataObjects/Peak.h" #include "MantidDataObjects/Peak.h"
#include <boost/variant.hpp> #include <boost/variant.hpp>
...@@ -24,11 +25,11 @@ namespace DataObjects { ...@@ -24,11 +25,11 @@ namespace DataObjects {
* @author Janik Zikovsky * @author Janik Zikovsky
* @date 2011-04-25 18:06:32.952258 * @date 2011-04-25 18:06:32.952258
*/ */
class DLLExport PeakColumn : public Mantid::API::Column { template <class T> class DLLExport PeakColumn : public Mantid::API::Column {
public: public:
/// Construct a column with a reference to the peaks list, a name & type /// Construct a column with a reference to the peaks list, a name & type
PeakColumn(std::vector<Peak> &peaks, const std::string &name); PeakColumn(std::vector<T> &peaks, const std::string &name);
/// Number of individual elements in the column. /// Number of individual elements in the column.
size_t size() const override { return m_peaks.size(); } size_t size() const override { return m_peaks.size(); }
...@@ -67,7 +68,7 @@ public: ...@@ -67,7 +68,7 @@ public:
void fromDouble(size_t i, double value) override; void fromDouble(size_t i, double value) override;
/// Reference to the data. /// Reference to the data.
const std::vector<Peak> &data() const { return m_peaks; } const std::vector<T> &data() const { return m_peaks; }
bool equals(const Column &otherColumn, double tolerance) const override { bool equals(const Column &otherColumn, double tolerance) const override {
(void)otherColumn; (void)otherColumn;
...@@ -90,7 +91,7 @@ protected: ...@@ -90,7 +91,7 @@ protected:
private: private:
/// Reference to the peaks object saved in the PeaksWorkspace. /// Reference to the peaks object saved in the PeaksWorkspace.
std::vector<Peak> &m_peaks; std::vector<T> &m_peaks;
/// Precision of hkl in table workspace /// Precision of hkl in table workspace
int m_hklPrec; int m_hklPrec;
......
...@@ -73,7 +73,7 @@ public: ...@@ -73,7 +73,7 @@ public:
*/ */
bool customSort() const override { return true; } bool customSort() const override { return true; }
void sort(std::vector<std::pair<std::string, bool>> &criteria) override; void sort(std::vector<ColumnAndDirection> &criteria) override;
int getNumberPeaks() const override; int getNumberPeaks() const override;
std::string getConvention() const override; std::string getConvention() const override;
...@@ -95,12 +95,17 @@ public: ...@@ -95,12 +95,17 @@ public:
createPeak(const Kernel::V3D &Position, createPeak(const Kernel::V3D &Position,
const Kernel::SpecialCoordinateSystem &frame) const override; const Kernel::SpecialCoordinateSystem &frame) const override;
std::unique_ptr<Geometry::IPeak>
createPeakQSample(const Kernel::V3D &position) const override;
std::vector<std::pair<std::string, std::string>> std::vector<std::pair<std::string, std::string>>
peakInfo(const Kernel::V3D &qFrame, bool labCoords) const override; peakInfo(const Kernel::V3D &qFrame, bool labCoords) const override;
std::unique_ptr<Geometry::IPeak> std::unique_ptr<Geometry::IPeak>
createPeakHKL(const Kernel::V3D &HKL) const override; createPeakHKL(const Kernel::V3D &HKL) const override;
std::unique_ptr<Geometry::IPeak> createPeak() const override;
int peakInfoNumber(const Kernel::V3D &qFrame, bool labCoords) const override; int peakInfoNumber(const Kernel::V3D &qFrame, bool labCoords) const override;
std::vector<Peak> &getPeaks(); std::vector<Peak> &getPeaks();
...@@ -124,7 +129,7 @@ public: ...@@ -124,7 +129,7 @@ public:
// ================================== // ==================================
/// Number of columns in the workspace. /// Number of columns in the workspace.
size_t columnCount() const override { size_t columnCount() const override {
return static_cast<int>(columns.size()); return static_cast<int>(m_columns.size());
} }
/// Number of rows in the workspace. /// Number of rows in the workspace.
...@@ -157,7 +162,7 @@ public: ...@@ -157,7 +162,7 @@ public:
//--------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------
/// Returns a vector of all column names. /// Returns a vector of all column names.
std::vector<std::string> getColumnNames() const override { std::vector<std::string> getColumnNames() const override {
return this->columnNames; return this->m_columnNames;
} }
/// This is always threadsafe /// This is always threadsafe
bool threadSafe() const override { return true; } bool threadSafe() const override { return true; }
...@@ -180,9 +185,6 @@ private: ...@@ -180,9 +185,6 @@ private:
void initColumns(); void initColumns();
/// Adds a new PeakColumn of the given type /// Adds a new PeakColumn of the given type
void addPeakColumn(const std::string &name); void addPeakColumn(const std::string &name);
/// Create a peak from a QSample position
std::unique_ptr<Geometry::IPeak>
createPeakQSample(const Kernel::V3D &position) const;
// ====================================== ITableWorkspace Methods // ====================================== ITableWorkspace Methods
// ================================== // ==================================
...@@ -264,13 +266,13 @@ private: ...@@ -264,13 +266,13 @@ private:
// ================================== // ==================================
/** Vector of Peak contained within. */ /** Vector of Peak contained within. */
std::vector<Peak> peaks; std::vector<Peak> m_peaks;
/** Column shared pointers. */ /** Column shared pointers. */
std::vector<std::shared_ptr<Mantid::DataObjects::PeakColumn>> columns; std::vector<std::shared_ptr<Mantid::DataObjects::PeakColumn<Peak>>> m_columns;
/** Column names */ /** Column names */
std::vector<std::string> columnNames; std::vector<std::string> m_columnNames;
/// Coordinates /// Coordinates
Kernel::SpecialCoordinateSystem m_coordSystem; Kernel::SpecialCoordinateSystem m_coordSystem;
...@@ -282,4 +284,4 @@ using PeaksWorkspace_sptr = std::shared_ptr<PeaksWorkspace>; ...@@ -282,4 +284,4 @@ using PeaksWorkspace_sptr = std::shared_ptr<PeaksWorkspace>;
/// Typedef for a shared pointer to a const peaks workspace.