From 344bfd8809c036298b76e0e275a9b2cfa524f80b Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Thu, 6 Oct 2022 22:31:24 -0400 Subject: [PATCH] Fix several small bugs in the digitizer classes, serialization, aquisition. Overhaul scope, was basically useless in original form --- src/Core/ProjectSerializer.cpp | 2 +- src/DAQ/Digitizer.cpp | 46 +++++++++++-------------- src/DAQ/Digitizer.h | 4 +-- src/DAQ/DigitizerChain.cpp | 2 +- src/DAQ/DigitizerDefs.h | 12 +++---- src/Editor/EditorLayer.cpp | 2 +- src/Editor/ScopePanel.cpp | 62 +++++++++++++++++++++------------- src/Editor/ScopePanel.h | 11 +++--- 8 files changed, 75 insertions(+), 66 deletions(-) diff --git a/src/Core/ProjectSerializer.cpp b/src/Core/ProjectSerializer.cpp index d3164b9..1283335 100644 --- a/src/Core/ProjectSerializer.cpp +++ b/src/Core/ProjectSerializer.cpp @@ -31,7 +31,7 @@ namespace YAML { args.type = (CAEN_DGTZ_ConnectionType) node["ConnectionType"].as(); args.linkNumber = node["LinkNumber"].as(); - args.conetNode = node["ConetNode"].as(); + args.conetNode = node["CONETNode"].as(); args.vmeAddress = node["VMEAddress"].as(); args.handle = node["Handle"].as(); args.model = (CAEN_DGTZ_BoardModel_t) node["Model"].as(); diff --git a/src/DAQ/Digitizer.cpp b/src/DAQ/Digitizer.cpp index 7ee61c3..b2ac3d1 100644 --- a/src/DAQ/Digitizer.cpp +++ b/src/DAQ/Digitizer.cpp @@ -63,14 +63,13 @@ namespace Daqromancy { m_args.model = CAEN_DGTZ_BoardModel_t::CAEN_DGTZ_V1740; else m_args.model = CAEN_DGTZ_BoardModel_t::CAEN_DGTZ_DT5720; - m_args.name = info.ModelName + std::to_string(info.SerialNumber); + m_args.name = info.ModelName + std::string("_") + std::to_string(info.SerialNumber); m_args.firmware = CAEN_DGTZ_DPPFirmware_PHA; m_args.channels = info.Channels; m_channelParams.resize(info.Channels); m_eventCountsPerChannel = new uint32_t[info.Channels]; m_eventData = new CAEN_DGTZ_DPP_PHA_Event_t*[info.Channels]; - m_waveData = new CAEN_DGTZ_DPP_PHA_Waveforms_t*[info.Channels]; for (int i = 0; i < info.Channels; i++) { @@ -277,16 +276,14 @@ namespace Daqromancy { m_args.status |= CAEN_DGTZ_MallocReadoutBuffer(m_args.handle, &m_lowBuffer, &m_lowBufferSize); //void casts are soooo bad .... but required by CAEN API m_args.status |= CAEN_DGTZ_MallocDPPEvents(m_args.handle, (void**)(m_eventData), &m_eventBufferSize); - for(int channel=0; channel& buffer) @@ -300,7 +297,7 @@ namespace Daqromancy { return; } - m_args.status |= CAEN_DGTZ_GetDPPEvents(m_args.handle, m_lowBuffer, m_lowBufferSize, (void**)(&m_eventData), m_eventCountsPerChannel); + m_args.status |= CAEN_DGTZ_GetDPPEvents(m_args.handle, m_lowBuffer, m_lowBufferSize, (void**)(m_eventData), m_eventCountsPerChannel); size_t waveSize; DYData tempData; tempData.board = m_args.handle; @@ -318,15 +315,15 @@ namespace Daqromancy { if(m_digitizerParams.dppAcqMode != CAEN_DGTZ_DPP_ACQ_MODE_List) { CAEN_DGTZ_DecodeDPPWaveforms(m_args.handle, (void*)&(m_eventData[i][j]), m_waveData); - tempData.waveSize = m_waveData[i]->Ns; - waveSize = m_waveData[i]->Ns; + tempData.waveSize = m_waveData->Ns; + waveSize = m_waveData->Ns; if(waveSize != 0) { //Copy the data to our vectors PHA supports 2 analog traces and 2 digital traces - tempData.trace1Samples.assign(m_waveData[i]->Trace1, m_waveData[i]->Trace1 + waveSize); - tempData.trace2Samples.assign(m_waveData[i]->Trace2, m_waveData[i]->Trace2 + waveSize); //This is all zero if in single analog trace mode - tempData.digitalTrace1Samples.assign(m_waveData[i]->DTrace1, m_waveData[i]->DTrace1 + waveSize); - tempData.digitalTrace2Samples.assign(m_waveData[i]->DTrace2, m_waveData[i]->DTrace2 + waveSize); + tempData.trace1Samples.assign(m_waveData->Trace1, m_waveData->Trace1 + waveSize); + tempData.trace2Samples.assign(m_waveData->Trace2, m_waveData->Trace2 + waveSize); //This is all zero if in single analog trace mode + tempData.digitalTrace1Samples.assign(m_waveData->DTrace1, m_waveData->DTrace1 + waveSize); + tempData.digitalTrace2Samples.assign(m_waveData->DTrace2, m_waveData->DTrace2 + waveSize); } } buffer.push_back(tempData); @@ -358,14 +355,13 @@ namespace Daqromancy { m_args.model = CAEN_DGTZ_BoardModel_t::CAEN_DGTZ_V1740; else m_args.model = CAEN_DGTZ_BoardModel_t::CAEN_DGTZ_DT5720; - m_args.name = info.ModelName + std::to_string(info.SerialNumber); + m_args.name = info.ModelName + std::string(" ") + std::to_string(info.SerialNumber); m_args.firmware = CAEN_DGTZ_DPPFirmware_PSD; m_args.channels = info.Channels; m_channelParams.resize(info.Channels); m_eventCountsPerChannel = new uint32_t[info.Channels]; m_eventData = new CAEN_DGTZ_DPP_PSD_Event_t*[info.Channels]; - m_waveData = new CAEN_DGTZ_DPP_PSD_Waveforms_t*[info.Channels]; LoadDigitizerParameters(); LoadChannelParameters(); //Must load default parameters here to generate a buffer @@ -560,16 +556,14 @@ namespace Daqromancy { m_args.status |= CAEN_DGTZ_MallocReadoutBuffer(m_args.handle, &m_lowBuffer, &m_lowBufferSize); //void casts are soooo bad .... but required by CAEN API m_args.status |= CAEN_DGTZ_MallocDPPEvents(m_args.handle, (void**)(m_eventData), &m_eventBufferSize); - for(int channel=0; channel& buffer) @@ -583,7 +577,7 @@ namespace Daqromancy { return; } - m_args.status |= CAEN_DGTZ_GetDPPEvents(m_args.handle, m_lowBuffer, m_lowBufferSize, (void**)(&m_eventData), m_eventCountsPerChannel); + m_args.status |= CAEN_DGTZ_GetDPPEvents(m_args.handle, m_lowBuffer, m_lowBufferSize, (void**)(m_eventData), m_eventCountsPerChannel); size_t waveSize; DYData tempData; tempData.board = m_args.handle; @@ -602,15 +596,15 @@ namespace Daqromancy { if(m_digitizerParams.dppAcqMode != CAEN_DGTZ_DPP_ACQ_MODE_List) { CAEN_DGTZ_DecodeDPPWaveforms(m_args.handle, (void*)&(m_eventData[i][j]), m_waveData); - tempData.waveSize = m_waveData[i]->Ns; - waveSize = m_waveData[i]->Ns; + tempData.waveSize = m_waveData->Ns; + waveSize = m_waveData->Ns; if(tempData.waveSize != 0) { //Copy the data to our vectors PHA supports 2 analog traces and 2 digital traces - tempData.trace1Samples.assign(m_waveData[i]->Trace1, m_waveData[i]->Trace1 + waveSize); - tempData.trace2Samples.assign(m_waveData[i]->Trace2, m_waveData[i]->Trace2 + waveSize); //This is all zero if in single analog trace mode - tempData.digitalTrace1Samples.assign(m_waveData[i]->DTrace1, m_waveData[i]->DTrace1 + waveSize); - tempData.digitalTrace2Samples.assign(m_waveData[i]->DTrace2, m_waveData[i]->DTrace2 + waveSize); + tempData.trace1Samples.assign(m_waveData->Trace1, m_waveData->Trace1 + waveSize); + tempData.trace2Samples.assign(m_waveData->Trace2, m_waveData->Trace2 + waveSize); //This is all zero if in single analog trace mode + tempData.digitalTrace1Samples.assign(m_waveData->DTrace1, m_waveData->DTrace1 + waveSize); + tempData.digitalTrace2Samples.assign(m_waveData->DTrace2, m_waveData->DTrace2 + waveSize); } } buffer.push_back(tempData); diff --git a/src/DAQ/Digitizer.h b/src/DAQ/Digitizer.h index a592420..d7b4b14 100644 --- a/src/DAQ/Digitizer.h +++ b/src/DAQ/Digitizer.h @@ -179,7 +179,7 @@ namespace Daqromancy { //CAEN required data storage, does not interface to other parts of the program CAEN_DGTZ_DPP_PHA_Event_t** m_eventData; - CAEN_DGTZ_DPP_PHA_Waveforms_t** m_waveData; + CAEN_DGTZ_DPP_PHA_Waveforms_t* m_waveData; CAEN_DGTZ_DPP_PHA_Params_t m_caenParams; std::vector m_channelParams; @@ -218,7 +218,7 @@ namespace Daqromancy { //CAEN required data storage, does not interface to other parts of the program CAEN_DGTZ_DPP_PSD_Event_t** m_eventData; - CAEN_DGTZ_DPP_PSD_Waveforms_t** m_waveData; + CAEN_DGTZ_DPP_PSD_Waveforms_t* m_waveData; CAEN_DGTZ_DPP_PSD_Params_t m_caenParams; std::vector m_channelParams; diff --git a/src/DAQ/DigitizerChain.cpp b/src/DAQ/DigitizerChain.cpp index 2633a67..4a54c59 100644 --- a/src/DAQ/DigitizerChain.cpp +++ b/src/DAQ/DigitizerChain.cpp @@ -64,7 +64,7 @@ namespace Daqromancy { switch (mode) { case DPPAcqMode::List: modeIn = CAEN_DGTZ_DPP_ACQ_MODE_List; break; - case DPPAcqMode::Waves: modeIn = CAEN_DGTZ_DPP_ACQ_MODE_Oscilloscope; break; + case DPPAcqMode::Waves: modeIn = CAEN_DGTZ_DPP_ACQ_MODE_Mixed; break; case DPPAcqMode::None: DY_WARN("Attempted to set DPPAcqMode::None!"); return; } diff --git a/src/DAQ/DigitizerDefs.h b/src/DAQ/DigitizerDefs.h index a5c0b55..06401b3 100644 --- a/src/DAQ/DigitizerDefs.h +++ b/src/DAQ/DigitizerDefs.h @@ -242,17 +242,17 @@ namespace Daqromancy { //Option of dual analog, which types (digital probe 2 is always trigger for PHA) struct PHAWaveParameters { - CAEN_DGTZ_DPP_VirtualProbe_t isDual = CAEN_DGTZ_DPP_VIRTUALPROBE_SINGLE; //Default to a single analog trace - PHAVirtualProbe1Options analogProbe1 = PHAVirtualProbe1Options::PHAVP1_Input; //Main analog trace defaults to input signal; - PHAVirtualProbe2Options analogProbe2 = PHAVirtualProbe2Options::PHAVP2_None; //Default val; in default config wont be displayed - PHADigitalProbe1Options digitalProbe1 = PHADigitalProbe1Options::PHADP_TriggerWindow; //Idk guess this is good default + CAEN_DGTZ_DPP_VirtualProbe_t isDual = CAEN_DGTZ_DPP_VIRTUALPROBE_DUAL; //Default to a single analog trace + PHAVirtualProbe1Options analogProbe1 = PHAVirtualProbe1Options::PHAVP1_Delta2; //Main analog trace defaults to delta2; + PHAVirtualProbe2Options analogProbe2 = PHAVirtualProbe2Options::PHAVP2_Input; //Default val; in default config wont be displayed + PHADigitalProbe1Options digitalProbe1 = PHADigitalProbe1Options::PHADP_Peaking; //Idk guess this is good default }; struct PSDWaveParameters { - CAEN_DGTZ_DPP_VirtualProbe_t isDual = CAEN_DGTZ_DPP_VIRTUALPROBE_SINGLE; //Default to a single analog trace + CAEN_DGTZ_DPP_VirtualProbe_t isDual = CAEN_DGTZ_DPP_VIRTUALPROBE_DUAL; //Default to a single analog trace PSDVirtualProbe1Options analogProbe1 = PSDVirtualProbe1Options::PSDVP1_Input; //Main trace defaults to input - PSDVirtualProbe2Options analogProbe2 = PSDVirtualProbe2Options::PSDVP2_None; //Defaults to off + PSDVirtualProbe2Options analogProbe2 = PSDVirtualProbe2Options::PSDVP2_Baseline; //Defaults to off PSDDigitalProbe1Options digitalProbe1 = PSDDigitalProbe1Options::PSDDP1_Gate; //Defaults to long gate PSDDigitalProbe2Options digitalProbe2 = PSDDigitalProbe2Options::PSDDP2_GateShort; //Defaults to short gate }; diff --git a/src/Editor/EditorLayer.cpp b/src/Editor/EditorLayer.cpp index 50bdc54..9ad6c3f 100644 --- a/src/Editor/EditorLayer.cpp +++ b/src/Editor/EditorLayer.cpp @@ -231,7 +231,7 @@ namespace Daqromancy { AcqDPPModeEvent e; m_eventCallback(e); - m_scopePanel = new ScopePanel(m_digiPanels.size()); + m_scopePanel = new ScopePanel(m_project); } ImGui::EndCombo(); } diff --git a/src/Editor/ScopePanel.cpp b/src/Editor/ScopePanel.cpp index 127002b..ea379c4 100644 --- a/src/Editor/ScopePanel.cpp +++ b/src/Editor/ScopePanel.cpp @@ -1,18 +1,16 @@ #include "ScopePanel.h" +#include "DAQ/DigitizerDefs.h" + #include "imgui.h" #include "implot.h" namespace Daqromancy { - ScopePanel::ScopePanel(int nboards) : - m_dataReady(false), m_selectedBoard(0), m_selectedChannel(0), m_maxNumBoards(nboards) + ScopePanel::ScopePanel(const DYProject::Ref& project) : + m_dataReady(false), m_selectedBoard(-1), m_selectedChannel(-1), m_selectedSamplingPeriod(0.0), m_project(project) { m_dataHandle = DataDistributor::Connect(); - for (int i = 0; i < nboards; i++) - m_boardListForImGui.push_back(fmt::format("{0}", i)); - for (int i = 0; i < 16; i++) //bad hardcode, fix later - m_channelListForImGui.push_back(fmt::format("{0}", i)); } ScopePanel::~ScopePanel() @@ -31,9 +29,7 @@ namespace Daqromancy { if (hit.board == m_selectedBoard && hit.channel == m_selectedChannel) { m_selectedHit = hit; - m_selectedXAxis.clear(); - for (int i = 0; i < hit.waveSize; i++) - m_selectedXAxis.push_back(i); + m_selectedSamplingPeriod = GetSamplingPeriod(m_project->GetDigitizerArgs(m_selectedBoard).model); break; } } @@ -42,45 +38,65 @@ namespace Daqromancy { void ScopePanel::OnImGuiRender() { - static std::string selectedBoardString = fmt::format("{0}", m_selectedBoard); - static std::string selectedChannelString = fmt::format("{0}", m_selectedChannel); + static std::string selectedBoardString = ""; + static std::string selectedChannelString = ""; + static int availChannels = -1; + static std::string analog1 = "##analog1"; + static std::string analog2 = "##analog2"; + static std::string digital1 = "##digital1"; + static std::string digital2 = "##digital2"; if (ImGui::Begin("Oscilloscope")) { if (ImGui::BeginCombo("Board", selectedBoardString.c_str())) { - for (int board=0; boardGetDigitizerArgsList()) { - if (ImGui::Selectable(m_boardListForImGui[board].c_str(), board == m_selectedBoard)) + if (ImGui::Selectable(boardArgs.name.c_str(), boardArgs.handle == m_selectedBoard)) { - m_selectedBoard = board; + m_selectedBoard = boardArgs.handle; + availChannels = boardArgs.channels; selectedBoardString = fmt::format("{0}", m_selectedBoard); - m_selectedXAxis.clear(); + if (boardArgs.firmware == CAEN_DGTZ_DPPFirmware_PHA) + { + const auto& phaParams = m_project->GetPHAWaveParameters(boardArgs.handle); + analog1 = PHAVirtualProbe1ToString(phaParams.analogProbe1); + analog2 = PHAVirtualProbe2ToString(phaParams.analogProbe2); + digital1 = PHADigitalProbeToString(phaParams.digitalProbe1); + digital2 = "Trigger"; + } + else if (boardArgs.firmware == CAEN_DGTZ_DPPFirmware_PSD) + { + const auto& psdParams = m_project->GetPSDWaveParameters(boardArgs.handle); + analog1 = PSDVirtualProbe1ToString(psdParams.analogProbe1); + analog2 = PSDVirtualProbe2ToString(psdParams.analogProbe2); + digital1 = PSDDigitalProbe1ToString(psdParams.digitalProbe1); + digital2 = PSDDigitalProbe2ToString(psdParams.digitalProbe2); + } } } ImGui::EndCombo(); } if (ImGui::BeginCombo("Channel", selectedChannelString.c_str())) { - for (int channel = 0; channel < 16; channel++) //hardcoded bad, fix later + for (int channel = 0; channel < availChannels; channel++) { - if (ImGui::Selectable(m_channelListForImGui[channel].c_str(), channel == m_selectedChannel)) + if (ImGui::Selectable(fmt::format("{0}", channel).c_str(), channel == m_selectedChannel)) { m_selectedChannel = channel; selectedChannelString = fmt::format("{0}", m_selectedChannel); - m_selectedXAxis.clear(); } } ImGui::EndCombo(); } if (ImPlot::BeginPlot("ScopeView", ImVec2(-1,-1))) { - if (m_selectedXAxis.size() != 0) + if (m_selectedHit.waveSize != 0) { - ImPlot::PlotLine("AnalogProbe1", (ImU16*)m_selectedXAxis.data(), (ImU16*)m_selectedHit.trace1Samples.data(), m_selectedXAxis.size()); - ImPlot::PlotLine("AnalogProbe2", (ImU16*)m_selectedXAxis.data(), (ImU16*)m_selectedHit.trace2Samples.data(), m_selectedXAxis.size()); - ImPlot::PlotLine("DigitialProbe1", (ImU16*)m_selectedXAxis.data(), (ImU16*)m_selectedHit.digitalTrace1Samples.data(), m_selectedXAxis.size()); - ImPlot::PlotLine("DigitialProbe2", (ImU16*)m_selectedXAxis.data(), (ImU16*)m_selectedHit.digitalTrace2Samples.data(), m_selectedXAxis.size()); + ImPlot::PlotLine(analog1.c_str(), (ImU16*)m_selectedHit.trace1Samples.data(), m_selectedHit.trace1Samples.size(), m_selectedSamplingPeriod); + ImPlot::PlotLine(analog2.c_str(), (ImU16*)m_selectedHit.trace2Samples.data(), m_selectedHit.trace2Samples.size(), m_selectedSamplingPeriod); + ImPlot::PlotLine(digital1.c_str(), (ImU8*)m_selectedHit.digitalTrace1Samples.data(), m_selectedHit.digitalTrace1Samples.size(), m_selectedSamplingPeriod); + ImPlot::PlotLine(digital2.c_str(), (ImU8*)m_selectedHit.digitalTrace2Samples.data(), m_selectedHit.digitalTrace2Samples.size(), m_selectedSamplingPeriod); } ImPlot::EndPlot(); } diff --git a/src/Editor/ScopePanel.h b/src/Editor/ScopePanel.h index f0c3baf..ab5cc30 100644 --- a/src/Editor/ScopePanel.h +++ b/src/Editor/ScopePanel.h @@ -3,32 +3,31 @@ #include "DAQ/DigitizerDefs.h" #include "Core/DataDistributor.h" +#include "Core/DYProject.h" namespace Daqromancy { class ScopePanel { public: - ScopePanel(int nboards); + ScopePanel(const DYProject::Ref& project); ~ScopePanel(); void OnUpdate(); void OnImGuiRender(); private: - //uint64_t m_consumerID; DistributorClient m_dataHandle; std::vector m_buffer; //Buffered data retrieved from ring DYData m_selectedHit; //Hit associated with selected board/channel - std::vector m_selectedXAxis; //X data is not given by DAQ, has to be made based on number of wave samples bool m_dataReady; int m_selectedBoard; int m_selectedChannel; - int m_maxNumBoards; + double m_selectedSamplingPeriod; - std::vector m_boardListForImGui; - std::vector m_channelListForImGui; + + DYProject::Ref m_project; }; }