From e1b56dd1c3164c5dc243fcf43cf371bcde98fb0e Mon Sep 17 00:00:00 2001 From: Gordon McCann Date: Wed, 15 Jun 2022 00:21:57 -0400 Subject: [PATCH] Added in flexible board channel count to both online and offline CoMPASS sources. Started process of adding in scaler support (maybe graphs?) --- NavProject/src/SPSInputLayer.h | 2 +- Navigator/src/Navigator/Core/Parameter.cpp | 32 +++++++++++++++++++ Navigator/src/Navigator/Core/Parameter.h | 20 ++++++++++++ .../src/Navigator/Editor/SourceDialog.cpp | 7 ++-- Navigator/src/Navigator/Editor/SourceDialog.h | 1 + Navigator/src/Navigator/Events/PhysicsEvent.h | 18 +++++++---- .../Physics/Caen/CompassOnlineSource.cpp | 4 +-- .../Physics/Caen/CompassOnlineSource.h | 2 +- .../src/Navigator/Physics/Caen/CompassRun.cpp | 6 ++-- .../src/Navigator/Physics/Caen/CompassRun.h | 4 +-- .../src/Navigator/Physics/DataSource.cpp | 6 ++-- Navigator/src/Navigator/Physics/DataSource.h | 2 +- .../src/Navigator/Physics/PhysicsLayer.cpp | 2 +- .../src/Platform/OpenGL/OpenGLContext.cpp | 1 + .../src/Platform/OpenGL/OpenGLWindow.cpp | 1 + 15 files changed, 85 insertions(+), 23 deletions(-) diff --git a/NavProject/src/SPSInputLayer.h b/NavProject/src/SPSInputLayer.h index 0af7490..032598d 100644 --- a/NavProject/src/SPSInputLayer.h +++ b/NavProject/src/SPSInputLayer.h @@ -3,7 +3,7 @@ An example of what a user created layer might look like. This is how one would extend the base editor to have more functionality, specific to their experiment/setup. In this case, we provide inputs for reaction information so that the kinematic shift of the SE-SPS focal plane can be calculated, and weights for tracing particle trajectories are - produced for use in analysis (as NavVariables). + produced for use in analysis (as Variables). A reminder that these layers should not be that intense. The more work that is shoved into the UI, the less responsive and more sluggish overall the UI will become. The vast bulk of the analysis work should be left to the PhysicsLayer which has its own diff --git a/Navigator/src/Navigator/Core/Parameter.cpp b/Navigator/src/Navigator/Core/Parameter.cpp index 30ff737..949bbc7 100644 --- a/Navigator/src/Navigator/Core/Parameter.cpp +++ b/Navigator/src/Navigator/Core/Parameter.cpp @@ -61,4 +61,36 @@ namespace Navigator { } Variable::~Variable() {} + + void Variable::SetName(const std::string& name) + { + if (m_name != "") + { + NAV_ERROR("Attempting to change the name of an already bound Variable! Set name: {0} New name: {1}", m_name, name); + return; + } + m_name = name; + } + + Scaler::Scaler() : + m_pdata(nullptr), m_name("") + { + } + + Scaler::Scaler(const std::string& name) : + m_pdata(nullptr), m_name(name) + { + } + + Scaler::~Scaler() {} + + void Scaler::SetName(const std::string& name) + { + if (m_name != "") + { + NAV_ERROR("Attempting to change the name of an already bound Scaler! Set name: {0} New name: {1}", m_name, name); + return; + } + m_name = name; + } } diff --git a/Navigator/src/Navigator/Core/Parameter.h b/Navigator/src/Navigator/Core/Parameter.h index 0c0174a..e314232 100644 --- a/Navigator/src/Navigator/Core/Parameter.h +++ b/Navigator/src/Navigator/Core/Parameter.h @@ -74,6 +74,7 @@ namespace Navigator { inline void SetValue(double value) { *(m_pdata) = value; } inline double GetValue() { return *(m_pdata); } inline const std::string& GetName() { return m_name; } + void SetName(const std::string& name); friend class SpectrumManager; private: @@ -81,6 +82,25 @@ namespace Navigator { std::string m_name; }; + class Scaler + { + public: + Scaler(); + Scaler(const std::string& name); + ~Scaler(); + + inline void Increment() { ++(*m_pdata); } + + inline const std::string& GetName() { return m_name; } + inline uint64_t GetCounts() { return *m_pdata; } + void SetName(const std::string& name); + + friend class SpectrumManager; + private: + std::shared_ptr> m_pdata; + std::string m_name; + }; + } #endif diff --git a/Navigator/src/Navigator/Editor/SourceDialog.cpp b/Navigator/src/Navigator/Editor/SourceDialog.cpp index f849ba8..b29db93 100644 --- a/Navigator/src/Navigator/Editor/SourceDialog.cpp +++ b/Navigator/src/Navigator/Editor/SourceDialog.cpp @@ -43,6 +43,7 @@ namespace Navigator { m_chosenPort = "51489"; m_chosenWindow = 3000000; m_bitflags = 0; + m_channels_per_board = 16; ImGui::OpenPopup(ICON_FA_LINK " Attach Source"); } if (ImGui::BeginPopupModal(ICON_FA_LINK " Attach Source")) @@ -77,6 +78,7 @@ namespace Navigator { { m_bitflags = m_bitflags ^ CompassHeaders::EnergyCalibrated; } + ImGui::InputInt("Channels Per Digitizer Board", &m_channels_per_board); } else if (m_chosenType == DataSource::SourceType::CompassOffline) { @@ -88,6 +90,7 @@ namespace Navigator { auto temp = m_fileDialog.RenderFileDialog(); if (!temp.first.empty() && temp.second == FileDialog::Type::OpenDir) m_chosenLocation = temp.first; + ImGui::InputInt("Channels Per Digitizer Board", &m_channels_per_board); } ImGui::InputInt("Coinc. Window (ps)", &m_chosenWindow); @@ -96,12 +99,12 @@ namespace Navigator { { if (m_chosenType == DataSource::SourceType::CompassOffline) { - PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort); + PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort, false, 0U, m_channels_per_board); Application::Get().OnEvent(event); } else if (m_chosenType == DataSource::SourceType::CompassOnline) { - PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort, true, m_bitflags); + PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort, true, m_bitflags, m_channels_per_board); Application::Get().OnEvent(event); } ImGui::CloseCurrentPopup(); diff --git a/Navigator/src/Navigator/Editor/SourceDialog.h b/Navigator/src/Navigator/Editor/SourceDialog.h index 26c0da4..c79e06c 100644 --- a/Navigator/src/Navigator/Editor/SourceDialog.h +++ b/Navigator/src/Navigator/Editor/SourceDialog.h @@ -30,6 +30,7 @@ namespace Navigator { FileDialog m_fileDialog; uint16_t m_bitflags; int m_chosenWindow; + int m_channels_per_board; }; } diff --git a/Navigator/src/Navigator/Events/PhysicsEvent.h b/Navigator/src/Navigator/Events/PhysicsEvent.h index 5128243..7beca9e 100644 --- a/Navigator/src/Navigator/Events/PhysicsEvent.h +++ b/Navigator/src/Navigator/Events/PhysicsEvent.h @@ -21,15 +21,18 @@ namespace Navigator { { public: //Bitflags is a final option for random crap needed for a source. Currently used for compass online to indicate header state. - PhysicsStartEvent(const std::string& loc, DataSource::SourceType type, uint64_t window, const std::string& port = "51489", bool sortFlag=false, uint16_t bitflags = 0) : - m_sourceLocation(loc), m_port(port), m_sourceType(type), m_coincidenceWindow(window), m_sortFlag(sortFlag), m_bitflags(bitflags) + PhysicsStartEvent(const std::string& loc, DataSource::SourceType type, uint64_t window, const std::string& port = "51489", bool sortFlag=false, uint16_t bitflags = 0, + int channels_per_board=16) : + m_sourceLocation(loc), m_port(port), m_sourceType(type), m_coincidenceWindow(window), m_sortFlag(sortFlag), m_bitflags(bitflags), m_channels_per_board(channels_per_board) {} - 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; } + inline const std::string GetSourceLocation() const { return m_sourceLocation; } + inline const std::string GetSourcePort() const { return m_port; } + inline const DataSource::SourceType GetSourceType() const { return m_sourceType; } + inline const uint64_t GetCoincidenceWindow() const { return m_coincidenceWindow; } + inline const bool GetSortFlag() const { return m_sortFlag; } + inline const int GetChannelsPerBoard() const { return m_channels_per_board; } + inline const uint16_t GetBitFlags() const { return m_bitflags; } std::string ToString() const override { @@ -46,6 +49,7 @@ namespace Navigator { uint64_t m_coincidenceWindow; bool m_sortFlag; uint16_t m_bitflags; + int m_channels_per_board; }; class NAV_API PhysicsStopEvent : public Event diff --git a/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.cpp b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.cpp index c28bf78..89167fb 100644 --- a/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.cpp +++ b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.cpp @@ -25,8 +25,8 @@ namespace Navigator { - CompassOnlineSource::CompassOnlineSource(const std::string& hostname, const std::string& port, uint16_t header) : - DataSource(), m_bufferIter(nullptr), m_bufferEnd(nullptr), m_header(header) + CompassOnlineSource::CompassOnlineSource(const std::string& hostname, const std::string& port, uint16_t header, int channels_per_board) : + DataSource(), m_bufferIter(nullptr), m_bufferEnd(nullptr), m_header(header), m_nchannels_per_board(channels_per_board) { InitConnection(hostname, port); } diff --git a/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h index 0d0e82a..a549f44 100644 --- a/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h +++ b/Navigator/src/Navigator/Physics/Caen/CompassOnlineSource.h @@ -39,7 +39,7 @@ namespace Navigator { class CompassOnlineSource : public DataSource { public: - CompassOnlineSource(const std::string& hostname, const std::string& port, uint16_t header); + CompassOnlineSource(const std::string& hostname, const std::string& port, uint16_t header, int channels_per_board=16); virtual ~CompassOnlineSource() override; virtual const NavData& GetData() override; diff --git a/Navigator/src/Navigator/Physics/Caen/CompassRun.cpp b/Navigator/src/Navigator/Physics/Caen/CompassRun.cpp index b287f37..67659ec 100644 --- a/Navigator/src/Navigator/Physics/Caen/CompassRun.cpp +++ b/Navigator/src/Navigator/Physics/Caen/CompassRun.cpp @@ -23,12 +23,12 @@ namespace Navigator { CompassRun::CompassRun() : - DataSource(), m_directory(""), m_startIndex(0) + DataSource(), m_directory(""), m_startIndex(0), m_nchannels_per_board(16) { } - CompassRun::CompassRun(const std::string& dir) : - DataSource(), m_directory(dir), m_startIndex(0) + CompassRun::CompassRun(const std::string& dir, int channels_per_board) : + DataSource(), m_directory(dir), m_startIndex(0), m_nchannels_per_board(channels_per_board) { CollectFiles(); } diff --git a/Navigator/src/Navigator/Physics/Caen/CompassRun.h b/Navigator/src/Navigator/Physics/Caen/CompassRun.h index 16ff417..61af679 100644 --- a/Navigator/src/Navigator/Physics/Caen/CompassRun.h +++ b/Navigator/src/Navigator/Physics/Caen/CompassRun.h @@ -36,7 +36,7 @@ namespace Navigator { public: CompassRun(); - CompassRun(const std::string& dir); + CompassRun(const std::string& dir, int channels_per_board=16); virtual ~CompassRun(); virtual const NavData& GetData() override; inline void SetDirectory(const std::string& dir) { m_directory = dir; CollectFiles(); } @@ -52,7 +52,7 @@ namespace Navigator { std::vector m_datafiles; unsigned int m_startIndex; //this is the file we start looking at; increases as we finish files. - 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 + int m_nchannels_per_board; //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. ShiftMap m_smap; diff --git a/Navigator/src/Navigator/Physics/DataSource.cpp b/Navigator/src/Navigator/Physics/DataSource.cpp index 77bd288..3e205f1 100644 --- a/Navigator/src/Navigator/Physics/DataSource.cpp +++ b/Navigator/src/Navigator/Physics/DataSource.cpp @@ -13,12 +13,12 @@ namespace Navigator { //loc=either an ip address or a file location, port=address port, or unused in case of file - DataSource* CreateDataSource(const std::string& loc, const std::string& port, DataSource::SourceType type, uint16_t bitflags) + DataSource* CreateDataSource(const std::string& location, const std::string& port, uint16_t header, int channels_per_board, DataSource::SourceType type) { switch(type) { - case DataSource::SourceType::CompassOffline : return new CompassRun(loc); - case DataSource::SourceType::CompassOnline : return new CompassOnlineSource(loc, port, bitflags); + case DataSource::SourceType::CompassOffline : return new CompassRun(location, channels_per_board); + case DataSource::SourceType::CompassOnline : return new CompassOnlineSource(location, port, header, channels_per_board); case DataSource::SourceType::None : return nullptr; } NAV_WARN("Invalid DataSourceType at CreateDataSource!"); diff --git a/Navigator/src/Navigator/Physics/DataSource.h b/Navigator/src/Navigator/Physics/DataSource.h index 1a9c213..3016c10 100644 --- a/Navigator/src/Navigator/Physics/DataSource.h +++ b/Navigator/src/Navigator/Physics/DataSource.h @@ -38,7 +38,7 @@ namespace Navigator { NavData m_datum; }; - NAV_API DataSource* CreateDataSource(const std::string& loc, const std::string& port, DataSource::SourceType type, uint16_t bitflags = 0); + NAV_API DataSource* CreateDataSource(const std::string& location, const std::string& port, uint16_t bitflags, int channels_per_board, DataSource::SourceType type); NAV_API std::string ConvertDataSourceTypeToString(DataSource::SourceType type); } diff --git a/Navigator/src/Navigator/Physics/PhysicsLayer.cpp b/Navigator/src/Navigator/Physics/PhysicsLayer.cpp index 2544e68..6f88d61 100644 --- a/Navigator/src/Navigator/Physics/PhysicsLayer.cpp +++ b/Navigator/src/Navigator/Physics/PhysicsLayer.cpp @@ -114,7 +114,7 @@ namespace Navigator { { NAV_PROFILE_FUNCTION(); 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_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetBitFlags(), event.GetChannelsPerBoard(), event.GetSourceType())); m_eventBuilder.SetCoincidenceWindow(event.GetCoincidenceWindow()); m_eventBuilder.SetSortFlag(event.GetSortFlag()); m_eventBuilder.ClearAll(); //Protect against stopping mid-event diff --git a/Navigator/src/Platform/OpenGL/OpenGLContext.cpp b/Navigator/src/Platform/OpenGL/OpenGLContext.cpp index bc887de..2fa7451 100644 --- a/Navigator/src/Platform/OpenGL/OpenGLContext.cpp +++ b/Navigator/src/Platform/OpenGL/OpenGLContext.cpp @@ -20,6 +20,7 @@ namespace Navigator { void OpenGLContext::Init() { + NAV_PROFILE_FUNCTION(); glfwMakeContextCurrent(m_windowHandle); int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); diff --git a/Navigator/src/Platform/OpenGL/OpenGLWindow.cpp b/Navigator/src/Platform/OpenGL/OpenGLWindow.cpp index 6c49854..fa06fc9 100644 --- a/Navigator/src/Platform/OpenGL/OpenGLWindow.cpp +++ b/Navigator/src/Platform/OpenGL/OpenGLWindow.cpp @@ -35,6 +35,7 @@ namespace Navigator { void OpenGLWindow::Init(const WindowProperties& props) { + NAV_PROFILE_FUNCTION(); m_data.width = props.width; m_data.height = props.height; m_data.name = props.name;