Mantid
Loading...
Searching...
No Matches
DataProcessorAlgorithm.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2012 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
17#include "MantidKernel/System.h"
18#include <vector>
19
20namespace Mantid {
21namespace API {
29template <class Base> class MANTID_API_DLL GenericDataProcessorAlgorithm : public Base {
30public:
32 std::string getPropertyValue(const std::string &name) const override;
33 Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override;
34
35protected:
36 std::shared_ptr<Algorithm> createChildAlgorithm(const std::string &name, const double startProgress = -1.,
37 const double endProgress = -1., const bool enableLogging = true,
38 const int &version = -1) override;
39 void setLoadAlg(const std::string &alg);
40 void setLoadAlgFileProp(const std::string &filePropName);
41 void setAccumAlg(const std::string &alg);
42 void setPropManagerPropName(const std::string &propName);
43 void mapPropertyName(const std::string &nameInProp, const std::string &nameInPropManager);
44 void copyProperty(const API::Algorithm_sptr &alg, const std::string &name);
45 virtual ITableWorkspace_sptr determineChunk(const std::string &filename);
46 virtual MatrixWorkspace_sptr loadChunk(const size_t rowIndex);
47 Workspace_sptr load(const std::string &inputData, const bool loadQuiet = false);
48 std::vector<std::string> splitInput(const std::string &input);
49 void forwardProperties();
50 std::shared_ptr<Kernel::PropertyManager>
51 getProcessProperties(const std::string &propertyManager = std::string()) const;
54 Workspace_sptr assemble(Workspace_sptr partialWS);
55 Workspace_sptr assemble(const std::string &partialWSName, [[maybe_unused]] const std::string &outputWSName);
56 void saveNexus(const std::string &outputWSName, const std::string &outputFile);
57 bool isMainThread();
58 int getNThreads();
59
63 MatrixWorkspace_sptr divide(const MatrixWorkspace_sptr lhs, const double &rhsValue);
64
68 MatrixWorkspace_sptr multiply(const MatrixWorkspace_sptr lhs, const double &rhsValue);
69
73 MatrixWorkspace_sptr plus(const MatrixWorkspace_sptr lhs, const double &rhsValue);
74
78 MatrixWorkspace_sptr minus(const MatrixWorkspace_sptr lhs, const double &rhsValue);
79
80private:
81 template <typename LHSType, typename RHSType, typename ResultType>
82 ResultType executeBinaryAlgorithm(const std::string &algorithmName, const LHSType lhs, const RHSType rhs) {
83 auto alg = createChildAlgorithm(algorithmName);
84 alg->initialize();
85
86 alg->template setProperty<LHSType>("LHSWorkspace", lhs);
87 alg->template setProperty<RHSType>("RHSWorkspace", rhs);
88 alg->execute();
89
90 if (alg->isExecuted()) {
91 // Get the output workspace property
92 return alg->getProperty("OutputWorkspace");
93 } else {
94 std::string message = "Error while executing operation: " + algorithmName;
95 throw std::runtime_error(message);
96 }
97 }
98
100 MatrixWorkspace_sptr createWorkspaceSingleValue(const double &rhsValue);
101
103 std::string m_loadAlg;
105 std::string m_accumulateAlg;
107 std::string m_loadAlgFileProp;
112 std::map<std::string, std::string> m_nameToPMName;
113
114 // This method is a workaround for the C4661 compiler warning in visual
115 // studio. This allows the template declaration and definition to be separated
116 // in different files. See stack overflow article for a more detailed
117 // explanation:
118 // https://stackoverflow.com/questions/44160467/warning-c4661no-suitable-definition-provided-for-explicit-template-instantiatio
119 // https://stackoverflow.com/questions/33517902/how-to-export-a-class-derived-from-an-explicitly-instantiated-template-in-visual
120 void visualStudioC4661Workaround();
121};
122
124
129
130} // namespace API
131} // namespace Mantid
const std::vector< double > & rhs
Data processor algorithm to be used as a parent to workflow algorithms.
std::string m_loadAlgFileProp
An alternate filename property for the load algorithm.
std::string m_propertyManagerPropertyName
The name of the parameter that names the property manager.
std::map< std::string, std::string > m_nameToPMName
Map property names to names in supplied properties manager.
std::string m_accumulateAlg
The name of the algorithm to invoke when accumulating data chunks.
std::string m_loadAlg
The name of the algorithm to invoke when loading data.
ResultType executeBinaryAlgorithm(const std::string &algorithmName, const LHSType lhs, const RHSType rhs)
bool m_useMPI
MPI option. If false, we will use one job event if MPI is available.
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
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Definition: Algorithm.h:61
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Helper class which provides the Collimation Length for SANS instruments.
Utility class that enables the getProperty() method to effectively be templated on the return type.