Skip to content

Commit

Permalink
Merge pull request #251 from ess-dmsc/issue_249_mutex
Browse files Browse the repository at this point in the history
Issue 249 mutex
  • Loading branch information
amues authored Jun 28, 2021
2 parents b8f5813 + 8951687 commit 5e69f14
Show file tree
Hide file tree
Showing 20 changed files with 94 additions and 63 deletions.
6 changes: 4 additions & 2 deletions source/daqlite/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ void Configuration::print() {
fmt::print("[Geometry]\n");
fmt::print(" Dimensions ({}, {}, {})\n", Geometry.XDim, Geometry.YDim, Geometry.ZDim);
fmt::print("[Plot]\n");
fmt::print(" WindowTitle {}\n", Plot.WindowTitle);
fmt::print(" Plot type {}\n", Plot.PlotType);
fmt::print(" Clear periodically {}\n", Plot.ClearPeriodic);
fmt::print(" Clear interval (s) {}\n", Plot.ClearEverySeconds);
fmt::print(" Interpolate image {}\n", Plot.Interpolate);
fmt::print(" Color gradient {}\n", Plot.ColorGradient);
fmt::print(" Invert gradient {}\n", Plot.InvertGradient);
fmt::print(" Log Scale {}\n", Plot.LogScale);
fmt::print(" Title {}\n", Plot.Title);
fmt::print(" PlotTitle {}\n", Plot.PlotTitle);
fmt::print(" X Axis {}\n", Plot.XAxis);
fmt::print("[TOF]\n");
fmt::print(" Scale {}\n", TOF.Scale);
Expand Down Expand Up @@ -80,7 +81,8 @@ try {
Plot.ColorGradient = j["plot"]["color_gradient"];
Plot.InvertGradient = j["plot"]["invert_gradient"];
Plot.LogScale = j["plot"]["log_scale"];
Plot.Title = j["plot"]["title"];
Plot.WindowTitle = j["plot"]["window_title"];
Plot.PlotTitle = j["plot"]["plot_title"];
Plot.XAxis = j["plot"]["xaxis"];
Plot.Width = j["plot"]["window_width"];
Plot.Height = j["plot"]["window_height"];
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ class Configuration {
std::string ColorGradient{"hot"};
bool InvertGradient{false};
bool LogScale{false};
std::string Title;
std::string WindowTitle{"Daquiri Lite - Daqlite"};
std::string PlotTitle{""};
std::string XAxis{""};
int Width{600}; // default window width
int Height{400}; // default window height
Expand Down
5 changes: 3 additions & 2 deletions source/daqlite/ESSConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
#include <unistd.h>

ESSConsumer::ESSConsumer(Configuration &Config) : mConfig(Config) {
const int OVERHEAD{1};
auto & geom = mConfig.Geometry;
mMaxPixel = geom.XDim * geom.YDim * geom.ZDim;
assert(mMaxPixel != 0);
mHistogram.resize(mMaxPixel);
mHistogramTof.resize(mConfig.TOF.BinSize);
mHistogram.resize(mMaxPixel + OVERHEAD);
mHistogramTof.resize(mConfig.TOF.BinSize + OVERHEAD);

mConsumer = subscribeTopic();
assert(mConsumer != nullptr);
Expand Down
1 change: 0 additions & 1 deletion source/daqlite/ESSConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ESSConsumer {
std::vector<uint32_t> mHistogram;
std::vector<uint32_t> mHistogramTofPlot;
std::vector<uint32_t> mHistogramTof;
uint64_t mCountsPlot{0};
uint64_t mCounts{0};


Expand Down
5 changes: 3 additions & 2 deletions source/daqlite/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ MainWindow::MainWindow(Configuration &Config, QWidget *parent)
, mConfig(Config) {

ui->setupUi(this);
setWindowTitle("Daquiri lite");

if (strcmp(Config.Plot.PlotType.c_str(), "tof") == 0) {
TOF = true;
Expand All @@ -37,7 +36,7 @@ MainWindow::MainWindow(Configuration &Config, QWidget *parent)
ui->gridLayout->addWidget(PlotTOF, 0, 0, 1, 1);
}

ui->lblDescriptionText->setText(mConfig.Plot.Title.c_str());
ui->lblDescriptionText->setText(mConfig.Plot.PlotTitle.c_str());
ui->lblEventRateText->setText("0");

connect(ui->pushButtonQuit, SIGNAL(clicked()), this, SLOT(handleExitButton()));
Expand Down Expand Up @@ -66,6 +65,7 @@ void MainWindow::startKafkaConsumerThread() {
// SLOT
void MainWindow::handleKafkaData(int EventRate) {
ui->lblEventRateText->setText(QString::number(EventRate));
KafkaConsumerThread->mutex.lock();
if (!TOF) {
Plot2DXY->addData(KafkaConsumerThread->consumer()->mHistogramPlot);
if (mConfig.Geometry.ZDim > 1) {
Expand All @@ -75,6 +75,7 @@ void MainWindow::handleKafkaData(int EventRate) {
} else {
PlotTOF->addData(KafkaConsumerThread->consumer()->mHistogramTofPlot);
}
KafkaConsumerThread->mutex.unlock();
}

// SLOT
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/WorkerThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ void WorkerThread::run() {
t2 = std::chrono::high_resolution_clock::now();
std::chrono::duration<int64_t,std::nano> elapsed = t2 - t1;
if (elapsed.count() >= 1000000000ULL) {
mutex.lock();
Consumer->mHistogramPlot = Consumer->mHistogram;
Consumer->mHistogramTofPlot = Consumer->mHistogramTof;
Consumer->mCountsPlot = Consumer->mCounts;
mutex.unlock();

uint64_t Rate = (uint64_t)((Consumer->mCounts * 1000000000ULL)/elapsed.count());
emit resultReady(Rate);
Expand Down
5 changes: 5 additions & 0 deletions source/daqlite/WorkerThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class WorkerThread : public QThread {
/// \brief Getter for the consumer
ESSConsumer * consumer() { return Consumer; }


QMutex mutex;

signals:
void resultReady(uint64_t &val);

Expand All @@ -41,4 +44,6 @@ class WorkerThread : public QThread {

/// \brief Kafka consumer
ESSConsumer *Consumer;


};
4 changes: 3 additions & 1 deletion source/daqlite/configs/amor.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},

"plot": {
"title" : "FREIA",
"plot_type" : "pixels",
"window_title" : "FREIA",
"plot_title" : "FREIA",
"clear_periodic" : false,
"clear_interval_seconds" : 5,
"interpolate_pixels" : false,
Expand Down
4 changes: 3 additions & 1 deletion source/daqlite/configs/dreamoffice.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},

"plot": {
"title" : "DREAM",
"plot_type" : "pixels",
"window_title" : "DREAM",
"plot_title" : "DREAM",
"clear_periodic" : false,
"clear_interval_seconds" : 30,
"interpolate_pixels" : false,
Expand Down
4 changes: 3 additions & 1 deletion source/daqlite/configs/lokioffice.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},

"plot": {
"title" : "LOKI",
"plot_type" : "pixels",
"window_title" : "LOKI",
"plot_title" : "LOKI",
"clear_periodic" : false,
"clear_interval_seconds" : 30,
"interpolate_pixels" : false,
Expand Down
4 changes: 3 additions & 1 deletion source/daqlite/configs/vipcspec2d.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},

"plot": {
"title" : "CSPEC 2D - 172.30.242.20 (36 x 800)",
"plot_type" : "pixels",
"window_title" : "CSPEC 2D - 172.30.242.20",
"plot_title" : "(36 x 800)",
"clear_periodic" : false,
"clear_interval_seconds" : 5,
"interpolate_pixels" : false,
Expand Down
4 changes: 3 additions & 1 deletion source/daqlite/configs/vipcspec3d.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},

"plot": {
"title" : "CSPEC 3D - 172.30.242.20 (36 x 40 x 20)",
"plot_type" : "pixels",
"window_title" : "CSPEC",
"plot_title" : "3D (36 x 40 x 20)",
"clear_periodic" : false,
"clear_interval_seconds" : 5,
"interpolate_pixels" : false,
Expand Down
4 changes: 3 additions & 1 deletion source/daqlite/configs/vipdream.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},

"plot": {
"title" : "DREAM",
"plot_type" : "pixels",
"window_title" : "DREAM",
"plot_title" : "DREAM",
"clear_periodic" : false,
"clear_interval_seconds" : 30,
"interpolate_pixels" : false,
Expand Down
4 changes: 3 additions & 1 deletion source/daqlite/configs/vipfreia.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},

"plot": {
"title" : "FREIA",
"plot_type" : "pixels",
"window_title" : "FREIA",
"plot_title" : "FREIA",
"clear_periodic" : false,
"clear_interval_seconds" : 5,
"interpolate_pixels" : false,
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/vipfreiatof.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

"plot": {
"plot_type" : "tof",
"title" : "FREIA - TOF",
"window_title" : "FREIA",
"plot_title" : "TOF",
"clear_periodic" : false,
"clear_interval_seconds" : 30,
"interpolate_pixels" : false,
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/viploki.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

"plot": {
"plot_type" : "pixels",
"title" : "LOKI",
"window_title" : "LOKI",
"plot_title" : "pixels",
"clear_periodic" : false,
"clear_interval_seconds" : 30,
"interpolate_pixels" : false,
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/viploki4amp.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

"plot": {
"plot_type" : "tof",
"title" : "LOKI - sum of 4 amps",
"window_title" : "LOKI",
"plot_title" : "sum of 4 amps",
"clear_periodic" : false,
"clear_interval_seconds" : 30,
"interpolate_pixels" : false,
Expand Down
3 changes: 2 additions & 1 deletion source/daqlite/configs/viplokitof.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

"plot": {
"plot_type" : "tof",
"title" : "LOKI - TOF",
"window_title" : "LOKI",
"plot_title" : "TOF",
"clear_periodic" : false,
"clear_interval_seconds" : 30,
"interpolate_pixels" : false,
Expand Down
4 changes: 3 additions & 1 deletion source/daqlite/configs/vipnmx.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
},

"plot": {
"title" : "NMX - 172.30.242.20 (256 x 256)",
"plot_type" : "pixels",
"window_title" : "NMX",
"plot_title" : "2D (256 x 256)",
"clear_periodic" : false,
"clear_interval_seconds" : 5,
"interpolate_pixels" : false,
Expand Down
85 changes: 43 additions & 42 deletions source/daqlite/daqlite.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
/* Copyright (C) 2020 European Spallation Source, ERIC. See LICENSE file */
//===----------------------------------------------------------------------===//
///
/// \file daqlite.cpp
///
/// \brief Daquiri Light main application
///
/// Handles command line option(s), instantiates GUI
//===----------------------------------------------------------------------===//

#include <Configuration.h>
#include <Custom2DPlot.h>
#include <MainWindow.h>
#include <WorkerThread.h>

#include <QApplication>
#include <QPlot/QPlot.h>
#include <fmt/format.h>
#include <QCommandLineParser>

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

QCommandLineParser CLI;
CLI.setApplicationDescription("Daquiri light - when you're driving home");
CLI.addHelpOption();

QCommandLineOption fileOption("f", "Configuration file", "file");
CLI.addOption(fileOption);
CLI.process(app);

Configuration Config;
if (CLI.isSet(fileOption)) {
std::string FileName = CLI.value(fileOption).toStdString();
Config.fromJsonFile(FileName);
}

MainWindow w(Config);
w.resize(Config.Plot.Width, Config.Plot.Height);

return app.exec();
}
/* Copyright (C) 2020 European Spallation Source, ERIC. See LICENSE file */
//===----------------------------------------------------------------------===//
///
/// \file daqlite.cpp
///
/// \brief Daquiri Light main application
///
/// Handles command line option(s), instantiates GUI
//===----------------------------------------------------------------------===//

#include <Configuration.h>
#include <Custom2DPlot.h>
#include <MainWindow.h>
#include <WorkerThread.h>

#include <QApplication>
#include <QPlot/QPlot.h>
#include <fmt/format.h>
#include <QCommandLineParser>

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

QCommandLineParser CLI;
CLI.setApplicationDescription("Daquiri light - when you're driving home");
CLI.addHelpOption();

QCommandLineOption fileOption("f", "Configuration file", "file");
CLI.addOption(fileOption);
CLI.process(app);

Configuration Config;
if (CLI.isSet(fileOption)) {
std::string FileName = CLI.value(fileOption).toStdString();
Config.fromJsonFile(FileName);
}

MainWindow w(Config);
w.setWindowTitle(QString::fromStdString(Config.Plot.WindowTitle));
w.resize(Config.Plot.Width, Config.Plot.Height);

return app.exec();
}

0 comments on commit 5e69f14

Please sign in to comment.