Mantid
Loading...
Searching...
No Matches
ExperimentInfo.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 +
9#include "MantidAPI/Run.h"
10#include "MantidAPI/Sample.h"
25#include <boost/python/class.hpp>
26#include <boost/python/copy_const_reference.hpp>
27#include <boost/python/list.hpp>
28#include <boost/python/overloads.hpp>
29#include <boost/python/register_ptr_to_python.hpp>
30
34using namespace Mantid::PythonInterface;
35using namespace boost::python;
36
38
39
40// As we can't have two converters in the global namespace we will
41// keep the converter with ExperimentInfo despite the C++ impl moving to
42// InstrumentFileFinder for backwards compatibility and as there is a single
43// user
44list getResourceFilenames(const std::string &prefix, const list &fileFormats, const list &directoryNames,
45 const std::string &date) {
48 Converters::PySequenceToVector<std::string>(directoryNames)(), date));
49}
50
62
63std::string getInstrumentFilenameWarn(const std::string &instName, const std::string &date = "") {
64 if (PyErr_Warn(PyExc_DeprecationWarning, "ExperimentInfo.getInstrumentFilename() is deprecated.\n"
65 "Use InstrumentFileFinder.getInstrumentFilename() instead.") < 0)
66 throw boost::python::error_already_set();
68}
69
70GNU_DIAG_OFF("unused-local-typedef")
71// Ignore -Wconversion warnings coming from boost::python
72// Seen with GCC 7.1.1 and Boost 1.63.0
73GNU_DIAG_OFF("conversion")
75// cppcheck-suppress unknownMacro
76BOOST_PYTHON_FUNCTION_OVERLOADS(getInstrumentFilename_Overload, getInstrumentFilenameWarn, 1, 2)
77GNU_DIAG_ON("conversion")
78GNU_DIAG_ON("unused-local-typedef")
79
80namespace {
81void setSample(ExperimentInfo &expInfo, const Mantid::API::Sample &sample) { expInfo.mutableSample() = sample; }
82void setRun(ExperimentInfo &expInfo, const Mantid::API::Run &run) { expInfo.mutableRun() = run; }
83
84// Forward the InstrumentMetadata accessors so that the metadata object itself does not
85// need to be handed out to Python.
86Mantid::Types::Core::DateAndTime instrumentValidFromDate(const ExperimentInfo &expInfo) {
87 return expInfo.instrumentMetadata().validFromDate();
88}
89Mantid::Types::Core::DateAndTime instrumentValidToDate(const ExperimentInfo &expInfo) {
90 return expInfo.instrumentMetadata().validToDate();
91}
92const std::string &instrumentFilename(const ExperimentInfo &expInfo) { return expInfo.instrumentMetadata().filename(); }
93const std::string &instrumentXmlText(const ExperimentInfo &expInfo) { return expInfo.instrumentMetadata().xmlText(); }
94const std::string &instrumentDefaultView(const ExperimentInfo &expInfo) {
95 return expInfo.instrumentMetadata().defaultView();
96}
97const std::string &instrumentDefaultAxis(const ExperimentInfo &expInfo) {
98 return expInfo.instrumentMetadata().defaultAxis();
99}
100
103Mantid::Geometry::IObject_sptr getLabFrameSampleShape(const ExperimentInfo &self) {
105}
106} // namespace
107
109 register_ptr_to_python<std::shared_ptr<ExperimentInfo>>();
110
111 class_<ExperimentInfo, boost::noncopyable>("ExperimentInfo", no_init)
112 .def("getInstrument", &getInstrumentDeprecated, return_value_policy<RemoveConstSharedPtr>(), args("self"),
113 "Returns the :class:`~mantid.geometry.Instrument` for this run "
114 "(deprecated, use the componentInfo/detectorInfo/spectrumInfo access layers).")
115 // InstrumentFileFinder binds Kept for backwards compat.
116 .def("getResourceFilenames", &getResourceFilenames,
117 (arg("prefix"), arg("fileFormats"), arg("directoryNames"), arg("date")),
118 "Compile a list of files in compliance with name pattern-matching,\n"
119 "file format, and date-stamp constraints\n\n"
120 "Ideally, the valid-from and valid-to of any valid file should\n"
121 "encapsulate the argument date. If this is not possible, then\n"
122 "the file with the most recent valid-from stamp is selected\n\n"
123 "prefix: the name of a valid file must begin with this "
124 "pattern\n"
125 "fileFormats: list of valid file extensions\n"
126 "directoryNames: list of directories to be searched\n"
127 "date : the 'valid-from' and 'valid-to 'dates of a valid\n"
128 "file will encapsulate this date (e.g '1900-01-31 23:59:00')\n"
129 "\nreturns : list of absolute paths for each valid file\n")
130 .staticmethod("getResourceFilenames")
131 .def("getInstrumentFilename", &InstrumentFileFinder::getInstrumentFilename,
132 getInstrumentFilename_Overload("Returns IDF filename", (arg("instrument"), arg("date") = "")))
133 .staticmethod("getInstrumentFilename")
134 .def("sample", &ExperimentInfo::sample, return_value_policy<reference_existing_object>(), args("self"),
135 "Return the :class:`~mantid.api.Sample` object. This cannot be "
136 "modified, use mutableSample to modify.")
137 .def("mutableSample", &ExperimentInfo::mutableSample, return_value_policy<reference_existing_object>(),
138 args("self"), "Return a modifiable :class:`~mantid.api.Sample` object.")
139 .def("getLabFrameSampleShape", &getLabFrameSampleShape, args("self"),
140 "Return the sample shape as it sits in the lab frame, rotated by whatever part of this "
141 "workspace's goniometer rotation the shape does not already carry.\n\n"
142 "A shape may be stored in its own frame or already rotated into the lab frame - "
143 ":ref:`algm-CopySample` bakes the goniometer in, while :ref:`algm-SetGoniometer` alone "
144 "leaves the shape untouched - so rotating by the goniometer unconditionally would turn an "
145 "already-rotated shape a second time. This applies only what is outstanding, and returns "
146 "a new shape; the workspace's own sample is unchanged.")
147 .def("run", &ExperimentInfo::run, return_value_policy<reference_existing_object>(), args("self"),
148 "Return the :class:`~mantid.api.Run` object. This cannot be "
149 "modified, use mutableRun to modify.")
150 .def("mutableRun", &ExperimentInfo::mutableRun, return_value_policy<reference_existing_object>(), args("self"),
151 "Return a modifiable :class:`~mantid.api.Run` object.")
152 .def("getRunNumber", &ExperimentInfo::getRunNumber, args("self"), "Returns the run identifier for this run.")
153 .def("getEFixed", (double (ExperimentInfo::*)(const Mantid::detid_t) const) & ExperimentInfo::getEFixed,
154 args("self", "detId"))
155 .def("setEFixed", &ExperimentInfo::setEFixed, args("self", "detId", "value"))
156 .def("getEMode", &ExperimentInfo::getEMode, args("self"), "Returns the energy mode.")
157 .def("detectorInfo", &ExperimentInfo::detectorInfo, return_value_policy<reference_existing_object>(),
158 args("self"),
159 "Return a const reference to the "
160 ":class:`~mantid.geometry.DetectorInfo` "
161 "object.")
162 .def("spectrumInfo", &ExperimentInfo::spectrumInfo, return_value_policy<reference_existing_object>(),
163 args("self"),
164 "Return a const reference to the :class:`~mantid.api.SpectrumInfo` "
165 "object.")
166 .def("componentInfo", &ExperimentInfo::componentInfo, return_value_policy<reference_existing_object>(),
167 args("self"),
168 "Return a const reference to the "
169 ":class:`~mantid.geometry.ComponentInfo` "
170 "object.")
171 .def("baseComponentInfo", &ExperimentInfo::baseComponentInfo, return_value_policy<reference_existing_object>(),
172 args("self"),
173 "Return a const reference to a :class:`~mantid.geometry.ComponentInfo` "
174 "describing the base instrument: the geometry as loaded from the instrument "
175 "definition, before any moves, rotations or other parameters were applied.")
176 .def("instrumentValidFromDate", &instrumentValidFromDate, args("self"),
177 "Return the valid-from :class:`~mantid.kernel.DateAndTime` of the instrument.")
178 .def("instrumentValidToDate", &instrumentValidToDate, args("self"),
179 "Return the valid-to :class:`~mantid.kernel.DateAndTime` of the instrument.")
180 .def("instrumentFilename", &instrumentFilename, args("self"), return_value_policy<copy_const_reference>(),
181 "Return the name of the file that the original IDF was from.")
182 .def("instrumentXmlText", &instrumentXmlText, args("self"), return_value_policy<copy_const_reference>(),
183 "Return the instrument XML.")
184 .def("instrumentDefaultView", &instrumentDefaultView, args("self"), return_value_policy<copy_const_reference>(),
185 "Return the name of the preferred view in instrument view.")
186 .def("instrumentDefaultAxis", &instrumentDefaultAxis, args("self"), return_value_policy<copy_const_reference>(),
187 "Return the axis the instrument view is wrapped around by default.")
188 .def("getInstrumentName", &ExperimentInfo::getInstrumentName, args("self"),
189 "Return the name of the instrument for this experiment.")
190 .def("setSample", setSample, args("self", "sample"))
191 .def("setRun", setRun, args("self", "run"))
192 .def("populateInstrumentParameters", &ExperimentInfo::populateInstrumentParameters, (arg("self")),
193 "Update parameters in the instrument-parameter map. Logs must be loaded before calling this method");
194}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
std::string getInstrumentFilenameWarn(const std::string &instName, const std::string &date="")
list getResourceFilenames(const std::string &prefix, const list &fileFormats, const list &directoryNames, const std::string &date)
Converter from C++ signature to python signature.
Mantid::Geometry::Instrument_const_sptr getInstrumentDeprecated(const ExperimentInfo &self)
void export_ExperimentInfo()
#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.
This class is shared by a few Workspace types and holds information related to a particular experimen...
Run & mutableRun()
Writable version of the run object.
const SpectrumInfo & spectrumInfo() const
Return a reference to the SpectrumInfo object.
Geometry::InstrumentMetadata const & instrumentMetadata() const
const Geometry::DetectorInfo & detectorInfo() const
Return a const reference to the DetectorInfo object.
double getEFixed(const detid_t detID) const
Easy access to the efixed value for this run & detector ID.
const Run & run() const
Run details object access.
Geometry::ComponentInfo const & baseComponentInfo() const
Returns a ComponentInfo for the base (unparametrized) instrument, i.e.
std::string getInstrumentName() const
Return the name of the instrument from the ComponentInfo object.
Geometry::Instrument_const_sptr getInstrument() const
Returns the parameterized instrument.
Kernel::DeltaEMode::Type getEMode() const
Returns the emode for this run.
const Sample & sample() const
Sample accessors.
void setEFixed(const detid_t detID, const double value)
Set the efixed value for a given detector ID.
int getRunNumber() const
Utility method to get the run number.
const Geometry::ComponentInfo & componentInfo() const
Sample & mutableSample()
Writable version of the sample object.
void populateInstrumentParameters()
Add parameters to the instrument parameter map that are defined in instrument definition file or para...
static std::vector< std::string > getResourceFilenames(const std::string &prefix, const std::vector< std::string > &fileFormats, const std::vector< std::string > &directoryNames, const std::string &date)
Utility to retrieve a resource file (IDF, Parameters, ..)
static std::string getInstrumentFilename(const std::string &instrumentName, const std::string &date="")
Get the IDF using the instrument name and date.
This class stores information regarding an experimental run as a series of log entries.
Definition Run.h:36
const Geometry::Goniometer & getGoniometer() const
Return reference to the first const Goniometer object for this run.
Definition Run.cpp:525
This class stores information about the sample used in particular run.
Definition Sample.h:35
const Geometry::IObject & getShape() const
Return the sample shape.
Definition Sample.cpp:146
const Kernel::DblMatrix & getR() const
Return global rotation matrix.
const Types::Core::DateAndTime & validFromDate() const
const Types::Core::DateAndTime & validToDate() const
const std::string & defaultAxis() const
const std::string & defaultView() const
MANTID_GEOMETRY_DLL std::shared_ptr< IObject > getLabFrameShape(const IObject &shape, const Kernel::Matrix< double > &goniometerR)
The shape as it sits in the lab frame: a clone rotated by whatever part of goniometerR it does not al...
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
std::shared_ptr< IObject > IObject_sptr
Typdef for a shared pointer.
Definition IObject.h:106
int32_t detid_t
Typedef for a detector ID.
STL namespace.
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...
Converter that takes a std::vector and converts it into a python list.
Definition ToPyList.h:22
Implements the RemoveConstSharedPtr policy.