13#include <boost/variant/get.hpp>
23size_t NCELL_ITEM_CACHED = 100;
29class ColumnNameToType {
68const std::string typeFromName(
const std::string &
name) {
69 static ColumnNameToType typeIndex;
70 auto iter = typeIndex.data().find(
name);
71 if (iter != typeIndex.data().end()) {
74 throw std::runtime_error(
"PeakColumn - Unknown column name: \"" +
name +
76 "Peak column names/types must be explicitly marked in PeakColumn.cpp");
90 const std::string key =
"PeakColumn.hklPrec";
91 auto hklPrec = ConfigService::Instance().getValue<
int>(key);
93 if (!hklPrec.has_value()) {
94 g_log.
information() <<
"In PeakColumn constructor, did not find any value for '" << key
95 <<
"' from the Config Service. Using default: " << this->m_hklPrec <<
"\n";
106 if (type() ==
"double") {
107 return typeid(double);
108 }
else if (type() ==
"int") {
110 }
else if (type() ==
"str") {
111 return typeid(std::string);
112 }
else if (type() ==
"V3D") {
115 throw std::runtime_error(
"PeakColumn::get_type_info() - Unknown column type: " + m_name);
121 if (type() ==
"double") {
122 return typeid(
double *);
123 }
else if (type() ==
"int") {
124 return typeid(
int *);
125 }
else if (type() ==
"str") {
126 return typeid(std::string *);
127 }
else if (type() ==
"V3D") {
128 return typeid(
V3D *);
130 throw std::runtime_error(
"PeakColumn::get_pointer_type_info() -: " + m_name);
141 T &peak = m_peaks[
index];
142 auto fullPeak =
dynamic_cast<Peak *
>(&peak);
144 s.imbue(std::locale(
"C"));
145 std::ios::fmtflags fflags(s.flags());
146 if (m_name ==
"RunNumber")
147 s << peak.getRunNumber();
148 else if (m_name ==
"DetID" && fullPeak) {
149 s << fullPeak->getDetectorID();
150 }
else if (m_name ==
"BankName" && fullPeak)
151 s << fullPeak->getBankName();
152 else if (m_name ==
"QLab")
153 s << peak.getQLabFrame();
154 else if (m_name ==
"QSample")
155 s << peak.getQSampleFrame();
156 else if (m_name ==
"h") {
157 s << std::fixed << std::setprecision(m_hklPrec) << peak.getH();
158 }
else if (m_name ==
"k") {
159 s << std::fixed << std::setprecision(m_hklPrec) << peak.getK();
160 }
else if (m_name ==
"l") {
161 s << std::fixed << std::setprecision(m_hklPrec) << peak.getL();
162 }
else if (m_name ==
"PeakNumber") {
163 s << peak.getPeakNumber();
164 }
else if (m_name ==
"IntHKL") {
165 s << peak.getIntHKL();
166 }
else if (m_name ==
"IntMNP") {
167 s << peak.getIntMNP();
169 s << peak.getValueByColName(m_name);
181 if (this->getReadOnly() ||
index >= m_peaks.size())
189 g_log.
error() <<
"Could not convert string '" << text <<
"' to a number.\n";
192 setPeakHKLOrRunNumber(
index, val);
201 if (this->getReadOnly() ||
index >= m_peaks.size())
207 }
catch (std::exception &e) {
208 g_log.
error() <<
"Could not convert input to a number. " << e.what() <<
'\n';
212 setPeakHKLOrRunNumber(
index, val);
218 return !((m_name ==
"h") || (m_name ==
"k") || (m_name ==
"l") || (m_name ==
"RunNumber"));
229 return sizeof(double) *
static_cast<long int>(m_peaks.size());
241 "added through the PeaksWorkspace "
254 "inserted through the PeaksWorkspace "
267 "remove through the PeaksWorkspace "
277 const auto *constThis =
const_cast<const PeakColumn *
>(
this);
278 return const_cast<void *
>(constThis->void_pointer(
index));
287 const T &peak = m_peaks[
index];
296 if (m_oldRows.size() > NCELL_ITEM_CACHED) {
297 m_oldRows.pop_back();
299 auto &
value = m_oldRows.front();
301 if (type() ==
"double") {
303 return boost::get<double>(&
value);
304 }
else if (m_name ==
"RunNumber") {
305 value = peak.getRunNumber();
306 return boost::get<int>(&
value);
307 }
else if (m_name ==
"PeakNumber") {
308 value = peak.getPeakNumber();
309 return boost::get<int>(&
value);
310 }
else if (m_name ==
"DetID" && fullPeak) {
311 value = fullPeak->getDetectorID();
312 return boost::get<int>(&
value);
313 }
else if (m_name ==
"BankName" && fullPeak) {
314 value = fullPeak->getBankName();
315 return boost::get<std::string>(&
value);
316 }
else if (m_name ==
"QLab") {
317 value = peak.getQLabFrame();
318 return boost::get<Kernel::V3D>(&
value);
319 }
else if (m_name ==
"QSample") {
320 value = peak.getQSampleFrame();
321 return boost::get<Kernel::V3D>(&
value);
322 }
else if (m_name ==
"IntHKL") {
323 value = peak.getIntHKL();
324 return boost::get<Kernel::V3D>(&
value);
325 }
else if (m_name ==
"IntMNP") {
326 value = peak.getIntMNP();
327 return boost::get<Kernel::V3D>(&
value);
329 throw std::runtime_error(
"void_pointer() - Unknown peak column name or type: " + m_name);
339 throw std::runtime_error(
"PeakColumn::toDouble() not implemented, PeakColumn "
340 "is has no general write access");
344 throw std::runtime_error(
"fromDouble() not implemented, PeakColumn is has no "
345 "general write access");
349 T &peak = m_peaks[
index];
352 else if (m_name ==
"k")
354 else if (m_name ==
"l")
356 else if (m_name ==
"RunNumber")
357 peak.setRunNumber(
static_cast<int>(val));
359 throw std::runtime_error(
"Unexpected column " + m_name +
" being set.");
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
std::unordered_map< std::string, std::string > m_type_index
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
const std::string & name() const
Name (caption) of the column.
PeakColumn : a Column sub-class used to display peak information as a TableWorkspace.
void fromDouble(size_t i, double value) override
Assign from double.
const std::type_info & get_type_info() const override
Returns typeid for the data in the column.
void * void_pointer(size_t index) override
Pointer to a data element.
void remove(size_t index) override
Removes an item.
bool isBool() const override
Specialized type check.
void insert(size_t index) override
Inserts an item.
bool getReadOnly() const override
PeakColumn(std::vector< T > &peaks, const std::string &name)
Construct a column with a reference to the peaks list, a name & type.
void setPeakHKLOrRunNumber(const size_t index, const double val)
Sets the correct value in the referenced peak.
const std::type_info & get_pointer_type_info() const override
Returns typeid for the pointer type to the data element in the column.
int m_hklPrec
Precision of hkl in table workspace.
bool isNumber() const override
Are elements of the column interpretable as a number?
void read(size_t index, const std::string &text) override
Read in some text and convert to a number in the PeaksWorkspace.
double toDouble(size_t i) const override
Cast to double.
void resize(size_t count) override
Sets the new column size.
boost::variant< double, int, std::string, Kernel::V3D > CacheValueType
Type of the row cache value.
long int sizeOfData() const override
Must return overall memory size taken by the column.
PeakColumn * clone() const override
Clone.
void print(size_t index, std::ostream &s) const override
Prints.
Structure describing a single-crystal peak.
double getValueByColName(std::string colName) const override
Helper function for displaying/sorting peaks.
Marks code as not implemented yet.
The Logger class is in charge of the publishing messages from the framework through various channels.
void error(const std::string &msg)
Logs at error level.
void information(const std::string &msg)
Logs at information level.
Kernel::Logger g_log("ExperimentInfo")
static logger object
int convert(const std::string &A, T &out)
Convert a string into a number.