Mantid
Loading...
Searching...
No Matches
Workspace.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 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 +
10#include "MantidKernel/Memory.h"
11
12namespace Mantid::API {
13
14Workspace::Workspace() : m_history(std::make_unique<WorkspaceHistory>()) {}
15
16// Defined as default in source for forward declaration with std::unique_ptr.
17Workspace::~Workspace() = default;
18
20 : Kernel::DataItem(other), m_title(other.m_title), m_comment(other.m_comment), m_name(),
21 m_history(std::make_unique<WorkspaceHistory>(other.getHistory())) {}
22
27void Workspace::setTitle(const std::string &t) { m_title = t; }
28
33void Workspace::setComment(const std::string &c) { m_comment = c; }
34
39void Workspace::setName(const std::string &name) { m_name = name; }
40
42
47const std::string Workspace::getTitle() const { return m_title; }
48
53const std::string &Workspace::getComment() const { return m_comment; }
54
59const std::string &Workspace::getName() const { return m_name; }
60
61const std::string &Workspace::getPythonVariableName() const { return m_pythonVariableName; }
62
74bool Workspace::isDirty(const int n) const { return static_cast<int>(m_history->size()) > n; }
75
80std::string Workspace::getMemorySizeAsStr() const {
81 return Mantid::Kernel::memToString<uint64_t>(static_cast<uint64_t>(getMemorySize()) / 1024);
82}
83} // namespace Mantid::API
84
86namespace Mantid::Kernel {
87
88template <>
89MANTID_API_DLL Mantid::API::Workspace_sptr
90IPropertyManager::getValue<Mantid::API::Workspace_sptr>(const std::string &name) const {
91 auto *prop = dynamic_cast<PropertyWithValue<Mantid::API::Workspace_sptr> *>(getPointerToProperty(name));
92 if (prop) {
93 return *prop;
94 } else {
95 std::string message = "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<Workspace>.";
96 throw std::runtime_error(message);
97 }
98}
99
100template <>
102IPropertyManager::getValue<Mantid::API::Workspace_const_sptr>(const std::string &name) const {
103 const auto *prop = dynamic_cast<PropertyWithValue<Mantid::API::Workspace_sptr> *>(getPointerToProperty(name));
104 if (prop) {
105 return prop->operator()();
106 } else {
107 std::string message =
108 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<Workspace>.";
109 throw std::runtime_error(message);
110 }
111}
112
113} // namespace Mantid::Kernel
std::string name
Definition Run.cpp:60
This class stores information about the Workspace History used by algorithms on a workspace and the e...
Base Workspace Abstract Class.
Definition Workspace.h:29
const std::string & getName() const override
Get the workspace name.
Definition Workspace.cpp:59
std::string m_pythonVariableName
The name of the variable holding the workspace, if not stored in the ADS.
Definition Workspace.h:101
std::string m_comment
A user-provided comment that is attached to the workspace.
Definition Workspace.h:96
void setName(const std::string &)
Set the name field of the workspace.
Definition Workspace.cpp:39
const std::string & getPythonVariableName() const
Definition Workspace.cpp:61
std::string m_title
The title of the workspace.
Definition Workspace.h:94
virtual void setTitle(const std::string &)
Set the title of the workspace.
Definition Workspace.cpp:27
const std::string & getComment() const
Get the workspace comment.
Definition Workspace.cpp:53
std::unique_ptr< WorkspaceHistory > m_history
The history of the workspace, algorithm and environment.
Definition Workspace.h:103
std::string m_name
The name associated with the object within the ADS (This is required for workspace algebra.
Definition Workspace.h:99
void setPythonVariableName(const std::string &)
Definition Workspace.cpp:41
virtual size_t getMemorySize() const =0
Get the footprint in memory in bytes.
std::string getMemorySizeAsStr() const
Returns the memory footprint in sensible units.
Definition Workspace.cpp:80
bool isDirty(const int n=1) const
Check whether other algorithms have been applied to the workspace by checking the history length.
Definition Workspace.cpp:74
virtual const std::string getTitle() const
Get the workspace title.
Definition Workspace.cpp:47
void setComment(const std::string &)
Set the comment field of the workspace.
Definition Workspace.cpp:33
This class forms the base class of any item that wishes to be stored in the analysis data service.
Definition DataItem.h:39
The concrete, templated class for properties.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< const Workspace > Workspace_const_sptr
shared pointer to Mantid::API::Workspace (const version)
template DLLExport string memToString< uint64_t >(const uint64_t)
STL namespace.