Mantid
Loading...
Searching...
No Matches
MergeRuns.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2008 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
12#include "MantidAlgorithms/DllConfig.h"
15
16#include <list>
17#include <optional>
18#include <span>
19
20namespace Mantid {
21namespace API {
22class WorkspaceGroup;
23}
24namespace HistogramData {
25class HistogramX;
26}
27namespace Algorithms {
53namespace MergeRunsParameter {
55static const std::string SUM_MERGE = "sample_logs_sum";
56static const std::string TIME_SERIES_MERGE = "sample_logs_time_series";
57static const std::string LIST_MERGE = "sample_logs_list";
58static const std::string WARN_MERGE = "sample_logs_warn";
59static const std::string WARN_MERGE_TOLERANCES = "sample_logs_warn_tolerances";
60static const std::string FAIL_MERGE = "sample_logs_fail";
61static const std::string FAIL_MERGE_TOLERANCES = "sample_logs_fail_tolerances";
62} // namespace MergeRunsParameter
63
64class MANTID_ALGORITHMS_DLL MergeRuns : public API::MultiPeriodGroupAlgorithm {
65public:
67 const std::string name() const override { return "MergeRuns"; }
69 const std::string summary() const override {
70 return "Combines the data contained in an arbitrary number of input "
71 "workspaces.";
72 }
73
75 int version() const override { return 1; }
76 const std::vector<std::string> seeAlso() const override { return {"ConjoinWorkspaces"}; }
78 const std::string category() const override { return "Transforms\\Merging"; }
79 // Overriden MultiPeriodGroupAlgorithm method.
80 bool useCustomInputPropertyName() const override;
81
82protected:
85 void fillHistory() override;
86
87private:
88 // Overridden Algorithm methods
89 void init() override;
90 void exec() override;
91 void execEvent();
92 void execHistogram(const std::vector<std::string> &inputs);
93 void buildAdditionTables();
94 // Overriden MultiPeriodGroupAlgorithm method.
95 std::string fetchInputPropertyName() const override;
96
100 using AdditionTable = std::vector<std::pair<int, int>>;
102 template <typename Container> void copyHistoryFromInputWorkspaces(const Container &workspaces) {
103 API::Workspace_sptr outWS = this->getProperty("OutputWorkspace");
104
105 // this is not a child algorithm. Add the history algorithm to the
106 // WorkspaceHistory object.
107 if (!isChild()) {
108 // Loop over the input workspaces, making the call that copies their
109 // history to the output ones
110 // (Protection against copy to self is in
111 // WorkspaceHistory::copyAlgorithmHistory)
112 for (auto inWS = workspaces.begin(); inWS != workspaces.end(); ++inWS) {
113 outWS->history().addHistory((*inWS)->getHistory());
114 }
115 // Add the history for the current algorithm to all the output workspaces
116 outWS->history().addHistory(m_history);
117 }
118 // this is a child algorithm, but we still want to keep the history.
119 else if (isRecordingHistoryForChild() && m_parentHistory) {
120 m_parentHistory->addChildHistory(m_history);
121 }
122 }
123
124 // Methods called by exec()
126 bool validateInputsForEventWorkspaces(const std::vector<std::string> &inputWorkspaces);
127 std::optional<std::vector<double>> checkRebinning();
128 static std::vector<double> calculateRebinParams(std::span<double const> bins1, std::span<double const> bins2);
129 static void noOverlapParams(std::span<double const> X1, std::span<double const> X2, std::vector<double> &params);
130 static void intersectionParams(std::span<double const> X1, size_t &i, std::span<double const> X2,
131 std::vector<double> &params);
132 static void inclusionParams(std::span<double const> X1, size_t &i, std::span<double const> X2,
133 std::vector<double> &params);
134 API::MatrixWorkspace_sptr rebinInput(const API::MatrixWorkspace_sptr &workspace, const std::vector<double> &params);
135 API::MatrixWorkspace_sptr buildScanningOutputWorkspace(const API::MatrixWorkspace_sptr &outWS,
136 const API::MatrixWorkspace_sptr &addee);
138 std::unique_ptr<API::Progress> m_progress;
139
141 std::vector<Mantid::DataObjects::EventWorkspace_sptr> m_inEventWS;
143 std::list<API::MatrixWorkspace_sptr> m_inMatrixWS;
145 std::vector<AdditionTable> m_tables;
147 size_t m_outputSize = 0;
148
149 std::vector<SpectrumDefinition> buildScanIntervals(const std::vector<SpectrumDefinition> &addeeSpecDefs,
150 const Geometry::DetectorInfo &addeeDetInfo,
151 const Geometry::DetectorInfo &newOutDetInfo);
152};
153
154} // namespace Algorithms
155} // namespace Mantid
IPeaksWorkspace_sptr workspace
std::map< std::string, std::string > validateInputs() override
Perform validation of ALL the input properties of the algorithm.
MutliPeriodGroupAlgorithm : Abstract algorithm.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
Definition MergeRuns.h:67
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
Definition MergeRuns.h:78
void copyHistoryFromInputWorkspaces(const Container &workspaces)
Copy the history from the input workspaces to the output workspaces.
Definition MergeRuns.h:102
std::vector< Mantid::DataObjects::EventWorkspace_sptr > m_inEventWS
List of input EVENT workspaces.
Definition MergeRuns.h:141
std::unique_ptr< API::Progress > m_progress
Progress reporting.
Definition MergeRuns.h:138
int version() const override
Algorithm's version for identification overriding a virtual method.
Definition MergeRuns.h:75
const std::string summary() const override
Summary of algorithms purpose.
Definition MergeRuns.h:69
std::vector< AdditionTable > m_tables
Addition tables for event workspaces.
Definition MergeRuns.h:145
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso algorithms related to this algorithm.
Definition MergeRuns.h:76
std::list< API::MatrixWorkspace_sptr > m_inMatrixWS
List of input matrix workspace.
Definition MergeRuns.h:143
std::vector< std::pair< int, int > > AdditionTable
An addition table is a list of pairs: First int = workspace index in the EW being added,...
Definition MergeRuns.h:100
Models a Container is used to hold a sample in the beam.
Definition Container.h:24
Geometry::DetectorInfo is an intermediate step towards a DetectorInfo that is part of Instrument-2....
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
static const std::string FAIL_MERGE_TOLERANCES
Definition MergeRuns.h:61
static const std::string WARN_MERGE_TOLERANCES
Definition MergeRuns.h:59
static const std::string WARN_MERGE
Definition MergeRuns.h:58
static const std::string FAIL_MERGE
Definition MergeRuns.h:60
static const std::string SUM_MERGE
MergeRuns parameter names of the paramter file for sample log merging.
Definition MergeRuns.h:55
static const std::string TIME_SERIES_MERGE
Definition MergeRuns.h:56
static const std::string LIST_MERGE
Definition MergeRuns.h:57
Helper class which provides the Collimation Length for SANS instruments.