20#include "MantidJson/Json.h"
31#include <Poco/ActiveMethod.h>
32#include <Poco/ActiveResult.h>
33#include <Poco/NotificationCenter.h>
34#include <Poco/RWLock.h>
55const std::string WORKSPACE_TYPES_SEPARATOR =
";";
59const size_t DELAY_BEFORE_GC = 5;
61class WorkspacePropertyValueIs {
65 auto *prop =
dynamic_cast<Property *
>(property);
75template <
typename T>
struct RunOnFinish {
76 RunOnFinish(T &&task) :
m_onfinsh(std::move(task)) {}
90 return static_cast<int>(toCheck) ==
EMPTY_INT();
98template MANTID_API_DLL
bool Algorithm::isEmpty<int>(
const int);
99template MANTID_API_DLL
bool Algorithm::isEmpty<int64_t>(
const int64_t);
100template MANTID_API_DLL
bool Algorithm::isEmpty<std::size_t>(
const std::size_t);
113 : m_cancel(false), m_parallelException(false), m_log(
"Algorithm"),
g_log(m_log), m_groupSize(0),
114 m_executeAsync(nullptr), m_notificationCenter(nullptr), m_progressObserver(nullptr),
116 m_isChildAlgorithm(false), m_recordHistoryForChild(false), m_alwaysStoreInADS(true), m_runningAsync(false),
117 m_rethrow(false), m_isAlgStartupLoggingEnabled(true), m_startChildProgress(0.), m_endChildProgress(0.),
118 m_algorithmID(this), m_singleGroup(-1), m_groupsHaveSimilarNames(false), m_inputWorkspaceHistories(),
216 (Mantid::Types::Core::DateAndTime::getCurrentTime() >
m_gcTime)) {
260 if (depo !=
nullptr) {
261 res.emplace_back(
"Deprecated");
308 }
catch (std::runtime_error &) {
315 }
catch (std::runtime_error &) {
350 for (
const auto &prop : props) {
354 switch (prop->direction()) {
367 throw std::logic_error(
"Unexpected property direction found for property " + prop->name() +
" of algorithm " +
404 const auto &ads = AnalysisDataService::Instance();
407 for (
const auto &prop : props) {
412 if (
auto ws = wsProp->getWorkspace()) {
417 wsFromADS = ads.retrieve(prop->value());
421 cacheHistories(wsFromADS);
423 }
else if (
auto strArrayProp =
dynamic_cast<ArrayPropertyString *
>(prop)) {
424 if (!isADSValidator(strArrayProp->getValidator()))
426 const auto &wsNames((*strArrayProp)());
427 for (
const auto &wsName : wsNames) {
428 cacheHistories(ads.retrieve(wsName));
445 throw std::logic_error(
"Algorithm::lockWorkspaces(): The workspaces have "
446 "already been locked!");
458 debugLog <<
"Write-locking " << ws->getName() <<
'\n';
459 ws->getLock()->writeLock();
474 debugLog <<
"Read-locking " << ws->getName() <<
'\n';
475 ws->getLock()->readLock();
493 debugLog <<
"Unlocking " << ws->getName() <<
'\n';
494 ws->getLock()->unlock();
499 debugLog <<
"Unlocking " << ws->getName() <<
'\n';
500 ws->getLock()->unlock();
528 bool algIsExecuted =
false;
529 AlgorithmManager::Instance().notifyAlgorithmStarting(this->
getAlgorithmID());
551 Mantid::Types::Core::DateAndTime startTime;
555 throw std::runtime_error(
"Algorithm is not initialised:" + this->
name());
563 constexpr bool resetTimer{
true};
564 float timingInit = timer.
elapsed(resetTimer);
568 for (
auto &prop : props) {
570 if (wsProp && !(wsProp->getWorkspace())) {
572 prop->setValue(prop->value());
578 throw std::runtime_error(
"Some invalid Properties found");
581 const float timingPropertyValidation = timer.
elapsed(resetTimer);
590 bool callProcessGroups =
true;
594 }
catch (std::exception &ex) {
595 getLogger().
error() <<
"Error in execution of algorithm " << this->
name() <<
"\n" << ex.what() <<
"\n";
605 timingInit += timer.
elapsed(resetTimer);
607 if ((!callProcessGroups))
609 std::map<std::string, std::string> errors = this->
validateInputs();
610 if (!errors.empty()) {
611 size_t numErrors = errors.size();
615 for (
auto &
error : errors) {
617 errorLog <<
"Invalid value for " <<
error.first <<
": " <<
error.second <<
"\n";
620 warnLog <<
"validateInputs() references non-existant property \"" <<
error.first <<
"\"\n";
625 std::stringstream msg;
626 msg <<
"Some invalid Properties found: ";
627 for (
const auto &
error : errors) {
628 msg <<
"\n " <<
error.first <<
": " <<
error.second;
631 throw std::runtime_error(msg.str());
635 const float timingInputValidation = timer.
elapsed(resetTimer);
647 m_history = std::make_shared<AlgorithmHistory>(algHist);
653 if (callProcessGroups) {
659 timingInit += timer.
elapsed(resetTimer);
666 startTime = Mantid::Types::Core::DateAndTime::getCurrentTime();
672 const float timingExec = timer.
elapsed(resetTimer);
674 const float duration = timingInit + timingPropertyValidation + timingInputValidation + timingExec;
689 algIsExecuted =
true;
693 "Time for other input validation: " +
std::to_string(timingInputValidation) +
" seconds\n" +
694 "Time for other initialization: " +
std::to_string(timingInit) +
" seconds\n" +
695 "Time to run exec: " +
std::to_string(timingExec) +
" seconds\n");
697 }
catch (std::runtime_error &ex) {
698 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
699 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
706 getLogger().
error() <<
"Error in execution of algorithm " << this->
name() <<
'\n' << ex.what() <<
'\n';
709 }
catch (std::logic_error &ex) {
710 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
711 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
718 getLogger().
error() <<
"Logic Error in execution of algorithm " << this->
name() <<
'\n' << ex.what() <<
'\n';
724 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
725 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
733 catch (std::exception &ex) {
735 getLogger().
error() <<
"Error in execution of algorithm " << this->
name() <<
":\n" << ex.what() <<
"\n";
736 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
737 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
745 catch (H5::Exception &ex) {
748 errmsg.append(ex.getCFuncName()).append(
": ").append(ex.getCDetailMsg());
749 getLogger().
error() <<
"H5 Exception in execution of algorithm " << this->
name() <<
":\n" << errmsg <<
"\n";
750 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
751 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
763 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
764 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
773 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
774 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
794 bool executed =
false;
797 }
catch (std::runtime_error &) {
802 throw std::runtime_error(
"Unable to successfully run ChildAlgorithm " + this->
name());
813 std::vector<int> groupWsIndicies;
816 for (
unsigned int i = 0; i < props.size(); ++i) {
821 auto group = std::dynamic_pointer_cast<WorkspaceGroup>(wsProp->getWorkspace());
825 }
catch (std::runtime_error &) {
829 groupWsIndicies.emplace_back(i);
835 std::vector<int>::const_iterator wsIndex;
836 for (wsIndex = groupWsIndicies.begin(); wsIndex != groupWsIndicies.end(); ++wsIndex) {
841 }
catch (std::runtime_error &) {
867 const double endProgress,
const bool enableLogging,
const int &version) {
880 const bool enableLogging) {
883 alg->setLogging(enableLogging);
888 }
catch (std::runtime_error &) {
889 throw std::runtime_error(
"Unable to initialise Child Algorithm '" + alg->name() +
"'");
894 const std::vector<Property *> &props = alg->getProperties();
895 for (
auto prop : props) {
898 if (prop->value().empty() && !wsProp->isOptional()) {
899 prop->createTemporaryValue();
904 if (startProgress >= 0.0 && endProgress > startProgress && endProgress <= 1.0) {
915 std::weak_ptr<IAlgorithm> weakPtr(alg);
938 root[
"name"] =
name();
939 root[
"version"] = this->
version();
955 ::Json::Value jsonMap;
957 auto props =
history.getProperties();
958 const size_t numProps(props.size());
959 for (
size_t i = 0; i < numProps; ++i) {
961 if (!prop->isDefault()) {
962 jsonMap[prop->name()] = prop->value();
967 root[
"version"] =
history.version();
968 root[
"properties"] = jsonMap;
970 const std::string output = Mantid::JsonHelpers::jsonToString(root);
975 }
catch (std::invalid_argument &) {
976 throw std::runtime_error(
"Could not create algorithm from history. "
977 "Is this a child algorithm whose workspaces are not in the ADS?");
993 if (Mantid::JsonHelpers::parse(input, &root)) {
996 throw std::runtime_error(
"Cannot create algorithm, invalid string format.");
1008 const std::string algName = serialized[
"name"].asString();
1009 const int versionNumber = serialized.get(
"version", -1).asInt();
1010 auto alg = AlgorithmManager::Instance().createUnmanaged(algName, versionNumber);
1012 alg->setProperties(serialized[
"properties"]);
1040 for (
const auto &prop : algProperties) {
1051 bool linked =
false;
1053 const auto &childHistories =
m_history->getChildHistories();
1054 auto childIter = childHistories.rbegin();
1055 for (; childIter != childHistories.rend() && !linked; ++childIter) {
1056 const auto &props = (*childIter)->getProperties();
1057 auto propIter = props.begin();
1058 for (; propIter != props.end() && !linked; ++propIter) {
1063 std::ostringstream os;
1064 os <<
"__TMP" << wsProp->getWorkspace().get();
1065 if (os.str() == (*propIter)->value()) {
1066 (*propIter)->setValue(prop->value());
1099 const std::string &strValue,
bool checkADS) {
1105 if (checkADS && !strValue.empty()) {
1106 return ads.retrieve(strValue);
1120 const auto &ads = AnalysisDataService::Instance();
1121 for (
const auto &prop : algProperties) {
1122 const unsigned int propDirection = prop->direction();
1126 appendWS(workspaceFromWSProperty(*wsProp, ads, prop->value(), checkADS));
1136 logger.notice() <<
name() <<
" started";
1138 logger.notice() <<
" (child)";
1139 logger.notice() <<
'\n';
1143 size_t maxPropertyLength = 40;
1144 if (logger.is(Logger::Priority::PRIO_DEBUG)) {
1146 maxPropertyLength = 0;
1148 algHistory.
printSelf(logger.information(), 0, maxPropertyLength);
1179 size_t numGroups = 0;
1180 bool doProcessGroups =
false;
1183 const auto &ads = AnalysisDataService::Instance();
1187 auto const prop =
dynamic_cast<Property *
>(inputWorkspaceProp);
1190 auto wsGroup = std::dynamic_pointer_cast<WorkspaceGroup>(ws);
1195 if (!wsGroup && prop && !prop->value().empty()) {
1205 if (wsGroup && !wsGroupProp) {
1207 doProcessGroups =
true;
1223 return doProcessGroups;
1235 throw std::invalid_argument(
"Empty group passed as input");
1236 if (!thisGroup.empty()) {
1239 if (wsGroup && (numGroups == 1))
1243 if (thisGroup.size() > 1) {
1247 throw std::invalid_argument(
"Input WorkspaceGroups are not of the same size.");
1260 return doProcessGroups;
1277 startTime = Mantid::Types::Core::DateAndTime::getCurrentTime();
1280 bool completed =
false;
1284 }
catch (std::exception &ex) {
1305 const float duration = timer.
elapsed();
1315 const bool checkADS{
true};
1351 for (
auto &outGroupItem : out) {
1352 outGroupItem->history().addHistory(in.
getHistory());
1356 for (
auto &outWS : outputWorkspaces) {
1357 auto outWSGroup = std::dynamic_pointer_cast<WorkspaceGroup>(outWS);
1361 copyHistoryToGroup(*inputWS, *outWSGroup);
1363 outWS->history().addHistory(inputWS->getHistory());
1368 for (
auto &outGroupItem : *outWSGroup) {
1369 outGroupItem->history().addHistory(
m_history);
1399 std::vector<WorkspaceGroup_sptr> outGroups;
1403 auto *prop =
dynamic_cast<Property *
>(pureOutputWorkspaceProp);
1404 if (prop && !prop->value().empty()) {
1405 auto outWSGrp = std::make_shared<WorkspaceGroup>();
1406 outGroups.emplace_back(outWSGrp);
1408 AnalysisDataService::Instance().addOrReplace(prop->value(), outWSGrp);
1411 *workspaceProperty = outputWorkspace;
1413 outWSGrp->observeADSNotifications(
false);
1417 double progress_proportion = 1.0 /
static_cast<double>(
m_groupSize);
1419 for (
size_t entry = 0; entry <
m_groupSize; entry++) {
1422 progress_proportion * (1 +
static_cast<double>(entry)),
1426 alg_sptr->setChild(
true);
1427 alg_sptr->setAlwaysStoreInADS(
true);
1428 alg_sptr->enableHistoryRecordingForChild(
false);
1429 alg_sptr->setRethrows(
true);
1435 std::string outputBaseName;
1440 if (!thisGroup.empty()) {
1448 if (entry < thisGroup.size()) {
1449 ws = thisGroup[entry];
1459 throw std::runtime_error(
"Unable to process over groups; consider passing workspaces "
1460 "one-by-one or override processGroup method of the algorithm.");
1464 if (!outputBaseName.empty())
1465 outputBaseName +=
"_";
1466 outputBaseName += ws->getName();
1470 if (ws->getName().empty()) {
1476 throw std::logic_error(
"Found a Workspace property which doesn't "
1477 "inherit from Property.");
1487 const std::string inName = prop->value();
1490 std::string outName;
1494 outName.append(outputBaseName).append(
"_").append(inName);
1506 if (!inputGroup.empty())
1507 outName = inputGroup[entry]->getName();
1514 outputWSNames[owp] = outName;
1516 throw std::logic_error(
"Found a Workspace property which doesn't "
1517 "inherit from Property.");
1524 }
catch (std::exception &e) {
1525 std::ostringstream msg;
1526 msg <<
"Execution of " << this->
name() <<
" for group entry " << (entry + 1) <<
" failed: ";
1528 throw std::runtime_error(msg.str());
1536 if (prop && prop->value().empty())
1539 outGroups[owp]->add(outputWSNames[owp]);
1545 for (
auto &outGroup : outGroups) {
1546 outGroup->observeADSNotifications(
true);
1560 throw std::runtime_error(
"Algorithm not created!");
1562 for (
const auto &prop : props) {
1599 return (wsProp !=
nullptr);
1610struct AsyncFlagHolder {
1620 AsyncFlagHolder() =
delete;
1669 m_progressObserver = std::make_unique<Poco::NObserver<Algorithm, ProgressNotification>>(
1686 sharedPtr->cancel();
1733 std::string optionalMessage;
1734 if (groupProcessing) {
1735 optionalMessage =
". Processed as a workspace group";
1741 std::stringstream msg;
1742 msg <<
name() <<
" successful, Duration ";
1743 double seconds = duration;
1744 if (seconds > 60.) {
1745 auto minutes =
static_cast<int>(seconds / 60.);
1746 msg << minutes <<
" minutes ";
1747 seconds = seconds -
static_cast<double>(minutes) * 60.;
1749 msg << std::fixed << std::setprecision(2) << seconds <<
" seconds" << optionalMessage;
1763 if (UsageService::Instance().isEnabled()) {
1764 std::ostringstream oss;
1766 UsageService::Instance().registerFeatureUsage(FeatureType::Algorithm, oss.str(),
isChild());
1789 :
Poco::Notification(), m_algorithm(alg) {}
1801 double estimatedTime,
int progressPrecision)
1803 progressPrecision(progressPrecision) {}
1848 const std::unordered_set<std::string> &ignoreProperties,
bool createMissing) {
1859 bool createMissing) {
1870 const std::unordered_set<std::string> &ignoreProperties) {
2060 std::string message =
"Attempt to assign property " +
name +
" to incorrect type. Expected shared_ptr<IAlgorithm>";
2061 throw std::runtime_error(message);
2073IPropertyManager::getValue<API::IAlgorithm_const_sptr>(
const std::string &
name)
const {
2076 return prop->operator()();
2078 std::string message =
2079 "Attempt to assign property " +
name +
" to incorrect type. Expected const shared_ptr<IAlgorithm>";
2080 throw std::runtime_error(message);
const std::string & m_value
bool & m_running_flag
Running flag.
double value
The value of the point.
IPeaksWorkspace_sptr workspace
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_CRITICAL(name)
std::vector< history_type > history
history information
ADSValidator : a validator that requires the value of a property to be present in the ADS.
This class stores information about the Command History used by algorithms on a workspace.
void printSelf(std::ostream &, const int indent=0, const size_t maxPropertyLength=0) const
print contents of object
Base class for algorithm notifications.
AlgorithmNotification(const Algorithm *const alg)
const IAlgorithm * algorithm() const
CancelException is thrown to cancel execution of the algorithm.
const char * what() const noexcept override
Returns the message string.
ErrorNotification is sent when an exception is caught during execution of the algorithm.
std::string name() const override
ErrorNotification(const Algorithm *const alg, std::string str)
Constructor.
FinishedNotification is sent after the algorithm finishes its execution.
std::string name() const override
FinishedNotification(const Algorithm *const alg, bool res)
An algorithm can report its progress by sending ProgressNotification.
ProgressNotification(const Algorithm *const alg, double p, std::string msg, double estimatedTime, int progressPrecision)
Constructor.
std::string name() const override
StartedNotification is sent when the algorithm begins execution.
StartedNotification(const Algorithm *const alg)
std::string name() const override
class name
Base class from which all concrete algorithm classes should be derived.
void clearWorkspaceCaches()
Clear any internal workspace handles so that workspaces will be deleted promptly after a managed algo...
void setRethrows(const bool rethrow) override
Set whether the algorithm will rethrow exceptions.
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.
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
void store()
Stores any output workspaces into the AnalysisDataService.
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...
bool isRunning() const override
True if the algorithm is running.
void setExecutionState(const ExecutionState state)
Sets the current execution state.
virtual const std::string workspaceMethodOnTypes() const
Returns a semi-colon separated list of workspace types to attach this algorithm.
Kernel::Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
const std::string workspaceMethodName() const override
bool calledByAlias
Flag to indicate if the algorithm is called by its alias.
std::vector< std::string > getDeclaredPropertyNames() const noexcept override
Return the list of declared property names.
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.
void clear() override
Clears all properties under management.
std::vector< IWorkspaceProperty * > m_inputWorkspaceProps
All the WorkspaceProperties that are Input or InOut. Set in execute()
bool isExecuted() const override
Has the Algorithm already been executed successfully.
::Json::Value asJson(bool withDefaultValues=false) const override
Return the property manager serialized as a json object.
void registerFeatureUsage() const
Registers the usage of the algorithm with the UsageService.
bool existsProperty(const std::string &name) const override
Checks whether the named property is already in the list of managed property.
WorkspaceVector m_writeLockedWorkspaces
Vector of all the workspaces that have been write-locked.
bool m_rethrow
Algorithm should rethrow exceptions while executing.
bool validateProperties() const override
Validates all the properties in the collection.
double m_startChildProgress
Whether to log alg startup and closedown messages from the base class (default = true)
void setPropertyOrdinal(const int &index, const std::string &value) override
Set the value of a property by an index N.B.
void afterPropertySet(const std::string &) override
Override this method to perform a custom action right after a property was set.
bool m_usingBaseProcessGroups
distinguish between base processGroups() and overriden/algorithm specific versions
void setAlgStartupLogging(const bool enabled) override
disable Logging of start and end messages
void removeProperty(const std::string &name, const bool delproperty=true) override
Removes the property from management.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
std::vector< std::weak_ptr< IAlgorithm > > m_ChildAlgorithms
A list of weak pointers to any child algorithms created.
Kernel::Property * getPointerToPropertyOrdinal(const int &index) const override
Get a property by an index.
std::unique_ptr< Kernel::Property > takeProperty(const size_t index) override
Removes the property from management and returns a pointer to it.
bool m_recordHistoryForProcessGroups
Opt-in for overridden processGroups() implementations that want the parent algorithm history recorded...
void copyNonWorkspaceProperties(IAlgorithm *alg, int periodNum)
Copy all the non-workspace properties from this to alg.
std::atomic< bool > m_cancel
Set to true to stop execution.
void setLogging(const bool value) override
Logging can be disabled by passing a value of false.
std::shared_ptr< AlgorithmHistory > m_parentHistory
Pointer to the parent history object (if set)
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
virtual void fillHistory()
Copy workspace history from input workspaces to output workspaces and record the history for ths algo...
void setResultState(const ResultState state)
Sets the result execution state.
void handleChildProgressNotification(const Poco::AutoPtr< ProgressNotification > &pNf)
Observation slot for child algorithm progress notification messages, these are scaled and then signal...
void addObserver(const Poco::AbstractObserver &observer) const override
Add an observer for a notification.
std::string toString() const override
Serialize an object to a string.
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()
void initialize() override
Initialization method invoked by the framework.
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
std::vector< IWorkspaceProperty * > m_pureOutputWorkspaceProps
All the WorkspaceProperties that are Output (not inOut). Set in execute()
size_t propertyCount() const override
Count the number of properties under management.
bool isChild() const override
To query whether algorithm is a child.
void setLoggingOffset(const int value) override
gets the logging priority offset
size_t m_groupSize
Size of the group(s) being processed.
static IAlgorithm_sptr fromString(const std::string &input)
De-serialize an object from a string.
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 progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
virtual void setOtherProperties(IAlgorithm *alg, const std::string &propertyName, const std::string &propertyValue, int periodNum)
Virtual method to set the non workspace properties for this algorithm.
bool isInitialized() const override
Has the Algorithm already been initialized.
bool m_alwaysStoreInADS
Always store in the ADS, even for child algos.
ExecutionState executionState() const override
Gets the current execution state.
bool m_isAlgStartupLoggingEnabled
bool trackingHistory()
get whether we are tracking the history for this algorithm,
bool execute() override final
The actions to be performed by the algorithm on a dataset.
void setAlwaysStoreInADS(const bool doStore) override
Do we ALWAYS store in the AnalysisDataService? This is set to true for python algorithms' child algor...
void linkHistoryWithLastChild()
Link the name of the output workspaces on this parent algorithm.
bool isLogging() const override
returns the status of logging, True = enabled
bool getAlgStartupLogging() const override
get the state of Logging of start and end messages
bool isWorkspaceProperty(const Kernel::Property *const prop) const
checks the property is a workspace property
void setProperties(const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false) override
Set the ordered list of properties by one string of values, separated by semicolons.
std::atomic< ResultState > m_resultState
the current result State
bool isReadyForGarbageCollection() const override
True if the algorithm is ready for garbage collection.
Poco::NotificationCenter & notificationCenter() const
Return a reference to the algorithm's notification dispatcher.
int getLoggingOffset() const override
returns the logging priority offset
std::unique_ptr< Poco::ActiveMethod< bool, Poco::Void, Algorithm, Poco::ActiveStarter< Algorithm > > > m_executeAsync
Poco::ActiveMethod used to implement asynchronous execution.
std::vector< WorkspaceVector > m_unrolledInputWorkspaces
One vector of workspaces for each input workspace property.
void resetProperties() override
Reset property values back to initial values (blank or default values)
void removeObserver(const Poco::AbstractObserver &observer) const override
Remove an observer.
void logAlgorithmInfo() const
Sends out algorithm parameter information to the logger.
void reportCompleted(const double &duration, const bool groupProcessing=false)
Report that the algorithm has completed.
bool m_isChildAlgorithm
Algorithm is a child algorithm.
bool getAlwaysStoreInADS() const override
Returns true if we always store in the AnalysisDataService.
void setPropertiesWithString(const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >()) override
Sets all the declared properties from a string.
bool executeInternal()
Invoced internally in execute()
Mantid::Kernel::PropertyManagerOwner m_properties
ResultState resultState() const override
Gets the current result State.
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.
void executeAsChildAlg() override
Execute as a Child Algorithm.
bool isDefault(const std::string &name) const
void trackAlgorithmHistory(std::shared_ptr< AlgorithmHistory > parentHist)
set whether we wish to track the child algorithm's history and pass it the parent object to fill.
const std::string workspaceMethodInputProperty() const override
std::string asString(bool withDefaultValues=false) const override
Return the property manager serialized as a string.
void declareOrReplaceProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add or replace property in the list of managed properties.
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
const std::vector< std::string > categories() const override
Function to return all of the categories that contain this algorithm.
void cancel() override
Raises the cancel flag.
const std::vector< std::string > workspaceMethodOn() const override
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
~Algorithm() override
Virtual destructor.
void enableHistoryRecordingForChild(const bool on) override
Change the state of the history recording flag.
bool m_runningAsync
Algorithm is running asynchronously.
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.
bool m_groupsHaveSimilarNames
All the groups have similar names (group_1, group_2 etc.)
Poco::ActiveResult< bool > executeAsync() override
Asynchronous execution.
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
void lockWorkspaces()
Go through the workspace properties of this algorithm and lock the workspaces for reading or writing.
void setupAsChildAlgorithm(const Algorithm_sptr &algorithm, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true)
Setup algorithm as child algorithm.
bool getCancel() const
Returns the cancellation state.
bool doCallProcessGroups(Mantid::Types::Core::DateAndTime &start_time)
Calls process groups with the required timing checks and algorithm execution finalization steps.
void cacheWorkspaceProperties()
Go through the properties and cache the input/output workspace properties for later use.
::Json::Value toJson() const override
Serialize an object to a json object.
void findWorkspaces(WorkspaceVector &workspaces, unsigned int direction, bool checkADS=false) const
Populate lists of the workspace properties for a given direction (InOut workspaces are included in bo...
Kernel::Logger & getLogger() const
Returns a reference to the logger.
void cacheInputWorkspaceHistories()
Cache the histories of any input workspaces so they can be copied over after algorithm completion.
double m_endChildProgress
Keeps value for algorithm's progress at Child Algorithm's finish.
virtual bool checkGroups()
Check the input workspace properties for groups.
bool isCompoundProperty(const std::string &name) const
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.
void setChild(const bool isChild) override
To set whether algorithm is a child.
void setPropertyValueFromJson(const std::string &name, const Json::Value &value) override
Set the value of a property by Json::Value object.
static size_t g_execCount
Counter to keep track of algorithm execution order.
bool m_recordHistoryForChild
Flag to indicate whether history should be recorded.
static IAlgorithm_sptr fromHistory(const AlgorithmHistory &history)
Construct an object from a history entry.
static IAlgorithm_sptr fromJson(const Json::Value &input)
De-serialize an object from a Json.
void unlockWorkspaces()
Unlock any previously locked workspaces.
const std::vector< Kernel::Property * > & getProperties() const override
Get the list of managed properties.
virtual bool processGroups()
Process WorkspaceGroup inputs.
const std::string name() const override=0
function to return a name of the algorithm, must be overridden in all algorithms
bool executeAsyncImpl(const Poco::Void &i)
Callback when an algorithm is executed asynchronously.
const Poco::AbstractObserver & progressObserver() const
Return a reference to the algorithm's object that is reporting progress.
void enableHistoryRecordingForProcessGroups(const bool on) override
Change the state of the processGroups history recording flag.
The Analysis data service stores instances of the Workspace objects and anything that derives from te...
Class for marking algorithms as deprecated.
DeprecatedAlias : Class for making algorithm with deprecated names (aliases).
IAlgorithm is the interface implemented by the Algorithm base class.
virtual const std::string name() const =0
function to return a name of the algorithm, must be overridden in all algorithms
An interface that is implemented by WorkspaceProperty.
virtual bool store()=0
Store a workspace into the AnalysisDataService.
virtual Workspace_sptr getWorkspace() const =0
Get a pointer to the workspace.
Class to hold a set of workspaces.
bool areNamesSimilar() const
Are the members of this group of similar names, e.g.
A property class for workspaces.
Workspace_sptr getWorkspace() const override
Get a pointer to the workspace.
Base Workspace Abstract Class.
const WorkspaceHistory & getHistory() const
Returns a reference to the WorkspaceHistory const.
Support for a property that holds an array of values.
Exception for when an item is not found in a collection.
virtual void setPropertyValue(const std::string &name, const std::string &value)=0
Sets property value from a string.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
The Logger class is in charge of the publishing messages from the framework through various channels.
void debug(const std::string &msg)
Logs at debug level.
void notice(const std::string &msg)
Logs at notice level.
void setName(const std::string &name)
Update the name of the logger.
int getLevelOffset() const
Gets the Logger's log offset level.
void error(const std::string &msg)
Logs at error level.
void warning(const std::string &msg)
Logs at warning level.
void setEnabled(const bool enabled)
set if the logging is enabled
bool getEnabled() const
returns true if the log is enabled
void fatal(const std::string &msg)
Logs at Fatal level.
void setLevelOffset(int level)
Sets the Logger's log offset level.
Property * getPointerToProperty(const std::string &name) const override
Get a property by name.
bool validateProperties() const override
Validates all the properties in the collection.
void afterPropertySet(const std::string &) override
Override this method to perform a custom action right after a property was set.
void setProperties(const std::string &propertiesJson, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >(), bool createMissing=false) override
Set the ordered list of properties by one string of values, separated by semicolons.
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
void declareOrReplaceProperty(std::unique_ptr< Property > p, const std::string &doc="") override
Add or replace property in the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
void clear() override
Clears all properties under management.
void setPropertyOrdinal(const int &index, const std::string &value) override
Set the value of a property by an index N.B.
void declareProperty(std::unique_ptr< Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
::Json::Value asJson(bool withDefaultValues=false) const override
Return the property manager serialized as a json object.
void setPropertyValueFromJson(const std::string &name, const Json::Value &value) override
Set the value of a property by Json::Value object.
const std::vector< Property * > & getProperties() const override
Get the list of managed properties.
std::vector< std::string > getDeclaredPropertyNames() const noexcept override
Return the list of declared property names.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
void setPropertiesWithString(const std::string &propertiesString, const std::unordered_set< std::string > &ignoreProperties=std::unordered_set< std::string >()) override
Sets all the declared properties from a string.
bool existsProperty(const std::string &name) const override
Checks whether the named property is already in the list of managed property.
Property * getPointerToPropertyOrdinal(const int &index) const override
Get a property by an index.
size_t propertyCount() const override
Count the number of properties under management.
void removeProperty(const std::string &name, const bool delproperty=true) override
Removes the property from management.
void resetProperties() override
Reset property values back to initial values (blank or default values)
std::unique_ptr< Property > takeProperty(const size_t index) override
Removes the property from management returning a pointer to it.
std::string asString(bool withDefaultValues=false) const override
Return the property manager serialized as a string.
The concrete, templated class for properties.
Base class for properties.
virtual bool isDefault() const =0
Overriden function that returns if property has the same value that it was initialised with,...
const std::string & name() const
Get the property's name.
virtual std::string value() const =0
Returns the value of the property as a string.
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
const TokenVec & asVector()
Returns a vector of tokenized strings.
A simple class that provides a wall-clock (not processor time) timer.
float elapsed(bool reset=true)
Returns the wall-clock time elapsed in seconds since the Timer object's creation, or the last call to...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< const IAlgorithm > IAlgorithm_const_sptr
shared pointer to Mantid::API::IAlgorithm (const version)
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
ResultState
The validity of the results of the algorithm object.
ExecutionState
The current state of the algorithm object.
MANTID_API_DLL void setPropertyModeForWorkspaceProperty(Mantid::Kernel::Property *prop, const PropertyMode::Type &optional)
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Mantid::Kernel::StringTokenizer tokenizer
std::string toString(const T &value)
Convert a number to a string.
std::shared_ptr< PropertyHistory > PropertyHistory_sptr
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Helper class which provides the Collimation Length for SANS instruments.
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
std::string to_string(const wide_integer< Bits, Signed > &n)
@ InOut
Both an input & output workspace.
@ Input
An input workspace.
@ Output
An output workspace.
Utility class that enables the getProperty() method to effectively be templated on the return type.