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"
22#include <boost/python/class.hpp>
23#include <boost/python/copy_const_reference.hpp>
24#include <boost/python/list.hpp>
25#include <boost/python/overloads.hpp>
26#include <boost/python/register_ptr_to_python.hpp>
27
31using namespace Mantid::PythonInterface;
32using namespace boost::python;
33
35
36
37// As we can't have two converters in the global namespace we will
38// keep the converter with ExperimentInfo despite the C++ impl moving to
39// InstrumentFileFinder for backwards compatibility and as there is a single
40// user
41list getResourceFilenames(const std::string &prefix, const list &fileFormats, const list &directoryNames,
42 const std::string &date) {
45 Converters::PySequenceToVector<std::string>(directoryNames)(), date));
46}
47
49 PyErr_Warn(PyExc_DeprecationWarning,
50 "'ExperimentInfo.getInstrument()' is deprecated in Mantid 7.0. "
51 "Use the componentInfo(), detectorInfo() and spectrumInfo() access layers instead. "
52 "See the 'Instrument Access via SpectrumInfo, DetectorInfo, ComponentInfo' concept page, "
53 "located at: https://docs.mantidproject.org/nightly/concepts/InstrumentAccessLayers.html");
54 return self.getInstrument();
55}
56
57std::string getInstrumentFilenameWarn(const std::string &instName, const std::string &date = "") {
58 PyErr_Warn(PyExc_DeprecationWarning, "ExperimentInfo.getInstrumentFilename() is deprecated.\n"
59 "Use InstrumentFileFinder.getInstrumentFilename() instead.");
61}
62
63GNU_DIAG_OFF("unused-local-typedef")
64// Ignore -Wconversion warnings coming from boost::python
65// Seen with GCC 7.1.1 and Boost 1.63.0
66GNU_DIAG_OFF("conversion")
68// cppcheck-suppress unknownMacro
69BOOST_PYTHON_FUNCTION_OVERLOADS(getInstrumentFilename_Overload, getInstrumentFilenameWarn, 1, 2)
70GNU_DIAG_ON("conversion")
71GNU_DIAG_ON("unused-local-typedef")
72
73namespace {
74void setSample(ExperimentInfo &expInfo, const Mantid::API::Sample &sample) { expInfo.mutableSample() = sample; }
75void setRun(ExperimentInfo &expInfo, const Mantid::API::Run &run) { expInfo.mutableRun() = run; }
76
77// Forward the InstrumentMetadata accessors so that the metadata object itself does not
78// need to be handed out to Python.
79Mantid::Types::Core::DateAndTime instrumentValidFromDate(const ExperimentInfo &expInfo) {
80 return expInfo.instrumentMetadata().validFromDate();
81}
82Mantid::Types::Core::DateAndTime instrumentValidToDate(const ExperimentInfo &expInfo) {
83 return expInfo.instrumentMetadata().validToDate();
84}
85const std::string &instrumentFilename(const ExperimentInfo &expInfo) { return expInfo.instrumentMetadata().filename(); }
86const std::string &instrumentXmlText(const ExperimentInfo &expInfo) { return expInfo.instrumentMetadata().xmlText(); }
87const std::string &instrumentDefaultView(const ExperimentInfo &expInfo) {
88 return expInfo.instrumentMetadata().defaultView();
89}
90const std::string &instrumentDefaultAxis(const ExperimentInfo &expInfo) {
91 return expInfo.instrumentMetadata().defaultAxis();
92}
93} // namespace
94
96 register_ptr_to_python<std::shared_ptr<ExperimentInfo>>();
97
98 class_<ExperimentInfo, boost::noncopyable>("ExperimentInfo", no_init)
99 .def("getInstrument", &getInstrumentDeprecated, return_value_policy<RemoveConstSharedPtr>(), args("self"),
100 "Returns the :class:`~mantid.geometry.Instrument` for this run "
101 "(deprecated, use the componentInfo/detectorInfo/spectrumInfo access layers).")
102 // InstrumentFileFinder binds Kept for backwards compat.
103 .def("getResourceFilenames", &getResourceFilenames,
104 (arg("prefix"), arg("fileFormats"), arg("directoryNames"), arg("date")),
105 "Compile a list of files in compliance with name pattern-matching,\n"
106 "file format, and date-stamp constraints\n\n"
107 "Ideally, the valid-from and valid-to of any valid file should\n"
108 "encapsulate the argument date. If this is not possible, then\n"
109 "the file with the most recent valid-from stamp is selected\n\n"
110 "prefix: the name of a valid file must begin with this "
111 "pattern\n"
112 "fileFormats: list of valid file extensions\n"
113 "directoryNames: list of directories to be searched\n"
114 "date : the 'valid-from' and 'valid-to 'dates of a valid\n"
115 "file will encapsulate this date (e.g '1900-01-31 23:59:00')\n"
116 "\nreturns : list of absolute paths for each valid file\n")
117 .staticmethod("getResourceFilenames")
118 .def("getInstrumentFilename", &InstrumentFileFinder::getInstrumentFilename,
119 getInstrumentFilename_Overload("Returns IDF filename", (arg("instrument"), arg("date") = "")))
120 .staticmethod("getInstrumentFilename")
121 .def("sample", &ExperimentInfo::sample, return_value_policy<reference_existing_object>(), args("self"),
122 "Return the :class:`~mantid.api.Sample` object. This cannot be "
123 "modified, use mutableSample to modify.")
124 .def("mutableSample", &ExperimentInfo::mutableSample, return_value_policy<reference_existing_object>(),
125 args("self"), "Return a modifiable :class:`~mantid.api.Sample` object.")
126 .def("run", &ExperimentInfo::run, return_value_policy<reference_existing_object>(), args("self"),
127 "Return the :class:`~mantid.api.Run` object. This cannot be "
128 "modified, use mutableRun to modify.")
129 .def("mutableRun", &ExperimentInfo::mutableRun, return_value_policy<reference_existing_object>(), args("self"),
130 "Return a modifiable :class:`~mantid.api.Run` object.")
131 .def("getRunNumber", &ExperimentInfo::getRunNumber, args("self"), "Returns the run identifier for this run.")
132 .def("getEFixed", (double (ExperimentInfo::*)(const Mantid::detid_t) const) & ExperimentInfo::getEFixed,
133 args("self", "detId"))
134 .def("setEFixed", &ExperimentInfo::setEFixed, args("self", "detId", "value"))
135 .def("getEMode", &ExperimentInfo::getEMode, args("self"), "Returns the energy mode.")
136 .def("detectorInfo", &ExperimentInfo::detectorInfo, return_value_policy<reference_existing_object>(),
137 args("self"),
138 "Return a const reference to the "
139 ":class:`~mantid.geometry.DetectorInfo` "
140 "object.")
141 .def("spectrumInfo", &ExperimentInfo::spectrumInfo, return_value_policy<reference_existing_object>(),
142 args("self"),
143 "Return a const reference to the :class:`~mantid.api.SpectrumInfo` "
144 "object.")
145 .def("componentInfo", &ExperimentInfo::componentInfo, return_value_policy<reference_existing_object>(),
146 args("self"),
147 "Return a const reference to the "
148 ":class:`~mantid.geometry.ComponentInfo` "
149 "object.")
150 .def("instrumentValidFromDate", &instrumentValidFromDate, args("self"),
151 "Return the valid-from :class:`~mantid.kernel.DateAndTime` of the instrument.")
152 .def("instrumentValidToDate", &instrumentValidToDate, args("self"),
153 "Return the valid-to :class:`~mantid.kernel.DateAndTime` of the instrument.")
154 .def("instrumentFilename", &instrumentFilename, args("self"), return_value_policy<copy_const_reference>(),
155 "Return the name of the file that the original IDF was from.")
156 .def("instrumentXmlText", &instrumentXmlText, args("self"), return_value_policy<copy_const_reference>(),
157 "Return the instrument XML.")
158 .def("instrumentDefaultView", &instrumentDefaultView, args("self"), return_value_policy<copy_const_reference>(),
159 "Return the name of the preferred view in instrument view.")
160 .def("instrumentDefaultAxis", &instrumentDefaultAxis, args("self"), return_value_policy<copy_const_reference>(),
161 "Return the axis the instrument view is wrapped around by default.")
162 .def("getInstrumentName", &ExperimentInfo::getInstrumentName, args("self"),
163 "Return the name of the instrument for this experiment.")
164 .def("setSample", setSample, args("self", "sample"))
165 .def("setRun", setRun, args("self", "run"))
166 .def("populateInstrumentParameters", &ExperimentInfo::populateInstrumentParameters, (arg("self")),
167 "Update parameters in the instrument-parameter map. Logs must be loaded before calling this method");
168}
#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.
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
This class stores information about the sample used in particular run.
Definition Sample.h:33
const Types::Core::DateAndTime & validFromDate() const
const Types::Core::DateAndTime & validToDate() const
const std::string & defaultAxis() const
const std::string & defaultView() const
std::shared_ptr< const Instrument > Instrument_const_sptr
Shared pointer to an const instrument object.
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.