mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Switched to single threaded application. Reduce complexity, until proven needed
This commit is contained in:
parent
66e1065394
commit
ccaae99472
|
@ -11,45 +11,33 @@ namespace Navigator {
|
||||||
Application* Application::s_instance = nullptr;
|
Application* Application::s_instance = nullptr;
|
||||||
|
|
||||||
Application::Application() :
|
Application::Application() :
|
||||||
m_runFlag(true), m_physThread(nullptr)
|
m_runFlag(true)
|
||||||
{
|
{
|
||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
|
||||||
m_window = std::unique_ptr<Window>(Window::Create());
|
m_window = std::unique_ptr<Window>(Window::Create());
|
||||||
m_window->SetEventCallback(BIND_EVENT_FUNCTION(Application::OnEvent));
|
m_window->SetEventCallback(BIND_EVENT_FUNCTION(Application::OnEvent));
|
||||||
|
|
||||||
PushLayer(new EditorLayer(&m_histMap));
|
m_physicsLayer = new PhysicsLayer();
|
||||||
|
PushLayer(m_physicsLayer);
|
||||||
m_histMap.AddHistogram("myHisto", "joseph", 100, 0, 10);
|
PushLayer(new EditorLayer());
|
||||||
m_histMap.AddHistogram("myHisto2D", "joseph", "joseph", 100, 0, 10, 100, 0, 10);
|
m_imgui_layer = new ImGuiLayer();
|
||||||
|
PushOverlay(m_imgui_layer);
|
||||||
|
HistogramMap& histMap = HistogramMap::GetInstance();
|
||||||
|
histMap.AddHistogram("myHisto", "joseph", 100, 0, 10);
|
||||||
|
histMap.AddHistogram("myHisto2D", "joseph", "joseph", 100, 0, 10, 100, 0, 10);
|
||||||
|
|
||||||
CutMap::GetInstance().AddCut("joe_cut","joseph",0.0, 7.0);
|
CutMap::GetInstance().AddCut("joe_cut","joseph",0.0, 7.0);
|
||||||
CutMap::GetInstance().AddCut("joe2D_cut", "joseph", "joseph", { 1.0, 3.0, 3.0, 1.0, 1.0}, { 1.0, 1.0, 3.0, 3.0, 1.0});
|
CutMap::GetInstance().AddCut("joe2D_cut", "joseph", "joseph", { 1.0, 3.0, 3.0, 1.0, 1.0}, { 1.0, 1.0, 3.0, 3.0, 1.0});
|
||||||
|
|
||||||
m_histMap.AddCutToHistogramDraw("joe_cut", "myHisto");
|
histMap.AddCutToHistogramDraw("joe_cut", "myHisto");
|
||||||
m_histMap.AddCutToHistogramDraw("joe2D_cut", "myHisto2D");
|
histMap.AddCutToHistogramDraw("joe2D_cut", "myHisto2D");
|
||||||
|
|
||||||
m_imgui_layer = new ImGuiLayer();
|
|
||||||
PushOverlay(m_imgui_layer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Application::~Application()
|
Application::~Application()
|
||||||
{
|
{
|
||||||
NAV_INFO("Detaching PhysicsEventBuilder at shutdown");
|
|
||||||
PhysicsEventBuilder::Get().DetachDataSource();
|
|
||||||
DestroyPhysThread();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::DestroyPhysThread()
|
|
||||||
{
|
|
||||||
if(m_physThread != nullptr && m_physThread->joinable())
|
|
||||||
m_physThread->join();
|
|
||||||
|
|
||||||
if(m_physThread != nullptr)
|
|
||||||
{
|
|
||||||
delete m_physThread;
|
|
||||||
m_physThread = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::SetParameterList()
|
void Application::SetParameterList()
|
||||||
|
@ -63,8 +51,6 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
EventDispatcher dispatch(event);
|
EventDispatcher dispatch(event);
|
||||||
dispatch.Dispatch<WindowCloseEvent>(BIND_EVENT_FUNCTION(Application::OnWindowCloseEvent));
|
dispatch.Dispatch<WindowCloseEvent>(BIND_EVENT_FUNCTION(Application::OnWindowCloseEvent));
|
||||||
dispatch.Dispatch<PhysicsStartEvent>(BIND_EVENT_FUNCTION(Application::OnPhysicsStartEvent));
|
|
||||||
dispatch.Dispatch<PhysicsStopEvent>(BIND_EVENT_FUNCTION(Application::OnPhysicsStopEvent));
|
|
||||||
for(auto iter = m_stack.end(); iter != m_stack.begin(); )
|
for(auto iter = m_stack.end(); iter != m_stack.begin(); )
|
||||||
{
|
{
|
||||||
(*(--iter))->OnEvent(event);
|
(*(--iter))->OnEvent(event);
|
||||||
|
@ -80,32 +66,6 @@ namespace Navigator {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::OnPhysicsStartEvent(PhysicsStartEvent& event)
|
|
||||||
{
|
|
||||||
if(PhysicsEventBuilder::Get().IsRunning())
|
|
||||||
{
|
|
||||||
PhysicsEventBuilder::Get().DetachDataSource();
|
|
||||||
NAV_INFO("Stopping the event builder...");
|
|
||||||
DestroyPhysThread();
|
|
||||||
}
|
|
||||||
PhysicsEventBuilder::Get().AttachDataSource(event.GetSourceLocation(), event.GetSourceType());
|
|
||||||
PhysicsEventBuilder::Get().SetCoincidenceWindow(event.GetCoincidenceWindow());
|
|
||||||
if(PhysicsEventBuilder::Get().IsRunning())
|
|
||||||
{
|
|
||||||
NAV_INFO("Starting the event builder...");
|
|
||||||
m_physThread = new std::thread(&PhysicsEventBuilder::Run, std::ref(PhysicsEventBuilder::Get()));
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Application::OnPhysicsStopEvent(PhysicsStopEvent& event)
|
|
||||||
{
|
|
||||||
PhysicsEventBuilder::Get().DetachDataSource();
|
|
||||||
NAV_INFO("Stopping the event builder...");
|
|
||||||
DestroyPhysThread();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::PushLayer(Layer* layer)
|
void Application::PushLayer(Layer* layer)
|
||||||
{
|
{
|
||||||
m_stack.PushLayer(layer);
|
m_stack.PushLayer(layer);
|
||||||
|
@ -122,7 +82,7 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
//PhysicsStartEvent junk("/media/gordon/GordonData/gwm17/NavTests/data/", DataSource::SourceType::CompassOffline, 2000000);
|
//PhysicsStartEvent junk("/media/gordon/GordonData/gwm17/NavTests/data/", DataSource::SourceType::CompassOffline, 2000000);
|
||||||
//OnEvent(junk);
|
//OnEvent(junk);
|
||||||
m_histMap.UpdateHistograms();
|
HistogramMap::GetInstance().UpdateHistograms();
|
||||||
while(m_runFlag)
|
while(m_runFlag)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,8 @@
|
||||||
#include "Navigator/Layer.h"
|
#include "Navigator/Layer.h"
|
||||||
#include "Navigator/Window.h"
|
#include "Navigator/Window.h"
|
||||||
#include "Navigator/ImGui/ImGuiLayer.h"
|
#include "Navigator/ImGui/ImGuiLayer.h"
|
||||||
#include "Navigator/Physics/PhysicsEventBuilder.h"
|
#include "Navigator/Physics/PhysicsLayer.h"
|
||||||
#include "Navigator/HistogramMap.h"
|
#include "Navigator/HistogramMap.h"
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
@ -25,31 +24,24 @@ namespace Navigator {
|
||||||
|
|
||||||
void OnEvent(Event& event);
|
void OnEvent(Event& event);
|
||||||
void PushLayer(Layer* layer);
|
void PushLayer(Layer* layer);
|
||||||
|
inline void PushAnalysisStage(AnalysisStage* stage) { m_physicsLayer->PushStage(stage); }
|
||||||
void PushOverlay(Layer* layer);
|
void PushOverlay(Layer* layer);
|
||||||
void SetParameterList();
|
void SetParameterList();
|
||||||
|
|
||||||
inline void AttachHistogramMap() { PhysicsEventBuilder::Get().AttachHistogramMap(&m_histMap); }
|
inline const std::vector<std::string>& GetParameterList() { return m_parameterList; }
|
||||||
inline const std::vector<std::string>& GetParameterList() { return m_parameterList; } //Thread-safe way to access a list of the available parameters (i.e. for the editor)
|
|
||||||
|
|
||||||
inline static Application& Get() { return *s_instance; }
|
inline static Application& Get() { return *s_instance; }
|
||||||
inline static void LinkHistogramMap() { s_instance->AttachHistogramMap(); } //IMPORTANT: Only use BEFORE calling Run(). NO guarantee of thread safety.
|
inline static void LinkParameterList() { s_instance->SetParameterList(); }
|
||||||
inline static void LinkParameterList() { s_instance->SetParameterList(); } //IMPORTANT: Only use BEFORE calling Run(). NO guarantee of thread safety.
|
|
||||||
|
|
||||||
inline Window& GetWindow() { return *m_window; }
|
inline Window& GetWindow() { return *m_window; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool OnWindowCloseEvent(WindowCloseEvent& event);
|
bool OnWindowCloseEvent(WindowCloseEvent& event);
|
||||||
bool OnPhysicsStartEvent(PhysicsStartEvent& event);
|
|
||||||
bool OnPhysicsStopEvent(PhysicsStopEvent& event);
|
|
||||||
|
|
||||||
void DestroyPhysThread();
|
|
||||||
|
|
||||||
std::thread* m_physThread;
|
|
||||||
|
|
||||||
LayerStack m_stack;
|
LayerStack m_stack;
|
||||||
HistogramMap m_histMap;
|
|
||||||
std::unique_ptr<Window> m_window;
|
std::unique_ptr<Window> m_window;
|
||||||
ImGuiLayer* m_imgui_layer;
|
ImGuiLayer* m_imgui_layer;
|
||||||
|
PhysicsLayer* m_physicsLayer;
|
||||||
std::vector<std::string> m_parameterList;
|
std::vector<std::string> m_parameterList;
|
||||||
bool m_runFlag;
|
bool m_runFlag;
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,6 @@ namespace Navigator {
|
||||||
|
|
||||||
void CutMap::DrawCut(const std::string& name)
|
void CutMap::DrawCut(const std::string& name)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_cutMutex);
|
|
||||||
auto iter = m_map.find(name);
|
auto iter = m_map.find(name);
|
||||||
if(iter != m_map.end())
|
if(iter != m_map.end())
|
||||||
iter->second->Draw();
|
iter->second->Draw();
|
||||||
|
@ -81,7 +80,6 @@ namespace Navigator {
|
||||||
|
|
||||||
bool CutMap::IsInsideCut(const std::string& name, double xval, double yval)
|
bool CutMap::IsInsideCut(const std::string& name, double xval, double yval)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_cutMutex);
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
auto iter = m_map.find(name);
|
auto iter = m_map.find(name);
|
||||||
if(iter != m_map.end())
|
if(iter != m_map.end())
|
||||||
|
@ -91,7 +89,6 @@ namespace Navigator {
|
||||||
|
|
||||||
std::vector<CutParams> CutMap::GetListOfCutParams()
|
std::vector<CutParams> CutMap::GetListOfCutParams()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_cutMutex);
|
|
||||||
std::vector<CutParams> list;
|
std::vector<CutParams> list;
|
||||||
list.reserve(m_map.size());
|
list.reserve(m_map.size());
|
||||||
for(auto& entry : m_map)
|
for(auto& entry : m_map)
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include "NavCore.h"
|
#include "NavCore.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
@ -82,12 +81,10 @@ namespace Navigator {
|
||||||
|
|
||||||
inline void AddCut(const std::string& name, const std::string& xpar, double min, double max)
|
inline void AddCut(const std::string& name, const std::string& xpar, double min, double max)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(m_cutMutex);
|
|
||||||
m_map[name].reset(new Cut1D(name, xpar, min, max));
|
m_map[name].reset(new Cut1D(name, xpar, min, max));
|
||||||
}
|
}
|
||||||
inline void AddCut(const std::string& name, const std::string& xpar, const std::string& ypar, const std::vector<double>& xpoints, const std::vector<double>& ypoints)
|
inline void AddCut(const std::string& name, const std::string& xpar, const std::string& ypar, const std::vector<double>& xpoints, const std::vector<double>& ypoints)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(m_cutMutex);
|
|
||||||
m_map[name].reset(new Cut2D(name, xpar, ypar, xpoints, ypoints));
|
m_map[name].reset(new Cut2D(name, xpar, ypar, xpoints, ypoints));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
EditorLayer::EditorLayer(HistogramMap* hmap) :
|
EditorLayer::EditorLayer() :
|
||||||
Layer("EditorLayer"), m_histMap(hmap), m_spectrumPanel(hmap)
|
Layer("EditorLayer"), m_spectrumPanel()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace Navigator {
|
||||||
|
|
||||||
void EditorLayer::UpdateHistogramLists()
|
void EditorLayer::UpdateHistogramLists()
|
||||||
{
|
{
|
||||||
m_histoList = m_histMap->GetListOfHistogramParams();
|
m_histoList = HistogramMap::GetInstance().GetListOfHistogramParams();
|
||||||
m_spectrumPanel.UpdateActiveList(m_histoList);
|
m_spectrumPanel.UpdateActiveList(m_histoList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace Navigator {
|
||||||
class EditorLayer : public Layer
|
class EditorLayer : public Layer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EditorLayer(HistogramMap* hmap);
|
EditorLayer();
|
||||||
~EditorLayer();
|
~EditorLayer();
|
||||||
|
|
||||||
virtual void OnAttach() override;
|
virtual void OnAttach() override;
|
||||||
|
@ -28,7 +28,6 @@ namespace Navigator {
|
||||||
void UpdateHistogramLists();
|
void UpdateHistogramLists();
|
||||||
void UpdateCutLists();
|
void UpdateCutLists();
|
||||||
bool OnPhysicsParamEvent(PhysicsParamEvent& event);
|
bool OnPhysicsParamEvent(PhysicsParamEvent& event);
|
||||||
HistogramMap* m_histMap; //Not owned by the EditorLayer!!
|
|
||||||
std::vector<HistogramParameters> m_histoList;
|
std::vector<HistogramParameters> m_histoList;
|
||||||
std::vector<CutParams> m_cutList;
|
std::vector<CutParams> m_cutList;
|
||||||
std::vector<std::string> m_paramList;
|
std::vector<std::string> m_paramList;
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
SpectrumPanel::SpectrumPanel(HistogramMap* map) :
|
SpectrumPanel::SpectrumPanel() :
|
||||||
m_histMap(map), m_zoomedFlag(false), m_zoomedGram(""), m_totalSlots(1)
|
m_zoomedFlag(false), m_zoomedGram(""), m_totalSlots(1)
|
||||||
{
|
{
|
||||||
m_tableSizes[0] = 1; m_tableSizes[1] = 1;
|
m_tableSizes[0] = 1; m_tableSizes[1] = 1;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ namespace Navigator {
|
||||||
|
|
||||||
void SpectrumPanel::OnImGuiRender()
|
void SpectrumPanel::OnImGuiRender()
|
||||||
{
|
{
|
||||||
|
HistogramMap& histMap = HistogramMap::GetInstance();
|
||||||
if (ImGui::Begin("Active View"))
|
if (ImGui::Begin("Active View"))
|
||||||
{
|
{
|
||||||
if (m_activeList.size() > 0)
|
if (m_activeList.size() > 0)
|
||||||
|
@ -21,7 +22,7 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
if (ImPlot::BeginPlot(m_zoomedGram.c_str(), ImVec2(-1, -1)))
|
if (ImPlot::BeginPlot(m_zoomedGram.c_str(), ImVec2(-1, -1)))
|
||||||
{
|
{
|
||||||
m_histMap->DrawHistogram(m_zoomedGram);
|
histMap.DrawHistogram(m_zoomedGram);
|
||||||
if (ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
if (ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||||
{
|
{
|
||||||
NAV_INFO("We lost 'em, de-zoom and enhance!");
|
NAV_INFO("We lost 'em, de-zoom and enhance!");
|
||||||
|
@ -67,7 +68,7 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
if (ImPlot::BeginPlot(spec.c_str()))
|
if (ImPlot::BeginPlot(spec.c_str()))
|
||||||
{
|
{
|
||||||
m_histMap->DrawHistogram(spec);
|
histMap.DrawHistogram(spec);
|
||||||
if (ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
if (ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||||
{
|
{
|
||||||
NAV_INFO("We got'em boys, they're in plot {0}. Zoom and enhance!", i);
|
NAV_INFO("We got'em boys, they're in plot {0}. Zoom and enhance!", i);
|
||||||
|
|
|
@ -9,17 +9,15 @@ namespace Navigator {
|
||||||
class NAV_API SpectrumPanel
|
class NAV_API SpectrumPanel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SpectrumPanel(HistogramMap* map);
|
SpectrumPanel();
|
||||||
~SpectrumPanel();
|
~SpectrumPanel();
|
||||||
|
|
||||||
inline void AttachHistogramMap(HistogramMap* map) { m_histMap = map; }
|
|
||||||
void OnImGuiRender();
|
void OnImGuiRender();
|
||||||
inline const std::string& GetZoomedOnHistogram() { return m_zoomedGram; }
|
inline const std::string& GetZoomedOnHistogram() { return m_zoomedGram; }
|
||||||
inline const bool IsZoomed() { return m_zoomedFlag; }
|
inline const bool IsZoomed() { return m_zoomedFlag; }
|
||||||
inline void UpdateActiveList(const std::vector<HistogramParameters>& list) { m_activeList = list; }
|
inline void UpdateActiveList(const std::vector<HistogramParameters>& list) { m_activeList = list; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HistogramMap* m_histMap; //Not owned by SpectrumPanel
|
|
||||||
std::vector<HistogramParameters> m_activeList; //This is where we get our info from. Reduces thread crossings
|
std::vector<HistogramParameters> m_activeList; //This is where we get our info from. Reduces thread crossings
|
||||||
std::vector<std::string> m_selectedGrams;
|
std::vector<std::string> m_selectedGrams;
|
||||||
bool m_zoomedFlag;
|
bool m_zoomedFlag;
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#include "ParameterMap.h"
|
#include "ParameterMap.h"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
|
HistogramMap* HistogramMap::s_instance = new HistogramMap();
|
||||||
|
|
||||||
HistogramMap::HistogramMap()
|
HistogramMap::HistogramMap()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -12,7 +15,6 @@ namespace Navigator {
|
||||||
|
|
||||||
void HistogramMap::AddCutToHistogramDraw(const std::string &cutname, const std::string &histoname)
|
void HistogramMap::AddCutToHistogramDraw(const std::string &cutname, const std::string &histoname)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_histMutex);
|
|
||||||
auto iter = m_map.find(histoname);
|
auto iter = m_map.find(histoname);
|
||||||
if(iter != m_map.end())
|
if(iter != m_map.end())
|
||||||
iter->second->AddCutToBeDrawn(cutname);
|
iter->second->AddCutToBeDrawn(cutname);
|
||||||
|
@ -20,7 +22,6 @@ namespace Navigator {
|
||||||
|
|
||||||
void HistogramMap::AddCutToHistogramApplied(const std::string &cutname, const std::string &histoname)
|
void HistogramMap::AddCutToHistogramApplied(const std::string &cutname, const std::string &histoname)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_histMutex);
|
|
||||||
auto iter = m_map.find(histoname);
|
auto iter = m_map.find(histoname);
|
||||||
if(iter != m_map.end())
|
if(iter != m_map.end())
|
||||||
iter->second->AddCutToBeApplied(cutname);
|
iter->second->AddCutToBeApplied(cutname);
|
||||||
|
@ -28,7 +29,6 @@ namespace Navigator {
|
||||||
|
|
||||||
void HistogramMap::UpdateHistograms()
|
void HistogramMap::UpdateHistograms()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(m_histMutex);
|
|
||||||
std::string xpar, ypar;
|
std::string xpar, ypar;
|
||||||
ParameterMap& pmap = ParameterMap::GetInstance();
|
ParameterMap& pmap = ParameterMap::GetInstance();
|
||||||
for (auto& pair : m_map)
|
for (auto& pair : m_map)
|
||||||
|
@ -68,7 +68,6 @@ namespace Navigator {
|
||||||
|
|
||||||
std::vector<HistogramParameters> HistogramMap::GetListOfHistogramParams()
|
std::vector<HistogramParameters> HistogramMap::GetListOfHistogramParams()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(m_histMutex);
|
|
||||||
std::vector<HistogramParameters> params;
|
std::vector<HistogramParameters> params;
|
||||||
params.reserve(m_map.size());
|
params.reserve(m_map.size());
|
||||||
for (auto& pair : m_map)
|
for (auto& pair : m_map)
|
||||||
|
@ -79,7 +78,6 @@ namespace Navigator {
|
||||||
//Only to be used within ImGui context!!
|
//Only to be used within ImGui context!!
|
||||||
void Navigator::HistogramMap::DrawHistograms()
|
void Navigator::HistogramMap::DrawHistograms()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(m_histMutex);
|
|
||||||
for (auto& pair : m_map)
|
for (auto& pair : m_map)
|
||||||
pair.second->Draw();
|
pair.second->Draw();
|
||||||
}
|
}
|
||||||
|
@ -87,7 +85,6 @@ namespace Navigator {
|
||||||
//Only to be used within ImGui context!!
|
//Only to be used within ImGui context!!
|
||||||
void Navigator::HistogramMap::DrawHistogram(const std::string& name)
|
void Navigator::HistogramMap::DrawHistogram(const std::string& name)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(m_histMutex);
|
|
||||||
auto iter = m_map.find(name);
|
auto iter = m_map.find(name);
|
||||||
if (iter != m_map.end())
|
if (iter != m_map.end())
|
||||||
iter->second->Draw();
|
iter->second->Draw();
|
||||||
|
|
|
@ -3,28 +3,22 @@
|
||||||
|
|
||||||
#include "NavCore.h"
|
#include "NavCore.h"
|
||||||
#include "Histogram.h"
|
#include "Histogram.h"
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
class NAV_API HistogramMap
|
class NAV_API HistogramMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using Iter = std::unordered_map<std::string, std::unique_ptr<Histogram>>::iterator;
|
|
||||||
|
|
||||||
HistogramMap();
|
HistogramMap();
|
||||||
~HistogramMap();
|
~HistogramMap();
|
||||||
|
|
||||||
inline void AddHistogram(const std::string& name, const std::string& param, int bins, double min, double max)
|
inline void AddHistogram(const std::string& name, const std::string& param, int bins, double min, double max)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(m_histMutex);
|
|
||||||
m_map[name].reset(new Histogram1D(name, param, bins, min, max));
|
m_map[name].reset(new Histogram1D(name, param, bins, min, max));
|
||||||
}
|
}
|
||||||
inline void AddHistogram(const std::string& name, const std::string& paramx, const std::string& paramy, int bins_x, double min_x, double max_x,
|
inline void AddHistogram(const std::string& name, const std::string& paramx, const std::string& paramy, int bins_x, double min_x, double max_x,
|
||||||
int bins_y, double min_y, double max_y)
|
int bins_y, double min_y, double max_y)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> guard(m_histMutex);
|
|
||||||
m_map[name].reset(new Histogram2D(name, paramx, paramy, bins_x, min_x, max_x, bins_y, min_y, max_y));
|
m_map[name].reset(new Histogram2D(name, paramx, paramy, bins_x, min_x, max_x, bins_y, min_y, max_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,13 +31,13 @@ namespace Navigator {
|
||||||
|
|
||||||
std::vector<HistogramParameters> GetListOfHistogramParams(); //thread safe access for GUI to the underlying parameters. Only needs to be called when a gram is added/removed
|
std::vector<HistogramParameters> GetListOfHistogramParams(); //thread safe access for GUI to the underlying parameters. Only needs to be called when a gram is added/removed
|
||||||
|
|
||||||
/*Not in general thread safe*/
|
static HistogramMap& GetInstance() { return *s_instance; }
|
||||||
inline Iter begin() { return m_map.begin(); }
|
|
||||||
inline Iter end() { return m_map.end(); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::unique_ptr<Histogram>> m_map;
|
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_map;
|
||||||
std::mutex m_histMutex;
|
|
||||||
|
static HistogramMap* s_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,17 +28,10 @@ namespace Navigator {
|
||||||
|
|
||||||
NavParameter::~NavParameter() {}
|
NavParameter::~NavParameter() {}
|
||||||
|
|
||||||
ParameterMap* ParameterMap::s_instance = nullptr;
|
ParameterMap* ParameterMap::s_instance = new ParameterMap();
|
||||||
|
|
||||||
ParameterMap* CreateParameterMap() { return new ParameterMap(); }
|
|
||||||
|
|
||||||
ParameterMap::ParameterMap()
|
ParameterMap::ParameterMap()
|
||||||
{
|
{
|
||||||
NAV_INFO("Created ParameterMap");
|
|
||||||
if(s_instance != nullptr)
|
|
||||||
NAV_ERROR("Cannot have multiple instances of ParameterMap!!!");
|
|
||||||
|
|
||||||
s_instance = this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ParameterMap::~ParameterMap() {}
|
ParameterMap::~ParameterMap() {}
|
||||||
|
|
|
@ -2,14 +2,13 @@
|
||||||
#define PARAMETER_MAP_H
|
#define PARAMETER_MAP_H
|
||||||
|
|
||||||
#include "NavCore.h"
|
#include "NavCore.h"
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
struct NAV_API ParameterData
|
struct NAV_API ParameterData
|
||||||
{
|
{
|
||||||
std::atomic<double> value=0.0;
|
double value=0.0;
|
||||||
std::atomic<bool> validFlag=false;
|
bool validFlag=false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -64,7 +63,6 @@ namespace Navigator {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
NAV_API ParameterMap* CreateParameterMap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,133 +0,0 @@
|
||||||
#include "PhysicsEventBuilder.h"
|
|
||||||
#include "Navigator/ParameterMap.h"
|
|
||||||
|
|
||||||
//temp
|
|
||||||
#include "CompassHit.h"
|
|
||||||
|
|
||||||
namespace Navigator {
|
|
||||||
|
|
||||||
PhysicsEventBuilder* PhysicsEventBuilder::s_instance = nullptr;
|
|
||||||
|
|
||||||
PhysicsEventBuilder::PhysicsEventBuilder() :
|
|
||||||
m_runFlag(false), m_source(nullptr), m_histMap(nullptr)
|
|
||||||
{
|
|
||||||
if(s_instance != nullptr)
|
|
||||||
{
|
|
||||||
NAV_ERROR("Trying to create a second PhysicsEventBuilder, this is not allowed!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
s_instance = this;
|
|
||||||
|
|
||||||
CreateParameterMap();
|
|
||||||
|
|
||||||
NavParameter par("joseph", "mama");
|
|
||||||
par.SetValue(8);
|
|
||||||
NAV_INFO("Does the par exist? {0}", ParameterMap::GetInstance().IsParameterValid("joseph"));
|
|
||||||
NAV_INFO("What is its value? {0}", ParameterMap::GetInstance().GetParameterValue("joseph"));
|
|
||||||
}
|
|
||||||
|
|
||||||
PhysicsEventBuilder::~PhysicsEventBuilder()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsEventBuilder::AttachDataSource(const std::string& loc, DataSource::SourceType type)
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(m_sourceLock); //Auto free lock at end of scope
|
|
||||||
NAV_INFO("Attempting to attach phyiscs data source at location {0}", loc);
|
|
||||||
|
|
||||||
m_runFlag = false;
|
|
||||||
|
|
||||||
m_source.reset(CreateDataSource(loc, type));
|
|
||||||
if(m_source->IsValid())
|
|
||||||
{
|
|
||||||
NAV_INFO("Attach successful. Enabling data pull...");
|
|
||||||
m_runFlag = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NAV_ERROR("DataSource attach failed... check for error conditions.");
|
|
||||||
m_source.reset(nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsEventBuilder::DetachDataSource()
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(m_sourceLock);
|
|
||||||
NAV_INFO("Detaching physics data source...");
|
|
||||||
m_runFlag = false;
|
|
||||||
m_source.reset(nullptr);
|
|
||||||
NAV_INFO("Detach successful");
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsEventBuilder::PushStage(AnalysisStage* stage)
|
|
||||||
{
|
|
||||||
m_physStack.PushStage(stage);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsEventBuilder::Run()
|
|
||||||
{
|
|
||||||
if(!m_runFlag)
|
|
||||||
{
|
|
||||||
NAV_WARN("Trying to Run PhysicsEventBuilder without a Data Source, killing thread!");
|
|
||||||
}
|
|
||||||
else if (m_histMap == nullptr || m_source == nullptr)
|
|
||||||
{
|
|
||||||
NAV_WARN("Internal state of PhysicsEventBuilder not set properly! Either histogram map or data source not initialized!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompassHit hit;
|
|
||||||
|
|
||||||
while(m_runFlag)
|
|
||||||
{
|
|
||||||
|
|
||||||
//small scope for locking access to the data source
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(m_sourceLock);
|
|
||||||
if(m_source == nullptr) // safety for stop occuring while running
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if(m_source->IsValid())
|
|
||||||
{
|
|
||||||
hit = m_source->GetData();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Looks funny, but two conditions lead to !IsValid(). Either source prev. shutdown,
|
|
||||||
OR we reached end of source, indicated after prev. data grab
|
|
||||||
*/
|
|
||||||
if(!m_source->IsValid())
|
|
||||||
{
|
|
||||||
NAV_INFO("End of data source.");
|
|
||||||
m_runFlag = false;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//NAV_INFO("Doing a physics");
|
|
||||||
if(m_rawSort.IsHitInWindow(hit))
|
|
||||||
{
|
|
||||||
//NAV_INFO("Adding hit to event with timestamp {0}", hit.timestamp);
|
|
||||||
m_rawSort.AddHit(hit);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//NAV_INFO("Obtaining built event...");
|
|
||||||
auto event = m_rawSort.GetRawPhysicsEvent();
|
|
||||||
//NAV_INFO("Built event size: {0}", event.size());
|
|
||||||
for (auto& stage : m_physStack)
|
|
||||||
stage->AnalyzeRawPhysicsEvent(event);
|
|
||||||
m_histMap->UpdateHistograms();
|
|
||||||
|
|
||||||
//Cleanup to be ready for next event
|
|
||||||
ParameterMap::GetInstance().InvalidateParameters();
|
|
||||||
m_rawSort.ClearRawPhysicsEvent();
|
|
||||||
//Need to add hit in hand, start new event
|
|
||||||
m_rawSort.AddHit(hit);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
#ifndef PHYSICS_EVENT_BUILDER_H
|
|
||||||
#define PHYSICS_EVENT_BUILDER_H
|
|
||||||
|
|
||||||
#include "Navigator/NavCore.h"
|
|
||||||
#include "Navigator/HistogramMap.h"
|
|
||||||
#include "AnalysisStack.h"
|
|
||||||
#include "AnalysisStage.h"
|
|
||||||
#include "PhysicsHitSort.h"
|
|
||||||
#include "DataSource.h"
|
|
||||||
#include <mutex>
|
|
||||||
#include <atomic>
|
|
||||||
|
|
||||||
namespace Navigator {
|
|
||||||
|
|
||||||
class NAV_API PhysicsEventBuilder
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PhysicsEventBuilder();
|
|
||||||
virtual ~PhysicsEventBuilder();
|
|
||||||
|
|
||||||
void Run();
|
|
||||||
|
|
||||||
void AttachDataSource(const std::string& loc, DataSource::SourceType type);
|
|
||||||
void DetachDataSource();
|
|
||||||
|
|
||||||
void SetCoincidenceWindow(uint64_t window) { m_rawSort.SetCoincidenceWindow(window); }
|
|
||||||
void PushStage(AnalysisStage* stage);
|
|
||||||
bool IsRunning() { return m_runFlag; }
|
|
||||||
inline void AttachHistogramMap(HistogramMap* map) { m_histMap = map; }
|
|
||||||
|
|
||||||
static PhysicsEventBuilder& Get() { return *s_instance; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
AnalysisStack m_physStack;
|
|
||||||
std::atomic<bool> m_runFlag; //ensures defined read/write across threads
|
|
||||||
static PhysicsEventBuilder* s_instance;
|
|
||||||
PhysicsHitSort m_rawSort;
|
|
||||||
|
|
||||||
std::mutex m_sourceLock;
|
|
||||||
|
|
||||||
std::unique_ptr<DataSource> m_source;
|
|
||||||
|
|
||||||
HistogramMap* m_histMap; //Not owned by PhysicsEventBuilder!
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
NAV_API PhysicsEventBuilder* CreatePhysicsEventBuilder();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
121
Navigator/src/Navigator/Physics/PhysicsLayer.cpp
Normal file
121
Navigator/src/Navigator/Physics/PhysicsLayer.cpp
Normal file
|
@ -0,0 +1,121 @@
|
||||||
|
#include "PhysicsLayer.h"
|
||||||
|
#include "Navigator/ParameterMap.h"
|
||||||
|
|
||||||
|
//temp
|
||||||
|
#include "CompassHit.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
PhysicsLayer::PhysicsLayer() :
|
||||||
|
m_activeFlag(false), m_source(nullptr)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PhysicsLayer::~PhysicsLayer()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsLayer::OnAttach()
|
||||||
|
{
|
||||||
|
NavParameter par("joseph", "mama");
|
||||||
|
par.SetValue(8);
|
||||||
|
NAV_INFO("Does the par exist? {0}", ParameterMap::GetInstance().IsParameterValid("joseph"));
|
||||||
|
NAV_INFO("What is its value? {0}", ParameterMap::GetInstance().GetParameterValue("joseph"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsLayer::OnDetach()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsLayer::OnEvent(Event& event)
|
||||||
|
{
|
||||||
|
EventDispatcher dispatch(event);
|
||||||
|
dispatch.Dispatch<PhysicsStartEvent>(BIND_EVENT_FUNCTION(PhysicsLayer::OnPhysicsStartEvent));
|
||||||
|
dispatch.Dispatch<PhysicsStopEvent>(BIND_EVENT_FUNCTION(PhysicsLayer::OnPhysicsStopEvent));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PhysicsLayer::OnPhysicsStartEvent(PhysicsStartEvent& event)
|
||||||
|
{
|
||||||
|
m_rawSort.SetCoincidenceWindow(event.GetCoincidenceWindow());
|
||||||
|
m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourceType()));
|
||||||
|
if (m_source->IsValid())
|
||||||
|
{
|
||||||
|
NAV_INFO("Attach successful. Enabling data pull...");
|
||||||
|
m_activeFlag = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NAV_ERROR("DataSource attach failed... check for error conditions.");
|
||||||
|
m_source.reset(nullptr);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PhysicsLayer::OnPhysicsStopEvent(PhysicsStopEvent& event)
|
||||||
|
{
|
||||||
|
NAV_INFO("Detaching physics data source...");
|
||||||
|
m_activeFlag = false;
|
||||||
|
m_source.reset(nullptr);
|
||||||
|
NAV_INFO("Detach succesful.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsLayer::PushStage(AnalysisStage* stage)
|
||||||
|
{
|
||||||
|
m_physStack.PushStage(stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PhysicsLayer::OnUpdate()
|
||||||
|
{
|
||||||
|
HistogramMap& histMap = HistogramMap::GetInstance();
|
||||||
|
|
||||||
|
if(!m_activeFlag)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (m_source == nullptr || !m_source->IsValid())
|
||||||
|
{
|
||||||
|
NAV_WARN("Internal state of PhysicsEventBuilder not set properly! Either histogram map or data source not initialized!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CompassHit hit;
|
||||||
|
hit = m_source->GetData();
|
||||||
|
|
||||||
|
/*
|
||||||
|
Looks funny, but two conditions lead to !IsValid(). Either source prev. shutdown,
|
||||||
|
OR we reached end of source, indicated after prev. data grab
|
||||||
|
*/
|
||||||
|
if(!m_source->IsValid())
|
||||||
|
{
|
||||||
|
NAV_INFO("End of data source.");
|
||||||
|
m_activeFlag = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//NAV_INFO("Doing a physics");
|
||||||
|
if(m_rawSort.IsHitInWindow(hit))
|
||||||
|
{
|
||||||
|
//NAV_INFO("Adding hit to event with timestamp {0}", hit.timestamp);
|
||||||
|
m_rawSort.AddHit(hit);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//NAV_INFO("Obtaining built event...");
|
||||||
|
auto event = m_rawSort.GetRawPhysicsEvent();
|
||||||
|
//NAV_INFO("Built event size: {0}", event.size());
|
||||||
|
for (auto& stage : m_physStack)
|
||||||
|
stage->AnalyzeRawPhysicsEvent(event);
|
||||||
|
histMap.UpdateHistograms();
|
||||||
|
|
||||||
|
//Cleanup to be ready for next event
|
||||||
|
ParameterMap::GetInstance().InvalidateParameters();
|
||||||
|
m_rawSort.ClearRawPhysicsEvent();
|
||||||
|
//Need to add hit in hand, start new event
|
||||||
|
m_rawSort.AddHit(hit);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
43
Navigator/src/Navigator/Physics/PhysicsLayer.h
Normal file
43
Navigator/src/Navigator/Physics/PhysicsLayer.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#ifndef PHYSICS_EVENT_BUILDER_H
|
||||||
|
#define PHYSICS_EVENT_BUILDER_H
|
||||||
|
|
||||||
|
#include "Navigator/NavCore.h"
|
||||||
|
#include "Navigator/HistogramMap.h"
|
||||||
|
#include "Navigator/Layer.h"
|
||||||
|
#include "Navigator/Events/PhysicsEvent.h"
|
||||||
|
#include "AnalysisStack.h"
|
||||||
|
#include "AnalysisStage.h"
|
||||||
|
#include "PhysicsHitSort.h"
|
||||||
|
#include "DataSource.h"
|
||||||
|
|
||||||
|
namespace Navigator {
|
||||||
|
|
||||||
|
class NAV_API PhysicsLayer : public Layer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PhysicsLayer();
|
||||||
|
virtual ~PhysicsLayer();
|
||||||
|
|
||||||
|
virtual void OnAttach() override;
|
||||||
|
virtual void OnUpdate() override;
|
||||||
|
virtual void OnDetach() override;
|
||||||
|
virtual void OnImGuiRender() override {};
|
||||||
|
virtual void OnEvent(Event& event) override;
|
||||||
|
|
||||||
|
bool OnPhysicsStartEvent(PhysicsStartEvent& event);
|
||||||
|
bool OnPhysicsStopEvent(PhysicsStopEvent& event);
|
||||||
|
|
||||||
|
void PushStage(AnalysisStage* stage);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AnalysisStack m_physStack;
|
||||||
|
bool m_activeFlag;
|
||||||
|
PhysicsHitSort m_rawSort;
|
||||||
|
|
||||||
|
std::unique_ptr<DataSource> m_source;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user