Skip to content
Snippets Groups Projects
Commit e0bc0686 authored by Antti Soininen's avatar Antti Soininen
Browse files

Fix vertical axis creation

WorkspaceCreation was failing to create a properly sized BinEdgeAxis
from a parent workspace.

Re #24355
parent 6451b471
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
// & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/BinEdgeAxis.h"
#include "MantidAPI/IPeaksWorkspace.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
......@@ -127,10 +128,12 @@ void WorkspaceFactoryImpl::initializeFromParent(
// deal with axis
for (size_t i = 0; i < parent.m_axes.size(); ++i) {
const size_t newAxisLength = child.getAxis(i)->length();
const size_t oldAxisLength = parent.getAxis(i)->length();
const bool isBinEdge =
dynamic_cast<const BinEdgeAxis *const>(parent.m_axes[i]) != nullptr;
const size_t newAxisLength = child.m_axes[i]->length() + (isBinEdge ? 1 : 0);
const size_t oldAxisLength = parent.m_axes[i]->length();
if (!differentSize || newAxisLength == oldAxisLength) {
if (!differentSize && newAxisLength == oldAxisLength) {
// Need to delete the existing axis created in init above
delete child.m_axes[i];
// Now set to a copy of the parent workspace's axis
......
......@@ -9,6 +9,7 @@
#include <cxxtest/TestSuite.h>
#include "MantidAPI/BinEdgeAxis.h"
#include "MantidAPI/Run.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/SpecialWorkspace2D.h"
......@@ -419,6 +420,30 @@ public:
check_zeroed_data(*ws);
}
void test_create_parent_numeric_vertical_axis() {
constexpr size_t parentNhist{3};
const auto parent = create<Workspace2D>(parentNhist, Histogram(Points{1}));
NumericAxis *parentAxis = new NumericAxis({-1.5, -0.5, 2.3});
parent->replaceAxis(1, parentAxis);
constexpr size_t nhist{2};
const auto ws = create<Workspace2D>(*parent, nhist, parent->histogram(0));
auto axis = ws->getAxis(1);
TS_ASSERT_DIFFERS(dynamic_cast<NumericAxis *>(axis), nullptr)
TS_ASSERT_EQUALS(axis->length(), nhist);
}
void test_create_parent_bin_edge_vertical_axis() {
constexpr size_t parentNhist{3};
const auto parent = create<Workspace2D>(parentNhist, Histogram(Points{1}));
BinEdgeAxis *parentAxis = new BinEdgeAxis({-1.5, -0.5, 2.3, 3.4});
parent->replaceAxis(1, parentAxis);
constexpr size_t nhist{2};
const auto ws = create<Workspace2D>(*parent, nhist, parent->histogram(0));
auto axis = ws->getAxis(1);
TS_ASSERT_DIFFERS(dynamic_cast<BinEdgeAxis *>(axis), nullptr)
TS_ASSERT_EQUALS(axis->length(), nhist + 1);
}
void test_create_drop_events() {
auto eventWS = create<EventWorkspace>(1, Histogram(BinEdges(3)));
auto ws = create<HistoWorkspace>(*eventWS);
......
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