Mantid
Loading...
Searching...
No Matches
Signals | Public Member Functions | Private Member Functions | Private Attributes | List of all members
MantidQt::API::BatchAlgorithmRunner Class Reference

Algorithm runner for execution of a queue of algorithms. More...

#include <BatchAlgorithmRunner.h>

Inheritance diagram for MantidQt::API::BatchAlgorithmRunner:

Signals

void algorithmComplete (MantidQt::API::IConfiguredAlgorithm_sptr algorithm)
 
void algorithmError (MantidQt::API::IConfiguredAlgorithm_sptr algorithm, std::string errorMessage)
 
void algorithmStarted (MantidQt::API::IConfiguredAlgorithm_sptr algorithm)
 
void batchCancelled ()
 
void batchComplete (bool error)
 Emitted when a batch has finished executing. More...
 

Public Member Functions

void addAlgorithm (const Mantid::API::IAlgorithm_sptr &algo)
 Adds an algorithm to the execution queue. More...
 
void addAlgorithm (const Mantid::API::IAlgorithm_sptr &algo, std::unique_ptr< IAlgorithmRuntimeProps > props)
 Adds an algorithm to the end of the queue. More...
 
 BatchAlgorithmRunner (QObject *parent=nullptr)
 
void cancelBatch ()
 Request to cancel processing the batch. More...
 
void clearQueue ()
 Clears all algorithms from queue. More...
 
bool executeBatch ()
 Executes the batch, waits for the result and returns it. More...
 
void executeBatchAsync ()
 Starts the batch executing and returns immediately. More...
 
size_t queueLength ()
 Gets size of queue. More...
 
void setQueue (std::deque< IConfiguredAlgorithm_sptr > algorithm)
 Set the queue of algorithms. More...
 
void stopOnFailure (bool stopOnFailure)
 Sets if the execuion should be stopped if an error is detected. More...
 
 ~BatchAlgorithmRunner () override
 

Private Member Functions

void addAllObservers ()
 
bool cancelRequested ()
 
bool executeAlgo (const IConfiguredAlgorithm_sptr &algorithm)
 Sets up and executes an algorithm. More...
 
Poco::ActiveResult< bool > executeAsync ()
 Holds result of async execution. More...
 
bool executeBatchAsyncImpl (const Poco::Void &)
 Implementation of algorithm runner. More...
 
void handleAlgorithmComplete (const Poco::AutoPtr< AlgorithmCompleteNotification > &pNf)
 
void handleAlgorithmError (const Poco::AutoPtr< AlgorithmErrorNotification > &pNf)
 
void handleAlgorithmStarted (const Poco::AutoPtr< AlgorithmStartedNotification > &pNf)
 
void handleBatchCancelled (const Poco::AutoPtr< BatchCancelledNotification > &pNf)
 
void handleBatchComplete (const Poco::AutoPtr< BatchCompleteNotification > &pNf)
 Handlers for notifications. More...
 
void removeAllObservers ()
 
void resetState ()
 Reset state ready for executing a new batch. More...
 

Private Attributes

Poco::NObserver< BatchAlgorithmRunner, AlgorithmCompleteNotificationm_algorithmCompleteObserver
 
Poco::NObserver< BatchAlgorithmRunner, AlgorithmErrorNotificationm_algorithmErrorObserver
 
std::deque< IConfiguredAlgorithm_sptrm_algorithms
 The queue of algorithms to be executed. More...
 
Poco::NObserver< BatchAlgorithmRunner, AlgorithmStartedNotificationm_algorithmStartedObserver
 
Poco::NObserver< BatchAlgorithmRunner, BatchCancelledNotificationm_batchCancelledObserver
 
Poco::NObserver< BatchAlgorithmRunner, BatchCompleteNotificationm_batchCompleteObserver
 Observer for notifications. More...
 
bool m_cancelRequested
 User has requested to cancel processing. More...
 
Mantid::API::IAlgorithm_sptr m_currentAlgorithm
 The current algorithm being executed. More...
 
Poco::ActiveMethod< bool, Poco::Void, BatchAlgorithmRunner, Poco::ActiveStarter< BatchAlgorithmRunner > > m_executeAsync
 Active method to run batch runner on separate thread. More...
 
std::mutex m_mutex
 
Poco::NotificationCenter m_notificationCenter
 Notification center used to handle notifications from active method. More...
 
