-
Notifications
You must be signed in to change notification settings - Fork 121
/
ConvertToHistogram.cpp
60 lines (53 loc) · 1.94 KB
/
ConvertToHistogram.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include "MantidAlgorithms/ConvertToHistogram.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/VectorHelper.h"
namespace Mantid {
namespace Algorithms {
DECLARE_ALGORITHM(ConvertToHistogram)
using API::MatrixWorkspace_sptr;
using Mantid::MantidVec;
using std::size_t;
//------------------------------------------------------------------------------
// Private member functions
//------------------------------------------------------------------------------
/**
* Returns true if the algorithm needs to be run.
* @param inputWS pointer to input workspace
* @returns True if the input workspace needs to be run through this algorithm
*/
bool ConvertToHistogram::isProcessingRequired(
const MatrixWorkspace_sptr inputWS) const {
if (inputWS->isHistogramData()) {
g_log.information() << "Input workspace already contains histogram data. "
<< "OutputWorkspace set to InputWorkspace value.\n";
return false;
}
return true;
}
/**
* Returns the size of the new X vector
* @param inputWS pointer to input workspace
* @returns An integer giving the size of the new X vector
*/
size_t
ConvertToHistogram::getNewXSize(const MatrixWorkspace_sptr inputWS) const {
return (inputWS->blocksize() + 1);
}
/**
* Calculate the histogram boundaries. For uniform bins this should work
* correctly
* and should be convertable back to point data. For non-uniform bins the
* boundaries
* are guessed such that the boundary goes mid-way between each point
* @param inputX :: A const reference to the input data
*/
Kernel::cow_ptr<HistogramData::HistogramX> ConvertToHistogram::calculateXPoints(
Kernel::cow_ptr<HistogramData::HistogramX> inputX) const {
return HistogramData::BinEdges(HistogramData::Points(std::move(inputX)))
.cowData();
}
}
}