diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h index ef79b40ce9227367a42861f72cde481a53665c68..7ef8caa37a6688a1f77d4e7f49783b84a94b2b29 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h @@ -1,13 +1,15 @@ #ifndef MANTID_GEOMETRY_DETECTORINFOITEM_H_ #define MANTID_GEOMETRY_DETECTORINFOITEM_H_ -#include <utility> - #include "MantidGeometry/Instrument/DetectorInfo.h" +#include "MantidKernel/Quat.h" #include "MantidKernel/V3D.h" -using Mantid::Kernel::V3D; +#include <utility> + using Mantid::Geometry::DetectorInfo; +using Mantid::Kernel::Quat; +using Mantid::Kernel::V3D; namespace Mantid { namespace Geometry { @@ -20,8 +22,18 @@ public: DetectorInfoItem(DetectorInfoItem &&other) = default; DetectorInfoItem &operator=(DetectorInfoItem &&rhs) = default; + bool isMonitor() const { return m_detectorInfo->isMonitor(m_index); } + + bool isMasked() const { return m_detectorInfo->isMasked(m_index); } + + double twoTheta() const { return m_detectorInfo->twoTheta(m_index); } + Mantid::Kernel::V3D position() const { - return m_detectorInfo->position(m_index); + return m_detectorInfo->position(m_index); + } + + Mantid::Kernel::Quat rotation() const { + return m_detectorInfo->rotation(m_index); } void advance(int64_t delta) { @@ -54,8 +66,8 @@ private: DetectorInfoItem(const DetectorInfo &detectorInfo, const size_t index) : m_detectorInfo(&detectorInfo), m_index(index) {} - // Non-owning pointer. A reference makes the class unable to define assignment - // operator that we need. + // Non-owning pointer. A reference makes the class unable to define an + // assignment operator that we need. const DetectorInfo *m_detectorInfo; size_t m_index; }; diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h index 18658a4818f08d4e8ed7d300338c982f80b6d9fc..671d46bad31bd9255acf6e9265317ab96a81c1b7 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h @@ -1,11 +1,11 @@ #ifndef MANTID_GEOMETRY_DETECTORINFOITERATOR_H_ #define MANTID_GEOMETRY_DETECTORINFOITERATOR_H_ +#include "MantidGeometry/Instrument/DetectorInfoItem.h" + #include <boost/iterator/iterator_facade.hpp> #include <memory> -#include "MantidGeometry/Instrument/DetectorInfoItem.h" - using Mantid::Geometry::DetectorInfoItem; namespace Mantid { @@ -17,7 +17,8 @@ class MANTID_GEOMETRY_DLL DetectorInfoIterator boost::bidirectional_traversal_tag> { public: - DetectorInfoIterator(const DetectorInfo& owner, const size_t index) : m_item(owner, index) {} + DetectorInfoIterator(const DetectorInfo &detectorInfo, const size_t index) + : m_item(detectorInfo, index) {} private: friend class boost::iterator_core_access; diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoPythonIterator.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoPythonIterator.h index 8554ace7dd2241767a9ece43600d11258e267152..1a3b20cc4a581a661578f0ccf5deead88cb0ffc8 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoPythonIterator.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoPythonIterator.h @@ -1,6 +1,10 @@ #ifndef MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_ #define MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_ +#include "MantidGeometry/Instrument/DetectorInfo.h" +#include "MantidGeometry/Instrument/DetectorInfoItem.h" +#include "MantidGeometry/Instrument/DetectorInfoIterator.h" + #include <boost/python/class.hpp> #include <boost/python/copy_const_reference.hpp> #include <boost/python/def.hpp> @@ -8,14 +12,9 @@ #include <boost/python/module.hpp> #include <boost/python/reference_existing_object.hpp> -#include "MantidGeometry/Instrument/DetectorInfo.h" -#include "MantidGeometry/Instrument/DetectorInfoItem.h" -#include "MantidGeometry/Instrument/DetectorInfoIterator.h" - using Mantid::Geometry::DetectorInfo; using Mantid::Geometry::DetectorInfoItem; using Mantid::Geometry::DetectorInfoIterator; - using namespace boost::python; namespace Mantid { @@ -23,8 +22,8 @@ namespace Geometry { class DetectorInfoPythonIterator { public: - explicit DetectorInfoPythonIterator(const DetectorInfo &source) - : m_begin(source.begin()), m_end(source.end()), m_current(*m_begin) {} + explicit DetectorInfoPythonIterator(const DetectorInfo &detectorInfo) + : m_begin(detectorInfo.begin()), m_end(detectorInfo.end()), m_current(*m_begin) {} const DetectorInfoItem &next() { if (m_begin == m_end) { @@ -42,4 +41,5 @@ private: } // namespace Geometry } // namespace Mantid + #endif /* MANTID_GEOMETRY_DETECTORINFOPYTHONITERATOR_H_ */ diff --git a/Framework/Geometry/src/Instrument/DetectorInfo.cpp b/Framework/Geometry/src/Instrument/DetectorInfo.cpp index c430dc84973ef33cb5fa2a9ac59cd56ea26aa45d..958d0d4f39338af7fc25988aa5716129c513ebd7 100644 --- a/Framework/Geometry/src/Instrument/DetectorInfo.cpp +++ b/Framework/Geometry/src/Instrument/DetectorInfo.cpp @@ -389,10 +389,12 @@ DetectorInfo::getDetectorPtr(const size_t index) const { return m_lastDetector[thread]; } +// Begin method for iterator DetectorInfoIterator DetectorInfo::begin() const { return DetectorInfoIterator(*this, 0); } +// End method for iterator DetectorInfoIterator DetectorInfo::end() const { return DetectorInfoIterator(*this, size()); } diff --git a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfo.cpp b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfo.cpp index 8f85905e75a91a7dfc403c0cf4aabf5547fa5285..6cc4bbd73fc9bb9bba63ce03543612ab1b1fa201 100644 --- a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfo.cpp +++ b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfo.cpp @@ -1,6 +1,10 @@ #include "MantidGeometry/Instrument/DetectorInfo.h" +#include "MantidGeometry/Instrument/DetectorInfoItem.h" +#include "MantidGeometry/Instrument/DetectorInfoIterator.h" +#include "MantidGeometry/Instrument/DetectorInfoPythonIterator.h" #include "MantidKernel/Quat.h" #include "MantidKernel/V3D.h" + #include <boost/iterator/iterator_facade.hpp> #include <boost/python/class.hpp> #include <boost/python/copy_const_reference.hpp> @@ -10,11 +14,6 @@ #include <boost/python/return_value_policy.hpp> #include <iterator> - -#include "MantidGeometry/Instrument/DetectorInfoItem.h" -#include "MantidGeometry/Instrument/DetectorInfoIterator.h" -#include "MantidGeometry/Instrument/DetectorInfoPythonIterator.h" - using Mantid::Geometry::DetectorInfo; using Mantid::Geometry::DetectorInfoItem; using Mantid::Geometry::DetectorInfoIterator; @@ -24,10 +23,12 @@ using Mantid::Kernel::Quat; using Mantid::Kernel::V3D; using namespace boost::python; -DetectorInfoPythonIterator make_pyiterator(const DetectorInfo &source) { - return DetectorInfoPythonIterator(source); +// Helper method to make the python iterator +DetectorInfoPythonIterator make_pyiterator(const DetectorInfo &detectorInfo) { + return DetectorInfoPythonIterator(detectorInfo); }; +// Export DetectorInfo void export_DetectorInfo() { // Function pointers to distinguish between overloaded versions diff --git a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoItem.cpp b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoItem.cpp index e7b7609116823914f687eb288e28952514612b34..567fab39109e53c240757ecf2d5321963be59d03 100644 --- a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoItem.cpp +++ b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoItem.cpp @@ -1,16 +1,21 @@ -#include <boost/python/class.hpp> -#include <boost/python/module.hpp> - #include "MantidGeometry/Instrument/DetectorInfoItem.h" #include "MantidKernel/V3D.h" +#include <boost/python/class.hpp> +#include <boost/python/module.hpp> + using Mantid::Geometry::DetectorInfoItem; using Mantid::Kernel::V3D; using namespace boost::python; +// Export DetectorInfoItem void export_DetectorInfoItem() { // Export to Python class_<DetectorInfoItem>("DetectorInfoItem", no_init) - .add_property("position", &DetectorInfoItem::position); + .add_property("isMonitor", &DetectorInfoItem::isMonitor) + .add_property("isMasked", &DetectorInfoItem::isMasked) + .add_property("twoTheta", &DetectorInfoItem::twoTheta) + .add_property("position", &DetectorInfoItem::position) + .add_property("rotation", &DetectorInfoItem::rotation); } diff --git a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoIterator.cpp b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoIterator.cpp index 9a25a1877376b114ce2b167b0d1be1c2ec10585f..0281819441dcd85a2c052374fdb28e0ff3f039ac 100644 --- a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoIterator.cpp +++ b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoIterator.cpp @@ -1,14 +1,16 @@ +#include "MantidGeometry/Instrument/DetectorInfoIterator.h" + #include <boost/python/class.hpp> -#include <boost/python/module.hpp> #include <boost/python/init.hpp> - -#include "MantidGeometry/Instrument/DetectorInfoIterator.h" +#include <boost/python/module.hpp> using Mantid::Geometry::DetectorInfoIterator; using namespace boost::python; +// Export DetectorInfoIterator void export_DetectorInfoIterator() { // Export to Python - class_<DetectorInfoIterator, boost::noncopyable>("DetectorInfoIterator", no_init); + class_<DetectorInfoIterator, boost::noncopyable>("DetectorInfoIterator", + no_init); } diff --git a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoPythonIterator.cpp b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoPythonIterator.cpp index 81faf22bb974d31fc2bb90a8cd0b21639db71c5b..090468e0f9c05a12eb49602ddafa759521c3fa65 100644 --- a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoPythonIterator.cpp +++ b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoPythonIterator.cpp @@ -1,3 +1,5 @@ +#include "MantidGeometry/Instrument/DetectorInfoPythonIterator.h" + #include <boost/python/class.hpp> #include <boost/python/copy_const_reference.hpp> #include <boost/python/def.hpp> @@ -5,25 +7,22 @@ #include <boost/python/module.hpp> #include <boost/python/reference_existing_object.hpp> -#include "MantidGeometry/Instrument/DetectorInfoPythonIterator.h" - -using namespace boost::python; using Mantid::Geometry::DetectorInfoPythonIterator; +using namespace boost::python; +// Export DetectorInfoPythonIterator void export_DetectorInfoPythonIterator() { // Export to Python class_<DetectorInfoPythonIterator>("DetectorInfoPythonIterator", no_init) - .def("__iter__", objects::identity_function()) - .def( + .def("__iter__", objects::identity_function()) + .def( #if PY_VERSION_HEX >= 0x03000000 - "__next__" -#else - "next" + "__next__" +#else + "next" #endif - , - &DetectorInfoPythonIterator::next, - return_value_policy<copy_const_reference>()); - - //def("detectorInfo", detectorInfo, return_value_policy<reference_existing_object>()); -} \ No newline at end of file + , + &DetectorInfoPythonIterator::next, + return_value_policy<copy_const_reference>()); +} diff --git a/Framework/PythonInterface/test/python/mantid/geometry/DetectorInfoTest.py b/Framework/PythonInterface/test/python/mantid/geometry/DetectorInfoTest.py index 26844dbbf2906a6398bc83397a8ac507f3db9150..9edff2ba62fa09a7d67f6d72e82a5c87d7b252dc 100644 --- a/Framework/PythonInterface/test/python/mantid/geometry/DetectorInfoTest.py +++ b/Framework/PythonInterface/test/python/mantid/geometry/DetectorInfoTest.py @@ -106,11 +106,31 @@ class DetectorInfoTest(unittest.TestCase): --------------- """ + def test_iteration_for_isMonitor(self): + info = self._ws.detectorInfo() + for detInfo in info: + self.assertEquals(type(detInfo.isMonitor), bool) + + def test_iteration_for_isMasked(self): + info = self._ws.detectorInfo() + for detInfo in info: + self.assertEquals(type(detInfo.isMasked), bool) + + def test_iteration_for_twoTheta(self): + info = self._ws.detectorInfo() + for detInfo in info: + self.assertEquals(type(detInfo.twoTheta), float) + def test_iteration_for_position(self): info = self._ws.detectorInfo() for detInfo in info: self.assertEquals(type(detInfo.position), V3D) + def test_iteration_for_rotation(self): + info = self._ws.detectorInfo() + for detInfo in info: + self.assertEquals(type(detInfo.rotation), Quat) + """ ----------------------------------------------------------------------------