bool m_stopOnFailure
 If execution should be stopped on algorithm failure. More...
 

Detailed Description

Algorithm runner for execution of a queue of algorithms.

Date
2014-08-10

Definition at line 86 of file BatchAlgorithmRunner.h.

Constructor & Destructor Documentation

◆ BatchAlgorithmRunner()

MantidQt::API::BatchAlgorithmRunner::BatchAlgorithmRunner ( QObject *  parent = nullptr)
explicit

Definition at line 48 of file BatchAlgorithmRunner.cpp.

◆ ~BatchAlgorithmRunner()

MantidQt::API::BatchAlgorithmRunner::~BatchAlgorithmRunner ( )
override

Definition at line 57 of file BatchAlgorithmRunner.cpp.

References removeAllObservers().

Member Function Documentation

◆ addAlgorithm() [1/2]

void MantidQt::API::BatchAlgorithmRunner::addAlgorithm ( const Mantid::API::IAlgorithm_sptr algo)

Adds an algorithm to the execution queue.

Adds an algorithm to the end of the queue with blank properties.

Parameters
algoAlgorithm to add to queue

Definition at line 89 of file BatchAlgorithmRunner.cpp.

References addAlgorithm().

Referenced by addAlgorithm().

◆ addAlgorithm() [2/2]

void MantidQt::API::BatchAlgorithmRunner::addAlgorithm ( const Mantid::API::IAlgorithm_sptr algo,
std::unique_ptr< IAlgorithmRuntimeProps props 
)

Adds an algorithm to the end of the queue.

Parameters
algoAlgorithm to add to queue
propsOptional map of property name to property values to be set just before execution (mainly intended for input and inout workspace names)

Definition at line 100 of file BatchAlgorithmRunner.cpp.

References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, and m_algorithms.

◆ addAllObservers()

void MantidQt::API::BatchAlgorithmRunner::addAllObservers ( )
private

◆ algorithmComplete

void MantidQt::API::BatchAlgorithmRunner::algorithmComplete ( MantidQt::API::IConfiguredAlgorithm_sptr  algorithm)
signal

Referenced by handleAlgorithmComplete().

◆ algorithmError

void MantidQt::API::BatchAlgorithmRunner::algorithmError ( MantidQt::API::IConfiguredAlgorithm_sptr  algorithm,
std::string  errorMessage 
)
signal

Referenced by handleAlgorithmError().

◆ algorithmStarted

void MantidQt::API::BatchAlgorithmRunner::algorithmStarted ( MantidQt::API::IConfiguredAlgorithm_sptr  algorithm)
signal

Referenced by handleAlgorithmStarted().

◆ batchCancelled

void MantidQt::API::BatchAlgorithmRunner::batchCancelled ( )
signal

Referenced by handleBatchCancelled().

◆ batchComplete

void MantidQt::API::BatchAlgorithmRunner::batchComplete ( bool  error)
signal

Emitted when a batch has finished executing.

Referenced by handleBatchComplete().

◆ cancelBatch()

void MantidQt::API::BatchAlgorithmRunner::cancelBatch ( )

Request to cancel processing the batch.

Cancel execution of remaining queued items.

Definition at line 153 of file BatchAlgorithmRunner.cpp.

References addAllObservers(), m_cancelRequested, m_mutex, m_notificationCenter, queueLength(), and removeAllObservers().

◆ cancelRequested()

bool MantidQt::API::BatchAlgorithmRunner::cancelRequested ( )
private

Definition at line 177 of file BatchAlgorithmRunner.cpp.

References m_cancelRequested, and m_mutex.

Referenced by executeBatchAsyncImpl().

◆ clearQueue()

void MantidQt::API::BatchAlgorithmRunner::clearQueue ( )

Clears all algorithms from queue.

Removes all algorithms from the queue.

Definition at line 122 of file BatchAlgorithmRunner.cpp.

References m_algorithms.

Referenced by resetState().

◆ executeAlgo()

bool MantidQt::API::BatchAlgorithmRunner::executeAlgo ( const IConfiguredAlgorithm_sptr algorithm)
private

Sets up and executes an algorithm.

Assigns properties to an algorithm then executes it.

Parameters
algorithmAlgorithm and properties to assign to it
Returns
False if algorithm execution failed

Definition at line 226 of file BatchAlgorithmRunner.cpp.

