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.
30Instrument_const_sptr getBaseInstrumentDeprecated(const Instrument &self) {
31 if (PyErr_Warn(PyExc_DeprecationWarning,
32 "Instrument.getBaseInstrument() is deprecated in Mantid 7.0.\n"
33 "Use ExperimentInfo.baseComponentInfo() instead. "
34 "For more information, see the instrument access layers concept page: "
35 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html") < 0)
36 throw boost::python::error_already_set();
37 return self.baseInstrument();
38}
39
40IComponent_const_sptr getSampleDeprecated(const Instrument &self) {
41 if (PyErr_Warn(PyExc_DeprecationWarning,
42 "'Instrument.getSample' is deprecated in Mantid 7.0, "
43 "use 'ComponentInfo.sample'/'samplePosition' instead. "
44 "For more information, see the instrument access layers concept page: "
45 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html") < 0)
46 throw boost::python::error_already_set();
47 return self.getSample();
48}
49
50IComponent_const_sptr getSourceDeprecated(const Instrument &self) {
51 if (PyErr_Warn(PyExc_DeprecationWarning,
52 "'Instrument.getSource' is deprecated in Mantid 7.0, "
53 "use 'ComponentInfo.source'/'sourcePosition' instead. "
54 "For more information, see the instrument access layers concept page: "
55 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html") < 0)
56 throw boost::python::error_already_set();
57 return self.getSource();
58}
59
60IComponent_const_sptr getComponentByNameDeprecated(const Instrument &self, const std::string &cname,
61 const int nlevels) {
70 return self.getComponentByName(cname, nlevels);
71}
72
73IDetector_const_sptr getDetectorDeprecated(const Instrument &self, const detid_t &detector_id) {
82 return self.getDetector(detector_id);
83}
84
85std::size_t getNumberDetectorsDeprecated(const Instrument &self, const bool skipMonitors = false) {
86 if (PyErr_Warn(PyExc_DeprecationWarning,
87 "'Instrument.getNumberDetectors' is deprecated in Mantid 7.0, "
88 "use 'DetectorInfo.size' instead. "
89 "For more information, see the instrument access layers concept page: "
90 "https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html") < 0)
91 throw boost::python::error_already_set();
92 return self.getNumberDetectors(skipMonitors);
93}
94
95std::vector<RectangularDetector_const_sptr> findRectDetectorsDeprecated(const Instrument &self) {
104 return self.findRectDetectors();
105}
106
107std::vector<GridDetector_const_sptr> findGridDetectorsDeprecated(const Instrument &self) {
116 return self.findGridDetectors();
117}
118
119// Ignore -Wconversion warnings coming from boost::python
120// Seen with GCC 7.1.1 and Boost 1.63.0
121GNU_DIAG_OFF("conversion")
122
123BOOST_PYTHON_FUNCTION_OVERLOADS(Instrument_getNumberDetectors, getNumberDetectorsDeprecated, 1, 2)
124
125GNU_DIAG_ON("conversion")
126
127} // namespace
128
130 register_ptr_to_python<std::shared_ptr<Instrument>>();
131
132 class_<Instrument, bases<CompAssembly>, boost::noncopyable>("Instrument", no_init)
133 .def("getSample", &getSampleDeprecated, arg("self"), return_value_policy<RemoveConstSharedPtr>(),
134 "Return the :class:`~mantid.geometry.Component` object that "
135 "represents the sample (deprecated, use ComponentInfo.sample)")
136
137 .def("getSource", &getSourceDeprecated, arg("self"), return_value_policy<RemoveConstSharedPtr>(),
138 "Return the :class:`~mantid.geometry.Component` object that "
139 "represents the source (deprecated, use ComponentInfo.source)")
140
141 .def("getComponentByName", &getComponentByNameDeprecated, (arg("self"), arg("cname"), arg("nlevels") = 0),
142 return_value_policy<RemoveConstSharedPtr>(),
143 "Returns the named :class:`~mantid.geometry.Component` "
144 "(deprecated, use ComponentInfo.indexOfAny)")
145
146 .def("getDetector", &getDetectorDeprecated, (arg("self"), arg("detector_id")),
147 return_value_policy<RemoveConstSharedPtr>(),
148 "Returns the :class:`~mantid.geometry.Detector` with the given ID "
149 "(deprecated, use DetectorInfo.indexOf)")
150
151 .def("getDefaultView", &Instrument::getDefaultView, arg("self"), return_value_policy<copy_const_reference>(),
152 "Return the name of the preferred view in instrument view.")
153
154 .def("getXmlText", &Instrument::getXmlText, arg("self"), return_value_policy<copy_const_reference>(),
155 "Return the instrument XML.")
156
157 .def("getNumberDetectors", &getNumberDetectorsDeprecated,
158 Instrument_getNumberDetectors("Return the number of detectors (deprecated, use DetectorInfo.size)",
159 (arg("self"), arg("skipMonitors") = false)))
160
161 .def("getReferenceFrame", (std::shared_ptr<const ReferenceFrame> (Instrument::*)())&Instrument::getReferenceFrame,
162 arg("self"), return_value_policy<RemoveConstSharedPtr>(),
163 "Returns the :class:`~mantid.geometry.ReferenceFrame` attached that "
164 "defines the instrument "
165 "axes")
166
167 .def("getValidFromDate", &Instrument::getValidFromDate, arg("self"),
168 "Return the valid from :class:`~mantid.kernel.DateAndTime` of the "
169 "instrument")
170
171 .def("getValidToDate", &Instrument::getValidToDate, arg("self"),
172 "Return the valid to :class:`~mantid.kernel.DateAndTime` of the "
173 "instrument")
174
175 .def("getFilename", &Instrument::getFilename, arg("self"), return_value_policy<copy_const_reference>(),
176 "Return the name of the file that the original IDF was from")
177
178 .def("setFilename", &Instrument::setFilename, (arg("self"), arg("filename")),
179 "Set the name of the file that the original IDF was from")
180
181 .def("getBaseInstrument", &getBaseInstrumentDeprecated, arg("self"), return_value_policy<RemoveConstSharedPtr>(),
182 "Return reference to the base instrument "
183 "(deprecated, use baseComponentInfo() on the workspace).")
184
185 .def("findRectDetectors", &findRectDetectorsDeprecated, arg("self"),
186 "Return a list of rectangular detectors "
187 "(deprecated, use ComponentInfo.componentType).")
188 .def("findGridDetectors", &findGridDetectorsDeprecated, arg("self"),
189 "Return a list of grid detectors "
190 "(deprecated, use ComponentInfo.componentType).")
191 .def("getMemorySize", &Instrument::getMemorySize, arg("self"),
192 "Return the memory footprint of the instrument in bytes.");
193}
#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:50
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:214
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:211
const std::string & getFilename() const
const std::string & getDefaultView() const
Get the default type of the instrument view.
Definition Instrument.h:150
const std::string & getXmlText() const
Types::Core::DateAndTime getValidFromDate() const
Definition Instrument.h:172
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:175
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:165
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
Definition IDetector.h:96
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
int32_t detid_t
Typedef for a detector ID.
Implements the RemoveConstSharedPtr policy.