19#include "MantidJson/Json.h"
30#include <Poco/ActiveMethod.h>
31#include <Poco/ActiveResult.h>
32#include <Poco/NotificationCenter.h>
33#include <Poco/RWLock.h>
54const std::string WORKSPACE_TYPES_SEPARATOR =
";";
58const size_t DELAY_BEFORE_GC = 5;
60class WorkspacePropertyValueIs {
64 auto *prop =
dynamic_cast<Property *
>(property);
74template <
typename T>
struct RunOnFinish {
75 RunOnFinish(T &&task) :
m_onfinsh(std::move(task)) {}
89 return static_cast<int>(toCheck) ==
EMPTY_INT();
97template MANTID_API_DLL
bool Algorithm::isEmpty<int>(
const int);
98template MANTID_API_DLL
bool Algorithm::isEmpty<int64_t>(
const int64_t);
99template MANTID_API_DLL
bool Algorithm::isEmpty<std::size_t>(
const std::size_t);
112 : m_cancel(false), m_parallelException(false), m_log(
"Algorithm"),
g_log(m_log), m_groupSize(0),
113 m_executeAsync(nullptr), m_notificationCenter(nullptr), m_progressObserver(nullptr),
115 m_isChildAlgorithm(false), m_recordHistoryForChild(false), m_alwaysStoreInADS(true), m_runningAsync(false),
116 m_rethrow(false), m_isAlgStartupLoggingEnabled(true), m_startChildProgress(0.), m_endChildProgress(0.),
117 m_algorithmID(this), m_singleGroup(-1), m_groupsHaveSimilarNames(false), m_inputWorkspaceHistories(),
210 (Mantid::Types::Core::DateAndTime::getCurrentTime() >
m_gcTime)) {
254 if (depo !=
nullptr) {
255 res.emplace_back(
"Deprecated");
302 }
catch (std::runtime_error &) {
309 }
catch (std::runtime_error &) {
344 for (
const auto &prop : props) {
348 switch (prop->direction()) {
361 throw std::logic_error(
"Unexpected property direction found for property " + prop->name() +
" of algorithm " +
398 const auto &ads = AnalysisDataService::Instance();
401 for (
const auto &prop : props) {
406 if (
auto ws = wsProp->getWorkspace()) {
411 wsFromADS = ads.retrieve(prop->value());
415 cacheHistories(wsFromADS);
417 }
else if (
auto strArrayProp =
dynamic_cast<ArrayPropertyString *
>(prop)) {
418 if (!isADSValidator(strArrayProp->getValidator()))
420 const auto &wsNames((*strArrayProp)());
421 for (
const auto &wsName : wsNames) {
422 cacheHistories(ads.retrieve(wsName));
439 throw std::logic_error(
"Algorithm::lockWorkspaces(): The workspaces have "
440 "already been locked!");
452 debugLog <<
"Write-locking " << ws->getName() <<
'\n';
453 ws->getLock()->writeLock();
468 debugLog <<
"Read-locking " << ws->getName() <<
'\n';
469 ws->getLock()->readLock();
487 debugLog <<
"Unlocking " << ws->getName() <<
'\n';
488 ws->getLock()->unlock();
493 debugLog <<
"Unlocking " << ws->getName() <<
'\n';
494 ws->getLock()->unlock();
522 bool algIsExecuted =
false;
523 AlgorithmManager::Instance().notifyAlgorithmStarting(this->
getAlgorithmID());
545 Mantid::Types::Core::DateAndTime startTime;
549 throw std::runtime_error(
"Algorithm is not initialised:" + this->
name());
557 constexpr bool resetTimer{
true};
558 float timingInit = timer.
elapsed(resetTimer);
562 for (
auto &prop : props) {
564 if (wsProp && !(wsProp->getWorkspace())) {
566 prop->setValue(prop->value());
572 throw std::runtime_error(
"Some invalid Properties found");
575 const float timingPropertyValidation = timer.
elapsed(resetTimer);
584 bool callProcessGroups =
true;
588 }
catch (std::exception &ex) {
589 getLogger().
error() <<
"Error in execution of algorithm " << this->
name() <<
"\n" << ex.what() <<
"\n";
599 timingInit += timer.
elapsed(resetTimer);
601 if ((!callProcessGroups))
603 std::map<std::string, std::string> errors = this->
validateInputs();
604 if (!errors.empty()) {
605 size_t numErrors = errors.size();
609 for (
auto &
error : errors) {
611 errorLog <<
"Invalid value for " <<
error.first <<
": " <<
error.second <<
"\n";
614 warnLog <<
"validateInputs() references non-existant property \"" <<
error.first <<
"\"\n";
619 std::stringstream msg;
620 msg <<
"Some invalid Properties found: ";
621 for (
const auto &
error : errors) {
622 msg <<
"\n " <<
error.first <<
": " <<
error.second;
625 throw std::runtime_error(msg.str());
629 const float timingInputValidation = timer.
elapsed(resetTimer);
641 m_history = std::make_shared<AlgorithmHistory>(algHist);
647 if (callProcessGroups) {
653 timingInit += timer.
elapsed(resetTimer);
660 startTime = Mantid::Types::Core::DateAndTime::getCurrentTime();
666 const float timingExec = timer.
elapsed(resetTimer);
668 const float duration = timingInit + timingPropertyValidation + timingInputValidation + timingExec;
683 algIsExecuted =
true;
687 "Time for other input validation: " +
std::to_string(timingInputValidation) +
" seconds\n" +
688 "Time for other initialization: " +
std::to_string(timingInit) +
" seconds\n" +
689 "Time to run exec: " +
std::to_string(timingExec) +
" seconds\n");
691 }
catch (std::runtime_error &ex) {
692 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
693 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
700 getLogger().
error() <<
"Error in execution of algorithm " << this->
name() <<
'\n' << ex.what() <<
'\n';
703 }
catch (std::logic_error &ex) {
704 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
705 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
712 getLogger().
error() <<
"Logic Error in execution of algorithm " << this->
name() <<
'\n' << ex.what() <<
'\n';
718 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
719 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
727 catch (std::exception &ex) {
729 getLogger().
error() <<
"Error in execution of algorithm " << this->
name() <<
":\n" << ex.what() <<
"\n";
730 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
731 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
739 catch (H5::Exception &ex) {
742 errmsg.append(ex.getCFuncName()).append(
": ").append(ex.getCDetailMsg());
743 getLogger().
error() <<
"H5 Exception in execution of algorithm " << this->
name() <<
":\n" << errmsg <<
"\n";
744 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
745 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
757 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
758 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
767 m_gcTime = Mantid::Types::Core::DateAndTime::getCurrentTime() +=
768 (Mantid::Types::Core::DateAndTime::ONE_SECOND * DELAY_BEFORE_GC);
788 bool executed =
false;
791 }
catch (std::runtime_error &) {
796 throw std::runtime_error(
"Unable to successfully run ChildAlgorithm " + this->
name());
807 std::vector<int> groupWsIndicies;
810 for (
unsigned int i = 0; i < props.size(); ++i) {
815 auto group = std::dynamic_pointer_cast<WorkspaceGroup>(wsProp->getWorkspace());
819 }
catch (std::runtime_error &) {
823 groupWsIndicies.emplace_back(i);
829 std::vector<int>::const_iterator wsIndex;
830 for (wsIndex = groupWsIndicies.begin(); wsIndex != groupWsIndicies.end(); ++wsIndex) {
835 }
catch (std::runtime_error &) {
861 const double endProgress,
const bool enableLogging,
const int &version) {
874 const bool enableLogging) {
877 alg->setLogging(enableLogging);
882 }
catch (std::runtime_error &) {
883 throw std::runtime_error(
"Unable to initialise Child Algorithm '" + alg->name() +
"'");
888 const std::vector<Property *> &props = alg->getProperties();
889 for (
auto prop : props) {
892 if (prop->value().empty() && !wsProp->isOptional()) {
893 prop->createTemporaryValue();
898 if (startProgress >= 0.0 && endProgress > startProgress && endProgress <= 1.0) {
909 std::weak_ptr<IAlgorithm> weakPtr(alg);
932 root[
"name"] =
name();
933 root[
"version"] = this->
version();
949 ::Json::Value jsonMap;
951 auto props =
history.getProperties();
952 const size_t numProps(props.size());
953 for (
size_t i = 0; i < numProps; ++i) {
955 if (!prop->isDefault()) {
956 jsonMap[prop->name()] = prop->value();
961 root[
"version"] =
history.version();
962 root[
"properties"] = jsonMap;
964 const std::string output = Mantid::JsonHelpers::jsonToString(root);
969 }
catch (std::invalid_argument &) {
970 throw std::runtime_error(
"Could not create algorithm from history. "
971 "Is this a child algorithm whose workspaces are not in the ADS?");
987 if (Mantid::JsonHelpers::parse(input, &root)) {
990 throw std::runtime_error(
"Cannot create algorithm, invalid string format.");
1002 const std::string algName = serialized[
"name"].asString();
1003 const int versionNumber = serialized.get(
"version", -1).asInt();
1004 auto alg = AlgorithmManager::Instance().createUnmanaged(algName, versionNumber);
1006 alg->setProperties(serialized[
"properties"]);
1034 for (
const auto &prop : algProperties) {
1045 bool linked =
false;
1047 const auto &childHistories =
m_history->getChildHistories();
1048 auto childIter = childHistories.rbegin();
1049 for (; childIter != childHistories.rend() && !linked; ++childIter) {
1050 const auto &props = (*childIter)->getProperties();
1051 auto propIter = props.begin();
1052 for (; propIter != props.end() && !linked; ++propIter) {
1057 std::ostringstream os;
1058 os <<
"__TMP" << wsProp->getWorkspace().get();
1059 if (os.str() == (*propIter)->value()) {
1060 (*propIter)->setValue(prop->value());
1093 const std::string &strValue,
bool checkADS) {
1099 if (checkADS && !strValue.empty()) {
1100 return ads.retrieve(strValue);
1114 const auto &ads = AnalysisDataService::Instance();
1115 for (
const auto &prop : algProperties) {
1116 const unsigned int propDirection = prop->direction();
1120 appendWS(workspaceFromWSProperty(*wsProp, ads, prop->value(), checkADS));
1130 logger.notice() <<
name() <<
" started";
1132 logger.notice() <<
" (child)";
1133 logger.notice() <<
'\n';
1137 size_t maxPropertyLength = 40;
1138 if (logger.is(Logger::Priority::PRIO_DEBUG)) {
1140 maxPropertyLength = 0;
1142 algHistory.
printSelf(logger.information(), 0, maxPropertyLength);
1173 size_t numGroups = 0;
1174 bool doProcessGroups =
false;
1177 const auto &ads = AnalysisDataService::Instance();
1181 auto const prop =
dynamic_cast<Property *
>(inputWorkspaceProp);
1184 auto wsGroup = std::dynamic_pointer_cast<WorkspaceGroup>(ws);
1189 if (!wsGroup && prop && !prop->value().empty()) {
1199 if (wsGroup && !wsGroupProp) {
1201 doProcessGroups =
true;
1217 return doProcessGroups;
1229 throw std::invalid_argument(
"Empty group passed as input");
1230 if (!thisGroup.empty()) {
1233 if (wsGroup && (numGroups == 1))
1237 if (thisGroup.size() > 1) {
1241 throw std::invalid_argument(
"Input WorkspaceGroups are not of the same size.");
1254 return doProcessGroups;
1271 startTime = Mantid::Types::Core::DateAndTime::getCurrentTime();
1274 bool completed =
false;
1278 }
catch (std::exception &ex) {
1299 const float duration = timer.
elapsed();
1305 const bool checkADS{
true};
1338 for (
auto &outGroupItem : out) {
1339 outGroupItem->history().addHistory(in.
getHistory());
1343 for (
auto &outWS : outputWorkspaces) {
1344 auto outWSGroup = std::dynamic_pointer_cast<WorkspaceGroup>(outWS);
1348 copyHistoryToGroup(*inputWS, *outWSGroup);
1350 outWS->history().addHistory(inputWS->getHistory());
1355 for (
auto &outGroupItem : *outWSGroup) {
1356 outGroupItem->history().addHistory(
m_history);
1386 std::vector<WorkspaceGroup_sptr> outGroups;
1390 auto *prop =
dynamic_cast<Property *
>(pureOutputWorkspaceProp);
1391 if (prop && !prop->value().empty()) {
1392 auto outWSGrp = std::make_shared<WorkspaceGroup>();
1393 outGroups.emplace_back(outWSGrp);
1395 AnalysisDataService::Instance().addOrReplace(prop->value(), outWSGrp);
1396 outWSGrp->observeADSNotifications(
false);
1400 double progress_proportion = 1.0 /
static_cast<double>(
m_groupSize);
1402 for (
size_t entry = 0; entry <
m_groupSize; entry++) {
1405 progress_proportion * (1 +
static_cast<double>(entry)),
1409 alg_sptr->setChild(
true);
1410 alg_sptr->setAlwaysStoreInADS(
true);
1411 alg_sptr->enableHistoryRecordingForChild(
false);
1412 alg_sptr->setRethrows(
true);
1418 std::string outputBaseName;
1423 if (!thisGroup.empty()) {
1431 if (entry < thisGroup.size()) {
1432 ws = thisGroup[entry];
1442 throw std::runtime_error(
"Unable to process over groups; consider passing workspaces "
1443 "one-by-one or override processGroup method of the algorithm.");
1447 if (!outputBaseName.empty())
1448 outputBaseName +=
"_";
1449 outputBaseName += ws->getName();
1453 if (ws->getName().empty()) {
1459 throw std::logic_error(
"Found a Workspace property which doesn't "
1460 "inherit from Property.");
1470 const std::string inName = prop->value();
1473 std::string outName;
1477 outName.append(outputBaseName).append(
"_").append(inName);
1489 if (!inputGroup.empty())
1490 outName = inputGroup[entry]->getName();
1497 outputWSNames[owp] = outName;
1499 throw std::logic_error(
"Found a Workspace property which doesn't "
1500 "inherit from Property.");
1507 }
catch (std::exception &e) {
1508 std::ostringstream msg;
1509 msg <<
"Execution of " << this->
name() <<
" for group entry " << (entry + 1) <<
" failed: ";
1511 throw std::runtime_error(msg.str());
1519 if (prop && prop->value().empty())
1522 outGroups[owp]->add(outputWSNames[owp]);
1528 for (
auto &outGroup : outGroups) {
1529 outGroup->observeADSNotifications(
true);
1543 throw std::runtime_error(
"Algorithm not created!");
1545 for (
const auto &prop : props) {
1582 return (wsProp !=
nullptr);
1593struct AsyncFlagHolder {
1603 AsyncFlagHolder() =
delete;
1652 m_progressObserver = std::make_unique<Poco::NObserver<Algorithm, ProgressNotification>>(
1669 sharedPtr->cancel();
1716 std::string optionalMessage;
1717 if (groupProcessing) {
1718 optionalMessage =
". Processed as a workspace group";
1724 std::stringstream msg;
1725 msg <<
name() <<
" successful, Duration ";
1726 double seconds = duration;
1727 if (seconds > 60.) {
1728 auto minutes =
static_cast<int>(seconds / 60.);
1729 msg << minutes <<
" minutes ";
1730 seconds = seconds -
static_cast<double>(minutes) * 60.;
1732 msg << std::fixed << std::setprecision(2) << seconds <<
" seconds" << optionalMessage;
1746 if (UsageService::Instance().isEnabled()) {
1747 std::ostringstream oss;
1749 UsageService::Instance().registerFeatureUsage(FeatureType::Algorithm, oss.str(),
isChild());
1772 :
Poco::Notification(), m_algorithm(alg) {}
1784 double estimatedTime,
int progressPrecision)
1786 progressPrecision(progressPrecision) {}
1831 const std::unordered_set<std::string> &ignoreProperties,
bool createMissing) {
1842 bool createMissing) {
1853 const std::unordered_set<std::string> &ignoreProperties) {
2043 std::string message =
"Attempt to assign property " +
name +
" to incorrect type. Expected shared_ptr<IAlgorithm>";
2044 throw std::runtime_error(message);
2056IPropertyManager::getValue<API::IAlgorithm_const_sptr>(
const std::string &
name)
const {
2059 return prop->operator()();
2061 std::string message =
2062 "Attempt to assign property " +
name +
" to incorrect type. Expected const shared_ptr<IAlgorithm>";
2063 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.
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.
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.