Skip to content

Commit

Permalink
Add pass-through methods for DataProcessor
Browse files Browse the repository at this point in the history
MSVC won't compile when they have been redefined as public on the adapter
class when used in conjunction with the boost.python class_ exporter.
Refs #5157
  • Loading branch information
martyngigg committed Mar 28, 2014
1 parent f3c7a76 commit dbf9091
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 28 deletions.
Expand Up @@ -46,20 +46,48 @@ namespace Mantid
/// A constructor that looks like a Python __init__ method
DataProcessorAdapter(PyObject* self);

// Public access for protected base methods for boost.python to call
using API::DataProcessorAlgorithm::setLoadAlg;
using API::DataProcessorAlgorithm::setLoadAlgFileProp;
using API::DataProcessorAlgorithm::setAccumAlg;
using API::DataProcessorAlgorithm::determineChunk;
using API::DataProcessorAlgorithm::loadChunk;
using API::DataProcessorAlgorithm::load;
using API::DataProcessorAlgorithm::splitInput;
using API::DataProcessorAlgorithm::forwardProperties;
using API::DataProcessorAlgorithm::getProcessProperties;
using API::DataProcessorAlgorithm::assemble;
using API::DataProcessorAlgorithm::saveNexus;
using API::DataProcessorAlgorithm::isMainThread;
using API::DataProcessorAlgorithm::getNThreads;
// -------------------- Pass through methods ----------------------------
// Boost.python needs public access to the base class methods in order to
// be able to call them. We should just be able to put a using declaration
// to raise the methods to public but this does not work on MSVC as in
// the class_ definition it can't seem to figure out that its calling
// this class not DataProcessorAlgorithm. This means we have to resort to
// proxy methods :(

void setLoadAlgProxy(const std::string & alg) { this->setLoadAlg(alg); }

void setLoadAlgFilePropProxy(const std::string & filePropName) { this->setLoadAlgFileProp(filePropName); }

void setAccumAlgProxy(const std::string & alg) { this->setAccumAlg(alg); }

API::ITableWorkspace_sptr determineChunkProxy() { return this->determineChunk(); }

void loadChunkProxy() { this->loadChunk(); }

API::Workspace_sptr loadProxy(const std::string &inputData, const bool loadQuiet = false) { return this->load(inputData, loadQuiet); }

std::vector<std::string> splitInputProxy(const std::string & input) { return this->splitInput(input); }

void forwardPropertiesProxy() { this->forwardProperties(); }

boost::shared_ptr<Kernel::PropertyManager> getProcessPropertiesProxy(const std::string &propertyManager)
{
return this->getProcessProperties(propertyManager);
}

API::Workspace_sptr assembleProxy(const std::string &partialWSName, const std::string &outputWSName)
{
return this->assemble(partialWSName, outputWSName);
}
void saveNexusProxy(const std::string &outputWSName, const std::string &outputFile)
{
this->saveNexus(outputWSName, outputFile);
}

bool isMainThreadProxy() { return this->isMainThread(); }

int getNThreadsProxy() { return this->getNThreads(); }
// ------------------------------------------------------------------------

private:
/// The PyObject must be supplied to construct the object
Expand Down
Expand Up @@ -23,53 +23,53 @@ void export_DataProcessorAlgorithm()

class_<DataProcessorAlgorithm, bases<Algorithm>, boost::shared_ptr<DataProcessorAdapter>,
boost::noncopyable>("DataProcessorAlgorithm", "Base class workflow-type algorithms")
.def("setLoadAlg", &DataProcessorAdapter::setLoadAlg,
.def("setLoadAlg", &DataProcessorAdapter::setLoadAlgProxy,
"Set the name of the algorithm called using the load() method [Default=Load]")

.def("setLoadAlgFileProp", &DataProcessorAdapter::setLoadAlgFileProp,
.def("setLoadAlgFileProp", &DataProcessorAdapter::setLoadAlgFilePropProxy,
"Set the name of the file property for the load algorithm when using "
"the load() method [Default=Filename]")

.def("setAccumAlg", &DataProcessorAdapter::setAccumAlg,
.def("setAccumAlg", &DataProcessorAdapter::setAccumAlgProxy,
"Set the name of the algorithm called to accumulate a chunk of processed data [Default=Plus]")

.def("determineChunk", &DataProcessorAdapter::determineChunk,
.def("determineChunk", &DataProcessorAdapter::determineChunkProxy,
"Return a TableWorkspace containing the information on how to split the "
"input file when processing in chunks")

.def("loadChunk", &DataProcessorAdapter::loadChunk,
.def("loadChunk", &DataProcessorAdapter::loadChunkProxy,
"Load a chunk of data")

.def("load", (loadOverload1)&DataProcessorAdapter::load,
.def("load", (loadOverload1)&DataProcessorAdapter::loadProxy,
"Loads the given file or workspace data and returns the workspace. "
"The output is not stored in the AnalysisDataService.")

.def("load", (loadOverload2)&DataProcessorAdapter::load,
.def("load", (loadOverload2)&DataProcessorAdapter::loadProxy,
"Loads the given file or workspace data and returns the workspace. "
"If loadQuiet=True then output is not stored in the AnalysisDataService.")

.def("splitInput", &DataProcessorAdapter::splitInput,
.def("splitInput", &DataProcessorAdapter::splitInputProxy,
return_value_policy<VectorToNumpy>())

.def("forwardProperties", &DataProcessorAdapter::forwardProperties)
.def("forwardProperties", &DataProcessorAdapter::forwardPropertiesProxy)

.def("getProcessProperties", &DataProcessorAdapter::getProcessProperties,
.def("getProcessProperties", &DataProcessorAdapter::getProcessPropertiesProxy,
"Returns the named property manager from the service or creates "
"a new one if it does not exist")

.def("assemble", &DataProcessorAdapter::assemble,
.def("assemble", &DataProcessorAdapter::assembleProxy,
"If an MPI build, assemble the partial workspaces from all MPI processes. "
"Otherwise, simply returns the input workspace")

.def("saveNexus", &DataProcessorAdapter::saveNexus,
.def("saveNexus", &DataProcessorAdapter::saveNexusProxy,
"Save a workspace as a nexus file. If this is an MPI build then saving only "
"happens for the main thread.")

.def("isMainThread", &DataProcessorAdapter::isMainThread,
.def("isMainThread", &DataProcessorAdapter::isMainThreadProxy,
"Returns true if this algorithm is the main thread for an MPI build. For "
"non-MPI build it always returns true")

.def("getNThreads", &DataProcessorAdapter::getNThreads,
.def("getNThreads", &DataProcessorAdapter::getNThreadsProxy,
"Returns the number of running MPI processes in an MPI build or 1 for "
"a non-MPI build")
;
Expand Down

0 comments on commit dbf9091

Please sign in to comment.