diff --git a/source/daqlite/Configuration.cpp b/source/daqlite/Configuration.cpp index d86bce0e..697bb80d 100644 --- a/source/daqlite/Configuration.cpp +++ b/source/daqlite/Configuration.cpp @@ -14,6 +14,7 @@ void Configuration::print() { fmt::print(" Topic {}\n", Kafka.Topic); fmt::print("[Geometry]\n"); fmt::print(" Dimensions ({}, {}, {})\n", Geometry.XDim, Geometry.YDim, Geometry.ZDim); + fmt::print(" Pixel Offset {}\n", Geometry.Offset); fmt::print("[Plot]\n"); fmt::print(" WindowTitle {}\n", Plot.WindowTitle); fmt::print(" Plot type {}\n", Plot.PlotType); @@ -50,6 +51,14 @@ void Configuration::fromJsonFile(std::string fname) throw std::runtime_error("Config error: invalid 'geometry' field"); } + /// 'geometry' offset field is optional + try { + Geometry.Offset = j["geometry"]["offset"]; + } catch (nlohmann::json::exception& e) { + fmt::print("Noncritical error in Geometry configuration - using default value for offset\n"); + fmt::print("{}\n", e.what()); + } + /// 'kafka' field is mandatory. 'broker' and 'topic' must be specified try { Kafka.Broker = j["kafka"]["broker"]; diff --git a/source/daqlite/Configuration.h b/source/daqlite/Configuration.h index 97cd2d04..2c060c41 100644 --- a/source/daqlite/Configuration.h +++ b/source/daqlite/Configuration.h @@ -35,9 +35,10 @@ class Configuration { } TOF; struct { - int XDim{256}; - int YDim{256}; + int XDim{1}; + int YDim{1}; int ZDim{1}; + int Offset{0}; } Geometry; struct { diff --git a/source/daqlite/Custom2DPlot.cpp b/source/daqlite/Custom2DPlot.cpp index d2f8a4cf..9ac20551 100644 --- a/source/daqlite/Custom2DPlot.cpp +++ b/source/daqlite/Custom2DPlot.cpp @@ -23,8 +23,7 @@ Custom2DPlot::Custom2DPlot(Configuration &Config, int Projection) : auto & geom = mConfig.Geometry; LogicalGeometry = new ESSGeometry(geom.XDim, geom.YDim, geom.ZDim, 1); - HistogramData.resize( - LogicalGeometry->nx() * LogicalGeometry->ny() * LogicalGeometry->nz() + 1); + HistogramData.resize(LogicalGeometry->max_pixel() + 1); // this will also allow rescaling the color scale by dragging/zooming setInteractions(QCP::iRangeDrag | QCP::iRangeZoom); diff --git a/source/daqlite/ESSConsumer.cpp b/source/daqlite/ESSConsumer.cpp index becd94a7..e8a6b291 100644 --- a/source/daqlite/ESSConsumer.cpp +++ b/source/daqlite/ESSConsumer.cpp @@ -15,9 +15,12 @@ ESSConsumer::ESSConsumer(Configuration &Config) : mConfig(Config) { const int OVERHEAD{1}; auto & geom = mConfig.Geometry; - mMaxPixel = geom.XDim * geom.YDim * geom.ZDim; + uint32_t NumPixels = geom.XDim * geom.YDim * geom.ZDim; + mMinPixel = geom.Offset; + mMaxPixel = NumPixels + geom.Offset; assert(mMaxPixel != 0); - mHistogram.resize(mMaxPixel + OVERHEAD); + assert(mMinPixel < mMaxPixel); + mHistogram.resize(NumPixels + OVERHEAD); mHistogramTof.resize(mConfig.TOF.BinSize + OVERHEAD); mConsumer = subscribeTopic(); @@ -66,6 +69,7 @@ uint32_t ESSConsumer::processEV42Data(RdKafka::Message *Msg) { auto EvMsg = GetEventMessage(Msg->payload()); auto PixelIds = EvMsg->detector_id(); auto TOFs = EvMsg->time_of_flight(); + if (PixelIds->size() != TOFs->size()) { return 0; } @@ -73,15 +77,20 @@ uint32_t ESSConsumer::processEV42Data(RdKafka::Message *Msg) { for (int i = 0; i < PixelIds->size(); i++) { uint32_t Pixel = (*PixelIds)[i]; uint32_t Tof = (*TOFs)[i]/mConfig.TOF.Scale; // ns to us - if (Pixel > mMaxPixel) { - printf("Error: invalid pixel id: %d > %d\n", Pixel, mMaxPixel); - exit(0); + + if ((Pixel > mMaxPixel) or (Pixel < mMinPixel)) { + // printf("Error: invalid pixel id: %d, min: %d, max: %d\n", + // Pixel, mMinPixel, mMaxPixel); + // exit(0); + PixelDiscard++; + } else { + Pixel -= mMinPixel; + mHistogram[Pixel]++; + Tof = std::min(Tof, mConfig.TOF.MaxValue); + mHistogramTof[Tof * mConfig.TOF.BinSize / mConfig.TOF.MaxValue]++; } - mHistogram[Pixel]++; - Tof = std::min(Tof, mConfig.TOF.MaxValue); - mHistogramTof[Tof * mConfig.TOF.BinSize / mConfig.TOF.MaxValue]++; } - mCounts += PixelIds->size(); + PixelCount += PixelIds->size(); return PixelIds->size(); } diff --git a/source/daqlite/ESSConsumer.h b/source/daqlite/ESSConsumer.h index 54c3b06b..8d969854 100644 --- a/source/daqlite/ESSConsumer.h +++ b/source/daqlite/ESSConsumer.h @@ -41,8 +41,8 @@ class ESSConsumer { std::vector mHistogram; std::vector mHistogramTofPlot; std::vector mHistogramTof; - uint64_t mCounts{0}; - + uint64_t PixelCount{0}; + uint64_t PixelDiscard{0}; private: RdKafka::Conf *mConf; @@ -65,5 +65,6 @@ class ESSConsumer { } mKafkaStats; - uint32_t mMaxPixel{0}; /// \brief Number of pixels + uint32_t mMinPixel{0}; ///< Offset + uint32_t mMaxPixel{0}; ///< Number of pixels + offset }; diff --git a/source/daqlite/MainWindow.cpp b/source/daqlite/MainWindow.cpp index 19ae4a8e..80aef9b8 100644 --- a/source/daqlite/MainWindow.cpp +++ b/source/daqlite/MainWindow.cpp @@ -65,6 +65,8 @@ void MainWindow::startKafkaConsumerThread() { // SLOT void MainWindow::handleKafkaData(int EventRate) { ui->lblEventRateText->setText(QString::number(EventRate)); + ui->lblDiscardedPixelsText->setText(QString::number(KafkaConsumerThread->consumer()->PixelDiscard)); + KafkaConsumerThread->mutex.lock(); if (!TOF) { Plot2DXY->addData(KafkaConsumerThread->consumer()->mHistogramPlot); diff --git a/source/daqlite/MainWindow.ui b/source/daqlite/MainWindow.ui index 319fe3c1..4e2fa798 100644 --- a/source/daqlite/MainWindow.ui +++ b/source/daqlite/MainWindow.ui @@ -102,6 +102,32 @@ + + + + + 0 + 0 + + + + Discarded: + + + + + + + + 0 + 0 + + + + + + + diff --git a/source/daqlite/WorkerThread.cpp b/source/daqlite/WorkerThread.cpp index 034edf68..77fb11a2 100644 --- a/source/daqlite/WorkerThread.cpp +++ b/source/daqlite/WorkerThread.cpp @@ -26,10 +26,10 @@ void WorkerThread::run() { Consumer->mHistogramTofPlot = Consumer->mHistogramTof; mutex.unlock(); - uint64_t Rate = (uint64_t)((Consumer->mCounts * 1000000000ULL)/elapsed.count()); + uint64_t Rate = (uint64_t)((Consumer->PixelCount * 1000000000ULL)/elapsed.count()); emit resultReady(Rate); - Consumer->mCounts = 0; + Consumer->PixelCount = 0; std::fill(Consumer->mHistogram.begin(), Consumer->mHistogram.end(), 0); std::fill(Consumer->mHistogramTof.begin(), Consumer->mHistogramTof.end(), 0); t1 = std::chrono::high_resolution_clock::now(); diff --git a/source/daqlite/configs/amor.json b/source/daqlite/configs/amor.json index bcfdfb45..7ac6aaae 100644 --- a/source/daqlite/configs/amor.json +++ b/source/daqlite/configs/amor.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 32, "ydim" : 160, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/dreamoffice.json b/source/daqlite/configs/dreamoffice.json index 5d3eb3a0..57776272 100644 --- a/source/daqlite/configs/dreamoffice.json +++ b/source/daqlite/configs/dreamoffice.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 1288, "ydim" : 256, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/lokioffice.json b/source/daqlite/configs/lokioffice.json index a2af30bb..2f389f97 100644 --- a/source/daqlite/configs/lokioffice.json +++ b/source/daqlite/configs/lokioffice.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 512, "ydim" : 56, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/vipcspec2d.json b/source/daqlite/configs/vipcspec2d.json index ca16ed0a..9bfc53cd 100644 --- a/source/daqlite/configs/vipcspec2d.json +++ b/source/daqlite/configs/vipcspec2d.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 36, "ydim" : 800, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/vipcspec3d.json b/source/daqlite/configs/vipcspec3d.json index 8ea93b0d..10dd32ff 100644 --- a/source/daqlite/configs/vipcspec3d.json +++ b/source/daqlite/configs/vipcspec3d.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 36, "ydim" : 40, - "zdim" : 20 + "zdim" : 20, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/vipdream.json b/source/daqlite/configs/vipdream.json index 74ffdf5a..7f61fc9b 100644 --- a/source/daqlite/configs/vipdream.json +++ b/source/daqlite/configs/vipdream.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 1288, "ydim" : 256, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/vipfreia.json b/source/daqlite/configs/vipfreia.json index aa06564c..9b60b1a6 100644 --- a/source/daqlite/configs/vipfreia.json +++ b/source/daqlite/configs/vipfreia.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 32, "ydim" : 192, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/vipfreiatof.json b/source/daqlite/configs/vipfreiatof.json index 2a40268e..a4a8ab18 100644 --- a/source/daqlite/configs/vipfreiatof.json +++ b/source/daqlite/configs/vipfreiatof.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 32, "ydim" : 192, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "tof" : { diff --git a/source/daqlite/configs/viploki.json b/source/daqlite/configs/viploki.json index 7f07fb0a..0ef7dec9 100644 --- a/source/daqlite/configs/viploki.json +++ b/source/daqlite/configs/viploki.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 512, "ydim" : 1344, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/viploki4amp.json b/source/daqlite/configs/viploki4amp.json index 43f6cdc2..01897ef1 100644 --- a/source/daqlite/configs/viploki4amp.json +++ b/source/daqlite/configs/viploki4amp.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 512, "ydim" : 1344, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "tof" : { diff --git a/source/daqlite/configs/viplokitof.json b/source/daqlite/configs/viplokitof.json index ff8dcab7..ff14ed77 100644 --- a/source/daqlite/configs/viplokitof.json +++ b/source/daqlite/configs/viplokitof.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 512, "ydim" : 1344, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": { diff --git a/source/daqlite/configs/vipnmx.json b/source/daqlite/configs/vipnmx.json index 1348ceeb..37e7c78a 100644 --- a/source/daqlite/configs/vipnmx.json +++ b/source/daqlite/configs/vipnmx.json @@ -13,7 +13,8 @@ "geometry" : { "xdim" : 256, "ydim" : 256, - "zdim" : 1 + "zdim" : 1, + "offset" : 0 }, "plot": {