diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h index 7ef8caa37a6688a1f77d4e7f49783b84a94b2b29..ff4487c5255adb9595da6c4884ae5d0a5a81b146 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h @@ -5,8 +5,6 @@ #include "MantidKernel/Quat.h" #include "MantidKernel/V3D.h" -#include <utility> - using Mantid::Geometry::DetectorInfo; using Mantid::Kernel::Quat; using Mantid::Kernel::V3D; @@ -14,9 +12,46 @@ using Mantid::Kernel::V3D; namespace Mantid { namespace Geometry { +/** DetectorInfoItem + +DetectorInfoItem is only created by DetectorInfoIterator and allows users of +the DetectorInfoIterator object access to data from DetectorInfo. The available +methods include: + - isMonitor() + - isMaksed() + - twoTheta() + - position() + - rotation() + +@author Bhuvan Bezawada, STFC +@date 2018 + +Copyright © 2018 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ + class MANTID_GEOMETRY_DLL DetectorInfoItem { public: + // Provide copy and move constructors DetectorInfoItem(const DetectorInfoItem &other) = default; DetectorInfoItem &operator=(const DetectorInfoItem &rhs) = default; DetectorInfoItem(DetectorInfoItem &&other) = default; @@ -43,6 +78,10 @@ public: m_index + static_cast<size_t>(delta)); } + // This could cause a segmentation fault if a user goes past the end of the + // iterator and tries to index into the n+1 th element (which would not + // exist). Adding range checks to all the above methods may slow down + // performance though. void incrementIndex() { if (m_index < m_detectorInfo->size()) { ++m_index; diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h index 671d46bad31bd9255acf6e9265317ab96a81c1b7..322ff622ec3c42a9aeb62df070deeb6ca4297287 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h @@ -4,13 +4,44 @@ #include "MantidGeometry/Instrument/DetectorInfoItem.h" #include <boost/iterator/iterator_facade.hpp> -#include <memory> using Mantid::Geometry::DetectorInfoItem; namespace Mantid { namespace Geometry { +/** DetectorInfoIterator + +DetectorInfoIterator allows users of the DetectorInfo object access to data +via an iterator. The iterator works as a slice view in that the index is +incremented and all items accessible at that index are made available via the +iterator. + +@author Bhuvan Bezawada, STFC +@date 2018 + +Copyright © 2018 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ + class MANTID_GEOMETRY_DLL DetectorInfoIterator : public boost::iterator_facade<DetectorInfoIterator, const DetectorInfoItem &, diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoPythonIterator.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoPythonIterator.h index 1a3b20cc4a581a661578f0ccf5deead88cb0ffc8..4d7e884c9d5cee9a49f1739a01e783b2cc50de9d 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoPythonIterator.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoPythonIterator.h @@ -5,12 +5,7 @@ #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> #include <boost/python/iterator.hpp> -#include <boost/python/module.hpp> -#include <boost/python/reference_existing_object.hpp> using Mantid::Geometry::DetectorInfo; using Mantid::Geometry::DetectorInfoItem; @@ -20,10 +15,47 @@ using namespace boost::python; namespace Mantid { namespace Geometry { +/** DetectorInfoPythonIterator + +DetectorInfoPythonIterator is used to expose DetectorInfoIterator to the Python +side. From Python the user will be able to use more pythonic loop syntax to +access data such as: +- isMonitor() +- isMaksed() +- twoTheta() +- position() +- rotation() +without the need for indexes. +@author Bhuvan Bezawada, STFC +@date 2018 + +Copyright © 2018 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ + class DetectorInfoPythonIterator { public: explicit DetectorInfoPythonIterator(const DetectorInfo &detectorInfo) - : m_begin(detectorInfo.begin()), m_end(detectorInfo.end()), m_current(*m_begin) {} + : m_begin(detectorInfo.begin()), m_end(detectorInfo.end()), + m_current(*m_begin) {} const DetectorInfoItem &next() { if (m_begin == m_end) { diff --git a/Framework/Geometry/test/DetectorInfoIteratorTest.h b/Framework/Geometry/test/DetectorInfoIteratorTest.h index 67c516b7b3188d78a79c04ff56ab91900eeb940e..b58dc886b9524c2204ba39ff7c9bf7b4937dfc5d 100644 --- a/Framework/Geometry/test/DetectorInfoIteratorTest.h +++ b/Framework/Geometry/test/DetectorInfoIteratorTest.h @@ -1,27 +1,48 @@ #ifndef MANTID_GEOMETRY_DETECTORINFOITERATORTEST_H_ #define MANTID_GEOMETRY_DETECTORINFOITERATORTEST_H_ -#include "MantidBeamline/DetectorInfo.h" +#include "MantidGeometry/Instrument/ComponentInfo.h" #include "MantidGeometry/Instrument/Detector.h" #include "MantidGeometry/Instrument/DetectorInfo.h" #include "MantidGeometry/Instrument/DetectorInfoItem.h" #include "MantidGeometry/Instrument/DetectorInfoIterator.h" #include "MantidGeometry/Instrument/InstrumentVisitor.h" -#include "MantidGeometry/Instrument/ParameterMap.h" -#include "MantidKernel/EigenConversionHelpers.h" -#include "MantidKernel/V3D.h" #include "MantidTestHelpers/ComponentCreationHelper.h" -#include <algorithm> -#include <boost/make_shared.hpp> #include <cxxtest/TestSuite.h> -#include <set> -using Mantid::detid_t; -using Mantid::Kernel::V3D; using namespace ComponentCreationHelper; using namespace Mantid::Geometry; +/** DetectorInfoIteratorTest + +Test class for testing the iterator behaviour for DetectorInfoIterator. + +@author Bhuvan Bezawada, STFC +@date 2018 + +Copyright © 2018 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +This file is part of Mantid. + +Mantid is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +Mantid is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. + +File change history is stored at: <https://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ + class DetectorInfoIteratorTest : public CxxTest::TestSuite { public: // This pair of boilerplate methods prevent the suite being created statically @@ -33,7 +54,8 @@ public: DetectorInfoIteratorTest(){}; - Mantid::Geometry::DetectorInfo create_detector_info_object() { + std::unique_ptr<Mantid::Geometry::DetectorInfo> + create_detector_info_object() { // Create a very basic instrument to visit auto visitee = createMinimalInstrument(V3D(0, 0, 0), // Source position @@ -54,48 +76,35 @@ public: // Create the instrument visitor InstrumentVisitor visitor(visitee); - // Visit everything - visitor.walkInstrument(); - - // Create the Beamline DetectorInfo - auto detInfo = visitor.detectorInfo(); - - // Get details from DetectorInfo - auto detIds = visitor.detectorIds(); - auto detMap = visitor.detectorIdToIndexMap(); - - // Create the Geometry DetectorInfo - Mantid::Geometry::DetectorInfo detectorInfo{visitor.detectorInfo(), visitee, - detIds, detMap}; - - return detectorInfo; + // Return the DetectorInfo object + return InstrumentVisitor::makeWrappers(*visitee, nullptr).second; } void test_iterator_begin() { // Get the DetectorInfo object auto detectorInfo = create_detector_info_object(); - auto iter = detectorInfo.begin(); + auto iter = detectorInfo->begin(); // Check we start at the correct place - TS_ASSERT(iter != detectorInfo.end()); + TS_ASSERT(iter != detectorInfo->end()); } void test_iterator_end() { // Get the DetectorInfo object auto detectorInfo = create_detector_info_object(); - auto iter = detectorInfo.end(); + auto iter = detectorInfo->end(); // Check we start at the correct place - TS_ASSERT(iter != detectorInfo.begin()); + TS_ASSERT(iter != detectorInfo->begin()); } void test_iterator_increment() { // Get the DetectorInfo object auto detectorInfo = create_detector_info_object(); - auto iter = detectorInfo.begin(); + auto iter = detectorInfo->begin(); // Check that we start at the beginning - TS_ASSERT(iter == detectorInfo.begin()); + TS_ASSERT(iter == detectorInfo->begin()); // Increment and check index for (int i = 0; i < 11; ++i) { @@ -104,16 +113,16 @@ public: } // Check we've reached the end - TS_ASSERT(iter == detectorInfo.end()); + TS_ASSERT(iter == detectorInfo->end()); } void test_iterator_decrement() { // Get the DetectorInfo object auto detectorInfo = create_detector_info_object(); - auto iter = detectorInfo.end(); + auto iter = detectorInfo->end(); // Check that we start at the end - TS_ASSERT(iter == detectorInfo.end()); + TS_ASSERT(iter == detectorInfo->end()); // Decrement and check index for (int i = 11; i > 0; --i) { @@ -122,13 +131,13 @@ public: } // Check we've reached the beginning - TS_ASSERT(iter == detectorInfo.begin()); + TS_ASSERT(iter == detectorInfo->begin()); } void test_iterator_advance() { // Get the DetectorInfo object auto detectorInfo = create_detector_info_object(); - auto iter = detectorInfo.begin(); + auto iter = detectorInfo->begin(); // Advance 6 places std::advance(iter, 6); @@ -136,7 +145,7 @@ public: // Go past end of valid range std::advance(iter, 8); - TS_ASSERT(iter == detectorInfo.end()); + TS_ASSERT(iter == detectorInfo->end()); // Go backwards std::advance(iter, -2); @@ -144,13 +153,13 @@ public: // Go past the start std::advance(iter, -100); - TS_ASSERT(iter == detectorInfo.begin()); + TS_ASSERT(iter == detectorInfo->begin()); } void test_copy_iterator() { // Get the DetectorInfo object auto detectorInfo = create_detector_info_object(); - auto iter = detectorInfo.begin(); + auto iter = detectorInfo->begin(); // Create a copy auto iterCopy = DetectorInfoIterator(iter); diff --git a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoIterator.cpp b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoIterator.cpp index 0281819441dcd85a2c052374fdb28e0ff3f039ac..29db1668f095129720efba7bec1ecd16ac4b229a 100644 --- a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoIterator.cpp +++ b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoIterator.cpp @@ -1,7 +1,6 @@ #include "MantidGeometry/Instrument/DetectorInfoIterator.h" #include <boost/python/class.hpp> -#include <boost/python/init.hpp> #include <boost/python/module.hpp> using Mantid::Geometry::DetectorInfoIterator; diff --git a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoPythonIterator.cpp b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoPythonIterator.cpp index 090468e0f9c05a12eb49602ddafa759521c3fa65..6968fba9c54600e8fb6bfbfe06bb251d5c799e44 100644 --- a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoPythonIterator.cpp +++ b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoPythonIterator.cpp @@ -2,10 +2,8 @@ #include <boost/python/class.hpp> #include <boost/python/copy_const_reference.hpp> -#include <boost/python/def.hpp> #include <boost/python/iterator.hpp> #include <boost/python/module.hpp> -#include <boost/python/reference_existing_object.hpp> using Mantid::Geometry::DetectorInfoPythonIterator; using namespace boost::python;