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:
createPeak(const Mantid::Kernel::V3D &position,
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
* @param HKL V3D
......@@ -126,6 +134,12 @@ public:
virtual std::unique_ptr<Geometry::IPeak>
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
* algorithm.
......
......@@ -38,6 +38,7 @@ set(SRC_FILES
src/PeakShapeSpherical.cpp
src/PeakShapeSphericalFactory.cpp
src/PeaksWorkspace.cpp
src/LeanElasticPeaksWorkspace.cpp
src/PropertyWithValue.cpp
src/RebinnedOutput.cpp
src/ReflectometryTransform.cpp
......@@ -121,6 +122,7 @@ set(INC_FILES
inc/MantidDataObjects/PeakShapeSpherical.h
inc/MantidDataObjects/PeakShapeSphericalFactory.h
inc/MantidDataObjects/PeaksWorkspace.h
inc/MantidDataObjects/LeanElasticPeaksWorkspace.h
inc/MantidDataObjects/RebinnedOutput.h
inc/MantidDataObjects/ReflectometryTransform.h
inc/MantidDataObjects/ScanningWorkspaceBuilder.h
......@@ -181,6 +183,7 @@ set(TEST_FILES
PeakTest.h
LeanElasticPeakTest.h
PeaksWorkspaceTest.h
LeanElasticPeaksWorkspaceTest.h
RebinnedOutputTest.h
RefAxisTest.h
ReflectometryTransformTest.h
......
......@@ -32,9 +32,6 @@ namespace DataObjects {
*/
class DLLExport BasePeak : public Geometry::IPeak {
public:
/// Allow PeakColumn class to directly access members.
friend class PeakColumn;
BasePeak();
BasePeak(const Mantid::Kernel::Matrix<double> &goniometer);
/// Copy constructor
......
......@@ -30,9 +30,6 @@ namespace DataObjects {
*/
class DLLExport LeanElasticPeak : public BasePeak {
public:
/// Allow PeakColumn class to directly access members.
friend class PeakColumn;
LeanElasticPeak();
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 {
*/
class DLLExport Peak : public BasePeak {
public:
/// Allow PeakColumn class to directly access members.
friend class PeakColumn;
Peak();
Peak(const Geometry::Instrument_const_sptr &m_inst,
const Mantid::Kernel::V3D &QLabFrame,
......
......@@ -7,6 +7,7 @@
#pragma once
#include "MantidAPI/Column.h"
#include "MantidDataObjects/LeanElasticPeak.h"
#include "MantidDataObjects/Peak.h"
#include <boost/variant.hpp>
......@@ -24,11 +25,11 @@ namespace DataObjects {
* @author Janik Zikovsky
* @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:
/// 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.
size_t size() const override { return m_peaks.size(); }
......@@ -67,7 +68,7 @@ public:
void fromDouble(size_t i, double value) override;
/// 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 {
(void)otherColumn;
......@@ -90,7 +91,7 @@ protected:
private:
/// 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
int m_hklPrec;
......
......@@ -73,7 +73,7 @@ public:
*/
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;
std::string getConvention() const override;
......@@ -95,12 +95,17 @@ public:
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<Peak> &getPeaks();
......@@ -124,7 +129,7 @@ public:
// ==================================
/// Number of columns in the workspace.
size_t columnCount() const override {
return static_cast<int>(columns.size());
return static_cast<int>(m_columns.size());
}
/// Number of rows in the workspace.
......@@ -157,7 +162,7 @@ public:
//---------------------------------------------------------------------------------------------
/// Returns a vector of all column names.
std::vector<std::string> getColumnNames() const override {
return this->columnNames;
return this->m_columnNames;
}
/// This is always threadsafe
bool threadSafe() const override { return true; }
......@@ -180,9 +185,6 @@ private:
void initColumns();
/// Adds a new PeakColumn of the given type
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
// ==================================
......@@ -264,13 +266,13 @@ private:
// ==================================
/** Vector of Peak contained within. */
std::vector<Peak> peaks;
std::vector<Peak> m_peaks;
/** 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 */
std::vector<std::string> columnNames;
std::vector<std::string> m_columnNames;
/// Coordinates
Kernel::SpecialCoordinateSystem m_coordSystem;
......@@ -282,4 +284,4 @@ using PeaksWorkspace_sptr = std::shared_ptr<PeaksWorkspace>;
/// Typedef for a shared pointer to a const peaks workspace.
using PeaksWorkspace_const_sptr = std::shared_ptr<const PeaksWorkspace>;
} // namespace DataObjects
} // namespace Mantid
\ No newline at end of file
} // namespace Mantid
......@@ -112,7 +112,10 @@ void LeanElasticPeak::setDetectorID(int) {
//----------------------------------------------------------------------------------------------
/** Get the ID of the detector at the center of the peak */
int LeanElasticPeak::getDetectorID() const { return -1; }
int LeanElasticPeak::getDetectorID() const {
throw Exception::NotImplementedError(
"LeanElasticPeak::getDetectorID(): no detector ID on LeanElasticPeak");
}
//----------------------------------------------------------------------------------------------
/** Set the instrument (and save the source/sample pos).
......@@ -161,7 +164,8 @@ double LeanElasticPeak::getWavelength() const { return m_wavelength; }
* peak,
* using the geometry of the detector */
double LeanElasticPeak::getTOF() const {
return std::numeric_limits<double>::quiet_NaN();
throw Exception::NotImplementedError(
"LeanElasticPeak::getTOF(): no detector infomation in LeanElasticPeak");
}
// -------------------------------------------------------------------------------------
......
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright &copy; 2018 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 +
#include "MantidDataObjects/LeanElasticPeaksWorkspace.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidGeometry/Crystal/OrientedLattice.h"
#include "MantidGeometry/Instrument/Goniometer.h"
#include "MantidKernel/IPropertyManager.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/UnitConversion.h"
// clang-format off
#include <nexus/NeXusFile.hpp>
#include <nexus/NeXusException.hpp>
// clang-format on
#include <cmath>
using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::Geometry;
namespace Mantid {
namespace DataObjects {
/// Register the workspace as a type
DECLARE_WORKSPACE(LeanElasticPeaksWorkspace)
//---------------------------------------------------------------------------------------------
/** Constructor. Create a table with all the required columns.
*
* @return LeanElasticPeaksWorkspace object
*/
LeanElasticPeaksWorkspace::LeanElasticPeaksWorkspace()
: IPeaksWorkspace(), m_peaks(), m_columns(), m_columnNames(),
m_coordSystem(None) {
initColumns();
// LeanElasticPeaksWorkspace does not use the grouping mechanism of
// ExperimentInfo.
setNumberOfDetectorGroups(0);
}
//---------------------------------------------------------------------------------------------
/** Copy constructor
*
* @param other :: other LeanElasticPeaksWorkspace to copy from
*/
LeanElasticPeaksWorkspace::LeanElasticPeaksWorkspace(
const LeanElasticPeaksWorkspace &other)
: IPeaksWorkspace(other), m_peaks(other.m_peaks), m_columns(),
m_columnNames(), m_coordSystem(other.m_coordSystem) {
initColumns();
// LeanElasticPeaksWorkspace does not use the grouping mechanism of
// ExperimentInfo.
setNumberOfDetectorGroups(0);
}
/** Comparator class for sorting peaks by one or more criteria
*/
class PeakComparator {
public:
using ColumnAndDirection = LeanElasticPeaksWorkspace::ColumnAndDirection;
std::vector<ColumnAndDirection> &criteria;
/** Constructor for the comparator for sorting peaks
* @param criteria : a vector with a list of pairs: column name, bool;