Commit 2089c550 authored by Ian Bush's avatar Ian Bush
Browse files

Refs #21319 Allow algorithms with optional output workspace properties

to be run over group workspaces.

1 - If an output workspace property is optional and not set do not try
and create an output workspace.
2 - If an output workspace property is optional and not set do not try
and set a name for the property when running the child algorithms.
3 - Child algorithms can be run without adding a temporary workspace
name. This is the desired behaviour when running over a group
workspace.
parent 0f77bf99
......@@ -291,11 +291,12 @@ public:
virtual boost::shared_ptr<Algorithm> createChildAlgorithm(
const std::string &name, const double startProgress = -1.,
const double endProgress = -1., const bool enableLogging = true,
const int &version = -1);
const int &version = -1, const bool useTempWorkspaceNames = true);
void setupAsChildAlgorithm(boost::shared_ptr<Algorithm> algorithm,
const double startProgress = -1.,
const double endProgress = -1.,
const bool enableLogging = true);
const bool enableLogging = true,
const bool useTempWorkspaceNames = true);
/// set whether we wish to track the child algorithm's history and pass it the
/// parent object to fill.
......
......@@ -49,7 +49,7 @@ protected:
boost::shared_ptr<Algorithm> createChildAlgorithm(
const std::string &name, const double startProgress = -1.,
const double endProgress = -1., const bool enableLogging = true,
const int &version = -1) override;
const int &version = -1, const bool useTemps = true) override;
void setLoadAlg(const std::string &alg);
void setLoadAlgFileProp(const std::string &filePropName);
void setAccumAlg(const std::string &alg);
......
......@@ -734,16 +734,19 @@ void Algorithm::store() {
*algorithm
* @param version :: The version of the child algorithm to create. By
*default gives the latest version.
* @param useTempWorkspaceNames :: If true then add placeholder names to
*workspaces that are never added to the ADS, due to running as a child
*algorithm, to preserve the algorithm history
* @return shared pointer to the newly created algorithm object
*/
Algorithm_sptr Algorithm::createChildAlgorithm(const std::string &name,
const double startProgress,
const double endProgress,
const bool enableLogging,
const int &version) {
Algorithm_sptr Algorithm::createChildAlgorithm(
const std::string &name, const double startProgress,
const double endProgress, const bool enableLogging, const int &version,
const bool useTempWorkspaceNames) {
Algorithm_sptr alg =
AlgorithmManager::Instance().createUnmanaged(name, version);
setupAsChildAlgorithm(alg, startProgress, endProgress, enableLogging);
setupAsChildAlgorithm(alg, startProgress, endProgress, enableLogging,
useTempWorkspaceNames);
return alg;
}
......@@ -756,7 +759,8 @@ Algorithm_sptr Algorithm::createChildAlgorithm(const std::string &name,
void Algorithm::setupAsChildAlgorithm(Algorithm_sptr alg,
const double startProgress,
const double endProgress,
const bool enableLogging) {
const bool enableLogging,
const bool useTempWorkspaceNames) {
// set as a child
alg->setChild(true);
alg->setLogging(enableLogging);
......@@ -775,7 +779,7 @@ void Algorithm::setupAsChildAlgorithm(Algorithm_sptr alg,
for (auto prop : props) {
auto wsProp = dynamic_cast<IWorkspaceProperty *>(prop);
if (prop->direction() == Mantid::Kernel::Direction::Output && wsProp) {
if (prop->value().empty()) {
if (prop->value().empty() && useTempWorkspaceNames) {
prop->createTemporaryValue();
}
}
......@@ -1301,7 +1305,7 @@ bool Algorithm::processGroups() {
// ---------- Create all the output workspaces ----------------------------
for (auto &pureOutputWorkspaceProp : m_pureOutputWorkspaceProps) {
Property *prop = dynamic_cast<Property *>(pureOutputWorkspaceProp);
if (prop) {
if (prop && !prop->value().empty()) {
auto outWSGrp = boost::make_shared<WorkspaceGroup>();
outGroups.push_back(outWSGrp);
// Put the GROUP in the ADS
......@@ -1317,7 +1321,7 @@ bool Algorithm::processGroups() {
Algorithm_sptr alg_sptr = this->createChildAlgorithm(
this->name(), progress_proportion * static_cast<double>(entry),
progress_proportion * (1 + static_cast<double>(entry)),
this->isLogging(), this->version());
this->isLogging(), this->version(), false);
// Don't make the new algorithm a child so that it's workspaces are stored
// correctly
alg_sptr->setChild(false);
......@@ -1370,6 +1374,8 @@ bool Algorithm::processGroups() {
dynamic_cast<Property *>(m_pureOutputWorkspaceProps[owp])) {
// Default name = "in1_in2_out"
const std::string inName = prop->value();
if (inName.empty())
continue;
std::string outName;
if (m_groupsHaveSimilarNames) {
outName.append(inName).append("_").append(
......@@ -1419,6 +1425,10 @@ bool Algorithm::processGroups() {
// this has to be done after execute() because a workspace must exist
// when it is added to a group
for (size_t owp = 0; owp < m_pureOutputWorkspaceProps.size(); owp++) {
Property *prop =
dynamic_cast<Property *>(m_pureOutputWorkspaceProps[owp]);
if (prop && prop->value().empty())
continue;
// And add it to the output group
outGroups[owp]->add(outputWSNames[owp]);
}
......
......@@ -52,14 +52,19 @@ DataProcessorAlgorithm::DataProcessorAlgorithm()
*algorithm
* @param version :: The version of the child algorithm to create. By
*default gives the latest version.
* @param useTempWorkspaceNames :: If true then add placeholder names to
*workspaces that are never added to the ADS, due to running as a child
*algorithm, to preserve the algorithm history
* @return shared pointer to the newly created algorithm object
*/
boost::shared_ptr<Algorithm> DataProcessorAlgorithm::createChildAlgorithm(
const std::string &name, const double startProgress,
const double endProgress, const bool enableLogging, const int &version) {
const double endProgress, const bool enableLogging, const int &version,
const bool useTempWorkspaceNames) {
// call parent method to create the child algorithm
auto alg = Algorithm::createChildAlgorithm(name, startProgress, endProgress,
enableLogging, version);
enableLogging, version,
useTempWorkspaceNames);
alg->enableHistoryRecordingForChild(this->isRecordingHistoryForChild());
if (this->isRecordingHistoryForChild()) {
// pass pointer to the history object created in Algorithm to the child
......
......@@ -94,7 +94,7 @@ void export_leaf_classes() {
.def("createChildAlgorithm", &Algorithm::createChildAlgorithm,
(arg("self"), arg("name"), arg("startProgress") = -1.0,
arg("endProgress") = -1.0, arg("enableLogging") = true,
arg("version") = -1),
arg("version") = -1, arg("useTempWorkspaceNames") = true),
"Creates and intializes a named child algorithm. Output workspaces "
"are given a dummy name.")
.def("declareProperty",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment