From 96edc8c9f3e6eacfbc4354d253213fb8d6a025cd Mon Sep 17 00:00:00 2001 From: Jonathan Haigh Date: Thu, 19 Sep 2024 13:33:16 +0100 Subject: [PATCH] remove workspace history workaround from binary ops no longer needed since the work in https://github.com/mantidproject/mantid/pull/37839 --- .../api/src/Exports/BinaryOperations.cpp | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/Framework/PythonInterface/mantid/api/src/Exports/BinaryOperations.cpp b/Framework/PythonInterface/mantid/api/src/Exports/BinaryOperations.cpp index cc5613661824..4eded72ef5f1 100644 --- a/Framework/PythonInterface/mantid/api/src/Exports/BinaryOperations.cpp +++ b/Framework/PythonInterface/mantid/api/src/Exports/BinaryOperations.cpp @@ -130,34 +130,13 @@ ResultType performBinaryOp(const LHSType lhs, const RHSType rhs, const std::stri template 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::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("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(); @@ -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(inputWS, singleValue, op, name, inplace, reverse); return result;