25#include <boost/mpi.hpp>
38 : m_useMPI(false), m_loadAlg(
"Load"), m_accumulateAlg(
"Plus"), m_loadAlgFileProp(
"Filename"),
39 m_propertyManagerPropertyName(
"ReductionProperties") {
40 Base::enableHistoryRecordingForChild(
true);
65std::shared_ptr<Algorithm>
67 const double endProgress,
const bool enableLogging,
71 alg->enableHistoryRecordingForChild(this->isRecordingHistoryForChild());
72 if (this->isRecordingHistoryForChild()) {
74 alg->trackAlgorithmHistory(Base::m_history);
81 throw std::invalid_argument(
"Cannot set load algorithm to empty string");
86 if (filePropName.empty()) {
87 throw std::invalid_argument(
"Cannot set the load algorithm file property name");
89 m_loadAlgFileProp = filePropName;
94 throw std::invalid_argument(
"Cannot set accumulate algorithm to empty string");
95 m_accumulateAlg = alg;
99 m_propertyManagerPropertyName = propName;
112 const std::string &nameInPropManager) {
113 m_nameToPMName[nameInProp] = nameInPropManager;
129 if (!alg->existsProperty(name)) {
130 std::stringstream msg;
131 msg <<
"Algorithm \"" << alg->name() <<
"\" does not have property \"" << name <<
"\"";
132 throw std::runtime_error(msg.str());
135 auto prop = alg->getPointerToProperty(name);
136 Base::declareProperty(std::unique_ptr<Property>(prop->clone()), prop->documentation());
149 if (!Base::isDefault(name)) {
154 auto mapping = m_nameToPMName.find(name);
155 if (mapping != m_nameToPMName.end()) {
156 auto pm = this->getProcessProperties();
157 if (pm->existsProperty(mapping->second)) {
158 return pm->getPropertyValue(mapping->second);
176 if (!Base::isDefault(name)) {
177 return Base::getProperty(name);
181 auto mapping = m_nameToPMName.find(name);
182 if (mapping != m_nameToPMName.end()) {
183 auto pm = this->getProcessProperties();
184 if (pm->existsProperty(mapping->second)) {
185 return pm->getProperty(mapping->second);
197 throw std::runtime_error(
"DataProcessorAlgorithm::determineChunk is not implemented");
203 throw std::runtime_error(
"DataProcessorAlgorithm::loadChunk is not implemented");
214 auto gatherAlg = createChildAlgorithm(
"GatherWorkspaces");
215 gatherAlg->setLogging(
true);
216 gatherAlg->setAlwaysStoreInADS(
true);
217 gatherAlg->setProperty(
"InputWorkspace", partialWS);
218 gatherAlg->setProperty(
"PreserveEvents",
true);
219 gatherAlg->setPropertyValue(
"OutputWorkspace",
"_total");
220 gatherAlg->execute();
222 if (isMainThread()) {
238 [[maybe_unused]]
const std::string &outputWSName) {
240 std::string threadOutput = partialWSName;
242 auto gatherAlg = createChildAlgorithm(
"GatherWorkspaces");
243 gatherAlg->setLogging(
true);
244 gatherAlg->setAlwaysStoreInADS(
true);
245 gatherAlg->setProperty(
"InputWorkspace", partialWS);
246 gatherAlg->setProperty(
"PreserveEvents",
true);
247 gatherAlg->setPropertyValue(
"OutputWorkspace", outputWSName);
248 gatherAlg->execute();
251 threadOutput = outputWSName;
253 const std::string &threadOutput = partialWSName;
269 if (boost::mpi::communicator().rank() <= 0 && !outputFile.empty()) {
271 if (!outputFile.empty()) {
273 auto saveAlg = createChildAlgorithm(
"SaveNexus");
274 saveAlg->setPropertyValue(
"Filename", outputFile);
275 saveAlg->setPropertyValue(
"InputWorkspace", outputWSName);
284 mainThread = (boost::mpi::communicator().rank() == 0);
294 return boost::mpi::communicator().size();
314 if (foundFile.empty()) {
317 const std::vector<std::string> facilityExts = facilityInfo.
extensions();
321 if (!foundFile.empty()) {
322 Poco::Path p(foundFile);
323 const std::string outputWSName = p.getBaseName();
325 auto loadAlg = createChildAlgorithm(m_loadAlg);
326 loadAlg->setProperty(m_loadAlgFileProp, foundFile);
328 loadAlg->setAlwaysStoreInADS(
true);
334 if (loadAlg->existsProperty(
"ChunkNumber") && loadAlg->existsProperty(
"TotalChunks")) {
337 boost::mpi::communicator world;
338 g_log.
notice() <<
"Chunk/Total: " << world.rank() + 1 <<
"/" << world.size() <<
'\n';
339 loadAlg->setPropertyValue(
"OutputWorkspace", outputWSName);
340 loadAlg->setProperty(
"ChunkNumber", world.rank() + 1);
341 loadAlg->setProperty(
"TotalChunks", world.size());
347 inputWS = loadAlg->getProperty(
"OutputWorkspace");
352 throw std::runtime_error(
"DataProcessorAlgorithm::load could process any data");
366std::shared_ptr<PropertyManager>
368 std::string propertyManagerName(propertyManager);
369 if (propertyManager.empty() && (!m_propertyManagerPropertyName.empty())) {
370 if (!Base::existsProperty(m_propertyManagerPropertyName)) {
371 std::stringstream msg;
372 msg <<
"Failed to find property \"" << m_propertyManagerPropertyName <<
"\"";
375 propertyManagerName = this->getPropertyValue(m_propertyManagerPropertyName);
378 std::shared_ptr<PropertyManager> processProperties;
382 Base::getLogger().notice() <<
"Could not find property manager\n";
383 processProperties = std::make_shared<PropertyManager>();
386 return processProperties;
392 throw std::runtime_error(
"DataProcessorAlgorithm::splitInput is not implemented");
396 throw std::runtime_error(
"DataProcessorAlgorithm::forwardProperties is not implemented");
412 return this->executeBinaryAlgorithm<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Divide", lhs,
424 const double &rhsValue) {
425 return this->executeBinaryAlgorithm<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
440 return this->executeBinaryAlgorithm<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Divide", lhs,
454 const double &rhsValue) {
455 return this->executeBinaryAlgorithm<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
468 return this->executeBinaryAlgorithm<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Plus", lhs,
480 return this->executeBinaryAlgorithm<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
493 return this->executeBinaryAlgorithm<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
"Minus", lhs,
506 const double &rhsValue) {
507 return this->executeBinaryAlgorithm<MatrixWorkspace_sptr, MatrixWorkspace_sptr, MatrixWorkspace_sptr>(
519 retVal->dataY(0)[0] = rhsValue;
const std::vector< double > & rhs
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Data processor algorithm to be used as a parent to workflow algorithms.
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,...
MatrixWorkspace_sptr createWorkspaceSingleValue(const double &rhsValue)
Create a matrix workspace from a single number.
Workspace_sptr assemble(Workspace_sptr partialWS)
Assemble the partial workspaces from all MPI processes.
std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1) override
Create a Child Algorithm.
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.
Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override
Get the property held by this object.
std::vector< std::string > splitInput(const std::string &input)
std::string getPropertyValue(const std::string &name) const override
Get the property held by this object.
void setAccumAlg(const std::string &alg)
void visualStudioC4661Workaround()
void setLoadAlgFileProp(const std::string &filePropName)
GenericDataProcessorAlgorithm()
Constructor.
void setLoadAlg(const std::string &alg)
int getNThreads()
Return the number of MPI processes running.
MatrixWorkspace_sptr plus(const MatrixWorkspace_sptr lhs, const MatrixWorkspace_sptr rhs)
Add a matrix workspace to another matrix workspace.
MatrixWorkspace_sptr minus(const MatrixWorkspace_sptr lhs, const MatrixWorkspace_sptr rhs)
Subract a matrix workspace by another matrix workspace.
MatrixWorkspace_sptr multiply(const MatrixWorkspace_sptr lhs, const MatrixWorkspace_sptr rhs)
Multiply a matrix workspace by another matrix workspace.
virtual MatrixWorkspace_sptr loadChunk(const size_t rowIndex)
void setPropManagerPropName(const std::string &propName)
Workspace_sptr load(const std::string &inputData, const bool loadQuiet=false)
Determine what kind of input data we have and load it.
void mapPropertyName(const std::string &nameInProp, const std::string &nameInPropManager)
Declare mapping of property name to name in the PropertyManager.
MatrixWorkspace_sptr divide(const MatrixWorkspace_sptr lhs, const MatrixWorkspace_sptr rhs)
Divide a matrix workspace by another matrix workspace.
Exception for when an item is not found in a collection.
A class that holds information about a facility.
const std::vector< std::string > extensions() const
Returns a list of file extensions.
void notice(const std::string &msg)
Logs at notice level.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
static MatrixWorkspace_sptr createWorkspaceSingleValue(const double &rhsValue)
Creates a temporary single value workspace the error is set to zero.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Utility class that enables the getProperty() method to effectively be templated on the return type.