From 15bd657effb490a4c0f94ffa5ca63664ab161987 Mon Sep 17 00:00:00 2001 From: Anton Piccardo-Selg <anton.piccardo-selg@tessella.com> Date: Fri, 16 Oct 2015 12:33:01 +0100 Subject: [PATCH] Refs #13872 Add more labels to RLU --- Framework/Kernel/inc/MantidKernel/MDUnit.h | 6 +++++ Framework/Kernel/src/MDUnit.cpp | 25 ++++++++++++++++--- Framework/Kernel/src/MDUnitFactory.cpp | 10 ++++---- Framework/Kernel/test/MDUnitTest.h | 12 +++++++++ Framework/SINQ/src/SINQHMListener.cpp | 3 ++- .../MantidTestHelpers/MDEventsTestHelper.h | 4 +-- Vates/VatesAPI/src/LoadVTK.cpp | 8 +++--- Vates/VatesAPI/test/LoadVTKTest.h | 4 +++ 8 files changed, 57 insertions(+), 15 deletions(-) diff --git a/Framework/Kernel/inc/MantidKernel/MDUnit.h b/Framework/Kernel/inc/MantidKernel/MDUnit.h index 2d9df34609a..7d339496728 100644 --- a/Framework/Kernel/inc/MantidKernel/MDUnit.h +++ b/Framework/Kernel/inc/MantidKernel/MDUnit.h @@ -54,10 +54,16 @@ public: /// Dimensionless RLU class DLLExport ReciprocalLatticeUnit : public QUnit { public: + ReciprocalLatticeUnit(); + ReciprocalLatticeUnit(const UnitLabel &unitLabel); UnitLabel getUnitLabel() const; bool canConvertTo(const MDUnit &other) const; ReciprocalLatticeUnit *clone() const; virtual ~ReciprocalLatticeUnit(); + +private: + bool isSpecialRLUUnitLabel() const; + UnitLabel m_unitLabel; }; /// Inverse Angstroms unit diff --git a/Framework/Kernel/src/MDUnit.cpp b/Framework/Kernel/src/MDUnit.cpp index 5dc249f5dbf..e995ba5e068 100644 --- a/Framework/Kernel/src/MDUnit.cpp +++ b/Framework/Kernel/src/MDUnit.cpp @@ -33,8 +33,19 @@ bool QUnit::isQUnit() const { return true; } //---------------------------------------------------------------------------------------------- // RLU //---------------------------------------------------------------------------------------------- +ReciprocalLatticeUnit::ReciprocalLatticeUnit() : m_unitLabel(UnitLabel("")) {} + +ReciprocalLatticeUnit::ReciprocalLatticeUnit(const UnitLabel &unitLabel) + : m_unitLabel(unitLabel) {} + +ReciprocalLatticeUnit::~ReciprocalLatticeUnit() {} + UnitLabel ReciprocalLatticeUnit::getUnitLabel() const { - return Units::Symbol::RLU; + if (isSpecialRLUUnitLabel()) { + return m_unitLabel; + } else { + return Units::Symbol::RLU; + } } bool ReciprocalLatticeUnit::canConvertTo(const MDUnit &other) const { @@ -42,10 +53,18 @@ bool ReciprocalLatticeUnit::canConvertTo(const MDUnit &other) const { } ReciprocalLatticeUnit *ReciprocalLatticeUnit::clone() const { - return new ReciprocalLatticeUnit; + if (isSpecialRLUUnitLabel()) { + return new ReciprocalLatticeUnit(m_unitLabel); + } else { + return new ReciprocalLatticeUnit; + } +} + +bool ReciprocalLatticeUnit::isSpecialRLUUnitLabel() const { + boost::regex pattern("in.*A.*\\^-1"); + return boost::regex_match(m_unitLabel.ascii(), pattern); } -ReciprocalLatticeUnit::~ReciprocalLatticeUnit() {} //---------------------------------------------------------------------------------------------- // End RLU //---------------------------------------------------------------------------------------------- diff --git a/Framework/Kernel/src/MDUnitFactory.cpp b/Framework/Kernel/src/MDUnitFactory.cpp index 286ec9f2f87..3b0371d9161 100644 --- a/Framework/Kernel/src/MDUnitFactory.cpp +++ b/Framework/Kernel/src/MDUnitFactory.cpp @@ -34,8 +34,8 @@ bool InverseAngstromsUnitFactory::canInterpret( } ReciprocalLatticeUnit * -ReciprocalLatticeUnitFactory::createRaw(const std::string &) const { - return new ReciprocalLatticeUnit; +ReciprocalLatticeUnitFactory::createRaw(const std::string & unitString) const { + return new ReciprocalLatticeUnit(UnitLabel(unitString)); } bool ReciprocalLatticeUnitFactory::canInterpret( @@ -44,15 +44,15 @@ bool ReciprocalLatticeUnitFactory::canInterpret( // In addition to having RLU we can encounter units of type "in 6.28 A^-1" // We need to account for the latter here - boost::regex pattern("in.*A\\^-1"); + boost::regex pattern("in.*A.*\\^-1"); auto isHoraceStyle = boost::regex_match(unitString, pattern); return isRLU || isHoraceStyle; } MDUnitFactory_uptr makeMDUnitFactoryChain() { typedef MDUnitFactory_uptr FactoryType; - auto first = FactoryType(new InverseAngstromsUnitFactory); - first->setSuccessor(FactoryType(new ReciprocalLatticeUnitFactory)) + auto first = FactoryType(new ReciprocalLatticeUnitFactory); + first->setSuccessor(FactoryType(new InverseAngstromsUnitFactory)) // Add more factories here! // Make sure that LabelUnitFactory is the last in the chain to give a fall // through diff --git a/Framework/Kernel/test/MDUnitTest.h b/Framework/Kernel/test/MDUnitTest.h index 17718f5806b..757fe99edf6 100644 --- a/Framework/Kernel/test/MDUnitTest.h +++ b/Framework/Kernel/test/MDUnitTest.h @@ -15,6 +15,18 @@ public: static MDUnitTest *createSuite() { return new MDUnitTest(); } static void destroySuite(MDUnitTest *suite) { delete suite; } + void test_RLU_Constructor_with_valid_special_unit_label_accepts_the_label() { + auto unitLabel = UnitLabel("in 1.992 A^-1"); + ReciprocalLatticeUnit unit(unitLabel); + TS_ASSERT_EQUALS(unitLabel.ascii(), unit.getUnitLabel().ascii()); + } + + void test_RLU_Constructor_with_invalid_special_unit_label_does_not_accept_the_label() { + auto unitLabel = UnitLabel("in invalidLabel A-1"); + ReciprocalLatticeUnit unit(unitLabel); + TS_ASSERT_EQUALS(Units::Symbol::RLU, unit.getUnitLabel()); + } + void test_RLU_getUnitLabel() { ReciprocalLatticeUnit unit; TS_ASSERT_EQUALS(Units::Symbol::RLU, unit.getUnitLabel()); diff --git a/Framework/SINQ/src/SINQHMListener.cpp b/Framework/SINQ/src/SINQHMListener.cpp index fd449cb9648..408cb99013c 100644 --- a/Framework/SINQ/src/SINQHMListener.cpp +++ b/Framework/SINQ/src/SINQHMListener.cpp @@ -102,8 +102,9 @@ boost::shared_ptr<Workspace> SINQHMListener::extractData() { std::vector<MDHistoDimension_sptr> dimensions; for (int i = 0; i < rank; i++) { + Mantid::Geometry::GeneralFrame frame(dimNames[i], ""); dimensions.push_back(MDHistoDimension_sptr(new MDHistoDimension( - dimNames[i], dimNames[i], "", .0, coord_t(dim[i]), dim[i]))); + dimNames[i], dimNames[i], frame, .0, coord_t(dim[i]), dim[i]))); } MDHistoWorkspace_sptr ws(new MDHistoWorkspace(dimensions)); ws->setTo(.0, .0, .0); diff --git a/Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h b/Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h index c2edb75dc8f..ab7872e02a2 100644 --- a/Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h +++ b/Framework/TestHelpers/inc/MantidTestHelpers/MDEventsTestHelper.h @@ -79,7 +79,7 @@ template <typename MDE, size_t nd> void addMDDimensionsWithIndividualFrames( boost::shared_ptr<Mantid::DataObjects::MDEventWorkspace<MDE, nd>> out, Mantid::coord_t min, Mantid::coord_t max, - std::vector<Mantid::Geometry::MDFrame_sptr> frame, + const std::vector<Mantid::Geometry::MDFrame_sptr>& frame, std::string axisNameFormat, std::string axisIdFormat) { for (size_t d = 0; d < nd; d++) { char name[200]; @@ -321,7 +321,7 @@ makeMDEWWithFrames(size_t splitInto, coord_t min, coord_t max, template <size_t nd> boost::shared_ptr<MDEventWorkspace<MDLeanEvent<nd>, nd>> makeMDEWWithIndividualFrames(size_t splitInto, coord_t min, coord_t max, - std::vector<Mantid::Geometry::MDFrame_sptr> frame, + const std::vector<Mantid::Geometry::MDFrame_sptr>& frame, size_t numEventsPerBox = 0) { return makeAnyMDEWWithIndividualFrames<MDLeanEvent<nd>, nd>(splitInto, min, max, frame, numEventsPerBox); diff --git a/Vates/VatesAPI/src/LoadVTK.cpp b/Vates/VatesAPI/src/LoadVTK.cpp index a003d1569f7..53c37ca3b04 100644 --- a/Vates/VatesAPI/src/LoadVTK.cpp +++ b/Vates/VatesAPI/src/LoadVTK.cpp @@ -321,12 +321,12 @@ namespace Mantid double bounds[6]; readDataset->ComputeBounds(); readDataset->GetBounds(bounds); - - auto dimX = boost::make_shared<MDHistoDimension>("X", "X", "", static_cast<coord_t>(bounds[0]), static_cast<coord_t>(bounds[1]), + Mantid::Geometry::UnknownFrame frame(""); + auto dimX = boost::make_shared<MDHistoDimension>("X", "X", frame, static_cast<coord_t>(bounds[0]), static_cast<coord_t>(bounds[1]), dimensions[0]); - auto dimY = boost::make_shared<MDHistoDimension>("Y", "Y", "", static_cast<coord_t>(bounds[2]), static_cast<coord_t>(bounds[3]), + auto dimY = boost::make_shared<MDHistoDimension>("Y", "Y", frame, static_cast<coord_t>(bounds[2]), static_cast<coord_t>(bounds[3]), dimensions[1]); - auto dimZ = boost::make_shared<MDHistoDimension>("Z", "Z", "", static_cast<coord_t>(bounds[4]), static_cast<coord_t>(bounds[5]), + auto dimZ = boost::make_shared<MDHistoDimension>("Z", "Z", frame, static_cast<coord_t>(bounds[4]), static_cast<coord_t>(bounds[5]), dimensions[2]); const int64_t nPoints = static_cast<int64_t>( readDataset->GetNumberOfPoints() ); diff --git a/Vates/VatesAPI/test/LoadVTKTest.h b/Vates/VatesAPI/test/LoadVTKTest.h index f8e46c2dee8..ee748126b01 100644 --- a/Vates/VatesAPI/test/LoadVTKTest.h +++ b/Vates/VatesAPI/test/LoadVTKTest.h @@ -133,6 +133,10 @@ public: do_check_dimension(outWS->getDimension(1), "Y", 0, 67, 68); // These numbers are expected min, max, and nbins known from the input file for dim y. do_check_dimension(outWS->getDimension(2), "Z", 0, 67, 68); // These numbers are expected min, max, and nbins known from the input file for dim z. + TSM_ASSERT_THROWS_NOTHING("Should be an UnknownFrame", dynamic_cast<const Mantid::Geometry::UnknownFrame&>(outWS->getDimension(0))) + TSM_ASSERT_THROWS_NOTHING("Should be an UnknownFrame", dynamic_cast<const Mantid::Geometry::UnknownFrame&>(outWS->getDimension(1))) + TSM_ASSERT_THROWS_NOTHING("Should be an UnknownFrame", dynamic_cast<const Mantid::Geometry::UnknownFrame&>(outWS->getDimension(2))) + double topPercent = loadVTK.getProperty("KeepTopPercent"); TSM_ASSERT_EQUALS("Should default to 25%", 25, topPercent); -- GitLab