1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-22 18:28:52 -05:00

Changed SpectrumManager from global static instance to memory allocated owned by App and passed to layers as needed. Better data encapsulation and hopefully make some things easier down the line

This commit is contained in:
Gordon McCann 2022-07-16 12:50:14 -04:00
parent 830aef4f9f
commit 798fb85687
24 changed files with 129 additions and 122 deletions

View File

@ -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<std::string> 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() {}

View File

@ -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;

View File

@ -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() {}

View File

@ -22,7 +22,7 @@ namespace Specter {
class SPSInputLayer : public Layer
{
public:
SPSInputLayer();
SPSInputLayer(const SpectrumManager::Ref& manager);
~SPSInputLayer();
virtual void OnAttach() override;

View File

@ -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));
}
};

View File

@ -34,9 +34,12 @@ namespace Specter {
m_window = std::unique_ptr<Window>(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<SpectrumManager>();
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();

View File

@ -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<SpectrumManager>& 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
};

View File

@ -14,8 +14,6 @@
namespace Specter {
SpectrumManager* SpectrumManager::s_instance = new SpectrumManager();
SpectrumManager::SpectrumManager()
{
}

View File

@ -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();
~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<std::string, std::shared_ptr<Histogram>> m_histoMap;
std::unordered_map<std::string, std::shared_ptr<Cut>> m_cutMap;

View File

@ -12,16 +12,14 @@
GWM -- Feb 2022
*/
#include "SpectrumSerializer.h"
#include "SpectrumManager.h"
#include <fstream>
#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<SpectrumManager>& 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<double> xpoints = manager.GetCutXPoints(args.name);
std::vector<double> 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<double> xpoints = manager.GetCutXPoints(args.name);
std::vector<double> ypoints = manager.GetCutYPoints(args.name);
std::vector<double> xpoints = manager->GetCutXPoints(args.name);
std::vector<double> 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<std::string> subhistos = manager.GetCutSubHistograms(args.name);
std::vector<double> xpoints = manager.GetCutXPoints(args.name);
std::vector<std::string> subhistos = manager->GetCutSubHistograms(args.name);
std::vector<double> 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<SpectrumManager>& 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<std::string> subhistos = SpectrumManager::GetInstance().GetSubHistograms(args.name);
std::vector<std::string> 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<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList)
void SpectrumSerializer::SerializeData(const SpectrumManager::Ref& manager, const std::vector<HistogramArgs>& histoList, const std::vector<CutArgs>& 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<std::string>();
if (tempArgs.type == CutType::Cut1D)
{
manager.AddCut(tempArgs, cut["XMin"].as<double>(), cut["XMax"].as<double>());
manager->AddCut(tempArgs, cut["XMin"].as<double>(), cut["XMax"].as<double>());
}
else if (tempArgs.type == CutType::Cut2D)
{
manager.AddCut(tempArgs, cut["XPoints"].as<std::vector<double>>(), cut["YPoints"].as<std::vector<double>>());
manager->AddCut(tempArgs, cut["XPoints"].as<std::vector<double>>(), cut["YPoints"].as<std::vector<double>>());
}
else if (tempArgs.type == CutType::CutSummaryAll || tempArgs.type == CutType::CutSummaryAny)
{
manager.AddCut(tempArgs, cut["SubHistos"].as<std::vector<std::string>>(), cut["XMin"].as<double>(), cut["XMax"].as<double>());
manager->AddCut(tempArgs, cut["SubHistos"].as<std::vector<std::string>>(), cut["XMin"].as<double>(), cut["XMax"].as<double>());
}
}
}
@ -172,11 +169,11 @@ namespace Specter {
tempArgs.cutsAppliedTo = histo["CutsApplied"].as<std::vector<std::string>>();
if (tempArgs.type == SpectrumType::Summary)
{
manager.AddHistogramSummary(tempArgs, histo["SubHistos"].as<std::vector<std::string>>());
manager->AddHistogramSummary(tempArgs, histo["SubHistos"].as<std::vector<std::string>>());
}
else
{
manager.AddHistogram(tempArgs);
manager->AddHistogram(tempArgs);
}
}
}

