Mantid
Loading...
Searching...
No Matches
InstrumentDataService.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2026 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 +
7
13
14#include <boost/python/class.hpp>
15#include <boost/python/return_value_policy.hpp>
16
17using namespace Mantid::API;
18using namespace Mantid::PythonInterface;
19using namespace boost::python;
20
22
23namespace {
24
25InstrumentDataServiceImpl &instance() { return InstrumentDataService::Instance(); }
26
27Mantid::Geometry::Instrument_sptr retrieveOrKeyError(const InstrumentDataServiceImpl &self, const std::string &name) {
28 // Can't use DataServiceExporter::retrieveOrKeyError here because it returns a weak pointer which we can't use with
29 // Instrument. So we have to reimplement the same logic here, but returning a shared pointer instead.
30 try {
31 return self.retrieve(name);
33 const std::string err = "'" + name + "' does not exist.";
34 PyErr_SetString(PyExc_KeyError, err.c_str());
35 throw boost::python::error_already_set();
36 }
37}
38
39} // namespace
40
43
44 class_<InstrumentDataServiceImpl, boost::noncopyable>("InstrumentDataServiceImpl", no_init)
45 .def("Instance", instance, return_value_policy<reference_existing_object>(),
46 "Return a reference to the singleton instance")
47 .staticmethod("Instance")
48 .def("doesExist", &InstrumentDataServiceImpl::doesExist, (arg("self"), arg("name")),
49 "Returns True if the object is found in the service.")
50 .def("retrieve", retrieveOrKeyError, (arg("self"), arg("name")),
51 "Retrieve the named object. Raises an exception if the name does not exist")
52 .def("remove", &IDSExporter::removeItem, (arg("self"), arg("name")), "Remove a named object")
53 .def("clear", &InstrumentDataServiceImpl::clear, arg("self"), "Removes all objects managed by the service.")
54 .def("size", &InstrumentDataServiceImpl::size, arg("self"), "Returns the number of objects within the service")
55 .def("getObjectNames", &IDSExporter::getObjectNamesAsList, (arg("self"), arg("contain") = ""),
56 "Return the list of names currently known to the IDS");
57}
std::string name
Definition Run.cpp:60
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition GetPointer.h:17
void export_InstrumentDataService()
std::shared_ptr< T > retrieve(const std::string &name) const
Get a shared pointer to a stored data object.
Exception for when an item is not found in a collection.
Definition Exception.h:145
std::shared_ptr< Instrument > Instrument_sptr
Shared pointer to an instrument object.
A helper struct to export templated DataService<> types to Python.