forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Counts.cpp
35 lines (31 loc) · 1.48 KB
/
Counts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidHistogramData/Counts.h"
#include "MantidHistogramData/BinEdges.h"
#include "MantidHistogramData/Frequencies.h"
namespace Mantid::HistogramData {
/// Constructs Counts from Frequencies and bin width based on BinEdges.
Counts::Counts(const Frequencies &frequencies, const BinEdges &edges) : Counts(Frequencies(frequencies), edges) {}
/// Move-constructs Counts from Frequencies and bin width based on BinEdges.
Counts::Counts(Frequencies &&frequencies, const BinEdges &edges) {
if (!frequencies)
return;
if (!edges)
throw std::logic_error("Counts: Cannot construct from Frequencies -- BinEdges are NULL.");
if ((frequencies.size() + 1) != edges.size())
if (!frequencies.empty() || !edges.empty())
throw std::logic_error("Counts: Cannot construct from Frequencies -- "
"BinEdges size does not match.");
// Cannot move frequencies private data since it is of different type.
m_data = frequencies.cowData();
frequencies = Kernel::cow_ptr<HistogramY>(nullptr);
auto &data = m_data.access();
for (size_t i = 0; i < data.size(); ++i) {
data[i] *= (edges[i + 1] - edges[i]);
}
}
} // namespace Mantid::HistogramData