Mantid
Loading...
Searching...
No Matches
Instrument.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 +
12
13#include <boost/python/class.hpp>
14#include <boost/python/copy_const_reference.hpp>
15#include <boost/python/overloads.hpp>
16#include <boost/python/register_ptr_to_python.hpp>
17
18using namespace Mantid::Geometry;
19using Mantid::detid_t;
20using namespace boost::python;
22
24
25namespace {
26
27// Deprecation wrappers. Legacy Instrument-tree access is being retired in favour
28// of the index-based ComponentInfo/DetectorInfo access layers. See the
29// 'Instrument Access via SpectrumInfo, DetectorInfo, ComponentInfo' concept page.
30IComponent_const_sptr getSampleDeprecated(const Instrument &self) {
31 PyErr_Warn(PyExc_DeprecationWarning, "'Instrument.getSample' is deprecated in Mantid 7.0, "
32 "use 'ComponentInfo.sample'/'samplePosition' instead. "
33 "For more information, see the instrument access layers concept page: "
34 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html");
35 return self.getSample();
36}
37
38IComponent_const_sptr getSourceDeprecated(const Instrument &self) {
39 PyErr_Warn(PyExc_DeprecationWarning, "'Instrument.getSource' is deprecated in Mantid 7.0, "
40 "use 'ComponentInfo.source'/'sourcePosition' instead. "
41 "For more information, see the instrument access layers concept page: "
42 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html");
43 return self.getSource();
44}
45
46IComponent_const_sptr getComponentByNameDeprecated(const Instrument &self, const std::string &cname,
47 const int nlevels) {
48 PyErr_Warn(PyExc_DeprecationWarning, "'Instrument.getComponentByName' is deprecated in Mantid 7.0, "
49 "use 'ComponentInfo.indexOfAny' instead. "
50 "For more information, see the instrument access layers concept page: "
51 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html");
52 return self.getComponentByName(cname, nlevels);
53}
54
55IDetector_const_sptr getDetectorDeprecated(const Instrument &self, const detid_t &detector_id) {
56 PyErr_Warn(PyExc_DeprecationWarning, "'Instrument.getDetector' is deprecated in Mantid 7.0, "
57 "use 'DetectorInfo.indexOf' instead. "
58 "For more information, see the instrument access layers concept page: "
59 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html");
60 return self.getDetector(detector_id);
61}
62
63std::size_t getNumberDetectorsDeprecated(const Instrument &self, const bool skipMonitors = false) {
64 PyErr_Warn(PyExc_DeprecationWarning, "'Instrument.getNumberDetectors' is deprecated in Mantid 7.0, "
65 "use 'DetectorInfo.size' instead. "
66 "For more information, see the instrument access layers concept page: "
67 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html");
68 return self.getNumberDetectors(skipMonitors);
69}
70
71std::vector<RectangularDetector_const_sptr> findRectDetectorsDeprecated(const Instrument &self) {
72 PyErr_Warn(PyExc_DeprecationWarning, "'Instrument.findRectDetectors' is deprecated in Mantid 7.0, "
73 "use 'ComponentInfo.componentType' to identify Rectangular banks instead. "
74 "For more information, see the instrument access layers concept page: "
75 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html");
76 return self.findRectDetectors();
77}
78
79std::vector<GridDetector_const_sptr> findGridDetectorsDeprecated(const Instrument &self) {
80 PyErr_Warn(PyExc_DeprecationWarning, "'Instrument.findGridDetectors' is deprecated in Mantid 7.0, "
81 "use 'ComponentInfo.componentType' to identify Grid banks instead. "
82 "For more information, see the instrument access layers concept page: "
83 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html");
84 return self.findGridDetectors();
85}
86
87// Ignore -Wconversion warnings coming from boost::python
88// Seen with GCC 7.1.1 and Boost 1.63.0
89GNU_DIAG_OFF("conversion")
90
91BOOST_PYTHON_FUNCTION_OVERLOADS(Instrument_getNumberDetectors, getNumberDetectorsDeprecated, 1, 2)
92
93GNU_DIAG_ON("conversion")
94
95} // namespace
96
98 register_ptr_to_python<std::shared_ptr<Instrument>>();
99
100 class_<Instrument, bases<CompAssembly>, boost::noncopyable>("Instrument", no_init)
101 .def("getSample", &getSampleDeprecated, arg("self"), return_value_policy<RemoveConstSharedPtr>(),
102 "Return the :class:`~mantid.geometry.Component` object that "
103 "represents the sample (deprecated, use ComponentInfo.sample)")
104
105 .def("getSource", &getSourceDeprecated, arg("self"), return_value_policy<RemoveConstSharedPtr>(),
106 "Return the :class:`~mantid.geometry.Component` object that "
107 "represents the source (deprecated, use ComponentInfo.source)")
108
109 .def("getComponentByName", &getComponentByNameDeprecated, (arg("self"), arg("cname"), arg("nlevels") = 0),
110 return_value_policy<RemoveConstSharedPtr>(),
111 "Returns the named :class:`~mantid.geometry.Component` "
112 "(deprecated, use ComponentInfo.indexOfAny)")
113
114 .def("getDetector", &getDetectorDeprecated, (arg("self"), arg("detector_id")),
115 return_value_policy<RemoveConstSharedPtr>(),
116 "Returns the :class:`~mantid.geometry.Detector` with the given ID "
117 "(deprecated, use DetectorInfo.indexOf)")
118
119 .def("getDefaultView", &Instrument::getDefaultView, arg("self"), return_value_policy<copy_const_reference>(),
120 "Return the name of the preferred view in instrument view.")
121
122 .def("getXmlText", &Instrument::getXmlText, arg("self"), return_value_policy<copy_const_reference>(),
123 "Return the instrument XML.")
124
125 .def("getNumberDetectors", &getNumberDetectorsDeprecated,
126 Instrument_getNumberDetectors("Return the number of detectors (deprecated, use DetectorInfo.size)",
127 (arg("self"), arg("skipMonitors") = false)))
128
129 .def("getReferenceFrame", (std::shared_ptr<const ReferenceFrame> (Instrument::*)())&Instrument::getReferenceFrame,
130 arg("self"), return_value_policy<RemoveConstSharedPtr>(),
131 "Returns the :class:`~mantid.geometry.ReferenceFrame` attached that "
132 "defines the instrument "
133 "axes")
134
135 .def("getValidFromDate", &Instrument::getValidFromDate, arg("self"),
136 "Return the valid from :class:`~mantid.kernel.DateAndTime` of the "
137 "instrument")
138
139 .def("getValidToDate", &Instrument::getValidToDate, arg("self"),
140 "Return the valid to :class:`~mantid.kernel.DateAndTime` of the "
141 "instrument")
142
143 .def("getFilename", &Instrument::getFilename, arg("self"), return_value_policy<copy_const_reference>(),
144 "Return the name of the file that the original IDF was from")
145
146 .def("setFilename", &Instrument::setFilename, (arg("self"), arg("filename")),
147 "Set the name of the file that the original IDF was from")
148
149 .def("getBaseInstrument", &Instrument::baseInstrument, arg("self"), return_value_policy<RemoveConstSharedPtr>(),
150 "Return reference to the base instrument")
151
152 .def("findRectDetectors", &findRectDetectorsDeprecated, arg("self"),
153 "Return a list of rectangular detectors "
154 "(deprecated, use ComponentInfo.componentType).")
155 .def("findGridDetectors", &findGridDetectorsDeprecated, arg("self"),
156 "Return a list of grid detectors "
157 "(deprecated, use ComponentInfo.componentType).")
158 .def("getMemorySize", &Instrument::getMemorySize, arg("self"),
159 "Return the memory footprint of the instrument in bytes.");
160}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
void export_Instrument()
#define GNU_DIAG_ON(x)
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
std::shared_ptr< const IComponent > getComponentByName(const std::string &cname, int nlevels=0) const override
Returns a pointer to the first component of assembly encountered with the given name.
Base Instrument Class.
Definition Instrument.h:49
std::size_t getNumberDetectors(bool skipMonitors=false) const
IComponent_const_sptr getSource() const
Gets a pointer to the source.
std::vector< GridDetector_const_sptr > findGridDetectors() const
Definition Instrument.h:212
std::shared_ptr< const Instrument > baseInstrument() const
Pointer to the 'real' instrument, for parametrized instruments.
size_t getMemorySize() const
Get the footprint in memory in bytes.
std::vector< RectangularDetector_const_sptr > findRectDetectors() const
Definition Instrument.h:209
const std::string & getFilename() const
const std::string & getDefaultView() const
Get the default type of the instrument view.
Definition Instrument.h:148
const std::string & getXmlText() const
Types::Core::DateAndTime getValidFromDate() const
Definition Instrument.h:170
std::shared_ptr< const ReferenceFrame > getReferenceFrame() const
Get refernce Frame.
IDetector_const_sptr getDetector(const detid_t &detector_id) const
Gets a pointer to the detector from its ID Note that for getting the detector associated with a spect...
void setFilename(const std::string &filename)
Set the path to the original IDF .xml file that was loaded for this instrument.
Types::Core::DateAndTime getValidToDate() const
Definition Instrument.h:173
IComponent_const_sptr getSample() const
Gets a pointer to the Sample Position.
std::shared_ptr< const IComponent > IComponent_const_sptr
Typdef of a shared pointer to a const IComponent.
Definition IComponent.h:167
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
Definition IDetector.h:102
int32_t detid_t
Typedef for a detector ID.
Implements the RemoveConstSharedPtr policy.