Skip to content
Snippets Groups Projects
Commit 15bd657e authored by Anton Piccardo-Selg's avatar Anton Piccardo-Selg
Browse files

Refs #13872 Add more labels to RLU

parent 3053603b
No related merge requests found
......@@ -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
......
......@@ -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
//----------------------------------------------------------------------------------------------
......
......@@ -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
......
......@@ -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());
......
......@@ -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);
......
......@@ -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);
......
......@@ -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() );
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment