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.
 

Public Member Functions

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

Private Member Functions

void addAllObservers ()
 
bool cancelRequested ()
 
bool executeAlgo (const IConfiguredAlgorithm_sptr &algorithm)
 Sets up and executes an algorithm.
 
Poco::ActiveResult< bool > executeAsync ()
 Holds result of async execution.
 
bool executeBatchAsyncImpl (const Poco::Void &)
 Implementation of algorithm runner.
 
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.
 
void postNotification (Poco::Notification *notification)
 Post a poco notification.
 
void removeAllObservers ()
 
void resetState ()
 Reset state ready for executing a new batch.
 
void setCancelRequested (bool const cancel)
 

Private Attributes

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

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 m_executeAsync, and 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 96 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< Mantid::API::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 107 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 179 of file BatchAlgorithmRunner.cpp.

References addAllObservers(), m_executeMutex, postNotification(), removeAllObservers(), and setCancelRequested().

Referenced by MantidQt::API::QtJobRunner::cancelAlgorithmQueue().

◆ cancelRequested()

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

Definition at line 202 of file BatchAlgorithmRunner.cpp.

References m_cancelMutex, and m_cancelRequested.

Referenced by executeBatchAsyncImpl().

◆ clearQueue()

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

Clears all algorithms from queue.

Removes all algorithms from the queue.

Definition at line 130 of file BatchAlgorithmRunner.cpp.

References m_algorithms, and m_executeMutex.

Referenced by MantidQt::API::QtJobRunner::clearAlgorithmQueue(), and 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 252 of file BatchAlgorithmRunner.cpp.

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

Referenced by executeBatchAsyncImpl().

◆ executeAlgorithmAsync()

void MantidQt::API::BatchAlgorithmRunner::executeAlgorithmAsync ( IConfiguredAlgorithm_sptr  algorithm)

Starts a single algorithm and returns immediately.

Starts the execution of a single algorithm on a separate thread.

Parameters
algorithmThe algorithm to execute asynchronously

Definition at line 169 of file BatchAlgorithmRunner.cpp.

References executeBatchAsync(), and setQueue().

Referenced by MantidQt::API::QtJobRunner::executeAlgorithm().

◆ 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 148 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 159 of file BatchAlgorithmRunner.cpp.

References addAllObservers(), and m_executeAsync.

Referenced by executeAlgorithmAsync(), and MantidQt::API::QtJobRunner::executeAlgorithmQueue().

◆ executeBatchAsyncImpl()

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

◆ handleAlgorithmComplete()

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

Definition at line 339 of file BatchAlgorithmRunner.cpp.

References algorithmComplete().

◆ handleAlgorithmError()

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

Definition at line 344 of file BatchAlgorithmRunner.cpp.

References algorithmError().

◆ handleAlgorithmStarted()

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

Definition at line 334 of file BatchAlgorithmRunner.cpp.

References algorithmStarted().

◆ handleBatchCancelled()

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

Definition at line 328 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 320 of file BatchAlgorithmRunner.cpp.

References batchComplete().

◆ postNotification()

void MantidQt::API::BatchAlgorithmRunner::postNotification ( Poco::Notification *  notification)
private

Post a poco notification.

Definition at line 305 of file BatchAlgorithmRunner.cpp.

References m_notificationCenter, and m_notificationMutex.

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

◆ queueLength()

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

Gets size of queue.

Returns the number of algorithms in the queue.

Definition at line 138 of file BatchAlgorithmRunner.cpp.

References m_algorithms, and m_executeMutex.

◆ 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 196 of file BatchAlgorithmRunner.cpp.

References clearQueue(), removeAllObservers(), and setCancelRequested().

Referenced by executeBatchAsyncImpl().

◆ setCancelRequested()

void MantidQt::API::BatchAlgorithmRunner::setCancelRequested ( bool const  cancel)
private

Definition at line 310 of file BatchAlgorithmRunner.cpp.

References m_cancelMutex, and m_cancelRequested.

Referenced by cancelBatch(), and resetState().

◆ 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 118 of file BatchAlgorithmRunner.cpp.

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

Referenced by executeAlgorithmAsync(), and MantidQt::API::QtJobRunner::setAlgorithmQueue().

◆ 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 89 of file BatchAlgorithmRunner.cpp.

References m_stopOnFailure, and stopOnFailure().

Referenced by MantidQt::API::QtJobRunner::QtJobRunner(), and stopOnFailure().

Member Data Documentation

◆ m_algorithmCompleteObserver

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

Definition at line 164 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), and removeAllObservers().

◆ m_algorithmErrorObserver

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

Definition at line 165 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 142 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 163 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), and removeAllObservers().

◆ m_batchCancelledObserver

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

Definition at line 162 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 161 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), and removeAllObservers().

◆ m_cancelMutex

std::recursive_mutex MantidQt::API::BatchAlgorithmRunner::m_cancelMutex
private

Definition at line 153 of file BatchAlgorithmRunner.h.

Referenced by cancelRequested(), and setCancelRequested().

◆ m_cancelRequested

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

User has requested to cancel processing.

Definition at line 151 of file BatchAlgorithmRunner.h.

Referenced by cancelRequested(), and setCancelRequested().

◆ m_currentAlgorithm

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

The current algorithm being executed.

Definition at line 145 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 168 of file BatchAlgorithmRunner.h.

Referenced by executeBatch(), executeBatchAsync(), and ~BatchAlgorithmRunner().

◆ m_executeMutex

std::recursive_mutex MantidQt::API::BatchAlgorithmRunner::m_executeMutex
private

◆ m_notificationCenter

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

Notification center used to handle notifications from active method.

Definition at line 159 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), postNotification(), and removeAllObservers().

◆ m_notificationMutex

std::recursive_mutex MantidQt::API::BatchAlgorithmRunner::m_notificationMutex
private

Definition at line 154 of file BatchAlgorithmRunner.h.

Referenced by addAllObservers(), postNotification(), and removeAllObservers().

◆ m_stopOnFailure

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

If execution should be stopped on algorithm failure.

Definition at line 148 of file BatchAlgorithmRunner.h.

Referenced by executeBatchAsyncImpl(), and stopOnFailure().


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