Mantid
Loading...
Searching...
No Matches
WorkspaceHistory.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 +
12
13#include <boost/python/class.hpp>
14#include <boost/python/copy_const_reference.hpp>
15#include <boost/python/list.hpp>
16#include <boost/python/operators.hpp>
17#include <boost/python/register_ptr_to_python.hpp>
18#include <boost/python/self.hpp>
19
21using namespace boost::python;
23
25
26
32boost::python::list getHistoriesAsList(const WorkspaceHistory &self) {
33 boost::python::list names;
34 const auto &histories = self.getAlgorithmHistories();
35 for (const auto &historie : histories) {
36 names.append(historie);
37 }
38 return names;
39}
40
42 register_ptr_to_python<WorkspaceHistory *>();
43
44 class_<WorkspaceHistory, boost::noncopyable>("WorkspaceHistory", no_init)
45
46 .def("getAlgorithmHistories", &getHistoriesAsList, arg("self"),
47 "Returns a list of algorithm histories for this workspace history.")
48
49 .def("getAlgorithmHistory", &WorkspaceHistory::getAlgorithmHistory, (arg("self"), arg("index")),
50 return_value_policy<Policies::RemoveConstSharedPtr>(),
51 "Returns the algorithm history at the given index in the history")
52
53 .def("size", &WorkspaceHistory::size, arg("self"), "Returns the number of algorithms in the immediate history")
54
55 .def("empty", &WorkspaceHistory::empty, arg("self"), "Returns whether the history has any entries")
56
57 .def("lastAlgorithm", &WorkspaceHistory::lastAlgorithm, arg("self"),
58 "Returns the last algorithm run on this workspace so that its "
59 "properties can be accessed")
60
61 .def("getAlgorithm", &WorkspaceHistory::getAlgorithm, (arg("self"), arg("index")),
62 "Returns the algorithm at the given index in the history")
63
64 // ----------------- Operators --------------------------------------
65 .def("__getitem__", &WorkspaceHistory::getAlgorithm, (arg("self"), arg("index")),
66 "Create an algorithm from a history record at a given index")
67 .def(self_ns::str(self));
68}
#define GET_POINTER_SPECIALIZATION(TYPE)
Definition: GetPointer.h:17
boost::python::list getHistoriesAsList(const WorkspaceHistory &self)
Return a Python list of history objects from the workspace history as this is far easier to work with...
void export_WorkspaceHistory()
This class stores information about the Workspace History used by algorithms on a workspace and the e...
std::shared_ptr< IAlgorithm > getAlgorithm(const size_t index) const
Create an algorithm from a history record at a given index.
AlgorithmHistory_const_sptr getAlgorithmHistory(const size_t index) const
Retrieve an algorithm history by index.
std::shared_ptr< IAlgorithm > lastAlgorithm() const
Convenience function for retrieving the last algorithm.
bool empty() const
Is the history empty.
size_t size() const
How many entries are there.
Definition: NDArray.h:49