Newer
Older
Peterson, Peter
committed
#include "MantidAPI/Algorithm.h"
#include "MantidAPI/AlgorithmHistory.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/AlgorithmProxy.h"
Peterson, Peter
committed
#include "MantidAPI/AnalysisDataService.h"
Peterson, Peter
committed
#include "MantidAPI/DeprecatedAlgorithm.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/IWorkspaceProperty.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidAPI/WorkspaceHistory.h"
#include "MantidKernel/EmptyValues.h"
#include "MantidKernel/DateAndTime.h"
#include "MantidKernel/MultiThreaded.h"
#include "MantidKernel/Strings.h"
#include "MantidKernel/Timer.h"
Gigg, Martyn Anthony
committed
#include <boost/algorithm/string/regex.hpp>
Gigg, Martyn Anthony
committed
#include <Poco/ActiveMethod.h>
#include <Poco/ActiveResult.h>
#include <Poco/NotificationCenter.h>
#include <Poco/RWLock.h>
#include <MantidKernel/StringTokenizer.h>
#include <map>
Peterson, Peter
committed
using namespace Mantid::Kernel;
namespace Mantid {
namespace API {
namespace {
/// Separator for workspace types in workspaceMethodOnTypes member
const std::string WORKSPACE_TYPES_SEPARATOR = ";";
class WorkspacePropertyValueIs {
public:
explicit WorkspacePropertyValueIs(const std::string &value)
: m_value(value){};
bool operator()(IWorkspaceProperty *property) {
Property *prop = dynamic_cast<Property *>(property);
if (!prop)
return false;
return prop->value() == m_value;
}
private:
}
// Doxygen can't handle member specialization at the moment:
// https://bugzilla.gnome.org/show_bug.cgi?id=406027
// so we have to ignore them
///@cond
template <typename NumT> bool Algorithm::isEmpty(const NumT toCheck) {
return static_cast<int>(toCheck) == EMPTY_INT();
}
template <> MANTID_API_DLL bool Algorithm::isEmpty(const double toCheck) {
return std::abs((toCheck - EMPTY_DBL()) / (EMPTY_DBL())) < 1e-8;
}
// concrete instantiations
template MANTID_API_DLL bool Algorithm::isEmpty<int>(const int);
template MANTID_API_DLL bool Algorithm::isEmpty<int64_t>(const int64_t);
template MANTID_API_DLL bool Algorithm::isEmpty<std::size_t>(const std::size_t);
///@endcond
//=============================================================================================
//================================== Constructors/Destructors
//=================================
//=============================================================================================
/// Initialize static algorithm counter
size_t Algorithm::g_execCount = 0;
/// Constructor
Algorithm::Algorithm()
: PropertyManagerOwner(), m_cancel(false), m_parallelException(false),
m_log("Algorithm"), g_log(m_log), m_groupSize(0), m_executeAsync(nullptr),
m_notificationCenter(nullptr), m_progressObserver(nullptr),
m_isInitialized(false), m_isExecuted(false), m_isChildAlgorithm(false),
m_recordHistoryForChild(false), m_alwaysStoreInADS(false),
m_runningAsync(false), m_running(false), m_rethrow(false),
Federico Montesino Pouzols
committed
m_isAlgStartupLoggingEnabled(true), m_startChildProgress(0.),
m_endChildProgress(0.), m_algorithmID(this), m_singleGroup(-1),
m_groupsHaveSimilarNames(false) {}
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/// Virtual destructor
Algorithm::~Algorithm() {
delete m_notificationCenter;
delete m_executeAsync;
delete m_progressObserver;
}
//=============================================================================================
//================================== Simple Getters/Setters
//===================================
//=============================================================================================
//---------------------------------------------------------------------------------------------
/// Has the Algorithm already been initialized
bool Algorithm::isInitialized() const { return m_isInitialized; }
/// Has the Algorithm already been executed
bool Algorithm::isExecuted() const { return m_isExecuted; }
//---------------------------------------------------------------------------------------------
/// Set the Algorithm initialized state
void Algorithm::setInitialized() { m_isInitialized = true; }
/** Set the executed flag to the specified state
// Public in Gaudi - don't know why and will leave here unless we find a reason
otherwise
// Also don't know reason for different return type and argument.
@param state :: New executed state
*/
void Algorithm::setExecuted(bool state) { m_isExecuted = state; }
//---------------------------------------------------------------------------------------------
/** To query whether algorithm is a child.
* @returns true - the algorithm is a child algorithm. False - this is a full
* managed algorithm.
*/
bool Algorithm::isChild() const { return m_isChildAlgorithm; }
/** To set whether algorithm is a child.
* @param isChild :: True - the algorithm is a child algorithm. False - this is
* a full managed algorithm.
*/
void Algorithm::setChild(const bool isChild) { m_isChildAlgorithm = isChild; }
/**
* Change the state of the history recording flag. Only applicable for
* child algorithms.
* @param on :: The new state of the flag
*/
void Algorithm::enableHistoryRecordingForChild(const bool on) {
m_recordHistoryForChild = on;
}
/** Do we ALWAYS store in the AnalysisDataService? This is set to true
* for python algorithms' child algorithms
*
* @param doStore :: always store in ADS
*/
void Algorithm::setAlwaysStoreInADS(const bool doStore) {
m_alwaysStoreInADS = doStore;
}
/** Set whether the algorithm will rethrow exceptions
* @param rethrow :: true if you want to rethrow exception.
*/
void Algorithm::setRethrows(const bool rethrow) { this->m_rethrow = rethrow; }
/// True if the algorithm is running.
bool Algorithm::isRunning() const { return m_running; }
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//---------------------------------------------------------------------------------------------
/** Add an observer to a notification
@param observer :: Reference to the observer to add
*/
void Algorithm::addObserver(const Poco::AbstractObserver &observer) const {
notificationCenter().addObserver(observer);
}
/** Remove an observer
@param observer :: Reference to the observer to remove
*/
void Algorithm::removeObserver(const Poco::AbstractObserver &observer) const {
notificationCenter().removeObserver(observer);
}
//---------------------------------------------------------------------------------------------
/** Sends ProgressNotification.
* @param p :: Reported progress, must be between 0 (just started) and 1
* (finished)
* @param msg :: Optional message string
* @param estimatedTime :: Optional estimated time to completion
* @param progressPrecision :: optional, int number of digits after the decimal
* point to show.
*/
void Algorithm::progress(double p, const std::string &msg, double estimatedTime,
int progressPrecision) {
notificationCenter().postNotification(
new ProgressNotification(this, p, msg, estimatedTime, progressPrecision));
}
//---------------------------------------------------------------------------------------------
/// Function to return all of the categories that contain this algorithm
const std::vector<std::string> Algorithm::categories() const {
Mantid::Kernel::StringTokenizer tokenizer(
category(), categorySeparator(),
Loading
Loading full blame...