20using namespace Kernel;
29 declareProperty<bool>(
"RenameMonitors",
false,
30 "If true, and monitor workspace found attached"
31 " to the source workspace, the monitors workspace is renamed too.\n"
32 "The monitor workspace name is created from the new workspace "
33 "name: NewWSName by adding the _monitors suffix"
34 " (e.g.: NewWSName_monitors)",
38 declareProperty<bool>(
"OverwriteExisting",
true,
39 "If true any existing workspaces with the output name will be"
40 " overwritten. Defaults to true to maintain backwards compatibility.",
51 map<string, string> errorList;
58 errorList[
"InputWorkspace"] =
"Input and output workspace"
59 " names must be different";
60 errorList[
"OutputWorkspace"] =
"Input and output workspace"
61 " names must be different";
65 if (AnalysisDataService::Instance().doesExist(outputwsName)) {
67 bool overrideWorkspaces =
getProperty(
"OverwriteExisting");
69 if (!overrideWorkspaces) {
74 errorList[
"OutputWorkspace"] =
"The workspace " + outputwsName +
" already exists";
75 errorList[
"OverwriteExisting"] =
"Set OverwriteExisting to true"
76 " to overwrite the existing workspace";
88 auto &ADS = AnalysisDataService::Instance();
96 std::string inputwsName = inputWS->getName();
104 if (inputwsName.empty())
105 ADS.addOrReplace(outputwsName, inputWS);
107 ADS.rename(inputwsName, outputwsName);
109 const bool renameMonitors =
getProperty(
"RenameMonitors");
114 auto matInputWS = std::dynamic_pointer_cast<MatrixWorkspace>(inputWS);
117 auto monWS = matInputWS->monitorWorkspace();
119 std::string monWSName = monWS->getName();
121 if (monWSName.empty()) {
124 ADS.add(outputwsName +
"_monitors", monWS);
127 ADS.rename(monWSName, outputwsName +
"_monitors");
129 ADS.add(monWSName, monWS);
130 ADS.rename(monWSName, outputwsName +
"_monitors");
139 const std::string inputwsName = inputWS->getName();
142 if (inputwsName == outputwsName) {
143 throw std::invalid_argument(
"The input and output workspace names must be different");
154 const bool renameMembers = inputGroup->areNamesSimilar();
156 AnalysisDataService::Instance().rename(inputwsName, outputwsName);
160 const std::vector<std::string> names = inputGroup->getNames();
163 for (
size_t i = 0; i < names.size(); ++i) {
166 std::stringstream suffix;
168 std::string wsName = outputwsName +
"_" + suffix.str();
170 auto alg = API::AlgorithmManager::Instance().createUnmanaged(this->
name(), this->
version());
172 alg->setPropertyValue(
"InputWorkspace", names[i]);
173 alg->setPropertyValue(
"OutputWorkspace", wsName);
175 alg->enableHistoryRecordingForChild(
false);
#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.
A property class for workspaces.
std::map< std::string, std::string > validateInputs() override
Check that input params are valid.
void init() override
Initialisation method.
bool processGroups() override
Process WorkspaceGroup inputs.
void exec() override
Executes the algorithm.
int version() const override
Algorithm's version for identification overriding a virtual method.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Exception for when an item is not found in a collection.
const char * what() const noexcept override
Writes out the range and limits.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
void error(const std::string &msg)
Logs at error level.
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
@ Input
An input workspace.
@ Output
An output workspace.