Commit 8d456219 authored by Tobias WEBER's avatar Tobias WEBER
Browse files

started with internal data representation

parent c7457213
......@@ -73,6 +73,7 @@ add_executable(in20
tools/in20/main.cpp tools/in20/mainwnd.cpp tools/in20/mainwnd.h
tools/in20/filebrowser.cpp tools/in20/filebrowser.h
tools/in20/workspace.cpp tools/in20/workspace.h
tools/in20/data.cpp tools/in20/data.h
tools/in20/command.cpp tools/in20/command.h
${BISON_cliparser_OUTPUT_SOURCE} ${BISON_cliparser_OUTPUT_HEADER}
......
/**
* algorithm helpers
* @author Tobias Weber <tweber@ill.fr>
* @date 9-Apr-2018
* @license see 'LICENSE' file
*/
#ifndef __IN20_ALGOS_H__
#define __IN20_ALGOS_H__
#include <algorithm>
/**
* copy algorithm with interleave
*/
template<class T1, class T2>
void copy_interleave(T1 inIter, T1 inEnd, T2 outIter, std::size_t interleave, std::size_t startskip)
{
std::advance(inIter, startskip);
while(std::distance(inIter, inEnd) > 0)
{
*outIter = *inIter;
++outIter;
std::advance(inIter, interleave);
}
}
#endif
......@@ -53,9 +53,9 @@ void CommandLineWidget::CommandEntered()
m_pEditCLI->clear();
if(!cmd.length()) return;
m_pEditHistory->insertHtml(cmd + "<br>");
m_pEditHistory->insertHtml("<font color=\"#0000ff\"><b>> </b>" + cmd + "</font><br>");
// Parse command
// parse command
std::istringstream istr(cmd.toStdString() + "\n");
m_parsectx.SetLexerInput(istr);
yy::CliParser parser(m_parsectx);
......@@ -63,10 +63,10 @@ void CommandLineWidget::CommandEntered()
// write error log
for(const auto& err : m_parsectx.GetErrors())
m_pEditHistory->insertHtml(((err + "<br>").c_str()));
m_pEditHistory->insertHtml((("<b><font color=\"#ff0000\">" + err + "</font></b><br>").c_str()));
m_parsectx.ClearErrors();
if(parse_state != 0)
m_pEditHistory->insertHtml("Error: Could not parse command.<br>");
m_pEditHistory->insertHtml("<b><font color=\"#ff0000\">Error: Could not parse command.</font></b><br>");
// scroll command list to last command
auto caret = m_pEditHistory->textCursor();
......
/**
* internal data representation
* @author Tobias Weber <tweber@ill.fr>
* @date 1-June-2018
* @license see 'LICENSE' file
*/
#include "data.h"
/**
* internal data representation
* @author Tobias Weber <tweber@ill.fr>
* @date 1-June-2018
* @license see 'LICENSE' file
*/
#ifndef __DATAREP_H__
#define __DATAREP_H__
#include <vector>
#include <string>
using t_real_dat = double;
/**
* data set (e.g. of one polarisation channel)
*/
class Data
{
private:
// counts
// can have multiple detectors and monitors
std::vector<std::vector<t_real_dat>> m_counts;
std::vector<std::vector<t_real_dat>> m_counts_err;
// monitors
std::vector<std::vector<t_real_dat>> m_monitors;
std::vector<std::vector<t_real_dat>> m_monitors_err;
// x axes
std::vector<std::vector<t_real_dat>> m_x;
std::vector<std::string> m_x_names;
public:
std::size_t GetNumDets() const { return m_counts.size(); }
std::size_t GetNumMons() const { return m_monitors.size(); }
std::size_t GetNumAxes() const { return m_x.size(); }
// counters
const std::vector<t_real_dat>& GetCounter(std::size_t i) const { return m_counts[i]; }
const std::vector<t_real_dat>& GetCounterErrors(std::size_t i) const { return m_counts_err[i]; }
void AddCounter(const std::vector<t_real_dat> &dat, const std::vector<t_real_dat> &err)
{
m_counts.push_back(dat);
m_counts_err.push_back(err);
}
void AddCounter(std::vector<t_real_dat> &&dat, std::vector<t_real_dat> &&err)
{
m_counts.push_back(std::move(dat));
m_counts_err.push_back(std::move(err));
}
// monitors
const std::vector<t_real_dat>& GetMonitor(std::size_t i) const { return m_monitors[i]; }
const std::vector<t_real_dat>& GetMonitorErrors(std::size_t i) const { return m_monitors_err[i]; }
void AddMonitor(const std::vector<t_real_dat> &dat, const std::vector<t_real_dat> &err)
{
m_monitors.push_back(dat);
m_monitors_err.push_back(err);
}
void AddMonitor(std::vector<t_real_dat> &&dat, std::vector<t_real_dat> &&err)
{
m_monitors.push_back(std::move(dat));
m_monitors_err.push_back(std::move(err));
}
// x axes
const std::vector<t_real_dat>& GetAxis(std::size_t i) const { return m_x[i]; }
const std::string& GetAxisName(std::size_t i) const { return m_x_names[i]; }
void AddAxis(const std::vector<t_real_dat> &dat, const std::string &name="")
{
m_x.push_back(dat);
if(name != "")
m_x_names.push_back(name);
else
m_x_names.push_back("ax" + std::to_string(GetNumAxes()));
}
void AddAxis(std::vector<t_real_dat> &&dat, const std::string &name="")
{
m_x.emplace_back(std::move(dat));
if(name != "")
m_x_names.push_back(name);
else
m_x_names.push_back("ax" + std::to_string(GetNumAxes()));
}
};
/**
* collection of individual data (i.e. polarisation channels)
*/
class Dataset
{
private:
std::vector<Data> m_data;
public:
std::size_t GetNumChannels() const { return m_data.size(); }
const Data& GetChannel(std::size_t channel) const { return m_data[channel]; }
void AddChannel(const Data &data) { m_data.push_back(data); }
void AddChannel(Data &&data) { m_data.emplace_back(std::move(data)); }
};
#endif
......@@ -12,8 +12,8 @@
#include <QtWidgets/QPushButton>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QFileDialog>
#include <algorithm>
#include "libs/algos.h"
#include "tlibs/file/loadinstr.h"
......@@ -147,24 +147,6 @@ void FileBrowserWidget::SetFolder(const QString& dir)
}
/**
* copy algorithm with interleave
*/
template<class T1, class T2>
void copy_interleave(T1 inIter, T1 inEnd, T2 outIter, std::size_t interleave, std::size_t startskip)
{
std::advance(inIter, startskip);
while(std::distance(inIter, inEnd) > 0)
{
*outIter = *inIter;
++outIter;
std::advance(inIter, interleave);
}
}
/**
* a file in the list was selected
*/
......@@ -293,20 +275,30 @@ void FileBrowserWidget::FileDoubleClicked(QListWidgetItem *pItem)
TransferToWorkspace(lst);
}
void FileBrowserWidget::TransferSelectedToWorkspace()
{
TransferToWorkspace(m_pListFiles->selectedItems());
}
/**
* load selected file(s) into workspace
* emit the file transfer
*/
void FileBrowserWidget::TransferToWorkspace(const QList<QListWidgetItem*>& lst)
void FileBrowserWidget::TransferToWorkspace(const QList<QListWidgetItem*> &lst)
{
std::vector<std::string> files;
// extract file names
for(const auto* item : lst)
{
if(!item) continue;
std::string file = item->data(Qt::UserRole).toString().toStdString();
files.emplace_back(std::move(file));
}
emit TransferFiles(files);
}
// ----------------------------------------------------------------------------
......
......@@ -15,6 +15,8 @@
#include <QtWidgets/QListWidget>
#include <memory>
#include <vector>
#include <string>
#include "qcp/qcustomplot.h"
......@@ -23,7 +25,7 @@
* file browser widget
*/
class FileBrowserWidget : public QWidget
{
{ Q_OBJECT
private:
QSettings *m_pSettings = nullptr;
......@@ -45,6 +47,9 @@ protected:
void FileDoubleClicked(QListWidgetItem *pItem);
void TransferSelectedToWorkspace();
void TransferToWorkspace(const QList<QListWidgetItem*>&);
signals:
void TransferFiles(const std::vector<std::string>&);
};
......@@ -60,6 +65,8 @@ private:
public:
FileBrowser(QWidget* pParent = nullptr, QSettings *pSettings = nullptr);
virtual ~FileBrowser();
const FileBrowserWidget *GetWidget() const { return m_pBrowser.get(); }
};
#endif
......@@ -51,6 +51,13 @@ MainWnd::MainWnd(QSettings* pSettings)
this->addDockWidget(Qt::BottomDockWidgetArea, m_pCLI);
// ------------------------------------------------------------------------
// connections
connect(m_pBrowser->GetWidget(), &FileBrowserWidget::TransferFiles,
m_pWS->GetWidget(), &WorkSpaceWidget::ReceiveFiles);
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// restore settings
if(m_pSettings)
......
......@@ -68,6 +68,62 @@ void WorkSpaceWidget::ItemSelected(QListWidgetItem* pCur)
void WorkSpaceWidget::ItemDoubleClicked(QListWidgetItem* pCur)
{
}
/**
* transfer a file from the file browser and convert it into the internal format
*/
void WorkSpaceWidget::ReceiveFiles(const std::vector<std::string> &files)
{
for(const auto& file : files)
{
// load instrument data file
std::unique_ptr<tl::FileInstrBase<t_real>> pInstr(tl::FileInstrBase<t_real>::LoadInstr(file.c_str()));
const auto &colnames = pInstr->GetColNames();
if(pInstr && colnames.size()) // only valid files with a non-zero column count
{
// process polarisation data
pInstr->SetPolNames("p1", "p2", "i11", "i10");
pInstr->ParsePolData();
// get scan axis indices
std::vector<std::size_t> scan_idx;
for(const auto& scanvar : pInstr->GetScannedVars())
{
std::size_t idx = 0;
pInstr->GetCol(scanvar, &idx);
if(idx < colnames.size())
scan_idx.push_back(idx);
}
// try first axis if none found
if(scan_idx.size() == 0) scan_idx.push_back(0);
// get counter column index
std::vector<std::size_t> ctr_idx;
{
std::size_t idx = 0;
pInstr->GetCol(pInstr->GetCountVar(), &idx);
if(idx < colnames.size())
ctr_idx.push_back(idx);
}
// try second axis if none found
if(ctr_idx.size() == 0) ctr_idx.push_back(1);
// get monitor column index
std::vector<std::size_t> mon_idx;
{
std::size_t idx = 0;
pInstr->GetCol(pInstr->GetMonVar(), &idx);
if(idx < colnames.size())
mon_idx.push_back(idx);
}
}
}
}
// ----------------------------------------------------------------------------
......
......@@ -13,10 +13,11 @@
#include <QtWidgets/QDockWidget>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QListWidget>
#include "qcp/qcustomplot.h"
#include <memory>
#include "qcp/qcustomplot.h"
#include "data.h"
/**
......@@ -37,6 +38,9 @@ public:
protected:
void ItemSelected(QListWidgetItem* pCur);
void ItemDoubleClicked(QListWidgetItem* pCur);
public:
void ReceiveFiles(const std::vector<std::string>&);
};
......@@ -52,6 +56,8 @@ private:
public:
WorkSpace(QWidget* pParent = nullptr, QSettings *pSettings = nullptr);
virtual ~WorkSpace();
const WorkSpaceWidget *GetWidget() const { return m_pWS.get(); }
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment