Mantid
Loading...
Searching...
No Matches
DataProcessorAdapter.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2014 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#pragma once
8
9//-----------------------------------------------------------------------------
10// Includes
11//-----------------------------------------------------------------------------
17
18namespace Mantid {
19namespace PythonInterface {
28template <class Base> class DataProcessorAdapter : public AlgorithmAdapter<API::GenericDataProcessorAlgorithm<Base>> {
29public:
31 DataProcessorAdapter(PyObject *self);
32
36
39
42
43 // -------------------- Pass through methods ----------------------------
44 // Boost.python needs public access to the base class methods in order to
45 // be able to call them. We should just be able to put a using declaration
46 // to raise the methods to public but this does not work on MSVC as in
47 // the class_ definition it can't seem to figure out that its calling
48 // this class not DataProcessorAlgorithm. This means we have to resort to
49 // proxy methods :(
50
51 void setLoadAlgProxy(const std::string &alg) { this->setLoadAlg(alg); }
52
53 void setLoadAlgFilePropProxy(const std::string &filePropName) { this->setLoadAlgFileProp(filePropName); }
54
55 void setAccumAlgProxy(const std::string &alg) { this->setAccumAlg(alg); }
56
57 API::ITableWorkspace_sptr determineChunkProxy(const std::string &filename) { return this->determineChunk(filename); }
58
59 void loadChunkProxy(const size_t rowIndex) { this->loadChunk(rowIndex); }
60
61 void copyPropertiesProxy(const std::string &algName, const boost::python::object &propNames, const int version = -1) {
62 if (algName.empty()) {
63 throw std::invalid_argument("Failed to specify algorithm name");
64 }
65
66 std::vector<std::string> names;
67 if (!Mantid::PythonInterface::isNone(propNames)) {
68 boost::python::extract<std::string> extractor(propNames);
69 if (extractor.check()) {
70 names = std::vector<std::string>(1, extractor());
71 } else {
73 }
74
75 auto algorithm = API::AlgorithmManager::Instance().createUnmanaged(algName, version);
76 algorithm->initialize();
77
78 for (const auto &name : names) {
79 this->copyProperty(algorithm, name);
80 }
81 } else {
82 std::string msg("Failed to specify properties to copy from \"");
83 msg.append(algName).append("\"");
84 throw std::invalid_argument(msg);
85 }
86 }
87
88 API::Workspace_sptr loadProxy(const std::string &inputData, const bool loadQuiet = false) {
89 return this->load(inputData, loadQuiet);
90 }
91
92 std::vector<std::string> splitInputProxy(const std::string &input) { return this->splitInput(input); }
93
95
96 std::shared_ptr<Kernel::PropertyManager>
97 getProcessPropertiesProxy(const std::string &propertyManager = std::string()) {
98 return this->getProcessProperties(propertyManager);
99 }
100
101 API::Workspace_sptr assembleProxy(const std::string &partialWSName, const std::string &outputWSName) {
102 return this->assemble(partialWSName, outputWSName);
103 }
104
105 void saveNexusProxy(const std::string &outputWSName, const std::string &outputFile) {
106 this->saveNexus(outputWSName, outputFile);
107 }
108
109 bool isMainThreadProxy() { return this->isMainThread(); }
110
111 int getNThreadsProxy() { return this->getNThreads(); }
112 // ------------------------------------------------------------------------
113};
114} // namespace PythonInterface
115} // namespace Mantid
std::shared_ptr< Kernel::PropertyManager > getProcessProperties(const std::string &propertyManager=std::string()) const
Get the property manager object of a given name from the property manager data service,...
Workspace_sptr assemble(Workspace_sptr partialWS)
Assemble the partial workspaces from all MPI processes.
virtual ITableWorkspace_sptr determineChunk(const std::string &filename)
bool isMainThread()
Return true if we are running on the main thread.
void saveNexus(const std::string &outputWSName, const std::string &outputFile)
Save a workspace as a nexus file, with check for which thread we are executing in.
void copyProperty(const API::Algorithm_sptr &alg, const std::string &name)
Copy a property from an existing algorithm.
std::vector< std::string > splitInput(const std::string &input)
void setLoadAlgFileProp(const std::string &filePropName)
int getNThreads()
Return the number of MPI processes running.
virtual MatrixWorkspace_sptr loadChunk(const size_t rowIndex)
Workspace_sptr load(const std::string &inputData, const bool loadQuiet=false)
Determine what kind of input data we have and load it.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python ...
const std::string name() const override
Returns the name of the algorithm.
Provides a layer class for boost::python to allow C++ virtual functions to be overridden in a Python ...
DataProcessorAdapter(const DataProcessorAdapter &)=delete
Disable copy operator.
API::Workspace_sptr loadProxy(const std::string &inputData, const bool loadQuiet=false)
DataProcessorAdapter()=delete
Disable default constructor - The PyObject must be supplied to construct the object.
void copyPropertiesProxy(const std::string &algName, const boost::python::object &propNames, const int version=-1)
API::ITableWorkspace_sptr determineChunkProxy(const std::string &filename)
API::Workspace_sptr assembleProxy(const std::string &partialWSName, const std::string &outputWSName)
std::vector< std::string > splitInputProxy(const std::string &input)
void setLoadAlgFilePropProxy(const std::string &filePropName)
std::shared_ptr< Kernel::PropertyManager > getProcessPropertiesProxy(const std::string &propertyManager=std::string())
DataProcessorAdapter & operator=(const DataProcessorAdapter &)=delete
Disable assignment operator.
void saveNexusProxy(const std::string &outputWSName, const std::string &outputFile)
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
bool isNone(PyObject *ptr)
Definition: IsNone.h:26
Helper class which provides the Collimation Length for SANS instruments.
Converts a Python sequence type to a C++ std::vector, where the element type is defined by the templa...