29 : m_workspacePropertyName(
std::move(workspacePropertyName)) {}
43 if (inputGroup->isMultiperiod()) {
44 vecMultiPeriodWorkspaceGroups.emplace_back(inputGroup);
46 vecWorkspaceGroups.emplace_back(inputGroup);
54 throw std::invalid_argument(
"Algorithm must be initialized");
64 using WorkspaceNameType = std::vector<std::string>;
70 throw std::runtime_error(
"Support for custom input workspaces that are "
71 "not string Arrays are not currently "
88 using WorkspaceVector = std::vector<std::shared_ptr<Workspace>>;
89 WorkspaceVector inWorkspaces;
91 for (
auto &inWorkspace : inWorkspaces) {
96 if (!vecMultiPeriodWorkspaceGroups.empty() && !vecWorkspaceGroups.empty()) {
97 throw std::invalid_argument(
"The input contains a mix of multi-period and other workspaces.");
102 return vecMultiPeriodWorkspaceGroups;
130 std::string inputWorkspaces;
131 for (
const auto &vecWorkspaceGroup : vecWorkspaceGroups) {
132 inputWorkspaces += prefix + vecWorkspaceGroup->getItem(periodIndex)->getName();
135 return inputWorkspaces;
152 const int &periodNumber)
const {
154 for (
auto prop : props) {
158 if (
WorkspaceGroup_sptr inputws = std::dynamic_pointer_cast<WorkspaceGroup>(wsProp->getWorkspace())) {
159 if (inputws->isMultiperiod()) {
160 targetAlg->
setProperty(prop->name(), inputws->getItem(periodNumber - 1));
188 if (vecMultiPeriodGroups.empty()) {
192 const std::string outName = outputWorkspaceProperty->
value();
194 const size_t nPeriods = vecMultiPeriodGroups[0]->size();
198 double progress_proportion = 1.0 /
static_cast<double>(nPeriods);
201 for (
size_t i = 0; i < nPeriods; ++i) {
202 const auto periodNumber =
static_cast<int>(i + 1);
205 progress_proportion * (1 + periodNumber),
208 throw std::runtime_error(
"Algorithm creation failed.");
212 alg->setChild(
false);
213 alg->setRethrows(
true);
227 alg->setPropertyValue(
"OutputWorkspace", outName_i);
229 if (!alg->execute()) {
230 throw std::runtime_error(
"Execution of " + sourceAlg->
name() +
" for group entry " +
Strings::toString(i + 1) +
234 outputWS->add(outName_i);
237 sourceAlg->
setProperty(
"OutputWorkspace", outputWS);
248 const size_t multiPeriodGroupsSize = vecMultiPeriodGroups.size();
250 if (multiPeriodGroupsSize > 0) {
251 const size_t benchMarkGroupSize = vecMultiPeriodGroups[0]->size();
252 for (
size_t i = 0; i < multiPeriodGroupsSize; ++i) {
254 if (currentGroup->size() != benchMarkGroupSize) {
255 throw std::runtime_error(
"Not all the input Multi-period-group input "
256 "workspaces are the same size.");
258 for (
size_t j = 0; j < currentGroup->size(); ++j) {
260 std::dynamic_pointer_cast<const MatrixWorkspace>(currentGroup->getItem(j));
261 Property *nPeriodsProperty = currentNestedWS->run().getLogData(
"nperiods");
262 size_t nPeriods = std::stoul(nPeriodsProperty->
value());
263 if (nPeriods != benchMarkGroupSize) {
264 throw std::runtime_error(
"Missmatch between nperiods log and the "
265 "number of workspaces in the input group: " +
266 vecMultiPeriodGroups[i]->
getName());
268 Property *currentPeriodProperty = currentNestedWS->run().getLogData(
"current_period");
269 size_t currentPeriod = std::stoul(currentPeriodProperty->
value());
270 if (currentPeriod != (j + 1)) {
271 throw std::runtime_error(
"Multiperiod group workspaces must be "
272 "ordered by current_period. Correct: " +
273 currentNestedWS->getName());
IPeaksWorkspace_sptr workspace
std::string getName(const IMDDimension &self)
Base class from which all concrete algorithm classes should be derived.
void copyNonWorkspaceProperties(IAlgorithm *alg, int periodNum)
Copy all the non-workspace properties from this to alg.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
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.
bool isInitialized() const override
Has the Algorithm already been initialized.
bool isLogging() const override
returns the status of logging, True = enabled
int version() const override=0
function to return a version of the algorithm, must be overridden in all algorithms
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...
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.
An interface that is implemented by WorkspaceProperty.
MultiPeriodGroupWorker()=default
Constructor.
void validateMultiPeriodGroupInputs(const VecWSGroupType &vecMultiPeriodGroups) const
Validate the input group workspace.
VecWSGroupType findMultiPeriodGroups(Algorithm const *const sourceAlg) const
Check groups.
bool useCustomWorkspaceProperty() const
Flag to indicate use of a custom workspace property.
std::vector< WorkspaceGroup_sptr > VecWSGroupType
Convenience typdef for workspace names.
void copyInputWorkspaceProperties(IAlgorithm *targetAlg, IAlgorithm *sourceAlg, const int &periodNumber) const
Copy input workspace properties to spawned algorithm.
void tryAddInputWorkspaceToInputGroups(const Workspace_sptr &ws, VecWSGroupType &vecMultiPeriodWorkspaceGroups, VecWSGroupType &vecWorkspaceGroups) const
Try ot add a workspace to the group of input workspaces.
std::string createFormattedInputWorkspaceNames(const size_t &periodIndex, const VecWSGroupType &vecWorkspaceGroups) const
Create an input workspace string from the workspace groups.
std::string m_workspacePropertyName
Workspace property name.
bool processGroups(Algorithm *const sourceAlg, const VecWSGroupType &vecMultiPeriodGroups) const
Process groups.
Support for a property that holds an array of values.
Exception for when an item is not found in a collection.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
virtual const std::vector< Property * > & getProperties() const =0
Get the list of managed properties.
Base class for properties.
virtual std::string value() const =0
Returns the value of the property as a string.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
std::string toString(const T &value)
Convert a number to a string.
@ Input
An input workspace.