Skip to content

Commit

Permalink
Work in progress - run all algorithms on an ActiveMethod
Browse files Browse the repository at this point in the history
Refs #10092
  • Loading branch information
DanNixon committed Aug 18, 2014
1 parent 4be794b commit da71d31
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 373 deletions.
3 changes: 0 additions & 3 deletions Code/Mantid/MantidQt/API/CMakeLists.txt
@@ -1,5 +1,4 @@
set ( SRC_FILES
src/AbstractAsyncAlgorithmRunner.cpp
src/AlgorithmDialog.cpp
src/AlgorithmInputHistory.cpp
src/AlgorithmPropertiesWidget.cpp
Expand Down Expand Up @@ -39,7 +38,6 @@ set ( SRC_FILES
)

set ( MOC_FILES
inc/MantidQtAPI/AbstractAsyncAlgorithmRunner.h
inc/MantidQtAPI/AlgorithmDialog.h
inc/MantidQtAPI/AlgorithmRunner.h
inc/MantidQtAPI/AlgorithmPropertiesWidget.h
Expand Down Expand Up @@ -69,7 +67,6 @@ set ( MOC_FILES
# Include files aren't required, but this makes them appear in Visual Studio
set ( INC_FILES
${MOC_FILES}
inc/MantidQtAPI/AbstractAsyncAlgorithmRunner.h
inc/MantidQtAPI/AlgorithmInputHistory.h
inc/MantidQtAPI/AlgorithmRunner.h
inc/MantidQtAPI/BatchAlgorithmRunner.h
Expand Down

This file was deleted.

27 changes: 19 additions & 8 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/AlgorithmRunner.h
@@ -1,8 +1,6 @@
#ifndef MANTID_API_ALGORITHMRUNNER_H_
#define MANTID_API_ALGORITHMRUNNER_H_

#include "MantidQtAPI/AbstractAsyncAlgorithmRunner.h"

#include "DllOption.h"
#include "MantidAPI/Algorithm.h"

Expand All @@ -13,7 +11,6 @@ namespace MantidQt
{
namespace API
{

/** The AlgorithmRunner is a QObject that encapsulates
* methods for running an algorithm asynchronously (in the background)
* and feeds-back to a GUI widget.
Expand Down Expand Up @@ -49,7 +46,7 @@ namespace API
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class EXPORT_OPT_MANTIDQT_API AlgorithmRunner : public AbstractAsyncAlgorithmRunner
class EXPORT_OPT_MANTIDQT_API AlgorithmRunner : public QObject
{
Q_OBJECT

Expand All @@ -67,15 +64,29 @@ namespace API
void algorithmComplete(bool error);

/// Signal emitted when the algorithm reports progress
void algorithmProgress(double p,const std::string& msg);
void algorithmProgress(double p, const std::string& msg);

protected:
void handleAlgorithmFinish();
void handleAlgorithmProgress(double p, const std::string msg);
void handleAlgorithmError();

/// Algorithm notification handlers
void handleAlgorithmFinishedNotification(const Poco::AutoPtr<Mantid::API::Algorithm::FinishedNotification>& pNf);
Poco::NObserver<AlgorithmRunner, Mantid::API::Algorithm::FinishedNotification> m_finishedObserver;

void handleAlgorithmProgressNotification(const Poco::AutoPtr<Mantid::API::Algorithm::ProgressNotification>& pNf);
Poco::NObserver<AlgorithmRunner, Mantid::API::Algorithm::ProgressNotification> m_progressObserver;

void handleAlgorithmErrorNotification(const Poco::AutoPtr<Mantid::API::Algorithm::ErrorNotification>& pNf);
Poco::NObserver<AlgorithmRunner, Mantid::API::Algorithm::ErrorNotification> m_errorObserver;

/// For the asynchronous call in dynamic rebinning. Holds the result of asyncExecute() algorithm call
Poco::ActiveResult<bool> * m_asyncResult;

/// Reference to the algorithm executing asynchronously.
Mantid::API::IAlgorithm_sptr m_asyncAlg;

};


} // namespace API
} // namespace Mantid

Expand Down
50 changes: 38 additions & 12 deletions Code/Mantid/MantidQt/API/inc/MantidQtAPI/BatchAlgorithmRunner.h
@@ -1,13 +1,16 @@
#ifndef MANTID_API_BATCHALGORITHMRUNNER_H_
#define MANTID_API_BATCHALGORITHMRUNNER_H_

#include "MantidQtAPI/AbstractAsyncAlgorithmRunner.h"

#include "DllOption.h"
#include "MantidAPI/Algorithm.h"

#include <QObject>

#include <Poco/ActiveMethod.h>
#include <Poco/ActiveResult.h>
#include <Poco/NObserver.h>
#include <Poco/Void.h>

namespace MantidQt
{
namespace API
Expand Down Expand Up @@ -38,7 +41,21 @@ namespace API
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/

class EXPORT_OPT_MANTIDQT_API BatchAlgorithmRunner : public AbstractAsyncAlgorithmRunner
class BatchNotification : public Poco::Notification
{
public:
BatchNotification(bool inProgress, bool error) : Poco::Notification(),
m_inProgress(inProgress), m_error(error) {}

bool isInProgress() const { return m_inProgress; }
bool hasError() const { return m_error; }

private:
bool m_inProgress;
bool m_error;
};

class EXPORT_OPT_MANTIDQT_API BatchAlgorithmRunner : public QObject
{
Q_OBJECT

Expand All @@ -49,28 +66,37 @@ namespace API
explicit BatchAlgorithmRunner(QObject * parent = 0);
virtual ~BatchAlgorithmRunner();

void cancelAll();
void addAlgorithm(Mantid::API::IAlgorithm_sptr algo, AlgorithmRuntimeProps props = AlgorithmRuntimeProps());

void startBatch(bool stopOnFailure = true);
bool isExecuting();
bool executeBatch();
void executeBatchAsync();

void stopOnFailure(bool stopOnFailure);

signals:
void batchComplete(bool error);
void batchProgress(double p, const std::string& currentAlg, const std::string& algMsg);

private:
void startNextAlgo();
Mantid::API::IAlgorithm_sptr getCurrentAlgorithm();
Poco::NotificationCenter & notificationCenter() const;

Poco::ActiveResult<bool> executeAsync();
bool executeBatchAsyncImpl(const Poco::Void&);

bool startAlgo(ConfiguredAlgorithm algorithm);

std::deque<ConfiguredAlgorithm> m_algorithms;
size_t m_batchSize;

Mantid::API::IAlgorithm_sptr m_currentAlgorithm;

bool m_stopOnFailure;
bool m_isExecuting;

void handleAlgorithmFinish();
void handleAlgorithmProgress(double p, const std::string msg);
void handleAlgorithmError();
Poco::ActiveMethod<bool, Poco::Void, BatchAlgorithmRunner, Poco::ActiveStarter<BatchAlgorithmRunner>> m_executeAsync;
mutable Poco::NotificationCenter *m_notificationCenter;

void handleNotification(const Poco::AutoPtr<BatchNotification>& pNf);
Poco::NObserver<BatchAlgorithmRunner, BatchNotification> m_notificationObserver;
};

} // namespace API
Expand Down
136 changes: 0 additions & 136 deletions Code/Mantid/MantidQt/API/src/AbstractAsyncAlgorithmRunner.cpp

This file was deleted.

0 comments on commit da71d31

Please sign in to comment.