15#include <boost/algorithm/string/trim.hpp>
17#include <json/value.h>
33template <
typename TYPE>
37 m_workspaceName(wsName), m_initialWSName(wsName), m_optional(
PropertyMode::Mandatory), m_locking(
LockMode::Lock) {
52template <
typename TYPE>
57 m_workspaceName(wsName), m_initialWSName(wsName), m_optional(optional), m_locking(
LockMode::Lock) {}
75template <
typename TYPE>
80 m_workspaceName(wsName), m_initialWSName(wsName), m_optional(optional), m_locking(locking) {}
84template <
typename TYPE>
87 m_initialWSName(
right.m_initialWSName), m_optional(
right.m_optional), m_locking(
right.m_locking) {}
103template <
typename TYPE>
105 std::string wsName =
value->getName();
107 m_workspaceName = wsName;
138 return !m_workspaceName.empty() || !this->
m_value;
153 m_workspaceName =
value;
155 boost::trim(m_workspaceName);
157 retrieveWorkspaceFromADS();
170 return setValue(
value.asString());
171 }
catch (std::exception &exc) {
181template <
typename TYPE>
183 std::shared_ptr<TYPE> typed = std::dynamic_pointer_cast<TYPE>(
value);
186 typed->setPythonVariableName(m_workspaceName);
189 m_workspaceName = typed->getName();
202 m_optional = optional;
217 return isValidOutputWs();
228 if (m_workspaceName.empty()) {
229 return isOptionalWs();
233 wksp = AnalysisDataService::Instance().retrieve(m_workspaceName);
235 return isOptionalWs();
240 if (std::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(wksp)) {
241 return isValidGroup(std::dynamic_pointer_cast<Mantid::API::WorkspaceGroup>(wksp));
244 std::string
error =
"Workspace " + this->
value() +
" is not of the correct type";
258 if (m_initialWSName.empty()) {
259 return m_workspaceName.empty() && !this->
m_value;
261 return m_initialWSName == m_workspaceName;
284 vals.emplace_back(
"");
291 auto eraseIter = remove_if(vals.begin(), vals.end(),
292 [&tester](
const std::string &wsName) { return !tester.setValue(wsName).empty(); });
294 vals.erase(eraseIter, vals.end());
298 return std::vector<std::string>();
305 std::string wsName = m_workspaceName;
306 bool isdefault = this->isDefault();
307 bool pythonVariable =
false;
309 if ((wsName.empty() || this->hasTemporaryValue()) && this->operator()()) {
311 pythonVariable = !pvName.empty();
312 if (pythonVariable) {
316 std::ostringstream os;
317 os <<
"__TMP" << this->operator()().get();
331 if (!this->
operator()() && isOptional())
333 if (this->direction())
336 if (this->
operator()()) {
338 API::AnalysisDataService::Instance().addOrReplace(m_workspaceName, this->
operator()());
340 throw std::runtime_error(
"WorkspaceProperty doesn't point to a workspace");
357template <
typename TYPE>
359 g_log.
debug() <<
" Input WorkspaceGroup found \n";
361 std::vector<std::string> wsGroupNames = wsGroup->getNames();
365 for (
const auto &memberWsName : wsGroupNames) {
366 std::shared_ptr<Workspace> memberWs = AnalysisDataService::Instance().retrieve(memberWsName);
369 if (
"TableWorkspace" == memberWs->id()) {
370 error =
"Workspace " + memberWsName +
371 " is of type TableWorkspace and "
372 "will therefore be ignored as "
373 "part of the GroupedWorkspace.";
379 if (!std::dynamic_pointer_cast<TYPE>(memberWs)) {
380 error =
"Workspace " + memberWsName +
" is not of type " +
390 std::string memberError = memberWsProperty.
setValue(memberWsName);
391 if (!memberError.empty())
408 const std::string workspaceName = this->
value();
409 if (!workspaceName.empty()) {
411 error = AnalysisDataService::Instance().isValid(workspaceName);
416 error =
"Enter a name for the Output workspace";
429 if (m_workspaceName.empty()) {
433 error =
"Enter a name for the Input/InOut workspace";
436 error =
"Workspace \"" + this->
value() +
"\" was not found in the Analysis Data Service";
454 AnalysisDataService::Instance().retrieveWS<
TYPE>(m_workspaceName);
const std::string & m_value
double value
The value of the point.
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'
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...
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.
WorkspaceProperty(const std::string &name, const std::string &wsName, const unsigned int direction, const Kernel::IValidator_sptr &validator=Kernel::IValidator_sptr(new Kernel::NullValidator))
Constructor.
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.
bool store() override
If this is an output workspace, store it into the AnalysisDataService.
Exception for when an item is not found in a collection.
Marks code as not implemented yet.
void debug(const std::string &msg)
Logs at debug level.
This class stores information about the parameters used by an algorithm.
The concrete, templated class for properties.
Base class for properties.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Helper class which provides the Collimation Length for SANS instruments.
Enumeration for locking behaviour.
Enumeration for a mandatory/optional property.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.
@ Output
An output workspace.