diff --git a/SpecProject/src/SPSAnalysisStage.cpp b/SpecProject/src/SPSAnalysisStage.cpp index 80cf0d7..ec68a96 100644 --- a/SpecProject/src/SPSAnalysisStage.cpp +++ b/SpecProject/src/SPSAnalysisStage.cpp @@ -9,43 +9,42 @@ namespace Specter { //Construct each NavParameter with their unique name. Then bind them to the SpectrumManager. - SPSAnalysisStage::SPSAnalysisStage() : + SPSAnalysisStage::SPSAnalysisStage(const SpectrumManager::Ref& manager) : AnalysisStage("SPSAnalysis"), delayFLTime("delayFLTime"), delayFRTime("delayFRTime"), delayBLTime("delayBLTime"), delayBRTime("delayBRTime"), x1("x1"), x2("x2"), xavg("xavg"), scintLeft("scintLeft"), anodeBack("anodeBack"), anodeFront("anodeFront"), cathode("cathode"), xavg_sabreCoinc("xavg_sabreCoinc"), x1_weight("x1_weight"), x2_weight("x2_weight"), beamIntegrator("beamIntegrator") { SPEC_PROFILE_FUNCTION(); - SpectrumManager& manager = SpectrumManager::GetInstance(); - manager.BindParameter(delayFLTime); - manager.BindParameter(delayFRTime); - manager.BindParameter(delayBLTime); - manager.BindParameter(delayBRTime); + manager->BindParameter(delayFLTime); + manager->BindParameter(delayFRTime); + manager->BindParameter(delayBLTime); + manager->BindParameter(delayBRTime); //Bind parameters with some default histograms. Saves us the effort of making them in the UI. - manager.BindParameter(x1, 600, -300.0, 300.0); - manager.BindParameter(x2, 600, -300.0, 300.0); - manager.BindParameter(xavg, 600, -300.0, 300.0); - manager.BindParameter(scintLeft, 4096, 0.0, 4096.0); - manager.BindParameter(anodeBack, 4096, 0.0, 4096.0); - manager.BindParameter(anodeFront, 4096, 0.0, 4096.0); - manager.BindParameter(cathode, 4096, 0.0, 4096); - manager.BindParameter(xavg_sabreCoinc, 600, -300.0, 300.0); + manager->BindParameter(x1, 600, -300.0, 300.0); + manager->BindParameter(x2, 600, -300.0, 300.0); + manager->BindParameter(xavg, 600, -300.0, 300.0); + manager->BindParameter(scintLeft, 4096, 0.0, 4096.0); + manager->BindParameter(anodeBack, 4096, 0.0, 4096.0); + manager->BindParameter(anodeFront, 4096, 0.0, 4096.0); + manager->BindParameter(cathode, 4096, 0.0, 4096); + manager->BindParameter(xavg_sabreCoinc, 600, -300.0, 300.0); std::vector sabre_list; for (int i = 0; i < 127; i++) { sabre_list.push_back("sabre_" + std::to_string(i)); sabre.emplace_back(sabre_list[i]); - manager.BindParameter(sabre[i]); + manager->BindParameter(sabre[i]); } //If you want to make a histogram default available, you can add one like this. - manager.AddHistogramSummary(HistogramArgs("sabre_summary", "", 512, 0.0, 16384), sabre_list); + manager->AddHistogramSummary(HistogramArgs("sabre_summary", "", 512, 0.0, 16384), sabre_list); //Note that if you save a config, the config rep of this histogram will supercede this version. - manager.BindVariable(x1_weight); - manager.BindVariable(x2_weight); + manager->BindVariable(x1_weight); + manager->BindVariable(x2_weight); - manager.BindScaler(beamIntegrator); + manager->BindScaler(beamIntegrator); } SPSAnalysisStage::~SPSAnalysisStage() {} diff --git a/SpecProject/src/SPSAnalysisStage.h b/SpecProject/src/SPSAnalysisStage.h index 4b7fd88..fe3ceab 100644 --- a/SpecProject/src/SPSAnalysisStage.h +++ b/SpecProject/src/SPSAnalysisStage.h @@ -11,7 +11,7 @@ namespace Specter { class SPSAnalysisStage : public AnalysisStage { public: - SPSAnalysisStage(); + SPSAnalysisStage(const SpectrumManager::Ref& manager); virtual ~SPSAnalysisStage(); virtual void AnalyzePhysicsEvent(const SpecEvent& event) override; diff --git a/SpecProject/src/SPSInputLayer.cpp b/SpecProject/src/SPSInputLayer.cpp index df38ced..9bc1242 100644 --- a/SpecProject/src/SPSInputLayer.cpp +++ b/SpecProject/src/SPSInputLayer.cpp @@ -16,7 +16,7 @@ namespace Specter { - SPSInputLayer::SPSInputLayer() : + SPSInputLayer::SPSInputLayer(const SpectrumManager::Ref& manager) : Layer("SPSInputLayer"), x1_weight("x1_weight"), x2_weight("x2_weight"), m_bfield(0.0), m_theta(0.0), m_beamKE(0.0), m_rxnEqn("") { @@ -28,9 +28,8 @@ namespace Specter { m_residNums[i] = 0; } - SpectrumManager& manager = SpectrumManager::GetInstance(); - manager.BindVariable(x1_weight); - manager.BindVariable(x2_weight); + manager->BindVariable(x1_weight); + manager->BindVariable(x2_weight); } SPSInputLayer::~SPSInputLayer() {} diff --git a/SpecProject/src/SPSInputLayer.h b/SpecProject/src/SPSInputLayer.h index 16ae851..8e67e22 100644 --- a/SpecProject/src/SPSInputLayer.h +++ b/SpecProject/src/SPSInputLayer.h @@ -22,7 +22,7 @@ namespace Specter { class SPSInputLayer : public Layer { public: - SPSInputLayer(); + SPSInputLayer(const SpectrumManager::Ref& manager); ~SPSInputLayer(); virtual void OnAttach() override; diff --git a/SpecProject/src/main.cpp b/SpecProject/src/main.cpp index dfd9000..f232c2b 100644 --- a/SpecProject/src/main.cpp +++ b/SpecProject/src/main.cpp @@ -16,9 +16,9 @@ public: SPSApp(const Specter::ApplicationArgs& args) : Specter::Application(args) { - PushLayer(new Specter::SPSInputLayer()); + PushLayer(new Specter::SPSInputLayer(m_manager)); //PushLayer(new Navigator::TestServerLayer()); - PushAnalysisStage(new Specter::SPSAnalysisStage()); + PushAnalysisStage(new Specter::SPSAnalysisStage(m_manager)); } }; diff --git a/Specter/src/Specter/Core/Application.cpp b/Specter/src/Specter/Core/Application.cpp index f58d8de..144d41c 100644 --- a/Specter/src/Specter/Core/Application.cpp +++ b/Specter/src/Specter/Core/Application.cpp @@ -34,9 +34,12 @@ namespace Specter { m_window = std::unique_ptr(Window::Create({m_args.name, 1280, 720})); m_window->SetEventCallback(BIND_EVENT_FUNCTION(Application::OnEvent)); //Allow window to pass events back - m_physicsLayer = new PhysicsLayer(); + //Create the manager + m_manager = std::make_shared(); + + m_physicsLayer = new PhysicsLayer(m_manager); PushLayer(m_physicsLayer); - EditorLayer* editor = new EditorLayer(); //memory handled by layer stack + EditorLayer* editor = new EditorLayer(m_manager); //memory handled by layer stack editor->SetEventCallbackFunc(BIND_EVENT_FUNCTION(Application::OnEvent)); //Allow editor to pass events back PushLayer(editor); m_imgui_layer = new ImGuiLayer(); diff --git a/Specter/src/Specter/Core/Application.h b/Specter/src/Specter/Core/Application.h index 540b485..86e43f1 100644 --- a/Specter/src/Specter/Core/Application.h +++ b/Specter/src/Specter/Core/Application.h @@ -20,6 +20,7 @@ #include "Specter/Core/Window.h" #include "Specter/ImGui/ImGuiLayer.h" #include "Specter/Physics/PhysicsLayer.h" +#include "SpectrumManager.h" #include "glm/vec4.hpp" namespace Specter { @@ -44,6 +45,7 @@ namespace Specter { inline void PushAnalysisStage(AnalysisStage* stage) { m_physicsLayer->PushStage(stage); } void PushOverlay(Layer* layer); + inline static Application& Get() { return *s_instance; } inline Window& GetWindow() { return *m_window; } @@ -52,6 +54,7 @@ namespace Specter { private: bool OnWindowCloseEvent(WindowCloseEvent& event); + bool OnManagerBindEvent(const std::shared_ptr& manager); ApplicationArgs m_args; @@ -65,6 +68,9 @@ namespace Specter { glm::vec4 m_bckgnd_color = {0.1f, 0.1f, 0.1f, 1.0f}; static Application* s_instance; + + protected: + SpectrumManager::Ref m_manager; //manager needs to be available to derived classes }; diff --git a/Specter/src/Specter/Core/SpectrumManager.cpp b/Specter/src/Specter/Core/SpectrumManager.cpp index 1c5a86f..4eaf79f 100644 --- a/Specter/src/Specter/Core/SpectrumManager.cpp +++ b/Specter/src/Specter/Core/SpectrumManager.cpp @@ -14,8 +14,6 @@ namespace Specter { - SpectrumManager* SpectrumManager::s_instance = new SpectrumManager(); - SpectrumManager::SpectrumManager() { } diff --git a/Specter/src/Specter/Core/SpectrumManager.h b/Specter/src/Specter/Core/SpectrumManager.h index 2334007..7c8eecd 100644 --- a/Specter/src/Specter/Core/SpectrumManager.h +++ b/Specter/src/Specter/Core/SpectrumManager.h @@ -1,12 +1,16 @@ /* SpectrumManager.h - SpectrumManager is the global resource management class. Controls everything related to spectra (histograms, cuts, parameters). Since + SpectrumManager is the application resource management class. Controls everything related to spectra (histograms, cuts, parameters). Since the manager must traverse threads, explicit synchronoization is handled through a mutex. To this end, excessive calls to the manager should be avoided if possible, as this will increase the lock deadtime in the application, which is especially bad for online data sources. Note that SpectrumManager is a singleton. There should only ever be one SpectrumManager with a given application. GWM -- Feb 2022 + + Modified to be non-singleton. Singleton implementation was going to hold us back from some future development. + + GWM -- July 2022 */ #ifndef SPECTRUM_MANAGER_H #define SPECTRUM_MANAGER_H @@ -26,11 +30,11 @@ namespace Specter { class SpectrumManager { public: + using Ref = std::shared_ptr; + SpectrumManager(); ~SpectrumManager(); - inline static SpectrumManager& GetInstance() { return *s_instance; } - //To clear all managed spectra. Note that Parameters are left untouched. inline void RemoveAllSpectra() { @@ -105,8 +109,6 @@ namespace Specter { bool IsCutValid(const std::string& name); void ResetCutValidities(); - static SpectrumManager* s_instance; - //Actual data std::unordered_map> m_histoMap; std::unordered_map> m_cutMap; diff --git a/Specter/src/Specter/Core/SpectrumSerializer.cpp b/Specter/src/Specter/Core/SpectrumSerializer.cpp index 7ffbe4f..b4b0830 100644 --- a/Specter/src/Specter/Core/SpectrumSerializer.cpp +++ b/Specter/src/Specter/Core/SpectrumSerializer.cpp @@ -12,16 +12,14 @@ GWM -- Feb 2022 */ #include "SpectrumSerializer.h" -#include "SpectrumManager.h" #include #include "yaml-cpp/yaml.h" namespace Specter { - static void SerializeCut(YAML::Emitter& output, const CutArgs& args) + static void SerializeCut(YAML::Emitter& output, const std::shared_ptr& manager, const CutArgs& args) { - SpectrumManager& manager = SpectrumManager::GetInstance(); output << YAML::BeginMap; output << YAML::Key << "Cut" << YAML::Value << args.name; output << YAML::Key << "Type" << YAML::Value << ConvertCutTypeToString(args.type); @@ -29,21 +27,21 @@ namespace Specter { output << YAML::Key << "YParameter" << YAML::Value << args.y_par; if (args.type == CutType::Cut1D) { - std::vector xpoints = manager.GetCutXPoints(args.name); + std::vector xpoints = manager->GetCutXPoints(args.name); output << YAML::Key << "XMin" << YAML::Value << xpoints[0]; output << YAML::Key << "XMax" << YAML::Value << xpoints[1]; } else if (args.type == CutType::Cut2D) { - std::vector xpoints = manager.GetCutXPoints(args.name); - std::vector ypoints = manager.GetCutYPoints(args.name); + std::vector xpoints = manager->GetCutXPoints(args.name); + std::vector ypoints = manager->GetCutYPoints(args.name); output << YAML::Key << "XPoints" << YAML::Value << xpoints; output << YAML::Key << "YPoints" << YAML::Value << ypoints; } else if (args.type == CutType::CutSummaryAll || args.type == CutType::CutSummaryAny) { - std::vector subhistos = manager.GetCutSubHistograms(args.name); - std::vector xpoints = manager.GetCutXPoints(args.name); + std::vector subhistos = manager->GetCutSubHistograms(args.name); + std::vector xpoints = manager->GetCutXPoints(args.name); output << YAML::Key << "XMin" << YAML::Value << xpoints[0]; output << YAML::Key << "XMax" << YAML::Value << xpoints[1]; output << YAML::Key << "SubHistos" << YAML::Value << subhistos; @@ -51,7 +49,7 @@ namespace Specter { output << YAML::EndMap; } - static void SerializeHistogram(YAML::Emitter& output, const HistogramArgs& args) + static void SerializeHistogram(YAML::Emitter& output, const std::shared_ptr& manager, const HistogramArgs& args) { output << YAML::BeginMap; output << YAML::Key << "Histogram" << YAML::Value << args.name; @@ -66,7 +64,7 @@ namespace Specter { output << YAML::Key << "YBins" << YAML::Value << args.nbins_y; if (args.type == SpectrumType::Summary) { - std::vector subhistos = SpectrumManager::GetInstance().GetSubHistograms(args.name); + std::vector subhistos = manager->GetSubHistograms(args.name); output << YAML::Key << "SubHistos" << YAML::Value << subhistos; } output << YAML::Key << "CutsDrawn" << YAML::Value << args.cutsDrawnUpon; @@ -82,7 +80,7 @@ namespace Specter { SpectrumSerializer::~SpectrumSerializer() {} - void SpectrumSerializer::SerializeData(const std::vector& histoList, const std::vector& cutList) + void SpectrumSerializer::SerializeData(const SpectrumManager::Ref& manager, const std::vector& histoList, const std::vector& cutList) { std::ofstream output(m_filename); if (!output.is_open()) @@ -96,13 +94,13 @@ namespace Specter { yamlStream << YAML::Key << "Cuts" << YAML::Value << YAML::BeginSeq; for (auto& cut : cutList) { - SerializeCut(yamlStream, cut); + SerializeCut(yamlStream, manager, cut); } yamlStream << YAML::EndSeq; yamlStream << YAML::Key << "Histograms" << YAML::Value << YAML::BeginSeq; for (auto& histo : histoList) { - SerializeHistogram(yamlStream, histo); + SerializeHistogram(yamlStream, manager, histo); } yamlStream << YAML::EndSeq << YAML::EndMap; @@ -111,10 +109,9 @@ namespace Specter { output.close(); } - void SpectrumSerializer::DeserializeData() + void SpectrumSerializer::DeserializeData(const SpectrumManager::Ref& manager) { - SpectrumManager& manager = SpectrumManager::GetInstance(); - manager.RemoveAllSpectra(); //When loading in, we remove all extant data, to avoid any potential collisions. + manager->RemoveAllSpectra(); //When loading in, we remove all extant data, to avoid any potential collisions. YAML::Node data; try @@ -139,15 +136,15 @@ namespace Specter { tempArgs.y_par = cut["YParameter"].as(); if (tempArgs.type == CutType::Cut1D) { - manager.AddCut(tempArgs, cut["XMin"].as(), cut["XMax"].as()); + manager->AddCut(tempArgs, cut["XMin"].as(), cut["XMax"].as()); } else if (tempArgs.type == CutType::Cut2D) { - manager.AddCut(tempArgs, cut["XPoints"].as>(), cut["YPoints"].as>()); + manager->AddCut(tempArgs, cut["XPoints"].as>(), cut["YPoints"].as>()); } else if (tempArgs.type == CutType::CutSummaryAll || tempArgs.type == CutType::CutSummaryAny) { - manager.AddCut(tempArgs, cut["SubHistos"].as>(), cut["XMin"].as(), cut["XMax"].as()); + manager->AddCut(tempArgs, cut["SubHistos"].as>(), cut["XMin"].as(), cut["XMax"].as()); } } } @@ -172,11 +169,11 @@ namespace Specter { tempArgs.cutsAppliedTo = histo["CutsApplied"].as>(); if (tempArgs.type == SpectrumType::Summary) { - manager.AddHistogramSummary(tempArgs, histo["SubHistos"].as>()); + manager->AddHistogramSummary(tempArgs, histo["SubHistos"].as>()); } else { - manager.AddHistogram(tempArgs); + manager->AddHistogram(tempArgs); } } } diff --git a/Specter/src/Specter/Core/SpectrumSerializer.h b/Specter/src/Specter/Core/SpectrumSerializer.h index 86edfe3..86ccf6a 100644 --- a/Specter/src/Specter/Core/SpectrumSerializer.h +++ b/Specter/src/Specter/Core/SpectrumSerializer.h @@ -16,6 +16,7 @@ #include "Histogram.h" #include "Cut.h" +#include "SpectrumManager.h" namespace Specter { @@ -25,8 +26,8 @@ namespace Specter { SpectrumSerializer(const std::string& filepath); ~SpectrumSerializer(); - void SerializeData(const std::vector& histoList, const std::vector& cutList); - void DeserializeData(); + void SerializeData(const SpectrumManager::Ref& manager, const std::vector& histoList, const std::vector& cutList); + void DeserializeData(const SpectrumManager::Ref& manager); inline const std::string& GetFilename() { return m_filename; } diff --git a/Specter/src/Specter/Editor/EditorLayer.cpp b/Specter/src/Specter/Editor/EditorLayer.cpp index 8f439ee..acdb609 100644 --- a/Specter/src/Specter/Editor/EditorLayer.cpp +++ b/Specter/src/Specter/Editor/EditorLayer.cpp @@ -12,7 +12,6 @@ #include "FileDialog.h" #include "Specter/Core/Application.h" #include "Specter/Core/SpectrumSerializer.h" -#include "Specter/Core/SpectrumManager.h" #include "IconsFontAwesome5.h" @@ -23,8 +22,8 @@ namespace Specter { return p1 < p2; } - EditorLayer::EditorLayer() : - Layer("EditorLayer"), m_removeHistogram(false), m_removeCut(false), m_exportHistogram(false) + EditorLayer::EditorLayer(const SpectrumManager::Ref& manager) : + Layer("EditorLayer"), m_manager(manager), m_removeHistogram(false), m_removeCut(false), m_exportHistogram(false) { } @@ -40,7 +39,7 @@ namespace Specter { void EditorLayer::OnUpdate(Timestep& step) { - SpectrumManager::GetInstance().UpdateGraphs(step); + m_manager->UpdateGraphs(step); } void EditorLayer::OnEvent(Event& e) @@ -50,31 +49,31 @@ namespace Specter { //These updates are used whenever a new object is added to the manager. void EditorLayer::UpdateHistogramList() { - m_histoList = SpectrumManager::GetInstance().GetListOfHistograms(); + m_histoList = m_manager->GetListOfHistograms(); std::sort(m_histoList.begin(), m_histoList.end(), SortByName); } void EditorLayer::UpdateCutList() { - m_cutList = SpectrumManager::GetInstance().GetListOfCuts(); + m_cutList = m_manager->GetListOfCuts(); std::sort(m_cutList.begin(), m_cutList.end(), SortByName); } void EditorLayer::UpdateParameterList() { - m_paramList = SpectrumManager::GetInstance().GetListOfParameters(); + m_paramList = m_manager->GetListOfParameters(); std::sort(m_paramList.begin(), m_paramList.end(), SortByString); } void EditorLayer::UpdateScalerList() { - m_scalerList = SpectrumManager::GetInstance().GetListOfScalers(); + m_scalerList = m_manager->GetListOfScalers(); std::sort(m_scalerList.begin(), m_scalerList.end(), SortByString); } void EditorLayer::UpdateGraphList() { - m_graphList = SpectrumManager::GetInstance().GetListOfGraphs(); + m_graphList = m_manager->GetListOfGraphs(); std::sort(m_graphList.begin(), m_graphList.end(), SortByName); } @@ -206,7 +205,7 @@ namespace Specter { case FileDialog::Type::OpenFile: { SpectrumSerializer serializer(fd_result.first); - serializer.DeserializeData(); + serializer.DeserializeData(m_manager); UpdateHistogramList(); UpdateCutList(); break; @@ -215,17 +214,17 @@ namespace Specter { { SPEC_INFO("Found a Save File! {0}", fd_result.first); SpectrumSerializer serializer(fd_result.first); - serializer.SerializeData(m_histoList, m_cutList); + serializer.SerializeData(m_manager, m_histoList, m_cutList); break; } } } - if(m_spectrumDialog.ImGuiRenderSpectrumDialog(m_histoList, m_cutList, m_paramList)) + if(m_spectrumDialog.ImGuiRenderSpectrumDialog(m_manager, m_histoList, m_cutList, m_paramList)) UpdateHistogramList(); - m_scalerPanel.OnImGuiRender(m_scalerList, m_graphList); + m_scalerPanel.OnImGuiRender(m_manager, m_scalerList, m_graphList); m_sourceDialog.ImGuiRenderSourceDialog(); @@ -235,7 +234,7 @@ namespace Specter { ExportHistogramDialog(); - if(m_spectrumPanel.OnImGuiRender(m_histoList, m_cutList, m_paramList)) + if(m_spectrumPanel.OnImGuiRender(m_manager, m_histoList, m_cutList, m_paramList)) { UpdateCutList(); UpdateHistogramList(); @@ -315,7 +314,7 @@ namespace Specter { } if (ImGui::Button("Ok")) { - SpectrumManager::GetInstance().RemoveHistogram(selectedGram); + m_manager->RemoveHistogram(selectedGram); UpdateHistogramList(); ImGui::CloseCurrentPopup(); } @@ -351,7 +350,7 @@ namespace Specter { } if (ImGui::Button("Ok")) { - SpectrumManager::GetInstance().RemoveCut(selectedCut); + m_manager->RemoveCut(selectedCut); UpdateHistogramList(); UpdateCutList(); ImGui::CloseCurrentPopup(); @@ -418,7 +417,7 @@ namespace Specter { return; } - std::vector data = SpectrumManager::GetInstance().GetBinData(selectedGram.name); + std::vector data = m_manager->GetBinData(selectedGram.name); output<<"Histogram Name,"<; - EditorLayer(); + EditorLayer(const SpectrumManager::Ref& manager); ~EditorLayer(); void SetEventCallbackFunc(const EventCallbackFunc& f) { m_callbackFunc = f; } @@ -50,6 +51,8 @@ namespace Specter { void UpdateGraphList(); //Same void ExportHistogram(HistogramArgs selectedGram, const std::string& filename); + SpectrumManager::Ref m_manager; + EventCallbackFunc m_callbackFunc; SpectrumPanel m_spectrumPanel; diff --git a/Specter/src/Specter/Editor/ScalerPanel.cpp b/Specter/src/Specter/Editor/ScalerPanel.cpp index 86a1196..dd5f317 100644 --- a/Specter/src/Specter/Editor/ScalerPanel.cpp +++ b/Specter/src/Specter/Editor/ScalerPanel.cpp @@ -1,5 +1,4 @@ #include "ScalerPanel.h" -#include "Specter/Core/SpectrumManager.h" #include "imgui.h" #include "implot.h" @@ -10,9 +9,8 @@ namespace Specter { ScalerPanel::~ScalerPanel() {} - void ScalerPanel::OnImGuiRender(const std::vector& scalerList, const std::vector& graphList) + void ScalerPanel::OnImGuiRender(const SpectrumManager::Ref& manager, const std::vector& scalerList, const std::vector& graphList) { - SpectrumManager& manager = SpectrumManager::GetInstance(); if (ImGui::Begin("ScalerPanel")) { if (ImGui::TreeNode("Scalers")) @@ -34,7 +32,7 @@ namespace Specter { } if (ImPlot::BeginPlot("Scaler Graphs")) { - manager.DrawGraph(m_selectedGraph.name); + manager->DrawGraph(m_selectedGraph.name); ImPlot::EndPlot(); } } diff --git a/Specter/src/Specter/Editor/ScalerPanel.h b/Specter/src/Specter/Editor/ScalerPanel.h index 06ea58f..a3622ed 100644 --- a/Specter/src/Specter/Editor/ScalerPanel.h +++ b/Specter/src/Specter/Editor/ScalerPanel.h @@ -2,6 +2,7 @@ #define SCALER_PANEL_H #include "Specter/Core/Graph.h" +#include "Specter/Core/SpectrumManager.h" namespace Specter { @@ -11,7 +12,7 @@ namespace Specter { ScalerPanel(); ~ScalerPanel(); - void OnImGuiRender(const std::vector& scalerList, const std::vector& graphList); + void OnImGuiRender(const SpectrumManager::Ref& manager, const std::vector& scalerList, const std::vector& graphList); private: GraphArgs m_selectedGraph; diff --git a/Specter/src/Specter/Editor/SpectrumDialog.cpp b/Specter/src/Specter/Editor/SpectrumDialog.cpp index 17dfc5b..1e22246 100644 --- a/Specter/src/Specter/Editor/SpectrumDialog.cpp +++ b/Specter/src/Specter/Editor/SpectrumDialog.cpp @@ -5,7 +5,6 @@ GWM -- Feb 2022 */ #include "SpectrumDialog.h" -#include "Specter/Core/SpectrumManager.h" #include "misc/cpp/imgui_stdlib.h" @@ -24,7 +23,7 @@ namespace Specter { { } - bool SpectrumDialog::ImGuiRenderSpectrumDialog(const std::vector& histoList, const std::vector& cutList, const std::vector& paramList) + bool SpectrumDialog::ImGuiRenderSpectrumDialog(const SpectrumManager::Ref& manager, const std::vector& histoList, const std::vector& cutList, const std::vector& paramList) { SPEC_PROFILE_FUNCTION(); static std::string selectedCut = ""; @@ -78,9 +77,9 @@ namespace Specter { { switch (m_newParams.type) { - case SpectrumType::Histo1D: SpectrumManager::GetInstance().AddHistogram(m_newParams); break; - case SpectrumType::Histo2D: SpectrumManager::GetInstance().AddHistogram(m_newParams); break; - case SpectrumType::Summary: SpectrumManager::GetInstance().AddHistogramSummary(m_newParams, m_subhistos); break; + case SpectrumType::Histo1D: manager->AddHistogram(m_newParams); break; + case SpectrumType::Histo2D: manager->AddHistogram(m_newParams); break; + case SpectrumType::Summary: manager->AddHistogramSummary(m_newParams, m_subhistos); break; case SpectrumType::None: break; } ImGui::CloseCurrentPopup(); diff --git a/Specter/src/Specter/Editor/SpectrumDialog.h b/Specter/src/Specter/Editor/SpectrumDialog.h index 873d113..4d9389c 100644 --- a/Specter/src/Specter/Editor/SpectrumDialog.h +++ b/Specter/src/Specter/Editor/SpectrumDialog.h @@ -9,6 +9,7 @@ #include "Specter/Core/Histogram.h" #include "Specter/Core/Cut.h" +#include "Specter/Core/SpectrumManager.h" #include "imgui.h" @@ -21,7 +22,7 @@ namespace Specter { SpectrumDialog(); ~SpectrumDialog(); - bool ImGuiRenderSpectrumDialog(const std::vector& histoList, const std::vector& cutList, const std::vector& paramList); + bool ImGuiRenderSpectrumDialog(const SpectrumManager::Ref& manager, const std::vector& histoList, const std::vector& cutList, const std::vector& paramList); inline void SetSpectrumDialog() { m_openFlag = true; } private: diff --git a/Specter/src/Specter/Editor/SpectrumPanel.cpp b/Specter/src/Specter/Editor/SpectrumPanel.cpp index 8351a69..b07e630 100644 --- a/Specter/src/Specter/Editor/SpectrumPanel.cpp +++ b/Specter/src/Specter/Editor/SpectrumPanel.cpp @@ -6,7 +6,6 @@ GWM -- Feb 2022 */ #include "SpectrumPanel.h" -#include "Specter/Core/SpectrumManager.h" #include "misc/cpp/imgui_stdlib.h" #include "IconsFontAwesome5.h" @@ -35,7 +34,7 @@ namespace Specter { SpectrumPanel::~SpectrumPanel() {} //Main render function. Handles generating subplot regions as well as the zoomed in region - bool SpectrumPanel::OnImGuiRender(const std::vector& histoList, const std::vector& cutList, const std::vector& paramList) + bool SpectrumPanel::OnImGuiRender(const SpectrumManager::Ref& manager, const std::vector& histoList, const std::vector& cutList, const std::vector& paramList) { SPEC_PROFILE_FUNCTION(); static bool acceptCutFlag = false; @@ -50,20 +49,20 @@ namespace Specter { ImGui::SameLine(); if(ImGui::Button("Clear")) { - SpectrumManager::GetInstance().ClearHistogram(m_zoomedGram.name); + manager->ClearHistogram(m_zoomedGram.name); } ImGui::SameLine(); RenderRemoveRegionButton(); if (m_zoomedGram.type == SpectrumType::Histo2D || m_zoomedGram.type == SpectrumType::Summary) { - float* scale = SpectrumManager::GetInstance().GetColorScaleRange(m_zoomedGram.name); + float* scale = manager->GetColorScaleRange(m_zoomedGram.name); ImGui::DragFloatRange2("Min / Max", &(scale[0]), &(scale[1]), 0.01f); ImPlot::ColormapScale("##HistogramScale", scale[0], scale[1], ImVec2(0, -1), ImPlotColormap_Viridis); ImGui::SameLine(); } if (ImPlot::BeginPlot(m_zoomedGram.name.c_str(), ImVec2(-1, -1))) { - SpectrumManager::GetInstance().DrawHistogram(m_zoomedGram.name); + manager->DrawHistogram(m_zoomedGram.name); if (!m_cutModeFlag && ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { m_zoomedFlag = false; @@ -88,14 +87,14 @@ namespace Specter { if (m_zoomedGram.name == region.histogram_name) { ImPlot::DragRect(int(i), ®ion.region.X.Min, ®ion.region.Y.Min, ®ion.region.X.Max, ®ion.region.Y.Max, ImVec4(1, 0, 1, 1), ImPlotDragToolFlags_NoFit); - StatResults results = SpectrumManager::GetInstance().AnalyzeHistogramRegion(m_zoomedGram.name, region.region); + StatResults results = manager->AnalyzeHistogramRegion(m_zoomedGram.name, region.region); ImPlot::PlotText(GenerateStatString(region.name, results, m_zoomedGram.y_par != "None").c_str(), (region.region.X.Max + region.region.X.Min) * 0.5, (region.region.Y.Min + region.region.Y.Max) * 0.5); } } ImPlot::EndPlot(); } - RenderAcceptCutDialog(); + RenderAcceptCutDialog(manager); } else { @@ -103,7 +102,7 @@ namespace Specter { ImGui::SameLine(); if (ImGui::Button("Clear All")) { - SpectrumManager::GetInstance().ClearHistograms(); + manager->ClearHistograms(); } m_totalSlots = m_tableSizes[0] * m_tableSizes[1]; m_selectedGrams.resize(m_totalSlots); @@ -140,7 +139,7 @@ namespace Specter { { if (ImPlot::BeginPlot(spec.name.c_str())) { - SpectrumManager::GetInstance().DrawHistogram(spec.name); + manager->DrawHistogram(spec.name); if (ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) { m_zoomedFlag = true; @@ -223,7 +222,7 @@ namespace Specter { } } - void SpectrumPanel::RenderAcceptCutDialog() + void SpectrumPanel::RenderAcceptCutDialog(const SpectrumManager::Ref& manager) { if (m_acceptCutFlag) { @@ -236,36 +235,35 @@ namespace Specter { ImGui::Text("Save this Cut?"); if (ImGui::Button("Yes")) { - SpectrumManager& manager = SpectrumManager::GetInstance(); switch (m_newCutArgs.type) { case CutType::Cut1D: { std::sort(m_newCutX.begin(), m_newCutX.end()); - manager.AddCut(m_newCutArgs, m_newCutX[0], m_newCutX[1]); - manager.AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name); + manager->AddCut(m_newCutArgs, m_newCutX[0], m_newCutX[1]); + manager->AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name); break; } case CutType::Cut2D: { - manager.AddCut(m_newCutArgs, m_newCutX, m_newCutY); - manager.AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name); + manager->AddCut(m_newCutArgs, m_newCutX, m_newCutY); + manager->AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name); break; } case CutType::CutSummaryAny: { std::sort(m_newCutX.begin(), m_newCutX.end()); - std::vector subhistos = manager.GetSubHistograms(m_zoomedGram.name); - manager.AddCut(m_newCutArgs, subhistos, m_newCutX[0], m_newCutX[1]); - manager.AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name); + std::vector subhistos = manager->GetSubHistograms(m_zoomedGram.name); + manager->AddCut(m_newCutArgs, subhistos, m_newCutX[0], m_newCutX[1]); + manager->AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name); break; } case CutType::CutSummaryAll: { std::sort(m_newCutX.begin(), m_newCutX.end()); - std::vector subhistos = manager.GetSubHistograms(m_zoomedGram.name); - manager.AddCut(m_newCutArgs, subhistos, m_newCutX[0], m_newCutX[1]); - manager.AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name); + std::vector subhistos = manager->GetSubHistograms(m_zoomedGram.name); + manager->AddCut(m_newCutArgs, subhistos, m_newCutX[0], m_newCutX[1]); + manager->AddCutToHistogramDraw(m_newCutArgs.name, m_zoomedGram.name); break; } case CutType::None: diff --git a/Specter/src/Specter/Editor/SpectrumPanel.h b/Specter/src/Specter/Editor/SpectrumPanel.h index 8fa5c68..0e48cf6 100644 --- a/Specter/src/Specter/Editor/SpectrumPanel.h +++ b/Specter/src/Specter/Editor/SpectrumPanel.h @@ -8,6 +8,7 @@ #ifndef SPECTRUM_PANEL_H #define SPECTRUM_PANEL_H +#include "Specter/Core/SpectrumManager.h" #include "Specter/Core/Histogram.h" #include "Specter/Core/Cut.h" #include "imgui.h" @@ -33,16 +34,17 @@ namespace Specter { SpectrumPanel(); ~SpectrumPanel(); - bool OnImGuiRender(const std::vector& histoList, const std::vector& cutList, const std::vector& paramList); + bool OnImGuiRender(const SpectrumManager::Ref& manager, const std::vector& histoList, const std::vector& cutList, const std::vector& paramList); inline const std::string& GetZoomedOnHistogram() { return m_zoomedGram.name; } inline const bool IsZoomed() { return m_zoomedFlag; } private: void HandleCutMode(); - void RenderAcceptCutDialog(); + void RenderAcceptCutDialog(const SpectrumManager::Ref& manager); void RenderCutButton(); void RenderRemoveRegionButton(); void RemoveSelectedRegion(const std::string& region); + std::vector m_selectedGrams; std::vector m_integralRegions; bool m_zoomedFlag; diff --git a/Specter/src/Specter/Physics/Caen/CompassFile.cpp b/Specter/src/Specter/Physics/Caen/CompassFile.cpp index 9f265ec..9a3a8f0 100644 --- a/Specter/src/Specter/Physics/Caen/CompassFile.cpp +++ b/Specter/src/Specter/Physics/Caen/CompassFile.cpp @@ -53,7 +53,7 @@ namespace Specter { m_file->seekg(0, std::ios_base::end); m_size = (unsigned int)m_file->tellg(); - if(m_size == 0) + if(m_size == 2) { m_eofFlag = true; } diff --git a/Specter/src/Specter/Physics/Caen/CompassHit.h b/Specter/src/Specter/Physics/Caen/CompassHit.h index f77d492..71729e1 100644 --- a/Specter/src/Specter/Physics/Caen/CompassHit.h +++ b/Specter/src/Specter/Physics/Caen/CompassHit.h @@ -33,8 +33,8 @@ namespace Specter { enum CompassHeaders { Energy = 0x0001, - EnergyShort = 0x0002, - EnergyCalibrated = 0x0004, + EnergyShort = 0x0004, + EnergyCalibrated = 0x0002, Waves = 0x0008 }; diff --git a/Specter/src/Specter/Physics/Caen/CompassRun.h b/Specter/src/Specter/Physics/Caen/CompassRun.h index 0e3a3f3..9568c6f 100644 --- a/Specter/src/Specter/Physics/Caen/CompassRun.h +++ b/Specter/src/Specter/Physics/Caen/CompassRun.h @@ -48,7 +48,7 @@ namespace Specter { bool GetHitsFromFiles(); std::filesystem::path m_directory; - const std::string m_extension = ".bin"; + const std::string m_extension = ".BIN"; std::vector m_datafiles; unsigned int m_startIndex; //this is the file we start looking at; increases as we finish files. diff --git a/Specter/src/Specter/Physics/PhysicsLayer.cpp b/Specter/src/Specter/Physics/PhysicsLayer.cpp index 742edcf..4cda838 100644 --- a/Specter/src/Specter/Physics/PhysicsLayer.cpp +++ b/Specter/src/Specter/Physics/PhysicsLayer.cpp @@ -8,13 +8,12 @@ GWM -- Feb 2022 */ #include "PhysicsLayer.h" -#include "Specter/Core/SpectrumManager.h" #include "SpecData.h" namespace Specter { - PhysicsLayer::PhysicsLayer() : - m_activeFlag(false), m_source(nullptr), m_eventBuilder(0), m_physThread(nullptr) + PhysicsLayer::PhysicsLayer(const SpectrumManager::Ref& manager) : + m_manager(manager), m_activeFlag(false), m_source(nullptr), m_eventBuilder(0), m_physThread(nullptr) { } @@ -89,6 +88,7 @@ namespace Specter { void PhysicsLayer::OnUpdate(Timestep& step) {} + /*Threaded functions*/ void PhysicsLayer::DestroyPhysThread() @@ -143,7 +143,6 @@ namespace Specter { void PhysicsLayer::RunSource() { SPEC_PROFILE_FUNCTION(); - SpectrumManager& manager = SpectrumManager::GetInstance(); std::vector events; SpecData datum; @@ -178,9 +177,9 @@ namespace Specter { stage->AnalyzePhysicsEvent(event); //Now that the analysis stack has filled all our NavParameters with data, update the histogram counts - manager.UpdateHistograms(); + m_manager->UpdateHistograms(); //Invalidate all parameters to get ready for next event - manager.InvalidateParameters(); + m_manager->InvalidateParameters(); } } } diff --git a/Specter/src/Specter/Physics/PhysicsLayer.h b/Specter/src/Specter/Physics/PhysicsLayer.h index 57b61f8..547033e 100644 --- a/Specter/src/Specter/Physics/PhysicsLayer.h +++ b/Specter/src/Specter/Physics/PhysicsLayer.h @@ -17,6 +17,7 @@ #include "AnalysisStage.h" #include "DataSource.h" #include "PhysicsEventBuilder.h" +#include "Specter/Core/SpectrumManager.h" #include #include @@ -27,7 +28,7 @@ namespace Specter { class PhysicsLayer : public Layer { public: - PhysicsLayer(); + PhysicsLayer(const SpectrumManager::Ref& manager); virtual ~PhysicsLayer(); virtual void OnAttach() override; @@ -47,6 +48,7 @@ namespace Specter { void DetachDataSource(); void RunSource(); + SpectrumManager::Ref m_manager; AnalysisStack m_physStack; std::atomic m_activeFlag; //safe read/write across thread, but more expensive