References Mantid::API::g_log, Mantid::Kernel::Logger::information(), m_currentAlgorithm, m_notificationCenter, UNUSED_ARG, Mantid::Kernel::Logger::warning(), and Mantid::Kernel::Exception::NotFoundError::what().

Referenced by executeBatchAsyncImpl().

◆ executeAsync()

Poco::ActiveResult< bool > MantidQt::API::BatchAlgorithmRunner::executeAsync ( )
private

Holds result of async execution.

◆ executeBatch()

bool MantidQt::API::BatchAlgorithmRunner::executeBatch ( )

Executes the batch, waits for the result and returns it.

Executes the algorithms on a separate thread and waits for their completion.

Returns
False if the batch was stopped due to error

Definition at line 134 of file BatchAlgorithmRunner.cpp.

References addAllObservers(), m_executeAsync, and removeAllObservers().

◆ executeBatchAsync()

void MantidQt::API::BatchAlgorithmRunner::executeBatchAsync ( )

Starts the batch executing and returns immediately.

Starts executing the queue of algorithms on a separate thread.

Definition at line 145 of file BatchAlgorithmRunner.cpp.

References addAllObservers(), and m_executeAsync.

◆ executeBatchAsyncImpl()

bool MantidQt::API::BatchAlgorithmRunner::executeBatchAsyncImpl ( const Poco::Void &  )
private

Implementation of algorithm runner.

Implementation of sequential algorithm scheduler.

Definition at line 185 of file BatchAlgorithmRunner.cpp.

References cancelRequested(), executeAlgo(), Mantid::API::g_log, Mantid::Kernel::Logger::information(), m_algorithms, m_currentAlgorithm, m_notificationCenter, m_stopOnFailure, resetState(), and Mantid::Kernel::Logger::warning().

◆ handleAlgorithmComplete()

void MantidQt::API::BatchAlgorithmRunner::handleAlgorithmComplete ( const Poco::AutoPtr< AlgorithmCompleteNotification > &  pNf)
private

Definition at line 302 of file BatchAlgorithmRunner.cpp.

References algorithmComplete().

◆ handleAlgorithmError()

void MantidQt::API::BatchAlgorithmRunner::handleAlgorithmError ( const Poco::AutoPtr< AlgorithmErrorNotification > &  pNf)
private

Definition at line 307 of file BatchAlgorithmRunner.cpp.

References algorithmError().

◆ handleAlgorithmStarted()

void MantidQt::API::BatchAlgorithmRunner::handleAlgorithmStarted ( const Poco::AutoPtr< AlgorithmStartedNotification > &  pNf)
private

Definition at line 297 of file BatchAlgorithmRunner.cpp.

References algorithmStarted().

◆ handleBatchCancelled()

void MantidQt::API::BatchAlgorithmRunner::handleBatchCancelled ( const Poco::AutoPtr< BatchCancelledNotification > &  pNf)
private

Definition at line 291 of file BatchAlgorithmRunner.cpp.

References batchCancelled(), and UNUSED_ARG.

◆ handleBatchComplete()

void MantidQt::API::BatchAlgorithmRunner::handleBatchComplete ( const Poco::AutoPtr< BatchCompleteNotification > &  pNf)
private

Handlers for notifications.

Handles the notification posted when the algorithm queue stops execution.

Parameters
pNfNotification object

Definition at line 283 of file BatchAlgorithmRunner.cpp.

References batchComplete().

◆ queueLength()

size_t MantidQt::API::BatchAlgorithmRunner::queueLength ( )

Gets size of queue.

Returns the number of algorithms in the queue.

Definition at line 127 of file BatchAlgorithmRunner.cpp.

References m_algorithms.

Referenced by cancelBatch().

◆ removeAllObservers()

void MantidQt::API::BatchAlgorithmRunner::removeAllObservers ( )
private

◆ resetState()

void MantidQt::API::BatchAlgorithmRunner::resetState ( )
private

Reset state ready for executing a new batch.

Definition at line 170 of file BatchAlgorithmRunner.cpp.

References clearQueue(), m_cancelRequested, m_mutex, and removeAllObservers().

Referenced by executeBatchAsyncImpl().

◆ setQueue()

void MantidQt::API::BatchAlgorithmRunner::setQueue ( std::deque< IConfiguredAlgorithm_sptr algorithms)

Set the queue of algorithms.

Parameters
algorithmsThe queue of configured algorithms

