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
11#include "MantidAPI/DllConfig.h"
15#include <vector>
16
17namespace Mantid {
18namespace API {
26template <class Base> class MANTID_API_DLL GenericDataProcessorAlgorithm : public Base {
27public:
29 std::string getPropertyValue(const std::string &name) const override;
30 Kernel::IPropertyManager::TypedValue getProperty(const std::string &name) const override;
31
32protected:
33 std::shared_ptr<Algorithm> createChildAlgorithm(const std::string &name, const double startProgress = -1.,
34 const double endProgress = -1., const bool enableLogging = true,
35 const int &version = -1) override;
36 void setLoadAlg(const std::string &alg);
37 void setLoadAlgFileProp(const std::string &filePropName);
38 void setAccumAlg(const std::string &alg);
39 void setPropManagerPropName(const std::string &propName);
40 void mapPropertyName(const std::string &nameInProp, const std::string &nameInPropManager);
41 void copyProperty(const API::Algorithm_sptr &alg, const std::string &name);
42 virtual ITableWorkspace_sptr determineChunk(const std::string &filename);
43 virtual MatrixWorkspace_sptr loadChunk(const size_t rowIndex);
44 Workspace_sptr load(const std::string &inputData, const bool loadQuiet = false);
45 std::vector<std::string> splitInput(const std::string &input);
46 void forwardProperties();
47 std::shared_ptr<Kernel::PropertyManager>
48 getProcessProperties(const std::string &propertyManager = std::string()) const;
49 void saveNexus(const std::string &outputWSName, const std::string &outputFile);
50
54 MatrixWorkspace_sptr divide(const MatrixWorkspace_sptr lhs, const double &rhsValue);
55
59 MatrixWorkspace_sptr multiply(const MatrixWorkspace_sptr lhs, const double &rhsValue);
60
64 MatrixWorkspace_sptr plus(const MatrixWorkspace_sptr lhs, const double &rhsValue);
65
69 MatrixWorkspace_sptr minus(const MatrixWorkspace_sptr lhs, const double &rhsValue);
70
71private:
72 template <typename LHSType, typename RHSType, typename ResultType>
73 ResultType executeBinaryAlgorithm(const std::string &algorithmName, const LHSType lhs, const RHSType rhs) {
74 auto alg = createChildAlgorithm(algorithmName);
75 alg->initialize();
76
77 alg->template setProperty<LHSType>("LHSWorkspace", lhs);
78 alg->template setProperty<RHSType>("RHSWorkspace", rhs);
79 alg->execute();
80
81 if (alg->isExecuted()) {
82 // Get the output workspace property
83 return alg->getProperty("OutputWorkspace");
84 } else {
85 std::string message = "Error while executing operation: " + algorithmName;
86 throw std::runtime_error(message);
87 }
88 }
89
91 MatrixWorkspace_sptr createWorkspaceSingleValue(const double &rhsValue);
92
94 std::string m_loadAlg;
96 std::string m_accumulateAlg;
98 std::string m_loadAlgFileProp;
103 std::map<std::string, std::string> m_nameToPMName;
104
105 // This method is a workaround for the C4661 compiler warning in visual
106 // studio. This allows the template declaration and definition to be separated
107 // in different files. See stack overflow article for a more detailed
108 // explanation:
109 // https://stackoverflow.com/questions/44160467/warning-c4661no-suitable-definition-provided-for-explicit-template-instantiatio
110 // https://stackoverflow.com/questions/33517902/how-to-export-a-class-derived-from-an-explicitly-instantiated-template-in-visual
111 void visualStudioC4661Workaround();
112};
113
115
117} // namespace API
118} // namespace Mantid
std::string name
Definition Run.cpp:60
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)
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Definition Algorithm.h:52
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.