Mantid
Loading...
Searching...
No Matches
GroupDetectors2.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
10#include "MantidDataHandling/DllConfig.h"
14
15#include <map>
16
17namespace Mantid {
18namespace DataHandling {
93class MANTID_DATAHANDLING_DLL GroupDetectors2 final : public API::Algorithm {
94public:
96 const std::string name() const override { return "GroupDetectors"; };
98 const std::string summary() const override {
99 return "Sums spectra bin-by-bin, equivalent to grouping the data from a "
100 "set of detectors. Individual groups can be specified by passing "
101 "the algorithm a list of spectrum numbers, detector IDs or "
102 "workspace indices. Many spectra groups can be created in one "
103 "execution via an input file.";
104 }
105
107 int version() const override { return 2; };
108 const std::vector<std::string> seeAlso() const override { return {"SpatialGrouping"}; }
110 const std::string category() const override { return "Transforms\\Grouping"; }
111
113 std::map<std::string, std::string> validateInputs() override;
114
115private:
119 public:
120 static void getList(const std::string &line, std::vector<size_t> &outList);
121
122 private:
125 RangeHelper() = default;
127 enum {
128 IGNORE_SPACES =
132 };
133 };
134
137 using storage_map = std::map<specnum_t, std::vector<size_t>>;
138
141 double m_FracCompl = 0.0;
145
146 // Implement abstract Algorithm methods
147 void init() override;
148 void exec() override;
149 void execEvent();
150
152 void getGroups(const API::MatrixWorkspace_const_sptr &workspace, std::vector<int64_t> &unUsedSpec);
155 void processFile(const std::string &fname, const API::MatrixWorkspace_const_sptr &workspace,
156 std::vector<int64_t> &unUsedSpec);
158 void processXMLFile(const std::string &fname, const API::MatrixWorkspace_const_sptr &workspace,
159 std::vector<int64_t> &unUsedSpec);
160 void processGroupingWorkspace(const DataObjects::GroupingWorkspace_const_sptr &groupWS,
161 const API::MatrixWorkspace_const_sptr &workspace, std::vector<int64_t> &unUsedSpec);
162 void processMatrixWorkspace(const API::MatrixWorkspace_const_sptr &groupWS,
163 const API::MatrixWorkspace_const_sptr &workspace, std::vector<int64_t> &unUsedSpec);
166 int readInt(const std::string &line);
167
168 void readFile(const spec2index_map &specs2index, std::istream &File, size_t &lineNum,
169 std::vector<int64_t> &unUsedSpec, const bool ignoreGroupNumber);
170
173 void readSpectraIndexes(const std::string &line, const spec2index_map &specs2index, std::vector<size_t> &output,
174 std::vector<int64_t> &unUsedSpec, const std::string &seperator = "#");
175
178 double fileReadProg(DataHandling::GroupDetectors2::storage_map::size_type numGroupsRead,
179 DataHandling::GroupDetectors2::storage_map::size_type numInHists);
180
183 size_t formGroups(const API::MatrixWorkspace_const_sptr &inputWS, const API::MatrixWorkspace_sptr &outputWS,
184 const double prog4Copy, const bool keepAll, const std::set<int64_t> &unGroupedSet,
185 Indexing::IndexInfo &indexInfo);
188 size_t formGroupsEvent(const DataObjects::EventWorkspace_const_sptr &inputWS,
189 const DataObjects::EventWorkspace_sptr &outputWS, const double prog4Copy);
190
192 template <class TIn, class TOut>
193 void moveOthers(const std::set<int64_t> &unGroupedSet, const TIn &inputWS, TOut &outputWS, size_t outIndex);
194
196 enum {
197 USED = 1000 - INT_MAX,
202 EMPTY_LINE = 1001 - INT_MAX,
207 };
208
209 static const double CHECKBINS;
213 static const double OPENINGFILE;
214 static const double READFILE;
217 static const int INTERVAL = 128;
220};
221
232template <class TIn, class TOut>
233void GroupDetectors2::moveOthers(const std::set<int64_t> &unGroupedSet, const TIn &inputWS, TOut &outputWS,
234 size_t outIndex) {
235 g_log.debug() << "Starting to copy the ungrouped spectra\n";
236 double prog4Copy = (1. - 1. * static_cast<double>(m_FracCompl)) / static_cast<double>(unGroupedSet.size());
237
238 // go thorugh all the spectra in the input workspace
239 for (auto copyFrIt : unGroupedSet) {
240 if (copyFrIt == USED)
241 continue; // Marked as not to be used
242 size_t sourceIndex = static_cast<size_t>(copyFrIt);
243
244 outputWS.getSpectrum(outIndex) = inputWS.getSpectrum(sourceIndex);
245
246 // go to the next free index in the output workspace
247 outIndex++;
248 // make regular progress reports and check for cancelling the algorithm
249 if (outIndex % INTERVAL == 0) {
250 m_FracCompl += INTERVAL * prog4Copy;
251 if (m_FracCompl > 1.0) {
252 m_FracCompl = 1.0;
253 }
256 }
257 }
258
259 g_log.debug() << name() << " copied " << unGroupedSet.size() - 1 << " ungrouped spectra\n";
260}
261
262} // namespace DataHandling
263} // namespace Mantid
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:85
Kernel::Logger & g_log
Definition: Algorithm.h:451
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
Definition: Algorithm.cpp:231
void interruption_point()
This is called during long-running operations, and check if the algorithm has requested that it be ca...
Definition: Algorithm.cpp:1687
provides a function that expands pairs of integers separated with a hyphen into a list of all the int...
RangeHelper()=default
this class can't be constructed it is just a holder for some static things
An algorithm for grouping detectors and their associated spectra into single spectra and DetectorGrou...
double m_FracCompl
An estimate of the percentage of the algorithm runtimes that has been completed.
static const double OPENINGFILE
required to check that the X bin boundaries are the same as a percentage of total algorithm run time
const std::string summary() const override
Summary of algorithms purpose.
storage_map m_GroupWsInds
stores lists of spectra indexes to group, although we never do an index search on it
const std::string category() const override
Algorithm's category for identification overriding a virtual method.
const std::string name() const override
Algorithm's name for identification overriding a virtual method.
int version() const override
Algorithm's version for identification overriding a virtual method.
void moveOthers(const std::set< int64_t > &unGroupedSet, const TIn &inputWS, TOut &outputWS, size_t outIndex)
Copy the ungrouped spectra from the input workspace to the output.
static const double CHECKBINS
a (worse case) estimate of the time
const std::vector< std::string > seeAlso() const override
Function to return all of the seeAlso (these are not validated) algorithms related to this algorithm....
static const double READFILE
if a file must be read in estimate that
static const int INTERVAL
reading it will take this percentage of the algorithm execution time
@ USED
goes in the unGrouped spectra list to say that a
std::map< specnum_t, std::vector< size_t > > storage_map
used to store the lists of WORKSPACE INDICES that will be grouped, the keys are not used
void debug(const std::string &msg)
Logs at debug level.
Definition: Logger.cpp:114
@ TOK_IGNORE_EMPTY
ignore empty tokens
@ TOK_TRIM
remove leading and trailing whitespace from tokens
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< const GroupingWorkspace > GroupingWorkspace_const_sptr
shared pointer to a const GroupingWorkspace
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
Helper class which provides the Collimation Length for SANS instruments.
std::unordered_map< specnum_t, size_t > spec2index_map
Map with key = spectrum number, value = workspace index.