Mantid
Loading...
Searching...
No Matches
WorkspaceCreation.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
11#include "MantidIndexing/IndexInfo.h"
12
14HistogramData::Histogram stripData(HistogramData::Histogram histogram) {
15 histogram.setSharedY(nullptr);
16 histogram.setSharedE(nullptr);
17 return histogram;
18}
19
20template <> std::unique_ptr<EventWorkspace> createHelper() { return {nullptr}; }
21
22template <> std::unique_ptr<API::HistoWorkspace> createHelper() { return std::make_unique<Workspace2D>(); }
23
24template <> std::unique_ptr<API::MatrixWorkspace> createHelper() { return {nullptr}; }
25
26template <> std::unique_ptr<API::MatrixWorkspace> createConcreteHelper() {
27 throw std::runtime_error("Attempt to create instance of abstract type MatrixWorkspace");
28}
29template <> std::unique_ptr<API::HistoWorkspace> createConcreteHelper() {
30 throw std::runtime_error("Attempt to create instance of abstract type HistoWorkspace");
31}
32
33template <class UseIndexInfo>
35 const bool differentSize) {
36 API::WorkspaceFactory::Instance().initializeFromParent(parent, workspace, differentSize);
37}
38
48template <>
50 const bool differentSize) {
51 // Ignore flag since with IndexInfo the size is the same but we nevertheless
52 // do not want to copy some data since spectrum order or definitions may have
53 // changed. This should take care of not copying bin masks and Y axis.
54 static_cast<void>(differentSize);
55
56 const auto indexInfo = child.indexInfo();
57 API::WorkspaceFactory::Instance().initializeFromParent(parent, child, true);
58 // Restore previously set IndexInfo of child, undo changes to spectrum numbers
59 // and detector ID grouping initializeFromParent does by default. This hack is
60 // not optimal performance wise but copying data between workspaces is too
61 // complicated and dangerous currently without using initializeFromParent.
62 child.setIndexInfo(indexInfo);
63}
64
71template <class UseIndexInfo> void initializeFromParent(const API::MatrixWorkspace &parent, API::MatrixWorkspace &ws) {
72 bool differentSize = (parent.x(0).size() != ws.x(0).size()) || (parent.y(0).size() != ws.y(0).size());
73 doInitializeFromParent<UseIndexInfo>(parent, ws, differentSize);
74 // For EventWorkspace, `ws.y(0)` put entry 0 in the MRU. However, clients
75 // would typically expect an empty MRU and fail to clear it. This dummy call
76 // removes the entry from the MRU.
77 static_cast<void>(ws.mutableX(0));
78}
79
80template <> void fixDistributionFlag(API::MatrixWorkspace &workspace, const HistogramData::Histogram &histArg) {
81 workspace.setDistribution(histArg.yMode() == HistogramData::Histogram::YMode::Frequencies);
82}
83
84template void MANTID_DATAOBJECTS_DLL initializeFromParent<std::true_type>(const API::MatrixWorkspace &,
86template void MANTID_DATAOBJECTS_DLL initializeFromParent<std::false_type>(const API::MatrixWorkspace &,
88} // namespace Mantid::DataObjects::detail
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
Base MatrixWorkspace Abstract Class.
HistogramData::HistogramX & mutableX(const size_t index) &
const HistogramData::HistogramX & x(const size_t index) const
const Indexing::IndexInfo & indexInfo() const
Returns a const reference to the IndexInfo object of the workspace.
const HistogramData::HistogramY & y(const size_t index) const
void setIndexInfo(const Indexing::IndexInfo &indexInfo)
Sets the IndexInfo object of the workspace.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Factory methods for creating MatrixWorkspaces.
void doInitializeFromParent(const API::MatrixWorkspace &parent, API::MatrixWorkspace &workspace, const bool differentSize)
template void MANTID_DATAOBJECTS_DLL initializeFromParent< std::false_type >(const API::MatrixWorkspace &, API::MatrixWorkspace &)
void doInitializeFromParent< std::true_type >(const API::MatrixWorkspace &parent, API::MatrixWorkspace &child, const bool differentSize)
Same as WorkspaceFactory::initializeFromParent, with modifications for changed IndexInfo.
MANTID_DATAOBJECTS_DLL HistogramData::Histogram stripData(HistogramData::Histogram histogram)
void initializeFromParent(const API::MatrixWorkspace &parent, API::MatrixWorkspace &workspace)
Initialize a MatrixWorkspace from its parent including instrument, unit, number of spectra and Run.
std::unique_ptr< T > createHelper()
std::unique_ptr< T > createConcreteHelper()
template void MANTID_DATAOBJECTS_DLL initializeFromParent< std::true_type >(const API::MatrixWorkspace &, API::MatrixWorkspace &)
void fixDistributionFlag(API::MatrixWorkspace &, const HistArg &)