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

Cleaned up creation of python lists

re #22923
parent 932b47ec
No related branches found
No related tags found
No related merge requests found
#include "MantidGeometry/Instrument/ComponentInfo.h" #include "MantidGeometry/Instrument/ComponentInfo.h"
#include "MantidKernel/Quat.h" #include "MantidKernel/Quat.h"
#include "MantidKernel/V3D.h" #include "MantidKernel/V3D.h"
#include "MantidPythonInterface/kernel/Converters/VectorToNDArray.h"
#include "MantidPythonInterface/kernel/Converters/WrapWithNumpy.h"
#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/handle.hpp>
#include <boost/python/list.hpp> #include <boost/python/list.hpp>
#include <boost/python/return_value_policy.hpp> #include <boost/python/return_value_policy.hpp>
...@@ -10,19 +14,18 @@ using Mantid::Geometry::ComponentInfo; ...@@ -10,19 +14,18 @@ using Mantid::Geometry::ComponentInfo;
using Mantid::Kernel::Quat; using Mantid::Kernel::Quat;
using Mantid::Kernel::V3D; using Mantid::Kernel::V3D;
using namespace boost::python; using namespace boost::python;
namespace Converters = Mantid::PythonInterface::Converters;
// Helper function for converting std::vector<size_t> to a Python list // Helper function to call a converter for std::vector<size_t> to a Python list
boost::python::list createList(std::vector<size_t> items) { boost::python::list createList(std::vector<size_t> items) {
// Create the result list // Create a list to populate
boost::python::list result; boost::python::list dataAsList;
// Populate the Python list // Store the data
std::vector<size_t>::iterator it; dataAsList.append(object(handle<>(
for (it = items.begin(); it != items.end(); ++it) { Converters::VectorToNDArray<size_t, Converters::WrapReadOnly>()(items))));
result.append(*it);
}
return result; return dataAsList;
} }
// Helper function to call the detectorsInSubtree method // Helper function to call the detectorsInSubtree method
...@@ -56,11 +59,9 @@ void (ComponentInfo::*setPosition)(const size_t, const Mantid::Kernel::V3D &) = ...@@ -56,11 +59,9 @@ void (ComponentInfo::*setPosition)(const size_t, const Mantid::Kernel::V3D &) =
void (ComponentInfo::*setRotation)(const size_t, const Mantid::Kernel::Quat &) = void (ComponentInfo::*setRotation)(const size_t, const Mantid::Kernel::Quat &) =
&ComponentInfo::setRotation; &ComponentInfo::setRotation;
// Export ComponentInfo
void export_ComponentInfo() { void export_ComponentInfo() {
// WARNING ComponentInfo is work in progress and not ready for exposing more
// of its functionality to Python, and should not yet be used in user scripts.
// DO NOT ADD EXPORTS TO OTHER METHODS without contacting the team working on
// Instrument-2.0.
class_<ComponentInfo, boost::noncopyable>("ComponentInfo", no_init) class_<ComponentInfo, boost::noncopyable>("ComponentInfo", no_init)
.def("__len__", &ComponentInfo::size, arg("self"), .def("__len__", &ComponentInfo::size, arg("self"),
......
...@@ -22,10 +22,10 @@ The other two are: ...@@ -22,10 +22,10 @@ The other two are:
--------- ---------
Indexing Indexing
--------- ---------
The ``ComponentInfo`` object is accessed by an index going from 0 to the number of components N. The ``ComponentInfo`` object is accessed by an index going from 0 to N-1 where N is the number of components.
The component index for a detector is EQUAL to the detector index. In other words, a detector with a detector index of 5 when working with a ``DetectorInfo`` object and will have a component index of 5 when working with a ``ComponentInfo`` object. The component index for a detector is EQUAL to the detector index. In other words, a detector with a detector index of 5 when working with a ``DetectorInfo`` object and will have a component index of 5 when working with a ``ComponentInfo`` object.
Another way to think about this is that the first 0 - n components referenced in ``ComponentInfo`` are detectors, where n is the total number of detectors. Another way to think about this is that the first 0 to n-1 components referenced in ``ComponentInfo`` are detectors, where n is the total number of detectors.
------- -------
Usage Usage
......
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