27 auto allowedPropNames = alg->getDeclaredPropertyNames();
31 std::sort(allowedPropNames.begin(), allowedPropNames.end());
32 std::sort(propNamesToUpdate.begin(), propNamesToUpdate.end());
34 std::vector<std::string> invalidProps;
35 std::set_difference(propNamesToUpdate.cbegin(), propNamesToUpdate.cend(), allowedPropNames.cbegin(),
36 allowedPropNames.cend(), std::back_inserter(invalidProps));
38 if (invalidProps.size() > 0) {
39 const auto invalidPropsStr = std::accumulate(std::next(invalidProps.cbegin()), invalidProps.cend(), invalidProps[0],
40 [](
const auto &a,
const auto &b) { return a +
"," + b; });
49 : QObject(parent), m_stopOnFailure(true), m_cancelRequested(false), m_notificationCenter(),
90 this->
addAlgorithm(algo, std::make_unique<AlgorithmRuntimeProps>());
101 m_algorithms.emplace_back(std::make_unique<ConfiguredAlgorithm>(algo, std::move(props)));
103 g_log.
debug() <<
"Added algorithm \"" <<
m_algorithms.back()->algorithm()->name() <<
"\" to batch queue\n";
112 g_log.
debug() <<
"Set batch queue to algorithm list:\n";
113 for (
auto &algorithm : algorithms)
114 g_log.
debug() << algorithm->algorithm()->name() <<
"\n";
139 return result.data();
154 std::lock_guard<std::mutex> lock(
m_mutex);
171 std::lock_guard<std::mutex> lock(
m_mutex);
178 std::lock_guard<std::mutex> lock(
m_mutex);
186 bool errorFlag =
false;
200 g_log.
warning(
"Stopping batch algorithm because of execution error");
229 auto const &props = algorithm->getAlgorithmRuntimeProps();
242 auto message = std::string(
"Algorithm") + algorithm->algorithm()->name() + std::string(
" execution failed");
253 g_log.
warning(
"Algorithm property does not exist.\nStopping queue execution.");
258 catch (std::invalid_argument &invalidArgEx) {
260 g_log.
warning(
"Algorithm property given value of incorrect type.\nStopping "
266 catch (std::exception &ex) {
271 g_log.
warning(
"Unknown error starting next batch algorithm");
284 bool inProgress = pNf->isInProgress();
308 auto errorMessage = pNf->errorMessage();
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Algorithm runner for execution of a queue of algorithms.
void handleAlgorithmComplete(const Poco::AutoPtr< AlgorithmCompleteNotification > &pNf)
bool m_cancelRequested
User has requested to cancel processing.
void handleBatchCancelled(const Poco::AutoPtr< BatchCancelledNotification > &pNf)
void algorithmStarted(MantidQt::API::IConfiguredAlgorithm_sptr algorithm)
Mantid::API::IAlgorithm_sptr m_currentAlgorithm
The current algorithm being executed.
void setQueue(std::deque< IConfiguredAlgorithm_sptr > algorithm)
Set the queue of algorithms.
void handleBatchComplete(const Poco::AutoPtr< BatchCompleteNotification > &pNf)
Handlers for notifications.
std::deque< IConfiguredAlgorithm_sptr > m_algorithms
The queue of algorithms to be executed.
BatchAlgorithmRunner(QObject *parent=nullptr)
bool m_stopOnFailure
If execution should be stopped on algorithm failure.
void resetState()
Reset state ready for executing a new batch.
void stopOnFailure(bool stopOnFailure)
Sets if the execuion should be stopped if an error is detected.
void handleAlgorithmError(const Poco::AutoPtr< AlgorithmErrorNotification > &pNf)
void cancelBatch()
Request to cancel processing the batch.
bool executeBatch()
Executes the batch, waits for the result and returns it.
Poco::NObserver< BatchAlgorithmRunner, AlgorithmStartedNotification > m_algorithmStartedObserver
Poco::NObserver< BatchAlgorithmRunner, BatchCompleteNotification > m_batchCompleteObserver
Observer for notifications.
void executeBatchAsync()
Starts the batch executing and returns immediately.
Poco::NotificationCenter m_notificationCenter
Notification center used to handle notifications from active method.
void handleAlgorithmStarted(const Poco::AutoPtr< AlgorithmStartedNotification > &pNf)
bool executeAlgo(const IConfiguredAlgorithm_sptr &algorithm)
Sets up and executes an algorithm.
Poco::ActiveMethod< bool, Poco::Void, BatchAlgorithmRunner, Poco::ActiveStarter< BatchAlgorithmRunner > > m_executeAsync
Active method to run batch runner on separate thread.
Poco::NObserver< BatchAlgorithmRunner, AlgorithmErrorNotification > m_algorithmErrorObserver
void algorithmError(MantidQt::API::IConfiguredAlgorithm_sptr algorithm, std::string errorMessage)
void algorithmComplete(MantidQt::API::IConfiguredAlgorithm_sptr algorithm)
Poco::NObserver< BatchAlgorithmRunner, AlgorithmCompleteNotification > m_algorithmCompleteObserver
void batchComplete(bool error)
Emitted when a batch has finished executing.
void removeAllObservers()
void clearQueue()
Clears all algorithms from queue.
size_t queueLength()
Gets size of queue.
~BatchAlgorithmRunner() override
bool executeBatchAsyncImpl(const Poco::Void &)
Implementation of algorithm runner.
Poco::NObserver< BatchAlgorithmRunner, BatchCancelledNotification > m_batchCancelledObserver
void addAlgorithm(const Mantid::API::IAlgorithm_sptr &algo)
Adds an algorithm to the execution queue.
Exception for when an item is not found in a collection.
const char * what() const noexcept override
Writes out the range and limits.
virtual std::vector< std::string > getDeclaredPropertyNames() const noexcept=0
Get the list of managed property names.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
void warning(const std::string &msg)
Logs at warning level.
void information(const std::string &msg)
Logs at information level.
std::shared_ptr< IConfiguredAlgorithm > IConfiguredAlgorithm_sptr
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
Kernel::Logger g_log("ExperimentInfo")
static logger object