20using namespace Kernel;
27 "Names of the Input Workspaces to Group");
29 "Add all Workspaces that match Glob expression to Group");
31 "Name of the workspace to be created as the output of grouping ");
38 const std::vector<std::string> inputWorkspaces =
getProperty(
"InputWorkspaces");
40 const std::string globExpression =
getProperty(
"GlobExpression");
41 std::string outputWorkspace =
getProperty(
"OutputWorkspace");
46 if (!inputWorkspaces.empty())
48 if (!globExpression.empty())
51 throw std::invalid_argument(
"Glob pattern " + globExpression +
" does not match any workspace names in the ADS.");
53 auto ¬ifier = API::AnalysisDataService::Instance().notificationCenter;
58 std::map<std::string, std::string> results;
59 const std::vector<std::string> inputWorkspaces =
getProperty(
"InputWorkspaces");
60 std::string globExpression =
getProperty(
"GlobExpression");
62 for (
auto it = globExpression.begin(); it < globExpression.end(); ++it) {
64 it = globExpression.erase(it, it + 1);
68 if (inputWorkspaces.empty() && globExpression.empty()) {
69 results[
"InputWorkspaces"] =
"No InputWorkspace names specified. Rerun with a list of workspaces "
70 "names or a glob expression";
76 if (!globExpression.empty()) {
79 if (globExpression.find_first_of(
"*?[]") == std::string::npos) {
80 results[
"GlobExpression"] =
"Expression is expected to contain one or "
81 "more of the following characters: *?[";
84 if (std::count(globExpression.cbegin(), globExpression.cend(),
'[') !=
85 std::count(globExpression.cbegin(), globExpression.cend(),
']')) {
86 results[
"GlobExpression"] =
"Expression has a mismatched number of []";
99 g_log.
debug() <<
"convert \"" << globExpression <<
"\" to \"" << globRegexp <<
"\"\n";
100 std::regex pattern(globRegexp);
104 for (
const auto &wsName : wsNames) {
105 if (std::regex_match(wsName.first, pattern)) {
119 for (
const auto &wsName : names) {
129 auto localGroup = std::dynamic_pointer_cast<WorkspaceGroup>(
workspace);
130 auto &ads = AnalysisDataService::Instance();
133 if (ads.doesExist(
workspace->getName())) {
139 m_group = std::make_shared<WorkspaceGroup>();
#define DECLARE_ALGORITHM(classname)
IPeaksWorkspace_sptr workspace
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
std::map< std::string, Workspace_sptr > topLevelItems() const
Return a lookup of the top level items.
virtual Workspace_sptr remove(const std::string &name)
Overridden remove member to delete its name held by the workspace itself.
A property class for workspaces.
void init() override
Overridden Init method.
void addToGroup(const std::vector< std::string > &names, const std::string &outputName="")
Add a list of names to the new group.
void exec() override
overridden execute method
std::map< std::string, std::string > validateInputs() override
Method checking errors on ALL the inputs, before execution.
API::WorkspaceGroup_sptr m_group
A pointer to the new group.
Support for a property that holds an array of values.
std::shared_ptr< T > retrieve(const std::string &name) const
Get a shared pointer to a stored data object.
static std::string globToRegex(const std::string &globPattern)
Convert a glob pattern to an equivalent regular expression.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void debug(const std::string &msg)
Logs at debug level.
The concrete, templated class for properties.
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
AnalysisDataServiceImpl::GroupWorkspacesNotification WorkspacesGroupedNotification
@ Output
An output workspace.