diff --git a/Framework/API/test/DetectorInfoTest.h b/Framework/API/test/DetectorInfoTest.h index e26952906731d6d670be3ca63c1699e86a5ced37..0627189da66d900faeee03e96824e1b9a1651f7e 100644 --- a/Framework/API/test/DetectorInfoTest.h +++ b/Framework/API/test/DetectorInfoTest.h @@ -3,9 +3,9 @@ #include <cxxtest/TestSuite.h> +#include "MantidAPI/WorkspaceFactory.h" #include "MantidGeometry/Instrument/ComponentInfo.h" #include "MantidGeometry/Instrument/DetectorInfo.h" -#include "MantidAPI/WorkspaceFactory.h" #include "MantidTestHelpers/ComponentCreationHelper.h" #include "MantidTestHelpers/FakeObjects.h" #include "MantidTestHelpers/InstrumentCreationHelper.h" @@ -393,8 +393,8 @@ public: size_t numberOfBins = 1; workspace.initialize(numberOfHistograms, numberOfBins + 1, numberOfBins); for (int32_t i = 0; i < numberOfHistograms; ++i) - workspace.getSpectrum(i) - .setSpectrumNo(static_cast<int32_t>(numberOfHistograms) - i); + workspace.getSpectrum(i).setSpectrumNo( + static_cast<int32_t>(numberOfHistograms) - i); bool includeMonitors = false; bool startYNegative = true; const std::string instrumentName("SimpleFakeInstrument"); diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfo.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfo.h index a20f9002e6c78266d6c27753e6802a70d98a486a..c8b4dc130a5d01b4742c06a97dbb8bbfe6bf324a 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfo.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfo.h @@ -1,19 +1,16 @@ #ifndef MANTID_GEOMETRY_DETECTORINFO_H_ #define MANTID_GEOMETRY_DETECTORINFO_H_ -#include "MantidGeometry/DllConfig.h" -#include "MantidKernel/DateAndTime.h" -#include "MantidKernel/Quat.h" -#include "MantidKernel/V3D.h" - -//#include "MantidGeometry/Instrument/DetectorInfoIterator.h" - #include <boost/shared_ptr.hpp> - #include <mutex> #include <unordered_map> #include <vector> +#include "MantidGeometry/DllConfig.h" +#include "MantidKernel/DateAndTime.h" +#include "MantidKernel/Quat.h" +#include "MantidKernel/V3D.h" + namespace Mantid { using detid_t = int32_t; namespace Beamline { diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h index 86c1417de959de1837ac82a7b2c3951c96113c75..1776e45861644692e4a14f1952574a177749d2e1 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoItem.h @@ -13,12 +13,10 @@ namespace Geometry { class MANTID_GEOMETRY_DLL DetectorInfoItem { public: - DetectorInfoItem(const DetectorInfoItem ©) - : m_detectorInfo(copy.m_detectorInfo), m_index(copy.m_index) { - } + : m_detectorInfo(copy.m_detectorInfo), m_index(copy.m_index) {} - DetectorInfoItem& operator=(const DetectorInfoItem &rhs) { + DetectorInfoItem &operator=(const DetectorInfoItem &rhs) { this->m_index = rhs.m_index; return *this; } @@ -62,10 +60,10 @@ private: // Variables to hold data const DetectorInfo &m_detectorInfo; - size_t m_index; + size_t m_index = 0; }; } // namespace Geometry } // namespace Mantid -#endif +#endif /* MANTID_GEOMETRY_DETECTORINFOITEM_H_ */ diff --git a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h index cc3879dabdf050c2d97075a9fc9a0727935fa853..7bdf19eabd26de6987e650e66cf05a4329c1b6fc 100644 --- a/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h +++ b/Framework/Geometry/inc/MantidGeometry/Instrument/DetectorInfoIterator.h @@ -2,12 +2,11 @@ #ifndef MANTID_GEOMETRY_DETECTORINFOITERATOR_H_ #define MANTID_GEOMETRY_DETECTORINFOITERATOR_H_ -//#include "MantidGeometry/Instrument/DetectorInfo.h" -#include "MantidGeometry/Instrument/DetectorInfoItem.h" - #include <boost/iterator/iterator_facade.hpp> #include <memory> +#include "MantidGeometry/Instrument/DetectorInfoItem.h" + namespace Mantid { namespace Geometry { @@ -20,10 +19,13 @@ class MANTID_GEOMETRY_DLL DetectorInfoIterator public: DetectorInfoIterator(const DetectorInfo &detectorInfo, const size_t index) - : m_item(detectorInfo, index), m_detectorInfo(detectorInfo), m_index(index) {} + : m_item(detectorInfo, index) { + } // m_detectorInfo(detectorInfo), m_index(index) {} - DetectorInfoIterator(const DetectorInfoIterator&detInfoIterator) : - m_index(detInfoIterator.m_index), m_detectorInfo(detInfoIterator.m_detectorInfo), m_item(detInfoIterator.m_detectorInfo, detInfoIterator.m_index) {} + DetectorInfoIterator(const DetectorInfoIterator &detInfoIterator) + : m_item(detInfoIterator.m_item) { + } // m_detectorInfo(detInfoIterator.m_detectorInfo), + // m_item(detInfoIterator.m_detectorInfo, detInfoIterator.m_index) {} private: friend class boost::iterator_core_access; @@ -46,11 +48,11 @@ private: } DetectorInfoItem m_item; - DetectorInfo m_detectorInfo; - size_t m_index; + // DetectorInfo m_detectorInfo; + // size_t m_index; }; } // namespace Geometry } // namespace Mantid -#endif +#endif /* MANTID_GEOMETRY_DETECTORINFOITERATOR_H_ */ diff --git a/Framework/Geometry/src/Instrument/DetectorInfo.cpp b/Framework/Geometry/src/Instrument/DetectorInfo.cpp index 92c3a12cf3d3ccce52f964d1d08dc3d4277d387a..3b92f76be5873fe6201d0f592a4f8c8cabb34a7d 100644 --- a/Framework/Geometry/src/Instrument/DetectorInfo.cpp +++ b/Framework/Geometry/src/Instrument/DetectorInfo.cpp @@ -1,15 +1,14 @@ +#include "MantidGeometry/Instrument/DetectorInfo.h" +#include "MantidBeamline/DetectorInfo.h" #include "MantidGeometry/Instrument.h" #include "MantidGeometry/Instrument/Detector.h" -#include "MantidGeometry/Instrument/DetectorInfo.h" +#include "MantidGeometry/Instrument/DetectorInfoIterator.h" #include "MantidGeometry/Instrument/ReferenceFrame.h" -#include "MantidBeamline/DetectorInfo.h" #include "MantidKernel/EigenConversionHelpers.h" #include "MantidKernel/Exception.h" #include "MantidKernel/MultiThreaded.h" #include "MantidKernel/make_unique.h" -#include "MantidGeometry/Instrument/DetectorInfoIterator.h" - namespace Mantid { namespace Geometry { @@ -346,8 +345,9 @@ DetectorInfo::scanInterval(const std::pair<size_t, size_t> &index) const { * i.e., time intervals must be set with this method before merging individual * scans. */ void DetectorInfo::setScanInterval( - const size_t index, const std::pair<Types::Core::DateAndTime, - Types::Core::DateAndTime> &interval) { + const size_t index, + const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> + &interval) { m_detectorInfo->setScanInterval(index, {interval.first.totalNanoseconds(), interval.second.totalNanoseconds()}); } @@ -356,8 +356,9 @@ void DetectorInfo::setScanInterval( * * Prefer this over setting intervals for individual detectors since it enables * internal performance optimization. See also overload for other details. */ -void DetectorInfo::setScanInterval(const std::pair< - Types::Core::DateAndTime, Types::Core::DateAndTime> &interval) { +void DetectorInfo::setScanInterval( + const std::pair<Types::Core::DateAndTime, Types::Core::DateAndTime> + &interval) { m_detectorInfo->setScanInterval( {interval.first.totalNanoseconds(), interval.second.totalNanoseconds()}); } diff --git a/Framework/Geometry/test/DetectorInfoIteratorTest.h b/Framework/Geometry/test/DetectorInfoIteratorTest.h index 2eecf7c80de9661d38433b48823b4729385240ad..cb6f5ea05831eab347456cea423fb772c4be06d5 100644 --- a/Framework/Geometry/test/DetectorInfoIteratorTest.h +++ b/Framework/Geometry/test/DetectorInfoIteratorTest.h @@ -164,7 +164,7 @@ public: auto iter = detectorInfo.begin(); auto iterCopy = DetectorInfoIterator(iter); - + TS_ASSERT_EQUALS(iter->getIndex(), 0); TS_ASSERT_EQUALS(iterCopy->getIndex(), 0); @@ -178,8 +178,8 @@ public: TS_ASSERT_EQUALS(iterCopy->getIndex(), 1); TS_ASSERT_EQUALS(iter->position(), 1); - TS_ASSERT_EQUALS(iterCopy->position(),1); + TS_ASSERT_EQUALS(iterCopy->position(), 1); } }; -#endif /* MANTID_HISTOGRAMDATA_HISTOGRAMITERATORTEST_H_ */ +#endif /* MANTID_GEOMETRY_DETECTORINFOITERATORTEST_H_ */ diff --git a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfo.cpp b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfo.cpp index 3742b82b5e53c88208edc528bdf20c86a28ae47f..dee9a394921bb6bb843dcc9f36cb8d9bd3753272 100644 --- a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfo.cpp +++ b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfo.cpp @@ -1,22 +1,21 @@ #include "MantidGeometry/Instrument/DetectorInfo.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> +#include <boost/python/copy_non_const_reference.hpp> +#include <boost/python/iterator.hpp> #include <boost/python/return_by_value.hpp> #include <boost/python/return_value_policy.hpp> -#include <boost/python/iterator.hpp> -#include <boost/iterator/iterator_facade.hpp> - -#include <Python.h> -#include <boost/python.hpp> +#include <iterator> #include "MantidGeometry/Instrument/DetectorInfoItem.h" #include "MantidGeometry/Instrument/DetectorInfoIterator.h" -using Mantid::Geometry::DetectorInfoItem; -using Mantid::Geometry::DetectorInfoIterator; using Mantid::Geometry::DetectorInfo; +using Mantid::Geometry::DetectorInfoItem; +using Mantid::Geometry::DetectorInfoIterator; using Mantid::Kernel::Quat; using Mantid::Kernel::V3D; using namespace boost::python; @@ -41,10 +40,20 @@ void export_DetectorInfo() { void (DetectorInfo::*setMasked)(const size_t, bool) = &DetectorInfo::setMasked; + /* + Mantid::Geometry::DetectorInfoIterator group_begin(DetectorInfo &self) { + return self.begin(); + } + + Mantid::Geometry::DetectorInfoIterator group_end(DetectorInfo &self) { + return self.end(); + }*/ + // Export to Python class_<DetectorInfo, boost::noncopyable>("DetectorInfo", no_init) - .def("__iter__", range(&DetectorInfo::begin, &DetectorInfo::end)) + .def("__iter__", range<return_value_policy<copy_const_reference>>( + &DetectorInfo::begin, &DetectorInfo::end)) .def("__len__", &DetectorInfo::size, (arg("self")), "Returns the size of the DetectorInfo, i.e., the number of " @@ -68,9 +77,10 @@ void export_DetectorInfo() { "Sets all mask flags to false (unmasked).") .def("isEquivalent", &DetectorInfo::isEquivalent, - (arg("self"), arg("other")), "Returns True if the content of this " - "detector is equivalent to the content " - "of the other detector.") + (arg("self"), arg("other")), + "Returns True if the content of this " + "detector is equivalent to the content " + "of the other detector.") .def("twoTheta", twoTheta, (arg("self"), arg("index")), "Returns 2 theta (scattering angle w.r.t beam direction).") diff --git a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoItem.cpp b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoItem.cpp index 07f17e4630aee734cb09cbeb7ef0b38e525d7a07..152b6d1a11a9498bf6198fa2937c177887729b01 100644 --- a/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoItem.cpp +++ b/Framework/PythonInterface/mantid/geometry/src/Exports/DetectorInfoItem.cpp @@ -1,5 +1,6 @@ #include <boost/python/class.hpp> #include <boost/python/module.hpp> + #include "MantidGeometry/Instrument/DetectorInfoItem.h" #include "MantidKernel/V3D.h" @@ -11,6 +12,6 @@ void export_DetectorInfoItem() { // Export to Python class_<DetectorInfoItem>("DetectorInfoItem", no_init) - .add_property("position", &DetectorInfoItem::position); - //.def("position", &DetectorInfoItem::position, arg("self")); + .add_property("position", &DetectorInfoItem::position); + //.def("position", &DetectorInfoItem::position, arg("self")); } diff --git a/Framework/PythonInterface/test/python/mantid/geometry/DetectorInfoTest.py b/Framework/PythonInterface/test/python/mantid/geometry/DetectorInfoTest.py index c68e7649e62949a3ca01619b803e175ad40a3650..751b323bd2dc58faf3870ad0902c4c8fc46c5e23 100644 --- a/Framework/PythonInterface/test/python/mantid/geometry/DetectorInfoTest.py +++ b/Framework/PythonInterface/test/python/mantid/geometry/DetectorInfoTest.py @@ -107,14 +107,16 @@ class DetectorInfoTest(unittest.TestCase): """ def test_iteration(self): + import time + time.sleep(20) info = self._ws.detectorInfo() #self.assertEquals(len(info), 0) #self.assertEquals(info.size(), 0) for a in info: #self.assertEquals(type(a), DetectorInfoItem) #self.assertEquals(info.position(0), "") - #self.assertEquals(a.position, 100) - print(a) + print(a.position) + #print(a) self.fail()