22using namespace Kernel;
31 "Names of the Input Workspaces");
34 "New Names of the Workspaces");
42 declareProperty<bool>(
"OverwriteExisting",
true,
43 "If true all existing workspaces with the output name will be"
44 " overwritten. Defaults to true to maintain backwards compatibility.",
54 map<string, string> errorList;
57 std::vector<std::string> newWsName =
getProperty(
"WorkspaceNames");
63 if (newWsName.empty() && prefix.empty() && suffix.empty()) {
64 errorList[
"WorkspaceNames"] =
"No list of Workspace names, prefix or suffix has been supplied.";
67 if (!newWsName.empty() && (!prefix.empty() || !suffix.empty())) {
68 errorList[
"WorkspaceNames"] =
"Both a list of workspace names and a prefix "
69 "or suffix has been supplied.";
70 if (!prefix.empty()) {
71 errorList[
"Prefix"] =
"Both a list of workspace names and a prefix "
72 "or suffix has been supplied.";
74 errorList[
"Suffix"] =
"Both a list of workspace names and a prefix "
75 "or suffix has been supplied.";
79 if (newWsName.size() > 1) {
80 for (
size_t i = 0; i < newWsName.size() - 1; ++i) {
81 for (
size_t j = i + 1; j < newWsName.size(); ++j) {
82 if (newWsName[i] == newWsName[j]) {
83 errorList[
"WorkspaceNames"] =
"Duplicate '" + newWsName[i] +
"' found in WorkspaceNames.";
98 std::vector<std::string> inputWsName =
getProperty(
"InputWorkspaces");
101 std::vector<std::string> newWsName =
getProperty(
"WorkspaceNames");
106 bool overrideWorkspace =
getProperty(
"OverwriteExisting");
110 size_t nWs = inputWsName.size();
111 if (!newWsName.empty()) {
113 if (nWs > newWsName.size()) {
114 nWs = newWsName.size();
119 for (
size_t i = 0; i < nWs; ++i) {
120 newWsName.emplace_back(prefix + inputWsName[i] + suffix);
125 for (
const auto &
name : newWsName) {
129 if (!overrideWorkspace) {
130 throw std::runtime_error(
"A workspace called " +
name +
" already exists");
136 for (
size_t i = 0; i < nWs; ++i) {
137 std::ostringstream os;
138 os <<
"OutputWorkspace_" << i + 1;
141 alg->setPropertyValue(
"InputWorkspace", inputWsName[i]);
142 alg->setPropertyValue(
"OutputWorkspace", newWsName[i]);
143 alg->setProperty(
"OverwriteExisting", overrideWorkspace);
145 alg->executeAsChildAlg();
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
A property class for workspaces.
void exec() override
Executes the algorithm.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
std::map< std::string, std::string > validateInputs() override
Validator to check out name does not already exist.
void init() override
Initialisation method.
Support for a property that holds an array of values.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
Validator to check that a property is not left empty.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
@ Input
An input workspace.
@ Output
An output workspace.