Skip to content
Snippets Groups Projects
Commit b0922c77 authored by Bhuvan Bezawada's avatar Bhuvan Bezawada
Browse files

Removed unnecessary includes and also cleaned up code

re #23145
parent 248b1bbf
No related branches found
No related tags found
No related merge requests found
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
#include "MantidKernel/Quat.h" #include "MantidKernel/Quat.h"
#include "MantidKernel/V3D.h" #include "MantidKernel/V3D.h"
#include <utility>
using Mantid::Geometry::DetectorInfo; using Mantid::Geometry::DetectorInfo;
using Mantid::Kernel::Quat; using Mantid::Kernel::Quat;
using Mantid::Kernel::V3D; using Mantid::Kernel::V3D;
...@@ -14,9 +12,46 @@ using Mantid::Kernel::V3D; ...@@ -14,9 +12,46 @@ using Mantid::Kernel::V3D;
namespace Mantid { namespace Mantid {
namespace Geometry { 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 &copy; 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 { class MANTID_GEOMETRY_DLL DetectorInfoItem {
public: public:
// Provide copy and move constructors
DetectorInfoItem(const DetectorInfoItem &other) = default; DetectorInfoItem(const DetectorInfoItem &other) = default;
DetectorInfoItem &operator=(const DetectorInfoItem &rhs) = default; DetectorInfoItem &operator=(const DetectorInfoItem &rhs) = default;
DetectorInfoItem(DetectorInfoItem &&other) = default; DetectorInfoItem(DetectorInfoItem &&other) = default;
...@@ -43,6 +78,10 @@ public: ...@@ -43,6 +78,10 @@ public:
m_index + static_cast<size_t>(delta)); 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() { void incrementIndex() {
if (m_index < m_detectorInfo->size()) { if (m_index < m_detectorInfo->size()) {
++m_index; ++m_index;
......
...@@ -4,13 +4,44 @@ ...@@ -4,13 +4,44 @@
#include "MantidGeometry/Instrument/DetectorInfoItem.h" #include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include <boost/iterator/iterator_facade.hpp> #include <boost/iterator/iterator_facade.hpp>
#include <memory>
using Mantid::Geometry::DetectorInfoItem; using Mantid::Geometry::DetectorInfoItem;
namespace Mantid { namespace Mantid {
namespace Geometry { 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 &copy; 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 class MANTID_GEOMETRY_DLL DetectorInfoIterator
: public boost::iterator_facade<DetectorInfoIterator, : public boost::iterator_facade<DetectorInfoIterator,
const DetectorInfoItem &, const DetectorInfoItem &,
......
...@@ -5,12 +5,7 @@ ...@@ -5,12 +5,7 @@
#include "MantidGeometry/Instrument/DetectorInfoItem.h" #include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include "MantidGeometry/Instrument/DetectorInfoIterator.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/iterator.hpp>
#include <boost/python/module.hpp>
#include <boost/python/reference_existing_object.hpp>
using Mantid::Geometry::DetectorInfo; using Mantid::Geometry::DetectorInfo;
using Mantid::Geometry::DetectorInfoItem; using Mantid::Geometry::DetectorInfoItem;
...@@ -20,10 +15,47 @@ using namespace boost::python; ...@@ -20,10 +15,47 @@ using namespace boost::python;
namespace Mantid { namespace Mantid {
namespace Geometry { 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 &copy; 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 { class DetectorInfoPythonIterator {
public: public:
explicit DetectorInfoPythonIterator(const DetectorInfo &detectorInfo) 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() { const DetectorInfoItem &next() {
if (m_begin == m_end) { if (m_begin == m_end) {
......
#ifndef MANTID_GEOMETRY_DETECTORINFOITERATORTEST_H_ #ifndef MANTID_GEOMETRY_DETECTORINFOITERATORTEST_H_
#define 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/Detector.h"
#include "MantidGeometry/Instrument/DetectorInfo.h" #include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidGeometry/Instrument/DetectorInfoItem.h" #include "MantidGeometry/Instrument/DetectorInfoItem.h"
#include "MantidGeometry/Instrument/DetectorInfoIterator.h" #include "MantidGeometry/Instrument/DetectorInfoIterator.h"
#include "MantidGeometry/Instrument/InstrumentVisitor.h" #include "MantidGeometry/Instrument/InstrumentVisitor.h"
#include "MantidGeometry/Instrument/ParameterMap.h"
#include "MantidKernel/EigenConversionHelpers.h"
#include "MantidKernel/V3D.h"
#include "MantidTestHelpers/ComponentCreationHelper.h" #include "MantidTestHelpers/ComponentCreationHelper.h"
#include <algorithm>
#include <boost/make_shared.hpp>
#include <cxxtest/TestSuite.h> #include <cxxtest/TestSuite.h>
#include <set>
using Mantid::detid_t;
using Mantid::Kernel::V3D;
using namespace ComponentCreationHelper; using namespace ComponentCreationHelper;
using namespace Mantid::Geometry; using namespace Mantid::Geometry;
/** DetectorInfoIteratorTest
Test class for testing the iterator behaviour for DetectorInfoIterator.
@author Bhuvan Bezawada, STFC
@date 2018
Copyright &copy; 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 { class DetectorInfoIteratorTest : public CxxTest::TestSuite {
public: public:
// This pair of boilerplate methods prevent the suite being created statically // This pair of boilerplate methods prevent the suite being created statically
...@@ -33,7 +54,8 @@ public: ...@@ -33,7 +54,8 @@ public:
DetectorInfoIteratorTest(){}; 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 // Create a very basic instrument to visit
auto visitee = createMinimalInstrument(V3D(0, 0, 0), // Source position auto visitee = createMinimalInstrument(V3D(0, 0, 0), // Source position
...@@ -54,48 +76,35 @@ public: ...@@ -54,48 +76,35 @@ public:
// Create the instrument visitor // Create the instrument visitor
InstrumentVisitor visitor(visitee); InstrumentVisitor visitor(visitee);
// Visit everything // Return the DetectorInfo object
visitor.walkInstrument(); return InstrumentVisitor::makeWrappers(*visitee, nullptr).second;
// 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;
} }
void test_iterator_begin() { void test_iterator_begin() {
// Get the DetectorInfo object // Get the DetectorInfo object
auto detectorInfo = create_detector_info_object(); auto detectorInfo = create_detector_info_object();
auto iter = detectorInfo.begin(); auto iter = detectorInfo->begin();
// Check we start at the correct place // Check we start at the correct place
TS_ASSERT(iter != detectorInfo.end()); TS_ASSERT(iter != detectorInfo->end());
} }
void test_iterator_end() { void test_iterator_end() {
// Get the DetectorInfo object // Get the DetectorInfo object
auto detectorInfo = create_detector_info_object(); auto detectorInfo = create_detector_info_object();
auto iter = detectorInfo.end(); auto iter = detectorInfo->end();
// Check we start at the correct place // Check we start at the correct place
TS_ASSERT(iter != detectorInfo.begin()); TS_ASSERT(iter != detectorInfo->begin());
} }
void test_iterator_increment() { void test_iterator_increment() {
// Get the DetectorInfo object // Get the DetectorInfo object
auto detectorInfo = create_detector_info_object(); auto detectorInfo = create_detector_info_object();
auto iter = detectorInfo.begin(); auto iter = detectorInfo->begin();
// Check that we start at the beginning // Check that we start at the beginning
TS_ASSERT(iter == detectorInfo.begin()); TS_ASSERT(iter == detectorInfo->begin());
// Increment and check index // Increment and check index
for (int i = 0; i < 11; ++i) { for (int i = 0; i < 11; ++i) {
...@@ -104,16 +113,16 @@ public: ...@@ -104,16 +113,16 @@ public:
} }
// Check we've reached the end // Check we've reached the end
TS_ASSERT(iter == detectorInfo.end()); TS_ASSERT(iter == detectorInfo->end());
} }
void test_iterator_decrement() { void test_iterator_decrement() {
// Get the DetectorInfo object // Get the DetectorInfo object
auto detectorInfo = create_detector_info_object(); auto detectorInfo = create_detector_info_object();
auto iter = detectorInfo.end(); auto iter = detectorInfo->end();
// Check that we start at the end // Check that we start at the end
TS_ASSERT(iter == detectorInfo.end()); TS_ASSERT(iter == detectorInfo->end());
// Decrement and check index // Decrement and check index
for (int i = 11; i > 0; --i) { for (int i = 11; i > 0; --i) {
...@@ -122,13 +131,13 @@ public: ...@@ -122,13 +131,13 @@ public:
} }
// Check we've reached the beginning // Check we've reached the beginning
TS_ASSERT(iter == detectorInfo.begin()); TS_ASSERT(iter == detectorInfo->begin());
} }
void test_iterator_advance() { void test_iterator_advance() {
// Get the DetectorInfo object // Get the DetectorInfo object
auto detectorInfo = create_detector_info_object(); auto detectorInfo = create_detector_info_object();
auto iter = detectorInfo.begin(); auto iter = detectorInfo->begin();
// Advance 6 places // Advance 6 places
std::advance(iter, 6); std::advance(iter, 6);
...@@ -136,7 +145,7 @@ public: ...@@ -136,7 +145,7 @@ public:
// Go past end of valid range // Go past end of valid range
std::advance(iter, 8); std::advance(iter, 8);
TS_ASSERT(iter == detectorInfo.end()); TS_ASSERT(iter == detectorInfo->end());
// Go backwards // Go backwards
std::advance(iter, -2); std::advance(iter, -2);
...@@ -144,13 +153,13 @@ public: ...@@ -144,13 +153,13 @@ public:
// Go past the start // Go past the start
std::advance(iter, -100); std::advance(iter, -100);
TS_ASSERT(iter == detectorInfo.begin()); TS_ASSERT(iter == detectorInfo->begin());
} }
void test_copy_iterator() { void test_copy_iterator() {
// Get the DetectorInfo object // Get the DetectorInfo object
auto detectorInfo = create_detector_info_object(); auto detectorInfo = create_detector_info_object();
auto iter = detectorInfo.begin(); auto iter = detectorInfo->begin();
// Create a copy // Create a copy
auto iterCopy = DetectorInfoIterator(iter); auto iterCopy = DetectorInfoIterator(iter);
......
#include "MantidGeometry/Instrument/DetectorInfoIterator.h" #include "MantidGeometry/Instrument/DetectorInfoIterator.h"
#include <boost/python/class.hpp> #include <boost/python/class.hpp>
#include <boost/python/init.hpp>
#include <boost/python/module.hpp> #include <boost/python/module.hpp>
using Mantid::Geometry::DetectorInfoIterator; using Mantid::Geometry::DetectorInfoIterator;
......
...@@ -2,10 +2,8 @@ ...@@ -2,10 +2,8 @@
#include <boost/python/class.hpp> #include <boost/python/class.hpp>
#include <boost/python/copy_const_reference.hpp> #include <boost/python/copy_const_reference.hpp>
#include <boost/python/def.hpp>
#include <boost/python/iterator.hpp> #include <boost/python/iterator.hpp>
#include <boost/python/module.hpp> #include <boost/python/module.hpp>
#include <boost/python/reference_existing_object.hpp>
using Mantid::Geometry::DetectorInfoPythonIterator; using Mantid::Geometry::DetectorInfoPythonIterator;
using namespace boost::python; using namespace boost::python;
......
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