Commit 9e09d1ef authored by Sam Jenkins's avatar Sam Jenkins
Browse files

Re #25465 Removed owning pointer from NexusTestHelper

parent fcac3c6f
......@@ -630,14 +630,14 @@ public:
inst1->setXmlText("");
ws.setInstrument(inst1);
TS_ASSERT_THROWS_NOTHING(ws.saveExperimentInfoNexus(th.file););
TS_ASSERT_THROWS_NOTHING(ws.saveExperimentInfoNexus(th.file.get()););
// ------------------------ Re-load the contents ----------------------
ExperimentInfo ws2;
std::string parameterStr;
th.reopenFile();
TS_ASSERT_THROWS_NOTHING(
ws2.loadExperimentInfoNexus(filename, th.file, parameterStr));
ws2.loadExperimentInfoNexus(filename, th.file.get(), parameterStr));
Instrument_const_sptr inst = ws2.getInstrument();
TS_ASSERT_EQUALS(inst->getName(), "GEM");
TS_ASSERT(inst->getFilename().find("GEM_Definition.xml", 0) !=
......@@ -656,14 +656,14 @@ public:
inst1->setXmlText("");
ws.setInstrument(inst1);
TS_ASSERT_THROWS_NOTHING(ws.saveExperimentInfoNexus(th.file););
TS_ASSERT_THROWS_NOTHING(ws.saveExperimentInfoNexus(th.file.get()););
// ------------------------ Re-load the contents ----------------------
ExperimentInfo ws2;
std::string parameterStr;
th.reopenFile();
TS_ASSERT_THROWS_NOTHING(
ws2.loadExperimentInfoNexus(filename, th.file, parameterStr));
ws2.loadExperimentInfoNexus(filename, th.file.get(), parameterStr));
Instrument_const_sptr inst = ws2.getInstrument();
TS_ASSERT_EQUALS(inst->getName(), "");
TS_ASSERT_EQUALS(parameterStr, "");
......@@ -689,14 +689,14 @@ public:
// this occurs in ConvertToMD, copy methadata
ei.mutableRun().addProperty("W_MATRIX", wTrVector, true);
TS_ASSERT_THROWS_NOTHING(ei.saveExperimentInfoNexus(th.file));
TS_ASSERT_THROWS_NOTHING(ei.saveExperimentInfoNexus(.get()));
th.reopenFile();
ExperimentInfo other;
std::string InstrParameters;
TS_ASSERT_THROWS_NOTHING(
other.loadExperimentInfoNexus(filename, th.file, InstrParameters));
other.loadExperimentInfoNexus(filename, th.file.get(), InstrParameters));
std::vector<double> wMatrRestored =
other.run().getPropertyValueAsType<std::vector<double>>("W_MATRIX");
......
......@@ -484,7 +484,7 @@ public:
addTimeSeriesEntry(run1, "omega", 78.9);
addTimeSeriesEntry(run1, "proton_charge", 78.9);
run1.saveNexus(th.file, "logs");
run1.saveNexus(th.file.get(), "logs");
th.file->openGroup("logs", "NXgroup");
th.file->makeGroup("junk_to_ignore", "NXmaterial");
th.file->makeGroup("more_junk_to_ignore", "NXsample");
......@@ -492,7 +492,7 @@ public:
// ---- Now re-load the same and compare ------
th.reopenFile();
LogManager run2;
run2.loadNexus(th.file, "logs");
run2.loadNexus(th.file.get(), "logs");
TS_ASSERT(run2.hasProperty("double_series"));
TS_ASSERT(run2.hasProperty("int_val"));
TS_ASSERT(run2.hasProperty("string_val"));
......@@ -502,8 +502,8 @@ public:
// Reload without opening the group (for backwards-compatible reading of old
// files)
LogManager run3;
th.file->openGroup("logs", "NXgroup");
run3.loadNexus(th.file, "");
th.file.get()->openGroup("logs", "NXgroup");
run3.loadNexus(th.file.get(), "");
TS_ASSERT(run3.hasProperty("double_series"));
TS_ASSERT(run3.hasProperty("int_val"));
TS_ASSERT(run3.hasProperty("string_val"));
......@@ -519,7 +519,7 @@ public:
th.reopenFile();
th.file->openGroup("sample", "NXsample");
LogManager run3;
run3.loadNexus(th.file, "");
run3.loadNexus(th.file.get(), "");
}
private:
......
......@@ -246,12 +246,12 @@ public:
G.setRotationAngle("phi", 45.0);
G.setRotationAngle("chi", 23.0);
G.setRotationAngle("omega", 7.0);
G.saveNexus(th.file, "goniometer");
G.saveNexus(th.file.get(), "goniometer");
// Reload from the file
th.reopenFile();
Goniometer G2;
G2.loadNexus(th.file, "goniometer");
G2.loadNexus(th.file.get(), "goniometer");
TS_ASSERT_EQUALS(G2.getNumberAxes(), 3);
// Rotation matrices should be the same after loading
TS_ASSERT_EQUALS(G2.getR(), G.getR());
......
......@@ -53,11 +53,11 @@ public:
th.createFile("OrientedLatticeTest.nxs");
DblMatrix U(3, 3, true);
OrientedLattice u(1, 2, 3, 90, 89, 88);
u.saveNexus(th.file, "lattice");
u.saveNexus(th.file.get(), "lattice");
th.reopenFile();
OrientedLattice u2;
u2.loadNexus(th.file, "lattice");
u2.loadNexus(th.file.get(), "lattice");
// Was it reloaded correctly?
TS_ASSERT_DELTA(u2.a(), 1.0, 1e-5);
TS_ASSERT_DELTA(u2.b(), 2.0, 1e-5);
......
......@@ -134,11 +134,11 @@ public:
NexusTestHelper th(true);
th.createFile("MaterialTest.nxs");
TS_ASSERT_THROWS_NOTHING(testA.saveNexus(th.file, "material"););
TS_ASSERT_THROWS_NOTHING(testA.saveNexus(th.file.get(), "material"););
Material testB;
th.reopenFile();
TS_ASSERT_THROWS_NOTHING(testB.loadNexus(th.file, "material"););
TS_ASSERT_THROWS_NOTHING(testB.loadNexus(th.file.get(), "material"););
TS_ASSERT_EQUALS(testB.name(), "testMaterial");
TS_ASSERT_DELTA(testB.numberDensity(), 0.072, 1e-6);
......@@ -155,10 +155,10 @@ public:
Material testA;
NexusTestHelper th(true);
th.createFile("MaterialTest.nxs");
TS_ASSERT_THROWS_NOTHING(testA.saveNexus(th.file, "material"););
TS_ASSERT_THROWS_NOTHING(testA.saveNexus(th.file.get(), "material"););
Material testB;
th.reopenFile();
TS_ASSERT_THROWS_NOTHING(testB.loadNexus(th.file, "material"););
TS_ASSERT_THROWS_NOTHING(testB.loadNexus(th.file.get(), "material"););
}
void test_parseMaterial() {
......
......@@ -418,10 +418,10 @@ public:
NexusTestHelper th(true);
th.createFile("V3DTest.nxs");
V3D a(1, 2, 3);
a.saveNexus(th.file, "vector");
a.saveNexus(th.file.get(), "vector");
th.reopenFile();
V3D b;
b.loadNexus(th.file, "vector");
b.loadNexus(th.file.get(), "vector");
TS_ASSERT_EQUALS(a, b);
}
......
......@@ -234,16 +234,16 @@ protected:
// Put an 'empty' axis in to test the getAxis method
m_axes.resize(2);
m_axes[0] = new Mantid::API::RefAxis(this);
m_axes[1] = new Mantid::API::SpectraAxis(this);
m_axes[0] = std::make_unique<Mantid::API::RefAxis>(this);
m_axes[1] = std::make_unique<Mantid::API::SpectraAxis>(this);
}
void init(const Mantid::HistogramData::Histogram &histogram) override {
AxeslessWorkspaceTester::init(histogram);
// Put an 'empty' axis in to test the getAxis method
m_axes.resize(2);
m_axes[0] = new Mantid::API::RefAxis(this);
m_axes[1] = new Mantid::API::SpectraAxis(this);
m_axes[0] = std::make_unique<Mantid::API::RefAxis>(this);
m_axes[1] = std::make_unique<Mantid::API::SpectraAxis>(this);
}
private:
......
......@@ -14,6 +14,7 @@
#define MANTID_NEXUSCPP_NEXUSTESTHELPER_H_
#include <string>
#include <memory>
namespace NeXus {
class File;
......@@ -32,7 +33,7 @@ public:
void reopenFile();
/// Nexus file handle
::NeXus::File *file;
std::unique_ptr<::NeXus::File> file;
/// Created filename (full path)
std::string filename;
......
......@@ -29,7 +29,7 @@ createWorkspaceWithTextAxis(int const &numberOfSpectra,
int const &numberOfBins) {
if (static_cast<std::size_t>(numberOfSpectra) == labels.size()) {
auto workspace = createWorkspace(numberOfSpectra, numberOfBins);
workspace->replaceAxis(1, getTextAxis(numberOfSpectra, labels));
workspace->replaceAxis(1, std::unique_ptr<Axis>(getTextAxis(numberOfSpectra, labels)));
return workspace;
} else
throw std::runtime_error(
......@@ -42,7 +42,7 @@ createWorkspaceWithBinValues(int const &numberOfSpectra,
int const &numberOfBins) {
if (static_cast<std::size_t>(numberOfBins) == values.size()) {
auto workspace = createWorkspace(numberOfSpectra, numberOfBins);
workspace->replaceAxis(0, getNumericAxis(numberOfBins, values));
workspace->replaceAxis(0, std::unique_ptr<Axis>(getNumericAxis(numberOfBins, values)));
return workspace;
} else
throw std::runtime_error(
......
......@@ -13,6 +13,7 @@
#include "MantidTestHelpers/NexusTestHelper.h"
#include "MantidKernel/ConfigService.h"
#include <Poco/File.h>
#include <memory>
#if defined(_MSC_VER)
#pragma warning(push, 0)
......@@ -36,7 +37,6 @@ NexusTestHelper::~NexusTestHelper() {
if (!file)
return;
file->close();
delete file;
if (deleteFile) {
if (Poco::File(filename).exists())
Poco::File(filename).remove();
......@@ -53,7 +53,7 @@ void NexusTestHelper::createFile(std::string barefilename) {
barefilename);
if (Poco::File(filename).exists())
Poco::File(filename).remove();
file = new ::NeXus::File(filename, NXACC_CREATE5);
file = std::make_unique<::NeXus::File>(filename, NXACC_CREATE5);
file->makeGroup("test_entry", "NXentry", true);
}
......@@ -64,7 +64,6 @@ void NexusTestHelper::reopenFile() {
throw std::runtime_error(
"NexusTestHelper: you must call createFile() before reopenFile().");
file->close();
delete file;
file = new ::NeXus::File(filename, NXACC_READ);
file = std::make_unique<::NeXus::File>(filename, NXACC_READ);
file->openGroup("test_entry", "NXentry");
}
\ No newline at end of file
......@@ -183,8 +183,8 @@ Workspace2D_sptr create2DWorkspaceWhereYIsWorkspaceIndex(int nhist,
Workspace2D_sptr create2DWorkspaceThetaVsTOF(int nHist, int nBins) {
Workspace2D_sptr outputWS = create2DWorkspaceBinned(nHist, nBins);
auto const newAxis = new NumericAxis(nHist);
outputWS->replaceAxis(1, newAxis);
auto newAxis = std::make_unique<NumericAxis>(nHist);
outputWS->replaceAxis(1, std::move(newAxis));
newAxis->unit() = boost::make_shared<Units::Degrees>();
for (int i = 0; i < nHist; ++i) {
newAxis->setValue(i, i + 1);
......@@ -478,12 +478,12 @@ createEventWorkspaceWithFullInstrument(int numBanks, int numPixels,
// Set the X axes
const auto &xVals = ws->x(0);
const size_t xSize = xVals.size();
auto ax0 = new NumericAxis(xSize);
auto ax0 = std::make_unique<NumericAxis>(xSize);
ax0->setUnit("dSpacing");
for (size_t i = 0; i < xSize; i++) {
ax0->setValue(i, xVals[i]);
}
ws->replaceAxis(0, ax0);
ws->replaceAxis(0, std::move(ax0));
// re-assign detector IDs to the rectangular detector
const auto detIds = inst->getDetectorIDs();
......@@ -818,7 +818,7 @@ EventWorkspace_sptr createRandomEventWorkspace(size_t numbins, size_t numpixels,
retVal->initialize(numpixels, numbins, numbins - 1);
// and X-axis for references:
auto pAxis0 = new NumericAxis(numbins);
auto pAxis0 = std::make_unique<NumericAxis>(numbins);
// Create the original X axis to histogram on.
// Create the x-axis for histogramming.
HistogramData::BinEdges axis(numbins, LinearGenerator(0.0, bin_delta));
......@@ -841,7 +841,7 @@ EventWorkspace_sptr createRandomEventWorkspace(size_t numbins, size_t numpixels,
events.addDetectorID(detid_t(i));
}
retVal->setAllX(axis);
retVal->replaceAxis(0, pAxis0);
retVal->replaceAxis(0, std::move(pAxis0));
return retVal;
}
......@@ -990,13 +990,13 @@ createProcessedWorkspaceWithCylComplexInstrument(size_t numPixels,
Mantid::API::MatrixWorkspace_sptr ws =
createGroupedWorkspace2DWithRingsAndBoxes(rHist, 10, 0.1);
auto pAxis0 = new NumericAxis(numBins);
auto pAxis0 = std::make_unique<NumericAxis>(numBins);
for (size_t i = 0; i < numBins; i++) {
double dE = -1.0 + static_cast<double>(i) * 0.8;
pAxis0->setValue(i, dE);
}
pAxis0->setUnit("DeltaE");
ws->replaceAxis(0, pAxis0);
ws->replaceAxis(0, std::move(pAxis0));
if (has_oriented_lattice) {
auto latt = std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.);
ws->mutableSample().setOrientedLattice(latt.release());
......@@ -1063,7 +1063,7 @@ createProcessedInelasticWS(const std::vector<double> &L2,
}
// set axis, correspondent to the X-values
auto pAxis0 = new NumericAxis(numBins);
auto pAxis0 = std::make_unique<NumericAxis>(numBins);
const auto &E_transfer = ws->x(0);
for (size_t i = 0; i < numBins; i++) {
double E = 0.5 * (E_transfer[i] + E_transfer[i + 1]);
......@@ -1072,7 +1072,7 @@ createProcessedInelasticWS(const std::vector<double> &L2,
pAxis0->setUnit("DeltaE");
ws->replaceAxis(0, pAxis0);
ws->replaceAxis(0, std::move(pAxis0));
// define oriented lattice which requested for processed ws
auto latt = std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.);
......@@ -1190,8 +1190,8 @@ RebinnedOutput_sptr createRebinnedOutputWorkspace() {
HistogramData::BinEdges x1{-3.0, -2.0, -1.0, 0.0, 1.0, 2.0, 3.0};
// Create a numeric axis to replace the default vertical one
Axis *const verticalAxis = new NumericAxis(numY);
outputWS->replaceAxis(1, verticalAxis);
auto verticalAxis = std::make_unique<NumericAxis>(numY);
// Now set the axis values
for (int i = 0; i < numHist; ++i) {
......@@ -1204,6 +1204,7 @@ RebinnedOutput_sptr createRebinnedOutputWorkspace() {
// Set the 'y' axis units
verticalAxis->unit() = UnitFactory::Instance().create("MomentumTransfer");
verticalAxis->title() = "|Q|";
outputWS->replaceAxis(1, std::move(verticalAxis));
// Set the X axis title (for conversion to MD)
outputWS->getAxis(0)->title() = "Energy transfer";
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment