forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Frequencies.cpp
35 lines (31 loc) · 1.45 KB
/
Frequencies.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/Frequencies.h"
#include "MantidHistogramData/BinEdges.h"
#include "MantidHistogramData/Counts.h"
namespace Mantid::HistogramData {
/// Constructs Frequencies from Counts and bin width based on BinEdges.
Frequencies::Frequencies(const Counts &counts, const BinEdges &edges) : Frequencies(Counts(counts), edges) {}
/// Move-constructs Frequencies from Counts and bin width based on BinEdges.
Frequencies::Frequencies(Counts &&counts, const BinEdges &edges) {
if (!counts)
return;
if (!edges)
throw std::logic_error("Frequencies: Cannot construct from Counts -- BinEdges are NULL.");
if ((counts.size() + 1) != edges.size())
if (!counts.empty() || !edges.empty())
throw std::logic_error("Frequencies: Cannot construct from Counts -- "
"BinEdges size does not match.");
// Cannot move counts private data since it is of different type.
m_data = counts.cowData();
counts = 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