EventWorkspace.h 6.29 KB
Newer Older
1
2
3
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4
5
//   NScD Oak Ridge National Laboratory, European Spallation Source,
//   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6
// SPDX - License - Identifier: GPL - 3.0 +
7
#pragma once
8

9
#include "MantidAPI/IEventWorkspace.h"
10
#include "MantidAPI/ISpectrum.h"
11
12
#include "MantidDataObjects/EventList.h"
#include "MantidKernel/System.h"
13
#include <boost/date_time/posix_time/posix_time.hpp>
14
#include <string>
15

16
17
18
namespace Mantid {
namespace API {
class Progress;
19
}
20

21
namespace DataObjects {
22
class EventWorkspaceMRU;
23

24
25
/** \class EventWorkspace

26
27
28
    This class is intended to fulfill the design specified in
    <https://github.com/mantidproject/documents/tree/master/Design/Event
   WorkspaceDetailed Design Document.doc>
29
 */
30

31
class DLLExport EventWorkspace : public API::IEventWorkspace {
32

33
public:
Janik Zikovsky's avatar
Janik Zikovsky committed
34
  // The name of the workspace type.
35
  const std::string id() const override { return "EventWorkspace"; }
36

Janik Zikovsky's avatar
Janik Zikovsky committed
37
  // Constructor
38
39
  EventWorkspace(
      const Parallel::StorageMode storageMode = Parallel::StorageMode::Cloned);
40

Janik Zikovsky's avatar
Janik Zikovsky committed
41
  // Destructor
42
  ~EventWorkspace() override;
43

44
45
46
47
48
  /// Returns a clone of the workspace
  std::unique_ptr<EventWorkspace> clone() const {
    return std::unique_ptr<EventWorkspace>(doClone());
  }

49
50
51
52
53
  /// Returns a default-initialized clone of the workspace
  std::unique_ptr<EventWorkspace> cloneEmpty() const {
    return std::unique_ptr<EventWorkspace>(doCloneEmpty());
  }

Janik Zikovsky's avatar
Janik Zikovsky committed
54
  // Initialize the pixels
55
56
  void init(const std::size_t &, const std::size_t &,
            const std::size_t &) override;
57
  void init(const HistogramData::Histogram &histogram) override;
58

59
  bool threadSafe() const override;
60

61
62
  //------------------------------------------------------------

Janik Zikovsky's avatar
Janik Zikovsky committed
63
  // Returns the number of single indexable items in the workspace
64
  std::size_t size() const override;
65

Janik Zikovsky's avatar
Janik Zikovsky committed
66
  // Get the blocksize, aka the number of bins in the histogram
67
  std::size_t blocksize() const override;
68

69
  size_t getMemorySize() const override;
70

Janik Zikovsky's avatar
Janik Zikovsky committed
71
  // Get the number of histograms. aka the number of pixels or detectors.
72
  std::size_t getNumberHistograms() const override;
73

74
75
76
77
  EventList &getSpectrum(const size_t index) override {
    invalidateCommonBinsFlag();
    return getSpectrumWithoutInvalidation(index);
  }
78
  const EventList &getSpectrum(const size_t index) const override;
79
  EventList *getSpectrumUnsafe(const size_t index);
80
81

