Newer
Older
Janik Zikovsky
committed
#include "MantidDataObjects/PeakColumn.h"
#include "MantidKernel/System.h"
Janik Zikovsky
committed
#include "MantidKernel/Strings.h"
using namespace Mantid::Kernel;
Janik Zikovsky
committed
namespace Mantid
{
namespace DataObjects
{
//----------------------------------------------------------------------------------------------
/** Constructor
* @param peaks :: vector of peaks
*/
PeakColumn::PeakColumn(std::vector<Peak> & peaks, std::string name) :
peaks(peaks)
{
setName(name);
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
PeakColumn::~PeakColumn()
{
}
/// Returns typeid for the data in the column
const std::type_info& PeakColumn::get_type_info()const
{
return typeid(double);
Janik Zikovsky
committed
}
/// Returns typeid for the pointer type to the data element in the column
const std::type_info& PeakColumn::get_pointer_type_info()const
{
return typeid(double*);
Janik Zikovsky
committed
}
Janik Zikovsky
committed
//-------------------------------------------------------------------------------------
Janik Zikovsky
committed
/** Prints out the column string at the given row index.
*
* @param s :: stream to output
* @param index :: row index
*/
void PeakColumn::print(std::ostream& s, int index) const
Janik Zikovsky
committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{
Peak & peak = peaks[index];
if (m_name == "RunNumber")
s << peak.getRunNumber();
else if (m_name == "DetID")
s << peak.getDetectorID();
else if (m_name == "h")
s << peak.getH();
else if (m_name == "k")
s << peak.getK();
else if (m_name == "l")
s << peak.getL();
else if (m_name == "Wavelength")
s << peak.getWavelength();
else if (m_name == "Energy")
s << peak.getInitialEnergy();
else if (m_name == "TOF")
s << peak.getTOF();
else if (m_name == "DSpacing")
s << peak.getDSpacing();
else if (m_name == "Intens")
s << peak.getIntensity();
else if (m_name == "SigInt")
s << peak.getSigmaIntensity();
else if (m_name == "BinCount")
s << peak.getBinCount();
else if (m_name == "BankName")
s << peak.getBankName();
else if (m_name == "Row")
s << peak.getRow();
else if (m_name == "Col")
s << peak.getCol();
else if (m_name == "QLab")
s << peak.getQLabFrame();
else if (m_name == "QSample")
s << peak.getQSampleFrame();
else
throw std::runtime_error("Unexpected column name");
}
Janik Zikovsky
committed
//-------------------------------------------------------------------------------------
/** Read in some text and convert to a number in the PeaksWorkspace
*
* @param text :: string to read
* @param index :: index of the peak to modify
*/
void PeakColumn::read(const std::string & text, int index)
{
// Don't modify read-only ones
if (this->getReadOnly())
return;
// Avoid going out of bounds
if (size_t(index) >= peaks.size())
return;
// Reference to the peak in the workspace
Peak & peak = peaks[index];
// Convert to a double
double val = 0;
int success = Strings::convert(text, val);
Janik Zikovsky
committed
int ival = static_cast<int>(val);
if (success == 0)
Janik Zikovsky
committed
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
{
g_log.error() << "Could not convert string '" << text << "' to a number.\n";
return;
}
if (m_name == "h")
peak.setH(val);
else if (m_name == "k")
peak.setK(val);
else if (m_name == "l")
peak.setL(val);
else if (m_name == "RunNumber")
peak.setRunNumber(ival);
else
throw std::runtime_error("Unexpected column " + m_name + " being set.");
}
//-------------------------------------------------------------------------------------
/** @return true if the column is read-only */
bool PeakColumn::getReadOnly() const
{
if (
(m_name == "h") || (m_name == "k") || (m_name == "l") ||
(m_name == "RunNumber")
)
return false;
else
// Default to true for most columns
return true;
}
//-------------------------------------------------------------------------------------
Janik Zikovsky
committed
/// Specialized type check
bool PeakColumn::isBool()const
{
return false;
}
/// Must return overall memory size taken by the column.
long int PeakColumn::sizeOfData()const
{
return sizeof(double) * static_cast<long int>(peaks.size());
Janik Zikovsky
committed
}
/// Sets the new column size.
Janik Zikovsky
committed
{
throw std::runtime_error("Not implemented.");
}
/// Inserts an item.
Janik Zikovsky
committed
{
throw std::runtime_error("Not implemented.");
}
/// Removes an item.
Janik Zikovsky
committed
{
throw std::runtime_error("Not implemented.");
}
/// Pointer to a data element
void* PeakColumn::void_pointer(int /*index*/)
Janik Zikovsky
committed
{
throw std::runtime_error("void_pointer() not implemented. Looks to be unused?");
}
} // namespace Mantid
} // namespace DataObjects