17#include <boost/python/enum.hpp>
19#include <boost/python/list.hpp>
20#include <boost/python/overloads.hpp>
21#include <boost/python/return_value_policy.hpp>
31std::once_flag INIT_FLAG;
41 auto &ads = AnalysisDataService::Instance();
42 std::call_once(INIT_FLAG, []() {
45 PyRun_SimpleString(
"import atexit\n"
46 "def cleanup_ADS():\n"
47 " from mantid.api import AnalysisDataService\n"
48 " AnalysisDataService.clear(True)\n"
49 "atexit.register(cleanup_ADS)");
61list retrieveWorkspaces(
AnalysisDataServiceImpl const *
const self,
const list &names,
bool unrollGroups =
false) {
62 using WeakPtr = std::weak_ptr<Workspace>;
63 const auto wsSharedPtrs =
65 std::vector<WeakPtr> wsWeakPtrs;
66 wsWeakPtrs.reserve(wsSharedPtrs.size());
67 std::transform(wsSharedPtrs.cbegin(), wsSharedPtrs.cend(), std::back_inserter(wsWeakPtrs),
68 [](
const Workspace_sptr &wksp) -> WeakPtr { return WeakPtr(wksp); });
73 using WeakPtr = std::weak_ptr<Workspace>;
79 return !gws->isGroupPeaksWorkspaces();
83 auto end = std::remove_if(wsSharedPtrs.begin(), wsSharedPtrs.end(), isNotGroupPeakWorkspace);
84 wsSharedPtrs.erase(end, wsSharedPtrs.end());
86 std::vector<WeakPtr> wsWeakPtrs;
87 wsWeakPtrs.reserve(wsSharedPtrs.size());
88 std::transform(wsSharedPtrs.cbegin(), wsSharedPtrs.cend(), std::back_inserter(wsWeakPtrs),
89 [](
const Workspace_sptr &wksp) -> WeakPtr { return WeakPtr(wksp); });
98BOOST_PYTHON_FUNCTION_OVERLOADS(AdsRetrieveWorkspacesOverloads, retrieveWorkspaces, 2, 3)
105 auto pythonClass = ADSExporter::define(
"AnalysisDataServiceImpl");
107 .def(
"Instance", instance, return_value_policy<reference_existing_object>(),
108 "Return a reference to the singleton instance")
109 .staticmethod(
"Instance")
110 .def(
"retrieveWorkspaces", retrieveWorkspaces,
111 AdsRetrieveWorkspacesOverloads(
"Retrieve a list of workspaces by name",
112 (arg(
"self"), arg(
"names"), arg(
"unrollGroups") =
false)))
113 .def(
"retrieveGroupPeaksWorkspaces", retrieveGroupPeaksWorkspaces, (arg(
"self"), arg(
"names")))
115 "Add a workspace in the ADS to a group in the ADS")
117 "Remove a workspace from a group in the ADS")
119 (arg(
"self"), arg(
"n") = 5, arg(
"prefix") =
"", arg(
"suffix") =
""),
120 "Return a randomly generated unique name for a workspace\n"
122 ":param str n: length of string of random numbers\n"
123 ":param str prefix: String to be prepended to the generated string\n"
124 ":param str suffix: String to be appended to the generated string\n"
125 ":return: prefix + n*random characters + suffix\n"
128 "Return a randomly generated unique hidden workspace name.");
#define GET_POINTER_SPECIALIZATION(TYPE)
void export_AnalysisDataService()
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
const std::string uniqueName(const int n=5, const std::string &prefix="", const std::string &suffix="")
Random generated unique workspace name.
void addToGroup(const std::string &groupName, const std::string &wsName)
Add a workspace to a group.
std::vector< Workspace_sptr > retrieveWorkspaces(const std::vector< std::string > &names, bool unrollGroups=false) const
Given a list of names retrieve the corresponding workspace handles.
const std::string uniqueHiddenName()
Random generated unique hidden workspace name.
void removeFromGroup(const std::string &groupName, const std::string &wsName)
Remove a workspace from a group but not from the ADS.
Class to hold a set of workspaces.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
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.
A helper struct to export templated DataService<> types to Python.