From 5b39589c17667a9114a5e78402d5de685ed7a08b Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Wed, 11 May 2022 22:34:14 -0400 Subject: [PATCH] Attempted fix to handling the online CoMPASS data. No changes to CompassOnlineSource really, instead make event builder handle this. Now buffer up 100 hits, and then can optionally sort the hits. Hits glomed into events, and then passed to analysis chain. --- .../src/Navigator/Editor/SourceDialog.cpp | 12 ++++- Navigator/src/Navigator/Events/PhysicsEvent.h | 6 ++- .../Physics/Caen/CompassOnlineSource.h | 1 - .../Navigator/Physics/PhysicsEventBuilder.cpp | 49 +++++++++++-------- .../Navigator/Physics/PhysicsEventBuilder.h | 19 ++++--- .../src/Navigator/Physics/PhysicsLayer.cpp | 26 +++++----- 6 files changed, 69 insertions(+), 44 deletions(-) diff --git a/Navigator/src/Navigator/Editor/SourceDialog.cpp b/Navigator/src/Navigator/Editor/SourceDialog.cpp index b3c7666..17d1472 100644 --- a/Navigator/src/Navigator/Editor/SourceDialog.cpp +++ b/Navigator/src/Navigator/Editor/SourceDialog.cpp @@ -78,8 +78,16 @@ namespace Navigator { if (ImGui::Button("Ok")) { - PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort); - Application::Get().OnEvent(event); + if (m_chosenType == DataSource::SourceType::CompassOffline) + { + PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort); + Application::Get().OnEvent(event); + } + else if (m_chosenType == DataSource::SourceType::CompassOnline) + { + PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort, true); + Application::Get().OnEvent(event); + } ImGui::CloseCurrentPopup(); } ImGui::SameLine(); diff --git a/Navigator/src/Navigator/Events/PhysicsEvent.h b/Navigator/src/Navigator/Events/PhysicsEvent.h index 865b679..9abc2c9 100644 --- a/Navigator/src/Navigator/Events/PhysicsEvent.h +++ b/Navigator/src/Navigator/Events/PhysicsEvent.h @@ -16,14 +16,15 @@ namespace Navigator { class NAV_API PhysicsStartEvent : public Event { public: - PhysicsStartEvent(const std::string& loc, DataSource::SourceType type, uint64_t window, const std::string& port = "51489") : - m_sourceLocation(loc), m_port(port), m_sourceType(type), m_coincidenceWindow(window) + PhysicsStartEvent(const std::string& loc, DataSource::SourceType type, uint64_t window, const std::string& port = "51489", bool sortFlag=false) : + m_sourceLocation(loc), m_port(port), m_sourceType(type), m_coincidenceWindow(window), m_sortFlag(sortFlag) {} inline std::string GetSourceLocation() { return m_sourceLocation; } inline std::string GetSourcePort() { return m_port; } inline DataSource::SourceType GetSourceType() { return m_sourceType; } inline uint64_t GetCoincidenceWindow() { return m_coincidenceWindow; } + inline bool GetSortFlag() { return m_sortFlag; } std::string ToString() const override { @@ -38,6 +39,7 @@ namespace Navigator { std::string m_port; DataSource::SourceType m_sourceType; uint64_t m_coincidenceWindow; + bool m_sortFlag; }; class NAV_API PhysicsStopEvent : public Event diff --git a/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h index 73a7745..b25e13e 100644 --- a/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h +++ b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h @@ -44,7 +44,6 @@ namespace Navigator { void GetHit(); std::vector m_currentBuffer; - std::vector m_fragment; static constexpr int m_datasize = 24; //size of CoMPASS hit in bytes, change as needed (if for example you have calibrated energies) const int m_nchannels_per_board = 16; //IMPORTANT: Used for ID'ing channels uniquely. If you use boards with 32 or 8 or 64 channels you must change this! If you mix boards with //different numbers of channels, you will have to find a different id solution. diff --git a/Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp b/Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp index c9b6dc3..23442b8 100644 --- a/Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp +++ b/Navigator/src/Navigator/Physics/PhysicsEventBuilder.cpp @@ -13,7 +13,7 @@ namespace Navigator { PhysicsEventBuilder::PhysicsEventBuilder(uint64_t windowSize) : - m_coincWindow(windowSize), m_eventStartTime(0) + m_sortFlag(false), m_coincWindow(windowSize), m_bufferIndex(0) { } @@ -21,36 +21,45 @@ namespace Navigator { { } - bool PhysicsEventBuilder::AddDatumToEvent(const NavData& datum) + bool PhysicsEventBuilder::AddDatum(const NavData& datum) { NAV_PROFILE_FUNCTION(); if (datum.timestamp == 0) //Ignore empty data (need a valid timestamp) return false; - if (m_eventStartTime == 0) //first ever event - { - m_eventStartTime = datum.timestamp; - m_event.push_back(datum); + m_dataBuffer[m_bufferIndex] = datum; + m_bufferIndex++; + if (m_bufferIndex < s_maxDataBuffer) //If we haven't filled the buffer keep going return false; - } - else if (datum.timestamp - m_eventStartTime < m_coincWindow) //are we within active window + else if (m_sortFlag) + std::sort(m_dataBuffer.begin(), m_dataBuffer.end(), [](NavData& i, NavData& j) { return i.timestamp < j.timestamp; }); + + //Generate our ready events + m_readyEvents.clear(); + uint64_t eventStartTime = m_dataBuffer[0].timestamp; + NavEvent event; + event.push_back(m_dataBuffer[0]); + for (auto& data : m_dataBuffer) { - m_event.push_back(datum); - return false; - } - else // found one that falls outside - { - m_readyEvent = m_event; - m_event.clear(); - m_eventStartTime = datum.timestamp; - m_event.push_back(datum); - return true; + if (data.timestamp - eventStartTime < m_coincWindow) //are we within active window + { + event.push_back(data); + } + else // found one that falls outside + { + m_readyEvents.push_back(event); + event.clear(); + eventStartTime = data.timestamp; + event.push_back(data); + } } + m_bufferIndex = 0; + return true; } - const NavEvent& PhysicsEventBuilder::GetReadyEvent() const + const std::vector& PhysicsEventBuilder::GetReadyEvents() const { - return m_readyEvent; + return m_readyEvents; } } \ No newline at end of file diff --git a/Navigator/src/Navigator/Physics/PhysicsEventBuilder.h b/Navigator/src/Navigator/Physics/PhysicsEventBuilder.h index 28d2dc9..09b8a5e 100644 --- a/Navigator/src/Navigator/Physics/PhysicsEventBuilder.h +++ b/Navigator/src/Navigator/Physics/PhysicsEventBuilder.h @@ -21,20 +21,23 @@ namespace Navigator { PhysicsEventBuilder(uint64_t windowSize); ~PhysicsEventBuilder(); inline void SetCoincidenceWindow(uint64_t windowSize) { m_coincWindow = windowSize; } + inline void SetSortFlag(bool flag) { m_sortFlag = flag; } inline void ClearAll() // reset all internal structures { - m_event.clear(); - m_readyEvent.clear(); - m_eventStartTime = 0; + m_bufferIndex = 0; + m_readyEvents.clear(); } - bool AddDatumToEvent(const NavData& datum); - const NavEvent& GetReadyEvent() const; + bool AddDatum(const NavData& datum); + const std::vector& GetReadyEvents() const; private: - NavEvent m_event; - NavEvent m_readyEvent; + bool m_sortFlag; + static constexpr int s_maxDataBuffer = 100; + std::array m_dataBuffer; + int m_bufferIndex; + std::vector m_readyEvents; uint64_t m_coincWindow; - uint64_t m_eventStartTime; + }; } diff --git a/Navigator/src/Navigator/Physics/PhysicsLayer.cpp b/Navigator/src/Navigator/Physics/PhysicsLayer.cpp index c553f02..2544e68 100644 --- a/Navigator/src/Navigator/Physics/PhysicsLayer.cpp +++ b/Navigator/src/Navigator/Physics/PhysicsLayer.cpp @@ -116,6 +116,7 @@ namespace Navigator { std::scoped_lock guard(m_sourceMutex); //Shouldn't matter for this, but safety first m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetSourceType())); m_eventBuilder.SetCoincidenceWindow(event.GetCoincidenceWindow()); + m_eventBuilder.SetSortFlag(event.GetSortFlag()); m_eventBuilder.ClearAll(); //Protect against stopping mid-event if (m_source->IsValid()) { @@ -144,7 +145,7 @@ namespace Navigator { NAV_PROFILE_FUNCTION(); SpectrumManager& manager = SpectrumManager::GetInstance(); - NavEvent event; + std::vector events; NavData datum; while(m_activeFlag) { @@ -167,17 +168,20 @@ namespace Navigator { } } - //Pass data from source to event builder. True from AddDatumToEvent indicates event is ready - if (m_eventBuilder.AddDatumToEvent(datum)) + //Pass data from source to event builder. True from AddDatum indicates events are ready + if (m_eventBuilder.AddDatum(datum)) { - event = m_eventBuilder.GetReadyEvent(); - for (auto& stage : m_physStack) - stage->AnalyzePhysicsEvent(event); - - //Now that the analysis stack has filled all our NavParameters with data, update the histogram counts - manager.UpdateHistograms(); - //Invalidate all parameters to get ready for next event - manager.InvalidateParameters(); + events = m_eventBuilder.GetReadyEvents(); + for (auto& event : events) + { + for (auto& stage : m_physStack) + stage->AnalyzePhysicsEvent(event); + + //Now that the analysis stack has filled all our NavParameters with data, update the histogram counts + manager.UpdateHistograms(); + //Invalidate all parameters to get ready for next event + manager.InvalidateParameters(); + } } } }