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