  //------------------------------------------------------------
82

83
  double getTofMin() const override;
84

85
  double getTofMax() const override;
86

87
88
89
90
  Mantid::Types::Core::DateAndTime getPulseTimeMin() const override;
  Mantid::Types::Core::DateAndTime getPulseTimeMax() const override;
  void getPulseTimeMinMax(Mantid::Types::Core::DateAndTime &xmin,
                          Mantid::Types::Core::DateAndTime &xmax) const;
91

92
  Mantid::Types::Core::DateAndTime
93
  getTimeAtSampleMin(double tofOffset = 0) const override;
94

95
  Mantid::Types::Core::DateAndTime
96
  getTimeAtSampleMax(double tofOffset = 0) const override;
97

98
99
100
101
  double getEventXMin() const;
  double getEventXMax() const;
  void getEventXMinMax(double &xmin, double &xmax) const;

102
103
104
105
106
107
108
109
  MantidVec &dataX(const std::size_t) override;
  MantidVec &dataY(const std::size_t) override;
  MantidVec &dataE(const std::size_t) override;
  MantidVec &dataDx(const std::size_t) override;
  const MantidVec &dataX(const std::size_t) const override;
  const MantidVec &dataY(const std::size_t) const override;
  const MantidVec &dataE(const std::size_t) const override;
  const MantidVec &dataDx(const std::size_t) const override;
110
111
  Kernel::cow_ptr<HistogramData::HistogramX>
  refX(const std::size_t) const override;
112

113
  /// Generate a new histogram from specified event list at the given index.
114
115
  void generateHistogram(const std::size_t index, const MantidVec &X,
                         MantidVec &Y, MantidVec &E,
116
                         bool skipError = false) const override;
117

118
  /// Generate a new histogram from specified event list at the given index.
119
120
121
  void generateHistogramPulseTime(const std::size_t index, const MantidVec &X,
                                  MantidVec &Y, MantidVec &E,
                                  bool skipError = false) const;
122

Janik Zikovsky's avatar
Janik Zikovsky committed
123
  // Set the x-axis data (histogram bins) for all pixels
124
  void setAllX(const HistogramData::BinEdges &x) override;
125

126
  // Update all X values to fit around all events
127
  void resetAllXToSingleBin() override;
128

Janik Zikovsky's avatar
Janik Zikovsky committed
129
  // The total number of events across all of the spectra.
130
  std::size_t getNumberEvents() const override;
131

Janik Zikovsky's avatar
Janik Zikovsky committed
132
  // Type of the events
133
  Mantid::API::EventType getEventType() const override;
134

Janik Zikovsky's avatar
Janik Zikovsky committed
135
  // Change the event type
136
137
  void switchEventType(const Mantid::API::EventType type);

138
139
  // Returns true always - an EventWorkspace always represents histogramm-able
  // data
140
  bool isHistogramData() const override;
141

Peterson, Peter's avatar
Peterson, Peter committed
142
  std::size_t MRUSize() const;
143

144
  void clearMRU() const override;
145

146
147
  EventSortType getSortType() const;

Janik Zikovsky's avatar
Janik Zikovsky committed
148
  // Sort all event lists. Uses a parallelized algorithm
149
150
  void sortAll(EventSortType sortType, Mantid::API::Progress *prog) const;
  void sortAllOld(EventSortType sortType, Mantid::API::Progress *prog) const;
151

152
153
154
  void getIntegratedSpectra(std::vector<double> &out, const double minX,
                            const double maxX,
                            const bool entireRange) const override;
155
  EventWorkspace &operator=(const EventWorkspace &other) = delete;
156

157
158
159
protected:
  /// Protected copy constructor. May be used by childs for cloning.
  EventWorkspace(const EventWorkspace &other);
Russell Taylor's avatar
Russell Taylor committed
160

161
private:
162
  EventWorkspace *doClone() const override { return new EventWorkspace(*this); }
163
164
165
  EventWorkspace *doCloneEmpty() const override {
    return new EventWorkspace(storageMode());
  }
166

167
168
  EventList &getSpectrumWithoutInvalidation(const size_t index) override;

169
170
  /** A vector that holds the event list for each spectrum; the key is
   * the workspace index, which is not necessarily the pixelid.
171
   */
172
  std::vector<std::unique_ptr<EventList>> data;
173

174
  /// Container for the MRU lists of the event lists contained.
175
  mutable std::unique_ptr<EventWorkspaceMRU> mru;
176
177
};

178
/// shared pointer to the EventWorkspace class
179
using EventWorkspace_sptr = std::shared_ptr<EventWorkspace>;
180
/// shared pointer to a const Workspace2D
181
using EventWorkspace_const_sptr = std::shared_ptr<const EventWorkspace>;
182

LamarMoore's avatar
LamarMoore committed
183
184
} // namespace DataObjects
} // namespace Mantid