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;
260 void enableCheckForStringArrayWorkspaceOutputs(
const bool on);
265 std::string
toString()
const override;
267 ::Json::Value toJson()
const override;
276 virtual std::shared_ptr<Algorithm> createChildAlgorithm(
const std::string &
name,
const double startProgress = -1.,
277 const double endProgress = -1.,
278 const bool enableLogging =
true,
const int &version = -1);
279 void setupAsChildAlgorithm(
const Algorithm_sptr &algorithm,
const double startProgress = -1.,
280 const double endProgress = -1.,
const bool enableLogging =
true);
284 void trackAlgorithmHistory(std::shared_ptr<AlgorithmHistory> parentHist);
288 void findWorkspaces(
WorkspaceVector &workspaces,
unsigned int direction,
bool checkADS =
false)
const;
291 virtual bool checkGroups();
293 virtual bool processGroups();
295 void copyNonWorkspaceProperties(
IAlgorithm *alg,
int periodNum);
298 void declareProperty(std::unique_ptr<Kernel::Property> p,
const std::string &doc =
"")
override;
301 void declareOrReplaceProperty(std::unique_ptr<Kernel::Property> p,
const std::string &doc =
"")
override;
302 void resetProperties()
override;
303 using IPropertyManager::declareProperty;
305 void setProperties(
const std::string &propertiesJson,
306 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
307 bool createMissing =
false)
override;
310 void setProperties(const ::Json::Value &jsonValue,
311 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
312 bool createMissing =
false)
override;
315 void setPropertiesWithString(
316 const std::string &propertiesString,
317 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>())
override;
319 void setPropertyValue(
const std::string &
name,
const std::string &
value)
override;
320 void setPropertyValueFromJson(
const std::string &
name,
const Json::Value &
value)
override;
321 void setPropertyOrdinal(
const int &
index,
const std::string &
value)
override;
326 bool existsProperty(
const std::string &
name)
const override;
327 bool validateProperties()
const override;
328 size_t propertyCount()
const override;
330 std::string getPropertyValue(
const std::string &
name)
const override;
331 const std::vector<Kernel::Property *> &getProperties()
const override;
332 std::vector<std::string> getDeclaredPropertyNames() const noexcept override;
335 TypedValue getProperty(const
std::
string &
name) const override;
338 std::
string asString(
bool withDefaultValues = false) const override;
341 ::
Json::Value asJson(
bool withDefaultValues = false) const override;
343 bool isDefault(const
std::
string &
name) const;
346 void removeProperty(const
std::
string &
name, const
bool delproperty = true) override;
348 std::unique_ptr<Kernel::
Property> takeProperty(const
size_t index) override;
351 void clear() override;
355 void afterPropertySet(const
std::
string &) override;
357 Kernel::
Property *getPointerToProperty(const
std::
string &
name) const override;
358 Kernel::
Property *getPointerToPropertyOrdinal(const
int &
index) const override;
362 virtual
void init() = 0;
364 virtual
void exec() = 0;
368 virtual const
std::
string workspaceMethodOnTypes()
const {
return ""; }
370 void cacheWorkspaceProperties();
371 void cacheInputWorkspaceHistories();
380 void progress(
double p,
const std::string &msg =
"",
double estimatedTime = 0.0,
int progressPrecision = 0);
381 void interruption_point();
384 Poco::NotificationCenter ¬ificationCenter()
const;
388 void handleChildProgressNotification(
const Poco::AutoPtr<ProgressNotification> &pNf);
390 const Poco::AbstractObserver &progressObserver()
const;
394 template <
typename NumT>
static bool isEmpty(
const NumT toCheck);
400 bool trackingHistory();
403 virtual void fillHistory();
405 void fillHistory(
const std::vector<Workspace_sptr> &outputWorkspaces);
416 virtual void setOtherProperties(
IAlgorithm *alg,
const std::string &propertyName,
const std::string &propertyValue,
438 bool m_usingBaseProcessGroups =
false;
441 bool m_recordHistoryForProcessGroups =
false;
443 template <typename T, const int AllowedIndexTypes = static_cast<int>(IndexType::WorkspaceIndex),
444 typename... WSPropArgs,
445 typename =
typename std::enable_if<std::is_convertible<T *, MatrixWorkspace *>::value>::type>
446 void declareWorkspaceInputProperties(
const std::string &propertyName,
const std::string &doc,
447 WSPropArgs &&...wsPropArgs);
450 template <
typename T1,
typename T2,
typename WsType>
451 void doSetInputProperties(
const std::string &
name,
const T1 &wksp,
IndexType type,
const T2 &list);
452 void lockWorkspaces();
454 void unlockWorkspaces();
456 void clearWorkspaceCaches();
458 void linkHistoryWithLastChild();
460 void logAlgorithmInfo()
const;
462 bool executeInternal();
464 bool executeAsyncImpl(
const Poco::Void &i);
466 bool doCallProcessGroups(Mantid::Types::Core::DateAndTime &start_time);
469 void reportCompleted(
const double &duration,
const bool groupProcessing =
false);
471 void registerFeatureUsage()
const;
473 bool isCompoundProperty(
const std::string &
name)
const;
477 std::unique_ptr<Poco::ActiveMethod<bool, Poco::Void, Algorithm, Poco::ActiveStarter<Algorithm>>>
m_executeAsync;
547#define DECLARE_ALGORITHM(classname) \
549 Mantid::Kernel::RegistrationHelper \
550 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
bool m_checkForStringArrayWorkspaceOutputs
Flag to indicate checking of output StringArrayProperty outputs for valid workspaces.
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.
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.)
std::atomic_bool m_runningAsync
Algorithm is scheduled or running asynchronously.
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.