12#include "MantidAPI/DllConfig.h"
16#include "MantidTypes/Core/DateAndTime.h"
27class NotificationCenter;
39using time_point_ns = std::chrono::time_point<std::chrono::high_resolution_clock>;
42class SpectrumIndexSet;
48class AlgorithmHistory;
49class WorkspaceHistory;
92 std::string
name()
const override;
99 std::string
name()
const override;
110 int progressPrecision);
111 std::string
name()
const override;
125 std::string
name()
const override;
139 const char *what()
const noexcept override;
151 const std::string
name()
const override = 0;
157 const std::string
summary()
const override = 0;
160 const std::string
category()
const override {
return "Misc"; }
162 const std::vector<std::string> categories()
const override;
168 const std::vector<std::string>
seeAlso()
const override {
return {}; };
170 const std::string
alias()
const override {
return ""; }
172 bool calledByAlias =
false;
180 const std::string
helpURL()
const override {
return ""; }
182 template <typename T, typename = typename std::enable_if<std::is_convertible<T *, MatrixWorkspace *>::value>::type>
183 std::tuple<std::shared_ptr<T>, Indexing::SpectrumIndexSet> getWorkspaceAndIndices(
const std::string &
name)
const;
185 template <
typename T1,
typename T2,
186 typename =
typename std::enable_if<std::is_convertible<T1 *, MatrixWorkspace *>::value>::type,
187 typename =
typename std::enable_if<std::is_convertible<T2 *, std::string *>::value ||
188 std::is_convertible<T2 *, std::vector<int64_t> *>
::value>::type>
189 void setWorkspaceInputProperties(
const std::string &
name,
const std::shared_ptr<T1> &wksp,
IndexType type,
192 template <
typename T1,
typename T2,
193 typename =
typename std::enable_if<std::is_convertible<T1 *, MatrixWorkspace *>::value>::type,
194 typename =
typename std::enable_if<std::is_convertible<T2 *, std::string *>::value ||
195 std::is_convertible<T2 *, std::vector<int64_t> *>
::value>::type>
196 void setWorkspaceInputProperties(
const std::string &
name,
const std::string &wsName,
IndexType type,
const T2 &list);
198 const std::string workspaceMethodName()
const override;
199 const std::vector<std::string> workspaceMethodOn()
const override;
200 const std::string workspaceMethodInputProperty()
const override;
207 void initialize()
override;
208 bool execute() override final;
210 void executeAsChildAlg() override;
211 std::map<
std::
string,
std::
string> validateInputs() override;
217 bool isInitialized() const override;
218 bool isExecuted() const override;
219 bool isRunning() const override;
220 bool isReadyForGarbageCollection() const override;
222 bool isChild() const override;
223 void setChild(const
bool isChild) override;
224 void enableHistoryRecordingForChild(const
bool on) override;
225 void enableHistoryRecordingForProcessGroups(const
bool on) override;
226 bool isRecordingHistoryForChild() {
return m_recordHistoryForChild; }
227 void setAlwaysStoreInADS(
const bool doStore)
override;
228 bool getAlwaysStoreInADS()
const override;
229 void setRethrows(
const bool rethrow)
override;
235 void addObserver(
const Poco::AbstractObserver &observer)
const override;
238 void removeObserver(
const Poco::AbstractObserver &observer)
const override;
241 void cancel()
override;
242 bool getCancel()
const;
245 void setLogging(
const bool value)
override;
246 bool isLogging()
const override;
247 void setLoggingOffset(
const int value)
override;
248 int getLoggingOffset()
const override;
250 void setAlgStartupLogging(
const bool enabled)
override;
252 bool getAlgStartupLogging()
const override;
262 std::string
toString()
const override;
264 ::Json::Value toJson()
const override;
273 virtual std::shared_ptr<Algorithm> createChildAlgorithm(
const std::string &
name,
const double startProgress = -1.,
274 const double endProgress = -1.,
275 const bool enableLogging =
true,
const int &version = -1);
276 void setupAsChildAlgorithm(
const Algorithm_sptr &algorithm,
const double startProgress = -1.,
277 const double endProgress = -1.,
const bool enableLogging =
true);
281 void trackAlgorithmHistory(std::shared_ptr<AlgorithmHistory> parentHist);
285 void findWorkspaces(
WorkspaceVector &workspaces,
unsigned int direction,
bool checkADS =
false)
const;
288 virtual bool checkGroups();
290 virtual bool processGroups();
292 void copyNonWorkspaceProperties(
IAlgorithm *alg,
int periodNum);
295 void declareProperty(std::unique_ptr<Kernel::Property> p,
const std::string &doc =
"")
override;
298 void declareOrReplaceProperty(std::unique_ptr<Kernel::Property> p,
const std::string &doc =
"")
override;
299 void resetProperties()
override;
300 using IPropertyManager::declareProperty;
302 void setProperties(
const std::string &propertiesJson,
303 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
304 bool createMissing =
false)
override;
307 void setProperties(const ::Json::Value &jsonValue,
308 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
309 bool createMissing =
false)
override;
312 void setPropertiesWithString(
313 const std::string &propertiesString,
314 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>())
override;
316 void setPropertyValue(
const std::string &
name,
const std::string &
value)
override;
317 void setPropertyValueFromJson(
const std::string &
name,
const Json::Value &
value)
override;
318 void setPropertyOrdinal(
const int &
index,
const std::string &
value)
override;
323 bool existsProperty(
const std::string &
name)
const override;
324 bool validateProperties()
const override;
325 size_t propertyCount()
const override;
327 std::string getPropertyValue(
const std::string &
name)
const override;
328 const std::vector<Kernel::Property *> &getProperties()
const override;
329 std::vector<std::string> getDeclaredPropertyNames() const noexcept override;
332 TypedValue getProperty(const
std::
string &
name) const override;
335 std::
string asString(
bool withDefaultValues = false) const override;
338 ::
Json::Value asJson(
bool withDefaultValues = false) const override;
340 bool isDefault(const
std::
string &
name) const;
343 void removeProperty(const
std::
string &
name, const
bool delproperty = true) override;
345 std::unique_ptr<Kernel::
Property> takeProperty(const
size_t index) override;
348 void clear() override;
352 void afterPropertySet(const
std::
string &) override;
354 Kernel::
Property *getPointerToProperty(const
std::
string &
name) const override;
355 Kernel::
Property *getPointerToPropertyOrdinal(const
int &
index) const override;
359 virtual
void init() = 0;
361 virtual
void exec() = 0;
365 virtual const
std::
string workspaceMethodOnTypes()
const {
return ""; }
367 void cacheWorkspaceProperties();
368 void cacheInputWorkspaceHistories();
377 void progress(
double p,
const std::string &msg =
"",
double estimatedTime = 0.0,
int progressPrecision = 0);
378 void interruption_point();
381 Poco::NotificationCenter ¬ificationCenter()
const;
385 void handleChildProgressNotification(
const Poco::AutoPtr<ProgressNotification> &pNf);
387 const Poco::AbstractObserver &progressObserver()
const;
391 template <
typename NumT>
static bool isEmpty(
const NumT toCheck);
397 bool trackingHistory();
400 virtual void fillHistory();
402 void fillHistory(
const std::vector<Workspace_sptr> &outputWorkspaces);
413 virtual void setOtherProperties(
IAlgorithm *alg,
const std::string &propertyName,
const std::string &propertyValue,
435 bool m_usingBaseProcessGroups =
false;
438 bool m_recordHistoryForProcessGroups =
false;
440 template <typename T, const int AllowedIndexTypes = static_cast<int>(IndexType::WorkspaceIndex),
441 typename... WSPropArgs,
442 typename =
typename std::enable_if<std::is_convertible<T *, MatrixWorkspace *>::value>::type>
443 void declareWorkspaceInputProperties(
const std::string &propertyName,
const std::string &doc,
444 WSPropArgs &&...wsPropArgs);
447 template <
typename T1,
typename T2,
typename WsType>
448 void doSetInputProperties(
const std::string &
name,
const T1 &wksp,
IndexType type,
const T2 &list);
449 void lockWorkspaces();
451 void unlockWorkspaces();
453 void clearWorkspaceCaches();
455 void linkHistoryWithLastChild();
457 void logAlgorithmInfo()
const;
459 bool executeInternal();
461 bool executeAsyncImpl(
const Poco::Void &i);
463 bool doCallProcessGroups(Mantid::Types::Core::DateAndTime &start_time);
466 void reportCompleted(
const double &duration,
const bool groupProcessing =
false);
468 void registerFeatureUsage()
const;
470 bool isCompoundProperty(
const std::string &
name)
const;
474 std::unique_ptr<Poco::ActiveMethod<bool, Poco::Void, Algorithm, Poco::ActiveStarter<Algorithm>>>
m_executeAsync;
542#define DECLARE_ALGORITHM(classname) \
544 Mantid::Kernel::RegistrationHelper \
545 register_alg_##classname(((Mantid::API::AlgorithmFactory::Instance().subscribe<classname>()), 0)); \
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
std::vector< history_type > history
history information
This class stores information about the Command History used by algorithms on a workspace.
Base class for algorithm notifications.
const IAlgorithm *const m_algorithm
The algorithm.
CancelException is thrown to cancel execution of the algorithm.
ErrorNotification is sent when an exception is caught during execution of the algorithm.
std::string what
message string
FinishedNotification is sent after the algorithm finishes its execution.
bool success
true if the finished algorithm was successful or false if it failed.
An algorithm can report its progress by sending ProgressNotification.
double estimatedTime
Estimated time to completion.
double progress
Current progress. Value must be between 0 and 1.
int progressPrecision
Digits of precision to the progress (after the decimal).
std::string message
Message sent with notification.
StartedNotification is sent when the algorithm begins execution.
Base class from which all concrete algorithm classes should be derived.
const std::string categorySeparator() const override
Function to return the separator token for the category string.
std::vector< std::shared_ptr< WorkspaceGroup > > m_groupWorkspaces
Pointer to the WorkspaceGroup (if any) for each input workspace property.
std::vector< Workspace_sptr > m_inputWorkspaceHistories
Store a pointer to the input workspace histories so they can be copied to the outputs to avoid anythi...
AlgorithmID m_algorithmID
Algorithm ID for managed algorithms.
std::unique_ptr< Poco::NObserver< Algorithm, ProgressNotification > > m_progressObserver
Child algorithm progress observer.
std::vector< std::string > m_reservedList
Reserved property names.
AlgorithmID getAlgorithmID() const override
Algorithm ID.
int m_singleGroup
If only one input is a group, this is its index. -1 if they are all groups.
std::vector< IWorkspaceProperty * > m_inputWorkspaceProps
All the WorkspaceProperties that are Input or InOut. Set in execute()
void setChildEndProgress(const double endProgress) const override
setting the child end progress
WorkspaceVector m_writeLockedWorkspaces
Vector of all the workspaces that have been write-locked.
bool m_rethrow
Algorithm should rethrow exceptions while executing.
double m_startChildProgress
Whether to log alg startup and closedown messages from the base class (default = true)
const std::string aliasDeprecated() const override
Expiration date (in ISO8601 format) for the algorithm aliases; default implementation for no expirati...
std::vector< std::weak_ptr< IAlgorithm > > m_ChildAlgorithms
A list of weak pointers to any child algorithms created.
std::atomic< bool > m_cancel
Set to true to stop execution.
std::shared_ptr< AlgorithmHistory > m_parentHistory
Pointer to the parent history object (if set)
Algorithm(const Algorithm &)=delete
std::shared_ptr< AlgorithmHistory > m_history
Pointer to the history for the algorithm being executed.
std::vector< IWorkspaceProperty * > m_outputWorkspaceProps
All the WorkspaceProperties that are Output or InOut. Set in execute()
std::vector< IWorkspaceProperty * > m_pureOutputWorkspaceProps
All the WorkspaceProperties that are Output (not inOut). Set in execute()
virtual void copyPropertiesFrom(const Algorithm &alg)
Make m_properties point to the same PropertyManager as alg.m_properties.
size_t m_groupSize
Size of the group(s) being processed.
std::atomic< bool > m_parallelException
Set if an exception is thrown, and not caught, within a parallel region.
WorkspaceVector m_readLockedWorkspaces
Vector of all the workspaces that have been read-locked.
std::vector< std::shared_ptr< Workspace > > WorkspaceVector
void setChildStartProgress(const double startProgress) const override
setting the child start progress
bool m_alwaysStoreInADS
Always store in the ADS, even for child algos.
bool m_isAlgStartupLoggingEnabled
std::atomic< ResultState > m_resultState
the current result State
const std::string alias() const override
function to return any aliases to the algorithm; A default implementation is provided
std::unique_ptr< Poco::ActiveMethod< bool, Poco::Void, Algorithm, Poco::ActiveStarter< Algorithm > > > m_executeAsync
Poco::ActiveMethod used to implement asynchronous execution.
Algorithm & operator=(const Algorithm &)=delete
std::vector< WorkspaceVector > m_unrolledInputWorkspaces
One vector of workspaces for each input workspace property.
bool m_isChildAlgorithm
Algorithm is a child algorithm.
Mantid::Kernel::PropertyManagerOwner m_properties
const std::string category() const override
function to return a category of the algorithm.
~Algorithm() override
Virtual destructor.
bool m_runningAsync
Algorithm is running asynchronously.
const std::string helpURL() const override
function to return URL for algorithm documentation; A default implementation is provided.
int version() const override=0
function to return a version of the algorithm, must be overridden in all algorithms
std::atomic< ExecutionState > m_executionState
the current execution state
static bool isEmpty(const NumT toCheck)
checks that the value was not set by users, uses the value in empty double/int.
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
bool m_groupsHaveSimilarNames
All the groups have similar names (group_1, group_2 etc.)
const std::string summary() const override=0
function returns a summary message that will be displayed in the default GUI, and in the help.
double m_endChildProgress
Keeps value for algorithm's progress at Child Algorithm's finish.
Mantid::Types::Core::DateAndTime m_gcTime
The earliest this class should be considered for garbage collection.
std::unique_ptr< Poco::NotificationCenter > m_notificationCenter
Sends notifications to observers.
Kernel::Logger m_log
Logger for this algorithm.
static size_t g_execCount
Counter to keep track of algorithm execution order.
bool m_recordHistoryForChild
Flag to indicate whether history should be recorded.
const std::string name() const override=0
function to return a name of the algorithm, must be overridden in all algorithms
IAlgorithm is the interface implemented by the Algorithm base class.
Helper class for reporting progress from algorithms.
This class stores information about the Workspace History used by algorithms on a workspace and the e...
The Logger class is in charge of the publishing messages from the framework through various channels.
Kernel/PropertyManagerOwner.h.
Base class for properties.
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
ResultState
The validity of the results of the algorithm object.
ExecutionState
The current state of the algorithm object.
void * AlgorithmID
As we have multiple interfaces to the same logical algorithm we need a way of uniquely identifying ma...
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::chrono::time_point< std::chrono::high_resolution_clock > time_point_ns
std::string toString(const T &value)
Convert values to strings.
Helper class which provides the Collimation Length for SANS instruments.