16#include "MantidDataObjects/DllConfig.h"
29#include "tbb/parallel_for.h"
34using namespace boost::posix_time;
35using Mantid::Types::Core::DateAndTime;
40Kernel::Logger
g_log(
"EventWorkspace");
45using Kernel::Exception::NotImplementedError;
53 for (
const auto &el : other.data) {
55 auto newel = std::make_unique<EventList>(*el);
57 newel->setMRU(this->
mru.get());
58 this->
data.emplace_back(std::move(newel));
82void EventWorkspace::init(
const std::size_t &NVectors,
const std::size_t &XLength,
const std::size_t &YLength) {
83 static_cast<void>(XLength);
84 static_cast<void>(YLength);
88 throw std::out_of_range(
"Zero pixels specified to EventWorkspace::init");
94 HistogramData::BinEdges edges{0.0, std::numeric_limits<double>::min()};
97 data.resize(NVectors);
101 for (
size_t i = 0; i < NVectors; i++) {
102 data[i] = std::make_unique<EventList>(el);
109 m_axes[0] = std::make_unique<API::RefAxis>(
this);
110 m_axes[1] = std::make_unique<API::SpectraAxis>(
this);
114 if (
histogram.xMode() != HistogramData::Histogram::XMode::BinEdges)
115 throw std::runtime_error(
"EventWorkspace can only be initialized with XMode::BinEdges");
118 throw std::runtime_error(
"EventWorkspace cannot be initialized non-NULL Y or E data");
123 for (
size_t i = 0; i <
data.size(); i++) {
124 data[i] = std::make_unique<EventList>(el);
130 m_axes[0] = std::make_unique<API::RefAxis>(
this);
131 m_axes[1] = std::make_unique<API::SpectraAxis>(
this);
138 throw std::runtime_error(
"There are no pixels in the event workspace, "
139 "therefore cannot determine if it is ragged.");
141 const auto numberOfBins =
data[0]->histogram_size();
142 return std::any_of(
data.cbegin(),
data.cend(),
143 [&numberOfBins](
const auto &eventList) { return numberOfBins != eventList->histogram_size(); });
150 return std::accumulate(
151 data.begin(),
data.end(),
static_cast<size_t>(0),
152 [](
size_t value,
const std::unique_ptr<EventList> &histo) { return value + histo->histogram_size(); });
159 throw std::range_error(
"EventWorkspace::blocksize, no pixels in workspace, "
160 "therefore cannot determine blocksize (# of bins).");
162 size_t numBins =
data[0]->histogram_size();
163 const auto iterPos = std::find_if_not(
data.cbegin(),
data.cend(),
164 [numBins](
const auto &iter) { return numBins == iter->histogram_size(); });
165 if (iterPos !=
data.cend())
166 throw std::length_error(
"blocksize undefined because size of histograms is not equal");
179 throw std::invalid_argument(
"Could not find number of bins in a histogram at index " +
std::to_string(
index) +
180 ": index is too large.");
190 auto maxNumberOfBins =
data[0]->histogram_size();
191 for (
const auto &iter :
data) {
192 const auto numberOfBins = iter->histogram_size();
193 if (numberOfBins > maxNumberOfBins)
194 maxNumberOfBins = numberOfBins;
196 return maxNumberOfBins;
216 throw std::range_error(
"EventWorkspace::getSpectrum, workspace index out of range");
243 Mantid::Types::Core::DateAndTime tMin = DateAndTime::maximum();
244 size_t numWorkspace = this->
data.size();
246 for (
size_t workspaceIndex = 0; workspaceIndex < numWorkspace; workspaceIndex++) {
261 Mantid::Types::Core::DateAndTime tMax = DateAndTime::minimum();
262 size_t numWorkspace = this->
data.size();
264 for (
size_t workspaceIndex = 0; workspaceIndex < numWorkspace; workspaceIndex++) {
278 Mantid::Types::Core::DateAndTime &Tmax)
const {
280 Tmax = DateAndTime::minimum();
281 Tmin = DateAndTime::maximum();
283 auto numWorkspace =
static_cast<int64_t
>(this->
data.size());
286 DateAndTime tTmax = DateAndTime::minimum();
287 DateAndTime tTmin = DateAndTime::maximum();
288#pragma omp for nowait
289 for (int64_t workspaceIndex = 0; workspaceIndex < numWorkspace; workspaceIndex++) {
291 DateAndTime tempMin, tempMax;
293 tTmin = std::min(tTmin, tempMin);
294 tTmax = std::max(tTmax, tempMax);
298 Tmin = std::min(Tmin, tTmin);
299 Tmax = std::max(Tmax, tTmax);
311 const auto L1 = specInfo.l1();
314 Mantid::Types::Core::DateAndTime tMin = DateAndTime::maximum();
315 size_t numWorkspace = this->
data.size();
318 for (
size_t workspaceIndex = 0; workspaceIndex < numWorkspace; workspaceIndex++) {
319 const auto L2 = specInfo.l2(workspaceIndex);
320 const double tofFactor = L1 / (L1 + L2);
337 const auto L1 = specInfo.l1();
340 Mantid::Types::Core::DateAndTime tMax = DateAndTime::minimum();
341 size_t numWorkspace = this->
data.size();
343 for (
size_t workspaceIndex = 0; workspaceIndex < numWorkspace; workspaceIndex++) {
344 const auto L2 = specInfo.l2(workspaceIndex);
345 const double tofFactor = L1 / (L1 + L2);
367 double xmin = std::numeric_limits<double>::max();
370 size_t numWorkspace = this->
data.size();
371 for (
size_t workspaceIndex = 0; workspaceIndex < numWorkspace; workspaceIndex++) {
392 double xmax = std::numeric_limits<double>::lowest();
395 size_t numWorkspace = this->
data.size();
396 for (
size_t workspaceIndex = 0; workspaceIndex < numWorkspace; workspaceIndex++) {
413 xmin = std::numeric_limits<double>::max();
418 auto numWorkspace =
static_cast<int64_t
>(this->
data.size());
423#pragma omp for nowait
424 for (int64_t workspaceIndex = 0; workspaceIndex < numWorkspace; workspaceIndex++) {
426 tXmin = std::min(evList.
getTofMin(), tXmin);
427 tXmax = std::max(evList.
getTofMax(), tXmax);
431 xmin = std::min(xmin, tXmin);
432 xmax = std::max(xmax, tXmax);
440 return std::accumulate(
data.cbegin(),
data.cend(),
size_t{0},
441 [](
const auto total,
const auto &list) { return total + list->getNumberEvents(); });
450 for (
const auto &list : this->
data) {
452 if (
static_cast<int>(out) <
static_cast<int>(thisType)) {
467 for (
auto &eventList : this->
data)
468 eventList->switchTo(type);
490 size_t total = std::accumulate(
data.begin(),
data.end(),
size_t{0},
491 [](
size_t total,
auto &list) { return total + list->getMemorySize(); });
511[[deprecated("The dataX() method is deprecated in
Mantid 7.0. Use mutableX() instead.")]]
520[[deprecated(
"The dataDx() method is deprecated in Mantid 7.0. Use mutableDx() instead.")]]
531[[deprecated("The dataY() method is deprecated in
Mantid 7.0. Use mutableY() instead.")]]
534 "array: you can't modify the histogrammed data in "
535 "an EventWorkspace!");
541[[deprecated(
"The dataE() method is deprecated in Mantid 7.0. Use mutableE() instead.")]]
544 "array: you can't modify the histogrammed data in "
545 "an EventWorkspace!");
551[[deprecated(
"The dataX() method is deprecated in Mantid 7.0. Use x() instead.")]]
559[[deprecated(
"The dataDx() method is deprecated in Mantid 7.0. Use dx() instead.")]]
567[[deprecated(
"The dataY() method is deprecated in Mantid 7.0. Use y() instead.")]]
575[[deprecated(
"The dataE() method is deprecated in Mantid 7.0. Use e() instead.")]]
583[[deprecated(
"The refX() method is deprecated in Mantid 7.0. Use sharedX() instead.")]]
599 bool skipError)
const {
601 throw std::range_error(
"EventWorkspace::generateHistogram, histogram number out of range");
602 this->
data[
index]->generateHistogram(X,
Y, E, skipError);
618 throw std::range_error(
"EventWorkspace::generateHistogramPulseTime, "
619 "histogram number out of range");
620 this->
data[
index]->generateHistogramPulseTime(X,
Y, E, skipError);
631 for (
auto &eventList : this->
data)
632 eventList->setHistogram(
x);
643 double tofmin, tofmax;
648 if (tofmin > tofmax) {
650 tofmax = std::numeric_limits<double>::min();
651 }
else if (tofmin == tofmax) {
652 tofmax += std::numeric_limits<double>::min();
665 void operator()(
const tbb::blocked_range<size_t> &range)
const {
666 for (
size_t wi = range.begin(); wi < range.end(); ++wi) {
670 if (spectrum.empty())
696 std::find_if(
data.cbegin(),
data.cend(), [&order](
const auto &list) { return list->getSortType() != order; });
697 if (it !=
data.cend())
709 if (prog !=
nullptr) {
717 constexpr size_t GRAINSIZE_DEFAULT{100};
718 const size_t grainsize = std::min<size_t>(GRAINSIZE_DEFAULT, (this->
getNumberHistograms() / GRAINSIZE_DEFAULT) + 1);
719 tbb::parallel_for(tbb::blocked_range<size_t>(0,
data.size(), grainsize), task);
735 const bool entireRange)
const {
746 out[wksp_index] = el->
integrate(minX, maxX, entireRange);
755IPropertyManager::getValue<Mantid::DataObjects::EventWorkspace_sptr>(
const std::string &
name)
const {
760 std::string message =
761 "Attempt to assign property " +
name +
" to incorrect type. Expected shared_ptr<EventWorkspace>.";
762 throw std::runtime_error(message);
768IPropertyManager::getValue<Mantid::DataObjects::EventWorkspace_const_sptr>(
const std::string &
name)
const {
772 return prop->operator()();
774 std::string message =
775 "Attempt to assign property " +
name +
" to incorrect type. Expected const shared_ptr<EventWorkspace>.";
776 throw std::runtime_error(message);
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
#define PARALLEL_FOR_NO_WSP_CHECK()
#define GNU_DIAG_OFF(x)
This is a collection of macros for turning compiler warnings off in a controlled manner.
#define DECLARE_WORKSPACE(classname)
const SpectrumInfo & spectrumInfo() const
Return a reference to the SpectrumInfo object.
size_t numberOfDetectorGroups() const
Returns the number of detector groups.
const Run & run() const
Run details object access.
This class provides an interface to an EventWorkspace.
void setHistogram(T &&...data)
Sets the Histogram associated with this spectrum.
void setMatrixWorkspace(MatrixWorkspace *matrixWorkspace, const size_t index)
Sets the MatrixWorkspace pointer (pointer to the owning workspace).
const HistogramData::HistogramX & x() const
const HistogramData::HistogramDx & dx() const
Kernel::cow_ptr< HistogramData::HistogramX > sharedX() const
std::vector< std::unique_ptr< Axis > > m_axes
A vector of pointers to the axes for this workspace.
virtual size_t getMemorySizeForXAxes() const
Returns the memory used (in bytes) by the X axes, handling ragged bins.
void invalidateCommonBinsFlag()
Invalidates the commons bins flag.
HistogramData::Histogram histogram(const size_t index) const
Returns the Histogram at the given workspace index.
Helper class for reporting progress from algorithms.
size_t getMemorySize() const override
Return an approximate memory size for the object in bytes.
Mantid::Types::Core::DateAndTime getTimeAtSampleMax(const double &tofFactor, const double &tofOffset) const override
Get the maximum time at sample.
double getTofMax() const override
void setSortOrder(const EventSortType order) const
Manually set the event list sort order value.
double getTofMin() const override
const HistogramData::HistogramY & y() const override
void getPulseTimeMinMax(Mantid::Types::Core::DateAndTime &tMin, Mantid::Types::Core::DateAndTime &tM) const
Mantid::Types::Core::DateAndTime getPulseTimeMax() const override
MantidVec & dataDx() override
Deprecated, use mutableDx() instead.
Mantid::Types::Core::DateAndTime getTimeAtSampleMin(const double &tofFactor, const double &tofOffset) const override
Get the minimum time at sample.
const HistogramData::HistogramE & e() const override
void integrate(const double minX, const double maxX, const bool entireRange, double &sum, double &error) const
Integrate the events between a range of X values, or all events.
Mantid::Types::Core::DateAndTime getPulseTimeMin() const override
Task for sorting an event list.
void operator()(const tbb::blocked_range< size_t > &range) const
const EventWorkspace * m_WS
EventWorkspace on which to sort.
EventSortType m_sortType
How to sort.
EventSortingTask(const EventWorkspace *WS, EventSortType sortType, Mantid::API::Progress *prog)
ctor
Mantid::API::Progress * prog
Optional Progress dialog.
This is a container for the MRU (most-recently-used) list of generated histograms.
This class is intended to fulfill the design specified in <https://github.com/mantidproject/documents...
void init(const std::size_t &, const std::size_t &, const std::size_t &) override
Initialize the pixels.
void generateHistogram(const std::size_t index, std::span< double const > X, MantidVec &Y, MantidVec &E, bool skipError=false) const override
Generate a new histogram from specified event list at the given index.
std::vector< std::unique_ptr< EventList > > data
A vector that holds the event list for each spectrum; the key is the workspace index,...
void setAllX(const HistogramData::BinEdges &x) override
Set all histogram X vectors.
double getEventXMax() const
Get them maximum x-value for the events themselves, ignoring the histogram representation.
EventList * getSpectrumUnsafe(const size_t index)
Returns a pointer to the EventList for a given spectrum in a timely manner.
MantidVec & dataY(const std::size_t) override
Deprecated, use mutableY() instead.
std::size_t getNumberBins(const std::size_t &index) const override
Returns the number of bins for a given histogram index.
Kernel::cow_ptr< HistogramData::HistogramX > refX(const std::size_t) const override
Deprecated, use sharedX() instead.
bool isHistogramData() const override
Returns true always - an EventWorkspace always represents histogramm-able data.
Mantid::Types::Core::DateAndTime getPulseTimeMin() const override
Get the minimum pulse time for events accross the entire workspace.
std::size_t getMaxNumberBins() const override
Returns the maximum number of bins in a workspace (works on ragged data).
EventList & getSpectrum(const size_t index) override
Return the underlying ISpectrum ptr at the given workspace index.
std::size_t MRUSize() const
Return how many entries in the Y MRU list are used.
void getEventXMinMax(double &xmin, double &xmax) const
Get them minimum and maximum x-values for the events themselves, ignoring the histogram representatio...
std::size_t getNumberHistograms() const override
Get the number of histograms, usually the same as the number of pixels or detectors.
void generateHistogramPulseTime(const std::size_t index, std::span< double const > X, MantidVec &Y, MantidVec &E, bool skipError=false) const
Generate a new histogram from specified event list at the given index.
double getTofMax() const override
void getPulseTimeMinMax(Mantid::Types::Core::DateAndTime &xmin, Mantid::Types::Core::DateAndTime &xmax) const
Get the maximum and mimumum pulse time for events accross the entire workspace.
Mantid::Types::Core::DateAndTime getTimeAtSampleMin(double tofOffset=0) const override
Get the minimum time at sample for events across the entire workspace.
~EventWorkspace() override
EventSortType getSortType() const
double getEventXMin() const
Get them minimum x-value for the events themselves, ignoring the histogram representation.
void switchEventType(const Mantid::API::EventType type)
Switch all event lists to the given event type.
Mantid::Types::Core::DateAndTime getPulseTimeMax() const override
Get the maximum pulse time for events accross the entire workspace.
MantidVec & dataDx(const std::size_t) override
Deprecated, use mutableDx() instead.
void getIntegratedSpectra(std::vector< double > &out, const double minX, const double maxX, const bool entireRange) const override
Integrate all the spectra in the matrix workspace within the range given.
bool threadSafe() const override
Returns true if the EventWorkspace is safe for multithreaded operations.
std::size_t size() const override
The total size of the workspace.
void sortAll(EventSortType sortType, Mantid::API::Progress *prog) const
EventList & getSpectrumWithoutInvalidation(const size_t index) override
Return const reference to EventList at the given workspace index.
void clearMRU() const override
Clears the MRU lists.
Mantid::API::EventType getEventType() const override
Get the EventType of the most-specialized EventList in the workspace.
double getTofMin() const override
bool isRaggedWorkspace() const override
Returns true if the workspace is ragged (has differently sized spectra).
MantidVec & dataX(const std::size_t) override
Deprecated, use mutableX() instead.
Mantid::Types::Core::DateAndTime getTimeAtSampleMax(double tofOffset=0) const override
Get the maximum time at sample for events across the entire workspace.
std::size_t getNumberEvents() const override
The total number of events across all of the spectra.
std::size_t blocksize() const override
Get the blocksize, aka the number of bins in the histogram.
size_t getMemorySize() const override
Returns the amount of memory used in bytes.
MantidVec & dataE(const std::size_t) override
Deprecated, use mutableE() instead.
std::unique_ptr< EventWorkspaceMRU > mru
Container for the MRU lists of the event lists contained.
void resetAllXToSingleBin() override
Set all Histogram X vectors to a single bin with boundaries that fit the TOF of all events across all...
Marks code as not implemented yet.
void reportIncrement(int inc, const std::string &msg="")
Sends the progress notification and increment the loop counter by more than one.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
The concrete, templated class for properties.
Implements a copy on write data template.
Kernel::Logger g_log("ExperimentInfo")
static logger object
EventType
What kind of event list is being stored.
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
EventSortType
How the event list is sorted.
std::shared_ptr< EventWorkspace > EventWorkspace_sptr
shared pointer to the EventWorkspace class
Helper class which provides the Collimation Length for SANS instruments.
std::vector< double > MantidVec
typedef for the data storage used in Mantid matrix workspaces
int32_t specnum_t
Typedef for a spectrum Number.
std::string to_string(const wide_integer< Bits, Signed > &n)