From 841f7c191ff4d4f1b2f62c1408abf8bdbd443ed4 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 27 Apr 2021 13:21:49 +0200 Subject: [PATCH 01/22] Alloc more for successive reads --- V1724.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/V1724.cc b/V1724.cc index 46860fa8..992a3ae8 100644 --- a/V1724.cc +++ b/V1724.cc @@ -225,11 +225,11 @@ int V1724::Read(std::unique_ptr& outptr){ do{ // Reserve space for this block transfer - thisBLT = new char32_t[alloc_words]; + thisBLT = new char32_t[alloc_words << count]; ret = CAENVME_FIFOBLTReadCycle(fBoardHandle, fBaseAddress, ((unsigned char*)thisBLT), - BLT_SIZE, cvA32_U_MBLT, cvD64, &nb); + BLT_SIZE << count, cvA32_U_MBLT, cvD64, &nb); if( (ret != cvSuccess) && (ret != cvBusError) ){ fLog->Entry(MongoLog::Error, "Board %i read error after %i reads: (%i) and transferred %i bytes this read", @@ -240,9 +240,9 @@ int V1724::Read(std::unique_ptr& outptr){ for (auto& b : xfer_buffers) delete[] b.first; return -1; } - if (nb > BLT_SIZE) fLog->Entry(MongoLog::Message, + if (nb > (BLT_SIZE<Entry(MongoLog::Message, "Board %i got %i more bytes than asked for (headroom %i)", - fBID, nb-BLT_SIZE, alloc_words*sizeof(char32_t)-nb); + fBID, nb-(BLT_SIZE< Date: Wed, 28 Apr 2021 10:34:31 +0200 Subject: [PATCH 02/22] Time for release builds --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 07f58b8f..6a43c00d 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ SHELL = /bin/bash -O extglob -c CC = g++ CXX = g++ BUILD_COMMIT = "$(shell git log -n 1 --pretty=oneline | awk '{print $$1}')" -CFLAGS = -Wall -Wextra -pedantic -pedantic-errors -g -DLINUX -DREDAX_BUILD_COMMIT='$(BUILD_COMMIT)' -std=c++17 -pthread $(shell pkg-config --cflags libmongocxx) +CFLAGS = -Wall -Wextra -pedantic -pedantic-errors -g -O2 -DLINUX -DREDAX_BUILD_COMMIT='$(BUILD_COMMIT)' -std=c++17 -pthread $(shell pkg-config --cflags libmongocxx) CPPFLAGS := $(CFLAGS) IS_READER0 := false ifeq "$(shell hostname)" "reader0" From ab12c35b1b229facc1e3fda9b8c7112fc6623dd9 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Wed, 28 Apr 2021 10:37:11 +0200 Subject: [PATCH 03/22] Typo --- MongoLog.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MongoLog.cc b/MongoLog.cc index a96c0040..4619fbf1 100644 --- a/MongoLog.cc +++ b/MongoLog.cc @@ -52,7 +52,7 @@ void MongoLog::Flusher() { fCV.wait(lk, [&]{return fQueue.size() > 0 || fFlush == false;}); if (fQueue.size()) { auto [today, ms, priority, message] = std::move(fQueue.front()); - fQueue.pop(); + fQueue.pop_front(); lk.unlock(); std::stringstream msg; msg< Date: Thu, 29 Apr 2021 11:45:45 +0200 Subject: [PATCH 04/22] Misc optimizations, tweaks --- DAQController.cc | 6 +++--- StraxFormatter.cc | 8 ++++---- V1495.hh | 13 ------------- V1724.cc | 5 ++--- V1724.hh | 3 +-- 5 files changed, 10 insertions(+), 25 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index d0c423b3..48b8d3de 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -209,6 +209,7 @@ void DAQController::ReadData(int link){ std::vector mutex_wait_times; int words = 0; int local_size(0); + int transfer_batch = fOptions->GetInt("transfer_batch", 16); fRunning[link] = true; std::chrono::microseconds sleep_time(fOptions->GetInt("us_between_reads", 10)); while(fReadLoop){ @@ -232,8 +233,7 @@ void DAQController::ReadData(int link){ fLog->Entry(MongoLog::Local, "Board %i has PLL unlock", digi->bid()); fPLL++; } - if (err_val & 0x2) fLog->Entry(MongoLog::Local, "Board %i has VME bus error", - digi->bid()); + if (err_val & 0x2) fLog->Entry(MongoLog::Local, "Board %i has VME bus error", digi->bid()); } } if((words = digi->Read(dp))<0){ @@ -246,7 +246,7 @@ void DAQController::ReadData(int link){ local_size += words*sizeof(char32_t); } } // for digi in digitizers - if (local_buffer.size() > 0) { + if (local_buffer.size() >= transfer_batch) { fDataRate += local_size; int selector = (fCounter++)%fNProcessingThreads; auto t_start = std::chrono::high_resolution_clock::now(); diff --git a/StraxFormatter.cc b/StraxFormatter.cc index a6835448..92dcf695 100644 --- a/StraxFormatter.cc +++ b/StraxFormatter.cc @@ -319,11 +319,11 @@ void StraxFormatter::WriteOutChunk(int chunk_i){ struct timespec comp_start, comp_end; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &comp_start); - std::vector*> buffers{{&fChunks[chunk_i], &fOverlaps[chunk_i]}}; - std::vector uncompressed_size(3, 0); + std::list* buffers[2] = {&fChunks[chunk_i], &fOverlaps[chunk_i]}; + long uncompressed_size[3] = {0L, 0L, 0L}; std::string uncompressed; - std::vector> out_buffer(3); - std::vector wsize(3); + std::shared_ptr out_buffer[3]; + int wsize[3]; long max_compressed_size = 0; for (int i = 0; i < 2; i++) { diff --git a/V1495.hh b/V1495.hh index d5ecb4f2..d114d4d3 100644 --- a/V1495.hh +++ b/V1495.hh @@ -4,19 +4,6 @@ #include #include -//Register address definitions taken from XENON1T m_veto class in kodiaq -//https://github.com/coderdj/kodiaq and XENON1T DAQ m_veto config files - -/* -#define V1495_ModuleReset 0x800A -#define V1495_MaskInA 0x1020 -#define V1495_MaskInB 0x1024 -#define V1495_MaskInD 0x1028 -#define V1495_MajorityThreshold 0x1014 -#define V1495_CoincidenceWidth 0x1010 -#define V1495_CTRL 0x1018 -*/ - class MongoLog; class Options; diff --git a/V1724.cc b/V1724.cc index 992a3ae8..d43e6b55 100644 --- a/V1724.cc +++ b/V1724.cc @@ -227,8 +227,7 @@ int V1724::Read(std::unique_ptr& outptr){ // Reserve space for this block transfer thisBLT = new char32_t[alloc_words << count]; - ret = CAENVME_FIFOBLTReadCycle(fBoardHandle, fBaseAddress, - ((unsigned char*)thisBLT), + ret = CAENVME_FIFOBLTReadCycle(fBoardHandle, fBaseAddress, thisBLT, BLT_SIZE << count, cvA32_U_MBLT, cvD64, &nb); if( (ret != cvSuccess) && (ret != cvBusError) ){ fLog->Entry(MongoLog::Error, @@ -265,7 +264,7 @@ int V1724::Read(std::unique_ptr& outptr){ for (auto& xfer : xfer_buffers) { s.append(xfer.first, xfer.second); } - fBLTCounter[count]++; + fBLTCounter[int(std::ceil(std::log2(blt_words)))]++; auto [ht, cc] = GetClockInfo(s); outptr = std::make_unique(std::move(s), ht, cc); } diff --git a/V1724.hh b/V1724.hh index 73619aa4..aea4295e 100644 --- a/V1724.hh +++ b/V1724.hh @@ -52,7 +52,6 @@ class V1724{ virtual bool EnsureStopped(int ntries, int sleep); virtual int CheckErrors(); virtual uint32_t GetAcquisitionStatus(); - virtual int ResetClocks(); protected: // Some values for base classes to override @@ -73,7 +72,7 @@ protected: unsigned int fBoardErrRegister; int BLT_SIZE; - std::map fBLTCounter; + std::map fBLTCounter; bool MonitorRegister(uint32_t reg, uint32_t mask, int ntries, int sleep, uint32_t val=1); virtual std::tuple GetClockInfo(std::u32string_view); From 20810abf15277425c613eeca81c43b0cda7c62c5 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Thu, 29 Apr 2021 12:05:03 +0200 Subject: [PATCH 05/22] Typos and docs --- DAQController.cc | 2 +- V1724.cc | 5 ----- docs/daq_options.md | 3 ++- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index 3ce6d790..73fb6cf4 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -209,7 +209,7 @@ void DAQController::ReadData(int link){ std::vector mutex_wait_times; mutex_wait_times.reserve(1<<20); int words = 0; - int transfer_batch = fOptions->GetInt("transfer_batch", 8); + unsigned transfer_batch = fOptions->GetInt("transfer_batch", 8); int bytes_this_loop(0); fRunning[link] = true; std::chrono::microseconds sleep_time(fOptions->GetInt("us_between_reads", 10)); diff --git a/V1724.cc b/V1724.cc index 5dd3ad5e..05b066dd 100644 --- a/V1724.cc +++ b/V1724.cc @@ -123,11 +123,6 @@ bool V1724::EnsureStopped(int ntries, int tsleep){ uint32_t V1724::GetAcquisitionStatus(){ return ReadRegister(fAqStatusRegister); } -int V1724::ResetClocks() { - fRolloverCounter = 0; - fLastClock = 0; - return WriteRegister(fClearRegister, 0x1); -} int V1724::CheckErrors(){ auto pll = ReadRegister(fBoardFailStatRegister); auto ros = ReadRegister(fReadoutStatusRegister); diff --git a/docs/daq_options.md b/docs/daq_options.md index 7a57e0a9..ca48fa44 100644 --- a/docs/daq_options.md +++ b/docs/daq_options.md @@ -289,7 +289,7 @@ Redax accepts a variety of options that control various low-level operations. Th | Option | Description | | ---- | ---- | -| baseline_max_steps | Int. The maximum number of steps during baselining. Steps involve measuring the baseline and trying to adjust it towards the target value. Default 20. | +| baseline_max_steps | Int. The maximum number of steps during baselining. Steps involve measuring the baseline and trying to adjust it towards the target value. Default 30. | | baseline_adjustment_threshold | Int. How close the measured baseline must be to the target baseline in ADC units. If the absolute difference is less than this value, a channel is considered to have converged. Default 10. | | baselie_convergence_threshold | Int. How many consecutive times a channel must be within the adjustment threshold to be considered stable and finished. Default 3. | | baseline_min_adjustment | Int. The minimum change to the DAC value, given in DAC units. Note that the DAC is 16-bit while the digitizer is only 14-bit, so a conversion of approximately 0.25 does apply. Default 10. | @@ -302,4 +302,5 @@ Redax accepts a variety of options that control various low-level operations. Th | blt_safety_factor | Float. Sometimes the digitizer returns more bytes during a BLT readout than you ask for (it depends on the number and size of events in the digitizer's memory). This value is how much extra memory to allocate so you don't overrun the readout buffer. Default 1.5. | | do_sn_check | 0/1. Whether or not to have each board check its serial number during initialization. Default 0. | | us_between_reads | Int. How many microseconds to sleep between polling digitizers for data. This has a major performance impact that will matter when under extremely high loads (ie, the bleeding edge of what your server(s) and boards are capable of), but otherwise shouldn't matter much. Default 10. | +| transfer_batch | Int. How many data packets to accumulate in one readout thread before passing off to a processing thread. Default 16. | From 73e522f70f768ab6f5f18a61db5c32e5a38103c0 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Fri, 7 May 2021 13:26:38 +0200 Subject: [PATCH 06/22] Reduced copying for logs, maybe buffer overflow in rate tracking? --- DAQController.cc | 13 ++++++++----- DAQController.hh | 3 +-- MongoLog.cc | 29 +++++++++++++++++------------ MongoLog.hh | 2 +- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index 73fb6cf4..443ded36 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -207,20 +207,22 @@ void DAQController::ReadData(int link){ std::list> local_buffer; std::unique_ptr dp; std::vector mutex_wait_times; + std::vector dps_per_loop; mutex_wait_times.reserve(1<<20); + dps_per_loop.reserve(1<<24); int words = 0; unsigned transfer_batch = fOptions->GetInt("transfer_batch", 8); int bytes_this_loop(0); fRunning[link] = true; std::chrono::microseconds sleep_time(fOptions->GetInt("us_between_reads", 10)); int c = 0; + int bytes_last_loop = 0; const int num_threads = fNProcessingThreads; while(fReadLoop){ for(auto& digi : fDigitizers[link]) { - // Every 1k reads check board status - if(readcycler%10000==0){ - readcycler=0; + // periodically report board status + if(readcycler == 0){ board_status = digi->GetAcquisitionStatus(); fLog->Entry(MongoLog::Local, "Board %i has status 0x%04x", digi->bid(), board_status); @@ -249,7 +251,8 @@ void DAQController::ReadData(int link){ bytes_this_loop += words*sizeof(char32_t); } } // for digi in digitizers - if (local_buffer.size() >= transfer_batch) { + dps_per_loop.push_back(local_buffer.size()); + if (local_buffer.size() >= transfer_batch || fReadLoop == false) { fDataRate += bytes_this_loop; auto t_start = std::chrono::high_resolution_clock::now(); while (fFormatters[(++c)%num_threads]->ReceiveDatapackets(local_buffer, bytes_this_loop)) {} @@ -258,7 +261,7 @@ void DAQController::ReadData(int link){ t_end-t_start).count()); bytes_this_loop = 0; } - readcycler++; + readcycler = ++readcycler>10000 ? 0 : readcycler; std::this_thread::sleep_for(sleep_time); } // while run if (mutex_wait_times.size() > 0) { diff --git a/DAQController.hh b/DAQController.hh index 8c9219fb..237c31bd 100644 --- a/DAQController.hh +++ b/DAQController.hh @@ -56,8 +56,7 @@ private: int fNProcessingThreads; // For reporting to frontend - std::atomic_int fDataRate; - std::atomic_long fCounter; + std::atomic_long fDataRate; std::atomic_int fPLL; }; diff --git a/MongoLog.cc b/MongoLog.cc index 4619fbf1..99ec2da3 100644 --- a/MongoLog.cc +++ b/MongoLog.cc @@ -54,8 +54,6 @@ void MongoLog::Flusher() { auto [today, ms, priority, message] = std::move(fQueue.front()); fQueue.pop_front(); lk.unlock(); - std::stringstream msg; - msg<tm_year+1900, + std::sprintf(writeto, "%04i-%02i-%02i %02i:%02i:%02i.%03i", date->tm_year+1900, date->tm_mon+1, date->tm_mday, date->tm_hour, date->tm_min, date->tm_sec, ms); return out; } @@ -151,24 +153,27 @@ int MongoLog::RotateLogFile() { int MongoLog::Entry(int priority, const std::string& message, ...){ auto [today, ms] = Now(); - // Thanks Martin - // http://www.martinbroadhurst.com/string-formatting-in-c.html + // if we had c++20 this would look much cleaner va_list args; va_start (args, message); // First pass just gets what the length will be size_t len = std::vsnprintf(NULL, 0, message.c_str(), args); va_end (args); // Declare with proper length - std::string msg(len + 1, 0); - va_start (args, message); + int length_overhead = 36; + std::string full_message(length_overhead + len + 1, '\0'); // Fill the new string we just made - std::vsnprintf(msg.data(), len+1, message.c_str(), args); + FormatTime(&today, ms, full_message.data()); + int end_i = 24; // YYYY-MM-DD HH:MM:SS.SSS_ + end_i += std::sprintf(full_message.data() + end_i, " [%s]: ", fPriorities[priority+1].c_str()); + va_start (args, message); + std::vsnprintf(full_message.data() + end_i, len+1, message.c_str(), args); va_end (args); // strip the trailing \0 - msg.pop_back(); + while (full_message.back() == '\0') full_message.pop_back(); { std::unique_lock lg(fMutex); - fQueue.emplace_back(std::make_tuple(std::move(today), ms, priority, std::move(msg))); + fQueue.emplace_back(std::make_tuple(today, ms, priority, std::move(msg))); } fCV.notify_one(); return 0; diff --git a/MongoLog.hh b/MongoLog.hh index 712c0d2d..db6772c5 100644 --- a/MongoLog.hh +++ b/MongoLog.hh @@ -77,7 +77,7 @@ protected: std::tuple Now(); void Flusher(); int RotateLogFile(); - virtual std::string FormatTime(struct tm*, int); + virtual std::string FormatTime(struct tm*, int, char*=nullptr); virtual int Today(struct tm*); virtual std::string LogFileName(struct tm*); virtual std::experimental::filesystem::path OutputDirectory(struct tm*); From 28238bd7ce52fe66f311446c2cd3af60aca8281d Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Fri, 7 May 2021 13:31:22 +0200 Subject: [PATCH 07/22] Typos --- DAQController.cc | 1 - MongoLog.cc | 8 ++++---- MongoLog.hh | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index 443ded36..5495a958 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -107,7 +107,6 @@ int DAQController::Arm(std::shared_ptr& options){ digi->AcquisitionStop(); } } - fCounter = 0; if (OpenThreads()) { fLog->Entry(MongoLog::Warning, "Error opening threads"); fStatus = DAXHelpers::Idle; diff --git a/MongoLog.cc b/MongoLog.cc index 99ec2da3..2021b199 100644 --- a/MongoLog.cc +++ b/MongoLog.cc @@ -51,12 +51,12 @@ void MongoLog::Flusher() { std::unique_lock lk(fMutex); fCV.wait(lk, [&]{return fQueue.size() > 0 || fFlush == false;}); if (fQueue.size()) { - auto [today, ms, priority, message] = std::move(fQueue.front()); + auto [today, std::ignore, priority, message] = std::move(fQueue.front()); fQueue.pop_front(); lk.unlock(); if (Today(&today) != fToday) RotateLogFile(); - std::cout << msg.str(); - fOutfile << msg.str(); + std::cout << message << std::endl; + fOutfile << message << std::endl; if(priority >= fLogLevel){ try{ auto d = bsoncxx::builder::stream::document{} << @@ -173,7 +173,7 @@ int MongoLog::Entry(int priority, const std::string& message, ...){ while (full_message.back() == '\0') full_message.pop_back(); { std::unique_lock lg(fMutex); - fQueue.emplace_back(std::make_tuple(today, ms, priority, std::move(msg))); + fQueue.emplace_back(std::make_tuple(today, ms, priority, std::move(full_message))); } fCV.notify_one(); return 0; diff --git a/MongoLog.hh b/MongoLog.hh index db6772c5..0e36e6b5 100644 --- a/MongoLog.hh +++ b/MongoLog.hh @@ -77,7 +77,7 @@ protected: std::tuple Now(); void Flusher(); int RotateLogFile(); - virtual std::string FormatTime(struct tm*, int, char*=nullptr); + virtual std::string FormatTime(struct tm*, int, char*nullptr); virtual int Today(struct tm*); virtual std::string LogFileName(struct tm*); virtual std::experimental::filesystem::path OutputDirectory(struct tm*); From 8c39a8235d897d9c7ee2bfe4624ae72f314833f1 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Fri, 7 May 2021 13:44:00 +0200 Subject: [PATCH 08/22] More typos --- DAQController.cc | 3 +-- MongoLog.cc | 8 ++++---- MongoLog.hh | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index 5495a958..b52c1c2b 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -215,7 +215,6 @@ void DAQController::ReadData(int link){ fRunning[link] = true; std::chrono::microseconds sleep_time(fOptions->GetInt("us_between_reads", 10)); int c = 0; - int bytes_last_loop = 0; const int num_threads = fNProcessingThreads; while(fReadLoop){ for(auto& digi : fDigitizers[link]) { @@ -260,7 +259,7 @@ void DAQController::ReadData(int link){ t_end-t_start).count()); bytes_this_loop = 0; } - readcycler = ++readcycler>10000 ? 0 : readcycler; + if (++readcycler > 10000) readcycler = 0; std::this_thread::sleep_for(sleep_time); } // while run if (mutex_wait_times.size() > 0) { diff --git a/MongoLog.cc b/MongoLog.cc index 2021b199..e4efd69f 100644 --- a/MongoLog.cc +++ b/MongoLog.cc @@ -51,10 +51,10 @@ void MongoLog::Flusher() { std::unique_lock lk(fMutex); fCV.wait(lk, [&]{return fQueue.size() > 0 || fFlush == false;}); if (fQueue.size()) { - auto [today, std::ignore, priority, message] = std::move(fQueue.front()); + auto [today, priority, message] = std::move(fQueue.front()); fQueue.pop_front(); lk.unlock(); - if (Today(&today) != fToday) RotateLogFile(); + if (today != fToday) RotateLogFile(); std::cout << message << std::endl; fOutfile << message << std::endl; if(priority >= fLogLevel){ @@ -169,11 +169,11 @@ int MongoLog::Entry(int priority, const std::string& message, ...){ va_start (args, message); std::vsnprintf(full_message.data() + end_i, len+1, message.c_str(), args); va_end (args); - // strip the trailing \0 + // strip trailing \0 while (full_message.back() == '\0') full_message.pop_back(); { std::unique_lock lg(fMutex); - fQueue.emplace_back(std::make_tuple(today, ms, priority, std::move(full_message))); + fQueue.emplace_back(std::make_tuple(Today(&today), priority, std::move(full_message))); } fCV.notify_one(); return 0; diff --git a/MongoLog.hh b/MongoLog.hh index 0e36e6b5..90a0084c 100644 --- a/MongoLog.hh +++ b/MongoLog.hh @@ -77,7 +77,7 @@ protected: std::tuple Now(); void Flusher(); int RotateLogFile(); - virtual std::string FormatTime(struct tm*, int, char*nullptr); + virtual std::string FormatTime(struct tm*, int, char* = nullptr); virtual int Today(struct tm*); virtual std::string LogFileName(struct tm*); virtual std::experimental::filesystem::path OutputDirectory(struct tm*); @@ -96,7 +96,7 @@ protected: int fDeleteAfterDays; int fToday; std::mutex fMutex; - std::list> fQueue; + std::list> fQueue; std::condition_variable fCV; std::experimental::filesystem::path fOutputDir; std::thread fFlushThread; From 65fe1410f038fbf5b33c14d2457f1808997c9239 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Mon, 10 May 2021 15:30:25 +0200 Subject: [PATCH 09/22] Sync status updates --- main.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.cc b/main.cc index be725529..cf8e83d3 100644 --- a/main.cc +++ b/main.cc @@ -39,22 +39,24 @@ void UpdateStatus(std::shared_ptr pool, std::string dbname, auto client = pool->acquire(); auto db = (*client)[dbname]; auto collection = db["status"]; + auto next_sec = ceil(system_clock::now()); + const auto dt = seconds(1); + std::this_thread::sleep_until(next_sec); while (b_run == true) { - auto start = std::chrono::system_clock::now(); try{ controller->StatusUpdate(&collection); }catch(const std::exception &e){ std::cout<<"Can't connect to DB to update."<: id number of this readout instance, required\n" << "--uri : full MongoDB URI, required\n" << "--db : name of the database to use, default \"daq\"\n" From be9f0f52e6768bf2e9f5d67fc2dbcfc4a0ed22d9 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 11 May 2021 12:21:34 +0200 Subject: [PATCH 10/22] Intelligent allocation escalation --- Options.cc | 13 +++++++++++++ Options.hh | 1 + V1724.cc | 40 ++++++++++++++++++++++------------------ V1724.hh | 4 ++-- docs/daq_options.md | 4 ++-- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/Options.cc b/Options.cc index 34fcd41c..c7f5ba6a 100644 --- a/Options.cc +++ b/Options.cc @@ -233,6 +233,19 @@ std::vector Options::GetThresholds(int board) { } } +std::vector Options::GetBLTalloc() { + int default_value = 0x80000; + std::vector ret; + try{ + for (auto& val : bson_options["blt_alloc"].get_array().value) + ret.push_back(val.get_int32().value); + } catch(std::exception& e) { + fLog->Entry(MongoLog::Local, "Using default BLT allocs") + ret.push_back(default_value); + } + return ret; +} + int Options::GetV1495Opts(std::map& ret) { if (bson_options.find("V1495") == bson_options.end()) return 1; diff --git a/Options.hh b/Options.hh index 59d109c7..738bcb81 100644 --- a/Options.hh +++ b/Options.hh @@ -83,6 +83,7 @@ public: std::vector GetBoards(std::string); std::vector GetRegisters(int, bool=false); std::vector GetDAC(int, int, uint16_t); + std::vector GetBLTalloc(); int GetV1495Opts(std::map&); int GetCrateOpt(CrateOptions &ret); int GetHEVOpt(HEVOptions &ret); diff --git a/V1724.cc b/V1724.cc index 05b066dd..9472e918 100644 --- a/V1724.cc +++ b/V1724.cc @@ -37,7 +37,7 @@ V1724::V1724(std::shared_ptr& log, std::shared_ptr& opts, int fRolloverCounter = 0; fLastClock = 0; fBLTSafety = opts->GetDouble("blt_safety_factor", 1.5); - BLT_SIZE = opts->GetInt("blt_size", 512*1024); + fBLTalloc = opts->GetBLTalloc(); // there's a more elegant way to do this, but I'm not going to write it fClockPeriod = std::chrono::nanoseconds((1l<<31)*fClockCycle); fArtificialDeadtimeChannel = 790; @@ -213,18 +213,28 @@ int V1724::Read(std::unique_ptr& outptr){ // Initialize int blt_words=0, nb=0, ret=-5; std::vector> xfer_buffers; - xfer_buffers.reserve(16); + xfer_buffers.reserve(4); + //int blt_size[] = {16, 19, 20, 23}; int count = 0; - int alloc_words = BLT_SIZE/sizeof(char32_t)*fBLTSafety; + int alloc_bytes, request_bytes; char32_t* thisBLT = nullptr; do{ - + // each loop allocate more memory than the last one. + // there's a fine line to walk between making many small allocations for full digitizers + // and fewer, large allocations for empty digitizers. 16 19 20 23 seem to be optimal + // for the readers, but this depends heavily on specific machines. + if (count < fBLTalloc.size()) { + alloc_bytes = 1 << fBLTalloc[count]; + } else { + alloc_bytes = 1 << (fBLTalloc.back() + count - fBLTalloc.size() + 1); + } // Reserve space for this block transfer - thisBLT = new char32_t[alloc_words << count]; + thisBLT = new char32_t[alloc_bytes/sizeof(char32_t)]; + request_bytes = alloc_bytes/fBLTsafety; ret = CAENVME_FIFOBLTReadCycle(fBoardHandle, fBaseAddress, thisBLT, - BLT_SIZE << count, cvA32_U_MBLT, cvD64, &nb); + request_bytes, cvA32_U_MBLT, cvD64, &nb); if( (ret != cvSuccess) && (ret != cvBusError) ){ fLog->Entry(MongoLog::Error, "Board %i read error after %i reads: (%i) and transferred %i bytes this read", @@ -235,9 +245,9 @@ int V1724::Read(std::unique_ptr& outptr){ for (auto& b : xfer_buffers) delete[] b.first; return -1; } - if (nb > (BLT_SIZE<Entry(MongoLog::Message, - "Board %i got %i more bytes than asked for (headroom %i)", - fBID, nb-(BLT_SIZE< request_bytes) fLog->Entry(MongoLog::Message, + "Board %i got %x more bytes than asked for (headroom %x)", + fBID, nb-request_bytes, alloc_bytes-nb); count++; blt_words+=nb/sizeof(char32_t); @@ -245,15 +255,9 @@ int V1724::Read(std::unique_ptr& outptr){ }while(ret != cvBusError); - /*Now, unfortunately we need to make one copy of the data here or else our memory - usage explodes. We declare above a buffer of several MB, which is the maximum capacity - of the board in case every channel is 100% saturated (the practical largest - capacity is certainly smaller depending on settings). But if we just keep reserving - O(MB) blocks and filling 50kB with actual data, we're gonna run out of memory. - So here we declare the return buffer as *just* large enough to hold the actual - data and free up the rest of the memory reserved as buffer. - In tests this does not seem to impact our ability to read out the V1724 at the - maximum bandwidth of the link. */ + // Now we have to concatenate all this data into a single continuous buffer + // because I'm too lazy to write a class that allows us to use fragmented + // buffers as if they were continuous if(blt_words>0){ std::u32string s; s.reserve(blt_words); diff --git a/V1724.hh b/V1724.hh index aea4295e..65945877 100644 --- a/V1724.hh +++ b/V1724.hh @@ -71,7 +71,7 @@ protected: unsigned int fVMEAlignmentRegister; unsigned int fBoardErrRegister; - int BLT_SIZE; + std::vector fBLTalloc; std::map fBLTCounter; bool MonitorRegister(uint32_t reg, uint32_t mask, int ntries, int sleep, uint32_t val=1); @@ -90,7 +90,7 @@ protected: std::shared_ptr fLog; std::atomic_bool fError; - float fBLTSafety, fBufferSafety; + float fBLTSafety; int fSampleWidth, fClockCycle; int16_t fArtificialDeadtimeChannel; }; diff --git a/docs/daq_options.md b/docs/daq_options.md index ca48fa44..40078b40 100644 --- a/docs/daq_options.md +++ b/docs/daq_options.md @@ -298,8 +298,8 @@ Redax accepts a variety of options that control various low-level operations. Th | baseline_fraction_around_max | Float. What fraction of total samples in the pulse must be around the mode for the pulse to be accepted. Default 0.8. | | baseline_triggers_per_step | Int. How many software triggers to send for each baseline step. Default 3. | | baseline_ms_between_triggers | Int. How long between software triggers. Default 10. | -| blt_size | Int. How many bytes to read from the digitizer during each BLT readout. This should be rather larger than your expected event sizes. Default 0x80000. | -| blt_safety_factor | Float. Sometimes the digitizer returns more bytes during a BLT readout than you ask for (it depends on the number and size of events in the digitizer's memory). This value is how much extra memory to allocate so you don't overrun the readout buffer. Default 1.5. | +| blt_alloc | Array of integers. An array of (probably increasing) values of how much memory to allocate when reading out a specific board, in log2. Allocating memory is expensive, and it's a waste of time to always allocate a large buffer when the digitizer usually only has one photon, but if a board is full you have to make a lot of single photon-sized allocs to read it all out. Tuning this value depends on what the data looks like and how fast your server allocates memory. [16 19 20 23] is optimal for the XENONnT readout servers, and this saves minutes of CPU time per hour. Default [19]. | +| blt_safety_factor | Float. Sometimes the digitizer returns more bytes during a BLT readout than you ask for (it depends on the number and size of events in the digitizer's memory). This value is how much less to ask for than you allocate you don't overrun the readout buffer. Default 1.5. | | do_sn_check | 0/1. Whether or not to have each board check its serial number during initialization. Default 0. | | us_between_reads | Int. How many microseconds to sleep between polling digitizers for data. This has a major performance impact that will matter when under extremely high loads (ie, the bleeding edge of what your server(s) and boards are capable of), but otherwise shouldn't matter much. Default 10. | | transfer_batch | Int. How many data packets to accumulate in one readout thread before passing off to a processing thread. Default 16. | From d46bf8a47e57cd891a7acd39d9af57109dd430f0 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 11 May 2021 15:47:47 +0200 Subject: [PATCH 11/22] Change rate reporting --- DAQController.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DAQController.cc b/DAQController.cc index b52c1c2b..896c17e1 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -334,10 +334,13 @@ void DAQController::StatusUpdate(mongocxx::collection* collection) { buf.second += x.second; } } + int rate_alt = std::accumulate(retmap.begin(), retmap.end(), 0, + [&](int tot, std::pair& p) {return std::move(tot) + p.second;}); auto doc = document{} << "host" << fHostname << "time" << bsoncxx::types::b_date(std::chrono::system_clock::now())<< - "rate" << rate/1e6 << + "rate_old" << rate/1e6 << + "rate" << rate_alt/1e6 << "status" << fStatus << "buffer_size" << (buf.first + buf.second)/1e6 << "mode" << (fOptions ? fOptions->GetString("name", "none") : "none") << From 40154721214d15b9c13ab2aaa54f99d59f9721ee Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 11 May 2021 15:51:14 +0200 Subject: [PATCH 12/22] Typos --- DAQController.cc | 2 +- Options.cc | 2 +- V1724.cc | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index 896c17e1..c0b3eb09 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -335,7 +335,7 @@ void DAQController::StatusUpdate(mongocxx::collection* collection) { } } int rate_alt = std::accumulate(retmap.begin(), retmap.end(), 0, - [&](int tot, std::pair& p) {return std::move(tot) + p.second;}); + [&](int tot, const std::pair& p) {return std::move(tot) + p.second;}); auto doc = document{} << "host" << fHostname << "time" << bsoncxx::types::b_date(std::chrono::system_clock::now())<< diff --git a/Options.cc b/Options.cc index c7f5ba6a..c5249713 100644 --- a/Options.cc +++ b/Options.cc @@ -240,7 +240,7 @@ std::vector Options::GetBLTalloc() { for (auto& val : bson_options["blt_alloc"].get_array().value) ret.push_back(val.get_int32().value); } catch(std::exception& e) { - fLog->Entry(MongoLog::Local, "Using default BLT allocs") + fLog->Entry(MongoLog::Local, "Using default BLT allocs"); ret.push_back(default_value); } return ret; diff --git a/V1724.cc b/V1724.cc index 9472e918..2d0f3360 100644 --- a/V1724.cc +++ b/V1724.cc @@ -48,7 +48,7 @@ V1724::~V1724(){ End(); if (fBLTCounter.empty()) return; std::stringstream msg; - msg << "BLT report for board " << fBID << " (BLT " << BLT_SIZE << ")"; + msg << "BLT report for board " << fBID; for (auto p : fBLTCounter) msg << " | " << p.first << " " << int(std::log2(p.second)); fLog->Entry(MongoLog::Local, msg.str()); } @@ -231,7 +231,7 @@ int V1724::Read(std::unique_ptr& outptr){ } // Reserve space for this block transfer thisBLT = new char32_t[alloc_bytes/sizeof(char32_t)]; - request_bytes = alloc_bytes/fBLTsafety; + request_bytes = alloc_bytes/fBLTSafety; ret = CAENVME_FIFOBLTReadCycle(fBoardHandle, fBaseAddress, thisBLT, request_bytes, cvA32_U_MBLT, cvD64, &nb); From 46a9adae4e252d33af403e4cedf8c2d528beef4d Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 11 May 2021 15:51:52 +0200 Subject: [PATCH 13/22] No warnings here --- V1724.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/V1724.cc b/V1724.cc index 2d0f3360..ceb9dc25 100644 --- a/V1724.cc +++ b/V1724.cc @@ -216,7 +216,7 @@ int V1724::Read(std::unique_ptr& outptr){ xfer_buffers.reserve(4); //int blt_size[] = {16, 19, 20, 23}; - int count = 0; + unsigned count = 0; int alloc_bytes, request_bytes; char32_t* thisBLT = nullptr; do{ From 080524b43817685b2ff7d6df284b23d30e02ea23 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 18 May 2021 08:55:06 +0200 Subject: [PATCH 14/22] Tweaks --- DAQController.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index c0b3eb09..0f90f59a 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -206,7 +206,6 @@ void DAQController::ReadData(int link){ std::list> local_buffer; std::unique_ptr dp; std::vector mutex_wait_times; - std::vector dps_per_loop; mutex_wait_times.reserve(1<<20); dps_per_loop.reserve(1<<24); int words = 0; @@ -249,8 +248,7 @@ void DAQController::ReadData(int link){ bytes_this_loop += words*sizeof(char32_t); } } // for digi in digitizers - dps_per_loop.push_back(local_buffer.size()); - if (local_buffer.size() >= transfer_batch || fReadLoop == false) { + if (local_buffer.size() && (readcycler % transfer_batch == 0)) { fDataRate += bytes_this_loop; auto t_start = std::chrono::high_resolution_clock::now(); while (fFormatters[(++c)%num_threads]->ReceiveDatapackets(local_buffer, bytes_this_loop)) {} @@ -339,8 +337,8 @@ void DAQController::StatusUpdate(mongocxx::collection* collection) { auto doc = document{} << "host" << fHostname << "time" << bsoncxx::types::b_date(std::chrono::system_clock::now())<< - "rate_old" << rate/1e6 << - "rate" << rate_alt/1e6 << + "rate_old" << rate*1e-6 << + "rate" << rate_alt*1e-6 << "status" << fStatus << "buffer_size" << (buf.first + buf.second)/1e6 << "mode" << (fOptions ? fOptions->GetString("name", "none") : "none") << @@ -352,7 +350,7 @@ void DAQController::StatusUpdate(mongocxx::collection* collection) { doc << std::to_string(pair.first) << short(pair.second>>10); // KB not MB } << close_document << finalize; - collection->insert_one(std::move(doc)); // opts is const& + collection->insert_one(std::move(doc)); return; } From b44f6023fc45bb1ff370b3fb33f14c8ef4b815ed Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 18 May 2021 08:55:52 +0200 Subject: [PATCH 15/22] Forgot that line --- DAQController.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/DAQController.cc b/DAQController.cc index 0f90f59a..b32a6255 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -207,7 +207,6 @@ void DAQController::ReadData(int link){ std::unique_ptr dp; std::vector mutex_wait_times; mutex_wait_times.reserve(1<<20); - dps_per_loop.reserve(1<<24); int words = 0; unsigned transfer_batch = fOptions->GetInt("transfer_batch", 8); int bytes_this_loop(0); From 695c2494239135abff7eb6abb35a8f8e5b1116e5 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 18 May 2021 09:57:06 +0200 Subject: [PATCH 16/22] Forgot this should be log2 --- Options.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Options.cc b/Options.cc index c5249713..518096b7 100644 --- a/Options.cc +++ b/Options.cc @@ -234,7 +234,7 @@ std::vector Options::GetThresholds(int board) { } std::vector Options::GetBLTalloc() { - int default_value = 0x80000; + int default_value = 19; std::vector ret; try{ for (auto& val : bson_options["blt_alloc"].get_array().value) From 50f28adfd445354eca968fb020f55de98e831e0e Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Mon, 24 May 2021 10:47:12 +0200 Subject: [PATCH 17/22] Tweaks --- DAQController.cc | 4 ++++ DAQController.hh | 2 +- MongoLog.cc | 16 ++++++++-------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index b32a6255..6b0a45bc 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -603,6 +603,10 @@ int DAQController::FitBaselines(std::vector> &digis, // iterate if (channel_finished[bid][ch] >= convergence_threshold) { done &= true; + if (channel_finished[bid][ch]++ == convergence_threshold) { + fLog->Entry(MongoLog::Local, "%i.%i converged after %i steps: %.1f", bid, ch, + step, bl_per_channel[bid][ch][step]); + } continue; } diff --git a/DAQController.hh b/DAQController.hh index 237c31bd..a4334826 100644 --- a/DAQController.hh +++ b/DAQController.hh @@ -56,7 +56,7 @@ private: int fNProcessingThreads; // For reporting to frontend - std::atomic_long fDataRate; + volatile std::atomic_long fDataRate; std::atomic_int fPLL; }; diff --git a/MongoLog.cc b/MongoLog.cc index e4efd69f..8a4e6d64 100644 --- a/MongoLog.cc +++ b/MongoLog.cc @@ -61,7 +61,7 @@ void MongoLog::Flusher() { try{ auto d = bsoncxx::builder::stream::document{} << "user" << fHostname << - "message" << std::move(message) << + "message" << message.substr(45) << // 45 overhead chars "priority" << priority << "runid" << fRunId << bsoncxx::builder::stream::finalize; @@ -85,12 +85,12 @@ void MongoLog::Flusher() { std::string MongoLog::FormatTime(struct tm* date, int ms, char* writeto) { std::string out; if (writeto == nullptr) { - out = "YYYY-MM-DD HH:mm:SS.SSS"; + out = "YYYY-MM-DD HH:mm:SS.SSS | fRunId |"; writeto = out.data(); } // this is kinda awkward but we can't use c++20's time-formatting gubbins so :( - std::sprintf(writeto, "%04i-%02i-%02i %02i:%02i:%02i.%03i", date->tm_year+1900, - date->tm_mon+1, date->tm_mday, date->tm_hour, date->tm_min, date->tm_sec, ms); + std::sprintf(writeto, "%04i-%02i-%02i %02i:%02i:%02i.%03i | %6i |", date->tm_year+1900, + date->tm_mon+1, date->tm_mday, date->tm_hour, date->tm_min, date->tm_sec, ms, fRunId); return out; } @@ -160,19 +160,19 @@ int MongoLog::Entry(int priority, const std::string& message, ...){ size_t len = std::vsnprintf(NULL, 0, message.c_str(), args); va_end (args); // Declare with proper length - int length_overhead = 36; + int length_overhead = 46; std::string full_message(length_overhead + len + 1, '\0'); // Fill the new string we just made FormatTime(&today, ms, full_message.data()); - int end_i = 24; // YYYY-MM-DD HH:MM:SS.SSS_ - end_i += std::sprintf(full_message.data() + end_i, " [%s]: ", fPriorities[priority+1].c_str()); + int end_i = std::strlen("YYYY-MM-DD HH:MM:SS.SSS | fRunID |"); + end_i += std::sprintf(full_message.data() + end_i, " %7s | ", fPriorities[priority+1].c_str()); va_start (args, message); std::vsnprintf(full_message.data() + end_i, len+1, message.c_str(), args); va_end (args); // strip trailing \0 while (full_message.back() == '\0') full_message.pop_back(); { - std::unique_lock lg(fMutex); + std::lock_guard lg(fMutex); fQueue.emplace_back(std::make_tuple(Today(&today), priority, std::move(full_message))); } fCV.notify_one(); From 74c4bd32ecc5a99a9ca585a449f2a84914d7ead7 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Mon, 24 May 2021 11:14:38 +0200 Subject: [PATCH 18/22] More tweaks --- DAQController.cc | 4 ++-- V1724.cc | 4 ++++ V1724.hh | 1 + V2718.cc | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/DAQController.cc b/DAQController.cc index 6b0a45bc..55b38caf 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -161,7 +161,7 @@ int DAQController::Stop(){ if (one_still_running) std::this_thread::sleep_for(std::chrono::milliseconds(100)); }while(one_still_running && counter++ < 10); if (counter >= 10) fLog->Entry(MongoLog::Local, "Boards taking a while to clear"); - std::cout<<"Deactivating boards"<Entry(MongoLog::Local, "Stopping boards"); for( auto const& link : fDigitizers ){ for(auto digi : link.second){ digi->AcquisitionStop(true); @@ -190,7 +190,7 @@ int DAQController::Stop(){ fPLL = 0; fLog->SetRunId(-1); fOptions.reset(); - std::cout<<"Finished end"<Entry(MongoLog::Local, "Finished end sequence"); fStatus = DAXHelpers::Idle; return 0; } diff --git a/V1724.cc b/V1724.cc index ceb9dc25..2e48d1a7 100644 --- a/V1724.cc +++ b/V1724.cc @@ -50,6 +50,7 @@ V1724::~V1724(){ std::stringstream msg; msg << "BLT report for board " << fBID; for (auto p : fBLTCounter) msg << " | " << p.first << " " << int(std::log2(p.second)); + msg << " | " << long(fTotReadTime.count()); fLog->Entry(MongoLog::Local, msg.str()); } @@ -209,6 +210,8 @@ unsigned int V1724::ReadRegister(unsigned int reg){ } int V1724::Read(std::unique_ptr& outptr){ + using namespace std::chrono; + auto t_start = high_resolution_clock::now(); if ((GetAcquisitionStatus() & 0x8) == 0) return 0; // Initialize int blt_words=0, nb=0, ret=-5; @@ -269,6 +272,7 @@ int V1724::Read(std::unique_ptr& outptr){ outptr = std::make_unique(std::move(s), ht, cc); } for (auto b : xfer_buffers) delete[] b.first; + fTotReadTime += duration_cast(high_resolution_clock::now()-t_start); return blt_words; } diff --git a/V1724.hh b/V1724.hh index 65945877..d4c6c44d 100644 --- a/V1724.hh +++ b/V1724.hh @@ -93,6 +93,7 @@ protected: float fBLTSafety; int fSampleWidth, fClockCycle; int16_t fArtificialDeadtimeChannel; + std::chrono::nanoseconds fTotReadTime; }; diff --git a/V2718.cc b/V2718.cc index b58233a1..23313cb0 100644 --- a/V2718.cc +++ b/V2718.cc @@ -31,7 +31,7 @@ int V2718::SendStartSignal(){ // Line 3 : LED Pulser CAENVME_SetOutputConf(fBoardHandle, cvOutput3, cvDirect, cvActiveHigh, cvMiscSignals); // Line 4 : NV S-IN Logic - CAENVME_SetOutputConf(fBoardHandle, cvOutput4, cvDirect, cvActiveHigh, cvMiscSignals); // soonTM + CAENVME_SetOutputConf(fBoardHandle, cvOutput4, cvDirect, cvActiveHigh, cvManualSW); // Set the output register From 73eb382c124ce3ea8fe1794bce1b1f315b62e6f2 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Mon, 24 May 2021 15:28:18 +0200 Subject: [PATCH 19/22] Demote that message --- DAQController.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DAQController.cc b/DAQController.cc index 55b38caf..43d52e87 100644 --- a/DAQController.cc +++ b/DAQController.cc @@ -362,7 +362,7 @@ void DAQController::InitLink(std::vector>& digis, fLog->Entry(MongoLog::Warning, "Errors during baseline fitting"); return; } else if (ret > 0) { - fLog->Entry(MongoLog::Message, "Baselines didn't converge so we'll use Plan B"); + fLog->Entry(MongoLog::Debug, "Baselines didn't converge so we'll use Plan B"); } } From 849c8d38b6d7641efe84f1cbf54ae92a6c67feb6 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Tue, 25 May 2021 10:35:08 +0200 Subject: [PATCH 20/22] DDC10 cleanup --- DDC10.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/DDC10.cc b/DDC10.cc index 197f355a..5bcb70de 100644 --- a/DDC10.cc +++ b/DDC10.cc @@ -16,6 +16,15 @@ DDC10::DDC10(){ } DDC10::~DDC10(){ + fHopts.signal_threshold = fHopts.sign = fHopts.rise_time_cut = fHopts.dynamic_veto_limit = fHopts.static_veto_duration = 0; + fHopts.integration_threshold = fHopts.rho_0 = fHopts.rho_1 = fHopts.rho_2 = fHopts.rho_3 = 0; + fHopts.window = fHopts.prescaling = fHopts.component_status = fHopts.width_cut = fHopts.delay = 0; + try{ + if (fHopts.address != "") + Initialize(fHopts); + }catch(std::exception& e) { + std::cout<<"HEV cleanup threw: " << e.what() << std::endl; + } } int DDC10::Initialize(HEVOptions d_opts) From c0e6f8a1a6490862a4900d4601aeaa42ecf30e89 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Mon, 7 Jun 2021 16:49:15 +0200 Subject: [PATCH 21/22] Tweaks and fixes --- MongoLog.cc | 2 +- Options.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MongoLog.cc b/MongoLog.cc index 8a4e6d64..dd03da7d 100644 --- a/MongoLog.cc +++ b/MongoLog.cc @@ -116,7 +116,7 @@ int MongoLog::RotateLogFile() { auto filename = LogFilePath(&today); std::cout<<"Logging to " << filename << std::endl; auto pp = filename.parent_path(); - if (!fs::exists(pp) && !fs::create_directories(pp)) { + if (!pp.empty() && !fs::exists(pp) && !fs::create_directories(pp)) { std::cout << "Could not create output directories for logging!" << std::endl; return -1; } diff --git a/Options.cc b/Options.cc index 518096b7..b0083a39 100644 --- a/Options.cc +++ b/Options.cc @@ -234,7 +234,7 @@ std::vector Options::GetThresholds(int board) { } std::vector Options::GetBLTalloc() { - int default_value = 19; + int default_value = 23; std::vector ret; try{ for (auto& val : bson_options["blt_alloc"].get_array().value) From 9e33c6dba96840122127e6feccb6fa015fb8f286 Mon Sep 17 00:00:00 2001 From: Darryl Masson Date: Wed, 9 Jun 2021 10:15:22 +0200 Subject: [PATCH 22/22] Few more tweaks --- MongoLog.cc | 12 ++++++------ V1724.cc | 3 +-- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/MongoLog.cc b/MongoLog.cc index dd03da7d..fbac52f1 100644 --- a/MongoLog.cc +++ b/MongoLog.cc @@ -125,7 +125,7 @@ int MongoLog::RotateLogFile() { std::cout << "Could not rotate logfile!\n"; return -1; } - fOutfile << FormatTime(&today, ms) << " [INIT]: logfile initialized: commit " << REDAX_BUILD_COMMIT << "\n"; + fOutfile << FormatTime(&today, ms) << " INIT | logfile initialized, commit " << REDAX_BUILD_COMMIT << "\n"; fToday = Today(&today); if (fDeleteAfterDays == 0) return 0; std::vector days_per_month = {31,28,31,30,31,30,31,31,30,31,30,31}; @@ -141,11 +141,11 @@ int MongoLog::RotateLogFile() { last_week.tm_mday += days_per_month[last_week.tm_mon]; // off by one error??? } auto p = LogFileName(&last_week); - if (std::experimental::filesystem::exists(p)) { - fOutfile << FormatTime(&today, ms) << " [INIT]: Deleting " << p << '\n'; - std::experimental::filesystem::remove(p); + if (fs::exists(p)) { + fOutfile << FormatTime(&today, ms) << " INIT | Deleting " << p << '\n'; + fs::remove(p); } else { - fOutfile << FormatTime(&today, ms) << " [INIT]: No older logfile to delete :(\n"; + fOutfile << FormatTime(&today, ms) << " INIT | No older logfile to delete :(\n"; } return 0; } @@ -160,7 +160,7 @@ int MongoLog::Entry(int priority, const std::string& message, ...){ size_t len = std::vsnprintf(NULL, 0, message.c_str(), args); va_end (args); // Declare with proper length - int length_overhead = 46; + int length_overhead = 50; std::string full_message(length_overhead + len + 1, '\0'); // Fill the new string we just made FormatTime(&today, ms, full_message.data()); diff --git a/V1724.cc b/V1724.cc index 2e48d1a7..e1bd5b03 100644 --- a/V1724.cc +++ b/V1724.cc @@ -217,7 +217,6 @@ int V1724::Read(std::unique_ptr& outptr){ int blt_words=0, nb=0, ret=-5; std::vector> xfer_buffers; xfer_buffers.reserve(4); - //int blt_size[] = {16, 19, 20, 23}; unsigned count = 0; int alloc_bytes, request_bytes; @@ -249,7 +248,7 @@ int V1724::Read(std::unique_ptr& outptr){ return -1; } if (nb > request_bytes) fLog->Entry(MongoLog::Message, - "Board %i got %x more bytes than asked for (headroom %x)", + "Board %i got %x more bytes than asked for (headroom %i)", fBID, nb-request_bytes, alloc_bytes-nb); count++;