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 bool isRecordingHistoryForChild() {
return m_recordHistoryForChild; }
226 void setAlwaysStoreInADS(
const bool doStore)
override;
227 bool getAlwaysStoreInADS()
const override;
228 void setRethrows(
const bool rethrow)
override;
234 void addObserver(
const Poco::AbstractObserver &observer)
const override;
237 void removeObserver(
const Poco::AbstractObserver &observer)
const override;
240 void cancel()
override;
241 bool getCancel()
const;
244 void setLogging(
const bool value)
override;
245 bool isLogging()
const override;
246 void setLoggingOffset(
const int value)
override;
247 int getLoggingOffset()
const override;
249 void setAlgStartupLogging(
const bool enabled)
override;
251 bool getAlgStartupLogging()
const override;
261 std::string
toString()
const override;
263 ::Json::Value toJson()
const override;
272 virtual std::shared_ptr<Algorithm> createChildAlgorithm(
const std::string &
name,
const double startProgress = -1.,
273 const double endProgress = -1.,
274 const bool enableLogging =
true,
const int &version = -1);
275 void setupAsChildAlgorithm(
const Algorithm_sptr &algorithm,
const double startProgress = -1.,
276 const double endProgress = -1.,
const bool enableLogging =
true);
280 void trackAlgorithmHistory(std::shared_ptr<AlgorithmHistory> parentHist);
284 void findWorkspaces(
WorkspaceVector &workspaces,
unsigned int direction,
bool checkADS =
false)
const;
287 virtual bool checkGroups();
289 virtual bool processGroups();
291 void copyNonWorkspaceProperties(
IAlgorithm *alg,
int periodNum);
294 void declareProperty(std::unique_ptr<Kernel::Property> p,
const std::string &doc =
"")
override;
297 void declareOrReplaceProperty(std::unique_ptr<Kernel::Property> p,
const std::string &doc =
"")
override;
298 void resetProperties()
override;
299 using IPropertyManager::declareProperty;
301 void setProperties(
const std::string &propertiesJson,
302 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
303 bool createMissing =
false)
override;
306 void setProperties(const ::Json::Value &jsonValue,
307 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
308 bool createMissing =
false)
override;
311 void setPropertiesWithString(
312 const std::string &propertiesString,
313 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>())
override;
315 void setPropertyValue(
const std::string &
name,
const std::string &
value)
override;
316 void setPropertyValueFromJson(
const std::string &
name,
const Json::Value &
value)
override;
317 void setPropertyOrdinal(
const int &
index,
const std::string &
value)
override;
322 bool existsProperty(
const std::string &
name)
const override;
323 bool validateProperties()
const override;
324 size_t propertyCount()
const override;
326 std::string getPropertyValue(
const std::string &
name)
const override;
327 const std::vector<Kernel::Property *> &getProperties()
const override;
328 std::vector<std::string> getDeclaredPropertyNames() const noexcept override;
331 TypedValue getProperty(const
std::
string &
name) const override;
334 std::
string asString(
bool withDefaultValues = false) const override;
337 ::
Json::Value asJson(
bool withDefaultValues = false) const override;
339 bool isDefault(const
std::
string &
name) const;
342 void removeProperty(const
std::
string &
name, const
bool delproperty = true) override;
344 std::unique_ptr<Kernel::
Property> takeProperty(const
size_t index) override;
347 void clear() override;
351 void afterPropertySet(const
std::
string &) override;
353 Kernel::
Property *getPointerToProperty(const
std::
string &
name) const override;
354 Kernel::
Property *getPointerToPropertyOrdinal(const
int &
index) const override;
358 virtual
void init() = 0;
360 virtual
void exec() = 0;
364 virtual const
std::
string workspaceMethodOnTypes()
const {
return ""; }
366 void cacheWorkspaceProperties();
367 void cacheInputWorkspaceHistories();
376 void progress(
double p,
const std::string &msg =
"",
double estimatedTime = 0.0,
int progressPrecision = 0);
377 void interruption_point();
380 Poco::NotificationCenter ¬ificationCenter()
const;
384 void handleChildProgressNotification(
const Poco::AutoPtr<ProgressNotification> &pNf);
386 const Poco::AbstractObserver &progressObserver()
const;
390 template <
typename NumT>
static bool isEmpty(
const NumT toCheck);
396 bool trackingHistory();
399 virtual void fillHistory();
401 void fillHistory(
const std::vector<Workspace_sptr> &outputWorkspaces);
412 virtual void setOtherProperties(
IAlgorithm *alg,
const std::string &propertyName,
const std::string &propertyValue,
434 bool m_usingBaseProcessGroups =
false;
436 template <typename T, const int AllowedIndexTypes = static_cast<int>(IndexType::WorkspaceIndex),
437 typename... WSPropArgs,
438 typename =
typename std::enable_if<std::is_convertible<T *, MatrixWorkspace *>::value>::type>
439 void declareWorkspaceInputProperties(
const std::string &propertyName,
const std::string &doc,
440 WSPropArgs &&...wsPropArgs);
443 template <
typename T1,
typename T2,
typename WsType>
444 void doSetInputProperties(
const std::string &
name,
const T1 &wksp,
IndexType type,
const T2 &list);
445 void lockWorkspaces();
447 void unlockWorkspaces();
449 void clearWorkspaceCaches();
451 void linkHistoryWithLastChild();
453 void logAlgorithmInfo()
const;
455 bool executeInternal();
457 bool executeAsyncImpl(
const Poco::Void &i);
459 bool doCallProcessGroups(Mantid::Types::Core::DateAndTime &start_time);
462 void reportCompleted(
const double &duration,
const bool groupProcessing =
false);
464 void registerFeatureUsage()
const;
466 bool isCompoundProperty(
const std::string &
name)
const;
470 std::unique_ptr<Poco::ActiveMethod<bool, Poco::Void, Algorithm, Poco::ActiveStarter<Algorithm>>>
m_executeAsync;
538#define DECLARE_ALGORITHM(classname) \
540 Mantid::Kernel::RegistrationHelper \
541 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.