Commit bf7c1cd1 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #7386. Safe detector position method.

parent 399f9b7d
......@@ -46,6 +46,7 @@ namespace API
virtual void setHKL(double H, double K, double L) = 0;
virtual void setHKL(Mantid::Kernel::V3D HKL) = 0;
virtual Mantid::Kernel::V3D getDetectorPosition() const = 0;
virtual Mantid::Kernel::V3D getDetectorPositionSafe() const = 0;
virtual Mantid::Kernel::V3D getQLabFrame() const = 0;
virtual Mantid::Kernel::V3D getQSampleFrame() const = 0;
......
......@@ -70,6 +70,7 @@ namespace DataObjects
Mantid::Kernel::V3D getQLabFrame() const;
Mantid::Kernel::V3D getQSampleFrame() const;
Mantid::Kernel::V3D getDetectorPosition() const;
Mantid::Kernel::V3D getDetectorPositionSafe() const;
void setQSampleFrame(Mantid::Kernel::V3D QSampleFrame, double detectorDistance=1.0);
void setQLabFrame(Mantid::Kernel::V3D QLabFrame, double detectorDistance=1.0);
......
......@@ -812,6 +812,22 @@ namespace DataObjects
return getDetector()->getPos();
}
/**
Forwarding function. Exposes the detector position directly, but checks that the detector is not null before
accessing its position. Throws if null.
*/
Mantid::Kernel::V3D Peak::getDetectorPositionSafe() const
{
auto det = getDetector();
if(det == NULL)
{
std::stringstream stream;
stream << "Peak at row " << this->m_Row;
throw Mantid::Kernel::Exception::NotFoundError("Detector cannot be found.", stream.str());
}
return getDetector()->getPos();
}
} // namespace Mantid
......
......@@ -330,6 +330,28 @@ public:
TS_ASSERT_EQUALS( p2.getDetectorID(), 19999);
}
void test_getDetectorPositionSafe()
{
const int detectorId = 19999;
const double wavelength = 2;
Peak p(inst, detectorId, wavelength);
V3D a = p.getDetectorPosition();
V3D b = p.getDetectorPositionSafe();
TSM_ASSERT_EQUALS("Results should be the same", a, b);
}
void test_getDetectorPositionThrows()
{
const int detectorId = 19999;
const double wavelength = 2;
Peak p(inst, detectorId, wavelength);
TSM_ASSERT_THROWS_NOTHING("Nothing wrong here, detector is valid", p.getDetectorPositionSafe());
p.setQLabFrame(V3D(1,1,1), 1); // This sets the detector pointer to null and detector id to -1;
TSM_ASSERT_THROWS("Detector is not valid", p.getDetectorPositionSafe(), Mantid::Kernel::Exception::NotFoundError&);
}
private:
void check_Contributing_Detectors(const Peak & peak, const std::vector<int> & expected)
{
......
Markdown is supported
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