Definition at line 111 of file BatchAlgorithmRunner.cpp.

References Mantid::Kernel::Logger::debug(), Mantid::API::g_log, and m_algorithms.

◆ stopOnFailure()

void MantidQt::API::BatchAlgorithmRunner::stopOnFailure ( bool  stopOnFailure)

Sets if the execuion should be stopped if an error is detected.

Sets if the execution of the queue should be stopped if an algorithm fails.

Defaults to true

Parameters
stopOnFailureFlase to continue to tnd of queue on failure

Definition at line 82 of file BatchAlgorithmRunner.cpp.

References m_stopOnFailure, and stopOnFailure().

Referenced by stopOnFailure().

Member Data Documentation

◆ m_algorithmCompleteObserver

Poco::NObserver<BatchAlgorithmRunner, AlgorithmCompleteNotification> MantidQt::API::BatchAlgorithmRunner::m_algorithmCompleteObserver
private

Definition at line 155 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), and removeAllObservers().

◆ m_algorithmErrorObserver

Poco::NObserver<BatchAlgorithmRunner, AlgorithmErrorNotification> MantidQt::API::BatchAlgorithmRunner::m_algorithmErrorObserver
private

Definition at line 156 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), and removeAllObservers().

◆ m_algorithms

std::deque<IConfiguredAlgorithm_sptr> MantidQt::API::BatchAlgorithmRunner::m_algorithms
private

The queue of algorithms to be executed.

Definition at line 135 of file BatchAlgorithmRunner.h.

Referenced by addAlgorithm(), clearQueue(), executeBatchAsyncImpl(), queueLength(), and setQueue().

◆ m_algorithmStartedObserver

Poco::NObserver<BatchAlgorithmRunner, AlgorithmStartedNotification> MantidQt::API::BatchAlgorithmRunner::m_algorithmStartedObserver
private

Definition at line 154 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), and removeAllObservers().

◆ m_batchCancelledObserver

Poco::NObserver<BatchAlgorithmRunner, BatchCancelledNotification> MantidQt::API::BatchAlgorithmRunner::m_batchCancelledObserver
private

Definition at line 153 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), and removeAllObservers().

◆ m_batchCompleteObserver

Poco::NObserver<BatchAlgorithmRunner, BatchCompleteNotification> MantidQt::API::BatchAlgorithmRunner::m_batchCompleteObserver
private

Observer for notifications.

Definition at line 152 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), and removeAllObservers().

◆ m_cancelRequested

bool MantidQt::API::BatchAlgorithmRunner::m_cancelRequested
private

User has requested to cancel processing.

Definition at line 144 of file BatchAlgorithmRunner.h.

Referenced by cancelBatch(), cancelRequested(), and resetState().

◆ m_currentAlgorithm

Mantid::API::IAlgorithm_sptr MantidQt::API::BatchAlgorithmRunner::m_currentAlgorithm
private

The current algorithm being executed.

Definition at line 138 of file BatchAlgorithmRunner.h.

Referenced by executeAlgo(), and executeBatchAsyncImpl().

◆ m_executeAsync

Poco::ActiveMethod<bool, Poco::Void, BatchAlgorithmRunner, Poco::ActiveStarter<BatchAlgorithmRunner> > MantidQt::API::BatchAlgorithmRunner::m_executeAsync
private

Active method to run batch runner on separate thread.

Definition at line 159 of file BatchAlgorithmRunner.h.

Referenced by executeBatch(), and executeBatchAsync().

◆ m_mutex

std::mutex MantidQt::API::BatchAlgorithmRunner::m_mutex
private

Definition at line 145 of file BatchAlgorithmRunner.h.

Referenced by cancelBatch(), cancelRequested(), and resetState().

◆ m_notificationCenter

Poco::NotificationCenter MantidQt::API::BatchAlgorithmRunner::m_notificationCenter
mutableprivate

Notification center used to handle notifications from active method.

Definition at line 150 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), cancelBatch(), executeAlgo(), executeBatchAsyncImpl(), and removeAllObservers().

◆ m_stopOnFailure

bool MantidQt::API::BatchAlgorithmRunner::m_stopOnFailure
private

If execution should be stopped on algorithm failure.

Definition at line 141 of file BatchAlgorithmRunner.h.

Referenced by executeBatchAsyncImpl(), and stopOnFailure().


The documentation for this class was generated from the following files: