Mantid
Loading...
Searching...
No Matches
WorkspaceProperty.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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
10#include "MantidKernel/Logger.h"
12
13#include <string>
14
15namespace Mantid {
16namespace API {
17// -------------------------------------------------------------------------
18// Forward decaration
19// -------------------------------------------------------------------------
20class Workspace;
21class MatrixWorkspace;
22class WorkspaceGroup;
23class IEventWorkspace;
24class IMDEventWorkspace;
25class IMDHistoWorkspace;
26class IMDWorkspace;
27class IPeaksWorkspace;
28class ITableWorkspace;
29
31struct LockMode {
32 enum Type { Lock, NoLock };
33};
34
57template <typename TYPE = MatrixWorkspace>
58class WorkspaceProperty : public Kernel::PropertyWithValue<std::shared_ptr<TYPE>>, public IWorkspaceProperty {
59public:
60 explicit WorkspaceProperty(
61 const std::string &name, const std::string &wsName, const unsigned int direction,
63
64 explicit WorkspaceProperty(
65 const std::string &name, const std::string &wsName, const unsigned int direction,
66 const PropertyMode::Type optional,
68
69 explicit WorkspaceProperty(
70 const std::string &name, const std::string &wsName, const unsigned int direction,
71 const PropertyMode::Type optional, const LockMode::Type locking,
73
75
77
78 WorkspaceProperty &operator=(const std::shared_ptr<TYPE> &value) override;
79
81
82 WorkspaceProperty<TYPE> *clone() const override;
83
84 std::string value() const override;
85
86 Json::Value valueAsJson() const override;
87
88 bool isValueSerializable() const override;
89
90 std::string getDefault() const override;
91
92 std::string setValue(const std::string &value) override;
93
94 std::string setValueFromJson(const Json::Value &value) override;
95
96 std::string setDataItem(const std::shared_ptr<Kernel::DataItem> &value) override;
97
98 void setPropertyMode(const PropertyMode::Type &optional) override;
99
100 std::string isValid() const override;
101
102 bool isDefault() const override;
103
104 bool isOptional() const override;
105 bool isLocking() const override;
106
107 std::vector<std::string> allowedValues() const override;
108
109 const Kernel::PropertyHistory createHistory() const override;
110
111 bool store() override;
112
113 Workspace_sptr getWorkspace() const override;
114
115private:
116 std::string isValidGroup(const std::shared_ptr<WorkspaceGroup> &wsGroup) const;
117
118 std::string isValidOutputWs() const;
119
120 std::string isOptionalWs() const;
121
122 void clear() override;
123
125
127 std::string m_workspaceName;
129 std::string m_initialWSName;
136
139};
140
141template <typename TYPE> Kernel::Logger WorkspaceProperty<TYPE>::g_log("WorkspaceProperty");
142
143#if !defined(API_EXPORTS) && defined(__APPLE__) && defined(__clang__)
144// Extern template instantiations for macOS/Clang to ensure typeinfo visibility for dynamic_cast
145extern template class WorkspaceProperty<Workspace>;
146extern template class WorkspaceProperty<IEventWorkspace>;
147extern template class WorkspaceProperty<IMDEventWorkspace>;
148extern template class WorkspaceProperty<IMDHistoWorkspace>;
149extern template class WorkspaceProperty<IMDWorkspace>;
150extern template class WorkspaceProperty<MatrixWorkspace>;
151extern template class WorkspaceProperty<IPeaksWorkspace>;
152extern template class WorkspaceProperty<ITableWorkspace>;
153extern template class WorkspaceProperty<WorkspaceGroup>;
154#endif
155
156} // namespace API
157} // namespace Mantid
double right
An interface that is implemented by WorkspaceProperty.
A property class for workspaces.
std::string value() const override
Get the name of the workspace.
std::string setDataItem(const std::shared_ptr< Kernel::DataItem > &value) override
Set a value from a data item.
void setPropertyMode(const PropertyMode::Type &optional) override
Set the property mode of the property e.g.
std::string isOptionalWs() const
Checks whether the entered workspace (that by this point we've found is not in the ADS) is actually a...
std::string setValue(const std::string &value) override
Set the name of the workspace.
bool isLocking() const override
Does the workspace need to be locked before starting an algorithm?
std::string isValidGroup(const std::shared_ptr< WorkspaceGroup > &wsGroup) const
Checks whether the entered workspace group is valid.
WorkspaceProperty< TYPE > * clone() const override
'Virtual copy constructor'
std::string m_initialWSName
The name of the workspace that the this this object was created for.
Workspace_sptr getWorkspace() const override
Get a pointer to the workspace.
WorkspaceProperty & operator+=(Kernel::Property const *) override
Add the value of another property.
Json::Value valueAsJson() const override
std::string isValidOutputWs() const
Checks whether the entered output workspace is valid.
void retrieveWorkspaceFromADS()
Attempts to retreive the data from the ADS if the data is not foung the internal pointer is set to nu...
static Kernel::Logger g_log
for access to logging streams
std::string setValueFromJson(const Json::Value &value) override
Set the name of the workspace from a Json::Value object Also tries to retrieve it from the AnalysisDa...
bool isOptional() const override
Is the workspace property optional.
std::string getDefault() const override
Get the value the property was initialised with -its default value.
std::string isValid() const override
Checks whether the entered workspace is valid.
bool isValueSerializable() const override
Returns true if the workspace is in the ADS or there is none.
const Kernel::PropertyHistory createHistory() const override
Create a history record.
void clear() override
Reset the pointer to the workspace.
bool isDefault() const override
Indicates if the object is still pointing to the same workspace.
std::vector< std::string > allowedValues() const override
Returns the current contents of the AnalysisDataService for input workspaces.
WorkspaceProperty & operator=(const WorkspaceProperty &right)
Copy assignment operator.
PropertyMode::Type m_optional
A flag indicating whether the property should be considered optional.
std::string m_workspaceName
The name of the workspace (as used by the AnalysisDataService)
LockMode::Type m_locking
A flag indicating whether the workspace should be read or write-locked when an algorithm begins.
bool store() override
If this is an output workspace, store it into the AnalysisDataService.
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition Logger.h:51
NullValidator is a validator that doesn't.
This class stores information about the parameters used by an algorithm.
The concrete, templated class for properties.
Base class for properties.
Definition Property.h:94
unsigned int direction() const
returns the direction of the property
Definition Property.h:176
const std::string & name() const
Get the property's name.
Definition Property.cpp:63
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition IValidator.h:26
Helper class which provides the Collimation Length for SANS instruments.
Enumeration for locking behaviour.