MatrixWorkspace.h 25 KB
Newer Older
1
2
3
4
5
6
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2007 ISIS Rutherford Appleton Laboratory UKRI,
//     NScD Oak Ridge National Laboratory, European Spallation Source
//     & Institut Laue - Langevin
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8

9
10
#include "MantidAPI/DllConfig.h"
#include "MantidAPI/ExperimentInfo.h"
11
#include "MantidAPI/IMDWorkspace.h"
12
#include "MantidAPI/ISpectrum.h"
13
#include "MantidAPI/MatrixWorkspace_fwd.h"
14
#include "MantidKernel/EmptyValues.h"
15

16
#include <atomic>
17
#include <mutex>
18

19
namespace Mantid {
20
21

namespace Indexing {
22
class IndexInfo;
23
24
}

25
namespace Types {
26
namespace Core {
27
class DateAndTime;
28
}
LamarMoore's avatar
LamarMoore committed
29
} // namespace Types
30

31
32
33
namespace Geometry {
class ParameterMap;
}
34

35
namespace API {
36
class Axis;
37
38
39
class SpectrumDetectorMapping;

/// typedef for the image type
40
using MantidImage = std::vector<std::vector<double>>;
41
/// shared pointer to MantidImage
42
using MantidImage_sptr = boost::shared_ptr<MantidImage>;
43
/// shared pointer to const MantidImage
44
using MantidImage_const_sptr = boost::shared_ptr<const MantidImage>;
45

46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//----------------------------------------------------------------------
/** Base MatrixWorkspace Abstract Class.

@author Laurent C Chapon, ISIS, RAL
@date 26/09/2007
*/
class MANTID_API_DLL MatrixWorkspace : public IMDWorkspace,
                                       public ExperimentInfo {

private:
  using ExperimentInfo::toString;

public:
  // The Workspace Factory create-from-parent method needs direct access to the
  // axes.
  friend class WorkspaceFactoryImpl;

  void initialize(const std::size_t &NVectors, const std::size_t &XLength,
                  const std::size_t &YLength);
65
66
  void initialize(const std::size_t &NVectors,
                  const HistogramData::Histogram &histogram);
67
68
  void initialize(const Indexing::IndexInfo &indexInfo,
                  const HistogramData::Histogram &histogram);
69
70

  MatrixWorkspace &operator=(const MatrixWorkspace &other) = delete;
71
  /// Delete
72
  ~MatrixWorkspace() override;
73

74
  /// Returns a clone of the workspace
Martyn Gigg's avatar
Martyn Gigg committed
75
  MatrixWorkspace_uptr clone() const { return MatrixWorkspace_uptr(doClone()); }
76

77
78
79
80
81
  /// Returns a default-initialized clone of the workspace
  MatrixWorkspace_uptr cloneEmpty() const {
    return MatrixWorkspace_uptr(doCloneEmpty());
  }

82
  const Indexing::IndexInfo &indexInfo() const;
83
  void setIndexInfo(const Indexing::IndexInfo &indexInfo);
84

85
86
  using IMDWorkspace::toString;
  /// String description of state
87
  const std::string toString() const override;
88
89
90

  /**@name Instrument queries */
  //@{
91
92
  boost::shared_ptr<const Geometry::IDetector>
  getDetector(const size_t workspaceIndex) const;
93
94
  double detectorTwoTheta(const Geometry::IDetector &det) const;
  double detectorSignedTwoTheta(const Geometry::IDetector &det) const;
95

96
97
  //@}

Owen Arnold's avatar
Owen Arnold committed
98
  virtual void updateSpectraUsing(const SpectrumDetectorMapping &map);
99
100
  /// Build the default spectra mapping, most likely wanted after an instrument
  /// update
101
102
  void rebuildSpectraMapping(const bool includeMonitors = true,
                             const specnum_t specNumOffset = 1);
103
104
105
106
107

  // More mapping
  spec2index_map getSpectrumToWorkspaceIndexMap() const;
  detid2index_map
  getDetectorIDToWorkspaceIndexMap(bool throwIfMultipleDets = false) const;
108
109
  virtual std::vector<size_t>
  getDetectorIDToWorkspaceIndexVector(detid_t &offset,
110
                                      bool throwIfMultipleDets = false) const;
Nick Draper's avatar
Nick Draper committed
111

112
  virtual std::vector<size_t>
Nick Draper's avatar
Nick Draper committed
113
  getSpectrumToWorkspaceIndexVector(specnum_t &offset) const;
114
  std::vector<size_t>
Nick Draper's avatar
Nick Draper committed
115
116
  getIndicesFromSpectra(const std::vector<specnum_t> &spectraList) const;
  size_t getIndexFromSpectrumNumber(const specnum_t specNo) const;
117
118
  std::vector<size_t>
  getIndicesFromDetectorIDs(const std::vector<detid_t> &detIdList) const;
Nick Draper's avatar
Nick Draper committed
119
  std::vector<specnum_t>
120
  getSpectraFromDetectorIDs(const std::vector<detid_t> &detIdList) const;
121
122
123
124

  bool hasGroupedDetectors() const;

  /// Get the footprint in memory in bytes.
125
  size_t getMemorySize() const override;
126
127
128
129
130
  virtual size_t getMemorySizeForXAxes() const;

  // Section required for iteration
  /// Returns the number of single indexable items in the workspace
  virtual std::size_t size() const = 0;
Peterson, Peter's avatar
Peterson, Peter committed
131
132
133
  /// Returns the size of each block of data returned by the dataY accessors.
  /// This throws an exception if the lengths are not identical across the
  /// spectra.
134
135
136
137
138
  virtual std::size_t blocksize() const = 0;
  /// Returns the number of histograms in the workspace
  virtual std::size_t getNumberHistograms() const = 0;

  /// Sets MatrixWorkspace title
139
  void setTitle(const std::string &) override;
140
  /// Gets MatrixWorkspace title (same as Run object run_title property)
141
  const std::string getTitle() const override;
142

143
144
  virtual Types::Core::DateAndTime getFirstPulseTime() const;
  Types::Core::DateAndTime getLastPulseTime() const;
145

Robert Applin's avatar
Robert Applin committed
146
147
148
  /// Returns the y index which corresponds to the X Value provided
  std::size_t yIndexOfX(const double xValue, const std::size_t = 0,
                        const double tolerance = 0.0) const;
149
150
151
152
153
154

  //----------------------------------------------------------------------
  // DATA ACCESSORS
  //----------------------------------------------------------------------

  /// Return the underlying ISpectrum ptr at the given workspace index.
155
  virtual ISpectrum &getSpectrum(const size_t index) = 0;
156
157
  /// Return the underlying ISpectrum ptr (const version) at the given workspace
  /// index.
158
  virtual const ISpectrum &getSpectrum(const size_t index) const = 0;
159

160
161
  /// Returns the Histogram at the given workspace index.
  HistogramData::Histogram histogram(const size_t index) const {
162
    return getSpectrum(index).histogram();
163
  }
164
165
  template <typename... T>
  void setHistogram(const size_t index, T &&... data) & {
Moore's avatar
Moore committed
166
    getSpectrum(index).setHistogram(std::forward<T>(data)...);
167
  }
168
  void convertToCounts(const size_t index) {
169
    getSpectrumWithoutInvalidation(index).convertToCounts();
170
171
  }
  void convertToFrequencies(const size_t index) {
172
    getSpectrumWithoutInvalidation(index).convertToFrequencies();
173
  }
174
  HistogramData::BinEdges binEdges(const size_t index) const {
175
    return getSpectrum(index).binEdges();
176
177
  }
  HistogramData::Points points(const size_t index) const {
178
    return getSpectrum(index).points();
179
  }
180
181
  HistogramData::PointStandardDeviations
  pointStandardDeviations(const size_t index) const {
182
    return getSpectrum(index).pointStandardDeviations();
183
  }
184
185
  template <typename... T>
  void setBinEdges(const size_t index, T &&... data) & {
186
    getSpectrum(index).setBinEdges(std::forward<T>(data)...);
187
  }
188
  template <typename... T> void setPoints(const size_t index, T &&... data) & {
189
    getSpectrum(index).setPoints(std::forward<T>(data)...);
190
  }
191
  template <typename... T>
192
  void setPointVariances(const size_t index, T &&... data) & {
193
194
    getSpectrumWithoutInvalidation(index).setPointVariances(
        std::forward<T>(data)...);
195
196
  }
  template <typename... T>
197
  void setPointStandardDeviations(const size_t index, T &&... data) & {
198
199
    getSpectrumWithoutInvalidation(index).setPointStandardDeviations(
        std::forward<T>(data)...);
200
  }
201
  HistogramData::Counts counts(const size_t index) const {
202
    return getSpectrum(index).counts();
203
204
  }
  HistogramData::CountVariances countVariances(const size_t index) const {
205
    return getSpectrum(index).countVariances();
206
207
208
  }
  HistogramData::CountStandardDeviations
  countStandardDeviations(const size_t index) const {
209
    return getSpectrum(index).countStandardDeviations();
210
211
  }
  HistogramData::Frequencies frequencies(const size_t index) const {
212
    return getSpectrum(index).frequencies();
213
214
215
  }
  HistogramData::FrequencyVariances
  frequencyVariances(const size_t index) const {
216
    return getSpectrum(index).frequencyVariances();
217
218
219
  }
  HistogramData::FrequencyStandardDeviations
  frequencyStandardDeviations(const size_t index) const {
220
    return getSpectrum(index).frequencyStandardDeviations();
221
  }
222
  template <typename... T> void setCounts(const size_t index, T &&... data) & {
223
    getSpectrumWithoutInvalidation(index).setCounts(std::forward<T>(data)...);
224
225
226
  }
  template <typename... T>
  void setCountVariances(const size_t index, T &&... data) & {
227
228
    getSpectrumWithoutInvalidation(index).setCountVariances(
        std::forward<T>(data)...);
229
230
231
  }
  template <typename... T>
  void setCountStandardDeviations(const size_t index, T &&... data) & {
232
233
    getSpectrumWithoutInvalidation(index).setCountStandardDeviations(
        std::forward<T>(data)...);
234
235
236
  }
  template <typename... T>
  void setFrequencies(const size_t index, T &&... data) & {
237
238
    getSpectrumWithoutInvalidation(index).setFrequencies(
        std::forward<T>(data)...);
239
240
241
  }
  template <typename... T>
  void setFrequencyVariances(const size_t index, T &&... data) & {
242
243
    getSpectrumWithoutInvalidation(index).setFrequencyVariances(
        std::forward<T>(data)...);
244
245
246
  }
  template <typename... T>
  void setFrequencyStandardDeviations(const size_t index, T &&... data) & {
247
248
    getSpectrumWithoutInvalidation(index).setFrequencyStandardDeviations(
        std::forward<T>(data)...);
249
  }
250
  const HistogramData::HistogramX &x(const size_t index) const {
251
    return getSpectrum(index).x();
252
  }
253
  const HistogramData::HistogramY &y(const size_t index) const {
254
    return getSpectrum(index).y();
255
256
  }
  const HistogramData::HistogramE &e(const size_t index) const {
257
    return getSpectrum(index).e();
258
  }
259
  const HistogramData::HistogramDx &dx(const size_t index) const {
260
    return getSpectrum(index).dx();
261
  }
262
  HistogramData::HistogramX &mutableX(const size_t index) & {
263
    return getSpectrum(index).mutableX();
264
  }
265
  HistogramData::HistogramDx &mutableDx(const size_t index) & {
266
    return getSpectrumWithoutInvalidation(index).mutableDx();
267
  }
268
  HistogramData::HistogramY &mutableY(const size_t index) & {
269
    return getSpectrumWithoutInvalidation(index).mutableY();
270
  }
271
  HistogramData::HistogramE &mutableE(const size_t index) & {
272
    return getSpectrumWithoutInvalidation(index).mutableE();
273
  }
274
  Kernel::cow_ptr<HistogramData::HistogramX> sharedX(const size_t index) const {
275
    return getSpectrum(index).sharedX();
276
  }
277
  Kernel::cow_ptr<HistogramData::HistogramY> sharedY(const size_t index) const {
278
    return getSpectrum(index).sharedY();
279
280
  }
  Kernel::cow_ptr<HistogramData::HistogramE> sharedE(const size_t index) const {
281
    return getSpectrum(index).sharedE();
282
  }
283
284
  Kernel::cow_ptr<HistogramData::HistogramDx>
  sharedDx(const size_t index) const {
285
    return getSpectrum(index).sharedDx();
286
  }
287
  void setSharedX(const size_t index,
288
                  const Kernel::cow_ptr<HistogramData::HistogramX> &x) & {
289
    getSpectrum(index).setSharedX(x);
290
  }
291
  void setSharedDx(const size_t index,
292
                   const Kernel::cow_ptr<HistogramData::HistogramDx> &dx) & {
293
    getSpectrumWithoutInvalidation(index).setSharedDx(dx);
294
  }
295
  void setSharedY(const size_t index,
296
                  const Kernel::cow_ptr<HistogramData::HistogramY> &y) & {
297
    getSpectrumWithoutInvalidation(index).setSharedY(y);
298
299
  }
  void setSharedE(const size_t index,
300
                  const Kernel::cow_ptr<HistogramData::HistogramE> &e) & {
301
    getSpectrumWithoutInvalidation(index).setSharedE(e);
302
  }
303
304
  // Methods for getting read-only access to the data.
  // Just passes through to the virtual dataX/Y/E function (const version)
305
306
  /// Deprecated, use x() instead. Returns a read-only (i.e. const) reference to
  /// the specified X array
307
308
  /// @param index :: workspace index to retrieve.
  const MantidVec &readX(std::size_t const index) const {
309
    return getSpectrum(index).dataX();
310
  }
311
312
  /// Deprecated, use y() instead. Returns a read-only (i.e. const) reference to
  /// the specified Y array
313
314
  /// @param index :: workspace index to retrieve.
  const MantidVec &readY(std::size_t const index) const {
315
    return getSpectrum(index).dataY();
316
  }
317
318
  /// Deprecated, use e() instead. Returns a read-only (i.e. const) reference to
  /// the specified E array
319
320
  /// @param index :: workspace index to retrieve.
  const MantidVec &readE(std::size_t const index) const {
321
    return getSpectrum(index).dataE();
322
  }
323
324
  /// Deprecated, use dx() instead. Returns a read-only (i.e. const) reference
  /// to the specified X error array
325
326
  /// @param index :: workspace index to retrieve.
  const MantidVec &readDx(size_t const index) const {
327
    return getSpectrum(index).dataDx();
328
329
  }

330
  /// Deprecated, use mutableX() instead. Returns the x data
331
  virtual MantidVec &dataX(const std::size_t index) {
332
    return getSpectrum(index).dataX();
333
  }
334
  /// Deprecated, use mutableY() instead. Returns the y data
335
  virtual MantidVec &dataY(const std::size_t index) {
336
    return getSpectrumWithoutInvalidation(index).dataY();
337
  }
338
  /// Deprecated, use mutableE() instead. Returns the error data
339
  virtual MantidVec &dataE(const std::size_t index) {
340
    return getSpectrumWithoutInvalidation(index).dataE();
341
  }
342
  /// Deprecated, use mutableDx() instead. Returns the x error data
343
  virtual MantidVec &dataDx(const std::size_t index) {
344
    return getSpectrumWithoutInvalidation(index).dataDx();
345
346
  }

347
  /// Deprecated, use x() instead. Returns the x data const
348
  virtual const MantidVec &dataX(const std::size_t index) const {
349
    return getSpectrum(index).dataX();
350
  }
351
  /// Deprecated, use y() instead. Returns the y data const
352
  virtual const MantidVec &dataY(const std::size_t index) const {
353
    return getSpectrum(index).dataY();
354
  }
355
  /// Deprecated, use e() instead. Returns the error const
356
  virtual const MantidVec &dataE(const std::size_t index) const {
357
    return getSpectrum(index).dataE();
358
  }
359
  /// Deprecated, use dx() instead. Returns the error const
360
  virtual const MantidVec &dataDx(const std::size_t index) const {
361
    return getSpectrum(index).dataDx();
362
  }
363

364
365
366
  virtual double getXMin() const;
  virtual double getXMax() const;
  virtual void getXMinMax(double &xmin, double &xmax) const;
367

368
  /// Deprecated, use sharedX() instead. Returns a pointer to the x data
369
370
  virtual Kernel::cow_ptr<HistogramData::HistogramX>
  refX(const std::size_t index) const {
371
    return getSpectrum(index).ptrX();
372
373
  }

374
375
  /// Deprecated, use setSharedX() instead. Set the specified X array to point
  /// to the given existing array
376
377
  virtual void setX(const std::size_t index,
                    const Kernel::cow_ptr<HistogramData::HistogramX> &X) {
378
    getSpectrum(index).setX(X);
379
380
  }

381
382
  /// Deprecated, use setSharedX() instead. Set the specified X array to point
  /// to the given existing array
383
384
  virtual void setX(const std::size_t index,
                    const boost::shared_ptr<HistogramData::HistogramX> &X) {
385
    getSpectrum(index).setX(X);
386
387
  }

388
389
  /**
   * Probes if DX (X Error) values were set on a particular spectrum
Nick Draper's avatar
Nick Draper committed
390
   * @param index: the workspace index
391
   */
392
  virtual bool hasDx(const std::size_t index) const {
393
    return getSpectrum(index).hasDx();
394
395
  }

396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
  /// Generate the histogram or rebin the existing histogram.
  virtual void generateHistogram(const std::size_t index, const MantidVec &X,
                                 MantidVec &Y, MantidVec &E,
                                 bool skipError = false) const = 0;

  /// Return a vector with the integrated counts for all spectra withing the
  /// given range
  virtual void getIntegratedSpectra(std::vector<double> &out, const double minX,
                                    const double maxX,
                                    const bool entireRange) const;

  /// Return an index in the X vector for an x-value close to a given value
  std::pair<size_t, double> getXIndex(size_t i, double x, bool isLeft = true,
                                      size_t start = 0) const;

  //----------------------------------------------------------------------

  int axes() const;
Owen Arnold's avatar
Owen Arnold committed
414
  virtual Axis *getAxis(const std::size_t &axisIndex) const;
415
  void replaceAxis(const std::size_t &axisIndex, std::unique_ptr<Axis> newAxis);
416

417
418
419
420
  /// Will return the number of Axis currently stored in the workspace it is not
  /// always safe to assume it is just 2
  size_t numberOfAxis() const;

Hahn, Steven's avatar
Hahn, Steven committed
421
422
423
  /// Returns true if the workspace contains common X bins with log spacing
  virtual bool isCommonLogBins() const;

424
425
  /// Returns true if the workspace contains data in histogram form (as
  /// opposed to point-like)
426
427
  virtual bool isHistogramData() const;

428
  /// Returns true if the workspace contains common X bins
429
430
431
432
  virtual bool isCommonBins() const;

  std::string YUnit() const;
  void setYUnit(const std::string &newUnit);
433
434
  std::string YUnitLabel(bool useLatex = false,
                         bool plotAsDistribution = false) const;
435
436
437
  void setYUnitLabel(const std::string &newLabel);

  /// Are the Y-values dimensioned?
438
  bool isDistribution() const;
439
  void setDistribution(bool newValue);
440
441
442
443

  // Methods to set and access masked bins
  void maskBin(const size_t &workspaceIndex, const size_t &binIndex,
               const double &weight = 1.0);
444
  void flagMasked(const size_t &index, const size_t &binIndex,
445
                  const double &weight = 1.0);
446
  bool hasMaskedBins(const size_t &workspaceIndex) const;
447
  bool hasAnyMaskedBins() const;
448
449
  /// Masked bins for each spectrum are stored as a set of pairs containing <bin
  /// index, weight>
450
  using MaskList = std::map<size_t, double>;
451
  const MaskList &maskedBins(const size_t &workspaceIndex) const;
452
  std::vector<size_t> maskedBinsIndices(const size_t &workspaceIndex) const;
453
  void setMaskedBins(const size_t workspaceIndex, const MaskList &maskedBins);
454
455

  // Methods handling the internal monitor workspace
456
457
  virtual void
  setMonitorWorkspace(const boost::shared_ptr<MatrixWorkspace> &monitorWS);
458
459
460
461
462
463
464
  boost::shared_ptr<MatrixWorkspace> monitorWorkspace() const;

  void loadInstrumentNexus(::NeXus::File *file);

  //=====================================================================================
  // MD Geometry methods
  //=====================================================================================
465
466
467
468
469
  size_t getNumDims() const override;
  boost::shared_ptr<const Mantid::Geometry::IMDDimension>
  getDimension(size_t index) const override;
  boost::shared_ptr<const Mantid::Geometry::IMDDimension>
  getDimensionWithId(std::string id) const override;
470
471
472
473
474
475
476
477
478
  //=====================================================================================
  // End MD Geometry methods
  //=====================================================================================

  //=====================================================================================
  // IMDWorkspace methods
  //=====================================================================================

  /// Gets the number of points available on the workspace.
479
  uint64_t getNPoints() const override;
480
  /// Get the number of points available on the workspace.
481
  uint64_t getNEvents() const override { return this->getNPoints(); }
482
483
484
485
486
  /// Dimension id for x-dimension.
  static const std::string xDimensionId;
  /// Dimensin id for y-dimension.
  static const std::string yDimensionId;
  /// Generate a line plot through the matrix workspace.
487
488
489
  LinePlot getLinePlot(const Mantid::Kernel::VMD &start,
                       const Mantid::Kernel::VMD &end,
                       Mantid::API::MDNormalization normalize) const override;
490
  /// Get the signal at a coordinate in the workspace.
491
492
493
  signal_t getSignalAtCoord(
      const coord_t *coords,
      const Mantid::API::MDNormalization &normalization) const override;
494
  /// Get the signal at a coordinate in the workspace
495
  signal_t getSignalWithMaskAtCoord(
Matthew D Jones's avatar
Matthew D Jones committed
496
      const coord_t *coords,
497
      const Mantid::API::MDNormalization &normalization) const override;
498
499
  /// Create iterators. Partitions the iterators according to the number of
  /// cores.
500
  std::vector<std::unique_ptr<IMDIterator>> createIterators(
501
      size_t suggestedNumCores = 1,
502
      Mantid::Geometry::MDImplicitFunction *function = nullptr) const override;
503
504

  /// Apply masking.
505
506
  void setMDMasking(std::unique_ptr<Mantid::Geometry::MDImplicitFunction>
                        maskingRegion) override;
507
  /// Clear exsting masking.
508
  void clearMDMasking() override;
509
510

  /// @return the special coordinate system used if any.
511
512
  Mantid::Kernel::SpecialCoordinateSystem
  getSpecialCoordinateSystem() const override;
513

514
515
516
  // Check if this class has an oriented lattice on a sample object
  virtual bool hasOrientedLattice() const override;

Hahn, Steven's avatar
Hahn, Steven committed
517
  virtual std::pair<int64_t, int64_t> find(double value) const;
518

Hahn, Steven's avatar
Hahn, Steven committed
519
520
521
  //=====================================================================================
  // End IMDWorkspace methods
  //=====================================================================================
Hahn, Steven's avatar
Hahn, Steven committed
522

Hahn, Steven's avatar
Hahn, Steven committed
523
524
525
  //=====================================================================================
  // Image methods
  //=====================================================================================
526

Hahn, Steven's avatar
Hahn, Steven committed
527
528
529
  /// Get start and end x indices for images
  std::pair<size_t, size_t> getImageStartEndXIndices(size_t i, double startX,
                                                     double endX) const;
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
  /// Create an image of Ys.
  MantidImage_sptr getImageY(size_t start = 0, size_t stop = 0,
                             size_t width = 0, double startX = EMPTY_DBL(),
                             double endX = EMPTY_DBL()) const;
  /// Create an image of Es.
  MantidImage_sptr getImageE(size_t start = 0, size_t stop = 0,
                             size_t width = 0, double startX = EMPTY_DBL(),
                             double endX = EMPTY_DBL()) const;
  /// Copy the data (Y's) from an image to this workspace.
  virtual void setImageY(const MantidImage &image, size_t start = 0,
                         bool parallelExecution = true);
  /// Copy the data from an image to this workspace's errors.
  virtual void setImageE(const MantidImage &image, size_t start = 0,
                         bool parallelExecution = true);

  //=====================================================================================
  // End image methods
  //=====================================================================================

549
550
  void invalidateCachedSpectrumNumbers();

551
552
553
554
  /// Invalidates the commons bins flag.  This is generally called when a method
  /// could allow the X values to be changed.
  void invalidateCommonBinsFlag() { m_isCommonBinsFlagValid.store(false); }

555
protected:
556
557
558
  /// Protected copy constructor. May be used by childs for cloning.
  MatrixWorkspace(const MatrixWorkspace &other);

559
560
  MatrixWorkspace(
      const Parallel::StorageMode storageMode = Parallel::StorageMode::Cloned);
561
562
563
564
565

  /// Initialises the workspace. Sets the size and lengths of the arrays. Must
  /// be overloaded.
  virtual void init(const std::size_t &NVectors, const std::size_t &XLength,
                    const std::size_t &YLength) = 0;
566
  virtual void init(const HistogramData::Histogram &histogram) = 0;
567

568
569
  virtual ISpectrum &getSpectrumWithoutInvalidation(const size_t index) = 0;

570
  void updateCachedDetectorGrouping(const size_t index) const override;
571

572
  /// A vector of pointers to the axes for this workspace
573
  std::vector<std::unique_ptr<Axis>> m_axes;
574
575

private:
Robert Applin's avatar
Robert Applin committed
576
577
578
579
580
581
582
  std::size_t binIndexOfValue(Mantid::HistogramData::HistogramX const &xValues,
                              double const &xValue, bool const &ascendingOrder,
                              double const &tolerance) const;
  std::size_t xIndexOfValue(Mantid::HistogramData::HistogramX const &xValues,
                            double const &xValue,
                            double const &tolerance) const;

583
  MatrixWorkspace *doClone() const override = 0;
584
  MatrixWorkspace *doCloneEmpty() const override = 0;
585

586
587
588
589
590
591
592
593
594
  /// Create an MantidImage instance.
  MantidImage_sptr
  getImage(const MantidVec &(MatrixWorkspace::*read)(std::size_t const) const,
           size_t start, size_t stop, size_t width, size_t indexStart,
           size_t indexEnd) const;
  /// Copy data from an image.
  void setImage(MantidVec &(MatrixWorkspace::*dataVec)(const std::size_t),
                const MantidImage &image, size_t start, bool parallelExecution);

595
  void setIndexInfoWithoutISpectrumUpdate(const Indexing::IndexInfo &indexInfo);
596
  void buildDefaultSpectrumDefinitions();
597
598
  void rebuildDetectorIDGroupings();

599
  std::unique_ptr<Indexing::IndexInfo> m_indexInfo;
600

601
  /// Has this workspace been initialised?
602
  bool m_isInitialized{false};
603
604
605
606
607
608

  /// The unit for the data values (e.g. Counts)
  std::string m_YUnit;
  /// A text label for use when plotting spectra
  std::string m_YUnitLabel;

609
610
611
612
  /// Flag indicating if the common bins flag is in a valid state
  mutable std::atomic<bool> m_isCommonBinsFlagValid{false};
  /// Flag indicating whether the data has common bins
  mutable bool m_isCommonBinsFlag{false};
613
614
  /// A mutex protecting the update of m_isCommonBinsFlag.
  mutable std::mutex m_isCommonBinsMutex;
615

616
  /// The set of masked bins in a map keyed on workspace index
617
618
619
620
621
622
  std::map<int64_t, MaskList> m_masks;

  /// A workspace holding monitor data relating to the main data in the
  /// containing workspace (null if none).
  boost::shared_ptr<MatrixWorkspace> m_monitorWorkspace;

623
624
  mutable std::atomic<bool> m_indexInfoNeedsUpdate{true};
  mutable std::mutex m_indexInfoMutex;
625

626
627
628
629
630
631
protected:
  /// Getter for the dimension id based on the axis.
  std::string getDimensionIdFromAxis(const int &axisIndex) const;
};

/// shared pointer to the matrix workspace base class
632
using MatrixWorkspace_sptr = boost::shared_ptr<MatrixWorkspace>;
633
/// shared pointer to the matrix workspace base class (const version)
634
using MatrixWorkspace_const_sptr = boost::shared_ptr<const MatrixWorkspace>;
635
636
637

} // namespace API
} // namespace Mantid