Newer
Older
#ifndef MANTID_API_BATCHALGORITHMRUNNER_H_
#define MANTID_API_BATCHALGORITHMRUNNER_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>
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
namespace MantidQt {
namespace API {
/**
* Algorithm runner for execution of a queue of algorithms
@date 2014-08-10
Copyright © 2012 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
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
public:
typedef std::map<std::string, std::string> AlgorithmRuntimeProps;
typedef std::pair<Mantid::API::IAlgorithm_sptr, AlgorithmRuntimeProps>
ConfiguredAlgorithm;
explicit BatchAlgorithmRunner(QObject *parent = 0);
~BatchAlgorithmRunner() override;
/// Adds an algorithm to the execution queue
void addAlgorithm(Mantid::API::IAlgorithm_sptr algo,
AlgorithmRuntimeProps props = AlgorithmRuntimeProps());
/// Clears all algorithms from queue
void clearQueue();
/// Gets size of queue
size_t queueLength();
/// Executes the batch, waits for the result and returns it
bool executeBatch();
/// Starts the batch executing and returns immediately
void executeBatchAsync();
/// Sets if the execuion should be stopped if an error is detected
void stopOnFailure(bool stopOnFailure);
signals:
/// Emitted when a batch has finished executing
void batchComplete(bool error);
private:
/// Implementation of algorithm runner
bool executeBatchAsyncImpl(const Poco::Void &);
/// Sets up and executes an algorithm
bool executeAlgo(ConfiguredAlgorithm algorithm);
/// Handler for batch completion
void handleNotification(const Poco::AutoPtr<BatchNotification> &pNf);
/// The queue of algorithms to be executed
std::deque<ConfiguredAlgorithm> m_algorithms;
/// The current algorithm being executed
Mantid::API::IAlgorithm_sptr m_currentAlgorithm;
/// If execution should be stopped on algorithm failure
bool m_stopOnFailure;
/// Notification center used to handle notifications from active method
mutable Poco::NotificationCenter m_notificationCenter;
/// Observer for notifications
Poco::NObserver<BatchAlgorithmRunner, BatchNotification>
m_notificationObserver;
/// Active method to run batch runner on separate thread
Poco::ActiveMethod<bool, Poco::Void, BatchAlgorithmRunner,
Poco::ActiveStarter<BatchAlgorithmRunner>> m_executeAsync;
/// Holds result of async execution
Poco::ActiveResult<bool> executeAsync();
};
} // namespace API
} // namespace Mantid
#endif /* MANTID_API_BATCHALGORITHMRUNNER_H_ */