From 3dd073d5f1a468ef63cf5505614a0f9ef5400022 Mon Sep 17 00:00:00 2001 From: Morten Jagd Christensen Date: Fri, 11 Jun 2021 13:59:23 +0200 Subject: [PATCH 1/2] add mutex --- source/daqlite/ESSConsumer.h | 1 - source/daqlite/MainWindow.cpp | 2 ++ source/daqlite/WorkerThread.cpp | 3 ++- source/daqlite/WorkerThread.h | 5 +++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/source/daqlite/ESSConsumer.h b/source/daqlite/ESSConsumer.h index c80a426e..54c3b06b 100644 --- a/source/daqlite/ESSConsumer.h +++ b/source/daqlite/ESSConsumer.h @@ -41,7 +41,6 @@ class ESSConsumer { std::vector mHistogram; std::vector mHistogramTofPlot; std::vector mHistogramTof; - uint64_t mCountsPlot{0}; uint64_t mCounts{0}; diff --git a/source/daqlite/MainWindow.cpp b/source/daqlite/MainWindow.cpp index a83cd930..2746883c 100644 --- a/source/daqlite/MainWindow.cpp +++ b/source/daqlite/MainWindow.cpp @@ -66,6 +66,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) { @@ -75,6 +76,7 @@ void MainWindow::handleKafkaData(int EventRate) { } else { PlotTOF->addData(KafkaConsumerThread->consumer()->mHistogramTofPlot); } + KafkaConsumerThread->mutex.unlock(); } // SLOT diff --git a/source/daqlite/WorkerThread.cpp b/source/daqlite/WorkerThread.cpp index ad6e85a8..034edf68 100644 --- a/source/daqlite/WorkerThread.cpp +++ b/source/daqlite/WorkerThread.cpp @@ -21,9 +21,10 @@ void WorkerThread::run() { t2 = std::chrono::high_resolution_clock::now(); std::chrono::duration 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); diff --git a/source/daqlite/WorkerThread.h b/source/daqlite/WorkerThread.h index 7ec3f605..2adaef07 100644 --- a/source/daqlite/WorkerThread.h +++ b/source/daqlite/WorkerThread.h @@ -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); @@ -41,4 +44,6 @@ class WorkerThread : public QThread { /// \brief Kafka consumer ESSConsumer *Consumer; + + }; From 895168747ea67035b9744716e9b97e8c65ffab23 Mon Sep 17 00:00:00 2001 From: Morten Jagd Christensen Date: Fri, 25 Jun 2021 12:10:19 +0200 Subject: [PATCH 2/2] added window and plot titles, array overwrite (hopefully) fixed bu adding overhead --- source/daqlite/Configuration.cpp | 6 +- source/daqlite/Configuration.h | 3 +- source/daqlite/ESSConsumer.cpp | 5 +- source/daqlite/MainWindow.cpp | 3 +- source/daqlite/configs/amor.json | 4 +- source/daqlite/configs/dreamoffice.json | 4 +- source/daqlite/configs/lokioffice.json | 4 +- source/daqlite/configs/vipcspec2d.json | 4 +- source/daqlite/configs/vipcspec3d.json | 4 +- source/daqlite/configs/vipdream.json | 4 +- source/daqlite/configs/vipfreia.json | 4 +- source/daqlite/configs/vipfreiatof.json | 3 +- source/daqlite/configs/viploki.json | 3 +- source/daqlite/configs/viploki4amp.json | 3 +- source/daqlite/configs/viplokitof.json | 3 +- source/daqlite/configs/vipnmx.json | 4 +- source/daqlite/daqlite.cpp | 85 +++++++++++++------------ 17 files changed, 85 insertions(+), 61 deletions(-) diff --git a/source/daqlite/Configuration.cpp b/source/daqlite/Configuration.cpp index d357332c..d86bce0e 100644 --- a/source/daqlite/Configuration.cpp +++ b/source/daqlite/Configuration.cpp @@ -15,6 +15,7 @@ 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); @@ -22,7 +23,7 @@ void Configuration::print() { 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); @@ -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"]; diff --git a/source/daqlite/Configuration.h b/source/daqlite/Configuration.h index 08b5cbd4..3aab9e44 100644 --- a/source/daqlite/Configuration.h +++ b/source/daqlite/Configuration.h @@ -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 diff --git a/source/daqlite/ESSConsumer.cpp b/source/daqlite/ESSConsumer.cpp index bdb82386..becd94a7 100644 --- a/source/daqlite/ESSConsumer.cpp +++ b/source/daqlite/ESSConsumer.cpp @@ -13,11 +13,12 @@ #include 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); diff --git a/source/daqlite/MainWindow.cpp b/source/daqlite/MainWindow.cpp index 2746883c..19ae4a8e 100644 --- a/source/daqlite/MainWindow.cpp +++ b/source/daqlite/MainWindow.cpp @@ -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; @@ -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())); diff --git a/source/daqlite/configs/amor.json b/source/daqlite/configs/amor.json index 3c17fb42..9bce3e95 100644 --- a/source/daqlite/configs/amor.json +++ b/source/daqlite/configs/amor.json @@ -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, diff --git a/source/daqlite/configs/dreamoffice.json b/source/daqlite/configs/dreamoffice.json index 905fa98c..499064f9 100644 --- a/source/daqlite/configs/dreamoffice.json +++ b/source/daqlite/configs/dreamoffice.json @@ -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, diff --git a/source/daqlite/configs/lokioffice.json b/source/daqlite/configs/lokioffice.json index 8529f9ef..ee4652d3 100644 --- a/source/daqlite/configs/lokioffice.json +++ b/source/daqlite/configs/lokioffice.json @@ -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, diff --git a/source/daqlite/configs/vipcspec2d.json b/source/daqlite/configs/vipcspec2d.json index f6681ee2..bcf0ee46 100644 --- a/source/daqlite/configs/vipcspec2d.json +++ b/source/daqlite/configs/vipcspec2d.json @@ -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, diff --git a/source/daqlite/configs/vipcspec3d.json b/source/daqlite/configs/vipcspec3d.json index 632aa6e0..b690b205 100644 --- a/source/daqlite/configs/vipcspec3d.json +++ b/source/daqlite/configs/vipcspec3d.json @@ -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, diff --git a/source/daqlite/configs/vipdream.json b/source/daqlite/configs/vipdream.json index 4f3ec558..75bff2b8 100644 --- a/source/daqlite/configs/vipdream.json +++ b/source/daqlite/configs/vipdream.json @@ -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, diff --git a/source/daqlite/configs/vipfreia.json b/source/daqlite/configs/vipfreia.json index ceb3a04a..ded3de57 100644 --- a/source/daqlite/configs/vipfreia.json +++ b/source/daqlite/configs/vipfreia.json @@ -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, diff --git a/source/daqlite/configs/vipfreiatof.json b/source/daqlite/configs/vipfreiatof.json index c46362eb..f9b3ee30 100644 --- a/source/daqlite/configs/vipfreiatof.json +++ b/source/daqlite/configs/vipfreiatof.json @@ -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, diff --git a/source/daqlite/configs/viploki.json b/source/daqlite/configs/viploki.json index a6fb4e63..cd5a0adc 100644 --- a/source/daqlite/configs/viploki.json +++ b/source/daqlite/configs/viploki.json @@ -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, diff --git a/source/daqlite/configs/viploki4amp.json b/source/daqlite/configs/viploki4amp.json index dfc3f9bb..e99ce45d 100644 --- a/source/daqlite/configs/viploki4amp.json +++ b/source/daqlite/configs/viploki4amp.json @@ -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, diff --git a/source/daqlite/configs/viplokitof.json b/source/daqlite/configs/viplokitof.json index 44f72548..c5bf5601 100644 --- a/source/daqlite/configs/viplokitof.json +++ b/source/daqlite/configs/viplokitof.json @@ -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, diff --git a/source/daqlite/configs/vipnmx.json b/source/daqlite/configs/vipnmx.json index 49abb0d6..6e87e1db 100644 --- a/source/daqlite/configs/vipnmx.json +++ b/source/daqlite/configs/vipnmx.json @@ -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, diff --git a/source/daqlite/daqlite.cpp b/source/daqlite/daqlite.cpp index 8646a007..54fe2af6 100644 --- a/source/daqlite/daqlite.cpp +++ b/source/daqlite/daqlite.cpp @@ -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 -#include -#include -#include - -#include -#include -#include -#include - -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 +#include +#include +#include + +#include +#include +#include +#include + +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(); +}