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(const Parallel::StorageMode storageMode)
15 : m_history(std::make_unique<WorkspaceHistory>()), m_storageMode(storageMode) {}
16
17// Defined as default in source for forward declaration with std::unique_ptr.
18Workspace::~Workspace() = default;
19
21 : Kernel::DataItem(other), m_title(other.m_title), m_comment(other.m_comment), m_name(),
22 m_history(std::make_unique<WorkspaceHistory>(other.getHistory())), m_storageMode(other.m_storageMode) {}
23
28void Workspace::setTitle(const std::string &t) { m_title = t; }
29
34void Workspace::setComment(const std::string &c) { m_comment = c; }
35
40void Workspace::setName(const std::string &name) { m_name = name; }
41
46const std::string Workspace::getTitle() const { return m_title; }
47
52const std::string &Workspace::getComment() const { return m_comment; }
53
58const std::string &Workspace::getName() const { return m_name; }
59
71bool Workspace::isDirty(const int n) const { return static_cast<int>(m_history->size()) > n; }
72
77std::string Workspace::getMemorySizeAsStr() const {
78 return Mantid::Kernel::memToString<uint64_t>(static_cast<uint64_t>(getMemorySize()) / 1024);
79}
80
82Parallel::StorageMode Workspace::storageMode() const { return m_storageMode; }
83
85void Workspace::setStorageMode(Parallel::StorageMode storageMode) { m_storageMode = storageMode; }
86
87} // namespace Mantid::API
88
90namespace Mantid::Kernel {
91
92template <>
93MANTID_API_DLL Mantid::API::Workspace_sptr
94IPropertyManager::getValue<Mantid::API::Workspace_sptr>(const std::string &name) const {
95 auto *prop = dynamic_cast<PropertyWithValue<Mantid::API::Workspace_sptr> *>(getPointerToProperty(name));
96 if (prop) {
97 return *prop;
98 } else {
99 std::string message = "Attempt to assign property " + name + " to incorrect type. Expected shared_ptr<Workspace>.";
100 throw std::runtime_error(message);
101 }
102}
103
104template <>
106IPropertyManager::getValue<Mantid::API::Workspace_const_sptr>(const std::string &name) const {
107 auto *prop = dynamic_cast<PropertyWithValue<Mantid::API::Workspace_sptr> *>(getPointerToProperty(name));
108 if (prop) {
109 return prop->operator()();
110 } else {
111 std::string message =
112 "Attempt to assign property " + name + " to incorrect type. Expected const shared_ptr<Workspace>.";
113 throw std::runtime_error(message);
114 }
115}
116
117} // namespace Mantid::Kernel
This class stores information about the Workspace History used by algorithms on a workspace and the e...
Base Workspace Abstract Class.
Definition: Workspace.h:30
const std::string & getName() const override
Get the workspace name.
Definition: Workspace.cpp:58
Workspace(const Parallel::StorageMode storageMode=Parallel::StorageMode::Cloned)
Definition: Workspace.cpp:14
std::string m_comment
A user-provided comment that is attached to the workspace.
Definition: Workspace.h:98
void setName(const std::string &)
Set the name field of the workspace.
Definition: Workspace.cpp:40
Parallel::StorageMode storageMode() const
Returns the storage mode (used for MPI runs)
Definition: Workspace.cpp:82
std::string m_title
The title of the workspace.
Definition: Workspace.h:96
Parallel::StorageMode m_storageMode
Storage mode of the Workspace (used for MPI runs)
Definition: Workspace.h:105
virtual void setTitle(const std::string &)
Set the title of the workspace.
Definition: Workspace.cpp:28
const std::string & getComment() const
Get the workspace comment.
Definition: Workspace.cpp:52
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:101
void setStorageMode(Parallel::StorageMode mode)
Sets the storage mode (used for MPI runs)
Definition: Workspace.cpp:85
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:77
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:71
virtual const std::string getTitle() const
Get the workspace title.
Definition: Workspace.cpp:46
void setComment(const std::string &)
Set the comment field of the workspace.
Definition: Workspace.cpp:34
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
Definition: Workspace_fwd.h:20
std::shared_ptr< const Workspace > Workspace_const_sptr
shared pointer to Mantid::API::Workspace (const version)
Definition: Workspace_fwd.h:22
template DLLExport string memToString< uint64_t >(const uint64_t)
STL namespace.