Skip to content

Commit

Permalink
Merge pull request #38037 from mantidproject/38018_project_recovery_w…
Browse files Browse the repository at this point in the history
…ith_alg_history_changes

Remove workspace history workaround from binaryOpertaions
  • Loading branch information
SilkeSchomann committed Sep 19, 2024
2 parents e8fff4a + 96edc8c commit 6b3f244
Showing 1 changed file with 2 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,34 +130,13 @@ ResultType performBinaryOp(const LHSType lhs, const RHSType rhs, const std::stri
template <typename LHSType, typename ResultType>
ResultType performBinaryOpWithDouble(const LHSType inputWS, const double value, const std::string &op,
const std::string &name, bool inplace, bool reverse) {
// RAII struct to add/remove workspace from ADS
struct ScopedADSEntry {
ScopedADSEntry(const std::string &entryName, const MatrixWorkspace_sptr &value) : name(entryName) {
ads.addOrReplace(entryName, value);
}
~ScopedADSEntry() { ads.remove(name); }

const std::string &name;
API::AnalysisDataServiceImpl &ads = API::AnalysisDataService::Instance();
};

// In order to recreate a history record of the final binary operation
// there must be a record of the creation of the single value workspace used
// on the RHS here. This is achieved by running CreateSingleValuedWorkspace
// algorithm and adding the output workspace to the ADS. Adding the output
// to the ADS is critical so that workspace.name() is updated, by the ADS, to
// return the same string. WorkspaceProperty<TYPE>::createHistory() then
// records the correct workspace name for input into the final binary
// operation rather than creating a temporary name.

auto alg = API::AlgorithmManager::Instance().createUnmanaged("CreateSingleValuedWorkspace");
alg->setChild(false);
// we manually store the workspace as it's easier to retrieve the correct
// type from alg->getProperty rather than calling the ADS again and casting
alg->setAlwaysStoreInADS(false);
alg->initialize();
alg->setProperty<double>("DataValue", value);
const std::string tmpName("__python_binary_op_single_value");
alg->setPropertyValue("OutputWorkspace", tmpName);
alg->setPropertyValue("OutputWorkspace", "python_binary_op_single_value");
{ // instantiate releaseGIL in limited scope to allow for repeat in 'performBinaryOp'
ReleaseGlobalInterpreterLock releaseGIL;
alg->execute();
Expand All @@ -170,7 +149,6 @@ ResultType performBinaryOpWithDouble(const LHSType inputWS, const double value,
throw std::runtime_error("performBinaryOp: Error in execution of "
"CreateSingleValuedWorkspace");
}
ScopedADSEntry removeOnExit(tmpName, singleValue);
ResultType result =
performBinaryOp<LHSType, MatrixWorkspace_sptr, ResultType>(inputWS, singleValue, op, name, inplace, reverse);
return result;
Expand Down

0 comments on commit 6b3f244

Please sign in to comment.