View File

@ -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<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList);
void DeserializeData();
void SerializeData(const SpectrumManager::Ref& manager, const std::vector<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList);
void DeserializeData(const SpectrumManager::Ref& manager);
inline const std::string& GetFilename() { return m_filename; }

View File

@ -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<HistogramArgs>);
}
void EditorLayer::UpdateCutList()
{
m_cutList = SpectrumManager::GetInstance().GetListOfCuts();
m_cutList = m_manager->GetListOfCuts();
std::sort(m_cutList.begin(), m_cutList.end(), SortByName<CutArgs>);
}
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<GraphArgs>);
}
@ -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<double> data = SpectrumManager::GetInstance().GetBinData(selectedGram.name);
std::vector<double> data = m_manager->GetBinData(selectedGram.name);
output<<"Histogram Name,"<<selectedGram.name<<std::endl;
output<<"Min X,"<<selectedGram.min_x<<std::endl<<"Max X,"<<selectedGram.max_x<<std::endl;

View File

@ -19,6 +19,7 @@
#include "FileDialog.h"
#include "SpectrumDialog.h"
#include "SourceDialog.h"
#include "Specter/Core/SpectrumManager.h"
namespace Specter {
@ -27,7 +28,7 @@ namespace Specter {
public:
using EventCallbackFunc = std::function<void(Event&)>;
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;

View File

@ -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<std::string>& scalerList, const std::vector<GraphArgs>& graphList)
void ScalerPanel::OnImGuiRender(const SpectrumManager::Ref& manager, const std::vector<std::string>& scalerList, const std::vector<GraphArgs>& 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();
}
}

View File

@ -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<std::string>& scalerList, const std::vector<GraphArgs>& graphList);
void OnImGuiRender(const SpectrumManager::Ref& manager, const std::vector<std::string>& scalerList, const std::vector<GraphArgs>& graphList);
private:
GraphArgs m_selectedGraph;

View File

@ -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<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList, const std::vector<std::string>& paramList)
bool SpectrumDialog::ImGuiRenderSpectrumDialog(const SpectrumManager::Ref& manager, const std::vector<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList, const std::vector<std::string>& 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();

View File

@ -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<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList, const std::vector<std::string>& paramList);
bool ImGuiRenderSpectrumDialog(const SpectrumManager::Ref& manager, const std::vector<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList, const std::vector<std::string>& paramList);
inline void SetSpectrumDialog() { m_openFlag = true; }
private:

View File

@ -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<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList, const std::vector<std::string>& paramList)
bool SpectrumPanel::OnImGuiRender(const SpectrumManager::Ref& manager, const std::vector<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList, const std::vector<std::string>& 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), &region.region.X.Min, &region.region.Y.Min, &region.region.X.Max, &region.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<std::string> 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<std::string> 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<std::string> 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<std::string> 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:

View File

@ -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<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList, const std::vector<std::string>& paramList);
bool OnImGuiRender(const SpectrumManager::Ref& manager, const std::vector<HistogramArgs>& histoList, const std::vector<CutArgs>& cutList, const std::vector<std::string>& 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<HistogramArgs> m_selectedGrams;
std::vector<IntegrationRegion> m_integralRegions;
bool m_zoomedFlag;

View File

@ -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;
}

View File

@ -33,8 +33,8 @@ namespace Specter {
enum CompassHeaders
{
Energy = 0x0001,
EnergyShort = 0x0002,
EnergyCalibrated = 0x0004,
EnergyShort = 0x0004,
EnergyCalibrated = 0x0002,
Waves = 0x0008
};

View File

@ -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<CompassFile> m_datafiles;
unsigned int m_startIndex; //this is the file we start looking at; increases as we finish files.

View File

@ -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<SpecEvent> 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();
}
}
}

View File

@ -17,6 +17,7 @@
#include "AnalysisStage.h"
#include "DataSource.h"
#include "PhysicsEventBuilder.h"
#include "Specter/Core/SpectrumManager.h"
#include <thread>
#include <mutex>
@ -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<bool> m_activeFlag; //safe read/write across thread, but more expensive