From 424fc625647993efc02fadcecf56f62b2d743a7f Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@gmail.com> Date: Tue, 26 Nov 2019 15:24:46 +0000 Subject: [PATCH] Accept OrientedLattice by unique_ptr The overwhelming use case for this method is to take ownership of a lattice object into Sample. Using unique_ptr clarifies that this is happening at the call site and forces a caller to make copy if that is truly the desired behaviour. The old code make a copy internally but this was not obvious from the method call. --- Framework/API/inc/MantidAPI/Sample.h | 8 +-- Framework/API/src/Sample.cpp | 10 ++-- Framework/API/test/ExperimentInfoTest.h | 12 ++-- Framework/API/test/MatrixWorkspaceTest.h | 5 +- .../API/test/MultipleExperimentInfosTest.h | 7 +-- .../API/test/OrientedLatticeValidatorTest.h | 4 +- Framework/API/test/SampleTest.h | 53 ++++++++--------- Framework/Algorithms/src/CopySample.cpp | 7 ++- Framework/Algorithms/test/CopySampleTest.h | 10 ++-- Framework/Crystal/src/CalculateUMatrix.cpp | 8 +-- Framework/Crystal/src/FindUBUsingFFT.cpp | 14 ++--- .../Crystal/src/FindUBUsingIndexedPeaks.cpp | 20 +++---- .../src/FindUBUsingLatticeParameters.cpp | 22 +++---- Framework/Crystal/src/FindUBUsingMinMaxD.cpp | 14 ++--- .../src/GoniometerAnglesFromPhiRotation.cpp | 16 +++--- Framework/Crystal/src/LoadIsawUB.cpp | 10 ++-- .../src/OptimizeLatticeForCellType.cpp | 25 ++++---- .../Crystal/src/PredictSatellitePeaks.cpp | 57 +++++++++---------- Framework/Crystal/src/SelectCellOfType.cpp | 17 +++--- Framework/Crystal/src/SelectCellWithForm.cpp | 17 +++--- Framework/Crystal/src/SetUB.cpp | 24 ++++---- Framework/Crystal/src/TransformHKL.cpp | 3 +- Framework/Crystal/test/AddPeakHKLTest.h | 7 +-- .../Crystal/test/CalculatePeaksHKLTest.h | 17 ++---- Framework/Crystal/test/ClearUBTest.h | 11 ++-- Framework/Crystal/test/HasUBTest.h | 13 ++--- Framework/Crystal/test/IndexPeaksTest.h | 20 +++---- Framework/Crystal/test/SelectCellOfTypeTest.h | 8 +-- .../Crystal/test/SelectCellWithFormTest.h | 8 +-- .../Crystal/test/ShowPossibleCellsTest.h | 8 +-- Framework/Crystal/test/SortHKLTest.h | 4 +- .../test/StatisticsOfPeaksWorkspaceTest.h | 4 +- Framework/Crystal/test/TransformHKLTest.h | 6 +- .../DataObjects/test/PeaksWorkspaceTest.h | 4 +- .../test/WorkspaceValidatorsTest.h | 3 +- Framework/MDAlgorithms/src/LoadSQW.cpp | 5 +- Framework/MDAlgorithms/src/LoadSQW2.cpp | 3 +- .../test/CalculateCoverageDGSTest.h | 4 +- .../test/ConvertToMDMinMaxGlobalTest.h | 4 +- .../test/ConvertToMDMinMaxLocalTest.h | 5 +- .../MDAlgorithms/test/ConvertToQ3DdETest.h | 49 +++++----------- Framework/MDAlgorithms/test/CutMDTest.h | 5 +- .../test/IntegrateEllipsoidsTest.h | 6 +- .../IntegrateEllipsoidsWithSatellitesTest.h | 18 +++--- Framework/MDAlgorithms/test/MDWSTransfTest.h | 28 ++++----- .../SingleCrystalDiffractionTestHelper.cpp | 6 +- .../src/WorkspaceCreationHelper.cpp | 16 +++--- .../src/InstrumentWidgetPickTab.cpp | 4 +- 48 files changed, 294 insertions(+), 335 deletions(-) diff --git a/Framework/API/inc/MantidAPI/Sample.h b/Framework/API/inc/MantidAPI/Sample.h index 178d4af1c78..38eac2a75d2 100644 --- a/Framework/API/inc/MantidAPI/Sample.h +++ b/Framework/API/inc/MantidAPI/Sample.h @@ -78,11 +78,9 @@ public: const Geometry::OrientedLattice &getOrientedLattice() const; /// Get a reference to the sample's OrientedLattice Geometry::OrientedLattice &getOrientedLattice(); - /** Set the pointer to OrientedLattice defining the sample's lattice and - orientation. - No copying is done in the class, but the class deletes pointer on - destruction so the application, providing the pointer should not do it*/ - void setOrientedLattice(Geometry::OrientedLattice *latt); + /// Set the pointer to OrientedLattice defining the sample's lattice and + /// orientation + void setOrientedLattice(std::unique_ptr<Geometry::OrientedLattice> lattice); bool hasOrientedLattice() const; //@} diff --git a/Framework/API/src/Sample.cpp b/Framework/API/src/Sample.cpp index 2de319fb526..472507f8265 100644 --- a/Framework/API/src/Sample.cpp +++ b/Framework/API/src/Sample.cpp @@ -173,13 +173,11 @@ OrientedLattice &Sample::getOrientedLattice() { /** Attach an OrientedLattice onto this sample * - * @param latt :: A pointer to a OrientedLattice. + * @param lattice :: A pointer to a OrientedLattice. */ -void Sample::setOrientedLattice(OrientedLattice *latt) { - if (latt != nullptr) - m_lattice = std::make_unique<OrientedLattice>(*latt); - else - m_lattice.reset(nullptr); +void Sample::setOrientedLattice( + std::unique_ptr<Geometry::OrientedLattice> lattice) { + m_lattice = std::move(lattice); } /** @return true if the sample has an OrientedLattice */ diff --git a/Framework/API/test/ExperimentInfoTest.h b/Framework/API/test/ExperimentInfoTest.h index 6f2e66911e2..b85cfc85c29 100644 --- a/Framework/API/test/ExperimentInfoTest.h +++ b/Framework/API/test/ExperimentInfoTest.h @@ -210,8 +210,8 @@ public: ExperimentInfo ws; ws.mutableRun().setProtonCharge(1.234); ws.mutableSample().setName("test"); - OrientedLattice latt(1, 2, 3, 90, 90, 90); - ws.mutableSample().setOrientedLattice(&latt); + ws.mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 2, 3, 90, 90, 90)); boost::shared_ptr<Instrument> inst1 = boost::make_shared<Instrument>(); inst1->setName("MyTestInst"); ws.setInstrument(inst1); @@ -225,8 +225,8 @@ public: ExperimentInfo ws; ws.mutableRun().setProtonCharge(1.234); ws.mutableSample().setName("test"); - OrientedLattice latt(1, 2, 3, 90, 90, 90); - ws.mutableSample().setOrientedLattice(&latt); + ws.mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 2, 3, 90, 90, 90)); boost::shared_ptr<Instrument> inst1 = boost::make_shared<Instrument>(); inst1->setName("MyTestInst"); ws.setInstrument(inst1); @@ -240,8 +240,8 @@ public: ExperimentInfo ws; ws.mutableRun().setProtonCharge(1.234); ws.mutableSample().setName("test"); - OrientedLattice latt(1, 2, 3, 90, 90, 90); - ws.mutableSample().setOrientedLattice(&latt); + ws.mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 2, 3, 90, 90, 90)); boost::shared_ptr<Instrument> inst1 = boost::make_shared<Instrument>(); inst1->setName("MyTestInst"); ws.setInstrument(inst1); diff --git a/Framework/API/test/MatrixWorkspaceTest.h b/Framework/API/test/MatrixWorkspaceTest.h index 069b4742d73..26918b99e08 100644 --- a/Framework/API/test/MatrixWorkspaceTest.h +++ b/Framework/API/test/MatrixWorkspaceTest.h @@ -2377,9 +2377,8 @@ public: ws->hasOrientedLattice(), false); // add an oriented lattice - OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - ws->mutableSample().setOrientedLattice(latt); - delete latt; + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); TSM_ASSERT_EQUALS("A workspace with an oriented lattice should report true", ws->hasOrientedLattice(), true); diff --git a/Framework/API/test/MultipleExperimentInfosTest.h b/Framework/API/test/MultipleExperimentInfosTest.h index 27f7c932be7..dd2f295385d 100644 --- a/Framework/API/test/MultipleExperimentInfosTest.h +++ b/Framework/API/test/MultipleExperimentInfosTest.h @@ -51,13 +51,12 @@ public: MultipleExperimentInfos mei; TS_ASSERT_EQUALS(mei.hasOrientedLattice(), false); - OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - // add some oriented lattices to the multiple experiment info for (uint16_t i = 0; i < nExperimentInfosToAdd; ++i) { ExperimentInfo_sptr experimentInfo = boost::make_shared<ExperimentInfo>(); mei.addExperimentInfo(experimentInfo); - mei.getExperimentInfo(i)->mutableSample().setOrientedLattice(latt); + mei.getExperimentInfo(i)->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); TS_ASSERT_EQUALS(mei.hasOrientedLattice(), true); } @@ -72,8 +71,6 @@ public: ->mutableSample() .clearOrientedLattice(); TS_ASSERT_EQUALS(mei.hasOrientedLattice(), false); - - delete latt; } }; diff --git a/Framework/API/test/OrientedLatticeValidatorTest.h b/Framework/API/test/OrientedLatticeValidatorTest.h index e1ea0e364e4..51ee7075625 100644 --- a/Framework/API/test/OrientedLatticeValidatorTest.h +++ b/Framework/API/test/OrientedLatticeValidatorTest.h @@ -33,9 +33,9 @@ public: } void test_isValid_is_valid_when_latticeDefined() { - OrientedLattice lattice; auto info = boost::make_shared<ExperimentInfo>(); - info->mutableSample().setOrientedLattice(&lattice); + info->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>()); OrientedLatticeValidator validator; TS_ASSERT_EQUALS(validator.isValid(info), ""); diff --git a/Framework/API/test/SampleTest.h b/Framework/API/test/SampleTest.h index 7fb28f51c45..1885279be63 100644 --- a/Framework/API/test/SampleTest.h +++ b/Framework/API/test/SampleTest.h @@ -76,26 +76,23 @@ public: void test_OrientedLattice() { Sample sample; - OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - - TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice(latt)); + auto lattice = std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90); + auto latticeAddress = lattice.get(); + TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice(std::move(lattice))); const OrientedLattice &retLatt = sample.getOrientedLattice(); - // Test that this references the correct object - // TS_ASSERT_EQUALS(&retLatt, latt);//This is no longer correct. - // setOrientedLattice makes a copy of the OrientedLattice object - TS_ASSERT_EQUALS(retLatt.a(), 1.0); + // Test that this takes ownership of the lattice + TS_ASSERT_EQUALS(&retLatt, latticeAddress); TS_ASSERT_EQUALS(retLatt.b(), 2.0); TS_ASSERT_EQUALS(retLatt.c(), 3.0); - delete latt; } void test_OrientedLattice_and_theCopyconstructor() { Sample sample; - // const std::string envName("TestKit"); - OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); + auto lattice = std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90); + auto latticeAddress = lattice.get(); - TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice(latt)); + TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice(std::move(lattice))); // Copy constructor Sample sample2(sample); @@ -111,17 +108,16 @@ public: const OrientedLattice &retLatt = sample2.getOrientedLattice(); // The copy does NOT refer to the same object - TS_ASSERT_DIFFERS(&retLatt, latt); + TS_ASSERT_DIFFERS(&retLatt, latticeAddress); TS_ASSERT_EQUALS(retLatt.a(), 1.0); TS_ASSERT_EQUALS(retLatt.b(), 2.0); TS_ASSERT_EQUALS(retLatt.c(), 3.0); - delete latt; } void test_clearOrientedLattice() { Sample sample; - OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice(latt)); + TS_ASSERT_THROWS_NOTHING(sample.setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90))); TS_ASSERT(sample.hasOrientedLattice()) TS_ASSERT_THROWS_NOTHING(sample.getOrientedLattice()) @@ -131,14 +127,13 @@ public: TS_ASSERT(!sample.hasOrientedLattice()) TS_ASSERT_THROWS(sample.getOrientedLattice(), std::runtime_error &) - delete latt; } void test_clearOrientedLattice_and_the_copy_constructor() { // Create a sample with an oriented lattice. Sample sampleA; - OrientedLattice *latticeA = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - TS_ASSERT_THROWS_NOTHING(sampleA.setOrientedLattice(latticeA)); + TS_ASSERT_THROWS_NOTHING(sampleA.setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90))); // Copy the sample. Sample sampleB(sampleA); @@ -154,7 +149,7 @@ public: // One should be cleared, the other should not. TS_ASSERT(!sampleA.hasOrientedLattice()) - TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error &) + TS_ASSERT_THROWS(sampleA.getOrientedLattice(), const std::runtime_error &) TS_ASSERT(sampleB.hasOrientedLattice()) TS_ASSERT_THROWS_NOTHING(sampleB.getOrientedLattice()) @@ -165,17 +160,16 @@ public: // Both should be cleared. TS_ASSERT(!sampleA.hasOrientedLattice()) - TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error &) + TS_ASSERT_THROWS(sampleA.getOrientedLattice(), const std::runtime_error &) TS_ASSERT(!sampleB.hasOrientedLattice()) - TS_ASSERT_THROWS(sampleB.getOrientedLattice(), std::runtime_error &) - delete latticeA; + TS_ASSERT_THROWS(sampleB.getOrientedLattice(), const std::runtime_error &) } void test_clearOrientedLattice_and_assignment() { // Create a sample with an oriented lattice. Sample sampleA; - OrientedLattice *latticeA = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - TS_ASSERT_THROWS_NOTHING(sampleA.setOrientedLattice(latticeA)); + TS_ASSERT_THROWS_NOTHING(sampleA.setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90))); // Create and then assign to the sample. Sample sampleB; @@ -192,7 +186,7 @@ public: // One should be cleared, the other should not. TS_ASSERT(!sampleA.hasOrientedLattice()) - TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error &) + TS_ASSERT_THROWS(sampleA.getOrientedLattice(), const std::runtime_error &) TS_ASSERT(sampleB.hasOrientedLattice()) TS_ASSERT_THROWS_NOTHING(sampleB.getOrientedLattice()) @@ -203,10 +197,9 @@ public: // Both should be cleared. TS_ASSERT(!sampleA.hasOrientedLattice()) - TS_ASSERT_THROWS(sampleA.getOrientedLattice(), std::runtime_error &) + TS_ASSERT_THROWS(sampleA.getOrientedLattice(), const std::runtime_error &) TS_ASSERT(!sampleB.hasOrientedLattice()) - TS_ASSERT_THROWS(sampleB.getOrientedLattice(), std::runtime_error &) - delete latticeA; + TS_ASSERT_THROWS(sampleB.getOrientedLattice(), const std::runtime_error &) } void test_setCrystalStructure() { @@ -322,8 +315,8 @@ public: sample.setShape(shape_sptr); sample.setName("NameOfASample"); sample.setWidth(1.234); - OrientedLattice latt(4, 5, 6, 90, 91, 92); - sample.setOrientedLattice(&latt); + sample.setOrientedLattice( + std::make_unique<OrientedLattice>(4, 5, 6, 90, 91, 92)); auto sample2 = boost::make_shared<Sample>(); sample2->setName("test name for test_Multiple_Sample - 2"); sample.addSample(sample2); diff --git a/Framework/Algorithms/src/CopySample.cpp b/Framework/Algorithms/src/CopySample.cpp index f4da37a2d81..76dd0cc31ee 100644 --- a/Framework/Algorithms/src/CopySample.cpp +++ b/Framework/Algorithms/src/CopySample.cpp @@ -10,7 +10,7 @@ #include "MantidGeometry/Instrument/SampleEnvironment.h" #include "MantidKernel/EnabledWhenProperty.h" #include "MantidKernel/Material.h" -#include "MantidKernel/System.h" + namespace Mantid { namespace Algorithms { @@ -20,6 +20,7 @@ DECLARE_ALGORITHM(CopySample) using namespace Mantid::API; using namespace Mantid::Kernel; using Geometry::IObject; +using Geometry::OrientedLattice; using Geometry::SampleEnvironment; //---------------------------------------------------------------------------------------------- @@ -196,7 +197,9 @@ void CopySample::copyParameters(Sample &from, Sample &to, bool nameFlag, if (to.hasOrientedLattice() && orientationOnlyFlag) { to.getOrientedLattice().setU(from.getOrientedLattice().getU()); } else { - to.setOrientedLattice(&from.getOrientedLattice()); + // copy over + to.setOrientedLattice( + std::make_unique<OrientedLattice>(from.getOrientedLattice())); } } } diff --git a/Framework/Algorithms/test/CopySampleTest.h b/Framework/Algorithms/test/CopySampleTest.h index a3b3b6e50c2..601d62f85aa 100644 --- a/Framework/Algorithms/test/CopySampleTest.h +++ b/Framework/Algorithms/test/CopySampleTest.h @@ -51,9 +51,8 @@ public: envName, boost::make_shared<Container>(ShapeFactory().createShape(canShape))); sample.setEnvironment(std::move(kit)); - OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - sample.setOrientedLattice(latt); - delete latt; + sample.setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); auto shape_sptr = ComponentCreationHelper::createCappedCylinder( 0.0127, 1.0, V3D(), V3D(0.0, 1.0, 0.0), "cyl"); shape_sptr->setMaterial(Material( @@ -238,9 +237,8 @@ public: ExperimentInfo_sptr ei1(new ExperimentInfo); Sample s = createsample(); Sample s1; - OrientedLattice *latt = new OrientedLattice(6.0, 7.0, 8.0, 90, 90, 90); - s1.setOrientedLattice(latt); - delete latt; + s1.setOrientedLattice( + std::make_unique<OrientedLattice>(6.0, 7.0, 8.0, 90, 90, 90)); s1.setName("newsample"); ei->mutableSample() = s; TS_ASSERT_EQUALS(ew->addExperimentInfo(ei), 0); diff --git a/Framework/Crystal/src/CalculateUMatrix.cpp b/Framework/Crystal/src/CalculateUMatrix.cpp index 90323c0f5c7..2608453ac2b 100644 --- a/Framework/Crystal/src/CalculateUMatrix.cpp +++ b/Framework/Crystal/src/CalculateUMatrix.cpp @@ -56,8 +56,8 @@ void CalculateUMatrix::exec() { double alpha = this->getProperty("alpha"); double beta = this->getProperty("beta"); double gamma = this->getProperty("gamma"); - OrientedLattice o(a, b, c, alpha, beta, gamma); - Matrix<double> B = o.getB(); + auto lattice = std::make_unique<OrientedLattice>(a, b, c, alpha, beta, gamma); + Matrix<double> B = lattice->getB(); PeaksWorkspace_sptr ws = this->getProperty("PeaksWorkspace"); if (!ws) @@ -135,9 +135,9 @@ void CalculateUMatrix::exec() { Eval[0][0], Eval[1][0], Eval[2][0], Eval[3][0]); // the first column corresponds to the highest eigenvalue DblMatrix U(qR.getRotation()); - o.setU(U); + lattice->setU(U); - ws->mutableSample().setOrientedLattice(&o); + ws->mutableSample().setOrientedLattice(std::move(lattice)); } } // namespace Crystal diff --git a/Framework/Crystal/src/FindUBUsingFFT.cpp b/Framework/Crystal/src/FindUBUsingFFT.cpp index d0fc7f3eb55..960b5591ea8 100644 --- a/Framework/Crystal/src/FindUBUsingFFT.cpp +++ b/Framework/Crystal/src/FindUBUsingFFT.cpp @@ -102,15 +102,13 @@ void FindUBUsingFFT::exec() { << n_peaks << " with tolerance of " << std::setprecision(3) << std::setw(5) << tolerance << "\n"; - OrientedLattice o_lattice; - o_lattice.setUB(UB); - o_lattice.setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], - sigabc[5]); - + auto lattice = std::make_unique<OrientedLattice>(); + lattice->setUB(UB); + lattice->setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], + sigabc[5]); // Show the modified lattice parameters - g_log.notice() << o_lattice << "\n"; - - ws->mutableSample().setOrientedLattice(&o_lattice); + g_log.notice() << *lattice << "\n"; + ws->mutableSample().setOrientedLattice(std::move(lattice)); } } diff --git a/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp b/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp index 0b4a621d2ee..94e156ea140 100644 --- a/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp +++ b/Framework/Crystal/src/FindUBUsingIndexedPeaks.cpp @@ -195,22 +195,22 @@ void FindUBUsingIndexedPeaks::exec() { << satetolerance << " ,out of " << n_peaks << " Peaks \n"; g_log.notice(stream.str()); - OrientedLattice o_lattice; - o_lattice.setUB(UB); - o_lattice.setModUB(modUB); - o_lattice.setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], - sigabc[5]); + auto o_lattice = std::make_unique<OrientedLattice>(); + o_lattice->setUB(UB); + o_lattice->setModUB(modUB); + o_lattice->setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], + sigabc[5]); double ind_count_inv = 1. / static_cast<double>(indexed_count); errorHKL *= ind_count_inv; - o_lattice.setErrorModHKL(errorHKL); + o_lattice->setErrorModHKL(errorHKL); - o_lattice.setMaxOrder(MaxOrder); - o_lattice.setCrossTerm(CrossTerm); + o_lattice->setMaxOrder(MaxOrder); + o_lattice->setCrossTerm(CrossTerm); // Show the modified lattice parameters - logLattice(o_lattice, ModDim); + logLattice(*o_lattice, ModDim); - ws->mutableSample().setOrientedLattice(&o_lattice); + ws->mutableSample().setOrientedLattice(std::move(o_lattice)); } } void FindUBUsingIndexedPeaks::logLattice(OrientedLattice &o_lattice, diff --git a/Framework/Crystal/src/FindUBUsingLatticeParameters.cpp b/Framework/Crystal/src/FindUBUsingLatticeParameters.cpp index 297baea5c70..90d7c77fb7e 100644 --- a/Framework/Crystal/src/FindUBUsingLatticeParameters.cpp +++ b/Framework/Crystal/src/FindUBUsingLatticeParameters.cpp @@ -78,13 +78,13 @@ void FindUBUsingLatticeParameters::exec() { if (!ws) throw std::runtime_error("Could not read the peaks workspace"); - std::vector<Peak> &peaks = ws->getPeaks(); - size_t n_peaks = ws->getNumberPeaks(); + const std::vector<Peak> &peaks = ws->getPeaks(); + const int n_peaks = ws->getNumberPeaks(); std::vector<V3D> q_vectors; q_vectors.reserve(n_peaks); - for (size_t i = 0; i < n_peaks; i++) + for (int i = 0; i < n_peaks; i++) q_vectors.emplace_back(peaks[i].getQSampleFrame()); Matrix<double> UB(3, 3, false); @@ -104,11 +104,11 @@ void FindUBUsingLatticeParameters::exec() { } else // tell user how many would be indexed { // and save the UB in the sample char logInfo[200]; - int num_indexed = IndexingUtils::NumberIndexed(UB, q_vectors, tolerance); + const int num_indexed = + IndexingUtils::NumberIndexed(UB, q_vectors, tolerance); sprintf(logInfo, - std::string( - "New UB will index %1d Peaks out of %1d with tolerance %5.3f") - .c_str(), + "New UB will index %1d Peaks out of %1d with tolerance " + "%5.3f", num_indexed, n_peaks, tolerance); g_log.notice(std::string(logInfo)); @@ -122,13 +122,13 @@ void FindUBUsingLatticeParameters::exec() { g_log.notice() << lattice << "\n"; sprintf(logInfo, - std::string("Lattice Parameters (Refined - Input): %11.6f " - "%11.6f %11.6f %11.6f %11.6f %11.6f") - .c_str(), + "Lattice Parameters (Refined - Input): %11.6f " + "%11.6f %11.6f %11.6f %11.6f %11.6f", calc_a - a, calc_b - b, calc_c - c, calc_alpha - alpha, calc_beta - beta, calc_gamma - gamma); g_log.notice(std::string(logInfo)); - ws->mutableSample().setOrientedLattice(&lattice); + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(lattice)); } } diff --git a/Framework/Crystal/src/FindUBUsingMinMaxD.cpp b/Framework/Crystal/src/FindUBUsingMinMaxD.cpp index 64d19446ee2..31fbde2970e 100644 --- a/Framework/Crystal/src/FindUBUsingMinMaxD.cpp +++ b/Framework/Crystal/src/FindUBUsingMinMaxD.cpp @@ -130,15 +130,13 @@ void FindUBUsingMinMaxD::exec() { num_indexed, n_peaks, tolerance); g_log.notice(std::string(logInfo)); - OrientedLattice o_lattice; - o_lattice.setUB(UB); - o_lattice.setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], - sigabc[5]); - + auto lattice = std::make_unique<OrientedLattice>(); + lattice->setUB(UB); + lattice->setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], + sigabc[5]); // Show the modified lattice parameters - g_log.notice() << o_lattice << "\n"; - - ws->mutableSample().setOrientedLattice(&o_lattice); + g_log.notice() << *lattice << "\n"; + ws->mutableSample().setOrientedLattice(std::move(lattice)); } } diff --git a/Framework/Crystal/src/GoniometerAnglesFromPhiRotation.cpp b/Framework/Crystal/src/GoniometerAnglesFromPhiRotation.cpp index 6ac8127857d..be21a867c7a 100644 --- a/Framework/Crystal/src/GoniometerAnglesFromPhiRotation.cpp +++ b/Framework/Crystal/src/GoniometerAnglesFromPhiRotation.cpp @@ -190,10 +190,10 @@ void GoniometerAnglesFromPhiRotation::exec() { //---------------------------------------------- - Geometry::OrientedLattice lat2 = PeaksRun1->sample().getOrientedLattice(); - - lat2.setUB(UB1); - PeaksRun2->mutableSample().setOrientedLattice(&lat2); + auto lat2 = std::make_unique<OrientedLattice>( + PeaksRun1->sample().getOrientedLattice()); + lat2->setUB(UB1); + PeaksRun2->mutableSample().setOrientedLattice(std::move(lat2)); if (!Run1HasOrientedLattice) PeaksRun1->mutableSample().setOrientedLattice(nullptr); @@ -366,13 +366,13 @@ void GoniometerAnglesFromPhiRotation::exec() { PeaksRun2->getPeak(i).setGoniometerMatrix(Gon2a); } - OrientedLattice latt2(PeaksRun2->mutableSample().getOrientedLattice()); - // Kernel::Matrix<double> UB = latt2.getUB(); + auto latt2 = std::make_unique<OrientedLattice>( + PeaksRun2->mutableSample().getOrientedLattice()); Rot.Invert(); Gon2a.Invert(); - latt2.setUB(Gon2a * Mk * UB1); + latt2->setUB(Gon2a * Mk * UB1); - PeaksRun2->mutableSample().setOrientedLattice(&latt2); + PeaksRun2->mutableSample().setOrientedLattice(std::move(latt2)); } /** diff --git a/Framework/Crystal/src/LoadIsawUB.cpp b/Framework/Crystal/src/LoadIsawUB.cpp index 209eb43e532..dc9158dd6a3 100644 --- a/Framework/Crystal/src/LoadIsawUB.cpp +++ b/Framework/Crystal/src/LoadIsawUB.cpp @@ -190,16 +190,16 @@ void LoadIsawUB::readModulatedUB(std::ifstream &in, DblMatrix &ub) { throw std::invalid_argument("Must specify either a MatrixWorkspace or a " "PeaksWorkspace or a MDWorkspace."); - // Save it into the workspace - ws->mutableSample().setOrientedLattice(latt.get()); - - // Save it to every experiment info in MD workspaces + // Save a copy of it to every experiment info in MD workspaces if ((MDWS != nullptr) && (MDWS->getNumExperimentInfo() > 1)) { for (uint16_t i = 1; i < MDWS->getNumExperimentInfo(); i++) { ws = MDWS->getExperimentInfo(i); - ws->mutableSample().setOrientedLattice(latt.get()); + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(*latt)); } } + // Save it into the main workspace + ws->mutableSample().setOrientedLattice(std::move(latt)); this->setProperty("InputWorkspace", ws1); } diff --git a/Framework/Crystal/src/OptimizeLatticeForCellType.cpp b/Framework/Crystal/src/OptimizeLatticeForCellType.cpp index d646cc3d67e..3aaf58670ee 100644 --- a/Framework/Crystal/src/OptimizeLatticeForCellType.cpp +++ b/Framework/Crystal/src/OptimizeLatticeForCellType.cpp @@ -173,23 +173,24 @@ void OptimizeLatticeForCellType::exec() { ub_alg->setProperty("gamma", refinedCell.gamma()); ub_alg->executeAsChildAlg(); DblMatrix UBnew = peakWS->mutableSample().getOrientedLattice().getUB(); - OrientedLattice o_lattice; - o_lattice.setUB(UBnew); + auto o_lattice = std::make_unique<OrientedLattice>(); + o_lattice->setUB(UBnew); if (maxOrder > 0) { - o_lattice.setModUB(modUB); - o_lattice.setMaxOrder(maxOrder); - o_lattice.setCrossTerm(crossTerms); + o_lattice->setModUB(modUB); + o_lattice->setMaxOrder(maxOrder); + o_lattice->setCrossTerm(crossTerms); } - o_lattice.set(refinedCell.a(), refinedCell.b(), refinedCell.c(), - refinedCell.alpha(), refinedCell.beta(), refinedCell.gamma()); - o_lattice.setError(refinedCell.errora(), refinedCell.errorb(), - refinedCell.errorc(), refinedCell.erroralpha(), - refinedCell.errorbeta(), refinedCell.errorgamma()); + o_lattice->set(refinedCell.a(), refinedCell.b(), refinedCell.c(), + refinedCell.alpha(), refinedCell.beta(), + refinedCell.gamma()); + o_lattice->setError(refinedCell.errora(), refinedCell.errorb(), + refinedCell.errorc(), refinedCell.erroralpha(), + refinedCell.errorbeta(), refinedCell.errorgamma()); // Show the modified lattice parameters - g_log.notice() << i_run->getName() << " " << o_lattice << "\n"; + g_log.notice() << i_run->getName() << " " << *o_lattice << "\n"; - i_run->mutableSample().setOrientedLattice(&o_lattice); + i_run->mutableSample().setOrientedLattice(std::move(o_lattice)); setProperty("OutputChi2", chisq); diff --git a/Framework/Crystal/src/PredictSatellitePeaks.cpp b/Framework/Crystal/src/PredictSatellitePeaks.cpp index 70dcff85f74..2ab7870ba45 100644 --- a/Framework/Crystal/src/PredictSatellitePeaks.cpp +++ b/Framework/Crystal/src/PredictSatellitePeaks.cpp @@ -152,23 +152,22 @@ void PredictSatellitePeaks::exec() { } API::Sample sample = Peaks->mutableSample(); - - OrientedLattice lattice = sample.getOrientedLattice(); + auto lattice = std::make_unique<OrientedLattice>(sample.getOrientedLattice()); bool fromUB = getProperty("GetModVectorsFromUB"); if (fromUB) { - offsets1 = lattice.getModVec(0); - offsets2 = lattice.getModVec(1); - offsets3 = lattice.getModVec(2); + offsets1 = lattice->getModVec(0); + offsets2 = lattice->getModVec(1); + offsets3 = lattice->getModVec(2); if (maxOrder == 0) - maxOrder = lattice.getMaxOrder(); - crossTerms = lattice.getCrossTerm(); + maxOrder = lattice->getMaxOrder(); + crossTerms = lattice->getCrossTerm(); } else { - lattice.setModVec1(offsets1); - lattice.setModVec2(offsets2); - lattice.setModVec3(offsets3); - lattice.setMaxOrder(maxOrder); - lattice.setCrossTerm(crossTerms); + lattice->setModVec1(offsets1); + lattice->setModVec2(offsets2); + lattice->setModVec3(offsets3); + lattice->setMaxOrder(maxOrder); + lattice->setCrossTerm(crossTerms); } const auto instrument = Peaks->getInstrument(); @@ -176,7 +175,7 @@ void PredictSatellitePeaks::exec() { outPeaks = boost::dynamic_pointer_cast<IPeaksWorkspace>( WorkspaceFactory::Instance().createPeaks()); outPeaks->setInstrument(instrument); - outPeaks->mutableSample().setOrientedLattice(&lattice); + outPeaks->mutableSample().setOrientedLattice(std::move(lattice)); Kernel::Matrix<double> goniometer; goniometer.identityMatrix(); @@ -188,9 +187,9 @@ void PredictSatellitePeaks::exec() { std::vector<V3D> possibleHKLs; const double dMin = getProperty("MinDSpacing"); const double dMax = getProperty("MaxDSpacing"); - Geometry::HKLGenerator gen(lattice, dMin); - auto dSpacingFilter = - boost::make_shared<HKLFilterDRange>(lattice, dMin, dMax); + Geometry::HKLGenerator gen(outPeaks->sample().getOrientedLattice(), dMin); + auto dSpacingFilter = boost::make_shared<HKLFilterDRange>( + outPeaks->sample().getOrientedLattice(), dMin, dMax); V3D hkl = *(gen.begin()); g_log.information() << "HKL range for d_min of " << dMin << " to d_max of " @@ -207,7 +206,7 @@ void PredictSatellitePeaks::exec() { size_t N = possibleHKLs.size(); N = max<size_t>(100, N); - auto &UB = lattice.getUB(); + const auto &UB = outPeaks->sample().getOrientedLattice().getUB(); goniometer = peak0.getGoniometerMatrix(); Progress prog(this, 0.0, 1.0, N); vector<vector<int>> AlreadyDonePeaks; @@ -260,22 +259,22 @@ void PredictSatellitePeaks::exec_peaks() { API::Sample sample = Peaks->mutableSample(); - OrientedLattice lattice = sample.getOrientedLattice(); + auto lattice = std::make_unique<OrientedLattice>(sample.getOrientedLattice()); bool fromUB = getProperty("GetModVectorsFromUB"); if (fromUB) { - offsets1 = lattice.getModVec(0); - offsets2 = lattice.getModVec(1); - offsets3 = lattice.getModVec(2); + offsets1 = lattice->getModVec(0); + offsets2 = lattice->getModVec(1); + offsets3 = lattice->getModVec(2); if (maxOrder == 0) - maxOrder = lattice.getMaxOrder(); - crossTerms = lattice.getCrossTerm(); + maxOrder = lattice->getMaxOrder(); + crossTerms = lattice->getCrossTerm(); } else { - lattice.setModVec1(offsets1); - lattice.setModVec2(offsets2); - lattice.setModVec3(offsets3); - lattice.setMaxOrder(maxOrder); - lattice.setCrossTerm(crossTerms); + lattice->setModVec1(offsets1); + lattice->setModVec2(offsets2); + lattice->setModVec3(offsets3); + lattice->setMaxOrder(maxOrder); + lattice->setCrossTerm(crossTerms); } bool includePeaksInRange = false; @@ -293,7 +292,7 @@ void PredictSatellitePeaks::exec_peaks() { outPeaks = boost::dynamic_pointer_cast<IPeaksWorkspace>( WorkspaceFactory::Instance().createPeaks()); outPeaks->setInstrument(instrument); - outPeaks->mutableSample().setOrientedLattice(&lattice); + outPeaks->mutableSample().setOrientedLattice(std::move(lattice)); vector<vector<int>> AlreadyDonePeaks; HKLFilterWavelength lambdaFilter(DblMatrix(3, 3, true), 0.1, 100.); diff --git a/Framework/Crystal/src/SelectCellOfType.cpp b/Framework/Crystal/src/SelectCellOfType.cpp index 6b5b95f6122..69df078fcb7 100644 --- a/Framework/Crystal/src/SelectCellOfType.cpp +++ b/Framework/Crystal/src/SelectCellOfType.cpp @@ -83,8 +83,10 @@ void SelectCellOfType::exec() { throw std::runtime_error("Could not read the peaks workspace"); } - OrientedLattice o_lattice = ws->mutableSample().getOrientedLattice(); - Matrix<double> UB = o_lattice.getUB(); + // copy current lattice + auto o_lattice = std::make_unique<OrientedLattice>( + ws->mutableSample().getOrientedLattice()); + Matrix<double> UB = o_lattice->getUB(); if (!IndexingUtils::CheckUB(UB)) { throw std::runtime_error( @@ -117,12 +119,10 @@ void SelectCellOfType::exec() { std::vector<double> sigabc(6); SelectCellWithForm::DetermineErrors(sigabc, newUB, ws, tolerance); //---------------------------------------------- - o_lattice.setUB(newUB); + o_lattice->setUB(newUB); - o_lattice.setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], - sigabc[5]); - - ws->mutableSample().setOrientedLattice(&o_lattice); + o_lattice->setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], + sigabc[5]); std::vector<Peak> &peaks = ws->getPeaks(); size_t n_peaks = ws->getNumberPeaks(); @@ -130,7 +130,7 @@ void SelectCellOfType::exec() { int num_indexed = 0; double average_error = 0.0; - if (o_lattice.getMaxOrder() == 0) { + if (o_lattice->getMaxOrder() == 0) { std::vector<V3D> miller_indices; std::vector<V3D> q_vectors; for (size_t i = 0; i < n_peaks; i++) { @@ -151,6 +151,7 @@ void SelectCellOfType::exec() { peaks[i].setHKL(T * peaks[i].getHKL()); } } + ws->mutableSample().setOrientedLattice(std::move(o_lattice)); // Tell the user what happened. g_log.notice() << "Re-indexed the peaks with the new UB. \n"; diff --git a/Framework/Crystal/src/SelectCellWithForm.cpp b/Framework/Crystal/src/SelectCellWithForm.cpp index c9be3930a97..c848df75d12 100644 --- a/Framework/Crystal/src/SelectCellWithForm.cpp +++ b/Framework/Crystal/src/SelectCellWithForm.cpp @@ -112,8 +112,10 @@ void SelectCellWithForm::exec() { throw std::runtime_error("Could not read the peaks workspace"); } - OrientedLattice o_lattice = ws->mutableSample().getOrientedLattice(); - Matrix<double> UB = o_lattice.getUB(); + // copy current lattice + auto o_lattice = std::make_unique<OrientedLattice>( + ws->mutableSample().getOrientedLattice()); + Matrix<double> UB = o_lattice->getUB(); bool allowPermutations = this->getProperty("AllowPermutations"); @@ -147,14 +149,12 @@ void SelectCellWithForm::exec() { // least squares optimization //---------------------------------------------- - o_lattice.setUB(newUB); + o_lattice->setUB(newUB); std::vector<double> sigabc(6); DetermineErrors(sigabc, newUB, ws, tolerance); - o_lattice.setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], - sigabc[5]); - - ws->mutableSample().setOrientedLattice(&o_lattice); + o_lattice->setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], + sigabc[5]); std::vector<Peak> &peaks = ws->getPeaks(); size_t n_peaks = ws->getNumberPeaks(); @@ -162,7 +162,7 @@ void SelectCellWithForm::exec() { int num_indexed = 0; double average_error = 0.0; - if (o_lattice.getMaxOrder() == 0) { + if (o_lattice->getMaxOrder() == 0) { std::vector<V3D> miller_indices; std::vector<V3D> q_vectors; for (size_t i = 0; i < n_peaks; i++) { @@ -183,6 +183,7 @@ void SelectCellWithForm::exec() { peaks[i].setHKL(T * peaks[i].getHKL()); } } + ws->mutableSample().setOrientedLattice(std::move(o_lattice)); // Tell the user what happened. g_log.notice() << "Re-indexed the peaks with the new UB. \n"; diff --git a/Framework/Crystal/src/SetUB.cpp b/Framework/Crystal/src/SetUB.cpp index d98d86c56d5..92522470405 100644 --- a/Framework/Crystal/src/SetUB.cpp +++ b/Framework/Crystal/src/SetUB.cpp @@ -95,7 +95,7 @@ void SetUB::init() { @throws :: |B.u|=0 or |B.v|=0 or u||v */ void SetUB::exec() { - Mantid::Geometry::OrientedLattice o; + std::unique_ptr<Mantid::Geometry::OrientedLattice> lattice; std::vector<double> UBvec = getProperty("UB"); Mantid::Kernel::DblMatrix UBMatrix(UBvec), zeroMatrix(3, 3); if (UBMatrix == zeroMatrix) { @@ -109,14 +109,16 @@ void SetUB::exec() { std::vector<double> u = getProperty("u"); std::vector<double> v = getProperty("v"); - o = Mantid::Geometry::OrientedLattice(a, b, c, alpha, beta, gamma); - o.setUFromVectors(Mantid::Kernel::V3D(u[0], u[1], u[2]), - Mantid::Kernel::V3D(v[0], v[1], v[2])); + lattice = std::make_unique<OrientedLattice>(a, b, c, alpha, beta, gamma); + lattice->setUFromVectors(Mantid::Kernel::V3D(u[0], u[1], u[2]), + Mantid::Kernel::V3D(v[0], v[1], v[2])); } else { if (UBMatrix.determinant() == 0) throw std::invalid_argument("UB matrix determinant is 0"); - else - o.setUB(UBMatrix); + else { + lattice = std::make_unique<OrientedLattice>(); + lattice->setUB(UBMatrix); + } } // now attach the oriented lattice to the workspace @@ -130,8 +132,10 @@ void SetUB::exec() { if ((sampleNumber == EMPTY_INT()) || (sampleNumber < 0)) // copy to all samples { - for (uint16_t i = 0; i < mdws->getNumExperimentInfo(); i++) - mdws->getExperimentInfo(i)->mutableSample().setOrientedLattice(&o); + for (uint16_t i = 0; i < mdws->getNumExperimentInfo(); i++) { + mdws->getExperimentInfo(i)->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(*lattice)); + } } else // copy to a single sample { if (static_cast<uint16_t>(sampleNumber) > @@ -144,14 +148,14 @@ void SetUB::exec() { } mdws->getExperimentInfo(static_cast<uint16_t>(sampleNumber)) ->mutableSample() - .setOrientedLattice(&o); + .setOrientedLattice(std::move(lattice)); } } else // peaks workspace or matrix workspace { ExperimentInfo_sptr ei = boost::dynamic_pointer_cast<ExperimentInfo>(ws); if (!ei) throw std::invalid_argument("Wrong type of workspace"); - ei->mutableSample().setOrientedLattice(&o); + ei->mutableSample().setOrientedLattice(std::move(lattice)); } this->setProperty("Workspace", ws); } diff --git a/Framework/Crystal/src/TransformHKL.cpp b/Framework/Crystal/src/TransformHKL.cpp index cde96d87420..9167d87f5d6 100644 --- a/Framework/Crystal/src/TransformHKL.cpp +++ b/Framework/Crystal/src/TransformHKL.cpp @@ -123,7 +123,8 @@ void TransformHKL::exec() { SelectCellWithForm::DetermineErrors(sigabc, UB, ws, tolerance); o_lattice.setError(sigabc[0], sigabc[1], sigabc[2], sigabc[3], sigabc[4], sigabc[5]); - ws->mutableSample().setOrientedLattice(&o_lattice); + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(o_lattice)); std::vector<Peak> &peaks = ws->getPeaks(); size_t n_peaks = ws->getNumberPeaks(); diff --git a/Framework/Crystal/test/AddPeakHKLTest.h b/Framework/Crystal/test/AddPeakHKLTest.h index 2cdce23b34a..ed3b484a74e 100644 --- a/Framework/Crystal/test/AddPeakHKLTest.h +++ b/Framework/Crystal/test/AddPeakHKLTest.h @@ -71,9 +71,6 @@ public: Mantid::PhysicalConstants::h_bar; V3D qLab = qLabDir * wavenumber_in_angstrom_times_tof_in_microsec; - Mantid::Geometry::OrientedLattice orientedLattice( - 1, 1, 1, 90, 90, 90); // U is identity, real and reciprocal lattice - // vectors are identical. Mantid::Geometry::Goniometer goniometer; // identity V3D hkl = qLab / (2 * M_PI); // Given our settings above, this is the // simplified relationship between qLab and @@ -82,7 +79,9 @@ public: // Now create a peaks workspace around the simple fictional instrument PeaksWorkspace_sptr ws = boost::make_shared<PeaksWorkspace>(); ws->setInstrument(minimalInstrument); - ws->mutableSample().setOrientedLattice(&orientedLattice); + ws->mutableSample().setOrientedLattice( + std::make_unique<Mantid::Geometry::OrientedLattice>(1, 1, 1, 90, 90, + 90)); ws->mutableRun().setGoniometer(goniometer, false); AddPeakHKL alg; diff --git a/Framework/Crystal/test/CalculatePeaksHKLTest.h b/Framework/Crystal/test/CalculatePeaksHKLTest.h index aee3e0c4942..1327b3240ee 100644 --- a/Framework/Crystal/test/CalculatePeaksHKLTest.h +++ b/Framework/Crystal/test/CalculatePeaksHKLTest.h @@ -51,15 +51,14 @@ public: } void test_Execute() { - auto lattice = new Mantid::Geometry::OrientedLattice; + auto lattice = std::make_unique<Mantid::Geometry::OrientedLattice>(); Mantid::Kernel::DblMatrix UB(3, 3, true); UB.identityMatrix(); lattice->setUB(UB); auto ws = WorkspaceCreationHelper::createPeaksWorkspace(10); - ws->mutableSample().setOrientedLattice(lattice); + ws->mutableSample().setOrientedLattice(std::move(lattice)); - delete lattice; Mantid::API::AnalysisDataService::Instance().addOrReplace("ws", ws); CalculatePeaksHKL alg; @@ -82,17 +81,15 @@ public: // Don't index peaks that are already indexed. void test_SkipIndexing() { - auto lattice = new Mantid::Geometry::OrientedLattice; + auto lattice = std::make_unique<Mantid::Geometry::OrientedLattice>(); Mantid::Kernel::DblMatrix UB(3, 3, true); UB.identityMatrix(); lattice->setUB(UB); auto ws = WorkspaceCreationHelper::createPeaksWorkspace(10); - ws->mutableSample().setOrientedLattice(lattice); + ws->mutableSample().setOrientedLattice(std::move(lattice)); ws->getPeak(0).setHKL(1, 1, 1); // First peak is already indexed now. - delete lattice; - Mantid::API::AnalysisDataService::Instance().addOrReplace("ws", ws); CalculatePeaksHKL alg; @@ -108,17 +105,15 @@ public: // Don't index peaks that are already indexed. void test_OverwriteIndexed() { - auto lattice = new Mantid::Geometry::OrientedLattice; + auto lattice = std::make_unique<Mantid::Geometry::OrientedLattice>(); Mantid::Kernel::DblMatrix UB(3, 3, true); UB.identityMatrix(); lattice->setUB(UB); auto ws = WorkspaceCreationHelper::createPeaksWorkspace(10); - ws->mutableSample().setOrientedLattice(lattice); + ws->mutableSample().setOrientedLattice(std::move(lattice)); ws->getPeak(0).setHKL(1, 1, 1); // First peak is already indexed now. - delete lattice; - Mantid::API::AnalysisDataService::Instance().addOrReplace("ws", ws); CalculatePeaksHKL alg; diff --git a/Framework/Crystal/test/ClearUBTest.h b/Framework/Crystal/test/ClearUBTest.h index b670b8a4ad0..c4346254eeb 100644 --- a/Framework/Crystal/test/ClearUBTest.h +++ b/Framework/Crystal/test/ClearUBTest.h @@ -40,8 +40,8 @@ private: std::string createMatrixWorkspace(const bool withOrientedLattice = true) { auto ws = WorkspaceCreationHelper::create2DWorkspace(1, 2); if (withOrientedLattice) { - OrientedLattice latt(1.0, 2.0, 3.0, 90, 90, 90); - ws->mutableSample().setOrientedLattice(&latt); + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); } const std::string wsName = "TestWorkspace"; AnalysisDataService::Instance().addOrReplace(wsName, ws); @@ -54,13 +54,14 @@ private: const std::string wsName = "TestWorkspace"; auto ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1, 10, 10, 1, wsName); - OrientedLattice latt(1.0, 2.0, 3.0, 90, 90, 90); - ws->getExperimentInfo(0)->mutableSample().setOrientedLattice(&latt); + ws->getExperimentInfo(0)->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); for (uint16_t i = 1; i < nExperimentInfosToAdd; ++i) { ExperimentInfo_sptr experimentInfo = boost::make_shared<ExperimentInfo>(); ws->addExperimentInfo(experimentInfo); - ws->getExperimentInfo(i)->mutableSample().setOrientedLattice(&latt); + ws->getExperimentInfo(i)->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); } AnalysisDataService::Instance().addOrReplace(wsName, ws); diff --git a/Framework/Crystal/test/HasUBTest.h b/Framework/Crystal/test/HasUBTest.h index f4f55abac7a..4cee8033a01 100644 --- a/Framework/Crystal/test/HasUBTest.h +++ b/Framework/Crystal/test/HasUBTest.h @@ -29,9 +29,8 @@ private: std::string createMatrixWorkspace(const bool withOrientedLattice = true) { auto ws = WorkspaceCreationHelper::create2DWorkspace(1, 2); if (withOrientedLattice) { - OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - ws->mutableSample().setOrientedLattice(latt); - delete latt; + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); } const std::string wsName = "TestWorkspace"; AnalysisDataService::Instance().addOrReplace(wsName, ws); @@ -44,16 +43,16 @@ private: const std::string wsName = "TestWorkspace"; auto ws = MDEventsTestHelper::makeFakeMDHistoWorkspace(1, 1, 10, 10, 1, wsName); - OrientedLattice *latt = new OrientedLattice(1.0, 2.0, 3.0, 90, 90, 90); - ws->getExperimentInfo(0)->mutableSample().setOrientedLattice(latt); + ws->getExperimentInfo(0)->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); for (uint16_t i = 1; i < nExperimentInfosToAdd; ++i) { ExperimentInfo_sptr experimentInfo = boost::make_shared<ExperimentInfo>(); ws->addExperimentInfo(experimentInfo); - ws->getExperimentInfo(i)->mutableSample().setOrientedLattice(latt); + ws->getExperimentInfo(i)->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1.0, 2.0, 3.0, 90, 90, 90)); } - delete latt; AnalysisDataService::Instance().addOrReplace(wsName, ws); return wsName; } diff --git a/Framework/Crystal/test/IndexPeaksTest.h b/Framework/Crystal/test/IndexPeaksTest.h index d5c9f8663d3..b773976b1dc 100644 --- a/Framework/Crystal/test/IndexPeaksTest.h +++ b/Framework/Crystal/test/IndexPeaksTest.h @@ -37,10 +37,10 @@ createPeaksWorkspace(const MinimalPeaksList<NPeaks> &testPeaksInfo, const std::vector<V3D> &modVectors = std::vector<V3D>(), const bool crossTerms = false) { auto peaksWS = WorkspaceCreationHelper::createPeaksWorkspace(NPeaks); - OrientedLattice lattice; - lattice.setUB(ub); + auto lattice = std::make_unique<OrientedLattice>(); + lattice->setUB(ub); if (maxOrder > 0) { - lattice.setMaxOrder(maxOrder); + lattice->setMaxOrder(maxOrder); if (modVectors.empty() || modVectors.size() > 3) throw std::runtime_error("Only <= 3 modulation vectors can be provided."); auto modVecOrDefault = [&modVectors](const size_t index) { @@ -49,12 +49,12 @@ createPeaksWorkspace(const MinimalPeaksList<NPeaks> &testPeaksInfo, else return V3D(); }; - lattice.setModVec1(modVecOrDefault(0)); - lattice.setModVec2(modVecOrDefault(1)); - lattice.setModVec3(modVecOrDefault(2)); - lattice.setCrossTerm(crossTerms); + lattice->setModVec1(modVecOrDefault(0)); + lattice->setModVec2(modVecOrDefault(1)); + lattice->setModVec3(modVecOrDefault(2)); + lattice->setCrossTerm(crossTerms); } - peaksWS->mutableSample().setOrientedLattice(&lattice); + peaksWS->mutableSample().setOrientedLattice(std::move(lattice)); int peakCount{0}; for (const auto &testPeakInfo : testPeaksInfo) { @@ -139,8 +139,8 @@ public: void test_empty_peaks_workspace_indexes_nothing() { auto peaksWS = WorkspaceCreationHelper::createPeaksWorkspace(0); - OrientedLattice lattice; - peaksWS->mutableSample().setOrientedLattice(&lattice); + peaksWS->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>()); auto alg = indexPeaks(peaksWS, {{"Tolerance", "0.1"}}); diff --git a/Framework/Crystal/test/SelectCellOfTypeTest.h b/Framework/Crystal/test/SelectCellOfTypeTest.h index 1b765e252b4..c70b90cf07b 100644 --- a/Framework/Crystal/test/SelectCellOfTypeTest.h +++ b/Framework/Crystal/test/SelectCellOfTypeTest.h @@ -62,12 +62,12 @@ public: UB.setRow(1, row_1); UB.setRow(2, row_2); - OrientedLattice o_lattice; - o_lattice.setUB(UB); - ws->mutableSample().setOrientedLattice(&o_lattice); + auto lattice = std::make_unique<OrientedLattice>(); + lattice->setUB(UB); + ws->mutableSample().setOrientedLattice(std::move(lattice)); // now get the UB back from the WS - UB = o_lattice.getUB(); + UB = ws->sample().getOrientedLattice().getUB(); SelectCellOfType alg; TS_ASSERT_THROWS_NOTHING(alg.initialize()) diff --git a/Framework/Crystal/test/SelectCellWithFormTest.h b/Framework/Crystal/test/SelectCellWithFormTest.h index 3a49d16df33..334d607428b 100644 --- a/Framework/Crystal/test/SelectCellWithFormTest.h +++ b/Framework/Crystal/test/SelectCellWithFormTest.h @@ -62,12 +62,12 @@ public: UB.setRow(1, row_1); UB.setRow(2, row_2); - OrientedLattice o_lattice; - o_lattice.setUB(UB); - ws->mutableSample().setOrientedLattice(&o_lattice); + auto lattice = std::make_unique<OrientedLattice>(); + lattice->setUB(UB); + ws->mutableSample().setOrientedLattice(std::move(lattice)); // now get the UB back from the WS - UB = o_lattice.getUB(); + UB = ws->sample().getOrientedLattice().getUB(); SelectCellWithForm alg; TS_ASSERT_THROWS_NOTHING(alg.initialize()) diff --git a/Framework/Crystal/test/ShowPossibleCellsTest.h b/Framework/Crystal/test/ShowPossibleCellsTest.h index 5ab1542f7dd..384b3b10d36 100644 --- a/Framework/Crystal/test/ShowPossibleCellsTest.h +++ b/Framework/Crystal/test/ShowPossibleCellsTest.h @@ -62,12 +62,12 @@ public: UB.setRow(1, row_1); UB.setRow(2, row_2); - OrientedLattice o_lattice; - o_lattice.setUB(UB); - ws->mutableSample().setOrientedLattice(&o_lattice); + auto lattice = std::make_unique<Mantid::Geometry::OrientedLattice>(); + lattice->setUB(UB); + ws->mutableSample().setOrientedLattice(std::move(lattice)); // now get the UB back from the WS - UB = o_lattice.getUB(); + UB = ws->sample().getOrientedLattice().getUB(); ShowPossibleCells alg; TS_ASSERT_THROWS_NOTHING(alg.initialize()) diff --git a/Framework/Crystal/test/SortHKLTest.h b/Framework/Crystal/test/SortHKLTest.h index 0f00d69cd6e..44af4a434a5 100644 --- a/Framework/Crystal/test/SortHKLTest.h +++ b/Framework/Crystal/test/SortHKLTest.h @@ -46,11 +46,11 @@ public: PeaksWorkspace_sptr ws(new PeaksWorkspace()); ws->setInstrument(inst); - auto lattice = new Mantid::Geometry::OrientedLattice; + auto lattice = std::make_unique<Mantid::Geometry::OrientedLattice>(); Mantid::Kernel::DblMatrix UB(3, 3, true); UB.identityMatrix(); lattice->setUB(UB); - ws->mutableSample().setOrientedLattice(lattice); + ws->mutableSample().setOrientedLattice(std::move(lattice)); double smu = 0.357; double amu = 0.011; diff --git a/Framework/Crystal/test/StatisticsOfPeaksWorkspaceTest.h b/Framework/Crystal/test/StatisticsOfPeaksWorkspaceTest.h index 48c74bcc008..0a2c4a887c3 100644 --- a/Framework/Crystal/test/StatisticsOfPeaksWorkspaceTest.h +++ b/Framework/Crystal/test/StatisticsOfPeaksWorkspaceTest.h @@ -43,11 +43,11 @@ public: PeaksWorkspace_sptr ws(new PeaksWorkspace()); ws->setInstrument(inst); - auto lattice = new Mantid::Geometry::OrientedLattice; + auto lattice = std::make_unique<Mantid::Geometry::OrientedLattice>(); Mantid::Kernel::DblMatrix UB(3, 3, true); UB.identityMatrix(); lattice->setUB(UB); - ws->mutableSample().setOrientedLattice(lattice); + ws->mutableSample().setOrientedLattice(std::move(lattice)); for (int run = 1000; run < numRuns + 1000; run++) for (size_t b = 1; b <= numBanks; b++) diff --git a/Framework/Crystal/test/TransformHKLTest.h b/Framework/Crystal/test/TransformHKLTest.h index d46710db9d9..b43255aa866 100644 --- a/Framework/Crystal/test/TransformHKLTest.h +++ b/Framework/Crystal/test/TransformHKLTest.h @@ -62,9 +62,9 @@ public: UB.setRow(1, row_1); UB.setRow(2, row_2); - OrientedLattice o_lattice; - o_lattice.setUB(UB); - ws->mutableSample().setOrientedLattice(&o_lattice); + auto lattice = std::make_unique<OrientedLattice>(); + lattice->setUB(UB); + ws->mutableSample().setOrientedLattice(std::move(lattice)); Matrix<double> UB_inverse(UB); UB_inverse.Invert(); diff --git a/Framework/DataObjects/test/PeaksWorkspaceTest.h b/Framework/DataObjects/test/PeaksWorkspaceTest.h index a38486c77dc..e2cc914e775 100644 --- a/Framework/DataObjects/test/PeaksWorkspaceTest.h +++ b/Framework/DataObjects/test/PeaksWorkspaceTest.h @@ -611,8 +611,8 @@ private: PeaksWorkspace_sptr makeWorkspace(const PeakParameters ¶ms) { auto ws = boost::make_shared<PeaksWorkspace>(); ws->setInstrument(params.instrument); - OrientedLattice lattice(params.lattice); - ws->mutableSample().setOrientedLattice(&lattice); + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(params.lattice)); ws->mutableRun().setGoniometer(params.goniometer, false); return ws; } diff --git a/Framework/DataObjects/test/WorkspaceValidatorsTest.h b/Framework/DataObjects/test/WorkspaceValidatorsTest.h index af3a2a623b0..174f5234acf 100644 --- a/Framework/DataObjects/test/WorkspaceValidatorsTest.h +++ b/Framework/DataObjects/test/WorkspaceValidatorsTest.h @@ -236,8 +236,7 @@ public: validator.isValid(ws), "Workspace must have a sample with an orientation matrix defined."); - OrientedLattice lattice; - ws->mutableSample().setOrientedLattice(&lattice); + ws->mutableSample().setOrientedLattice(std::make_unique<OrientedLattice>()); TS_ASSERT_EQUALS(validator.isValid(ws), ""); } diff --git a/Framework/MDAlgorithms/src/LoadSQW.cpp b/Framework/MDAlgorithms/src/LoadSQW.cpp index 07c771154fb..4f8e61ceb3c 100644 --- a/Framework/MDAlgorithms/src/LoadSQW.cpp +++ b/Framework/MDAlgorithms/src/LoadSQW.cpp @@ -399,9 +399,8 @@ void LoadSQW::addLattice( // frame, // Q units so general goniometer should provide unit rotation matrix info->mutableRun().mutableGoniometer().makeUniversalGoniometer(); - // - OrientedLattice latt(a, b, c, aa, bb, cc); - info->mutableSample().setOrientedLattice(&latt); + info->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(a, b, c, aa, bb, cc)); ws->addExperimentInfo(info); } diff --git a/Framework/MDAlgorithms/src/LoadSQW2.cpp b/Framework/MDAlgorithms/src/LoadSQW2.cpp index 0a65cb931f7..3ca3d6ebd88 100644 --- a/Framework/MDAlgorithms/src/LoadSQW2.cpp +++ b/Framework/MDAlgorithms/src/LoadSQW2.cpp @@ -238,8 +238,6 @@ boost::shared_ptr<API::ExperimentInfo> LoadSQW2::readSingleSPEHeader() { V3D uVec(floats[6], floats[7], floats[8]), vVec(floats[9], floats[10], floats[11]); lattice->setUFromVectors(uVec, vVec); - // Lattice is copied into the Sample object - sample.setOrientedLattice(lattice.get()); if (g_log.is(Logger::Priority::PRIO_DEBUG)) { std::stringstream os; os << "Lattice:" @@ -255,6 +253,7 @@ boost::shared_ptr<API::ExperimentInfo> LoadSQW2::readSingleSPEHeader() { << "Inverse B matrix (calculated): " << lattice->getBinv() << "\n"; g_log.debug(os.str()); } + sample.setOrientedLattice(std::move(lattice)); // goniometer angles float psi(0.0f), omega(0.0f), dpsi(0.0f), gl(0.0f), gs(0.0f); diff --git a/Framework/MDAlgorithms/test/CalculateCoverageDGSTest.h b/Framework/MDAlgorithms/test/CalculateCoverageDGSTest.h index fbc0a5feb11..7cca4d9999b 100644 --- a/Framework/MDAlgorithms/test/CalculateCoverageDGSTest.h +++ b/Framework/MDAlgorithms/test/CalculateCoverageDGSTest.h @@ -56,8 +56,8 @@ public: V3D sampPos(0., 0., 0.), sourcePos(0, 0, -1.); WorkspaceCreationHelper::createInstrumentForWorkspaceWithDistances( inputWorkspace, sampPos, sourcePos, detectorPositions); - OrientedLattice ol(2, 2, 2, 90, 90, 90); - inputWorkspace->mutableSample().setOrientedLattice(&ol); + inputWorkspace->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(2, 2, 2, 90, 90, 90)); Goniometer gon(DblMatrix(3, 3, true)); inputWorkspace->mutableRun().setGoniometer(gon, true); inputWorkspace->mutableRun().addLogData( diff --git a/Framework/MDAlgorithms/test/ConvertToMDMinMaxGlobalTest.h b/Framework/MDAlgorithms/test/ConvertToMDMinMaxGlobalTest.h index 6e98afb1f9f..19fd653211e 100644 --- a/Framework/MDAlgorithms/test/ConvertToMDMinMaxGlobalTest.h +++ b/Framework/MDAlgorithms/test/ConvertToMDMinMaxGlobalTest.h @@ -82,8 +82,8 @@ Mantid::API::MatrixWorkspace_sptr MakeWorkspace(double xmin, double dx, new Mantid::Kernel::PropertyWithValue<double>("Ei", Ei)); } - Mantid::Geometry::OrientedLattice latt(2, 3, 4, 90, 90, 90); - ws->mutableSample().setOrientedLattice(&latt); + ws->mutableSample().setOrientedLattice( + std::make_unique<Mantid::Geometry::OrientedLattice>(2, 3, 4, 90, 90, 90)); Mantid::Kernel::TimeSeriesProperty<double> *p = new Mantid::Kernel::TimeSeriesProperty<double>("doubleProp"); diff --git a/Framework/MDAlgorithms/test/ConvertToMDMinMaxLocalTest.h b/Framework/MDAlgorithms/test/ConvertToMDMinMaxLocalTest.h index fed9171f070..d17661b8fa7 100644 --- a/Framework/MDAlgorithms/test/ConvertToMDMinMaxLocalTest.h +++ b/Framework/MDAlgorithms/test/ConvertToMDMinMaxLocalTest.h @@ -245,8 +245,9 @@ private: new Mantid::Kernel::PropertyWithValue<double>("Ei", Ei)); } - Mantid::Geometry::OrientedLattice latt(2, 3, 4, 90, 90, 90); - ws->mutableSample().setOrientedLattice(&latt); + ws->mutableSample().setOrientedLattice( + std::make_unique<Mantid::Geometry::OrientedLattice>(2, 3, 4, 90, 90, + 90)); // time average value of this is the simple average // of the first three values = 7.69667 diff --git a/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h b/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h index 2b5d267819c..3f841b00111 100644 --- a/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h +++ b/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h @@ -295,14 +295,11 @@ public: void xtestTransfMat1() { Mantid::API::MatrixWorkspace_sptr ws2D = WorkspaceCreationHelper:: createProcessedWorkspaceWithCylComplexInstrument(16, 10, true); - OrientedLattice *latt = new OrientedLattice(1, 2, 3, 90., 90., 90.); - ws2D->mutableSample().setOrientedLattice(latt); - delete latt; + ws2D->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 2, 3, 90., 90., 90.)); MDWSDescription TWS(4); std::vector<double> rot; - // std::vector<double> - // rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,0,0),Kernel::V3D(0,1,0)); Kernel::Matrix<double> unit = Kernel::Matrix<double>(3, 3, true); Kernel::Matrix<double> rez(rot); TS_ASSERT(unit.equals(rez, 1.e-4)); @@ -310,9 +307,8 @@ public: void xtestTransfMat2() { Mantid::API::MatrixWorkspace_sptr ws2D = WorkspaceCreationHelper:: createProcessedWorkspaceWithCylComplexInstrument(16, 10, true); - OrientedLattice *latt = new OrientedLattice(1, 2, 3, 75., 45., 35.); - ws2D->mutableSample().setOrientedLattice(latt); - delete latt; + ws2D->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 2, 3, 75., 45., 35.)); std::vector<double> rot; // std::vector<double> // rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,0,0),Kernel::V3D(0,1,0)); @@ -323,12 +319,9 @@ public: void xtestTransfMat3() { Mantid::API::MatrixWorkspace_sptr ws2D = WorkspaceCreationHelper:: createProcessedWorkspaceWithCylComplexInstrument(16, 10, true); - OrientedLattice *latt = new OrientedLattice(1, 2, 3, 75., 45., 35.); - ws2D->mutableSample().setOrientedLattice(latt); - delete latt; + ws2D->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 2, 3, 75., 45., 35.)); std::vector<double> rot; - // std::vector<double> - // rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,0,0),Kernel::V3D(0,-1,0)); Kernel::Matrix<double> unit = Kernel::Matrix<double>(3, 3, true); unit[1][1] = -1; unit[2][2] = -1; @@ -338,16 +331,13 @@ public: void xtestTransfMat4() { Mantid::API::MatrixWorkspace_sptr ws2D = WorkspaceCreationHelper:: createProcessedWorkspaceWithCylComplexInstrument(16, 10, true); - OrientedLattice *latt = new OrientedLattice(1, 1, 3, 90., 90., 90.); - ws2D->mutableSample().setOrientedLattice(latt); - delete latt; + ws2D->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 1, 3, 90., 90., 90.)); ws2D->mutableRun().mutableGoniometer().setRotationAngle(0, 0); ws2D->mutableRun().mutableGoniometer().setRotationAngle(1, 0); ws2D->mutableRun().mutableGoniometer().setRotationAngle(2, 0); std::vector<double> rot; - // std::vector<double> - // rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,1,0),Kernel::V3D(1,-1,0)); Kernel::Matrix<double> sample = Kernel::Matrix<double>(3, 3, true); sample[0][0] = 0.5 * M_SQRT2; sample[0][1] = 0.5 * M_SQRT2; @@ -360,19 +350,14 @@ public: void xtestTransfMat5() { Mantid::API::MatrixWorkspace_sptr ws2D = WorkspaceCreationHelper:: createProcessedWorkspaceWithCylComplexInstrument(16, 10, true); - OrientedLattice *latt = new OrientedLattice(1, 2, 3, 75., 45., 90.); - ws2D->mutableSample().setOrientedLattice(latt); - delete latt; + ws2D->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 2, 3, 75., 45., 90.)); ws2D->mutableRun().mutableGoniometer().setRotationAngle(0, 0); ws2D->mutableRun().mutableGoniometer().setRotationAngle(1, 0); ws2D->mutableRun().mutableGoniometer().setRotationAngle(2, 0); std::vector<double> rot; - // std::vector<double> - // rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,1,0),Kernel::V3D(1,-1,0)); Kernel::Matrix<double> sample = Kernel::Matrix<double>(3, 3, true); - // aa=[0.9521 0.3058 0.0000; 0.3058 -0.9521 0.0000; 0 0 - // -1.000]; sample[0][0] = 0.9521; sample[0][1] = 0.3058; sample[1][0] = 0.3058; @@ -384,17 +369,14 @@ public: void xtestTransf_PSI_DPSI() { Mantid::API::MatrixWorkspace_sptr ws2D = WorkspaceCreationHelper:: createProcessedWorkspaceWithCylComplexInstrument(16, 10, true); - OrientedLattice *latt = new OrientedLattice(1, 1, 1, 90., 90., 90.); - ws2D->mutableSample().setOrientedLattice(latt); - delete latt; + ws2D->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.)); ws2D->mutableRun().mutableGoniometer().setRotationAngle(0, 0); ws2D->mutableRun().mutableGoniometer().setRotationAngle(1, -20); // Psi, dPsi ws2D->mutableRun().mutableGoniometer().setRotationAngle(2, 0); std::vector<double> rot; - // std::vector<double> - // rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,0,0),Kernel::V3D(0,1,0)); Kernel::Matrix<double> sample = Kernel::Matrix<double>(3, 3, true); sample[0][0] = 0.9397; sample[0][1] = 0.3420; @@ -407,16 +389,13 @@ public: void xtestTransf_GL() { Mantid::API::MatrixWorkspace_sptr ws2D = WorkspaceCreationHelper:: createProcessedWorkspaceWithCylComplexInstrument(16, 10, true); - OrientedLattice *latt = new OrientedLattice(1, 1, 1, 90., 90., 90.); - ws2D->mutableSample().setOrientedLattice(latt); - delete latt; + ws2D->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.)); ws2D->mutableRun().mutableGoniometer().setRotationAngle(0, 20); // gl ws2D->mutableRun().mutableGoniometer().setRotationAngle(1, 0); ws2D->mutableRun().mutableGoniometer().setRotationAngle(2, 0); std::vector<double> rot; - // std::vector<double> - // rot=pAlg->get_transf_matrix(ws2D,Kernel::V3D(1,0,0),Kernel::V3D(0,1,0)); Kernel::Matrix<double> sample = Kernel::Matrix<double>(3, 3, true); sample[0][0] = 0.9397; diff --git a/Framework/MDAlgorithms/test/CutMDTest.h b/Framework/MDAlgorithms/test/CutMDTest.h index 10d8f150e92..c9106b9643e 100644 --- a/Framework/MDAlgorithms/test/CutMDTest.h +++ b/Framework/MDAlgorithms/test/CutMDTest.h @@ -90,8 +90,9 @@ private: AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( "__CutMDTest_tempMatWS"); - Mantid::Geometry::OrientedLattice latt(2, 3, 4, 90, 90, 90); - tempMatWS->mutableSample().setOrientedLattice(&latt); + tempMatWS->mutableSample().setOrientedLattice( + std::make_unique<Mantid::Geometry::OrientedLattice>(2, 3, 4, 90, 90, + 90)); ExperimentInfo_sptr ei(tempMatWS->cloneExperimentInfo()); eventWS->addExperimentInfo(ei); diff --git a/Framework/MDAlgorithms/test/IntegrateEllipsoidsTest.h b/Framework/MDAlgorithms/test/IntegrateEllipsoidsTest.h index ebb65b5cdac..207c55d62bd 100644 --- a/Framework/MDAlgorithms/test/IntegrateEllipsoidsTest.h +++ b/Framework/MDAlgorithms/test/IntegrateEllipsoidsTest.h @@ -62,9 +62,9 @@ createDiffractionData(const int nPixels = 100, const int nEventsPerPeak = 20, // Set the instrument to be the fake rectangular bank above. peaksWS->setInstrument(inst); // Set the oriented lattice for a cubic crystal - OrientedLattice ol(6, 6, 6, 90, 90, 90); - ol.setUFromVectors(V3D(6, 0, 0), V3D(0, 6, 0)); - peaksWS->mutableSample().setOrientedLattice(&ol); + auto lattice = std::make_unique<OrientedLattice>(6, 6, 6, 90, 90, 90); + lattice->setUFromVectors(V3D(6, 0, 0), V3D(0, 6, 0)); + peaksWS->mutableSample().setOrientedLattice(std::move(lattice)); // Make an event workspace and add fake peak data auto eventWS = boost::make_shared<EventWorkspace>(); diff --git a/Framework/MDAlgorithms/test/IntegrateEllipsoidsWithSatellitesTest.h b/Framework/MDAlgorithms/test/IntegrateEllipsoidsWithSatellitesTest.h index 77edec9e4a5..a6ec63fb683 100644 --- a/Framework/MDAlgorithms/test/IntegrateEllipsoidsWithSatellitesTest.h +++ b/Framework/MDAlgorithms/test/IntegrateEllipsoidsWithSatellitesTest.h @@ -63,18 +63,16 @@ createDiffractionData(const int nPixels = 100, const int nEventsPerPeak = 20, // Set the instrument to be the fake rectangular bank above. peaksWS->setInstrument(inst); // Set the oriented lattice for a cubic crystal - OrientedLattice ol(6, 6, 6, 90, 90, 90); - ol.setUFromVectors(V3D(6, 0, 0), V3D(0, 6, 0)); + auto lattice = std::make_unique<OrientedLattice>(6, 6, 6, 90, 90, 90); + lattice->setUFromVectors(V3D(6, 0, 0), V3D(0, 6, 0)); Matrix<double> modUB(3, 3, false); - Matrix<double> UB = ol.getUB(); + Matrix<double> UB = lattice->getUB(); modUB[0][0] = 0.2; - // modUB = UB.Invert() * modUB; - ol.setModUB(modUB); - ol.setMaxOrder(1); - ol.setCrossTerm(false); - ol.setModHKL(0, 0.5, 0., 0., 0., 0., 0., 0., 0.); - - peaksWS->mutableSample().setOrientedLattice(&ol); + lattice->setModUB(modUB); + lattice->setMaxOrder(1); + lattice->setCrossTerm(false); + lattice->setModHKL(0, 0.5, 0., 0., 0., 0., 0., 0., 0.); + peaksWS->mutableSample().setOrientedLattice(std::move(lattice)); // Make an event workspace and add fake peak data auto eventWS = boost::make_shared<EventWorkspace>(); diff --git a/Framework/MDAlgorithms/test/MDWSTransfTest.h b/Framework/MDAlgorithms/test/MDWSTransfTest.h index a65c140402b..485af23b94d 100644 --- a/Framework/MDAlgorithms/test/MDWSTransfTest.h +++ b/Framework/MDAlgorithms/test/MDWSTransfTest.h @@ -56,8 +56,6 @@ public: MDWSDescription TargWSDescription; Mantid::API::MatrixWorkspace_sptr spws = WorkspaceCreationHelper::create2DWorkspaceBinned(10, 10); - // Mantid::API::MatrixWorkspace_sptr spws - // =WorkspaceCreationHelper::createProcessedWorkspaceWithCylComplexInstrument(4,10,true); std::vector<double> minVal(4, -3), maxVal(4, 3); TargWSDescription.setMinMax(minVal, maxVal); @@ -68,12 +66,12 @@ public: Transf.findTargetFrame(TargWSDescription)); WorkspaceCreationHelper::setGoniometer(spws, 0, 0, 0); - // spws->mutableRun().mutableGoniometer().setRotationAngle(0,20); TS_ASSERT_EQUALS(CnvrtToMD::SampleFrame, Transf.findTargetFrame(TargWSDescription)); - spws->mutableSample().setOrientedLattice(pLattice.get()); + spws->mutableSample().setOrientedLattice( + std::make_unique<Geometry::OrientedLattice>(*pLattice)); TS_ASSERT_EQUALS(CnvrtToMD::HKLFrame, Transf.findTargetFrame(TargWSDescription)); } @@ -100,8 +98,8 @@ public: CnvrtToMD::SampleFrame, CnvrtToMD::HKLScale), const std::invalid_argument &); - spws->mutableSample().setOrientedLattice(pLattice.get()); - + spws->mutableSample().setOrientedLattice( + std::make_unique<Geometry::OrientedLattice>(*pLattice)); WorkspaceCreationHelper::setGoniometer(spws, 20, 0, 0); // spws->mutableRun().mutableGoniometer().setRotationAngle(0,20); @@ -150,7 +148,8 @@ public: pLattice = std::make_unique<Geometry::OrientedLattice>( 5 * M_PI, M_PI, 2 * M_PI, 90., 90., 90.); - ws2D->mutableSample().setOrientedLattice(pLattice.get()); + ws2D->mutableSample().setOrientedLattice( + std::make_unique<Geometry::OrientedLattice>(*pLattice)); TWS.buildFromMatrixWS(ws2D, "Q3D", "Direct"); std::vector<double> u(3, 0); @@ -223,9 +222,9 @@ public: MDWSDescription TWS; std::vector<double> minVal(4, -3), maxVal(4, 3); TWS.setMinMax(minVal, maxVal); - Geometry::OrientedLattice latt(5 * M_PI, M_PI, 2 * M_PI, 90., 90., 90.); - - ws2D->mutableSample().setOrientedLattice(&latt); + ws2D->mutableSample().setOrientedLattice( + std::make_unique<Geometry::OrientedLattice>(5 * M_PI, M_PI, 2 * M_PI, + 90., 90., 90.)); TWS.buildFromMatrixWS(ws2D, "Q3D", "Direct"); std::vector<double> u(3, 0); @@ -345,9 +344,9 @@ public: ws2D->mutableRun().mutableGoniometer().setRotationAngle(0, 0); // this is Wollastonite - Geometry::OrientedLattice latt(7.9250, 7.3200, 7.0650, 90.0550, 95.2170, - 103.4200); - ws2D->mutableSample().setOrientedLattice(&latt); + ws2D->mutableSample().setOrientedLattice( + std::make_unique<Geometry::OrientedLattice>( + 7.9250, 7.3200, 7.0650, 90.0550, 95.2170, 103.4200)); // //[transf,u_to_rlu]=calc_proj_matrix([7.9250,7.3200,7.0650], // 90.0550,95.2170,103.4200, u, v, 0, omega, dpsi, gl, gs) @@ -409,7 +408,8 @@ public: ws2D->mutableRun().addProperty("Ei", 13., "meV", true); pLattice = std::make_unique<Geometry::OrientedLattice>(3, 3, 2, 90, 90, 90); - ws2D->mutableSample().setOrientedLattice(pLattice.get()); + ws2D->mutableSample().setOrientedLattice( + std::make_unique<Geometry::OrientedLattice>(*pLattice)); // S_mantid*k_mantid = S_hor*k_hor; -- both Mantid and Horace produce the // same kind of crystal frame diff --git a/Framework/TestHelpers/src/SingleCrystalDiffractionTestHelper.cpp b/Framework/TestHelpers/src/SingleCrystalDiffractionTestHelper.cpp index d0506b75123..b1ec459c132 100644 --- a/Framework/TestHelpers/src/SingleCrystalDiffractionTestHelper.cpp +++ b/Framework/TestHelpers/src/SingleCrystalDiffractionTestHelper.cpp @@ -106,9 +106,9 @@ void WorkspaceBuilder::createPeaksWorkspace() { // Set the instrument to be the fake rectangular bank above. m_peaksWorkspace->setInstrument(m_instrument); // Set the oriented lattice for a cubic crystal - OrientedLattice ol(6, 6, 6, 90, 90, 90); - ol.setUFromVectors(V3D(6, 0, 0), V3D(0, 6, 0)); - m_peaksWorkspace->mutableSample().setOrientedLattice(&ol); + auto lattice = std::make_unique<OrientedLattice>(6, 6, 6, 90, 90, 90); + lattice->setUFromVectors(V3D(6, 0, 0), V3D(0, 6, 0)); + m_peaksWorkspace->mutableSample().setOrientedLattice(std::move(lattice)); } /** Create an empty event workspace diff --git a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp index 69756b1b455..1214b02df26 100644 --- a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp +++ b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp @@ -999,8 +999,8 @@ void addTSPEntry(Run &runInfo, std::string name, double val) { */ void setOrientedLattice(Mantid::API::MatrixWorkspace_sptr ws, double a, double b, double c) { - auto latt = std::make_unique<OrientedLattice>(a, b, c, 90., 90., 90.); - ws->mutableSample().setOrientedLattice(latt.release()); + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(a, b, c, 90., 90., 90.)); } // ===================================================================================== @@ -1040,8 +1040,8 @@ createProcessedWorkspaceWithCylComplexInstrument(size_t numPixels, pAxis0->setUnit("DeltaE"); 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()); + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.)); addTSPEntry(ws->mutableRun(), "phi", 0); addTSPEntry(ws->mutableRun(), "chi", 0); @@ -1117,8 +1117,8 @@ createProcessedInelasticWS(const std::vector<double> &L2, 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.); - ws->mutableSample().setOrientedLattice(latt.release()); + ws->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>(1, 1, 1, 90., 90., 90.)); ws->mutableRun().addProperty( new PropertyWithValue<std::string>("deltaE-mode", "Direct"), true); @@ -1324,8 +1324,8 @@ createPeaksWorkspace(const int numPeaks, const bool createOrientedLattice) { } if (createOrientedLattice) { - Mantid::Geometry::OrientedLattice lattice; - peaksWS->mutableSample().setOrientedLattice(&lattice); + peaksWS->mutableSample().setOrientedLattice( + std::make_unique<OrientedLattice>()); } return peaksWS; } diff --git a/qt/widgets/instrumentview/src/InstrumentWidgetPickTab.cpp b/qt/widgets/instrumentview/src/InstrumentWidgetPickTab.cpp index ccd43d92bdb..4ad382e409f 100644 --- a/qt/widgets/instrumentview/src/InstrumentWidgetPickTab.cpp +++ b/qt/widgets/instrumentview/src/InstrumentWidgetPickTab.cpp @@ -1825,9 +1825,9 @@ void DetectorPlotController::addPeak(double x, double y) { // if data WS has UB copy it to the new peaks workspace if (newPeaksWorkspace && ws->sample().hasOrientedLattice()) { auto UB = ws->sample().getOrientedLattice().getUB(); - auto lattice = new Mantid::Geometry::OrientedLattice; + auto lattice = std::make_unique<Mantid::Geometry::OrientedLattice>(); lattice->setUB(UB); - tw->mutableSample().setOrientedLattice(lattice); + tw->mutableSample().setOrientedLattice(std::move(lattice)); } // if there is a UB available calculate HKL for the new peak -- GitLab