12#include "MantidAPI/DllConfig.h"
27#include "MantidParallel/ExecutionMode.h"
28#include "MantidParallel/StorageMode.h"
33class NotificationCenter;
45using time_point_ns = std::chrono::time_point<std::chrono::high_resolution_clock>;
48class SpectrumIndexSet;
101 std::string name()
const override;
108 std::string name()
const override;
119 int progressPrecision);
120 std::string name()
const override;
134 std::string name()
const override;
148 const char *what()
const noexcept override;
160 const std::string
name()
const override = 0;
166 const std::string
summary()
const override = 0;
169 const std::string
category()
const override {
return "Misc"; }
171 const std::vector<std::string> categories()
const override;
177 const std::vector<std::string>
seeAlso()
const override {
return {}; };
179 const std::string
alias()
const override {
return ""; }
181 bool calledByAlias =
false;
189 const std::string
helpURL()
const override {
return ""; }
191 template <typename T, typename = typename std::enable_if<std::is_convertible<T *, MatrixWorkspace *>::value>::type>
194 template <
typename T1,
typename T2,
195 typename =
typename std::enable_if<std::is_convertible<T1 *, MatrixWorkspace *>::value>::type,
196 typename =
typename std::enable_if<std::is_convertible<T2 *, std::string *>::value ||
197 std::is_convertible<T2 *, std::vector<int64_t> *>
::value>::type>
201 template <
typename T1,
typename T2,
202 typename =
typename std::enable_if<std::is_convertible<T1 *, MatrixWorkspace *>::value>::type,
203 typename =
typename std::enable_if<std::is_convertible<T2 *, std::string *>::value ||
204 std::is_convertible<T2 *, std::vector<int64_t> *>
::value>::type>
207 const std::string workspaceMethodName()
const override;
208 const std::vector<std::string> workspaceMethodOn()
const override;
209 const std::string workspaceMethodInputProperty()
const override;
216 void initialize()
override;
217 bool execute() override final;
219 void executeAsChildAlg() override;
220 std::map<
std::
string,
std::
string> validateInputs() override;
226 bool isInitialized() const override;
227 bool isExecuted() const override;
228 bool isRunning() const override;
229 bool isReadyForGarbageCollection() const override;
231 bool isChild() const override;
232 void setChild(const
bool isChild) override;
233 void enableHistoryRecordingForChild(const
bool on) override;
234 bool isRecordingHistoryForChild() {
return m_recordHistoryForChild; }
235 void setAlwaysStoreInADS(
const bool doStore)
override;
236 bool getAlwaysStoreInADS()
const override;
237 void setRethrows(
const bool rethrow)
override;
243 void addObserver(
const Poco::AbstractObserver &observer)
const override;
246 void removeObserver(
const Poco::AbstractObserver &observer)
const override;
249 void cancel()
override;
250 bool getCancel()
const;
253 void setLogging(
const bool value)
override;
254 bool isLogging()
const override;
255 void setLoggingOffset(
const int value)
override;
256 int getLoggingOffset()
const override;
258 void setAlgStartupLogging(
const bool enabled)
override;
260 bool getAlgStartupLogging()
const override;
270 std::string toString()
const override;
272 ::Json::Value toJson()
const override;
281 virtual std::shared_ptr<Algorithm> createChildAlgorithm(
const std::string &name,
const double startProgress = -1.,
282 const double endProgress = -1.,
283 const bool enableLogging =
true,
const int &version = -1);
284 void setupAsChildAlgorithm(
const Algorithm_sptr &algorithm,
const double startProgress = -1.,
285 const double endProgress = -1.,
const bool enableLogging =
true);
289 void trackAlgorithmHistory(std::shared_ptr<AlgorithmHistory> parentHist);
293 void findWorkspaces(
WorkspaceVector &workspaces,
unsigned int direction,
bool checkADS =
false)
const;
296 virtual bool checkGroups();
298 virtual bool processGroups();
300 void copyNonWorkspaceProperties(
IAlgorithm *alg,
int periodNum);
302 const Parallel::Communicator &communicator()
const;
303 void setCommunicator(
const Parallel::Communicator &communicator);
306 void declareProperty(std::unique_ptr<Kernel::Property> p,
const std::string &doc =
"")
override;
309 void declareOrReplaceProperty(std::unique_ptr<Kernel::Property> p,
const std::string &doc =
"")
override;
310 void resetProperties()
override;
311 using IPropertyManager::declareProperty;
313 void setProperties(
const std::string &propertiesJson,
314 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
315 bool createMissing =
false)
override;
318 void setProperties(const ::Json::Value &jsonValue,
319 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>(),
320 bool createMissing =
false)
override;
323 void setPropertiesWithString(
324 const std::string &propertiesString,
325 const std::unordered_set<std::string> &ignoreProperties = std::unordered_set<std::string>())
override;
327 void setPropertyValue(
const std::string &name,
const std::string &
value)
override;
328 void setPropertyValueFromJson(
const std::string &name,
const Json::Value &
value)
override;
329 void setPropertyOrdinal(
const int &
index,
const std::string &
value)
override;
334 bool existsProperty(
const std::string &name)
const override;
335 bool validateProperties()
const override;
336 size_t propertyCount()
const override;
338 std::string getPropertyValue(
const std::string &name)
const override;
339 const std::vector<Kernel::Property *> &getProperties()
const override;
340 std::vector<std::string> getDeclaredPropertyNames() const noexcept override;
343 TypedValue getProperty(const
std::
string &name) const override;
346 std::
string asString(
bool withDefaultValues = false) const override;
349 ::
Json::Value asJson(
bool withDefaultValues = false) const override;
351 bool isDefault(const
std::
string &name) const;
354 void removeProperty(const
std::
string &name, const
bool delproperty = true) override;
356 std::unique_ptr<Kernel::
Property> takeProperty(const
size_t index) override;
359 void clear() override;
363 void afterPropertySet(const
std::
string &) override;
365 void filterByTime(const Types::Core::DateAndTime & , const Types::Core::DateAndTime & )
override {
366 throw(std::runtime_error(
"Not yet implmented"));
369 std::vector<Kernel::PropertyManager *> )
const override {
370 throw(std::runtime_error(
"Not yet implmented"));
375 throw(std::runtime_error(
"Not yet implmented"));
377 Kernel::Property *getPointerToProperty(
const std::string &name)
const override;
386 void exec(Parallel::ExecutionMode executionMode);
387 virtual void execDistributed();
388 virtual void execMasterOnly();
390 virtual Parallel::ExecutionMode
391 getParallelExecutionMode(
const std::map<std::string, Parallel::StorageMode> &storageModes)
const;
397 void cacheWorkspaceProperties();
398 void cacheInputWorkspaceHistories();
407 void progress(
double p,
const std::string &msg =
"",
double estimatedTime = 0.0,
int progressPrecision = 0);
408 void interruption_point();
411 Poco::NotificationCenter ¬ificationCenter()
const;
415 void handleChildProgressNotification(
const Poco::AutoPtr<ProgressNotification> &pNf);
417 const Poco::AbstractObserver &progressObserver()
const;
421 template <
typename NumT>
static bool isEmpty(
const NumT toCheck);
427 bool trackingHistory();
430 virtual void fillHistory();
441 virtual void setOtherProperties(
IAlgorithm *alg,
const std::string &propertyName,
const std::string &propertyValue,
463 bool m_usingBaseProcessGroups =
false;
465 template <typename T, const int AllowedIndexTypes = static_cast<int>(IndexType::WorkspaceIndex),
466 typename... WSPropArgs,
467 typename =
typename std::enable_if<std::is_convertible<T *, MatrixWorkspace *>::value>::type>
469 WSPropArgs &&...wsPropArgs);
472 template <
typename T1,
typename T2,
typename WsType>
474 void lockWorkspaces();
476 void unlockWorkspaces();
478 void clearWorkspaceCaches();
480 void linkHistoryWithLastChild();
482 void logAlgorithmInfo()
const;
484 bool executeInternal();
486 bool executeAsyncImpl(
const Poco::Void &i);
488 bool doCallProcessGroups(Mantid::Types::Core::DateAndTime &start_time);
490 void fillHistory(
const std::vector<Workspace_sptr> &outputWorkspaces);
493 void reportCompleted(
const double &duration,
const bool groupProcessing =
false);
495 void registerFeatureUsage()
const;
497 Parallel::ExecutionMode getExecutionMode()
const;
498 std::map<std::string, Parallel::StorageMode> getInputWorkspaceStorageModes()
const;
499 void setupSkipValidationMasterOnly();
501 bool isCompoundProperty(
const std::string &name)
const;
505 std::unique_ptr<Poco::ActiveMethod<bool, Poco::Void, Algorithm, Poco::ActiveStarter<Algorithm>>>
m_executeAsync;
576#define DECLARE_ALGORITHM(classname) \
578 Mantid::Kernel::RegistrationHelper \
579 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...
virtual const std::string workspaceMethodOnTypes() const
Returns a semi-colon separated list of workspace types to attach this algorithm.
void doSetInputProperties(const std::string &name, const T1 &wksp, IndexType type, const T2 &list)
void setWorkspaceInputProperties(const std::string &name, const std::string &wsName, IndexType type, const T2 &list)
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.
void declareWorkspaceInputProperties(const std::string &propertyName, const std::string &doc, WSPropArgs &&...wsPropArgs)
double m_startChildProgress
Whether to log alg startup and closedown messages from the base class (default = true)
void filterByProperty(const Kernel::TimeSeriesProperty< bool > &, const std::vector< std::string > &) override
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.
virtual void init()=0
Virtual method - must be overridden by concrete algorithm.
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
void splitByTime(std::vector< Kernel::SplittingInterval > &, std::vector< Kernel::PropertyManager * >) const override
void setWorkspaceInputProperties(const std::string &name, const std::shared_ptr< T1 > &wksp, IndexType type, const T2 &list)
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.
virtual void exec()=0
Virtual method - must be overridden by concrete 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.
std::unique_ptr< Parallel::Communicator > m_communicator
(MPI) communicator used when executing the algorithm.
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.
std::tuple< std::shared_ptr< T >, Indexing::SpectrumIndexSet > getWorkspaceAndIndices(const std::string &name) const
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.
A specialised Property class for holding a series of time-value pairs.
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
Helper class which provides the Collimation Length for SANS instruments.