16#include "Poco/String.h"
23using namespace Kernel;
25using namespace Geometry;
28 auto wsValidator = std::make_shared<WorkspaceUnitValidator>(
"Wavelength");
32 "The name of the input event Nexus file to load as dark current.");
36 "If true, the algorithm will be persistent and re-used when "
37 "other data sets are processed");
45 std::string output_message;
47 const std::string reductionManagerName =
getProperty(
"ReductionProperties");
48 std::shared_ptr<PropertyManager> reductionManager;
52 reductionManager = std::make_shared<PropertyManager>();
57 const bool persistent =
getProperty(
"PersistentCorrection");
58 if (!reductionManager->existsProperty(
"DarkCurrentAlgorithm") && persistent) {
59 auto algProp = std::make_unique<AlgorithmProperty>(
"DarkCurrentAlgorithm");
61 reductionManager->declareProperty(std::move(algProp));
71 progress.report(
"Subtracting dark current");
74 Poco::Path path(fileName);
75 const std::string entryName =
"DarkCurrent" + path.getBaseName();
77 if (reductionManager->existsProperty(entryName)) {
78 darkWS = reductionManager->getProperty(entryName);
79 darkWSName = reductionManager->getPropertyValue(entryName);
80 output_message += darkWSName +
'\n';
83 if (darkWSName.empty()) {
84 darkWSName =
"__dark_current_" + path.getBaseName();
89 if (!reductionManager->existsProperty(
"LoadAlgorithm")) {
91 loadAlg->setProperty(
"Filename", fileName);
92 loadAlg->setProperty(
"ReductionProperties", reductionManagerName);
93 loadAlg->executeAsChildAlg();
95 IAlgorithm_sptr loadAlg0 = reductionManager->getProperty(
"LoadAlgorithm");
96 const std::string loadString = loadAlg0->toString();
98 loadAlg->setChild(
true);
99 loadAlg->setProperty(
"Filename", fileName);
100 loadAlg->setProperty(
"ReductionProperties", reductionManagerName);
101 loadAlg->setPropertyValue(
"OutputWorkspace", darkWSName);
104 darkWS = loadAlg->getProperty(
"OutputWorkspace");
105 output_message +=
"\n Loaded " + fileName +
"\n";
106 if (loadAlg->existsProperty(
"OutputMessage")) {
107 std::string msg = loadAlg->getPropertyValue(
"OutputMessage");
108 output_message +=
" |" + Poco::replace(msg,
"\n",
"\n |") +
"\n";
113 reductionManager->setPropertyValue(entryName, darkWSName);
114 reductionManager->setProperty(entryName, darkWS);
116 progress.report(3,
"Loaded dark current");
122 scaleAlg->setProperty(
"InputWorkspace", darkWS);
123 scaleAlg->setProperty(
"Factor", dataTimer / darkTimer);
124 scaleAlg->setProperty(
"Operation",
"Multiply");
125 scaleAlg->executeAsChildAlg();
129 for (
size_t i = 0; i < scaledDarkWS->dataY(0).size(); i++) {
136 minusAlg->setProperty(
"LHSWorkspace", inputWS);
137 minusAlg->setProperty(
"RHSWorkspace", scaledDarkWS);
139 minusAlg->setProperty(
"OutputWorkspace", outputWS);
140 minusAlg->executeAsChildAlg();
143 setProperty(
"OutputMessage",
"Dark current subtracted: " + output_message);
145 progress.report(
"Subtracted dark current");
152 if (inputWS->run().hasProperty(
"timer")) {
153 return inputWS->run().getPropertyValueAsType<
double>(
"timer");
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
std::string toString() const override
Serialize an object to a string.
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.
static IAlgorithm_sptr fromString(const std::string &input)
De-serialize an object from a string.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
void setPropertyValue(const std::string &name, const std::string &value) override
Set the value of a property by string N.B.
@ Load
allowed here which will be passed to the algorithm
Helper class for reporting progress from algorithms.
A property class for workspaces.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
double getCountingTime(const API::MatrixWorkspace_sptr &inputWS)
Get the counting time from a workspace.
static const int DEFAULT_TIMER_ID
void exec() override
Execution code.
void init() override
Initialisation code.
static const int DEFAULT_MONITOR_ID
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
@ Input
An input workspace.
@ Output
An output workspace.