Mantid
Loading...
Searching...
No Matches
ComponentInfo.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include "MantidBeamline/ComponentType.h"
9#include "MantidBeamline/PixelGridComponent.h"
14#include "MantidKernel/Quat.h"
15#include "MantidKernel/V3D.h"
19#include "MantidPythonInterface/geometry/ComponentInfoPythonIterator.h"
20
21#include <boost/python/class.hpp>
22#include <boost/python/copy_const_reference.hpp>
23#include <boost/python/dict.hpp>
24#include <boost/python/enum.hpp>
25#include <boost/python/errors.hpp>
26#include <boost/python/extract.hpp>
27#include <boost/python/reference_existing_object.hpp>
28#include <boost/python/return_value_policy.hpp>
29#include <boost/python/scope.hpp>
30
31using Mantid::Beamline::ComponentType;
32using Mantid::Beamline::PixelGridComponent;
37using Mantid::PythonInterface::ComponentInfoPythonIterator;
40using namespace boost::python;
41
42namespace {
43ComponentInfoPythonIterator make_pyiterator(ComponentInfo &componentInfo) {
44 return ComponentInfoPythonIterator(componentInfo);
45}
46
47// Accept a bare observer position so this reads as a drop-in for the legacy
48// IDetector::solidAngle(observer), constructing SolidAngleParams internally.
49double solidAngle(const ComponentInfo &self, const size_t index, const V3D &observer) {
50 return self.solidAngle(index, SolidAngleParams(observer));
51}
52
53// Flat accessors for the grid metadata of a Rectangular/Grid bank. The
54// Beamline::PixelGridComponent aggregate is an implementation detail of the
55// Geometry layer and is deliberately not exported to Python; one member is
56// fetched per call.
57template <auto Field> auto pixelGridField(ComponentInfo const &self, size_t const componentIndex) {
58 return self.pixelGridComponent(componentIndex).*Field;
59}
60
61// Axis fill order ('x'/'y'/'z' permutation) as a 3-character string, since
62// std::array<char, 3> has no automatic boost::python converter.
63std::string pixelGridIdFillOrder(ComponentInfo const &self, size_t const componentIndex) {
64 auto const order = self.pixelGridComponent(componentIndex).idFillOrder;
65 return std::string(order.begin(), order.end());
66}
67
70double pixelGridXSize(ComponentInfo const &self, size_t const componentIndex) {
71 if (!self.isGridDetector(componentIndex)) {
72 throw std::runtime_error("ComponentInfo::pixelgridXSize: component is not a Rectangular or Grid bank");
73 }
74 double scalex = 1.0;
75 if (self.hasParameter(componentIndex, "scalex")) {
76 scalex = self.getNumberParameter(componentIndex, "scalex", false)[0];
77 }
78 PixelGridComponent const grid = self.pixelGridComponent(componentIndex);
79 return grid.nX * grid.xStep * scalex;
80}
81
84double pixelGridYSize(ComponentInfo const &self, size_t const componentIndex) {
85 if (!self.isGridDetector(componentIndex)) {
86 throw std::runtime_error("ComponentInfo::pixelgridYSize: component is not a Rectangular or Grid bank");
87 }
88 double scaley = 1.0;
89 if (self.hasParameter(componentIndex, "scaley")) {
90 scaley = self.getNumberParameter(componentIndex, "scaley", false)[0];
91 }
92 PixelGridComponent const grid = self.pixelGridComponent(componentIndex);
93 return grid.nY * grid.yStep * scaley;
94}
95
96// The C++ add*() methods take the description as an optional pointer. Python passes a
97// string, with the empty default standing in for "no description", since a parameter
98// description is only ever set to something non-empty.
99const std::string *descriptionOrNull(const std::string &description) {
100 return description.empty() ? nullptr : &description;
101}
102
103// Named parameters are usually the instrument-level ones held by the root component, so
104// 'index' is optional and None stands in for root(). A boost::python default cannot be
105// computed from 'self', so it is resolved here rather than in the keyword list.
106size_t indexOrRoot(const ComponentInfo &self, const object &componentIndex) {
107 if (componentIndex.is_none()) {
108 return self.root();
109 }
110 const extract<size_t> index(componentIndex);
111 if (!index.check()) {
112 PyErr_SetString(PyExc_TypeError, "'index' must be a component index, or None for the root component.");
113 throw_error_already_set();
114 }
115 return index();
116}
117
118template <auto Method> auto readParameter(const ComponentInfo &self, const object &componentIndex, bool recursive) {
119 return (self.*Method)(indexOrRoot(self, componentIndex), recursive);
120}
121
122// Reorders Python's (name, index, recursive) to the C++ (index, name, recursive).
123template <auto Method>
124auto readNamedParameter(const ComponentInfo &self, const std::string &name, const object &componentIndex,
125 bool recursive) {
126 return (self.*Method)(indexOrRoot(self, componentIndex), name, recursive);
127}
128
129double getFittingParameter(const ComponentInfo &self, const std::string &name, double xvalue,
130 const object &componentIndex) {
131 return self.getFittingParameter(indexOrRoot(self, componentIndex), name, xvalue);
132}
133
134void addParameter(ComponentInfo &self, const std::string &type, const std::string &name, const std::string &value,
135 const object &componentIndex, const std::string &description, const std::string &visible) {
136 self.addParameter(indexOrRoot(self, componentIndex), type, name, value, descriptionOrNull(description), visible);
137}
138
139// Typed add*() setter; 'visible' is optional as addV3D/addQuat lack it.
140template <auto Method, typename T, typename... Visible>
141void insertParameter(ComponentInfo &self, const std::string &name, const T &value, const object &componentIndex,
142 const std::string &description, const Visible &...visible) {
143 (self.*Method)(indexOrRoot(self, componentIndex), name, value, descriptionOrNull(description), visible...);
144}
145
146void addFittingParameter(ComponentInfo &self, const std::string &name, const std::string &fittingFunction,
147 const std::string &value, const object &componentIndex, const std::string &description,
148 const std::string &visible) {
149 self.addFittingParameter(indexOrRoot(self, componentIndex), name, fittingFunction, value,
150 descriptionOrNull(description), visible);
151}
152
153void clearParameter(ComponentInfo &self, const std::string &name, const object &componentIndex) {
154 self.clearParameter(indexOrRoot(self, componentIndex), name);
155}
156
157template <auto Method> std::string readDescription(const ComponentInfo &self, const object &componentIndex) {
158 return (self.*Method)(indexOrRoot(self, componentIndex));
159}
160
161void setDescription(ComponentInfo &self, const std::string &description, const object &componentIndex) {
162 self.setDescription(indexOrRoot(self, componentIndex), description);
163}
164
165dict shapeToComponentIndices(const ComponentInfo &componentInfo) {
166 dict result;
167 const auto shapeMap = componentInfo.shapeToComponentIndices();
168 for (const auto &shape : shapeMap) {
169 const auto csgObject = std::dynamic_pointer_cast<const Mantid::Geometry::CSGObject>(shape.first);
170 if (csgObject != nullptr) {
171 result[csgObject->getShapeXML()] = shape.second;
172 }
173 }
174 return result;
175}
176
177} // namespace
178
179// Function pointers to help resolve ambiguity
181
183
184void (ComponentInfo::*setPosition)(const size_t, const Mantid::Kernel::V3D &) = &ComponentInfo::setPosition;
185
186void (ComponentInfo::*setRotation)(const size_t, const Mantid::Kernel::Quat &) = &ComponentInfo::setRotation;
187
188// Export ComponentInfo
190 enum_<ComponentType>("ComponentType")
191 .value("Generic", ComponentType::Generic)
192 .value("Infinite", ComponentType::Infinite)
193 .value("Grid", ComponentType::Grid)
194 .value("Rectangular", ComponentType::Rectangular)
195 .value("Structured", ComponentType::Structured)
196 .value("Unstructured", ComponentType::Unstructured)
197 .value("Detector", ComponentType::Detector)
198 .value("OutlineComposite", ComponentType::OutlineComposite);
199
200 class_<ComponentInfo, boost::noncopyable>("ComponentInfo", no_init)
201
202 .def("__iter__", make_pyiterator)
203
204 .def("__len__", &ComponentInfo::size, arg("self"), "Returns the number of components.")
205
206 .def("size", &ComponentInfo::size, arg("self"), "Returns the number of components.")
207
208 .def("isDetector", &ComponentInfo::isDetector, (arg("self"), arg("index")),
209 "Checks if the component is a detector.")
210
211 .def("detectorsInSubtree", &ComponentInfo::detectorsInSubtree, return_value_policy<VectorToNumpy>(),
212 (arg("self"), arg("index")),
213 "Returns a list of detectors in the subtree for the component "
214 "identified by 'index'.")
215
216 .def("componentsInSubtree", &ComponentInfo::componentsInSubtree, return_value_policy<VectorToNumpy>(),
217 (arg("self"), arg("index")),
218 "Returns a list of components in the subtree for the component "
219 "identified by 'index'.")
220
221 .def("position", position, (arg("self"), arg("index")),
222 "Returns the absolute position of the component identified by "
223 "'index'.")
224
225 .def("rotation", rotation, (arg("self"), arg("index")),
226 "Returns the absolute rotation of the component identified by "
227 "'index'.")
228
229 .def("relativePosition", &ComponentInfo::relativePosition, (arg("self"), arg("index")),
230 "Returns the absolute relative position of the component identified "
231 "by 'index'.")
232
233 .def("relativeRotation", &ComponentInfo::relativeRotation, (arg("self"), arg("index")),
234 "Returns the absolute relative rotation of the component identified "
235 "by 'index'.")
236
237 .def("setPosition", setPosition, (arg("self"), arg("index"), arg("newPosition")),
238 "Set the absolute position of the component identified by 'index'.")
239
240 .def("setRotation", setRotation, (arg("self"), arg("index"), arg("newRotation")),
241 "Set the absolute rotation of the component identified by 'index'.")
242
243 .def("hasSource", &ComponentInfo::hasSource, arg("self"), "Returns True if a source is present.")
244
245 .def("hasEquivalentSource", &ComponentInfo::hasEquivalentSource, arg("self"), arg("other"),
246 "Returns True is both beamlines either lack a Source or "
247 "have a Source at the same position.")
248
249 .def("hasSample", &ComponentInfo::hasSample, arg("self"), "Returns True if a sample is present.")
250
251 .def("hasEquivalentSample", &ComponentInfo::hasEquivalentSample, arg("self"), arg("other"),
252 "Returns True is both beamlines either lack a Sample or "
253 "have a Sample at the same position.")
254
255 .def("source", &ComponentInfo::source, arg("self"), "Returns the source component index.")
256
257 .def("sample", &ComponentInfo::sample, arg("self"), "Returns the sample component index.")
258
259 .def("sourcePosition", &ComponentInfo::sourcePosition, arg("self"), "Returns the source position.")
260
261 .def("samplePosition", &ComponentInfo::samplePosition, arg("self"), "Returns the sample position.")
262
263 .def("hasParent", &ComponentInfo::hasParent, (arg("self"), arg("index")),
264 "Returns True only if the component identified by 'index' has a "
265 "parent component.")
266
267 .def("parent", &ComponentInfo::parent, (arg("self"), arg("index")),
268 "Returns the parent component of the component identified by "
269 "'index'.")
270
271 .def("children", &ComponentInfo::children, (arg("self"), arg("index")),
272 return_value_policy<VectorRefToNumpy<WrapReadOnly>>(),
273 "Returns a list of child components for the component identified by "
274 "'index'.")
275
276 .def("name", &ComponentInfo::name, (arg("self"), arg("index")), return_value_policy<copy_const_reference>(),
277 "Returns the name of the component identified by 'index'.")
278
279 .def("l1", &ComponentInfo::l1, arg("self"), "Returns the l1 value.")
280
281 .def("scaleFactor", &ComponentInfo::scaleFactor, (arg("self"), arg("index")),
282 "Returns the scale factor for the component identified by 'index'.")
283
284 .def("setScaleFactor", &ComponentInfo::setScaleFactor, (arg("self"), arg("index"), arg("scaleFactor")),
285 "Set the scale factor of the component identifed by 'index'.")
286
287 .def("hasValidShape", &ComponentInfo::hasValidShape, (arg("self"), arg("index")),
288 "Returns True if the component identified by 'index' has a valid "
289 "shape.")
290
291 .def("shape", &ComponentInfo::shape, (arg("self"), arg("index")),
292 return_value_policy<reference_existing_object>(),
293 "Returns the shape of the component identified by 'index'.")
294
295 .def("solidAngle", &solidAngle, (arg("self"), arg("index"), arg("observer")),
296 "Returns the solid angle of the component identified by 'index' as "
297 "seen from the observer position.")
298
299 .def("componentType", &ComponentInfo::componentType, (arg("self"), arg("index")),
300 "Returns the ComponentType of the component identified by 'index'.")
301
302 .def("isGridDetector", &ComponentInfo::isGridDetector, (arg("self"), arg("index")),
303 "Returns True if the component identified by 'index' is a Rectangular or Grid "
304 "bank. Every pixelGrid* accessor requires this to be True.")
305
306 .def("pixelGridNX", &pixelGridField<&PixelGridComponent::nX>, (arg("self"), arg("index")),
307 "Returns the number of pixels in the X (horizontal) direction of the "
308 "Rectangular/Grid bank identified by 'index'. Raises RuntimeError if the "
309 "component is not a Rectangular or Grid bank.")
310
311 .def("pixelGridNY", &pixelGridField<&PixelGridComponent::nY>, (arg("self"), arg("index")),
312 "Returns the number of pixels in the Y (vertical) direction of the "
313 "Rectangular/Grid bank identified by 'index'. Raises RuntimeError if the "
314 "component is not a Rectangular or Grid bank.")
315
316 .def("pixelGridNZ", &pixelGridField<&PixelGridComponent::nZ>, (arg("self"), arg("index")),
317 "Returns the number of pixels in the Z (usually beam) direction of the "
318 "Rectangular/Grid bank identified by 'index', or 0 for a 2D (rectangular) "
319 "bank. Raises RuntimeError if the component is not a Rectangular or Grid bank.")
320
321 .def("pixelGridXStart", &pixelGridField<&PixelGridComponent::xStart>, (arg("self"), arg("index")),
322 "Returns the X position of pixel (0, 0, 0), in the local (unrotated, unscaled) "
323 "frame of the Rectangular/Grid bank identified by 'index'. Raises RuntimeError "
324 "if the component is not a Rectangular or Grid bank.")
325
326 .def("pixelGridYStart", &pixelGridField<&PixelGridComponent::yStart>, (arg("self"), arg("index")),
327 "Returns the Y position of pixel (0, 0, 0), in the local (unrotated, unscaled) "
328 "frame of the Rectangular/Grid bank identified by 'index'. Raises RuntimeError "
329 "if the component is not a Rectangular or Grid bank.")
330
331 .def("pixelGridZStart", &pixelGridField<&PixelGridComponent::zStart>, (arg("self"), arg("index")),
332 "Returns the Z position of pixel (0, 0, 0), in the local (unrotated, unscaled) "
333 "frame of the Rectangular/Grid bank identified by 'index'. Raises RuntimeError "
334 "if the component is not a Rectangular or Grid bank.")
335
336 .def("pixelGridXStep", &pixelGridField<&PixelGridComponent::xStep>, (arg("self"), arg("index")),
337 "Returns the step size between neighbouring pixels along X for the "
338 "Rectangular/Grid bank identified by 'index'. Raises RuntimeError if the "
339 "component is not a Rectangular or Grid bank.")
340
341 .def("pixelGridYStep", &pixelGridField<&PixelGridComponent::yStep>, (arg("self"), arg("index")),
342 "Returns the step size between neighbouring pixels along Y for the "
343 "Rectangular/Grid bank identified by 'index'. Raises RuntimeError if the "
344 "component is not a Rectangular or Grid bank.")
345
346 .def("pixelGridZStep", &pixelGridField<&PixelGridComponent::zStep>, (arg("self"), arg("index")),
347 "Returns the step size between neighbouring pixels along Z for the "
348 "Rectangular/Grid bank identified by 'index'. Raises RuntimeError if the "
349 "component is not a Rectangular or Grid bank.")
350
351 .def("pixelGridIdStart", &pixelGridField<&PixelGridComponent::idStart>, (arg("self"), arg("index")),
352 "Returns the detector ID of the first pixel of the Rectangular/Grid bank "
353 "identified by 'index'. Raises RuntimeError if the component is not a "
354 "Rectangular or Grid bank.")
355
356 .def("pixelGridIdStep", &pixelGridField<&PixelGridComponent::idStep>, (arg("self"), arg("index")),
357 "Returns the detector ID step between pixels along the first-filled axis of "
358 "the Rectangular/Grid bank identified by 'index'. Raises RuntimeError if the "
359 "component is not a Rectangular or Grid bank.")
360
361 .def("pixelGridIdStepByRow", &pixelGridField<&PixelGridComponent::idStepByRow>, (arg("self"), arg("index")),
362 "Returns the detector ID step between rows along the second-filled axis of "
363 "the Rectangular/Grid bank identified by 'index'. Raises RuntimeError if the "
364 "component is not a Rectangular or Grid bank.")
365
366 .def("pixelGridMinDetectorID", &pixelGridField<&PixelGridComponent::minDetectorID>, (arg("self"), arg("index")),
367 "Returns the minimum detector ID in the Rectangular/Grid bank identified by "
368 "'index'. Raises RuntimeError if the component is not a Rectangular or Grid bank.")
369
370 .def("pixelGridMaxDetectorID", &pixelGridField<&PixelGridComponent::maxDetectorID>, (arg("self"), arg("index")),
371 "Returns the maximum detector ID in the Rectangular/Grid bank identified by "
372 "'index'. Raises RuntimeError if the component is not a Rectangular or Grid bank.")
373
374 .def("pixelGridIdFillOrder", &pixelGridIdFillOrder, (arg("self"), arg("index")),
375 "Returns the axis order in which detector IDs are filled for the "
376 "Rectangular/Grid bank identified by 'index', as a 3-character string "
377 "permutation of 'x', 'y' and 'z'. Raises RuntimeError if the component is not "
378 "a Rectangular or Grid bank.")
379
380 .def("pixelGridXSize", &pixelGridXSize, (arg("self"), arg("index")),
381 "Returns the x-size (width) in the Rectangular/Grid bank identified "
382 "by 'index'. Raises RuntimeError if the component is not a Rectangular or Grid "
383 "bank.")
384
385 .def("pixelGridYSize", &pixelGridYSize, (arg("self"), arg("index")),
386 "Returns the y-size (height) in the Rectangular/Grid bank identified "
387 "by 'index'. Raises RuntimeError if the component is not a Rectangular or Grid "
388 "bank.")
389
390 .def("detectorIndexAtXYZ", &ComponentInfo::detectorIndexAtXYZ,
391 (arg("self"), arg("index"), arg("x"), arg("y"), arg("z")),
392 "Returns the detector index of the pixel at (x, y, z) within the "
393 "Rectangular/Grid bank identified by 'index'.")
394
395 .def("indexOfAny", &ComponentInfo::indexOfAny, (arg("self"), arg("name")),
396 "Returns the index of the component matching name. Where several components share the name, "
397 "returns the one closest to the root, as Instrument.getComponentByName() did. Raises "
398 "ValueError if name not found")
399
400 .def("uniqueName", &ComponentInfo::uniqueName, (arg("self"), arg("name")),
401 "Returns True if the name is a unique single occurance. Zero occurances yields False.")
402
403 .def("root", &ComponentInfo::root, arg("self"), "Returns the index of the root component")
404 .def("referenceFrame", &ComponentInfo::referenceFrame, arg("self"), return_value_policy<RemoveConstSharedPtr>(),
405 "Returns the instrument's :class:`~mantid.geometry.ReferenceFrame`, which defines the axes pointing up "
406 "and along the beam, and the handedness. A default frame (Y up, Z along the beam, right-handed) if the "
407 "instrument has none.")
408 .def("getMemorySize", &ComponentInfo::getMemorySize, arg("self"),
409 "Return the memory footprint of the component info in bytes.")
410 .def("shapeToComponentIndices", &shapeToComponentIndices, arg("self"),
411 "Returns a mapping of shapes to the indices of components with that shape.")
412
413 .def("fullName", &ComponentInfo::fullName, (arg("self"), arg("index")),
414 "Returns the fully-qualified name of the component identified by 'index', "
415 "e.g. 'instrument/bank1/pixel3'.")
416
417 .def("indexOfFullName", &ComponentInfo::indexOfFullName, (arg("self"), arg("fullName")),
418 "Returns the index of the component with this fully-qualified name, or "
419 "ComponentInfo.invalidIndex if there is none.")
420
421 // Named parameters. The read accessors mirror the legacy component API, including the
422 // 'empty sequence if absent' convention and the 'recursive' flag, so that migrating a
423 // call site is a rename. 'index' defaults to the root component, which holds the
424 // instrument-level parameters the legacy Instrument methods looked up.
425 .def("hasParameter", &readNamedParameter<&ComponentInfo::hasParameter>,
426 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
427 "Returns True if the component identified by 'index' (the root component by "
428 "default) has a parameter of this name.")
429
430 .def("getParameterNames", &readParameter<&ComponentInfo::getParameterNames>,
431 (arg("self"), arg("index") = object(), arg("recursive") = true),
432 "Returns the names of the parameters on the component identified by 'index' "
433 "(the root component by default).")
434
435 .def("getNumberParameter", &readNamedParameter<&ComponentInfo::getNumberParameter>,
436 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
437 "Returns the named double parameter of the component identified by 'index' "
438 "(the root component by default), or an empty sequence if it is unset.")
439
440 .def("getIntParameter", &readNamedParameter<&ComponentInfo::getIntParameter>,
441 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
442 "Returns the named integer parameter of the component identified by 'index' "
443 "(the root component by default), or an empty sequence if it is unset.")
444
445 .def("getBoolParameter", &readNamedParameter<&ComponentInfo::getBoolParameter>,
446 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
447 "Returns the named boolean parameter of the component identified by 'index' "
448 "(the root component by default), or an empty sequence if it is unset.")
449
450 .def("getStringParameter", &readNamedParameter<&ComponentInfo::getStringParameter>,
451 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
452 "Returns the named string parameter of the component identified by 'index' "
453 "(the root component by default), or an empty sequence if it is unset.")
454
455 .def("getParameterType", &readNamedParameter<&ComponentInfo::getParameterType>,
456 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
457 "Returns the type of the named parameter of the component identified by 'index' "
458 "(the root component by default), or an empty string if it is unset.")
459
460 .def("getPositionParameter", &readNamedParameter<&ComponentInfo::getPositionParameter>,
461 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
462 "Returns the named V3D parameter of the component identified by 'index' "
463 "(the root component by default), or an empty sequence if it is unset.")
464
465 .def("getRotationParameter", &readNamedParameter<&ComponentInfo::getRotationParameter>,
466 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
467 "Returns the named Quat parameter of the component identified by 'index' "
468 "(the root component by default), or an empty sequence if it is unset.")
469
470 .def("getParameterAsString", &readNamedParameter<&ComponentInfo::getParameterAsString>,
471 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
472 "Returns the value of the named parameter of the component identified by 'index' "
473 "(the root component by default) as a string, whatever its type, or an empty string if it is unset.")
474
475 .def("getParameterVisible", &readNamedParameter<&ComponentInfo::getParameterVisible>,
476 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
477 "Returns the visibility attribute of the named parameter of the component identified by 'index' "
478 "(the root component by default), or False if it is unset.")
479
480 .def("getParamDescription", &readNamedParameter<&ComponentInfo::getParamDescription>,
481 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
482 "Returns the description of the named parameter of the component identified by 'index' "
483 "(the root component by default), or an empty string if it is unset.")
484
485 .def("getParamShortDescription", &readNamedParameter<&ComponentInfo::getParamShortDescription>,
486 (arg("self"), arg("name"), arg("index") = object(), arg("recursive") = true),
487 "Returns the short description (tooltip) of the named parameter of the component identified by "
488 "'index' (the root component by default), or an empty string if it is unset.")
489
490 .def("getDescription", &readDescription<&ComponentInfo::getDescription>, (arg("self"), arg("index") = object()),
491 "Returns the description of the component identified by 'index' (the root component by default).")
492
493 .def("getShortDescription", &readDescription<&ComponentInfo::getShortDescription>,
494 (arg("self"), arg("index") = object()),
495 "Returns the short description (tooltip) of the component identified by 'index' "
496 "(the root component by default).")
497
498 .def("setDescription", &setDescription, (arg("self"), arg("description"), arg("index") = object()),
499 "Sets the description of the component identified by 'index' (the root component by default).")
500
501 .def("getFittingParameter", &getFittingParameter,
502 (arg("self"), arg("name"), arg("xvalue"), arg("index") = object()),
503 "Returns the named fitting parameter of the component identified by 'index' (the "
504 "root component by default), evaluated at 'xvalue' from its look-up table or formula.")
505
506 .def("addParameter", &addParameter,
507 (arg("self"), arg("type"), arg("name"), arg("value"), arg("index") = object(), arg("description") = "",
508 arg("visible") = "true"),
509 "Adds or replaces the named parameter of this type, given its value as a string, "
510 "on the component identified by 'index' (the root component by default).")
511
512 .def("addDouble", &insertParameter<&ComponentInfo::addDouble, double, std::string>,
513 (arg("self"), arg("name"), arg("value"), arg("index") = object(), arg("description") = "",
514 arg("visible") = "true"),
515 "Adds or replaces a named double parameter on the component identified by 'index' "
516 "(the root component by default).")
517
518 .def("addInt", &insertParameter<&ComponentInfo::addInt, int, std::string>,
519 (arg("self"), arg("name"), arg("value"), arg("index") = object(), arg("description") = "",
520 arg("visible") = "true"),
521 "Adds or replaces a named integer parameter on the component identified by 'index' "
522 "(the root component by default).")
523
524 .def("addBool", &insertParameter<&ComponentInfo::addBool, bool, std::string>,
525 (arg("self"), arg("name"), arg("value"), arg("index") = object(), arg("description") = "",
526 arg("visible") = "true"),
527 "Adds or replaces a named boolean parameter on the component identified by 'index' "
528 "(the root component by default).")
529
530 .def("addString", &insertParameter<&ComponentInfo::addString, std::string, std::string>,
531 (arg("self"), arg("name"), arg("value"), arg("index") = object(), arg("description") = "",
532 arg("visible") = "true"),
533 "Adds or replaces a named string parameter on the component identified by 'index' "
534 "(the root component by default).")
535
536 .def("addV3D", &insertParameter<&ComponentInfo::addV3D, V3D>,
537 (arg("self"), arg("name"), arg("value"), arg("index") = object(), arg("description") = ""),
538 "Adds or replaces a named V3D parameter on the component identified by 'index' "
539 "(the root component by default).")
540
541 .def("addQuat", &insertParameter<&ComponentInfo::addQuat, Quat>,
542 (arg("self"), arg("name"), arg("value"), arg("index") = object(), arg("description") = ""),
543 "Adds or replaces a named Quat parameter on the component identified by 'index' "
544 "(the root component by default).")
545
546 .def("addFittingParameter", &addFittingParameter,
547 (arg("self"), arg("name"), arg("fittingFunction"), arg("value"), arg("index") = object(),
548 arg("description") = "", arg("visible") = "true"),
549 "Adds a named fitting parameter, given its value as a string, on the component "
550 "identified by 'index' (the root component by default).")
551
552 .def("clearParameter", &clearParameter, (arg("self"), arg("name"), arg("index") = object()),
553 "Removes every parameter of this name from the component identified by 'index' "
554 "(the root component by default).");
555
556 // The sentinel returned by indexOfFullName() for a name that matches no component.
557 scope().attr("ComponentInfo").attr("invalidIndex") = ComponentInfo::invalidIndex;
558}
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
SpectrumInfoPythonIterator make_pyiterator(SpectrumInfo &spectrumInfo)
void export_ComponentInfo()
Mantid::Kernel::Quat(ComponentInfo::* rotation)(const size_t) const
void(ComponentInfo::* setPosition)(const size_t, const Mantid::Kernel::V3D &)
void(ComponentInfo::* setRotation)(const size_t, const Mantid::Kernel::Quat &)
Mantid::Kernel::V3D(ComponentInfo::* position)(const size_t) const
ComponentInfo : Provides a component centric view on to the instrument.
bool hasParent(const size_t componentIndex) const
void clearParameter(const size_t componentIndex, const std::string &name)
Remove every parameter of this name from this component.
std::string fullName(const size_t componentIndex) const
The fully-qualified name of a component ("instrument/bank1/pixel3")
std::unordered_map< std::shared_ptr< const Geometry::IObject >, std::vector< size_t > > shapeToComponentIndices() const
Build a map from each unique shape to the list of component indices that share it.
size_t indexOfAny(const std::string &name) const
The first component with this name in a breadth-first search, as Instrument::getComponentByName() fin...
bool hasEquivalentSource(const ComponentInfo &other) const
void setDescription(const size_t componentIndex, const std::string &description)
Set the component's description, as Component::setDescription() does: on the parameter named after th...
std::shared_ptr< const ReferenceFrame > referenceFrame() const
The instrument's reference frame: which axes point up and along the beam, and its handedness.
void addFittingParameter(const size_t componentIndex, const std::string &name, const std::string &fittingFunction, const std::string &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Add a fitting parameter.
double solidAngle(const size_t componentIndex, const Geometry::SolidAngleParams &params) const
size_t parent(const size_t componentIndex) const
bool isGridDetector(size_t const componentIndex) const
const std::vector< size_t > & children(size_t componentIndex) const
std::vector< size_t > componentsInSubtree(size_t componentIndex) const
bool hasParameter(const size_t componentIndex, const std::string &name, bool recursive=true) const
Returns empty (or false) if the ComponentInfo was built without parameters or the parameter is unset.
bool hasValidShape(const size_t componentIndex) const
std::vector< double > getNumberParameter(const size_t componentIndex, const std::string &name, bool recursive=true) const
double getFittingParameter(const size_t componentIndex, const std::string &name, double xvalue) const
Beamline::PixelGridComponent pixelGridComponent(const size_t componentIndex) const
bool hasEquivalentSample(const ComponentInfo &other) const
void setScaleFactor(const size_t componentIndex, const Kernel::V3D &scaleFactor)
std::vector< size_t > detectorsInSubtree(size_t componentIndex) const
bool isDetector(const size_t componentIndex) const
bool uniqueName(const std::string &name) const
size_t detectorIndexAtXYZ(const size_t componentIndex, const int x, const int y, const int z) const
Kernel::V3D relativePosition(const size_t componentIndex) const
const std::string & name(const size_t componentIndex) const
size_t getMemorySize() const
Return memory used by the component info, in bytes.
Kernel::Quat relativeRotation(const size_t componentIndex) const
static constexpr size_t invalidIndex
Returned by indexOfOrInvalid() for a component ID that is not part of this instrument.
const Geometry::IObject & shape(const size_t componentIndex) const
size_t indexOfFullName(const std::string &fullName) const
The component with this fully-qualified name, or invalidIndex if there is none.
Beamline::ComponentType componentType(const size_t componentIndex) const
Kernel::V3D scaleFactor(const size_t componentIndex) const
void addParameter(const size_t componentIndex, const std::string &type, const std::string &name, const std::string &value, const std::string *const pDescription=nullptr, const std::string &pVisible="true")
Add or replace a named parameter at a specific component index.
Class for quaternions.
Definition Quat.h:38
Class for 3D vectors.
Definition V3D.h:35
Helper class which provides the Collimation Length for SANS instruments.
adjust instrument component position and orientation
: detector size scale at y-direction
Implements a return value policy that returns a numpy array from a rerence to a std::vector.