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