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
{
Peak & peak = peaks[index];
if (m_name == "RunNumber")
s << peak.getRunNumber();
else if (m_name == "DetID")
s << peak.getDetectorID();
else if (m_name == "BankName")
s << peak.getBankName();
else if (m_name == "QLab")
s << peak.getQLabFrame();
else if (m_name == "QSample")
s << peak.getQSampleFrame();
else
Janik Zikovsky
committed
s << peak.getValueByColName(m_name);
Janik Zikovsky
committed
}
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{
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?");
}
Anders Markvardsen
committed
/// Pointer to a data element
const void* PeakColumn::void_pointer(int /*index*/) const
{
throw std::runtime_error("const version of void_pointer() not implemented. Looks to be unused?");
}
Janik Zikovsky
committed
} // namespace Mantid
} // namespace DataObjects