diff --git a/Framework/API/CMakeLists.txt b/Framework/API/CMakeLists.txt index 96b00eb32f8cdfb5a1e4f15277209c854324343b..123b3a1bf0fa9970821d8eb10f099d4d884295e8 100644 --- a/Framework/API/CMakeLists.txt +++ b/Framework/API/CMakeLists.txt @@ -8,7 +8,6 @@ set(SRC_FILES src/AlgorithmManager.cpp src/AlgorithmObserver.cpp src/AlgorithmProperty.cpp - src/AlgorithmProxy.cpp src/AnalysisDataService.cpp src/AnalysisDataServiceObserver.cpp src/ArchiveSearchFactory.cpp @@ -172,7 +171,6 @@ set(INC_FILES inc/MantidAPI/AlgorithmManager.h inc/MantidAPI/AlgorithmObserver.h inc/MantidAPI/AlgorithmProperty.h - inc/MantidAPI/AlgorithmProxy.h inc/MantidAPI/AnalysisDataService.h inc/MantidAPI/AnalysisDataServiceObserver.h inc/MantidAPI/ArchiveSearchFactory.h @@ -379,7 +377,6 @@ set(TEST_FILES AlgorithmMPITest.h AlgorithmManagerTest.h AlgorithmPropertyTest.h - AlgorithmProxyTest.h AlgorithmTest.h AnalysisDataServiceTest.h AnalysisDataServiceObserverTest.h diff --git a/Framework/API/inc/MantidAPI/Algorithm.h b/Framework/API/inc/MantidAPI/Algorithm.h index b92a36024ec8a509b62f672e6b9ced601420e985..9649b15a85608877aa63e3a1cb9f0d8f37b1416f 100644 --- a/Framework/API/inc/MantidAPI/Algorithm.h +++ b/Framework/API/inc/MantidAPI/Algorithm.h @@ -51,7 +51,6 @@ namespace API { //---------------------------------------------------------------------- // Forward Declaration //---------------------------------------------------------------------- -class AlgorithmProxy; class AlgorithmHistory; class WorkspaceHistory; @@ -332,9 +331,6 @@ protected: void cacheWorkspaceProperties(); void cacheInputWorkspaceHistories(); - friend class AlgorithmProxy; - void initializeFromProxy(const AlgorithmProxy &); - void setExecutionState( const ExecutionState state); ///< Sets the current execution state void diff --git a/Framework/API/inc/MantidAPI/AlgorithmManager.h b/Framework/API/inc/MantidAPI/AlgorithmManager.h index 652795dd2ac45ca16480cbd93a7c6fd83ad1e4ce..ad2c9d04fb3be154a5cd09336ba9aec54d88ff48 100644 --- a/Framework/API/inc/MantidAPI/AlgorithmManager.h +++ b/Framework/API/inc/MantidAPI/AlgorithmManager.h @@ -42,8 +42,7 @@ private: class MANTID_API_DLL AlgorithmManagerImpl { public: /// Creates a managed algorithm with the option of choosing a version - IAlgorithm_sptr create(const std::string &algName, const int &version = -1, - bool makeProxy = true); + IAlgorithm_sptr create(const std::string &algName, const int &version = -1); /// Creates an unmanaged algorithm with the option of choosing a version boost::shared_ptr<Algorithm> createUnmanaged(const std::string &algName, const int &version = -1) const; diff --git a/Framework/API/inc/MantidAPI/AlgorithmProxy.h b/Framework/API/inc/MantidAPI/AlgorithmProxy.h deleted file mode 100644 index 45490f3bcb7167232b937cf1df29b8dbcb575f88..0000000000000000000000000000000000000000 --- a/Framework/API/inc/MantidAPI/AlgorithmProxy.h +++ /dev/null @@ -1,207 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/DllConfig.h" -#include "MantidAPI/IAlgorithm.h" -#include "MantidKernel/PropertyManagerOwner.h" - -#ifdef _MSC_VER -#pragma warning(disable : 4250) // Disable warning regarding inheritance via - // dominance, we have no way around it with the - // design -#endif - -//---------------------------------------------------------------------- -// Forward Declaration -//---------------------------------------------------------------------- -namespace Poco { -template <class R, class A, class O, class S> class ActiveMethod; -template <class O> class ActiveStarter; -class Void; -} // namespace Poco - -namespace Mantid { -namespace API { -class Algorithm; -using Algorithm_sptr = boost::shared_ptr<Algorithm>; - -/** - -A proxy class that stands between the user and the actual algorithm. -AlgorithmDataService stores algoruithm proxies. Actual algorithms are -created by the proxy and destroyed after execution to free memory. -Algorithm and its proxy share all properties. - -@author Russell Taylor, Tessella Support Services plc -@author Based on the Gaudi class of the same name (see -http://proj-gaudi.web.cern.ch/proj-gaudi/) -@date 12/09/2007 -@author Roman Tolchenov, Tessella plc -@date 03/03/2009 -*/ -class MANTID_API_DLL AlgorithmProxy : public IAlgorithm, - public Kernel::PropertyManagerOwner { -public: - AlgorithmProxy(const Algorithm_sptr &alg); - AlgorithmProxy(const AlgorithmProxy &) = delete; - AlgorithmProxy &operator=(const AlgorithmProxy &) = delete; - ~AlgorithmProxy() override; - - /// The name of the algorithm - const std::string name() const override { return m_name; } - /// The version of the algorithm - int version() const override { return m_version; } - /// The category of the algorithm - const std::string category() const override { return m_category; } - /// Function to return all of the categories that contain this algorithm - const std::vector<std::string> categories() const override; - /// Function to return the seperator token for the category string. A default - /// implementation ',' is provided - const std::string categorySeparator() const override { - return m_categorySeparator; - } - /// Function to return all of the seeAlso algorithms related to this algorithm - const std::vector<std::string> seeAlso() const override { return m_seeAlso; }; - /// Aliases to the algorithm - const std::string alias() const override { return m_alias; } - /// Optional documentation URL for the real algorithm - const std::string helpURL() const override { return m_helpURL; } - /// function returns a summary message that will be displayed in the default - /// GUI, and in the help. - const std::string summary() const override { return m_summary; } - - /// The algorithmID - AlgorithmID getAlgorithmID() const override; - - void initialize() override; - std::map<std::string, std::string> validateInputs() override; - bool execute() override; - void executeAsChildAlg() override { - throw std::runtime_error("Not implemented."); - } - Poco::ActiveResult<bool> executeAsync() override; - - /// Gets the current execution state - ExecutionState executionState() const override; - /// Gets the current result State - ResultState resultState() const override; - - bool isInitialized() const override; - bool isExecuted() const override; - - /// To query whether algorithm is a child. A proxy is always at top level, - /// returns false - bool isChild() const override { return m_isChild; } - void setChild(const bool val) override { - m_isChild = val; - setAlwaysStoreInADS(!val); - } - void setAlwaysStoreInADS(const bool val) override { - m_setAlwaysStoreInADS = val; - } - bool getAlwaysStoreInADS() const override { return m_setAlwaysStoreInADS; } - - /// Proxies only manage parent algorithms - void enableHistoryRecordingForChild(const bool) override{}; - void setRethrows(const bool rethrow) override; - - const std::string workspaceMethodName() const override; - const std::vector<std::string> workspaceMethodOn() const override; - const std::string workspaceMethodInputProperty() const override; - - /** @name PropertyManager methods */ - //@{ - /// Set the property value - void setPropertyValue(const std::string &name, - const std::string &value) override; - /// Do something after a property was set - void afterPropertySet(const std::string &) override; - /// Make m_properties point to the same PropertyManager as po. - void copyPropertiesFrom(const PropertyManagerOwner &po) override; - //@} - - void cancel() override; - bool isRunning() const override; - - void addObserver(const Poco::AbstractObserver &observer) const override; - void removeObserver(const Poco::AbstractObserver &observer) const override; - - /// Set logging on or off - ///@param value :: true = logging enabled - void setLogging(const bool value) override { m_isLoggingEnabled = value; } - /// Is the algorithm have logging enabled - bool isLogging() const override { return m_isLoggingEnabled; } - - /// returns the logging priority offset - void setLoggingOffset(const int value) override { m_loggingOffset = value; } - /// returns the logging priority offset - int getLoggingOffset() const override { return m_loggingOffset; } - /// disable Logging of start and end messages - void setAlgStartupLogging(const bool enabled) override; - /// get the state of Logging of start and end messages - bool getAlgStartupLogging() const override; - - /// setting the child start progress - void setChildStartProgress(const double startProgress) const override; - /// setting the child end progress - void setChildEndProgress(const double endProgress) const override; - - /** @name Serialization */ - //@{ - /// Serialize an object to a string - std::string toString() const override; - /// Serialize as a json value - Json::Value toJson() const override; - //@} - -private: - void createConcreteAlg(bool initOnly = false); - void stopped(); - void addObservers(); - void dropWorkspaceReferences(); - - /// Poco::ActiveMethod used to implement asynchronous execution. - Poco::ActiveMethod<bool, Poco::Void, AlgorithmProxy, - Poco::ActiveStarter<AlgorithmProxy>> *m_executeAsync; - /// Execute asynchronous implementation - bool executeAsyncImpl(const Poco::Void &dummy); - - const std::string m_name; ///< name of the real algorithm - const std::string m_category; ///< category of the real algorithm - const std::string - m_categorySeparator; ///< category seperator of the real algorithm - const std::vector<std::string> m_seeAlso; ///< seeAlso of the real algorithm - const std::string m_alias; ///< alias to the algorithm - const std::string m_helpURL; ///< Optional documentation URL - const std::string m_summary; ///< Message to display in GUI and help. - const int m_version; ///< version of the real algorithm - - mutable boost::shared_ptr<Algorithm> - m_alg; ///< Shared pointer to a real algorithm. Created on demand - - ExecutionState m_executionState; ///< the current execution state - ResultState m_resultState; ///< the current result State - bool m_isLoggingEnabled; ///< is the logging of the underlying algorithm - /// enabled - int m_loggingOffset; ///< the logging priority offset - bool m_isAlgStartupLoggingEnabled; /// Whether to log alg startup and - /// closedown messages from the base class - /// (default = true) - bool m_rethrow; ///< Whether or not to rethrow exceptions. - bool m_isChild; ///< Is this a child algo - bool m_setAlwaysStoreInADS; ///< If this will save in ADS - - /// Temporary holder of external observers wishing to subscribe - mutable std::vector<const Poco::AbstractObserver *> m_externalObservers; -}; - -} // namespace API -} // namespace Mantid diff --git a/Framework/API/inc/MantidAPI/FrameworkManager.h b/Framework/API/inc/MantidAPI/FrameworkManager.h index bce8df27990f98a1b5edd3e7bbe9160c61fac605..84269f1be98e8f7f9a5a20641f97cb9baea29c1b 100644 --- a/Framework/API/inc/MantidAPI/FrameworkManager.h +++ b/Framework/API/inc/MantidAPI/FrameworkManager.h @@ -58,19 +58,6 @@ public: /// Clear memory associated with the PropertyManagers void clearPropertyManagers(); - /// Creates and instance of an algorithm - IAlgorithm *createAlgorithm(const std::string &algName, - const int &version = -1); - - /// Creates an instance of an algorithm and sets the properties provided - IAlgorithm *createAlgorithm(const std::string &algName, - const std::string &propertiesArray, - const int &version = -1); - - /// Creates an instance of an algorithm, sets the properties provided & then - /// executes it. - IAlgorithm *exec(const std::string &algName, - const std::string &propertiesArray, const int &version = -1); /// Creates an algorithm and runs it, with variadic arguments boost::shared_ptr<IAlgorithm> exec(const std::string &algorithmName, diff --git a/Framework/API/inc/MantidAPI/IAlgorithm.h b/Framework/API/inc/MantidAPI/IAlgorithm.h index 9b22aeaa403a35904c47c304c99f68b1bad32d24..b1b8377ef1a2b2434f03ee9d4b8fa3febe199209 100644 --- a/Framework/API/inc/MantidAPI/IAlgorithm.h +++ b/Framework/API/inc/MantidAPI/IAlgorithm.h @@ -21,8 +21,7 @@ template <class T> class ActiveResult; namespace Mantid { namespace API { -/** As we have multiple interfaces to the same logical algorithm (Algorithm & - * AlgorithmProxy) +/** As we have multiple interfaces to the same logical algorithm * we need a way of uniquely identifying managed algorithms. It can be * AlgorithmID. */ diff --git a/Framework/API/src/Algorithm.cpp b/Framework/API/src/Algorithm.cpp index f76b90be2ee3db4a413cd4a91257dceb6ddbc174..4cc4e5d93cefc118e784424ac0dafb4aa5a05856 100644 --- a/Framework/API/src/Algorithm.cpp +++ b/Framework/API/src/Algorithm.cpp @@ -8,7 +8,6 @@ #include "MantidAPI/ADSValidator.h" #include "MantidAPI/AlgorithmHistory.h" #include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AlgorithmProxy.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/DeprecatedAlgorithm.h" #include "MantidAPI/IWorkspaceProperty.h" @@ -996,21 +995,6 @@ IAlgorithm_sptr Algorithm::fromJson(const Json::Value &serialized) { return alg; } -//------------------------------------------------------------------------- -/** Initialize using proxy algorithm. - * Call the main initialize method and then copy in the property values. - * @param proxy :: Initialising proxy algorithm */ -void Algorithm::initializeFromProxy(const AlgorithmProxy &proxy) { - initialize(); - copyPropertiesFrom(proxy); - m_algorithmID = proxy.getAlgorithmID(); - setLogging(proxy.isLogging()); - setLoggingOffset(proxy.getLoggingOffset()); - setAlgStartupLogging(proxy.getAlgStartupLogging()); - setChild(proxy.isChild()); - setAlwaysStoreInADS(proxy.getAlwaysStoreInADS()); -} - /** Fills History, Algorithm History and Algorithm Parameters */ void Algorithm::fillHistory() { diff --git a/Framework/API/src/AlgorithmManager.cpp b/Framework/API/src/AlgorithmManager.cpp index 2d657d81c4ffd3abba445d1597ce12ae57755968..19bb4e652533d5ca8984d41515808fac18fcd34e 100644 --- a/Framework/API/src/AlgorithmManager.cpp +++ b/Framework/API/src/AlgorithmManager.cpp @@ -10,7 +10,6 @@ #include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/Algorithm.h" #include "MantidAPI/AlgorithmFactory.h" -#include "MantidAPI/AlgorithmProxy.h" #include "MantidKernel/ConfigService.h" namespace Mantid { @@ -52,27 +51,18 @@ Algorithm_sptr AlgorithmManagerImpl::createUnmanaged(const std::string &algName, * * @param algName :: The name of the algorithm required * @param version :: The version of the algorithm required, if not defined most - *recent version is used -> version =-1 - * @param makeProxy :: If true (default), create and return AlgorithmProxy of - *the given algorithm. - * DO NOT SET TO FALSE unless you are really sure of what you are doing! + * recent version is used -> version =-1 * @return A pointer to the created algorithm * @throw NotFoundError Thrown if algorithm requested is not registered * @throw std::runtime_error Thrown if properties string is ill-formed */ IAlgorithm_sptr AlgorithmManagerImpl::create(const std::string &algName, - const int &version, - bool makeProxy) { + const int &version) { std::lock_guard<std::mutex> _lock(this->m_managedMutex); IAlgorithm_sptr alg; try { - Algorithm_sptr unmanagedAlg = AlgorithmFactory::Instance().create( - algName, version); // Throws on fail: - if (makeProxy) - alg = IAlgorithm_sptr(new AlgorithmProxy(unmanagedAlg)); - else - alg = unmanagedAlg; - + alg = AlgorithmFactory::Instance().create(algName, + version); // Throws on fail: auto count = removeFinishedAlgorithms(); g_log.debug() << count diff --git a/Framework/API/src/AlgorithmObserver.cpp b/Framework/API/src/AlgorithmObserver.cpp index 5fb257a1a9a2b8f1353d60106fc7bceb95b87d29..5c71b44e5390cfa4a15a11e6c8d15556c9e02f5c 100644 --- a/Framework/API/src/AlgorithmObserver.cpp +++ b/Framework/API/src/AlgorithmObserver.cpp @@ -113,13 +113,7 @@ void AlgorithmObserver::stopObservingManager() { /** Handler of the progress notifications. Must be overriden in inherited classes. The default handler is provided (doing nothing). -@param alg :: Pointer to the algorithm sending the notification. Note that -this can -point to a different object than the argument of a observeZZZ(...) method, -e.g. -an observer can be connected to an AlgorithmProxy instance and receive -notifications from -the corresponding Algorithm type object. +@param alg :: Pointer to the algorithm sending the notification. @param p :: Progress reported by the algorithm, 0 <= p <= 1 @param msg :: Optional message string sent by the algorithm */ @@ -138,37 +132,19 @@ void AlgorithmObserver::startingHandle(IAlgorithm_sptr alg) { UNUSED_ARG(alg) } /** Handler of the start notifications. Must be overriden in inherited classes. The default handler is provided (doing nothing). -@param alg :: Pointer to the algorithm sending the notification. Note that -this can -point to a different object than the argument of a observeZZZ(...) method, -e.g. -an observer can be connected to an AlgorithmProxy instance and receive -notifications from -the corresponding Algorithm type object. +@param alg :: Pointer to the algorithm sending the notification. */ void AlgorithmObserver::startHandle(const IAlgorithm *alg) { UNUSED_ARG(alg) } /** Handler of the finish notifications. Must be overriden in inherited classes. The default handler is provided (doing nothing). - @param alg :: Pointer to the algorithm sending the notification. Note that -this can - point to a different object than the argument of a observeZZZ(...) method, -e.g. - an observer can be connected to an AlgorithmProxy instance and receive -notifications from - the corresponding Algorithm type object. + @param alg :: Pointer to the algorithm sending the notification. */ void AlgorithmObserver::finishHandle(const IAlgorithm *alg) { UNUSED_ARG(alg) } /** Handler of the error notifications. Must be overriden in inherited classes. The default handler is provided (doing nothing). -@param alg :: Pointer to the algorithm sending the notification. Note that -this can -point to a different object than the argument of a observeZZZ(...) method, -e.g. -an observer can be connected to an AlgorithmProxy instance and receive -notifications from -the corresponding Algorithm type object. +@param alg :: Pointer to the algorithm sending the notification. @param what :: The error message */ void AlgorithmObserver::errorHandle(const IAlgorithm *alg, diff --git a/Framework/API/src/AlgorithmProxy.cpp b/Framework/API/src/AlgorithmProxy.cpp deleted file mode 100644 index 876a9b51d1b1b2504dd0b0551f8f9870860d3b5c..0000000000000000000000000000000000000000 --- a/Framework/API/src/AlgorithmProxy.cpp +++ /dev/null @@ -1,363 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#include "MantidAPI/AlgorithmProxy.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AlgorithmObserver.h" -#include "MantidAPI/DeprecatedAlgorithm.h" -#include "MantidKernel/StringTokenizer.h" - -#include <Poco/ActiveMethod.h> -#include <Poco/ActiveResult.h> -#include <Poco/Void.h> -#include <json/value.h> - -using namespace Mantid::Kernel; - -namespace Mantid { -namespace API { - -/// Constructor -AlgorithmProxy::AlgorithmProxy(const Algorithm_sptr &alg) - : PropertyManagerOwner(), - m_executeAsync(new Poco::ActiveMethod<bool, Poco::Void, AlgorithmProxy>( - this, &AlgorithmProxy::executeAsyncImpl)), - m_name(alg->name()), m_category(alg->category()), - m_categorySeparator(alg->categorySeparator()), m_seeAlso(alg->seeAlso()), - m_alias(alg->alias()), m_summary(alg->summary()), - m_version(alg->version()), m_alg(alg), - m_executionState(ExecutionState::Initialized), - m_resultState(ResultState::NotFinished), m_isLoggingEnabled(true), - m_loggingOffset(0), m_isAlgStartupLoggingEnabled(true), m_rethrow(false), - m_isChild(false), m_setAlwaysStoreInADS(true) { - if (!alg) { - throw std::logic_error("Unable to create a proxy algorithm."); - } - alg->initialize(); - copyPropertiesFrom(*alg); -} - -/// Virtual destructor -AlgorithmProxy::~AlgorithmProxy() { delete m_executeAsync; } - -/** Initialization method invoked by the framework. - * Does nothing for AlgorithmProxy as initialization is done in the - * constructor. - */ -void AlgorithmProxy::initialize() {} - -AlgorithmID AlgorithmProxy::getAlgorithmID() const { - return AlgorithmID(const_cast<AlgorithmProxy *>(this)); -} - -/** Perform whole-input validation */ -std::map<std::string, std::string> AlgorithmProxy::validateInputs() { - if (!m_alg) - createConcreteAlg(true); - return m_alg->validateInputs(); -} - -/** The actions to be performed by the AlgorithmProxy on a dataset. This method - *is - * invoked for top level AlgorithmProxys by the application manager. - * This method invokes exec() method. - * For Child AlgorithmProxys either the execute() method or exec() method - * must be EXPLICITLY invoked by the parent AlgorithmProxy. - * - * @throw runtime_error Thrown if AlgorithmProxy or Child AlgorithmProxy cannot - *be executed - */ -bool AlgorithmProxy::execute() { - createConcreteAlg(false); - try { - m_alg->execute(); - } catch (...) { - stopped(); - throw; - } - stopped(); - return isExecuted(); -} - -/** Asynchronous execution of the algorithm. - * This will launch the AlgorithmProxy::executeAsyncImpl() method - * but in a separate thread. - * - * @return Poco::ActiveResult containing the result from the thread. - */ -Poco::ActiveResult<bool> AlgorithmProxy::executeAsync() { - return (*m_executeAsync)(Poco::Void()); -} - -/** executeAsync() implementation. - * Calls execute and, when it has finished, deletes the real algorithm. - * @param dummy :: An unused dummy variable - */ -bool AlgorithmProxy::executeAsyncImpl(const Poco::Void &dummy) { - createConcreteAlg(false); - // Call Algorithm::executeAsyncImpl rather than executeAsync() because the - // latter - // would spawn off another (3rd) thread which is unecessary. - try { - m_alg->executeAsyncImpl( - dummy); // Pass through dummy argument, though not used - } catch (...) { - stopped(); - throw; - } - stopped(); - return isExecuted(); -} - -/// Gets the current execution state -ExecutionState AlgorithmProxy::executionState() const { - return m_executionState; -} - -/// Gets the current result State -ResultState AlgorithmProxy::resultState() const { return m_resultState; } - -/// True if the algorithm is running. -bool AlgorithmProxy::isRunning() const { - return m_alg ? (m_alg->executionState() == ExecutionState::Running) : false; -} - -/// Has the AlgorithmProxy already been initialized -bool AlgorithmProxy::isInitialized() const { - return true; // Algorithm Proxies will always initialize the algorithm -} - -/// Has the AlgorithmProxy already been executed successfully -bool AlgorithmProxy::isExecuted() const { - return resultState() == ResultState::Success; -} - -/// Cancel the execution of the algorithm -void AlgorithmProxy::cancel() { - if (m_alg) - m_alg->cancel(); -} - -/** Add an observer for a notification. If the real algorithm is running - * the observer is added directly. If the algorithm is not running yet - * the observer's address is added to a buffer to be used later when - * execute/executeAsync - * method is called. - * @param observer :: Observer - */ -void AlgorithmProxy::addObserver(const Poco::AbstractObserver &observer) const { - const Poco::AbstractObserver *obs = &observer; - if (m_alg) { - m_alg->addObserver(*obs); - } - // save the observer in any case because m_alg can be reset (eg in - // createConcreteAlg()) - m_externalObservers.emplace_back(obs); -} - -/** Remove an observer. - * @param observer :: Observer - */ -void AlgorithmProxy::removeObserver( - const Poco::AbstractObserver &observer) const { - auto o = std::find(m_externalObservers.begin(), m_externalObservers.end(), - &observer); - if (o != m_externalObservers.end()) - m_externalObservers.erase(o); - if (m_alg) - m_alg->removeObserver(observer); -} - -void AlgorithmProxy::setRethrows(const bool rethrow) { - this->m_rethrow = rethrow; - if (m_alg) - m_alg->setRethrows(rethrow); -} - -/** - * @return A string giving the method name that should be attached to a - * workspace - */ -const std::string AlgorithmProxy::workspaceMethodName() const { - if (m_alg) - return m_alg->workspaceMethodName(); - else - return ""; -} - -/** - * @return A set of workspace class names that should have the - * workspaceMethodName attached - */ -const std::vector<std::string> AlgorithmProxy::workspaceMethodOn() const { - if (m_alg) - return m_alg->workspaceMethodOn(); - else - return std::vector<std::string>(); -} - -/** - * @return The name of the property that the calling object will be passed to - */ -const std::string AlgorithmProxy::workspaceMethodInputProperty() const { - if (m_alg) - return m_alg->workspaceMethodInputProperty(); - else - return ""; -} - -/** - * Override setPropertyValue - * @param name The name of the property - * @param value The value of the property as a string - */ -void AlgorithmProxy::setPropertyValue(const std::string &name, - const std::string &value) { - createConcreteAlg(true); - m_alg->setPropertyValue(name, value); - copyPropertiesFrom(*m_alg); -} - -/** - * Do something after a property was set - * @param name :: The name of the property - */ -void AlgorithmProxy::afterPropertySet(const std::string &name) { - createConcreteAlg(true); - m_alg->getPointerToProperty(name)->setValueFromProperty( - *this->getPointerToProperty(name)); - m_alg->afterPropertySet(name); - copyPropertiesFrom(*m_alg); -} - -/** - * Copy properties from another property manager - * Making sure that the concrete alg is kept in sync - * @param po :: The property manager to copy - */ -void AlgorithmProxy::copyPropertiesFrom(const PropertyManagerOwner &po) { - PropertyManagerOwner::copyPropertiesFrom(po); - createConcreteAlg(true); - m_alg->copyPropertiesFrom(*this); -} - -//---------------------------------------------------------------------- -// Private methods -//---------------------------------------------------------------------- - -/** - * Creates an unmanaged instance of the actual algorithm and sets its properties - * @param initOnly If true then the algorithm will only having its init step - * run, otherwise observers will also be added and rethrows will be true - */ -void AlgorithmProxy::createConcreteAlg(bool initOnly) { - if ((m_alg) && initOnly) { - // the cached algorithm exists and is not going to be executed, - // use that one - } else { - m_alg = boost::dynamic_pointer_cast<Algorithm>( - AlgorithmManager::Instance().createUnmanaged(name(), version())); - m_alg->initializeFromProxy(*this); - if (!initOnly) { - m_alg->setRethrows(this->m_rethrow); - addObservers(); - } - } -} - -/** - * Clean up when the real algorithm stops - */ -void AlgorithmProxy::stopped() { - if (m_setAlwaysStoreInADS) - dropWorkspaceReferences(); - m_executionState = m_alg->executionState(); - m_resultState = m_alg->resultState(); - m_alg.reset(); -} - -/** - * Forces any workspace property to clear its internal workspace reference - */ -void AlgorithmProxy::dropWorkspaceReferences() { - const std::vector<Property *> &props = getProperties(); - for (auto prop : props) { - if (auto *wsProp = dynamic_cast<IWorkspaceProperty *>(prop)) { - wsProp->clear(); - } - } -} - -/** - * Add observers stored previously in m_externalObservers - */ -void AlgorithmProxy::addObservers() { - if (!m_alg) - return; - for (auto o = m_externalObservers.rbegin(); o != m_externalObservers.rend(); - ++o) - m_alg->addObserver(**o); - m_externalObservers.clear(); -} - -/// setting the child start progress -void AlgorithmProxy::setChildStartProgress(const double startProgress) const { - m_alg->setChildStartProgress(startProgress); -} -/// setting the child end progress -void AlgorithmProxy::setChildEndProgress(const double endProgress) const { - m_alg->setChildEndProgress(endProgress); -} - -/** - * Serialize this object to a string. Simple routes the call the algorithm - * @returns This object serialized as a string - */ -std::string AlgorithmProxy::toString() const { - const_cast<AlgorithmProxy *>(this)->createConcreteAlg(true); - return m_alg->toString(); -} - -/** - * Serialize this object to a Json::Value. Simple routes the call the algorithm - * @returns This object serialized as a Json::Value - */ -Json::Value AlgorithmProxy::toJson() const { - const_cast<AlgorithmProxy *>(this)->createConcreteAlg(true); - return m_alg->toJson(); -} - -/// Function to return all of the categories that contain this algorithm -const std::vector<std::string> AlgorithmProxy::categories() const { - Mantid::Kernel::StringTokenizer tokenizer( - category(), categorySeparator(), - Mantid::Kernel::StringTokenizer::TOK_TRIM | - Mantid::Kernel::StringTokenizer::TOK_IGNORE_EMPTY); - - auto res = tokenizer.asVector(); - - const auto *depo = dynamic_cast<const DeprecatedAlgorithm *>(this); - if (depo != nullptr) { - res.emplace_back("Deprecated"); - } - return res; -} - -/** Enable or disable Logging of start and end messages -@param enabled : true to enable logging, false to disable -*/ -void AlgorithmProxy::setAlgStartupLogging(const bool enabled) { - m_isAlgStartupLoggingEnabled = enabled; -} - -/** return the state of logging of start and end messages -@returns : true to logging is enabled -*/ -bool AlgorithmProxy::getAlgStartupLogging() const { - return m_isAlgStartupLoggingEnabled; -} -} // namespace API -} // namespace Mantid diff --git a/Framework/API/src/FrameworkManager.cpp b/Framework/API/src/FrameworkManager.cpp index 99aacd3f6e01ce0139ec570de717d2c6c33e4350..79155cbf1eb4083bca8a49e8286fea6938f05614 100644 --- a/Framework/API/src/FrameworkManager.cpp +++ b/Framework/API/src/FrameworkManager.cpp @@ -259,76 +259,6 @@ void FrameworkManagerImpl::clearPropertyManagers() { PropertyManagerDataService::Instance().clear(); } -/** Creates and initialises an instance of an algorithm - * - * @param algName :: The name of the algorithm required - * @param version :: The version of the algorithm - * @return A pointer to the created algorithm. - * WARNING! DO NOT DELETE THIS POINTER, because it is owned - * by a shared pointer in the AlgorithmManager. - * - * @throw NotFoundError Thrown if algorithm requested is not registered - */ -IAlgorithm *FrameworkManagerImpl::createAlgorithm(const std::string &algName, - const int &version) { - IAlgorithm *alg = AlgorithmManager::Instance().create(algName, version).get(); - return alg; -} - -/** Creates an instance of an algorithm and sets the properties provided - * - * @param algName :: The name of the algorithm required - * @param propertiesArray :: A single string containing properties in the - * form "Property1=Value1;Property2=Value2;..." - * @param version :: The version of the algorithm - * @return A pointer to the created algorithm - * WARNING! DO NOT DELETE THIS POINTER, because it is owned - * by a shared pointer in the AlgorithmManager. - * - * @throw NotFoundError Thrown if algorithm requested is not registered - * @throw std::invalid_argument Thrown if properties string is ill-formed - */ -IAlgorithm * -FrameworkManagerImpl::createAlgorithm(const std::string &algName, - const std::string &propertiesArray, - const int &version) { - // Use the previous method to create the algorithm - IAlgorithm *alg = AlgorithmManager::Instance() - .create(algName, version) - .get(); // createAlgorithm(algName); - alg->setPropertiesWithString(propertiesArray); - - return alg; -} - -/** Creates an instance of an algorithm, sets the properties provided and - * then executes it. - * - * @param algName :: The name of the algorithm required - * @param propertiesArray :: A single string containing properties in the - * form "Property1=Value1;Property2=Value2;..." - * @param version :: The version of the algorithm - * @return A pointer to the executed algorithm - * WARNING! DO NOT DELETE THIS POINTER, because it is owned - * by a shared pointer in the AlgorithmManager. - * - * @throw NotFoundError Thrown if algorithm requested is not registered - * @throw std::invalid_argument Thrown if properties string is ill-formed - * @throw runtime_error Thrown if algorithm cannot be executed - */ -IAlgorithm *FrameworkManagerImpl::exec(const std::string &algName, - const std::string &propertiesArray, - const int &version) { - // Make use of the previous method for algorithm creation and property - // setting - IAlgorithm *alg = createAlgorithm(algName, propertiesArray, version); - - // Now execute the algorithm - alg->execute(); - - return alg; -} - /** Run any algorithm with a variable number of parameters * * @param algorithmName @@ -500,8 +430,8 @@ void FrameworkManagerImpl::setupUsageReporting() { /// Update instrument definitions from github void FrameworkManagerImpl::updateInstrumentDefinitions() { try { - IAlgorithm *algDownloadInstrument = - this->createAlgorithm("DownloadInstrument"); + auto algDownloadInstrument = + Mantid::API::AlgorithmManager::Instance().create("DownloadInstrument"); algDownloadInstrument->setAlgStartupLogging(false); algDownloadInstrument->executeAsync(); } catch (Kernel::Exception::NotFoundError &) { @@ -513,7 +443,8 @@ void FrameworkManagerImpl::updateInstrumentDefinitions() { /// Check if a newer release of Mantid is available void FrameworkManagerImpl::checkIfNewerVersionIsAvailable() { try { - IAlgorithm *algCheckVersion = this->createAlgorithm("CheckMantidVersion"); + auto algCheckVersion = + Mantid::API::AlgorithmManager::Instance().create("CheckMantidVersion"); algCheckVersion->setAlgStartupLogging(false); algCheckVersion->executeAsync(); } catch (Kernel::Exception::NotFoundError &) { diff --git a/Framework/API/test/AlgorithmManagerTest.h b/Framework/API/test/AlgorithmManagerTest.h index e33bd369e99f41f277ef33a6cdebb86d6f341424..43db4ae41a0e5a34f7054509581f6cf9faaac618 100644 --- a/Framework/API/test/AlgorithmManagerTest.h +++ b/Framework/API/test/AlgorithmManagerTest.h @@ -10,7 +10,6 @@ #include "MantidAPI/Algorithm.h" #include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AlgorithmProxy.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidKernel/ConfigService.h" #include <Poco/ActiveResult.h> @@ -142,12 +141,12 @@ public: IAlgorithm_sptr alg; TS_ASSERT_THROWS_NOTHING( alg = AlgorithmManager::Instance().create("AlgTest", 1)); - TS_ASSERT_DIFFERS(dynamic_cast<AlgorithmProxy *>(alg.get()), - static_cast<AlgorithmProxy *>(nullptr)); + TS_ASSERT_DIFFERS(dynamic_cast<Algorithm *>(alg.get()), + static_cast<Algorithm *>(nullptr)); TS_ASSERT_THROWS_NOTHING( alg = AlgorithmManager::Instance().create("AlgTestSecond", 1)); - TS_ASSERT_DIFFERS(dynamic_cast<AlgorithmProxy *>(alg.get()), - static_cast<AlgorithmProxy *>(nullptr)); + TS_ASSERT_DIFFERS(dynamic_cast<Algorithm *>(alg.get()), + static_cast<Algorithm *>(nullptr)); TS_ASSERT_DIFFERS(dynamic_cast<IAlgorithm *>(alg.get()), static_cast<IAlgorithm *>(nullptr)); TS_ASSERT_EQUALS(AlgorithmManager::Instance().size(), @@ -165,17 +164,6 @@ public: TS_ASSERT_DIFFERS(Bptr.get(), static_cast<Algorithm *>(nullptr)); } - void testCreateNoProxy() { - AlgorithmManager::Instance().clear(); - IAlgorithm_sptr Aptr, Bptr; - Aptr = AlgorithmManager::Instance().create("AlgTest", -1, true); - Bptr = AlgorithmManager::Instance().create("AlgTest", -1, false); - TSM_ASSERT("Was created as a AlgorithmProxy", - dynamic_cast<AlgorithmProxy *>(Aptr.get())); - TSM_ASSERT("Was NOT created as a AlgorithmProxy", - dynamic_cast<AlgorithmProxy *>(Bptr.get()) == nullptr); - } - // This will be called back when an algo starts void handleAlgorithmStartingNotification( const Poco::AutoPtr<AlgorithmStartingNotification> & /*pNf*/) { @@ -194,19 +182,12 @@ public: AlgorithmManager::Instance().notificationCenter.addObserver(my_observer); IAlgorithm_sptr Aptr, Bptr; - Aptr = AlgorithmManager::Instance().create("AlgTest", -1, true); - Bptr = AlgorithmManager::Instance().create("AlgTest", -1, false); - - m_notificationValue = 0; - Poco::ActiveResult<bool> resB = Bptr->executeAsync(); - resB.wait(); - TSM_ASSERT_EQUALS("Notification was received.", m_notificationValue, 12345); + Aptr = AlgorithmManager::Instance().create("AlgTest", -1); m_notificationValue = 0; Poco::ActiveResult<bool> resA = Aptr->executeAsync(); resA.wait(); - TSM_ASSERT_EQUALS("Notification was received (proxy).", m_notificationValue, - 12345); + TSM_ASSERT_EQUALS("Notification was received.", m_notificationValue, 12345); AlgorithmManager::Instance().notificationCenter.removeObserver(my_observer); } @@ -252,7 +233,7 @@ public: // Create another 'runs forever' algorithm (without proxy) and another // 'normal' one auto aRunningAlgorithm = - AlgorithmManager::Instance().create("AlgRunsForever", 1, false); + AlgorithmManager::Instance().create("AlgRunsForever", 1); TS_ASSERT( AlgorithmManager::Instance().runningInstancesOf("AlgTest").empty()) TS_ASSERT_EQUALS(AlgorithmManager::Instance() @@ -279,7 +260,7 @@ public: // Create without proxy so that I can cast it to an Algorithm and get at // getCancel() algs[i] = boost::dynamic_pointer_cast<Algorithm>( - AlgorithmManager::Instance().create("AlgRunsForever", 1, false)); + AlgorithmManager::Instance().create("AlgRunsForever", 1)); TS_ASSERT(!algs[i]->getCancel()); } diff --git a/Framework/API/test/AlgorithmProxyTest.h b/Framework/API/test/AlgorithmProxyTest.h deleted file mode 100644 index bff605adc012261bb356f7708ac5b2d8b8d5d7e2..0000000000000000000000000000000000000000 --- a/Framework/API/test/AlgorithmProxyTest.h +++ /dev/null @@ -1,264 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#pragma once - -#include <cxxtest/TestSuite.h> - -#include "MantidAPI/Algorithm.h" -#include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AlgorithmObserver.h" -#include "MantidAPI/AlgorithmProxy.h" - -#include <Poco/ActiveResult.h> -#include <Poco/Thread.h> - -#include <boost/lexical_cast.hpp> -#include <utility> - -using namespace Mantid::API; -using namespace Mantid::Kernel; - -class ToyAlgorithmProxy : public Algorithm { -public: - ToyAlgorithmProxy() : Algorithm() {} - ~ToyAlgorithmProxy() override {} - const std::string name() const override { - return "ToyAlgorithmProxy"; - } ///< Algorithm's name for identification - int version() const override { - return 1; - } ///< Algorithm's version for identification - const std::string category() const override { - return "ProxyCat"; - } ///< Algorithm's category for identification - const std::vector<std::string> seeAlso() const override { - return {"elephant", "seal"}; - } ///< Algorithm's seeAlso - const std::string alias() const override { - return "Dog"; - } ///< Algorithm's alias - const std::string summary() const override { return "Test summary"; } - const std::string workspaceMethodName() const override { - return "toyalgorithm"; - } - const std::string workspaceMethodOnTypes() const override { - return "MatrixWorkspace;ITableWorkspace"; - } - const std::string workspaceMethodInputProperty() const override { - return "InputWorkspace"; - } - - void init() override { - declareProperty("prop1", "value"); - declareProperty("prop2", 1); - declareProperty("out", 8, Direction::Output); - } - void exec() override { - std::string p1 = getProperty("prop1"); - int p2 = getProperty("prop2"); - - Poco::Thread::current()->sleep(500); - progress(0.333, "Running"); - interruption_point(); - Algorithm *alg = dynamic_cast<Algorithm *>(this); - TS_ASSERT(alg); - - TS_ASSERT_EQUALS(p1, "stuff"); - TS_ASSERT_EQUALS(p2, 17); - - setProperty("out", 28); - } -}; - -class ToyAlgorithmProxyMultipleCategory : public Algorithm { -public: - ToyAlgorithmProxyMultipleCategory() : Algorithm() {} - ~ToyAlgorithmProxyMultipleCategory() override {} - const std::string name() const override { - return "ToyAlgorithmProxyMultipleCategory"; - } ///< Algorithm's name for identification - int version() const override { - return 1; - } ///< Algorithm's version for identification - const std::string category() const override { - return "ProxyCat;ProxyLeopard"; - } ///< Algorithm's category for identification - const std::string alias() const override { - return "Dog"; - } ///< Algorithm's alias - const std::string summary() const override { return "Test summary"; } - void init() override { - declareProperty("prop1", "value"); - declareProperty("prop2", 1); - declareProperty("out", 8, Direction::Output); - } - void exec() override { - std::string p1 = getProperty("prop1"); - int p2 = getProperty("prop2"); - - Poco::Thread::current()->sleep(500); - progress(0.333, "Running"); - interruption_point(); - Algorithm *alg = dynamic_cast<Algorithm *>(this); - TS_ASSERT(alg); - - TS_ASSERT_EQUALS(p1, "stuff"); - TS_ASSERT_EQUALS(p2, 17); - - setProperty("out", 28); - } -}; - -DECLARE_ALGORITHM(ToyAlgorithmProxy) -DECLARE_ALGORITHM(ToyAlgorithmProxyMultipleCategory) - -class TestProxyObserver : public AlgorithmObserver { -public: - bool start, progress, finish; - TestProxyObserver() - : AlgorithmObserver(), start(false), progress(false), finish(false) {} - TestProxyObserver(IAlgorithm_const_sptr alg) - : AlgorithmObserver(std::move(alg)), start(false), progress(false), - finish(false) {} - void startHandle(const IAlgorithm *) override { start = true; } - void progressHandle(const IAlgorithm *, double p, - const std::string &msg) override { - progress = true; - TS_ASSERT_EQUALS(p, 0.333); - TS_ASSERT_EQUALS(msg, "Running"); - } - void finishHandle(const IAlgorithm *) override { finish = true; } -}; - -class AlgorithmProxyTest : public CxxTest::TestSuite { -public: - void testCreateProxy() { - IAlgorithm_sptr alg = - AlgorithmManager::Instance().create("ToyAlgorithmProxy"); - TS_ASSERT(dynamic_cast<AlgorithmProxy *>(alg.get())); - TS_ASSERT_EQUALS(alg->name(), "ToyAlgorithmProxy"); - TS_ASSERT_EQUALS(alg->version(), 1); - TS_ASSERT_EQUALS(alg->category(), "ProxyCat"); - TS_ASSERT_EQUALS(alg->alias(), "Dog"); - std::vector<std::string> seeAlsoList{"elephant", "seal"}; - TS_ASSERT_EQUALS(alg->seeAlso(), seeAlsoList); - TS_ASSERT(alg->isInitialized()); - TS_ASSERT(alg->existsProperty("prop1")); - TS_ASSERT(alg->existsProperty("prop2")); - TS_ASSERT(!alg->isRunning()); - alg->setProperty("prop1", "stuff"); - alg->setProperty("prop2", 17); - TS_ASSERT_THROWS_NOTHING(alg->execute()); - TS_ASSERT(alg->isExecuted()); - TS_ASSERT_EQUALS(ExecutionState::Finished, alg->executionState()); - TS_ASSERT_EQUALS(ResultState::Success, alg->resultState()); - int out = alg->getProperty("out"); - TS_ASSERT_EQUALS(out, 28); - } - - void testMultipleCategory() { - IAlgorithm_sptr alg = AlgorithmManager::Instance().create( - "ToyAlgorithmProxyMultipleCategory"); - TS_ASSERT(dynamic_cast<AlgorithmProxy *>(alg.get())); - TS_ASSERT_EQUALS(alg->name(), "ToyAlgorithmProxyMultipleCategory"); - TS_ASSERT_EQUALS(alg->version(), 1); - TS_ASSERT_EQUALS(alg->category(), "ProxyCat;ProxyLeopard"); - std::vector<std::string> result{"ProxyCat", "ProxyLeopard"}; - TS_ASSERT_EQUALS(alg->categories(), result); - TS_ASSERT_EQUALS(alg->alias(), "Dog"); - TS_ASSERT(alg->isInitialized()); - } - - /** - * Disabled due to random failures that cannot be pinned down and are most - * likely timing issues. - * This test has never failed legitimately and only serves to cause confusion - * when it fails - * due to completely unrelated changes. - */ - void xtestRunning() { - IAlgorithm_sptr alg = - AlgorithmManager::Instance().create("ToyAlgorithmProxy"); - TS_ASSERT(dynamic_cast<AlgorithmProxy *>(alg.get())); - alg->setProperty("prop1", "stuff"); - alg->setProperty("prop2", 17); - Poco::ActiveResult<bool> res = alg->executeAsync(); - res.tryWait(60); - TS_ASSERT(alg->isRunning()); - - res.wait(); - TS_ASSERT(res.data()); - TS_ASSERT(alg->isExecuted()); - } - - void testCancel() { - IAlgorithm_sptr alg = - AlgorithmManager::Instance().create("ToyAlgorithmProxy"); - TS_ASSERT(dynamic_cast<AlgorithmProxy *>(alg.get())); - alg->setProperty("prop1", "stuff"); - alg->setProperty("prop2", 17); - Poco::ActiveResult<bool> res = alg->executeAsync(); - res.tryWait(100); - alg->cancel(); - res.wait(); - TS_ASSERT(!alg->isExecuted()); - int out = alg->getProperty("out"); - TS_ASSERT_EQUALS(out, 8); - } - void testAddObserver() { - IAlgorithm_sptr alg = - AlgorithmManager::Instance().create("ToyAlgorithmProxy"); - TS_ASSERT(dynamic_cast<AlgorithmProxy *>(alg.get())); - alg->setProperty("prop1", "stuff"); - alg->setProperty("prop2", 17); - TestProxyObserver obs(alg); - Poco::ActiveResult<bool> res = alg->executeAsync(); - res.wait(); - TS_ASSERT(obs.start); - TS_ASSERT(obs.progress); - TS_ASSERT(obs.finish); - } - - void test_WorkspaceMethodFunctionsReturnProxiedContent() { - IAlgorithm_sptr alg = - AlgorithmManager::Instance().create("ToyAlgorithmProxy"); - - TS_ASSERT_EQUALS("toyalgorithm", alg->workspaceMethodName()); - - auto types = alg->workspaceMethodOn(); - TS_ASSERT_EQUALS(2, types.size()); - if (types.size() == 2) { - TS_ASSERT_EQUALS("MatrixWorkspace", types[0]); - TS_ASSERT_EQUALS("ITableWorkspace", types[1]); - } - TS_ASSERT_EQUALS("InputWorkspace", alg->workspaceMethodInputProperty()); - } - - void test_copyPropertiesFrom() { - IAlgorithm_sptr alg = - AlgorithmManager::Instance().create("ToyAlgorithmProxy"); - alg->initialize(); - alg->setPropertyValue("prop1", "string"); - alg->setPropertyValue("prop2", "1"); - IAlgorithm_sptr algCopy = - AlgorithmManager::Instance().create("ToyAlgorithmProxy"); - - auto algProxy = boost::dynamic_pointer_cast<AlgorithmProxy>(alg); - auto algCopyProxy = boost::dynamic_pointer_cast<AlgorithmProxy>(algCopy); - algCopyProxy->copyPropertiesFrom(*algProxy); - - int val = boost::lexical_cast<int>(algCopy->getPropertyValue("prop2")); - - TS_ASSERT_EQUALS(val, 1); - - // set another value and check the other value is unaffected - algCopy->setPropertyValue("prop1", "A difference"); - int val2 = boost::lexical_cast<int>(algCopy->getPropertyValue("prop2")); - - TS_ASSERT_EQUALS(val, val2); - } -}; diff --git a/Framework/API/test/FrameworkManagerTest.h b/Framework/API/test/FrameworkManagerTest.h index eff6f5b03e97e92c0291d26f314dd063394d7c3d..147acdc945fc92d7bffea2840cf716da74d24576 100644 --- a/Framework/API/test/FrameworkManagerTest.h +++ b/Framework/API/test/FrameworkManagerTest.h @@ -8,38 +8,12 @@ #include <cxxtest/TestSuite.h> -#include "MantidAPI/Algorithm.h" -#include "MantidAPI/AlgorithmFactory.h" #include "MantidAPI/FrameworkManager.h" #include <stdexcept> using namespace Mantid::Kernel; using namespace Mantid::API; -class ToyAlgorithm2 : public Algorithm { -public: - ToyAlgorithm2() {} - ~ToyAlgorithm2() override {} - const std::string name() const override { - return "ToyAlgorithm2"; - }; ///< Algorithm's name for identification - int version() const override { - return 1; - }; ///< Algorithm's version for identification - const std::string summary() const override { return "Test summary"; } - void init() override { - declareProperty("Prop", ""); - declareProperty("P2", ""); - declareProperty("Filename", ""); - } - void exec() override {} - void final() {} -}; - -DECLARE_ALGORITHM(ToyAlgorithm2) - -using namespace Mantid; - class FrameworkManagerTest : public CxxTest::TestSuite { public: // This means the constructor isn't called when running other tests @@ -65,35 +39,6 @@ public: #endif } - void testcreateAlgorithm() { - TS_ASSERT_THROWS_NOTHING( - FrameworkManager::Instance().createAlgorithm("ToyAlgorithm2")) - TS_ASSERT_THROWS( - FrameworkManager::Instance().createAlgorithm("ToyAlgorithm2", "", 3), - const std::runtime_error &) - TS_ASSERT_THROWS(FrameworkManager::Instance().createAlgorithm("aaaaaa"), - const std::runtime_error &) - } - - void testcreateAlgorithmWithProps() { - IAlgorithm *alg = FrameworkManager::Instance().createAlgorithm( - "ToyAlgorithm2", "Prop=Val;P2=V2"); - std::string prop; - TS_ASSERT_THROWS_NOTHING(prop = alg->getPropertyValue("Prop")) - TS_ASSERT(!prop.compare("Val")) - TS_ASSERT_THROWS_NOTHING(prop = alg->getPropertyValue("P2")) - TS_ASSERT(!prop.compare("V2")) - - TS_ASSERT_THROWS_NOTHING( - FrameworkManager::Instance().createAlgorithm("ToyAlgorithm2", "")) - } - - void testExec() { - IAlgorithm *alg = - FrameworkManager::Instance().exec("ToyAlgorithm2", "Prop=Val;P2=V2"); - TS_ASSERT(alg->isExecuted()) - } - void testGetWorkspace() { TS_ASSERT_THROWS(FrameworkManager::Instance().getWorkspace("wrongname"), const std::runtime_error &) diff --git a/Framework/Algorithms/src/RenameWorkspace.cpp b/Framework/Algorithms/src/RenameWorkspace.cpp index 22728788e2d332a3d951ad0aa7e9f00e51be1f7a..46026243dfcf71065b20836113a6375b09283c27 100644 --- a/Framework/Algorithms/src/RenameWorkspace.cpp +++ b/Framework/Algorithms/src/RenameWorkspace.cpp @@ -5,8 +5,8 @@ // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + #include "MantidAlgorithms/RenameWorkspace.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidAPI/WorkspaceHistory.h" @@ -174,8 +174,9 @@ bool RenameWorkspace::processGroups() { suffix << i + 1; std::string wsName = outputwsName + "_" + suffix.str(); - IAlgorithm *alg = API::FrameworkManager::Instance().createAlgorithm( + auto alg = API::AlgorithmManager::Instance().createUnmanaged( this->name(), this->version()); + alg->initialize(); alg->setPropertyValue("InputWorkspace", names[i]); alg->setPropertyValue("OutputWorkspace", wsName); alg->setChild(true); diff --git a/Framework/Algorithms/test/AnyShapeAbsorptionTest.h b/Framework/Algorithms/test/AnyShapeAbsorptionTest.h index 00416e4ad487fde80e1613c6d4b4ea7b5d32e804..dd0f112feb6aad244062ae6d8563f929f66b3716 100644 --- a/Framework/Algorithms/test/AnyShapeAbsorptionTest.h +++ b/Framework/Algorithms/test/AnyShapeAbsorptionTest.h @@ -8,8 +8,8 @@ #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAlgorithms/AnyShapeAbsorption.h" #include "MantidAlgorithms/CylinderAbsorption.h" #include "MantidAlgorithms/FlatPlateAbsorption.h" @@ -17,8 +17,8 @@ #include "MantidTestHelpers/ComponentCreationHelper.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" +using Mantid::API::AlgorithmManager; using Mantid::API::AnalysisDataService; -using Mantid::API::FrameworkManager; using Mantid::API::MatrixWorkspace_sptr; class AnyShapeAbsorptionTest : public CxxTest::TestSuite { @@ -272,7 +272,7 @@ public: // set the sample/can geometry auto setSampleAlg = - FrameworkManager::Instance().createAlgorithm("SetSample"); + AlgorithmManager::Instance().createUnmanaged("SetSample"); setSampleAlg->setRethrows(true); setSampleAlg->initialize(); setSampleAlg->setPropertyValue("InputWorkspace", "bobby"); diff --git a/Framework/Algorithms/test/AppendSpectraTest.h b/Framework/Algorithms/test/AppendSpectraTest.h index 261eb100c1fb797034f42f05e8cd230c4d29ef16..aa98808db23ead7503b8b2ec7539da62dcc18d99 100644 --- a/Framework/Algorithms/test/AppendSpectraTest.h +++ b/Framework/Algorithms/test/AppendSpectraTest.h @@ -6,9 +6,9 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/SpectrumInfo.h" #include "MantidAlgorithms/AppendSpectra.h" #include "MantidDataHandling/LoadRaw3.h" @@ -418,8 +418,7 @@ private: const std::string &inputWorkspace2, const std::string &outputWorkspace) { auto appendSpectra = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "AppendSpectra"); + Mantid::API::AlgorithmManager::Instance().create("AppendSpectra"); TS_ASSERT_THROWS_NOTHING(appendSpectra->setRethrows(true)); TS_ASSERT_THROWS_NOTHING( appendSpectra->setProperty("InputWorkspace1", inputWorkspace1)); @@ -449,8 +448,8 @@ private: dataY.emplace_back(double(i)); } - auto createWS = Mantid::API::FrameworkManager::Instance().createAlgorithm( - "CreateWorkspace"); + auto createWS = + Mantid::API::AlgorithmManager::Instance().create("CreateWorkspace"); TS_ASSERT_THROWS_NOTHING(createWS->setProperty("OutputWorkspace", "we")); TS_ASSERT_THROWS_NOTHING(createWS->setProperty("DataX", dataX)); TS_ASSERT_THROWS_NOTHING(createWS->setProperty("DataY", dataY)); @@ -464,8 +463,7 @@ private: TS_ASSERT_THROWS_NOTHING(createWS->execute()); // we do a rebin so we can have nice bins - auto rebin = - Mantid::API::FrameworkManager::Instance().createAlgorithm("Rebin"); + auto rebin = Mantid::API::AlgorithmManager::Instance().create("Rebin"); TS_ASSERT_THROWS_NOTHING(rebin->setProperty("InputWorkspace", "we")); TS_ASSERT_THROWS_NOTHING( rebin->setProperty("Params", std::vector<double>{1})); diff --git a/Framework/Algorithms/test/CalculateCarpenterSampleCorrectionTest.h b/Framework/Algorithms/test/CalculateCarpenterSampleCorrectionTest.h index 275c8335ae670a041160e937924aca36887e01f1..9d3e5f9c72eacc127e3fb7689bba0af0f349e464 100644 --- a/Framework/Algorithms/test/CalculateCarpenterSampleCorrectionTest.h +++ b/Framework/Algorithms/test/CalculateCarpenterSampleCorrectionTest.h @@ -9,8 +9,8 @@ #include <cxxtest/TestSuite.h> #include <vector> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidAlgorithms/CalculateCarpenterSampleCorrection.h" #include "MantidDataObjects/WorkspaceCreation.h" @@ -85,8 +85,7 @@ public: // convert to wavelength auto convertUnitsAlg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "ConvertUnits"); + Mantid::API::AlgorithmManager::Instance().create("ConvertUnits"); convertUnitsAlg->setPropertyValue("InputWorkspace", "TestInputWS"); convertUnitsAlg->setPropertyValue("OutputWorkspace", "TestInputWS"); convertUnitsAlg->setProperty("Target", "Wavelength"); @@ -141,8 +140,7 @@ public: TS_ASSERT_DELTA(abs_corr_actual[i], abs_corr_expected[i], 0.00001); // Check applying absorption correction - auto divide = - Mantid::API::FrameworkManager::Instance().createAlgorithm("Divide"); + auto divide = Mantid::API::AlgorithmManager::Instance().create("Divide"); divide->initialize(); divide->setPropertyValue("LHSWorkspace", "TestInputWS"); divide->setPropertyValue("RHSWorkspace", absWksp->getName()); @@ -170,7 +168,7 @@ public: // Check applying multiple scattering correction auto multiply = - Mantid::API::FrameworkManager::Instance().createAlgorithm("Multiply"); + Mantid::API::AlgorithmManager::Instance().create("Multiply"); multiply->initialize(); multiply->setPropertyValue("LHSWorkspace", "TestInputWS"); multiply->setPropertyValue("RHSWorkspace", msWksp->getName()); @@ -189,8 +187,7 @@ public: TS_ASSERT_DELTA(ms_ws_actual[i], ms_ws_expected[i], 0.00001); // Check full correction comparison - auto minus = - Mantid::API::FrameworkManager::Instance().createAlgorithm("Minus"); + auto minus = Mantid::API::AlgorithmManager::Instance().create("Minus"); minus->initialize(); minus->setPropertyValue("LHSWorkspace", "TestAbsWS"); minus->setPropertyValue("RHSWorkspace", "TestMultScatWS"); diff --git a/Framework/Algorithms/test/CarpenterSampleCorrectionTest.h b/Framework/Algorithms/test/CarpenterSampleCorrectionTest.h index c0d7c6354b08b5d0ea2a62d86081db13520d28e2..e5650d8801f26476cb22bd1e8cc2c5f2cc394b56 100644 --- a/Framework/Algorithms/test/CarpenterSampleCorrectionTest.h +++ b/Framework/Algorithms/test/CarpenterSampleCorrectionTest.h @@ -9,9 +9,9 @@ #include <cxxtest/TestSuite.h> #include <vector> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAlgorithms/CarpenterSampleCorrection.h" #include "MantidDataObjects/WorkspaceCreation.h" #include "MantidHistogramData/LinearGenerator.h" @@ -78,8 +78,7 @@ public: // convert to wavelength auto convertUnitsAlg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "ConvertUnits"); + Mantid::API::AlgorithmManager::Instance().create("ConvertUnits"); convertUnitsAlg->setPropertyValue("InputWorkspace", "TestInputWS"); convertUnitsAlg->setPropertyValue("OutputWorkspace", "TestInputWS"); convertUnitsAlg->setProperty("Target", "Wavelength"); diff --git a/Framework/Algorithms/test/ConvertUnitsTest.h b/Framework/Algorithms/test/ConvertUnitsTest.h index ca345e3cb59181f7c47f22c8156c30b648183ecc..5ee8fb561b4c4d25ae19e7dd2cf4a2721a05387d 100644 --- a/Framework/Algorithms/test/ConvertUnitsTest.h +++ b/Framework/Algorithms/test/ConvertUnitsTest.h @@ -9,9 +9,9 @@ #include "MantidTestHelpers/WorkspaceCreationHelper.h" #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAlgorithms/ConvertToDistribution.h" #include "MantidAlgorithms/ConvertUnits.h" @@ -838,10 +838,14 @@ public: static void destroySuite(ConvertUnitsTestPerformance *suite) { delete suite; } void setUp() override { - FrameworkManager::Instance().exec( - "Load", "Filename=HET15869;OutputWorkspace=hist_tof"); - FrameworkManager::Instance().exec( - "Load", "Filename=CNCS_7860_event;OutputWorkspace=event_tof"); + auto algo = AlgorithmManager::Instance().create("Load"); + algo->setPropertyValue("Filename", "HET15869"); + algo->setPropertyValue("OutputWorkspace", "hist_tof"); + algo->execute(); + algo = AlgorithmManager::Instance().create("Load"); + algo->setPropertyValue("Filename", "CNCS_7860_event"); + algo->setPropertyValue("OutputWorkspace", "event_tof"); + algo->execute(); std::string WSname = "inputWS"; setup_Points_WS(WSname); } @@ -866,26 +870,32 @@ public: } void test_histogram_workspace() { - IAlgorithm *alg; - alg = FrameworkManager::Instance().exec( - "ConvertUnits", - "InputWorkspace=hist_tof;OutputWorkspace=hist_wave;Target=Wavelength"); + auto alg = AlgorithmManager::Instance().create("ConvertUnits"); + alg->setPropertyValue("InputWorkspace", "hist_tof"); + alg->setPropertyValue("OutputWorkspace", "hist_wave"); + alg->setPropertyValue("Target", "Wavelength"); + alg->execute(); TS_ASSERT(alg->isExecuted()); - alg = FrameworkManager::Instance().exec( - "ConvertUnits", "InputWorkspace=hist_wave;OutputWorkspace=hist_" - "dSpacing;Target=dSpacing"); + alg = AlgorithmManager::Instance().create("ConvertUnits"); + alg->setPropertyValue("InputWorkspace", "hist_tof"); + alg->setPropertyValue("OutputWorkspace", "hist_dSpacing"); + alg->setPropertyValue("Target", "dSpacing"); + alg->execute(); TS_ASSERT(alg->isExecuted()); } void test_event_workspace() { - IAlgorithm *alg; - alg = FrameworkManager::Instance().exec( - "ConvertUnits", "InputWorkspace=event_tof;OutputWorkspace=event_wave;" - "Target=Wavelength"); + auto alg = AlgorithmManager::Instance().create("ConvertUnits"); + alg->setPropertyValue("InputWorkspace", "event_tof"); + alg->setPropertyValue("OutputWorkspace", "event_wave"); + alg->setPropertyValue("Target", "Wavelength"); + alg->execute(); TS_ASSERT(alg->isExecuted()); - alg = FrameworkManager::Instance().exec( - "ConvertUnits", "InputWorkspace=event_wave;OutputWorkspace=event_" - "dSpacing;Target=dSpacing"); + alg = AlgorithmManager::Instance().create("ConvertUnits"); + alg->setPropertyValue("InputWorkspace", "event_tof"); + alg->setPropertyValue("OutputWorkspace", "event_dSpacing"); + alg->setPropertyValue("Target", "dSpacing"); + alg->execute(); TS_ASSERT(alg->isExecuted()); } diff --git a/Framework/Algorithms/test/FFTDerivativeTest.h b/Framework/Algorithms/test/FFTDerivativeTest.h index 721f5f5bb2bbdc8b0e87fbc29b79d193965a709b..4eb3dc8034e0fba69ab05858037484a37c348c74 100644 --- a/Framework/Algorithms/test/FFTDerivativeTest.h +++ b/Framework/Algorithms/test/FFTDerivativeTest.h @@ -8,8 +8,8 @@ #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidAlgorithms/FFTDerivative.h" @@ -25,8 +25,8 @@ public: createWS(N, 0, "exp"); - IAlgorithm *fft = Mantid::API::FrameworkManager::Instance().createAlgorithm( - "FFTDerivative"); + auto fft = + Mantid::API::AlgorithmManager::Instance().create("FFTDerivative"); fft->initialize(); fft->setPropertyValue("InputWorkspace", "FFTDerivative_WS_exp"); fft->setPropertyValue("OutputWorkspace", "FFTDerivative_out"); @@ -45,8 +45,8 @@ public: TS_ASSERT_DELTA(Y[i], (-4 * xx * exp(-(xx * xx) * 2)), 0.000001); } - FrameworkManager::Instance().deleteWorkspace("FFTDerivative_WS_exp"); - FrameworkManager::Instance().deleteWorkspace("FFTDerivative_out"); + AnalysisDataService::Instance().remove("FFTDerivative_WS_exp"); + AnalysisDataService::Instance().remove("FFTDerivative_out"); } void testGaussianSecondOrderDerivative() { @@ -54,8 +54,8 @@ public: createWS(N, 0, "exp"); - IAlgorithm *fft = Mantid::API::FrameworkManager::Instance().createAlgorithm( - "FFTDerivative"); + auto fft = + Mantid::API::AlgorithmManager::Instance().create("FFTDerivative"); fft->initialize(); fft->setPropertyValue("InputWorkspace", "FFTDerivative_WS_exp"); fft->setPropertyValue("OutputWorkspace", "FFTDerivative_out"); @@ -76,13 +76,12 @@ public: TS_ASSERT_DELTA(Y[i], (16 * xx * xx * ex - 4 * ex), 0.000001); } - FrameworkManager::Instance().deleteWorkspace("FFTDerivative_WS_exp"); - FrameworkManager::Instance().deleteWorkspace("FFTDerivative_out"); + AnalysisDataService::Instance().remove("FFTDerivative_WS_exp"); + AnalysisDataService::Instance().remove("FFTDerivative_out"); } private: MatrixWorkspace_sptr createWS(int n, int dn, const std::string &name) { - FrameworkManager::Instance(); Mantid::DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D>( WorkspaceFactory::Instance().create("Workspace2D", 1, n + dn, n)); diff --git a/Framework/Algorithms/test/FFTTest.h b/Framework/Algorithms/test/FFTTest.h index 904716b6be11c5c0dbe7fe5c09f5e9b75ca2a8f6..2d07c3e73e5705ed96dcdcf5a3ca980d3a316ad4 100644 --- a/Framework/Algorithms/test/FFTTest.h +++ b/Framework/Algorithms/test/FFTTest.h @@ -9,9 +9,9 @@ #include <cmath> #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/WorkspaceGroup.h" @@ -51,8 +51,7 @@ public: const auto inputWS = createWS(N, 0); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -88,8 +87,7 @@ public: MatrixWorkspace_sptr inputWS = createWS(N, 0); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -100,7 +98,7 @@ public: MatrixWorkspace_sptr intermediate = fft->getProperty("OutputWorkspace"); TS_ASSERT(intermediate); - fft = Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", intermediate); @@ -131,8 +129,7 @@ public: auto inputWS = createWS(N, 1); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -168,8 +165,7 @@ public: MatrixWorkspace_sptr inWS = createWS(N, 1); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inWS); @@ -180,7 +176,7 @@ public: MatrixWorkspace_sptr intermediate = fft->getProperty("OutputWorkspace"); TS_ASSERT(intermediate); - fft = Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", intermediate); @@ -211,8 +207,7 @@ public: const auto inWS = createWS(N, 0); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inWS); @@ -248,8 +243,7 @@ public: const MatrixWorkspace_sptr inWS = createWS(N, 0); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inWS); @@ -261,7 +255,7 @@ public: fft->getProperty("OutputWorkspace"); TS_ASSERT(intermediate); - fft = Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", intermediate); @@ -292,8 +286,7 @@ public: const auto inWS = createWS(N, 1); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inWS); @@ -329,8 +322,7 @@ public: const MatrixWorkspace_sptr inWS = createWS(N, 1); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inWS); @@ -342,7 +334,7 @@ public: fft->getProperty("OutputWorkspace"); TS_ASSERT(intermediate); - fft = Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", intermediate); @@ -373,8 +365,7 @@ public: const auto realWS = createWS(N, 0); const auto imagWS = createWS(N, 0); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", realWS); @@ -423,8 +414,7 @@ public: inWS->getAxis(0)->unit() = Mantid::Kernel::UnitFactory::Instance().create("Energy"); - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inWS); @@ -462,7 +452,7 @@ public: double aveX = (X[51] + X[49]) / 2.0; X[50] = aveX + 0.01; - auto fft = FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -480,7 +470,7 @@ public: double aveX = (X[51] + X[49]) / 2.0; X[50] = aveX + 0.01; - auto fft = FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -493,7 +483,7 @@ public: // Test that algorithm will not accept an empty input workspace void testEmptyInputWorkspace_Throws() { auto inputWS = createWS(1, 0); - auto fft = FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -504,7 +494,7 @@ public: void testRealOutOfRange_Throws() { auto inputWS = createWS(100, 0); - auto fft = FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -515,7 +505,7 @@ public: void testImaginaryOutOfRange_Throws() { auto inputWS = createWS(100, 0); - auto fft = FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -528,7 +518,7 @@ public: void testRealImaginarySizeMismatch_Throws() { auto inputWS = createWS(100, 0); auto inImagWS = createWS(99, 0); - auto fft = FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -576,7 +566,7 @@ public: auto fftAutoShiftWithOffset = doFFT(offsetWS, false, true); // perform transforms for manual shift - auto fft = FrameworkManager::Instance().createAlgorithm("FFT"); + auto fft = AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setPropertyValue("OutputWorkspace", "__NotUsed"); @@ -719,7 +709,7 @@ public: private: MatrixWorkspace_sptr doRebin(const MatrixWorkspace_sptr &inputWS, const std::string ¶ms) { - auto rebin = FrameworkManager::Instance().createAlgorithm("Rebin"); + auto rebin = AlgorithmManager::Instance().create("Rebin"); rebin->initialize(); rebin->setChild(true); rebin->setProperty("InputWorkspace", inputWS); @@ -729,9 +719,9 @@ private: return rebin->getProperty("OutputWorkspace"); } - MatrixWorkspace_sptr doFFT(const MatrixWorkspace_sptr &inputWS, - const bool complex, const bool phaseShift) { - auto fft = FrameworkManager::Instance().createAlgorithm("FFT"); + MatrixWorkspace_sptr doFFT(MatrixWorkspace_sptr inputWS, const bool complex, + const bool phaseShift) { + auto fft = AlgorithmManager::Instance().create("FFT"); fft->initialize(); fft->setChild(true); fft->setProperty("InputWorkspace", inputWS); @@ -797,14 +787,13 @@ private: } MatrixWorkspace_sptr createWS(int n, int dn, const std::string &name) { - FrameworkManager::Instance(); MatrixWorkspace_sptr ws = createWS(n, dn); AnalysisDataService::Instance().add("FFT_WS_" + name, ws); return ws; } - MatrixWorkspace_sptr offsetWorkspace(const MatrixWorkspace_sptr &workspace) { - auto scaleX = FrameworkManager::Instance().createAlgorithm("ScaleX"); + MatrixWorkspace_sptr offsetWorkspace(MatrixWorkspace_sptr workspace) { + auto scaleX = AlgorithmManager::Instance().create("ScaleX"); scaleX->initialize(); scaleX->setChild(true); scaleX->setProperty("InputWorkspace", workspace); @@ -836,8 +825,7 @@ private: Y.emplace_back(sin(omega * x)); E.emplace_back(0.1); } - auto create = - FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto create = AlgorithmManager::Instance().create("CreateWorkspace"); create->initialize(); create->setChild(true); create->setProperty("DataX", X); @@ -875,8 +863,7 @@ private: Y.emplace_back(y); E.emplace_back(0.1); } - auto create = - FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto create = AlgorithmManager::Instance().create("CreateWorkspace"); create->initialize(); create->setChild(true); create->setProperty("DataX", X); @@ -923,8 +910,7 @@ private: E.emplace_back(0.1); } // create workspace - auto create = - FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto create = AlgorithmManager::Instance().create("CreateWorkspace"); create->initialize(); create->setChild(true); create->setProperty("DataX", X); @@ -938,7 +924,7 @@ private: MatrixWorkspace_sptr doCrop(const MatrixWorkspace_sptr &inputWS, double lower, double higher) { - auto crop = FrameworkManager::Instance().createAlgorithm("CropWorkspace"); + auto crop = AlgorithmManager::Instance().create("CropWorkspace"); crop->initialize(); crop->setChild(true); crop->setProperty("InputWorkspace", inputWS); @@ -970,8 +956,7 @@ private: Y.emplace_back(y); } // create workspace - auto create = - FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto create = AlgorithmManager::Instance().create("CreateWorkspace"); create->initialize(); create->setChild(true); create->setProperty("DataX", X); diff --git a/Framework/Algorithms/test/FitPeaksTest.h b/Framework/Algorithms/test/FitPeaksTest.h index f4849daa7e74041dc0f17b229c559538138714aa..2b67c558fb7d3d0e627c5549ab8479bb6ad3167f 100644 --- a/Framework/Algorithms/test/FitPeaksTest.h +++ b/Framework/Algorithms/test/FitPeaksTest.h @@ -8,6 +8,7 @@ #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" #include "MantidAPI/FrameworkManager.h" @@ -39,12 +40,14 @@ private: public: // This pair of boilerplate methods prevent the suite being created statically // This means the constructor isn't called when running other tests - static FitPeaksTest *createSuite() { - API::FrameworkManager::Instance(); - return new FitPeaksTest(); - } + static FitPeaksTest *createSuite() { return new FitPeaksTest(); } static void destroySuite(FitPeaksTest *suite) { delete suite; } + void setUp() override { + // Needs other algorithms and functions to be registered + FrameworkManager::Instance(); + } + void test_Init() { // Initialize FitPeak FitPeaks fitpeaks; @@ -527,8 +530,7 @@ public: std::string input_ws_name("PG3_733"); // Start by loading our NXS file - IAlgorithm *loader = - Mantid::API::FrameworkManager::Instance().createAlgorithm("LoadNexus"); + auto loader = Mantid::API::AlgorithmManager::Instance().create("LoadNexus"); loader->setPropertyValue("Filename", "PG3_733.nxs"); loader->setPropertyValue("OutputWorkspace", input_ws_name); loader->execute(); @@ -610,8 +612,7 @@ public: std::string input_ws_name("PG3_733"); // Start by loading our NXS file - IAlgorithm *loader = - Mantid::API::FrameworkManager::Instance().createAlgorithm("LoadNexus"); + auto loader = Mantid::API::AlgorithmManager::Instance().create("LoadNexus"); loader->setPropertyValue("Filename", "PG3_733.nxs"); loader->setPropertyValue("OutputWorkspace", input_ws_name); loader->execute(); diff --git a/Framework/Algorithms/test/NormaliseByDetectorTest.h b/Framework/Algorithms/test/NormaliseByDetectorTest.h index be35738086039d1563ae01164aed81b963a18421..179784b71df32de9566bfd3b7c3abc7d43e5a20b 100644 --- a/Framework/Algorithms/test/NormaliseByDetectorTest.h +++ b/Framework/Algorithms/test/NormaliseByDetectorTest.h @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/SpectrumInfo.h" #include "MantidAPI/WorkspaceGroup.h" @@ -48,6 +49,8 @@ without exception producing an output workspace.. MatrixWorkspace_sptr do_test_doesnt_throw_on_execution(const MatrixWorkspace_sptr &inputWS, bool parallel = true) { + // Needs other algorithms and functions to be registered + FrameworkManager::Instance(); NormaliseByDetector alg(parallel); alg.setRethrows(true); alg.initialize(); @@ -75,8 +78,7 @@ private: */ MatrixWorkspace_sptr create_workspace_with_no_fitting_functions() { const std::string outWSName = "test_ws"; - IAlgorithm *workspaceAlg = - FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto workspaceAlg = AlgorithmManager::Instance().create("CreateWorkspace"); workspaceAlg->initialize(); workspaceAlg->setPropertyValue("DataX", "1, 2, 3, 4"); // 4 bins. workspaceAlg->setPropertyValue( @@ -574,8 +576,7 @@ public: void setUp() override { if (!ws) { // Load some data - IAlgorithm *loadalg = - FrameworkManager::Instance().createAlgorithm("Load"); + auto loadalg = AlgorithmManager::Instance().create("Load"); loadalg->setRethrows(true); loadalg->initialize(); loadalg->setPropertyValue("Filename", "POLREF00004699.nxs"); @@ -583,8 +584,7 @@ public: loadalg->execute(); // Convert units to wavelength - IAlgorithm *unitsalg = - FrameworkManager::Instance().createAlgorithm("ConvertUnits"); + auto unitsalg = AlgorithmManager::Instance().create("ConvertUnits"); unitsalg->initialize(); unitsalg->setPropertyValue("InputWorkspace", "testws"); unitsalg->setPropertyValue("OutputWorkspace", "testws"); @@ -592,8 +592,8 @@ public: unitsalg->execute(); // Convert the specturm axis ot signed_theta - IAlgorithm *specaxisalg = - FrameworkManager::Instance().createAlgorithm("ConvertSpectrumAxis"); + auto specaxisalg = + AlgorithmManager::Instance().create("ConvertSpectrumAxis"); specaxisalg->initialize(); specaxisalg->setPropertyValue("InputWorkspace", "testws"); specaxisalg->setPropertyValue("OutputWorkspace", "testws"); diff --git a/Framework/Algorithms/test/PDDetermineCharacterizationsTest.h b/Framework/Algorithms/test/PDDetermineCharacterizationsTest.h index f79748f75c1c2c86c4d1805a37c5486881ffd000..125109dfca3bae785a8bf0622f6948e08fe3db44 100644 --- a/Framework/Algorithms/test/PDDetermineCharacterizationsTest.h +++ b/Framework/Algorithms/test/PDDetermineCharacterizationsTest.h @@ -8,7 +8,7 @@ #include <cxxtest/TestSuite.h> -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/TableRow.h" #include "MantidAPI/WorkspaceFactory.h" @@ -44,8 +44,7 @@ public: m_logWSName = "_det_char_log"; { - auto alg = - FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto alg = AlgorithmManager::Instance().create("CreateWorkspace"); alg->setPropertyValue("DataX", "-1.0,-0.8,-0.6,-0.4,-0.2,0.0,0.2,0.4,0.6,0.8,1.0"); alg->setPropertyValue("DataY", @@ -54,7 +53,7 @@ public: TS_ASSERT(alg->execute()); } { - auto alg = FrameworkManager::Instance().createAlgorithm("AddSampleLog"); + auto alg = AlgorithmManager::Instance().create("AddSampleLog"); alg->setPropertyValue("LogName", "frequency"); alg->setProperty("LogText", frequency); alg->setPropertyValue("LogUnit", "Hz"); @@ -63,7 +62,7 @@ public: TS_ASSERT(alg->execute()); } { - auto alg = FrameworkManager::Instance().createAlgorithm("AddSampleLog"); + auto alg = AlgorithmManager::Instance().create("AddSampleLog"); alg->setPropertyValue("LogName", "LambdaRequest"); alg->setPropertyValue("LogText", wavelength); alg->setPropertyValue("LogUnit", "Angstrom"); @@ -73,7 +72,7 @@ public: } if (!canName.empty()) { - auto alg = FrameworkManager::Instance().createAlgorithm("AddSampleLog"); + auto alg = AlgorithmManager::Instance().create("AddSampleLog"); alg->setPropertyValue("LogName", "SampleContainer"); alg->setPropertyValue("LogText", canName); alg->setPropertyValue("LogType", "String"); diff --git a/Framework/Algorithms/test/PDFFourierTransformTest.h b/Framework/Algorithms/test/PDFFourierTransformTest.h index 8b39d78f74853f5ff1bdf57d557305490824ba06..490a41aa224871bb805c9d734cf569f63b562f5d 100644 --- a/Framework/Algorithms/test/PDFFourierTransformTest.h +++ b/Framework/Algorithms/test/PDFFourierTransformTest.h @@ -6,9 +6,9 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceFactory.h" @@ -35,7 +35,6 @@ Mantid::API::MatrixWorkspace_sptr createWS(size_t n, double dx, const std::string &unitlabel, const bool withBadValues = false) { - Mantid::API::FrameworkManager::Instance(); Mantid::DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D>( Mantid::API::WorkspaceFactory::Instance().create("Workspace2D", 1, n, @@ -100,9 +99,8 @@ public: createWS(20, 0.1, "CheckResult", "MomentumTransfer"); // 1. Run PDFFT - API::IAlgorithm *pdfft = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "PDFFourierTransform"); + auto pdfft = + Mantid::API::AlgorithmManager::Instance().create("PDFFourierTransform"); pdfft->initialize(); pdfft->setProperty("InputWorkspace", ws); @@ -136,9 +134,8 @@ public: createWS(20, 0.1, "CheckNan", "MomentumTransfer", true); // 1. Run PDFFT - API::IAlgorithm *pdfft = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "PDFFourierTransform"); + auto pdfft = + Mantid::API::AlgorithmManager::Instance().create("PDFFourierTransform"); pdfft->initialize(); pdfft->setProperty("InputWorkspace", ws); @@ -175,9 +172,8 @@ public: } // 1. Run PDFFT - API::IAlgorithm *pdfft = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "PDFFourierTransform"); + auto pdfft = + Mantid::API::AlgorithmManager::Instance().create("PDFFourierTransform"); pdfft->initialize(); pdfft->setProperty("InputWorkspace", ws); @@ -218,10 +214,9 @@ public: void setUp() override { ws = createWS(2000000, 0.1, "inputWS", "MomentumTransfer"); - pdfft = Mantid::API::FrameworkManager::Instance().createAlgorithm( - "PDFFourierTransform"); + pdfft = + Mantid::API::AlgorithmManager::Instance().create("PDFFourierTransform"); - pdfft->initialize(); pdfft->setProperty("InputWorkspace", ws); pdfft->setProperty("OutputWorkspace", "outputWS"); pdfft->setProperty("InputSofQType", "S(Q)"); @@ -240,5 +235,5 @@ public: private: Mantid::API::MatrixWorkspace_sptr ws; - API::IAlgorithm *pdfft; + Mantid::API::IAlgorithm_sptr pdfft; }; diff --git a/Framework/Algorithms/test/RealFFTTest.h b/Framework/Algorithms/test/RealFFTTest.h index 1c91c06a9b3c4e44d4ab6d021197f1ec32f91b7b..b043759509a120726134a4a221bf46b2660a6e57 100644 --- a/Framework/Algorithms/test/RealFFTTest.h +++ b/Framework/Algorithms/test/RealFFTTest.h @@ -9,8 +9,8 @@ #include <cmath> #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidAlgorithms/FFT.h" @@ -22,7 +22,6 @@ using namespace Mantid::API; // Anonymous namespace to share methods with Performance test namespace { void setupWorkspaces(int N, double dX) { - FrameworkManager::Instance(); Mantid::DataObjects::Workspace2D_sptr ws = boost::dynamic_pointer_cast<Mantid::DataObjects::Workspace2D>( WorkspaceFactory::Instance().create("Workspace2D", 1, N, N)); @@ -63,15 +62,14 @@ void setupWorkspaces(int N, double dX) { } void deleteWorkspacesFromADS() { - FrameworkManager::Instance().deleteWorkspace("RealFFT_WS"); - FrameworkManager::Instance().deleteWorkspace("RealFFT_WS_hist"); - FrameworkManager::Instance().deleteWorkspace("RealFFT_WS_forward"); - FrameworkManager::Instance().deleteWorkspace("RealFFT_WS_backward"); + AnalysisDataService::Instance().remove("RealFFT_WS"); + AnalysisDataService::Instance().remove("RealFFT_WS_hist"); + AnalysisDataService::Instance().remove("RealFFT_WS_forward"); + AnalysisDataService::Instance().remove("RealFFT_WS_backward"); } void doTestForward(const int N, const double XX, bool performance = false) { - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("RealFFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("RealFFT"); fft->initialize(); fft->setPropertyValue("InputWorkspace", "RealFFT_WS"); fft->setPropertyValue("OutputWorkspace", "RealFFT_WS_forward"); @@ -102,8 +100,7 @@ void doTestForward(const int N, const double XX, bool performance = false) { } void doTestBackward(const int N, const double dX, bool performance = false) { - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("RealFFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("RealFFT"); fft->initialize(); fft->setPropertyValue("InputWorkspace", "RealFFT_WS_forward"); fft->setPropertyValue("OutputWorkspace", "RealFFT_WS_backward"); @@ -131,8 +128,7 @@ void doTestBackward(const int N, const double dX, bool performance = false) { void doTestForwardHistogram(const int N, const double XX, bool performance = false) { - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("RealFFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("RealFFT"); fft->initialize(); fft->setPropertyValue("InputWorkspace", "RealFFT_WS_hist"); fft->setPropertyValue("OutputWorkspace", "RealFFT_WS_forward_hist"); @@ -164,8 +160,7 @@ void doTestForwardHistogram(const int N, const double XX, void doTestBackwardHistogram(const int N, const double dX, bool performance = false) { - IAlgorithm *fft = - Mantid::API::FrameworkManager::Instance().createAlgorithm("RealFFT"); + auto fft = Mantid::API::AlgorithmManager::Instance().create("RealFFT"); fft->initialize(); fft->setPropertyValue("InputWorkspace", "RealFFT_WS_forward_hist"); fft->setPropertyValue("OutputWorkspace", "RealFFT_WS_backward_hist"); diff --git a/Framework/Algorithms/test/ScaleTest.h b/Framework/Algorithms/test/ScaleTest.h index 973f48ebc645eca819f5c1a5bb9843aa42906f0e..e262da95df2f6349e5c93b305d9eb397d625d22c 100644 --- a/Framework/Algorithms/test/ScaleTest.h +++ b/Framework/Algorithms/test/ScaleTest.h @@ -6,7 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAlgorithms/Scale.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" #include <cxxtest/TestSuite.h> @@ -148,8 +148,7 @@ private: } // Act - auto algScale = - Mantid::API::FrameworkManager::Instance().createAlgorithm("Scale"); + auto algScale = Mantid::API::AlgorithmManager::Instance().create("Scale"); algScale->initialize(); algScale->setRethrows(true); algScale->setPropertyValue("InputWorkspace", wsName); diff --git a/Framework/Algorithms/test/SphericalAbsorptionTest.h b/Framework/Algorithms/test/SphericalAbsorptionTest.h index add3c2d2e82bb175d5fc2572d28e71e278f42b6d..b270c6af2286062ef1d0114430cf9a04a2a8dded 100644 --- a/Framework/Algorithms/test/SphericalAbsorptionTest.h +++ b/Framework/Algorithms/test/SphericalAbsorptionTest.h @@ -8,6 +8,7 @@ #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/Axis.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAlgorithms/SphericalAbsorption.h" @@ -23,31 +24,29 @@ using Mantid::API::MatrixWorkspace_sptr; class SphericalAbsorptionTest : public CxxTest::TestSuite { public: void testName() { - IAlgorithm *atten = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SphericalAbsorption"); + auto atten = + Mantid::API::AlgorithmManager::Instance().create("SphericalAbsorption"); TS_ASSERT_EQUALS(atten->name(), "SphericalAbsorption"); } void testVersion() { - IAlgorithm *atten = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SphericalAbsorption"); + auto atten = + Mantid::API::AlgorithmManager::Instance().create("SphericalAbsorption"); TS_ASSERT_EQUALS(atten->version(), 1); } void testInit() { - IAlgorithm *atten = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SphericalAbsorption"); + auto atten = + Mantid::API::AlgorithmManager::Instance().create("SphericalAbsorption"); TS_ASSERT_THROWS_NOTHING(atten->initialize()); TS_ASSERT(atten->isInitialized()); } void testExec() { - IAlgorithm *atten = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SphericalAbsorption"); + // register all the algorithms + FrameworkManager::Instance(); + auto atten = + Mantid::API::AlgorithmManager::Instance().create("SphericalAbsorption"); if (!atten->isInitialized()) atten->initialize(); diff --git a/Framework/Algorithms/test/StripVanadiumPeaks2Test.h b/Framework/Algorithms/test/StripVanadiumPeaks2Test.h index b5bc4e699a34dd1280a1160cf4af75608f28ce70..f85090c4c23c7c950b5cf314230cc94f1660d393 100644 --- a/Framework/Algorithms/test/StripVanadiumPeaks2Test.h +++ b/Framework/Algorithms/test/StripVanadiumPeaks2Test.h @@ -6,9 +6,9 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAlgorithms/StripVanadiumPeaks2.h" #include "MantidDataObjects/WorkspaceCreation.h" #include "MantidKernel/UnitFactory.h" @@ -41,8 +41,7 @@ public: std::string outputWSName("PG3_733_stripped"); // Start by loading our NXS file - IAlgorithm *loader = - Mantid::API::FrameworkManager::Instance().createAlgorithm("LoadNexus"); + auto loader = Mantid::API::AlgorithmManager::Instance().create("LoadNexus"); loader->setPropertyValue("Filename", "PG3_733.nxs"); loader->setPropertyValue("OutputWorkspace", inputWSName); loader->execute(); diff --git a/Framework/Algorithms/test/StripVanadiumPeaksTest.h b/Framework/Algorithms/test/StripVanadiumPeaksTest.h index c8fe9cb02e70048c42c0463657f790accb330296..008aa663cf5c1e54b3527884ee4de731233b9ca8 100644 --- a/Framework/Algorithms/test/StripVanadiumPeaksTest.h +++ b/Framework/Algorithms/test/StripVanadiumPeaksTest.h @@ -6,8 +6,8 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAlgorithms/StripVanadiumPeaks.h" #include "MantidKernel/UnitFactory.h" #include "MantidKernel/VectorHelper.h" @@ -37,8 +37,7 @@ public: std::string outputWSName("PG3_733_stripped"); // Start by loading our NXS file - IAlgorithm *loader = - Mantid::API::FrameworkManager::Instance().createAlgorithm("LoadNexus"); + auto loader = Mantid::API::AlgorithmManager::Instance().create("LoadNexus"); loader->setPropertyValue("Filename", "PG3_733.nxs"); loader->setPropertyValue("OutputWorkspace", inputWSName); loader->execute(); diff --git a/Framework/Crystal/test/FilterPeaksTest.h b/Framework/Crystal/test/FilterPeaksTest.h index 40bcf59a5d2a3a9dc9f141319f852f56fc4aee3e..e9fd0d8bb1b606fba620e238109c87f56e031ac3 100644 --- a/Framework/Crystal/test/FilterPeaksTest.h +++ b/Framework/Crystal/test/FilterPeaksTest.h @@ -8,7 +8,7 @@ #include <cxxtest/TestSuite.h> -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidCrystal/FilterPeaks.h" #include "MantidDataObjects/PeaksWorkspace.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" @@ -337,9 +337,8 @@ public: FilterPeaksTestPerformance() { const std::string outputWorkspace = "TOPAZ_3007.peaks"; - Mantid::API::FrameworkManagerImpl &manager = - Mantid::API::FrameworkManager::Instance(); - auto load = manager.createAlgorithm("LoadIsawPeaks"); + auto &manager = Mantid::API::AlgorithmManager::Instance(); + auto load = manager.create("LoadIsawPeaks"); load->initialize(); load->setProperty("Filename", "TOPAZ_3007.peaks"); load->setPropertyValue("OutputWorkspace", outputWorkspace); diff --git a/Framework/CurveFitting/src/IFittingAlgorithm.cpp b/Framework/CurveFitting/src/IFittingAlgorithm.cpp index 40d38142044ef380514c3a499dedcdeddbcc031d..6645487d7154eba9d9fe8cd1b186960af2589f1e 100644 --- a/Framework/CurveFitting/src/IFittingAlgorithm.cpp +++ b/Framework/CurveFitting/src/IFittingAlgorithm.cpp @@ -364,7 +364,6 @@ IFittingAlgorithm::getCostFunctionInitialized() const { /// Execute the algorithm. void IFittingAlgorithm::exec() { - // This is to make it work with AlgorithmProxy if (!m_domainCreator) { setFunction(); addWorkspaces(); diff --git a/Framework/CurveFitting/test/Algorithms/SplineBackgroundTest.h b/Framework/CurveFitting/test/Algorithms/SplineBackgroundTest.h index 38dcd6b546db218a923fa336b1ee4b715b0017f3..8dad4e319318294d8fd56e0f1fa2d68a7406f1b2 100644 --- a/Framework/CurveFitting/test/Algorithms/SplineBackgroundTest.h +++ b/Framework/CurveFitting/test/Algorithms/SplineBackgroundTest.h @@ -6,9 +6,9 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidCurveFitting/Algorithms/SplineBackground.h" #include "MantidDataObjects/Workspace2D.h" @@ -41,8 +41,8 @@ public: const std::string wsName = "SplineBackground_points"; WorkspaceCreationHelper::storeWS(wsName, ws); - IAlgorithm *alg = Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SplineBackground"); + auto alg = + Mantid::API::AlgorithmManager::Instance().create("SplineBackground"); alg->initialize(); alg->setPropertyValue("InputWorkspace", wsName); alg->setPropertyValue("OutputWorkspace", "SplineBackground_out"); @@ -87,8 +87,7 @@ public: WorkspaceCreationHelper::storeWS(inputWsName, ws); SplineBackgroundAlg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SplineBackground"); + Mantid::API::AlgorithmManager::Instance().create("SplineBackground"); SplineBackgroundAlg->initialize(); SplineBackgroundAlg->setPropertyValue("InputWorkspace", inputWsName); SplineBackgroundAlg->setPropertyValue("OutputWorkspace", outputWsName); @@ -107,7 +106,7 @@ public: } private: - IAlgorithm *SplineBackgroundAlg; + IAlgorithm_sptr SplineBackgroundAlg; Mantid::DataObjects::Workspace2D_sptr ws; const std::string inputWsName = "SplineBackground_points"; diff --git a/Framework/CurveFitting/test/Functions/UserFunction1DTest.h b/Framework/CurveFitting/test/Functions/UserFunction1DTest.h index 50d80af74d7a2ceb5af7836d13b89a8a3dc2a800..0f215137f832ffabfa4a5c687307ecc7e1ad3b9f 100644 --- a/Framework/CurveFitting/test/Functions/UserFunction1DTest.h +++ b/Framework/CurveFitting/test/Functions/UserFunction1DTest.h @@ -8,8 +8,8 @@ #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidCurveFitting/Functions/UserFunction1D.h" @@ -24,8 +24,7 @@ public: void testLinear() { setupWS(); - IAlgorithm *alg = - FrameworkManager::Instance().createAlgorithm("UserFunction1D"); + auto alg = AlgorithmManager::Instance().create("UserFunction1D"); alg->initialize(); alg->setPropertyValue("InputWorkspace", "UserFunction1DWS"); alg->setPropertyValue("WorkspaceIndex", "0"); @@ -44,8 +43,7 @@ public: TS_ASSERT_DELTA(params->Double(1, 1), 2, 0.01); TS_ASSERT_DELTA(params->Double(2, 1), 4, 0.01); - IAlgorithm *alg1 = - FrameworkManager::Instance().createAlgorithm("UserFunction1D"); + auto alg1 = AlgorithmManager::Instance().create("UserFunction1D"); alg1->initialize(); alg1->setPropertyValue("InputWorkspace", "UserFunction1DWS"); alg1->setPropertyValue("WorkspaceIndex", "1"); @@ -64,11 +62,11 @@ public: TS_ASSERT_DELTA(params1->Double(2, 1), 8, 0.01); // Tidy up - FrameworkManager::Instance().deleteWorkspace("UserFunction1DWS"); - FrameworkManager::Instance().deleteWorkspace("UserFunction1D_Parameters"); - FrameworkManager::Instance().deleteWorkspace("UserFunction1D_Workspace"); - FrameworkManager::Instance().deleteWorkspace("UserFunction1D1_Parameters"); - FrameworkManager::Instance().deleteWorkspace("UserFunction1D1_Workspace"); + AnalysisDataService::Instance().remove("UserFunction1DWS"); + AnalysisDataService::Instance().remove("UserFunction1D_Parameters"); + AnalysisDataService::Instance().remove("UserFunction1D_Workspace"); + AnalysisDataService::Instance().remove("UserFunction1D1_Parameters"); + AnalysisDataService::Instance().remove("UserFunction1D1_Workspace"); } private: diff --git a/Framework/DataHandling/test/FindDetectorsParTest.h b/Framework/DataHandling/test/FindDetectorsParTest.h index e2dfa289a2467599865d3370ad1d062b784e646a..7315b8f321a6463eb54a6d9e54684d46ed8df6bc 100644 --- a/Framework/DataHandling/test/FindDetectorsParTest.h +++ b/Framework/DataHandling/test/FindDetectorsParTest.h @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/TableRow.h" #include "MantidDataHandling/FindDetectorsPar.h" @@ -408,7 +409,7 @@ public: // algorithm in this way ensures that function is // executed - findPar = FrameworkManager::Instance().createAlgorithm("FindDetectorsPar"); + findPar = AlgorithmManager::Instance().create("FindDetectorsPar"); } ~FindDetectorsParTest() override { FrameworkManager::Instance().clearAlgorithms(); @@ -416,7 +417,7 @@ public: } private: - IAlgorithm *findPar; + IAlgorithm_sptr findPar; MatrixWorkspace_sptr inputWS; std::vector<Geometry::IDetector_const_sptr> partDetectors; diff --git a/Framework/DataHandling/test/LoadParameterFileTest.h b/Framework/DataHandling/test/LoadParameterFileTest.h index 5ada1ac483d9825ed57ab7bc22716149565cc4d7..80133f549219e1254a4138565f193c95dfd4e673 100644 --- a/Framework/DataHandling/test/LoadParameterFileTest.h +++ b/Framework/DataHandling/test/LoadParameterFileTest.h @@ -9,8 +9,8 @@ #include <cxxtest/TestSuite.h> #include "MantidAPI/Algorithm.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/Workspace.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataObjects/Workspace2D.h" @@ -45,8 +45,7 @@ public: TS_ASSERT_EQUALS(descr, "test fjols description."); // load in additional parameters - auto pLoaderPF = - FrameworkManager::Instance().createAlgorithm("LoadParameterFile"); + auto pLoaderPF = AlgorithmManager::Instance().create("LoadParameterFile"); TS_ASSERT_THROWS_NOTHING(pLoaderPF->initialize()); pLoaderPF->setPropertyValue( @@ -136,8 +135,7 @@ public: "</parameter-file>"; // load in additional parameters - auto pLoaderPF = - FrameworkManager::Instance().createAlgorithm("LoadParameterFile"); + auto pLoaderPF = AlgorithmManager::Instance().create("LoadParameterFile"); TS_ASSERT_THROWS_NOTHING(pLoaderPF->initialize()); pLoaderPF->setPropertyValue("ParameterXML", parameterXML); @@ -200,8 +198,7 @@ public: load_IDF2(); // Run algorithm without file or string properties set - auto pLoaderPF = - FrameworkManager::Instance().createAlgorithm("LoadParameterFile"); + auto pLoaderPF = AlgorithmManager::Instance().create("LoadParameterFile"); TS_ASSERT_THROWS_NOTHING(pLoaderPF->initialize()); pLoaderPF->setPropertyValue("Workspace", wsName); TS_ASSERT_THROWS_NOTHING(pLoaderPF->execute()); @@ -210,7 +207,7 @@ public: void load_IDF2() { auto pLoadInstrument = - FrameworkManager::Instance().createAlgorithm("LoadInstrument"); + AlgorithmManager::Instance().create("LoadInstrument"); TS_ASSERT_THROWS_NOTHING(pLoadInstrument->initialize()); diff --git a/Framework/DataHandling/test/MaskDetectorsInShapeTest.h b/Framework/DataHandling/test/MaskDetectorsInShapeTest.h index c675b30f5b874ce8dccf40e107baf6dd619663f2..7fd5fad8fc4a6cc9a5ecf8d89ea7c821eeef7d30 100644 --- a/Framework/DataHandling/test/MaskDetectorsInShapeTest.h +++ b/Framework/DataHandling/test/MaskDetectorsInShapeTest.h @@ -7,11 +7,10 @@ #pragma once #include <cxxtest/TestSuite.h> - #include <utility> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidDataHandling/LoadEmptyInstrument.h" #include "MantidDataHandling/MaskDetectorsInShape.h" #include "MantidGeometry/Instrument.h" @@ -142,16 +141,14 @@ public: MaskDetectorsInShapeTestPerformance() : workspace("SANS2D") { // Load the instrument alone so as to isolate the raw file loading time from // the instrument loading time - IAlgorithm *loader = - FrameworkManager::Instance().createAlgorithm("LoadEmptyInstrument"); + auto loader = AlgorithmManager::Instance().create("LoadEmptyInstrument"); loader->setPropertyValue("Filename", "SANS2D_Definition.xml"); loader->setPropertyValue("OutputWorkspace", workspace); TS_ASSERT(loader->execute()); } void testMaskingLotsOfDetectors() { - IAlgorithm *masker = - FrameworkManager::Instance().createAlgorithm("MaskDetectorsInShape"); + auto masker = AlgorithmManager::Instance().create("MaskDetectorsInShape"); masker->setPropertyValue("Workspace", workspace); masker->setPropertyValue( "ShapeXML", "<infinite-cylinder id=\"beam_area\"><centre x=\"0\" " diff --git a/Framework/DataHandling/test/SaveDaveGrpTest.h b/Framework/DataHandling/test/SaveDaveGrpTest.h index f3dcf752e3bbe97ef93e7b906a04675049c21d80..ba743330648c14061d9699a7b6087466b797d052 100644 --- a/Framework/DataHandling/test/SaveDaveGrpTest.h +++ b/Framework/DataHandling/test/SaveDaveGrpTest.h @@ -10,8 +10,8 @@ #include "MantidTestHelpers/WorkspaceCreationHelper.h" #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidDataHandling/LoadDaveGrp.h" #include "MantidDataHandling/LoadEventNexus.h" @@ -34,7 +34,7 @@ public: static void destroySuite(SaveDaveGrpTest *suite) { delete suite; } SaveDaveGrpTest() { - saver = FrameworkManager::Instance().createAlgorithm("SaveDaveGrp"); + saver = AlgorithmManager::Instance().create("SaveDaveGrp"); } ~SaveDaveGrpTest() override {} @@ -202,7 +202,6 @@ public: } void test_exec_event() { - Mantid::API::FrameworkManager::Instance(); LoadEventNexus ld; ld.initialize(); std::string outws("CNCS"); @@ -267,7 +266,7 @@ public: } private: - IAlgorithm *saver; + IAlgorithm_sptr saver; MatrixWorkspace_sptr makeWorkspace(const std::string &input) { // all the Y values in this new workspace are set to DEFAU_Y, which diff --git a/Framework/DataHandling/test/SaveNXTomoTest.h b/Framework/DataHandling/test/SaveNXTomoTest.h index 659808195de2a5e019fdece69f9b6d5ba41d25cb..c54c182ed4b2eec474b2abc85a9a5a729e4c7e33 100644 --- a/Framework/DataHandling/test/SaveNXTomoTest.h +++ b/Framework/DataHandling/test/SaveNXTomoTest.h @@ -8,7 +8,7 @@ #include <cxxtest/TestSuite.h> -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidDataHandling/SaveNXTomo.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" @@ -29,56 +29,12 @@ public: m_inputWS = "saveNXTomo_test"; m_outputFile = "SaveNXTomoTestFile.nxs"; m_axisSize = 50; - m_saver = FrameworkManager::Instance().createAlgorithm("SaveNXTomo"); } - void testName() { TS_ASSERT_EQUALS(m_saver->name(), "SaveNXTomo"); } - - void testVersion() { TS_ASSERT_EQUALS(m_saver->version(), 1); } - - void testInit() { - TS_ASSERT_THROWS_NOTHING(m_saver->initialize()); - TS_ASSERT(m_saver->isInitialized()); - } - - void testWriteSingleCreating(bool deleteWhenComplete = true) { - // Test creating a new file from a single WS - // Create a small test workspace - Workspace_sptr input = makeWorkspaceSingle(m_inputWS); - - TS_ASSERT_THROWS_NOTHING( - m_saver->setProperty<Workspace_sptr>("InputWorkspaces", input)); - TS_ASSERT_THROWS_NOTHING( - m_saver->setPropertyValue("Filename", m_outputFile)); - m_outputFile = m_saver->getPropertyValue("Filename"); // get absolute path - - // Set to overwrite to ensure creation not append - TS_ASSERT_THROWS_NOTHING(m_saver->setProperty("OverwriteFile", true)); - TS_ASSERT_THROWS_NOTHING(m_saver->setProperty("IncludeError", false)); - - TS_ASSERT_THROWS_NOTHING(m_saver->execute()); - TS_ASSERT(m_saver->isExecuted()); - - // Check file exists - Poco::File file(m_outputFile); - TS_ASSERT(file.exists()); - - // Check that the structure of the nxTomo file is correct - checkNXTomoStructure(); - - // Check count of entries for data / run_title / rotation_angle / image_key - checkNXTomoDimensions(1); - - // Check rotation values - checkNXTomoRotations(1); - - // Check main data values - checkNXTomoData(1); - - if (deleteWhenComplete) { - if (file.exists()) - file.remove(); - } + void testMetaData() { + auto saver = AlgorithmManager::Instance().create("SaveNXTomo"); + TS_ASSERT_EQUALS(saver->name(), "SaveNXTomo"); + TS_ASSERT_EQUALS(saver->version(), 1); } void testWriteGroupCreating() { @@ -88,18 +44,18 @@ public: WorkspaceGroup_sptr input = makeWorkspacesInGroup(m_inputWS, wspaces); AnalysisDataService::Instance().add(m_inputWS + "0", input); + auto saver = AlgorithmManager::Instance().create("SaveNXTomo"); TS_ASSERT_THROWS_NOTHING( - m_saver->setPropertyValue("InputWorkspaces", input->getName())); - TS_ASSERT_THROWS_NOTHING( - m_saver->setPropertyValue("Filename", m_outputFile)); - m_outputFile = m_saver->getPropertyValue("Filename"); // get absolute path + saver->setPropertyValue("InputWorkspaces", input->getName())); + TS_ASSERT_THROWS_NOTHING(saver->setPropertyValue("Filename", m_outputFile)); + m_outputFile = saver->getPropertyValue("Filename"); // get absolute path // Set to overwrite to ensure creation not append - TS_ASSERT_THROWS_NOTHING(m_saver->setProperty("OverwriteFile", true)); - TS_ASSERT_THROWS_NOTHING(m_saver->setProperty("IncludeError", false)); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("OverwriteFile", true)); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("IncludeError", false)); - TS_ASSERT_THROWS_NOTHING(m_saver->execute()); - TS_ASSERT(m_saver->isExecuted()); + TS_ASSERT_THROWS_NOTHING(saver->execute()); + TS_ASSERT(saver->isExecuted()); // Check file exists Poco::File file(m_outputFile); @@ -122,18 +78,18 @@ public: makeWorkspacesInGroup(wsgName, wspaces, 0, true); AnalysisDataService::Instance().add(wsgName + "0", input); + auto saver = AlgorithmManager::Instance().create("SaveNXTomo"); TS_ASSERT_THROWS_NOTHING( - m_saver->setPropertyValue("InputWorkspaces", input->getName())); - TS_ASSERT_THROWS_NOTHING( - m_saver->setPropertyValue("Filename", m_outputFile)); - m_outputFile = m_saver->getPropertyValue("Filename"); // get absolute path + saver->setPropertyValue("InputWorkspaces", input->getName())); + TS_ASSERT_THROWS_NOTHING(saver->setPropertyValue("Filename", m_outputFile)); + m_outputFile = saver->getPropertyValue("Filename"); // get absolute path // Set to overwrite to ensure creation not append - TS_ASSERT_THROWS_NOTHING(m_saver->setProperty("OverwriteFile", true)); - TS_ASSERT_THROWS_NOTHING(m_saver->setProperty("IncludeError", false)); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("OverwriteFile", true)); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("IncludeError", false)); - TS_ASSERT_THROWS_NOTHING(m_saver->execute()); - TS_ASSERT(m_saver->isExecuted()); + TS_ASSERT_THROWS_NOTHING(saver->execute()); + TS_ASSERT(saver->isExecuted()); // Check file exists Poco::File file(m_outputFile); @@ -149,11 +105,11 @@ public: void testWriteGroupAppending() { // this needs to be called, cxxtest won't run it when it has an argument - testWriteSingleCreating(true); + checkWriteSingleCreating(true); // Run the single workspace test again, without deleting the file at the end // (to test append) - testWriteSingleCreating(false); + checkWriteSingleCreating(false); // Test appending a ws group to an existing file if (Poco::File(m_outputFile).exists()) { @@ -165,18 +121,19 @@ public: AnalysisDataService::Instance().add( m_inputWS + boost::lexical_cast<std::string>(numberOfPriorWS), input); + auto saver = AlgorithmManager::Instance().create("SaveNXTomo"); TS_ASSERT_THROWS_NOTHING( - m_saver->setPropertyValue("InputWorkspaces", input->getName())); + saver->setPropertyValue("InputWorkspaces", input->getName())); TS_ASSERT_THROWS_NOTHING( - m_saver->setPropertyValue("Filename", m_outputFile)); - m_outputFile = m_saver->getPropertyValue("Filename"); // get absolute path + saver->setPropertyValue("Filename", m_outputFile)); + m_outputFile = saver->getPropertyValue("Filename"); // get absolute path // Ensure append not create - TS_ASSERT_THROWS_NOTHING(m_saver->setProperty("OverwriteFile", false)); - TS_ASSERT_THROWS_NOTHING(m_saver->setProperty("IncludeError", false)); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("OverwriteFile", false)); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("IncludeError", false)); - TS_ASSERT_THROWS_NOTHING(m_saver->execute()); - TS_ASSERT(m_saver->isExecuted()); + TS_ASSERT_THROWS_NOTHING(saver->execute()); + TS_ASSERT(saver->isExecuted()); // Check file exists Poco::File file(m_outputFile); @@ -255,6 +212,46 @@ private: return wsGroup; } + void checkWriteSingleCreating(bool deleteWhenComplete = true) { + // Test creating a new file from a single WS + // Create a small test workspace + Workspace_sptr input = makeWorkspaceSingle(m_inputWS); + + auto saver = AlgorithmManager::Instance().create("SaveNXTomo"); + TS_ASSERT_THROWS_NOTHING( + saver->setProperty<Workspace_sptr>("InputWorkspaces", input)); + TS_ASSERT_THROWS_NOTHING(saver->setPropertyValue("Filename", m_outputFile)); + m_outputFile = saver->getPropertyValue("Filename"); // get absolute path + + // Set to overwrite to ensure creation not append + TS_ASSERT_THROWS_NOTHING(saver->setProperty("OverwriteFile", true)); + TS_ASSERT_THROWS_NOTHING(saver->setProperty("IncludeError", false)); + + TS_ASSERT_THROWS_NOTHING(saver->execute()); + TS_ASSERT(saver->isExecuted()); + + // Check file exists + Poco::File file(m_outputFile); + TS_ASSERT(file.exists()); + + // Check that the structure of the nxTomo file is correct + checkNXTomoStructure(); + + // Check count of entries for data / run_title / rotation_angle / image_key + checkNXTomoDimensions(1); + + // Check rotation values + checkNXTomoRotations(1); + + // Check main data values + checkNXTomoData(1); + + if (deleteWhenComplete) { + if (file.exists()) + file.remove(); + } + } + void checkNXTomoStructure() { // Checks the structure of the file - not interested in the data content NXhandle fileHandle; @@ -412,7 +409,6 @@ private: } private: - IAlgorithm *m_saver; std::string m_outputFile; std::string m_inputWS; int m_axisSize; diff --git a/Framework/DataHandling/test/SaveSPETest.h b/Framework/DataHandling/test/SaveSPETest.h index 64ac643edf86974a916ff5fb6372008e6f503797..67f90a5b631fce93e9e6b6beb4cb352431a32bbd 100644 --- a/Framework/DataHandling/test/SaveSPETest.h +++ b/Framework/DataHandling/test/SaveSPETest.h @@ -8,7 +8,7 @@ #include <cxxtest/TestSuite.h> -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/NumericAxis.h" #include "MantidDataHandling/LoadInstrument.h" #include "MantidDataHandling/SaveSPE.h" @@ -45,7 +45,7 @@ public: SaveSPETest() { // the functioning of SaveSPE is affected by a function call // in the FrameworkManager's constructor, creating the // algorithm in this way ensures that function is executed - saver = FrameworkManager::Instance().createAlgorithm("SaveSPE"); + saver = AlgorithmManager::Instance().create("SaveSPE"); } void testName() { TS_ASSERT_EQUALS(saver->name(), "SaveSPE"); } @@ -203,5 +203,5 @@ private: } private: - IAlgorithm *saver; + IAlgorithm_sptr saver; }; diff --git a/Framework/DataHandling/test/SetSampleMaterialTest.h b/Framework/DataHandling/test/SetSampleMaterialTest.h index c197e29c8f4138e2880668fa1793c0ac22e156bf..2f10ba27ae9825680924fe80c520d1b0812a48b9 100644 --- a/Framework/DataHandling/test/SetSampleMaterialTest.h +++ b/Framework/DataHandling/test/SetSampleMaterialTest.h @@ -8,8 +8,8 @@ #include <cxxtest/TestSuite.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/Sample.h" #include "MantidDataHandling/SetSampleMaterial.h" #include "MantidKernel/Material.h" @@ -27,32 +27,24 @@ using Mantid::API::MatrixWorkspace_sptr; class SetSampleMaterialTest : public CxxTest::TestSuite { public: void testName() { - IAlgorithm *setmat = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SetSampleMaterial"); + auto setmat = AlgorithmManager::Instance().create("SetSampleMaterial"); TS_ASSERT_EQUALS(setmat->name(), "SetSampleMaterial"); } void testVersion() { - IAlgorithm *setmat = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SetSampleMaterial"); + auto setmat = AlgorithmManager::Instance().create("SetSampleMaterial"); TS_ASSERT_EQUALS(setmat->version(), 1); } void testInit() { - IAlgorithm *setmat = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SetSampleMaterial"); + auto setmat = AlgorithmManager::Instance().create("SetSampleMaterial"); TS_ASSERT_THROWS_NOTHING(setmat->initialize()); TS_ASSERT(setmat->isInitialized()); } void testExecAl2O3() { std::string wsName = "SetSampleMaterialTestWS"; - IAlgorithm *setmat = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SetSampleMaterial"); + auto setmat = AlgorithmManager::Instance().create("SetSampleMaterial"); if (!setmat->isInitialized()) setmat->initialize(); @@ -93,9 +85,7 @@ public: void testExecAl2O3overrides() { std::string wsName = "SetSampleMaterialTestWS"; - IAlgorithm *setmat = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SetSampleMaterial"); + auto setmat = AlgorithmManager::Instance().create("SetSampleMaterial"); if (!setmat->isInitialized()) setmat->initialize(); @@ -136,9 +126,7 @@ public: void testExecBaTiO3() { std::string wsName = "SetSampleMaterialTestWS"; - IAlgorithm *setmat = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SetSampleMaterial"); + auto setmat = AlgorithmManager::Instance().create("SetSampleMaterial"); if (!setmat->isInitialized()) setmat->initialize(); @@ -180,9 +168,7 @@ public: void testExecMat_Formula() { std::string wsName = "SetSampleMaterialTestWS_formula"; - IAlgorithm *setmat = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SetSampleMaterial"); + auto setmat = AlgorithmManager::Instance().create("SetSampleMaterial"); if (!setmat->isInitialized()) setmat->initialize(); @@ -224,9 +210,7 @@ public: void testExecMat_OneAtom() { std::string wsName = "SetSampleMaterialTestWS_oneatom"; - IAlgorithm *setmat = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "SetSampleMaterial"); + auto setmat = AlgorithmManager::Instance().create("SetSampleMaterial"); if (!setmat->isInitialized()) setmat->initialize(); diff --git a/Framework/LiveData/src/StartLiveData.cpp b/Framework/LiveData/src/StartLiveData.cpp index 76aee617550af2b1d60ed603c47f5a392b6701e8..6da6e8444b78ac598ca092c69068f0d9f2e7cd2b 100644 --- a/Framework/LiveData/src/StartLiveData.cpp +++ b/Framework/LiveData/src/StartLiveData.cpp @@ -7,7 +7,6 @@ #include "MantidLiveData/StartLiveData.h" #include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AlgorithmProperty.h" -#include "MantidAPI/AlgorithmProxy.h" #include "MantidAPI/LiveListenerFactory.h" #include "MantidAPI/Workspace.h" #include "MantidKernel/ArrayBoundedValidator.h" @@ -221,9 +220,9 @@ void StartLiveData::exec() { double UpdateEvery = this->getProperty("UpdateEvery"); if (UpdateEvery > 0) { - // Create the MonitorLiveData but DO NOT make a AlgorithmProxy to it + // Create the MonitorLiveData IAlgorithm_sptr algBase = - AlgorithmManager::Instance().create("MonitorLiveData", -1, false); + AlgorithmManager::Instance().create("MonitorLiveData", -1); auto *monitorAlg = dynamic_cast<MonitorLiveData *>(algBase.get()); if (!monitorAlg) diff --git a/Framework/LiveData/test/KafkaHistoStreamDecoderTest.h b/Framework/LiveData/test/KafkaHistoStreamDecoderTest.h index 3fc38756533dd776dda7b5c80e6e3bb4a843b739..70b2b2cec9610efed8194e6ccd293445bf073411 100644 --- a/Framework/LiveData/test/KafkaHistoStreamDecoderTest.h +++ b/Framework/LiveData/test/KafkaHistoStreamDecoderTest.h @@ -105,38 +105,49 @@ private: void startCapturing(Mantid::LiveData::KafkaHistoStreamDecoder &decoder, uint8_t maxIterations) { // Register callback to know when a whole loop as been iterated through + m_maxIterations = maxIterations; m_niterations = 0; - auto callback = [this, maxIterations]() { - this->iterationCallback(maxIterations); - }; - decoder.registerIterationEndCb(callback); - decoder.registerErrorCb(callback); + decoder.registerIterationEndCb([this]() { this->iterationCallback(); }); + + decoder.registerErrorCb([this, &decoder]() { errCallback(decoder); }); TS_ASSERT_THROWS_NOTHING(decoder.startCapture()); continueCapturing(decoder, maxIterations); } - void iterationCallback(uint8_t maxIterations) { + void iterationCallback() { std::unique_lock<std::mutex> lock(this->m_callbackMutex); this->m_niterations++; - if (this->m_niterations == maxIterations) { + if (this->m_niterations == m_maxIterations) { lock.unlock(); this->m_callbackCondition.notify_one(); } } - void continueCapturing(Mantid::LiveData::KafkaHistoStreamDecoder &decoder, + void errCallback(KafkaHistoStreamDecoder &decoder) { + try { + // Get the stored exception by calling extract data again + decoder.extractData(); + } catch (std::exception &e) { + // We could try to port the exception from this child thread to the main + // thread, or just print it here which is significantly easier + std::cerr << "Exception: " << e.what() << "\n"; + // Always keep incrementing so we don't deadlock + iterationCallback(); + } + } + + void continueCapturing(KafkaHistoStreamDecoder &decoder, uint8_t maxIterations) { + m_maxIterations = maxIterations; + // Re-register callback with the (potentially) new value of maxIterations - auto callback = [this, maxIterations]() { - this->iterationCallback(maxIterations); - }; - decoder.registerIterationEndCb(callback); - decoder.registerErrorCb(callback); + decoder.registerIterationEndCb([this]() { this->iterationCallback(); }); + decoder.registerErrorCb([this, &decoder]() { errCallback(decoder); }); + { std::unique_lock<std::mutex> lk(m_callbackMutex); - this->m_callbackCondition.wait(lk, [this, maxIterations]() { - return this->m_niterations == maxIterations; - }); + this->m_callbackCondition.wait( + lk, [this]() { return this->m_niterations == m_maxIterations; }); } } @@ -183,4 +194,5 @@ private: std::mutex m_callbackMutex; std::condition_variable m_callbackCondition; uint8_t m_niterations = 0; + std::atomic<uint8_t> m_maxIterations = 0; }; diff --git a/Framework/LiveData/test/MonitorLiveDataTest.h b/Framework/LiveData/test/MonitorLiveDataTest.h index 26575e099c00b333a620511a3456c13d28041caf..f154d828109455707024840fa530945ccade14e7 100644 --- a/Framework/LiveData/test/MonitorLiveDataTest.h +++ b/Framework/LiveData/test/MonitorLiveDataTest.h @@ -66,7 +66,7 @@ public: const std::string &RunTransitionBehavior = "Restart", const std::string &UpdateEvery = "1") { auto alg = boost::dynamic_pointer_cast<MonitorLiveData>( - AlgorithmManager::Instance().create("MonitorLiveData", -1, false)); + AlgorithmManager::Instance().create("MonitorLiveData", -1)); alg->setPropertyValue("Instrument", "TestDataListener"); alg->setPropertyValue("UpdateEvery", UpdateEvery); alg->setPropertyValue("AccumulationMethod", AccumulationMethod); diff --git a/Framework/MDAlgorithms/test/ConvertToDiffractionMDWorkspaceTest.h b/Framework/MDAlgorithms/test/ConvertToDiffractionMDWorkspaceTest.h index 3e2d163fa2c5dafc7f1934df9c9175693d8b3996..cafefa0120088fdb986b31248b0aca15a371cd8e 100644 --- a/Framework/MDAlgorithms/test/ConvertToDiffractionMDWorkspaceTest.h +++ b/Framework/MDAlgorithms/test/ConvertToDiffractionMDWorkspaceTest.h @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IAlgorithm.h" #include "MantidDataObjects/EventWorkspace.h" @@ -38,13 +39,13 @@ public: EventWorkspace_sptr in_ws = Mantid::DataObjects::MDEventsTestHelper:: createDiffractionEventWorkspace(10); AnalysisDataService::Instance().addOrReplace("testInEW", in_ws); - IAlgorithm *alg; - alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", - "InputWorkspace=testInEW;" - "OutputWorkspace=testOutMD;" - "OutputDimensions=Q (lab frame)", - 1); + auto alg = AlgorithmManager::Instance().create( + "ConvertToDiffractionMDWorkspace", 1); + alg->setPropertyValue("InputWorkspace", "testInEW"); + alg->setPropertyValue("OutputWorkspace", "testOutMD"); + alg->setPropertyValue("OutputDimensions", "Q (lab frame)"); + alg->execute(); TS_ASSERT(alg->isExecuted()); MDEventWorkspace3Lean::sptr ws; @@ -65,31 +66,34 @@ public: // But you can't add to an existing one of the wrong dimensions type, if you // choose Append - alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", - "InputWorkspace=testInEW;" - "OutputWorkspace=testOutMD;" - "Append=1;" - "OutputDimensions=HKL", - 1); + alg = AlgorithmManager::Instance().create("ConvertToDiffractionMDWorkspace", + 1); + alg->setPropertyValue("InputWorkspace", "testInEW"); + alg->setPropertyValue("OutputWorkspace", "testOutMD"); + alg->setPropertyValue("OutputDimensions", "HKL"); + alg->setPropertyValue("Append", "1"); + alg->execute(); TS_ASSERT(!alg->isExecuted()); // If Append is False, then it does work. The workspace gets replaced - alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", - "InputWorkspace=testInEW;" - "OutputWorkspace=testOutMD;" - "Append=0;" - "OutputDimensions=HKL", - 1); + alg = AlgorithmManager::Instance().create("ConvertToDiffractionMDWorkspace", + 1); + alg->setPropertyValue("InputWorkspace", "testInEW"); + alg->setPropertyValue("OutputWorkspace", "testOutMD"); + alg->setPropertyValue("OutputDimensions", "HKL"); + alg->setPropertyValue("Append", "0"); + alg->execute(); TS_ASSERT(alg->isExecuted()); // Let's remove the old workspace and try again - it will work. AnalysisDataService::Instance().remove("testOutMD"); - alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", - "InputWorkspace=testInEW;" - "OutputWorkspace=testOutMD;" - "Append=1;" - "OutputDimensions=HKL", - 1); + alg = AlgorithmManager::Instance().create("ConvertToDiffractionMDWorkspace", + 1); + alg->setPropertyValue("InputWorkspace", "testInEW"); + alg->setPropertyValue("OutputWorkspace", "testOutMD"); + alg->setPropertyValue("OutputDimensions", "HKL"); + alg->setPropertyValue("Append", "1"); + alg->execute(); TS_ASSERT(alg->isExecuted()); TS_ASSERT_THROWS_NOTHING( @@ -108,11 +112,12 @@ public: } AnalysisDataService::Instance().remove("testOutMD"); - alg = FrameworkManager::Instance().exec("ConvertToDiffractionMDWorkspace", - "InputWorkspace=testInEW;" - "OutputWorkspace=testOutMD;" - "OutputDimensions=Q (sample frame)", - 1); + alg = AlgorithmManager::Instance().create("ConvertToDiffractionMDWorkspace", + 1); + alg->setPropertyValue("InputWorkspace", "testInEW"); + alg->setPropertyValue("OutputWorkspace", "testOutMD"); + alg->setPropertyValue("OutputDimensions", "Q (sample frame)"); + alg->execute(); TS_ASSERT(alg->isExecuted()); TS_ASSERT_THROWS_NOTHING( @@ -131,6 +136,27 @@ public: } } + void test_MINITOPAZ() { do_test_MINITOPAZ(TOF, 100, 400); } + + void test_MINITOPAZ_Weighted() { do_test_MINITOPAZ(WEIGHTED, 100, 400); } + + void test_MINITOPAZ_addToExistingWorkspace() { + do_test_MINITOPAZ(TOF, 100, 400, 2); + } + + void test_MINITOPAZ_OneEventPerBin_fromEventWorkspace() { + do_test_MINITOPAZ(TOF, 100, 400, 1, true, false); + } + + void test_MINITOPAZ_OneEventPerBin_fromWorkspace2D() { + do_test_MINITOPAZ(TOF, 100, 400, 1, true, true); + } + + void test_MINITOPAZ_fromWorkspace2D() { + do_test_MINITOPAZ(TOF, 100, 400, 1, false, true); + } + +private: void do_test_MINITOPAZ(EventType type, int numEventsPer, int numPixels, size_t numTimesToAdd = 1, bool OneEventPerBin = false, bool MakeWorkspace2D = false) { @@ -205,26 +231,6 @@ public: AnalysisDataService::Instance().remove("test_md3"); } - - void test_MINITOPAZ() { do_test_MINITOPAZ(TOF, 100, 400); } - - void test_MINITOPAZ_Weighted() { do_test_MINITOPAZ(WEIGHTED, 100, 400); } - - void test_MINITOPAZ_addToExistingWorkspace() { - do_test_MINITOPAZ(TOF, 100, 400, 2); - } - - void test_MINITOPAZ_OneEventPerBin_fromEventWorkspace() { - do_test_MINITOPAZ(TOF, 100, 400, 1, true, false); - } - - void test_MINITOPAZ_OneEventPerBin_fromWorkspace2D() { - do_test_MINITOPAZ(TOF, 100, 400, 1, true, true); - } - - void test_MINITOPAZ_fromWorkspace2D() { - do_test_MINITOPAZ(TOF, 100, 400, 1, false, true); - } }; class CTDMDWorkspaceTestPerformance : public CxxTest::TestSuite { diff --git a/Framework/MDAlgorithms/test/ConvertToMDComponentsTest.h b/Framework/MDAlgorithms/test/ConvertToMDComponentsTest.h index e6bb76af1e6cea369664ecaa0448f070970afa35..ab570deb471d56b748149c2d79c6cc5fe27a96f8 100644 --- a/Framework/MDAlgorithms/test/ConvertToMDComponentsTest.h +++ b/Framework/MDAlgorithms/test/ConvertToMDComponentsTest.h @@ -7,7 +7,7 @@ #pragma once // tests for different parts of ConvertToMD exec functions -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/SpectrumInfo.h" #include "MantidGeometry/Instrument/Goniometer.h" #include "MantidMDAlgorithms/ConvertToMD.h" @@ -150,8 +150,7 @@ public: AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>( "testWSProcessed"); - auto clVs = Mantid::API::FrameworkManager::Instance().createAlgorithm( - "CloneWorkspace"); + auto clVs = AlgorithmManager::Instance().create("CloneWorkspace"); TS_ASSERT(clVs); if (!clVs) return; @@ -316,8 +315,6 @@ public: ws2D->mutableRun().addProperty("eFixed", 13., "meV", true); AnalysisDataService::Instance().addOrReplace("testWSProcessed", ws2D); - - Mantid::API::FrameworkManager::Instance(); } ~ConvertToMDComponentsTest() override { AnalysisDataService::Instance().remove("testWSProcessed"); diff --git a/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h b/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h index 2446c16225689947d1bcd4bea14850c8af458ca2..91e772b8e6a7e9659b034c5b207339f7ed42a0ca 100644 --- a/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h +++ b/Framework/MDAlgorithms/test/ConvertToQ3DdETest.h @@ -6,7 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/Sample.h" #include "MantidDataObjects/EventWorkspace.h" #include "MantidGeometry/Crystal/OrientedLattice.h" @@ -57,13 +57,12 @@ public: } /** Calculate min-max value defaults*/ - Mantid::API::IAlgorithm * + Mantid::API::IAlgorithm_sptr calcMinMaxValDefaults(const std::string &QMode, const std::string &QFrame, const std::string &OtherProperties = std::string("")) { - Mantid::API::IAlgorithm *childAlg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "ConvertToMDMinMaxLocal"); + auto childAlg = + AlgorithmManager::Instance().create("ConvertToMDMinMaxLocal"); if (!childAlg) { TSM_ASSERT("Can not create child ChildAlgorithm to found min/max values", false); @@ -365,9 +364,7 @@ public: pAlg->initialize(); // initialize (load)Matid algorithm framework -- needed to run this test // separately - Mantid::API::IAlgorithm *childAlg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "ConvertUnits"); + auto childAlg = AlgorithmManager::Instance().create("ConvertUnits"); TSM_ASSERT("Can not initialize Mantid algorithm framework", childAlg); if (!childAlg) { throw(std::runtime_error("Can not initalize/Load MantidAlgorithm dll")); diff --git a/Framework/MDAlgorithms/test/ConvertToReflectometryQTest.h b/Framework/MDAlgorithms/test/ConvertToReflectometryQTest.h index 04378718a13a55837fa7b67064f222fe91814970..60aad0d53227eb6eb86e637c809a10cceed79616 100644 --- a/Framework/MDAlgorithms/test/ConvertToReflectometryQTest.h +++ b/Framework/MDAlgorithms/test/ConvertToReflectometryQTest.h @@ -6,8 +6,8 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IMDEventWorkspace.h" #include "MantidAPI/IMDHistoWorkspace.h" #include "MantidAPI/NumericAxis.h" @@ -79,8 +79,6 @@ public: } static void destroySuite(ConvertToReflectometryQTest *suite) { delete suite; } - void setUp() override { Mantid::API::FrameworkManager::Instance(); } - void test_name() { ConvertToReflectometryQ alg; TS_ASSERT_EQUALS("ConvertToReflectometryQ", alg.name()); @@ -304,7 +302,7 @@ private: public: void setUp() override { // Load some data - IAlgorithm *loadalg = FrameworkManager::Instance().createAlgorithm("Load"); + auto loadalg = AlgorithmManager::Instance().create("Load"); loadalg->setRethrows(true); loadalg->initialize(); loadalg->setPropertyValue("Filename", "POLREF00004699.nxs"); @@ -312,8 +310,7 @@ public: loadalg->execute(); // Convert units to wavelength - IAlgorithm *unitsalg = - FrameworkManager::Instance().createAlgorithm("ConvertUnits"); + auto unitsalg = AlgorithmManager::Instance().create("ConvertUnits"); unitsalg->initialize(); unitsalg->setPropertyValue("InputWorkspace", "testws"); unitsalg->setPropertyValue("OutputWorkspace", "testws"); @@ -321,8 +318,8 @@ public: unitsalg->execute(); // Convert the specturm axis ot signed_theta - IAlgorithm *specaxisalg = - FrameworkManager::Instance().createAlgorithm("ConvertSpectrumAxis"); + auto specaxisalg = + AlgorithmManager::Instance().create("ConvertSpectrumAxis"); specaxisalg->initialize(); specaxisalg->setPropertyValue("InputWorkspace", "testws"); specaxisalg->setPropertyValue("OutputWorkspace", "testws"); diff --git a/Framework/MDAlgorithms/test/CreateMDTest.h b/Framework/MDAlgorithms/test/CreateMDTest.h index ee074eb2c7849fc1fd9ca274b0c40b5a7bfe131d..ea8ab13f51195db99e81ea53451bc5fbd88ae3e3 100644 --- a/Framework/MDAlgorithms/test/CreateMDTest.h +++ b/Framework/MDAlgorithms/test/CreateMDTest.h @@ -250,8 +250,5 @@ public: "__CreateMDTest_mdworkspace"); Mantid::API::AnalysisDataService::Instance().remove( "__CreateMDTest_mdworkspace_fb"); - - if (Poco::File(filename).exists()) - Poco::File(filename).remove(); } }; diff --git a/Framework/MDAlgorithms/test/CutMDTest.h b/Framework/MDAlgorithms/test/CutMDTest.h index cc8cef0d150d7acde449114000a7052bb11cfd8f..0b5f015c366e04c9c4b662554de3f58e8457eaa4 100644 --- a/Framework/MDAlgorithms/test/CutMDTest.h +++ b/Framework/MDAlgorithms/test/CutMDTest.h @@ -11,6 +11,7 @@ #include "../../API/inc/MantidAPI/IMDWorkspace.h" #include "../../Kernel/inc/MantidKernel/MDUnit.h" #include "../inc/MantidMDAlgorithms/CutMD.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IMDEventWorkspace.h" #include "MantidAPI/IMDHistoWorkspace.h" @@ -165,7 +166,7 @@ public: "Dimensions", "3", "Extents", "-10,10,-10,10,-10,10", "Names", "H,K,L", "Units", "U,U,U"); - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", wsName); @@ -182,7 +183,7 @@ public: void test_slice_to_original() { const std::string wsName = "__CutMDTest_slice_to_original"; - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", sharedWSName); @@ -223,7 +224,7 @@ public: void test_recalculate_extents_with_3_bin_arguments() { const std::string wsName = "__CutMDTest_recalc_extents_with_3_bin_args"; - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", sharedWSName); @@ -252,7 +253,7 @@ public: void test_truncate_extents() { const std::string wsName = "__CutMDTest_truncate_extents"; - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", sharedWSName); @@ -304,7 +305,7 @@ public: addNormalization(wsName); - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", wsName); @@ -364,7 +365,7 @@ public: addNormalization(wsName); - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", wsName); @@ -413,7 +414,7 @@ public: addNormalization(wsName); - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", wsName); @@ -460,7 +461,7 @@ public: addNormalization(wsName); - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", wsName); @@ -544,7 +545,7 @@ public: addNormalization(wsName); - auto algCutMD = FrameworkManager::Instance().createAlgorithm("CutMD"); + auto algCutMD = AlgorithmManager::Instance().create("CutMD"); algCutMD->initialize(); algCutMD->setRethrows(true); algCutMD->setProperty("InputWorkspace", wsName); diff --git a/Framework/MDAlgorithms/test/ReplicateMDTest.h b/Framework/MDAlgorithms/test/ReplicateMDTest.h index bfe5a4f1ec8bddb0ac1c63a056fb02d686d8c8fb..f59d3aa357b1cd3c24954267018598517d3bd54b 100644 --- a/Framework/MDAlgorithms/test/ReplicateMDTest.h +++ b/Framework/MDAlgorithms/test/ReplicateMDTest.h @@ -8,7 +8,7 @@ #include <cxxtest/TestSuite.h> -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/IMDHistoWorkspace.h" #include "MantidDataObjects/MDHistoWorkspace.h" @@ -27,8 +27,7 @@ MDHistoWorkspace_sptr makeHistoWorkspace(const std::vector<int> &shape, bool transpose = false, double value = 0.0) { - IAlgorithm *create = - FrameworkManager::Instance().createAlgorithm("CreateMDHistoWorkspace"); + auto create = AlgorithmManager::Instance().create("CreateMDHistoWorkspace"); create->setChild(true); create->initialize(); @@ -86,8 +85,7 @@ MDHistoWorkspace_sptr makeHistoWorkspace(const std::vector<int> &shape, axis = static_cast<int>(op()); } - IAlgorithm *transpose = - FrameworkManager::Instance().createAlgorithm("TransposeMD"); + auto transpose = AlgorithmManager::Instance().create("TransposeMD"); transpose->setChild(true); transpose->initialize(); transpose->setProperty("InputWorkspace", outWs); diff --git a/Framework/MDAlgorithms/test/WeightedMeanMDTest.h b/Framework/MDAlgorithms/test/WeightedMeanMDTest.h index e836ac0fe72261da5d032e3db9aadd4e3b1f89c4..396f05f0f49f85362df939e364d9a2fdfb932a00 100644 --- a/Framework/MDAlgorithms/test/WeightedMeanMDTest.h +++ b/Framework/MDAlgorithms/test/WeightedMeanMDTest.h @@ -6,7 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once -#include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidDataObjects/MDHistoWorkspace.h" #include "MantidMDAlgorithms/WeightedMeanMD.h" @@ -29,8 +29,7 @@ private: const std::string &name) { // Create and run the algorithm AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); - IAlgorithm *alg = - FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto alg = AlgorithmManager::Instance().create("CreateWorkspace"); alg->initialize(); alg->setProperty("NSpec", 1); alg->setProperty("DataY", s); @@ -49,8 +48,7 @@ private: const MatrixWorkspace_sptr &b, const std::string &name) { AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); - IAlgorithm *alg = - FrameworkManager::Instance().createAlgorithm("WeightedMean"); + auto alg = AlgorithmManager::Instance().create("WeightedMean"); alg->setRethrows(true); alg->initialize(); alg->setProperty("InputWorkspace1", a); @@ -183,8 +181,7 @@ public: // Create and run the algorithm AnalysisDataServiceImpl &ADS = Mantid::API::AnalysisDataService::Instance(); - IAlgorithm *alg = - FrameworkManager::Instance().createAlgorithm("CreateMDHistoWorkspace"); + auto alg = AlgorithmManager::Instance().create("CreateMDHistoWorkspace"); alg->initialize(); alg->setProperty("Dimensionality", 1); alg->setProperty("SignalInput", s); diff --git a/Framework/PythonInterface/mantid/api/CMakeLists.txt b/Framework/PythonInterface/mantid/api/CMakeLists.txt index 74819ff88cf7049b44d9e1e8d3f0163c09d04b85..12c4f9e0402d9ad1c34fcd9d1ab34eb0d8236ced 100644 --- a/Framework/PythonInterface/mantid/api/CMakeLists.txt +++ b/Framework/PythonInterface/mantid/api/CMakeLists.txt @@ -8,7 +8,6 @@ set(MODULE_TEMPLATE src/api.cpp.in) set(EXPORT_FILES src/Exports/IAlgorithm.cpp src/Exports/AlgorithmObserver.cpp - src/Exports/AlgorithmProxy.cpp src/Exports/AlgorithmHistory.cpp src/Exports/CatalogManager.cpp src/Exports/CatalogSession.cpp diff --git a/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmProxy.cpp b/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmProxy.cpp deleted file mode 100644 index 51f3f771bf529c9166a82e2871cc50874ac2798c..0000000000000000000000000000000000000000 --- a/Framework/PythonInterface/mantid/api/src/Exports/AlgorithmProxy.cpp +++ /dev/null @@ -1,36 +0,0 @@ -// Mantid Repository : https://github.com/mantidproject/mantid -// -// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI, -// NScD Oak Ridge National Laboratory, European Spallation Source, -// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS -// SPDX - License - Identifier: GPL - 3.0 + -#ifdef _MSC_VER -#pragma warning(disable : 4250) // Disable warning regarding inheritance via - // dominance, we have no way around it with the - // design -#endif -#include "MantidAPI/AlgorithmProxy.h" -#include "MantidPythonInterface/core/GetPointer.h" - -#include <boost/python/class.hpp> -#include <boost/python/register_ptr_to_python.hpp> - -using namespace Mantid::API; -using namespace boost::python; - -GET_POINTER_SPECIALIZATION(AlgorithmProxy) - -void export_algorithm_proxy() { - - register_ptr_to_python<boost::shared_ptr<AlgorithmProxy>>(); - - // We do not require any additional methods here but some parts of the code - // specifically check that a proxy has - // been returned - class_<AlgorithmProxy, bases<IAlgorithm>, boost::noncopyable>( - "AlgorithmProxy", "Proxy class returned by managed algorithms", no_init); -} - -#ifdef _MSC_VER -#pragma warning(default : 4250) -#endif diff --git a/Framework/PythonInterface/test/python/mantid/SimpleAPITest.py b/Framework/PythonInterface/test/python/mantid/SimpleAPITest.py index 06328a0c5a03cc8e1f68fe62ecdcff306737acc7..c9b4db207924db5355c9398629b6df2560f024f0 100644 --- a/Framework/PythonInterface/test/python/mantid/SimpleAPITest.py +++ b/Framework/PythonInterface/test/python/mantid/SimpleAPITest.py @@ -7,7 +7,7 @@ import inspect import unittest -from mantid.api import (AlgorithmFactory, AlgorithmProxy, IAlgorithm, IEventWorkspace, ITableWorkspace, +from mantid.api import (AlgorithmFactory, IAlgorithm, IEventWorkspace, ITableWorkspace, PythonAlgorithm, MatrixWorkspace, mtd) import mantid.simpleapi as simpleapi import numpy @@ -332,12 +332,12 @@ class SimpleAPITest(unittest.TestCase): def test_create_algorithm_object_produces_initialized_non_child_alorithm_outside_PyExec(self): alg = simpleapi._create_algorithm_object("Rebin") - self._is_initialized_test(alg, 1, expected_class=AlgorithmProxy, + self._is_initialized_test(alg, 1, expected_class=IAlgorithm, expected_child=False) def test_create_algorithm_with_version_produces_initialized_alorithm(self): alg = simpleapi._create_algorithm_object("LoadRaw", 3) - self._is_initialized_test(alg, 3, expected_class=AlgorithmProxy, + self._is_initialized_test(alg, 3, expected_class=IAlgorithm, expected_child=False) def test_create_algorithm_produces_child_inside_PyExec(self): diff --git a/Framework/PythonInterface/test/python/mantid/api/AlgorithmManagerTest.py b/Framework/PythonInterface/test/python/mantid/api/AlgorithmManagerTest.py index 666e691de96e155be73ddb3ebdf55e391717db6b..ee9cb6eca761f1750a964e5be8ac140d98afba05 100644 --- a/Framework/PythonInterface/test/python/mantid/api/AlgorithmManagerTest.py +++ b/Framework/PythonInterface/test/python/mantid/api/AlgorithmManagerTest.py @@ -6,7 +6,7 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest import testhelpers -from mantid.api import (AlgorithmManager, Algorithm, AlgorithmProxy, +from mantid.api import (AlgorithmManager, Algorithm, FrameworkManagerImpl, IAlgorithm) @@ -33,10 +33,6 @@ class AlgorithmManagerTest(unittest.TestCase): alg = AlgorithmManager.create("ConvertUnits") self.assertTrue(isinstance(alg, IAlgorithm)) - def test_managed_cppalg_isinstance_of_AlgorithmProxy(self): - alg = AlgorithmManager.create("ConvertUnits") - self.assertTrue(isinstance(alg, AlgorithmProxy)) - def test_unmanaged_cppalg_isinstance_of_Algorithm(self): alg = AlgorithmManager.createUnmanaged("ConvertUnits") self.assertTrue(isinstance(alg, Algorithm)) diff --git a/Framework/PythonInterface/test/python/mantid/api/FrameworkManagerTest.py b/Framework/PythonInterface/test/python/mantid/api/FrameworkManagerTest.py index 31072941983f5083975ec03d5394103eee60f641..3d65835650f7e9ad95afdc5d950447e238d381c7 100644 --- a/Framework/PythonInterface/test/python/mantid/api/FrameworkManagerTest.py +++ b/Framework/PythonInterface/test/python/mantid/api/FrameworkManagerTest.py @@ -6,7 +6,7 @@ # SPDX - License - Identifier: GPL - 3.0 + import unittest import testhelpers -from mantid.api import FrameworkManager, FrameworkManagerImpl, IAlgorithm, AlgorithmProxy +from mantid.api import FrameworkManager, FrameworkManagerImpl, IAlgorithm class FrameworkManagerTest(unittest.TestCase): diff --git a/Framework/PythonInterface/test/python/mantid/api/PythonAlgorithmTraitsTest.py b/Framework/PythonInterface/test/python/mantid/api/PythonAlgorithmTraitsTest.py index 055237ecdf101d2bf64483f1db89ec0be4997d12..c3f6a80ee3925ddfa5a1009cf1f33984a63623eb 100644 --- a/Framework/PythonInterface/test/python/mantid/api/PythonAlgorithmTraitsTest.py +++ b/Framework/PythonInterface/test/python/mantid/api/PythonAlgorithmTraitsTest.py @@ -10,7 +10,7 @@ such as name, version etc. import unittest import testhelpers -from mantid.api import (PythonAlgorithm, AlgorithmProxy, Algorithm, IAlgorithm, +from mantid.api import (PythonAlgorithm, Algorithm, IAlgorithm, AlgorithmManager, AlgorithmFactory) ########################### Test classes ##################################### @@ -88,9 +88,8 @@ class PythonAlgorithmTest(unittest.TestCase): AlgorithmFactory.subscribe(TestPyAlgIsRunningReturnsNonBool) AlgorithmFactory.subscribe(CancellableAlg) - def test_managed_alg_is_descendent_of_AlgorithmProxy(self): + def test_managed_alg_is_descendent_of_IAlgorithm(self): alg = AlgorithmManager.create("TestPyAlgDefaultAttrs") - self.assertTrue(isinstance(alg, AlgorithmProxy)) self.assertTrue(isinstance(alg, IAlgorithm)) def test_unmanaged_alg_is_descendent_of_PythonAlgorithm(self): diff --git a/Framework/TestHelpers/src/BinaryOperationMDTestHelper.cpp b/Framework/TestHelpers/src/BinaryOperationMDTestHelper.cpp index bce53656bb83b9d81c3d0be4fd313c1451eb481e..954f55f5cbc0197853a8c9b4f1089804c68247cf 100644 --- a/Framework/TestHelpers/src/BinaryOperationMDTestHelper.cpp +++ b/Framework/TestHelpers/src/BinaryOperationMDTestHelper.cpp @@ -11,6 +11,7 @@ *********************************************************************************/ #include "MantidTestHelpers/BinaryOperationMDTestHelper.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IMDEventWorkspace.h" #include "MantidDataObjects/MDHistoWorkspace.h" @@ -66,7 +67,7 @@ MDHistoWorkspace_sptr doTest(const std::string &algoName, const std::string &otherPropValue) { setUpBinaryOperationMDTestHelper(); - IAlgorithm *alg = FrameworkManager::Instance().createAlgorithm(algoName); + auto alg = AlgorithmManager::Instance().create(algoName); alg->initialize(); alg->setPropertyValue("LHSWorkspace", lhs); alg->setPropertyValue("RHSWorkspace", rhs); @@ -110,7 +111,7 @@ MDHistoWorkspace_sptr doTest(const std::string &algoName, AnalysisDataService::Instance().addOrReplace("event", event); AnalysisDataService::Instance().addOrReplace("scalar", scalar); - IAlgorithm *alg = FrameworkManager::Instance().createAlgorithm(algoName); + auto alg = AlgorithmManager::Instance().create(algoName); alg->initialize(); alg->setPropertyValue("InputWorkspace", inName); alg->setPropertyValue("OutputWorkspace", outName); diff --git a/docs/source/api/python/mantid/api/AlgorithmProxy.rst b/docs/source/api/python/mantid/api/AlgorithmProxy.rst deleted file mode 100644 index 7fb0355fc010a695cbd27888782afe711c8aa6b2..0000000000000000000000000000000000000000 --- a/docs/source/api/python/mantid/api/AlgorithmProxy.rst +++ /dev/null @@ -1,15 +0,0 @@ -================ - AlgorithmProxy -================ - -This is a Python binding to the C++ class Mantid::API::AlgorithmProxy. - -*bases:* :py:obj:`mantid.api.IAlgorithm` - -.. module:`mantid.api` - -.. autoclass:: mantid.api.AlgorithmProxy - :members: - :undoc-members: - :inherited-members: - diff --git a/docs/source/interfaces/Engineering Diffraction.rst b/docs/source/interfaces/Engineering Diffraction.rst index f25105692a3eb72adc7cf9b9449c3b47fb8a8c0f..dcc2d19d821df54253a7bf29b50ce13760ad82e8 100644 --- a/docs/source/interfaces/Engineering Diffraction.rst +++ b/docs/source/interfaces/Engineering Diffraction.rst @@ -39,10 +39,23 @@ Settings Close Close the interface. +Other Information +^^^^^^^^^^^^^^^^^ + Red Stars Red stars next to browse boxes and other fields indicate that the file could not be found. Hover over the star to see more information. +Status Bar + The status bar shows the calibration run numbers the GUI is currently using. + +Saved File Outputs + The location of files saved by the GUI during processing will be shown in the mantid + messages log. + + *Note*: The locations are shown at "Notice" level, so may not appear if the messages log + is on the incorrect setting. + Calibration ----------- diff --git a/docs/source/release/v5.1.0/diffraction.rst b/docs/source/release/v5.1.0/diffraction.rst index d7a3d7b38b0fa8b0e7854036ff09b67bf9209ea6..8b1ec10c3b76d07df22cc015ec6b5faafc092173 100644 --- a/docs/source/release/v5.1.0/diffraction.rst +++ b/docs/source/release/v5.1.0/diffraction.rst @@ -22,6 +22,8 @@ Improvements ^^^^^^^^^^^^ - TOPAS files (`.abc`) have replaced the `.dat` files generated when focusing using the GUI. - Focusing with the GUI will now generate a CSV containing the averaged values of all numerical sample logs. +- The currently loaded calibration is now shown at the bottom of the GUI. +- The location of the saved output files from the GUI is now shown in the messages log. Single Crystal Diffraction -------------------------- diff --git a/docs/source/release/v5.1.0/mantidworkbench.rst b/docs/source/release/v5.1.0/mantidworkbench.rst index 02ebff51ef367f1598a3d0e9d0ab7b1376588556..8107b1d6ff443e29d2cf3dfa76844468d4f6fabe 100644 --- a/docs/source/release/v5.1.0/mantidworkbench.rst +++ b/docs/source/release/v5.1.0/mantidworkbench.rst @@ -13,6 +13,8 @@ Improvements - The plot selection dialog now correctly shows the full range of valid spectra to plot, not just the min to max range. - Tile plots are now reloaded correctly by project recovery. +- When you stop a script running in workbench it will now automatically attempt to cancel the algorithm the script is running, rather than wait for the current algorthm to end. + This is similar to what Mantidplot does, and should result in the script stopping much sooner. - Fixed an issue where some scripts were running slower if a plot was open at the same time. diff --git a/qt/paraview_ext/VatesAPI/test/MDHWLoadingPresenterTest.h b/qt/paraview_ext/VatesAPI/test/MDHWLoadingPresenterTest.h index 8ea0b36657c1c43430f883c1a834e451c835fd64..34613820caa7a9d9bed65416c28d0355361f16d8 100644 --- a/qt/paraview_ext/VatesAPI/test/MDHWLoadingPresenterTest.h +++ b/qt/paraview_ext/VatesAPI/test/MDHWLoadingPresenterTest.h @@ -12,6 +12,7 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> +#include "MantidAPI/AlgorithmManager.h" #include "MantidDataObjects/MDHistoWorkspace.h" #include "MantidVatesAPI/MDHWLoadingPresenter.h" @@ -207,8 +208,8 @@ public: Mantid::API::IMDHistoWorkspace_sptr makeHistoWorkspace(const std::vector<int> &shape) { - IAlgorithm *create = - FrameworkManager::Instance().createAlgorithm("CreateMDHistoWorkspace"); + auto create = + AlgorithmManager::Instance().createUnmanaged("CreateMDHistoWorkspace"); create->setChild(true); create->initialize(); diff --git a/qt/paraview_ext/VatesAPI/test/MockObjects.h b/qt/paraview_ext/VatesAPI/test/MockObjects.h index 32637dcab1beb33a94d9a87625427a06384a5f25..b96f579a527d4d02a7b2bd7643be11fbc47fc8de 100644 --- a/qt/paraview_ext/VatesAPI/test/MockObjects.h +++ b/qt/paraview_ext/VatesAPI/test/MockObjects.h @@ -6,9 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once -//#include "MantidMDAlgorithms/CreateMDWorkspace.h" #include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IMDIterator.h" #include "MantidAPI/IMDWorkspace.h" #include "MantidAPI/NullCoordTransform.h" @@ -397,8 +395,8 @@ constructXMLForMDEvHelperData(const std::string &xDimensionIdMapping, Mantid::API::Workspace_sptr createSimple3DWorkspace() { using namespace Mantid::API; - IAlgorithm *create = - FrameworkManager::Instance().createAlgorithm("CreateMDWorkspace"); + auto create = + AlgorithmManager::Instance().createUnmanaged("CreateMDWorkspace"); create->setChild(true); create->initialize(); create->setProperty("Dimensions", 4); diff --git a/qt/python/mantidqt/utils/asynchronous.py b/qt/python/mantidqt/utils/asynchronous.py index bdaa790b1ad6c149f06fb878f0ba71efb8be7380..2b1dca15973c8779c200ab937cf4c0571183bb12 100644 --- a/qt/python/mantidqt/utils/asynchronous.py +++ b/qt/python/mantidqt/utils/asynchronous.py @@ -13,7 +13,7 @@ import sys import threading import time from traceback import extract_tb - +from mantid.api import IAlgorithm from enum import Enum @@ -83,6 +83,10 @@ class AsyncTask(threading.Thread): # https://stackoverflow.com/questions/5019436/python-how-to-terminate-a-blocking-thread ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.ident), ctypes.py_object(KeyboardInterrupt)) + #now try and cancel the running algorithm + alg = IAlgorithm._algorithmInThread(self.ident) + if alg is not None: + alg.cancel() time.sleep(0.1) @@ -147,6 +151,10 @@ class BlockingAsyncTaskWithCallback(AsyncTask): # https://stackoverflow.com/questions/5019436/python-how-to-terminate-a-blocking-thread ctypes.pythonapi.PyThreadState_SetAsyncExc(ctypes.c_long(self.task.ident), ctypes.py_object(KeyboardInterrupt)) + #now try and cancel the running algorithm + alg = IAlgorithm._algorithmInThread(self.task.ident) + if alg is not None: + alg.cancel() time.sleep(0.1) diff --git a/qt/scientific_interfaces/Muon/MuonSequentialFitDialog.cpp b/qt/scientific_interfaces/Muon/MuonSequentialFitDialog.cpp index 12bbd3b993f3df84ee1ccd873defa97ad6d5e185..2e79d5507e170d25590f5380e71b427d168ad50b 100644 --- a/qt/scientific_interfaces/Muon/MuonSequentialFitDialog.cpp +++ b/qt/scientific_interfaces/Muon/MuonSequentialFitDialog.cpp @@ -6,7 +6,6 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "MuonSequentialFitDialog.h" -#include "MantidAPI/AlgorithmProxy.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" diff --git a/qt/widgets/common/src/AlgorithmPropertiesWidget.cpp b/qt/widgets/common/src/AlgorithmPropertiesWidget.cpp index ffb6d372ccf23b521b5515fac66b0b6e7549b7c2..2a8ca90fb067bd1ba29a5bfa2bc9a4bac0b66224 100644 --- a/qt/widgets/common/src/AlgorithmPropertiesWidget.cpp +++ b/qt/widgets/common/src/AlgorithmPropertiesWidget.cpp @@ -8,7 +8,6 @@ #include "MantidAPI/Algorithm.h" #include "MantidAPI/AlgorithmManager.h" -#include "MantidAPI/AlgorithmProxy.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/IWorkspaceProperty.h" @@ -30,7 +29,6 @@ using namespace Mantid::Kernel; using Mantid::API::Algorithm_sptr; using Mantid::API::AlgorithmManager; -using Mantid::API::AlgorithmProxy; using Mantid::API::FrameworkManager; using Mantid::API::IWorkspaceProperty; @@ -124,11 +122,10 @@ void AlgorithmPropertiesWidget::setAlgorithmName(QString name) { try { Algorithm_sptr alg = AlgorithmManager::Instance().createUnmanaged(m_algoName.toStdString()); - auto algProxy = boost::make_shared<AlgorithmProxy>(alg); - algProxy->initialize(); + alg->initialize(); // Set the algorithm ptr. This will redo the layout - this->setAlgorithm(algProxy); + this->setAlgorithm(alg); } catch (std::runtime_error &) { } } diff --git a/qt/widgets/common/src/FitPropertyBrowser.cpp b/qt/widgets/common/src/FitPropertyBrowser.cpp index 7d1980f0dd33ffefc2f85bb8d22b7a39e87f9ed2..a7835c400c3bdd993635fdeb9dcb8e1b65ce86b5 100644 --- a/qt/widgets/common/src/FitPropertyBrowser.cpp +++ b/qt/widgets/common/src/FitPropertyBrowser.cpp @@ -718,6 +718,18 @@ FitPropertyBrowser::~FitPropertyBrowser() { using Mantid::API::FunctionFactory; FunctionFactory::Instance().notificationCenter.removeObserver( m_updateObserver); + + m_browser->unsetFactoryForManager(m_enumManager); + m_browser->unsetFactoryForManager(m_boolManager); + m_browser->unsetFactoryForManager(m_intManager); + m_browser->unsetFactoryForManager(m_doubleManager); + m_browser->unsetFactoryForManager(m_stringManager); + m_browser->unsetFactoryForManager(m_filenameManager); + m_browser->unsetFactoryForManager(m_formulaManager); + m_browser->unsetFactoryForManager(m_columnManager); + m_browser->unsetFactoryForManager(m_vectorSizeManager); + m_browser->unsetFactoryForManager(m_vectorDoubleManager); + m_browser->unsetFactoryForManager(m_parameterManager); } /// Get handler to the root composite function diff --git a/qt/widgets/common/test/ConvolutionFunctionModelTest.h b/qt/widgets/common/test/ConvolutionFunctionModelTest.h index 4df5793cbdebd2e536981bec031f17173b0083f6..93d0a50b3fd4ab218543ba6af8163e155ab97108 100644 --- a/qt/widgets/common/test/ConvolutionFunctionModelTest.h +++ b/qt/widgets/common/test/ConvolutionFunctionModelTest.h @@ -6,6 +6,7 @@ // SPDX - License - Identifier: GPL - 3.0 + #pragma once +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/FunctionFactory.h" #include "MantidAPI/IFunction.h" @@ -19,8 +20,8 @@ using namespace Mantid::API; class ConvolutionFunctionModelTest : public CxxTest::TestSuite { public: - ConvolutionFunctionModelTest() { - // To make sure API is initialized properly + void setUp() override { + // Needs other algorithms and functions to be registered FrameworkManager::Instance(); } @@ -205,7 +206,7 @@ public: } void test_resolution_workspace() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -225,7 +226,7 @@ public: } void test_resolution_workspace_index() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -245,7 +246,7 @@ public: } void test_setModel_with_resolution_workspace_list_creates_correct_function() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -273,7 +274,7 @@ public: } void test_setModel_with_delta_function_correct() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -303,8 +304,7 @@ public: } void test_setModel_with_delta_function_TeixeiraWaterSQE_correct() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); - algo->initialize(); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); algo->setPropertyValue("OutputWorkspace", "abc"); @@ -340,7 +340,7 @@ public: } void test_setModel_with_delta_function_TwoLorenztian_correct() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -376,7 +376,7 @@ public: } void test_setModel_with_delta_function_TwoLorenztian_correctWithTemp() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -418,7 +418,7 @@ public: } void test_component_prefixes_set_correctly_without_temp_correction() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -447,7 +447,7 @@ public: } void test_component_prefixes_set_correctly_with_temp_correction() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -476,7 +476,7 @@ public: } void test_component_prefixes_if_only_temp_set() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -499,7 +499,7 @@ public: } void test_component_prefixes_one_lorenzian_temp_set() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); @@ -524,7 +524,7 @@ public: } void test_component_prefixes_if_temp_and_delta_set() { - auto algo = FrameworkManager::Instance().createAlgorithm("CreateWorkspace"); + auto algo = AlgorithmManager::Instance().create("CreateWorkspace"); algo->initialize(); algo->setPropertyValue("DataX", "1,2,3"); algo->setPropertyValue("DataY", "1,2,3"); diff --git a/qt/widgets/instrumentview/src/InstrumentActor.cpp b/qt/widgets/instrumentview/src/InstrumentActor.cpp index b82e897367471665aac3f858cb5f9a8e18518a3e..fe636f30204b4d1d675d8919eef0978923286928 100644 --- a/qt/widgets/instrumentview/src/InstrumentActor.cpp +++ b/qt/widgets/instrumentview/src/InstrumentActor.cpp @@ -11,8 +11,8 @@ #include "MantidQtWidgets/InstrumentView/InstrumentRenderer.h" #include "MantidQtWidgets/InstrumentView/OpenGLError.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/IMaskWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" @@ -268,9 +268,8 @@ void InstrumentActor::invertMaskWorkspace() const { const std::string maskName = "__InstrumentActor_MaskWorkspace_invert"; Mantid::API::AnalysisDataService::Instance().addOrReplace( maskName, getMaskMatrixWorkspace()); - Mantid::API::IAlgorithm *invertAlg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "BinaryOperateMasks", -1); + auto invertAlg = + AlgorithmManager::Instance().create("BinaryOperateMasks", -1); invertAlg->setChild(true); invertAlg->setPropertyValue("InputWorkspace1", maskName); invertAlg->setPropertyValue("OutputWorkspace", maskName); @@ -313,9 +312,7 @@ void InstrumentActor::applyMaskWorkspace() { if (m_maskWorkspace) { // Mask detectors try { - Mantid::API::IAlgorithm *alg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "MaskDetectors", -1); + auto alg = AlgorithmManager::Instance().create("MaskDetectors", -1); alg->setPropertyValue("Workspace", wsName); alg->setProperty("MaskedWorkspace", m_maskWorkspace); alg->execute(); @@ -604,8 +601,7 @@ void InstrumentActor::sumDetectorsRagged(const std::vector<size_t> &dets, try { // rebin all spectra to the same binning - Mantid::API::IAlgorithm *alg = - Mantid::API::FrameworkManager::Instance().createAlgorithm("Rebin", -1); + auto alg = AlgorithmManager::Instance().create("Rebin", -1); alg->setProperty("InputWorkspace", dws); alg->setPropertyValue("OutputWorkspace", outName); alg->setPropertyValue("Params", params); @@ -786,9 +782,7 @@ void InstrumentActor::setAutoscaling(bool on) { */ Mantid::API::MatrixWorkspace_sptr InstrumentActor::extractCurrentMask() const { const std::string maskName = "__InstrumentActor_MaskWorkspace"; - Mantid::API::IAlgorithm *alg = - Mantid::API::FrameworkManager::Instance().createAlgorithm("ExtractMask", - -1); + auto alg = AlgorithmManager::Instance().create("ExtractMask", -1); alg->setPropertyValue("InputWorkspace", getWorkspace()->getName()); alg->setPropertyValue("OutputWorkspace", maskName); alg->setLogging(false); diff --git a/qt/widgets/instrumentview/src/InstrumentWidgetMaskTab.cpp b/qt/widgets/instrumentview/src/InstrumentWidgetMaskTab.cpp index 98261d2e6bb9c0f9003b1bd3b794554e14502a51..8f29e362b3d6c662721e202f11e6b2d27c019860 100644 --- a/qt/widgets/instrumentview/src/InstrumentWidgetMaskTab.cpp +++ b/qt/widgets/instrumentview/src/InstrumentWidgetMaskTab.cpp @@ -69,6 +69,8 @@ #include <fstream> #include <numeric> +using Mantid::API::AlgorithmManager; + namespace MantidQt { namespace MantidWidgets { InstrumentWidgetMaskTab::InstrumentWidgetMaskTab(InstrumentWidget *instrWidget) @@ -679,9 +681,7 @@ InstrumentWidgetMaskTab::createMaskWorkspace(bool invertMask, bool temp) const { Mantid::API::MatrixWorkspace_sptr outputWS; const std::string outputWorkspaceName = generateMaskWorkspaceName(temp); - Mantid::API::IAlgorithm *alg = - Mantid::API::FrameworkManager::Instance().createAlgorithm("ExtractMask", - -1); + auto alg = AlgorithmManager::Instance().create("ExtractMask", -1); alg->setProperty("InputWorkspace", inputWS); alg->setPropertyValue("OutputWorkspace", outputWorkspaceName); alg->execute(); @@ -691,9 +691,8 @@ InstrumentWidgetMaskTab::createMaskWorkspace(bool invertMask, bool temp) const { outputWorkspaceName)); if (invertMask) { - Mantid::API::IAlgorithm *invertAlg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "BinaryOperateMasks", -1); + auto invertAlg = + AlgorithmManager::Instance().create("BinaryOperateMasks", -1); invertAlg->setPropertyValue("InputWorkspace1", outputWorkspaceName); invertAlg->setPropertyValue("OutputWorkspace", outputWorkspaceName); invertAlg->setPropertyValue("OperationType", "NOT"); @@ -745,9 +744,7 @@ void InstrumentWidgetMaskTab::extractDetsToWorkspace() { std::string fname = mapFile(); if (!fname.empty()) { std::string workspaceName = m_instrWidget->getWorkspaceName().toStdString(); - Mantid::API::IAlgorithm *alg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "GroupDetectors"); + auto alg = AlgorithmManager::Instance().create("GroupDetectors"); alg->setPropertyValue("InputWorkspace", workspaceName); alg->setPropertyValue("MapFile", fname); alg->setPropertyValue("OutputWorkspace", workspaceName + "_selection"); @@ -769,9 +766,7 @@ void InstrumentWidgetMaskTab::sumDetsToWorkspace() { if (!fname.empty()) { std::string workspaceName = m_instrWidget->getWorkspaceName().toStdString(); - Mantid::API::IAlgorithm *alg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "GroupDetectors"); + auto alg = AlgorithmManager::Instance().create("GroupDetectors"); alg->setPropertyValue("InputWorkspace", workspaceName); alg->setPropertyValue("MapFile", fname); alg->setPropertyValue("OutputWorkspace", workspaceName + "_sum"); @@ -972,9 +967,7 @@ void InstrumentWidgetMaskTab::saveMaskingToTableWorkspace(bool invertMask) { std::cout << "[DB] MaskTableWorkspace is found? = " << overwrite << ". " << ".\n"; - Mantid::API::IAlgorithm *alg = - Mantid::API::FrameworkManager::Instance().createAlgorithm( - "ExtractMaskToTable", -1); + auto alg = AlgorithmManager::Instance().create("ExtractMaskToTable", -1); alg->setProperty("InputWorkspace", inputWS); if (overwrite) alg->setPropertyValue("MaskTableWorkspace", outputWorkspaceName); diff --git a/qt/widgets/instrumentview/src/InstrumentWidgetPickTab.cpp b/qt/widgets/instrumentview/src/InstrumentWidgetPickTab.cpp index cb6f779798f9a9933274a5fafa18f58e977e0da2..51d499678baa0a0696c8a633434f2548cc565307 100644 --- a/qt/widgets/instrumentview/src/InstrumentWidgetPickTab.cpp +++ b/qt/widgets/instrumentview/src/InstrumentWidgetPickTab.cpp @@ -16,9 +16,9 @@ #include "MantidQtWidgets/InstrumentView/ProjectionSurface.h" #include "MantidQtWidgets/InstrumentView/UnwrappedSurface.h" +#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/Axis.h" -#include "MantidAPI/FrameworkManager.h" #include "MantidAPI/IPeaksWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/Sample.h" @@ -51,6 +51,8 @@ #include <boost/math/constants/constants.hpp> +using Mantid::API::AlgorithmManager; + namespace MantidQt { namespace MantidWidgets { @@ -1810,8 +1812,7 @@ void DetectorPlotController::addPeak(double x, double y) { } // Run the AddPeak algorithm - auto alg = - Mantid::API::FrameworkManager::Instance().createAlgorithm("AddPeak"); + auto alg = AlgorithmManager::Instance().create("AddPeak"); const auto &detIDs = m_instrWidget->getInstrumentActor().detectorInfo().detectorIDs(); alg->setPropertyValue("RunWorkspace", ws->getName()); @@ -1832,8 +1833,7 @@ void DetectorPlotController::addPeak(double x, double y) { // if there is a UB available calculate HKL for the new peak if (tw->sample().hasOrientedLattice()) { - alg = Mantid::API::FrameworkManager::Instance().createAlgorithm( - "CalculatePeaksHKL"); + alg = AlgorithmManager::Instance().create("CalculatePeaksHKL"); alg->setPropertyValue("PeaksWorkspace", peakTableName); alg->execute(); } diff --git a/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py b/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py index 6c71e427b75654f2d919591e6d3d16503778cc9e..be588720e4be061837c89b36ecbeee7f6f79c4ba 100644 --- a/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py +++ b/scripts/Engineering/gui/engineering_diffraction/engineering_diffraction.py @@ -10,6 +10,8 @@ from qtpy import QtCore, QtWidgets from .tabs.calibration.model import CalibrationModel from .tabs.calibration.view import CalibrationView from .tabs.calibration.presenter import CalibrationPresenter +from .tabs.common import CalibrationObserver +from .tabs.common.path_handling import get_run_number_from_path from .tabs.focus.model import FocusModel from .tabs.focus.view import FocusView from .tabs.focus.presenter import FocusPresenter @@ -42,11 +44,16 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window): self.focus_presenter = None self.fitting_presenter = None self.settings_presenter = None + self.calibration_observer = CalibrationObserver(self) self.set_on_help_clicked(self.open_help_window) self.set_on_settings_clicked(self.open_settings) self.btn_settings.setIcon(get_icon("mdi.settings", "black", 1.2)) + # Setup status bar + self.status_label = QtWidgets.QLabel() + self.setup_statusbar() + # Setup Elements self.setup_settings() self.setup_calibration() @@ -96,6 +103,11 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window): def setup_calibration_notifier(self): self.calibration_presenter.calibration_notifier.add_subscriber( self.focus_presenter.calibration_observer) + self.calibration_presenter.calibration_notifier.add_subscriber(self.calibration_observer) + + def setup_statusbar(self): + self.statusbar.addWidget(self.status_label) + self.set_statusbar_text("No Calibration Loaded.") def set_on_help_clicked(self, slot): self.pushButton_help.clicked.connect(slot) @@ -118,3 +130,12 @@ class EngineeringDiffractionGui(QtWidgets.QMainWindow, Ui_main_window): def get_rb_no(self): return self.lineEdit_RBNumber.text() + + def update_calibration(self, calibration): + instrument = calibration.get_instrument() + van_no = get_run_number_from_path(calibration.get_vanadium(), instrument) + sample_no = get_run_number_from_path(calibration.get_sample(), instrument) + self.set_statusbar_text(f"V: {van_no}, CeO2: {sample_no}, Instrument: {instrument}") + + def set_statusbar_text(self, text): + self.status_label.setText(text) diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py index 99fdd6912832c521daa58d347d06fc606290b74a..c24f2deeafe553bf890cada233de58db094a327c 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/calibration/model.py @@ -316,6 +316,7 @@ class CalibrationModel(object): elif bank is None: # Custom cropped files use the north bank template. north_kwargs() generate_output_file([difa[0]], [difc[0]], [tzero[0]], "cropped", kwargs) + logger.notice(f"\n\nCalibration files saved to: \"{calibration_dir}\"\n\n") @staticmethod def get_info_from_file(file_path): diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/common/__init__.py b/scripts/Engineering/gui/engineering_diffraction/tabs/common/__init__.py index 560e8d35de7f60635faf6ebe1b8d6c30e40696f9..1c7fba2c733edbf6ca0b01284c7cc626784c83c3 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/common/__init__.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/common/__init__.py @@ -8,6 +8,7 @@ Holds some common constants across all tabs. """ from qtpy.QtWidgets import QMessageBox +from mantidqt.utils.observer_pattern import Observer # Dictionary of indexes for instruments. INSTRUMENT_DICT = {0: "ENGINX", 1: "IMAT"} @@ -15,3 +16,12 @@ INSTRUMENT_DICT = {0: "ENGINX", 1: "IMAT"} def create_error_message(parent, message): QMessageBox.warning(parent, "Engineering Diffraction - Error", str(message)) + + +class CalibrationObserver(Observer): + def __init__(self, outer): + Observer.__init__(self) + self.outer = outer + + def update(self, observable, calibration): + self.outer.update_calibration(calibration) diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py index 7018f1bf99c6d4a0e07821537979dbaff2ef833a..84f96df3116cbc9e37687aad6c1fd72abcacb542 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/model.py @@ -129,6 +129,10 @@ class FocusModel(object): rb_num) self._save_focused_output_files_as_topas_xye(instrument, sample_path, bank, sample_workspace, rb_num) + logger.notice(f"\n\nFocus files saved to: \"{path.join(path_handling.get_output_path(), 'Focus')}\"\n\n") + if rb_num: + output_path = path.join(path_handling.get_output_path(), 'User', rb_num, 'Focus') + logger.notice(f"\n\nFocus files saved to: \"{output_path}\"\n\n") def _save_focused_output_files_as_gss(self, instrument, sample_path, bank, sample_workspace, rb_num): diff --git a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py index b4d8a8c8290eb2f67b998a85963e7eb054583807..c448ae8ff1d7dfa447464498583cef737a6fc685 100644 --- a/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py +++ b/scripts/Engineering/gui/engineering_diffraction/tabs/focus/presenter.py @@ -5,12 +5,12 @@ # Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS # SPDX - License - Identifier: GPL - 3.0 + # pylint: disable=invalid-name -from Engineering.gui.engineering_diffraction.tabs.common import INSTRUMENT_DICT, create_error_message +from Engineering.gui.engineering_diffraction.tabs.common import INSTRUMENT_DICT, create_error_message, \ + CalibrationObserver from Engineering.gui.engineering_diffraction.tabs.common.calibration_info import CalibrationInfo from Engineering.gui.engineering_diffraction.tabs.common.vanadium_corrections import check_workspaces_exist from Engineering.gui.engineering_diffraction.tabs.common.cropping.cropping_widget import CroppingWidget from mantidqt.utils.asynchronous import AsyncTask -from mantidqt.utils.observer_pattern import Observer from qtpy.QtWidgets import QMessageBox @@ -20,7 +20,7 @@ class FocusPresenter(object): self.model = model self.view = view self.worker = None - self.calibration_observer = self.CalibrationObserver(self) + self.calibration_observer = CalibrationObserver(self) # Connect view signals to local methods. self.view.set_on_focus_clicked(self.on_focus_clicked) @@ -132,14 +132,3 @@ class FocusPresenter(object): def show_cropping(self, visible): self.view.set_cropping_widget_visibility(visible) - - # ----------------------- - # Observers / Observables - # ----------------------- - class CalibrationObserver(Observer): - def __init__(self, outer): - Observer.__init__(self) - self.outer = outer - - def update(self, observable, calibration): - self.outer.update_calibration(calibration) diff --git a/scripts/PyChop/maps.yaml b/scripts/PyChop/maps.yaml index 90a5bebdede26f0d41d0c0c06fc439c546fbc306..715e780742ed83d22a527d93623028b3d0933860 100644 --- a/scripts/PyChop/maps.yaml +++ b/scripts/PyChop/maps.yaml @@ -3,7 +3,7 @@ name: MAPS chopper_system: name: MAPS chopper system - chop_sam: 1.9 # Distance (x1) from final chopper to sample (m) + chop_sam: 1.899 # Distance (x1) from final chopper to sample (m) sam_det: 6.0 # Distance (x2) from sample to detector (m) aperture_width: 0.094 # Width of aperture at moderator face (m) aperture_height: 0.094 # Height of aperture at moderator face (m) @@ -26,7 +26,7 @@ chopper_system: phaseName: 'Multirep mode number' - name: MAPS Fermi - distance: 10.1 # Distance from moderator to this chopper in metres + distance: 10.143 # Distance from moderator to this chopper in metres aperture_distance: 8.27 # Distance from aperture (moderator face) to this chopper (only for Fermi) packages: # A hash of chopper packages A: diff --git a/scripts/reduction/reducer.py b/scripts/reduction/reducer.py index 76c7527a1948ec23ce098957a93fc49a1010d0cf..d86734fa73a7a52f2d35723f5bfc0d18b6507366 100644 --- a/scripts/reduction/reducer.py +++ b/scripts/reduction/reducer.py @@ -89,7 +89,7 @@ def validate_loader(func): # noqa data_file = self._data_file alg = mantid.api.AlgorithmManager.create(algorithm) - if not isinstance(alg, mantid.api.AlgorithmProxy): + if not isinstance(alg, mantid.api.IAlgorithm): raise RuntimeError("Reducer expects an Algorithm object from FrameworkManager, found '%s'" % str( type(alg))) @@ -241,7 +241,7 @@ def validate_step(func): # noqa if outputworkspace is None: outputworkspace = inputworkspace alg = mantid.AlgorithmManager.create(algorithm) - if not isinstance(alg, mantid.api.AlgorithmProxy): + if not isinstance(alg, mantid.api.IAlgorithm): raise RuntimeError("Reducer expects an Algorithm object from FrameworkManager, found '%s'" % str( type(alg))) diff --git a/scripts/test/PyChopTest.py b/scripts/test/PyChopTest.py index b0f9f98604b2d70dcbdf37ece5d6f6f2fd3f2dca..3557e4fa86ee76d848e8a0464791c4bb8830aebf 100644 --- a/scripts/test/PyChopTest.py +++ b/scripts/test/PyChopTest.py @@ -34,10 +34,11 @@ class PyChop2Tests(unittest.TestCase): self.assertGreater(flux[2], flux[1]) # Note that MAPS has been upgraded so now should have higher flux than MARI. self.assertGreater(flux[0], flux[1]) - # Checks that the resolution should be best for MARI, MAPS, and MERLIN in that order - # actually MAPS and MARI resolutions are very close - self.assertLess(res[1][0], res[0][0]) - self.assertLess(res[0][0], res[2][0]) + # Checks that the resolution should be best for MAPS, MARI, and MERLIN in that order + # actually MAPS and MARI resolutions are very close (previous error in MAPS distances + # meant that MARI was calculated to have a better resolution, but it *should* be MAPS) + self.assertLess(res[0][0], res[1][0]) + self.assertLess(res[1][0], res[2][0]) # Now tests the standalone function for inc, instname in enumerate(instnames): rr, ff = PyChop2.calculate(instname, 's', 200, 18, 0)