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

Added intial test classes to NavProject for use with SPS data. After brief testing, obv issue that analysis speed tied to rendering rate. Reverted to multi-threaded case, albeit with layer style

This commit is contained in:
Gordon McCann 2022-02-05 13:20:45 -05:00
parent ec401030e1
commit e8166cdbcd
24 changed files with 475 additions and 187 deletions

View File

@ -0,0 +1,34 @@
#include "SPSAnalysisStage.h"
namespace Navigator {
SPSAnalysisStage::SPSAnalysisStage() :
AnalysisStage("SPSAnalysis"), delayFLTime("delayFLTime"), delayFRTime("delayFRTime"), delayBLTime("delayBLTime"), delayBRTime("delayBRTime"), x1("x1"), x2("x2"), xavg("xavg")
{
}
SPSAnalysisStage::~SPSAnalysisStage() {}
void SPSAnalysisStage::AnalyzeRawPhysicsEvent(const RawPhysicsEvent& event)
{
for(auto& hit : event)
{
if(hit.board == 8 && hit.channel == 8)
delayFLTime.SetValue(hit.timestamp/1.0e3);
else if(hit.board == 8 && hit.channel == 9)
delayFRTime.SetValue(hit.timestamp/1.0e3);
else if(hit.board == 8 && hit.channel == 10)
delayBLTime.SetValue(hit.timestamp/1.0e3);
else if(hit.board == 8 && hit.channel == 11)
delayBRTime.SetValue(hit.timestamp/1.0e3);
}
if(delayFLTime.IsValid() && delayFRTime.IsValid())
x1.SetValue((delayFLTime.GetValue() - delayFRTime.GetValue())*0.5);
if(delayBLTime.IsValid() && delayBRTime.IsValid())
x1.SetValue((delayBLTime.GetValue() - delayBRTime.GetValue())*0.5);
}
}

View File

@ -0,0 +1,26 @@
#include "Navigator.h"
namespace Navigator {
class SPSAnalysisStage : public AnalysisStage
{
public:
SPSAnalysisStage();
virtual ~SPSAnalysisStage();
virtual void AnalyzeRawPhysicsEvent(const RawPhysicsEvent& event) override;
private:
NavParameter delayFLTime;
NavParameter delayFRTime;
NavParameter delayBLTime;
NavParameter delayBRTime;
NavParameter x1;
NavParameter x2;
NavParameter xavg;
double weight1 = 1.7;
double weight2 = -0.7;
};
}

View File

@ -1,6 +1,17 @@
#include "Navigator.h" #include "Navigator.h"
#include "SPSAnalysisStage.h"
Navigator::Application* Navigator::CreateApplication() { return new Application(); } class SPSApp : public Navigator::Application
{
public:
SPSApp() :
Navigator::Application()
{
PushAnalysisStage(new Navigator::SPSAnalysisStage());
}
};
Navigator::Application* Navigator::CreateApplication() { return new SPSApp(); }
int main(int argc, const char** argv) int main(int argc, const char** argv)
{ {

View File

@ -20,6 +20,8 @@
#include "Navigator/Logger.h" #include "Navigator/Logger.h"
#include "Navigator/Application.h" #include "Navigator/Application.h"
#include "Navigator/Physics/PhysicsLayer.h" #include "Navigator/Physics/PhysicsLayer.h"
#include "Navigator/Physics/AnalysisStage.h"
#include "Navigator/ParameterMap.h"
#include "Navigator/Layer.h" #include "Navigator/Layer.h"
#include "Navigator/Events/Event.h" #include "Navigator/Events/Event.h"
#include "Navigator/Renderer/Renderer.h" #include "Navigator/Renderer/Renderer.h"

View File

@ -80,8 +80,10 @@ namespace Navigator {
m_imgui_layer->End(); m_imgui_layer->End();
m_window->OnUpdate(); m_window->OnUpdate();
/* For debugging
ParameterMap::GetInstance().find("joseph")->second->validFlag = true; ParameterMap::GetInstance().find("joseph")->second->validFlag = true;
ParameterMap::GetInstance().find("joseph")->second->value = 8.0; ParameterMap::GetInstance().find("joseph")->second->value = 8.0;
*/
} }
} }
} }

View File

@ -15,10 +15,10 @@ namespace Navigator {
bool Cut1D::IsInside() const bool Cut1D::IsInside() const
{ {
ParameterMap& parMap = ParameterMap::GetInstance(); ParameterMap& parMap = ParameterMap::GetInstance();
auto iter = parMap.find(m_params.x_par); ParameterData param = parMap.GetParameter(m_params.x_par);
if (iter == parMap.end() || !iter->second->validFlag) if (!param.validFlag)
return false; return false;
return iter->second->value >= m_minVal && iter->second->value <= m_maxVal; return param.value >= m_minVal && param.value <= m_maxVal;
} }
//Only within an ImPlot/ImGui context!!! //Only within an ImPlot/ImGui context!!!
@ -46,12 +46,12 @@ namespace Navigator {
bool Cut2D::IsInside() const bool Cut2D::IsInside() const
{ {
ParameterMap& parMap = ParameterMap::GetInstance(); ParameterMap& parMap = ParameterMap::GetInstance();
auto iterx = parMap.find(m_params.x_par); ParameterData paramx = parMap.GetParameter(m_params.x_par);
auto itery = parMap.find(m_params.y_par); ParameterData paramy = parMap.GetParameter(m_params.y_par);
if (iterx == parMap.end() || itery == parMap.end() || !iterx->second->validFlag || !itery->second->validFlag) if (!paramx.validFlag || !paramy.validFlag)
return false; return false;
double x = iterx->second->value; double x = paramx.value;
double y = itery->second->value; double y = paramy.value;
bool result = false; bool result = false;
double slope; double slope;
for(size_t i=0; i<(m_xpoints.size()-1); i++) for(size_t i=0; i<(m_xpoints.size()-1); i++)
@ -85,6 +85,7 @@ namespace Navigator {
void CutMap::DrawCut(const std::string& name) void CutMap::DrawCut(const std::string& name)
{ {
std::lock_guard<std::mutex> guard(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();
@ -92,6 +93,7 @@ namespace Navigator {
bool CutMap::IsInsideCut(const std::string& name) bool CutMap::IsInsideCut(const std::string& name)
{ {
std::lock_guard<std::mutex> guard(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())
@ -99,8 +101,29 @@ namespace Navigator {
return result; return result;
} }
std::vector<double> CutMap::GetCutXPoints(const std::string& name)
{
std::lock_guard<std::mutex> guard(m_cutMutex);
std::vector<double> null_result;
auto iter = m_map.find(name);
if(iter != m_map.end())
return iter->second->GetXValues();
return null_result;
}
std::vector<double> CutMap::GetCutYPoints(const std::string& name)
{
std::lock_guard<std::mutex> guard(m_cutMutex);
std::vector<double> null_result;
auto iter = m_map.find(name);
if(iter != m_map.end())
return iter->second->GetYValues();
return null_result;
}
std::vector<CutParams> CutMap::GetListOfCutParams() std::vector<CutParams> CutMap::GetListOfCutParams()
{ {
std::lock_guard<std::mutex> guard(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)

View File

@ -4,6 +4,8 @@
#include "NavCore.h" #include "NavCore.h"
#include "imgui.h" #include "imgui.h"
#include <thread>
namespace Navigator { namespace Navigator {
struct NAV_API CutParams struct NAV_API CutParams
@ -104,12 +106,12 @@ namespace Navigator {
void DrawCut(const std::string& name); void DrawCut(const std::string& name);
bool IsInsideCut(const std::string& name); bool IsInsideCut(const std::string& name);
std::vector<double> GetCutXPoints(const std::string& name);
std::vector<double> GetCutYPoints(const std::string& name);
std::vector<CutParams> GetListOfCutParams(); std::vector<CutParams> GetListOfCutParams();
inline Iter begin() { return m_map.begin(); }
inline Iter end() { return m_map.end(); }
private: private:
std::mutex m_cutMutex;
std::unordered_map<std::string, std::shared_ptr<Cut>> m_map; std::unordered_map<std::string, std::shared_ptr<Cut>> m_map;
static CutMap* s_instance; static CutMap* s_instance;

View File

@ -32,12 +32,36 @@ namespace Navigator {
{ {
} }
void EditorLayer::UpdateHistogramList()
{
HistogramMap& histoMap = HistogramMap::GetInstance();
m_histoList = histoMap.GetListOfHistograms();
}
void EditorLayer::UpdateCutList()
{
CutMap& cutMap = CutMap::GetInstance();
m_cutList = cutMap.GetListOfCutParams();
}
void EditorLayer::UpdateParameterList()
{
ParameterMap& parMap = ParameterMap::GetInstance();
m_paramList = parMap.GetListOfParameters();
}
void EditorLayer::OnImGuiRender() void EditorLayer::OnImGuiRender()
{ {
static bool startFlag = true; //first render retrieve base
if(startFlag)
{
UpdateParameterList();
UpdateHistogramList();
UpdateCutList();
startFlag = false;
}
// We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into, // We are using the ImGuiWindowFlags_NoDocking flag to make the parent window not dockable into,
// because it would be confusing to have two docking targets within each others. // because it would be confusing to have two docking targets within each others.
HistogramMap& histoMap = HistogramMap::GetInstance();
CutMap& cutMap = CutMap::GetInstance();
if (opt_fullscreen) if (opt_fullscreen)
{ {
ImGuiViewport* viewport = ImGui::GetMainViewport(); ImGuiViewport* viewport = ImGui::GetMainViewport();
@ -140,15 +164,18 @@ namespace Navigator {
{ {
SpectrumSerializer serializer(open_file_result); SpectrumSerializer serializer(open_file_result);
serializer.DeserializeData(); serializer.DeserializeData();
UpdateHistogramList();
UpdateCutList();
} }
else if (!save_file_result.empty()) else if (!save_file_result.empty())
{ {
NAV_INFO("Found a Save File! {0}", save_file_result); NAV_INFO("Found a Save File! {0}", save_file_result);
SpectrumSerializer serializer(save_file_result); SpectrumSerializer serializer(save_file_result);
serializer.SerializeData(); serializer.SerializeData(m_histoList, m_cutList);
} }
m_spectrumDialog.ImGuiRenderSpectrumDialog(); if(m_spectrumDialog.ImGuiRenderSpectrumDialog(m_histoList, m_cutList, m_paramList))
UpdateHistogramList();
m_sourceDialog.ImGuiRenderSourceDialog(); m_sourceDialog.ImGuiRenderSourceDialog();
@ -156,13 +183,16 @@ namespace Navigator {
RemoveCutDialog(); RemoveCutDialog();
m_spectrumPanel.OnImGuiRender(); if(m_spectrumPanel.OnImGuiRender(m_histoList, m_cutList, m_paramList))
{
UpdateCutList();
UpdateHistogramList();
}
if (ImGui::Begin(ICON_FA_CHART_BAR " Spectra")) if (ImGui::Begin(ICON_FA_CHART_BAR " Spectra"))
{ {
for (auto& gram : histoMap) for (auto& params : m_histoList)
{ {
auto& params = gram.second->GetParameters();
if (ImGui::TreeNode(params.name.c_str())) if (ImGui::TreeNode(params.name.c_str()))
{ {
ImGui::BulletText("%s", ("X Parameter: "+params.x_par).c_str()); ImGui::BulletText("%s", ("X Parameter: "+params.x_par).c_str());
@ -192,9 +222,8 @@ namespace Navigator {
if(ImGui::Begin(ICON_FA_CUT " Cuts")) if(ImGui::Begin(ICON_FA_CUT " Cuts"))
{ {
for(auto& cut : cutMap) for(auto& params : m_cutList)
{ {
auto& params = cut.second->GetCutParams();
if(ImGui::TreeNode(params.name.c_str())) if(ImGui::TreeNode(params.name.c_str()))
{ {
ImGui::BulletText("%s", ("X Parameter: "+params.x_par).c_str()); ImGui::BulletText("%s", ("X Parameter: "+params.x_par).c_str());
@ -211,7 +240,6 @@ namespace Navigator {
void EditorLayer::RemoveHistogramDialog() void EditorLayer::RemoveHistogramDialog()
{ {
HistogramMap& histMap = HistogramMap::GetInstance();
static std::string selectedGram = ""; static std::string selectedGram = "";
if (m_removeHistogram) if (m_removeHistogram)
{ {
@ -223,16 +251,17 @@ namespace Navigator {
{ {
if (ImGui::BeginCombo("Histogram", selectedGram.c_str())) if (ImGui::BeginCombo("Histogram", selectedGram.c_str()))
{ {
for (auto& gram : histMap) for (auto& gram : m_histoList)
{ {
if (ImGui::Selectable(gram.second->GetName().c_str(), gram.second->GetName() == selectedGram, ImGuiSelectableFlags_DontClosePopups)) if (ImGui::Selectable(gram.name.c_str(), gram.name == selectedGram, ImGuiSelectableFlags_DontClosePopups))
selectedGram = gram.second->GetName(); selectedGram = gram.name;
} }
ImGui::EndPopup(); ImGui::EndPopup();
} }
if (ImGui::Button("Ok")) if (ImGui::Button("Ok"))
{ {
histMap.RemoveHistogram(selectedGram); HistogramMap::GetInstance().RemoveHistogram(selectedGram);
UpdateHistogramList();
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::SameLine(); ImGui::SameLine();
@ -246,8 +275,6 @@ namespace Navigator {
void EditorLayer::RemoveCutDialog() void EditorLayer::RemoveCutDialog()
{ {
HistogramMap& histMap = HistogramMap::GetInstance();
CutMap& cutMap = CutMap::GetInstance();
static std::string selectedCut = ""; static std::string selectedCut = "";
if (m_removeCut) if (m_removeCut)
{ {
@ -259,17 +286,19 @@ namespace Navigator {
{ {
if (ImGui::BeginCombo("Cut", selectedCut.c_str())) if (ImGui::BeginCombo("Cut", selectedCut.c_str()))
{ {
for (auto& cut : cutMap) for (auto& cut : m_cutList)
{ {
if (ImGui::Selectable(cut.second->GetName().c_str(), cut.second->GetName() == selectedCut, ImGuiSelectableFlags_DontClosePopups)) if (ImGui::Selectable(cut.name.c_str(), cut.name == selectedCut, ImGuiSelectableFlags_DontClosePopups))
selectedCut = cut.second->GetName(); selectedCut = cut.name;
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
if (ImGui::Button("Ok")) if (ImGui::Button("Ok"))
{ {
histMap.RemoveCutFromHistograms(selectedCut); HistogramMap::GetInstance().RemoveCutFromHistograms(selectedCut);
cutMap.RemoveCut(selectedCut); CutMap::GetInstance().RemoveCut(selectedCut);
UpdateHistogramList();
UpdateCutList();
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
ImGui::SameLine(); ImGui::SameLine();

View File

@ -33,6 +33,9 @@ namespace Navigator {
private: private:
void RemoveCutDialog(); void RemoveCutDialog();
void RemoveHistogramDialog(); void RemoveHistogramDialog();
void UpdateHistogramList();
void UpdateCutList();
void UpdateParameterList(); //Currently not really used, only once. Params all made at construction time of PhysicsLayer
EventCallbackFunc m_callbackFunc; EventCallbackFunc m_callbackFunc;
@ -41,6 +44,11 @@ namespace Navigator {
SpectrumDialog m_spectrumDialog; SpectrumDialog m_spectrumDialog;
SourceDialog m_sourceDialog; SourceDialog m_sourceDialog;
std::vector<HistogramParameters> m_histoList;
std::vector<CutParams> m_cutList;
std::vector<std::string> m_paramList;
//ImGui Settings //ImGui Settings
bool dockspaceOpen = true; bool dockspaceOpen = true;
bool opt_fullscreen = true; bool opt_fullscreen = true;

View File

@ -15,10 +15,11 @@ namespace Navigator {
{ {
} }
void SpectrumDialog::ImGuiRenderSpectrumDialog() bool SpectrumDialog::ImGuiRenderSpectrumDialog(const std::vector<HistogramParameters>& histoList, const std::vector<CutParams>& cutList, const std::vector<std::string>& paramList)
{ {
static int dims = 1; static int dims = 1;
static std::string selectedCut = ""; static std::string selectedCut = "";
bool result = false;
if (m_openFlag) if (m_openFlag)
{ {
m_newParams = m_blank; m_newParams = m_blank;
@ -29,7 +30,6 @@ namespace Navigator {
if (ImGui::BeginPopupModal(ICON_FA_CHART_BAR " New Spectrum Dialog")) if (ImGui::BeginPopupModal(ICON_FA_CHART_BAR " New Spectrum Dialog"))
{ {
ParameterMap& parMap = ParameterMap::GetInstance();
ImGui::InputText("Spectrum Name", &m_newParams.name); ImGui::InputText("Spectrum Name", &m_newParams.name);
ImGui::SliderInt("Dimensions", &dims, 1, 2); ImGui::SliderInt("Dimensions", &dims, 1, 2);
if (ImGui::BeginTable("SpecParamsTable", 4)) if (ImGui::BeginTable("SpecParamsTable", 4))
@ -40,10 +40,10 @@ namespace Navigator {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::BeginCombo("X Param.", m_newParams.x_par.c_str())) if (ImGui::BeginCombo("X Param.", m_newParams.x_par.c_str()))
{ {
for (auto& params : parMap) for (auto& params : paramList)
{ {
if (ImGui::Selectable(params.first.c_str(), params.first == m_newParams.x_par, selectFlags)) if (ImGui::Selectable(params.c_str(), params == m_newParams.x_par, selectFlags))
m_newParams.x_par = params.first; m_newParams.x_par = params;
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
@ -61,10 +61,10 @@ namespace Navigator {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
if (ImGui::BeginCombo("Y Param.", m_newParams.y_par.c_str())) if (ImGui::BeginCombo("Y Param.", m_newParams.y_par.c_str()))
{ {
for (auto& params : parMap) for (auto& params : paramList)
{ {
if (ImGui::Selectable(params.first.c_str(), params.first == m_newParams.y_par, selectFlags)) if (ImGui::Selectable(params.c_str(), params == m_newParams.y_par, selectFlags))
m_newParams.y_par = params.first; m_newParams.y_par = params;
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
@ -94,11 +94,10 @@ namespace Navigator {
} }
if (ImGui::BeginPopup("Cut List")) if (ImGui::BeginPopup("Cut List"))
{ {
CutMap& cutMap = CutMap::GetInstance(); for (auto& cut : cutList)
for (auto& cut : cutMap)
{ {
if (ImGui::Selectable(cut.first.c_str(), cut.first == selectedCut, selectFlags)) if (ImGui::Selectable(cut.name.c_str(), cut.name == selectedCut, selectFlags))
selectedCut = cut.first; selectedCut = cut.name;
} }
ImGui::InputText("Selected Cut", &selectedCut); ImGui::InputText("Selected Cut", &selectedCut);
if (ImGui::Button("Ok")) if (ImGui::Button("Ok"))
@ -118,13 +117,16 @@ namespace Navigator {
{ {
HistogramMap::GetInstance().AddHistogram(m_newParams); HistogramMap::GetInstance().AddHistogram(m_newParams);
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
result = true;
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("Cancel")) if (ImGui::Button("Cancel"))
{ {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
result = false;
} }
ImGui::EndPopup(); ImGui::EndPopup();
} }
return result;
} }
} }

View File

@ -16,7 +16,7 @@ namespace Navigator {
SpectrumDialog(); SpectrumDialog();
~SpectrumDialog(); ~SpectrumDialog();
void ImGuiRenderSpectrumDialog(); bool ImGuiRenderSpectrumDialog(const std::vector<HistogramParameters>& histoList, const std::vector<CutParams>& cutList, const std::vector<std::string>& paramList);
inline void SetSpectrumDialog() { m_openFlag = true; } inline void SetSpectrumDialog() { m_openFlag = true; }
private: private:

View File

@ -6,24 +6,25 @@
namespace Navigator { namespace Navigator {
SpectrumPanel::SpectrumPanel() : SpectrumPanel::SpectrumPanel() :
m_zoomedFlag(false), m_cutModeFlag(false), m_zoomedGram(""), m_totalSlots(1) m_zoomedFlag(false), m_cutModeFlag(false), m_zoomedGram(), m_totalSlots(1)
{ {
m_tableSizes[0] = 1; m_tableSizes[1] = 1; m_tableSizes[0] = 1; m_tableSizes[1] = 1;
} }
SpectrumPanel::~SpectrumPanel() {} SpectrumPanel::~SpectrumPanel() {}
void SpectrumPanel::OnImGuiRender() bool SpectrumPanel::OnImGuiRender(const std::vector<HistogramParameters>& histoList, const std::vector<CutParams>& cutList, const std::vector<std::string>& paramList)
{ {
HistogramMap& histMap = HistogramMap::GetInstance(); //HistogramMap& histMap = HistogramMap::GetInstance();
ParameterMap& paramMap = ParameterMap::GetInstance(); //ParameterMap& paramMap = ParameterMap::GetInstance();
CutMap& cutMap = CutMap::GetInstance(); //CutMap& cutMap = CutMap::GetInstance();
static bool acceptCutFlag = false; static bool acceptCutFlag = false;
bool result = false;
if (ImGui::Begin("Active View")) if (ImGui::Begin("Active View"))
{ {
if (histMap.size() > 0) if (histoList.size() > 0)
{ {
if (m_zoomedFlag && m_zoomedGram != "") if (m_zoomedFlag && m_zoomedGram.name != "")
{ {
if(ImGui::Button(ICON_FA_CUT " Draw Cut")) if(ImGui::Button(ICON_FA_CUT " Draw Cut"))
{ {
@ -34,9 +35,8 @@ namespace Navigator {
} }
if(ImGui::BeginPopupModal(ICON_FA_CUT " New Cut Dialog")) if(ImGui::BeginPopupModal(ICON_FA_CUT " New Cut Dialog"))
{ {
auto& zoomed_params = histMap.GetHistogramParams(m_zoomedGram); m_newCutParams.x_par = m_zoomedGram.x_par;
m_newCutParams.x_par = zoomed_params.x_par; m_newCutParams.y_par = m_zoomedGram.y_par;
m_newCutParams.y_par = zoomed_params.y_par;
ImGui::InputText("Cut Name", &m_newCutParams.name); ImGui::InputText("Cut Name", &m_newCutParams.name);
ImGui::BulletText("%s", ("X Parameter: "+m_newCutParams.x_par).c_str()); ImGui::BulletText("%s", ("X Parameter: "+m_newCutParams.x_par).c_str());
ImGui::BulletText("%s", ("Y Parameter: "+m_newCutParams.y_par).c_str()); ImGui::BulletText("%s", ("Y Parameter: "+m_newCutParams.y_par).c_str());
@ -53,14 +53,14 @@ namespace Navigator {
ImGui::EndPopup(); ImGui::EndPopup();
} }
if (ImPlot::BeginPlot(m_zoomedGram.c_str(), ImVec2(-1, -1))) if (ImPlot::BeginPlot(m_zoomedGram.name.c_str(), ImVec2(-1, -1)))
{ {
histMap.DrawHistogram(m_zoomedGram); HistogramMap::GetInstance().DrawHistogram(m_zoomedGram.name);
if (!m_cutModeFlag && ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) if (!m_cutModeFlag && ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{ {
NAV_INFO("We lost 'em, de-zoom and enhance!"); NAV_INFO("We lost 'em, de-zoom and enhance!");
m_zoomedFlag = false; m_zoomedFlag = false;
m_zoomedGram = ""; m_zoomedGram = HistogramParameters();
} }
else if (m_cutModeFlag && m_newCutParams.y_par == "None") else if (m_cutModeFlag && m_newCutParams.y_par == "None")
{ {
@ -107,19 +107,21 @@ namespace Navigator {
if (m_newCutParams.y_par == "None") if (m_newCutParams.y_par == "None")
{ {
std::sort(m_newCutX.begin(), m_newCutX.end()); std::sort(m_newCutX.begin(), m_newCutX.end());
cutMap.AddCut(m_newCutParams, m_newCutX[0], m_newCutX[1]); CutMap::GetInstance().AddCut(m_newCutParams, m_newCutX[0], m_newCutX[1]);
} }
else else
{ {
cutMap.AddCut(m_newCutParams, m_newCutX, m_newCutY); CutMap::GetInstance().AddCut(m_newCutParams, m_newCutX, m_newCutY);
} }
histMap.AddCutToHistogramDraw(m_newCutParams.name, m_zoomedGram); HistogramMap::GetInstance().AddCutToHistogramDraw(m_newCutParams.name, m_zoomedGram.name);
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
result = true;
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button("No")) if (ImGui::Button("No"))
{ {
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
result = false;
} }
ImGui::EndPopup(); ImGui::EndPopup();
} }
@ -141,13 +143,12 @@ namespace Navigator {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
this_gram = i * m_tableSizes[1] + j; this_gram = i * m_tableSizes[1] + j;
label = "Histogram" + std::to_string(this_gram); label = "Histogram" + std::to_string(this_gram);
if (ImGui::BeginCombo(label.c_str(), m_selectedGrams[this_gram].c_str())) if (ImGui::BeginCombo(label.c_str(), m_selectedGrams[this_gram].name.c_str()))
{ {
for (auto& gram : histMap) for (auto& params : histoList)
{ {
auto& params = gram.second->GetParameters(); if (ImGui::Selectable(params.name.c_str(), params.name == m_selectedGrams[this_gram].name))
if (ImGui::Selectable(params.name.c_str(), params.name == m_selectedGrams[this_gram])) m_selectedGrams[this_gram] = params;
m_selectedGrams[this_gram] = params.name;
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
@ -161,9 +162,9 @@ namespace Navigator {
int i = 0; int i = 0;
for (auto& spec : m_selectedGrams) for (auto& spec : m_selectedGrams)
{ {
if (ImPlot::BeginPlot(spec.c_str())) if (ImPlot::BeginPlot(spec.name.c_str()))
{ {
histMap.DrawHistogram(spec); HistogramMap::GetInstance().DrawHistogram(spec.name);
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);
@ -180,5 +181,6 @@ namespace Navigator {
} }
ImGui::End(); ImGui::End();
} }
return result;
} }
} }

View File

@ -14,15 +14,15 @@ namespace Navigator {
SpectrumPanel(); SpectrumPanel();
~SpectrumPanel(); ~SpectrumPanel();
void OnImGuiRender(); bool OnImGuiRender(const std::vector<HistogramParameters>& histoList, const std::vector<CutParams>& cutList, const std::vector<std::string>& paramList);
inline const std::string& GetZoomedOnHistogram() { return m_zoomedGram; } inline const std::string& GetZoomedOnHistogram() { return m_zoomedGram.name; }
inline const bool IsZoomed() { return m_zoomedFlag; } inline const bool IsZoomed() { return m_zoomedFlag; }
private: private:
std::vector<std::string> m_selectedGrams; std::vector<HistogramParameters> m_selectedGrams;
bool m_zoomedFlag; bool m_zoomedFlag;
bool m_cutModeFlag; bool m_cutModeFlag;
std::string m_zoomedGram; HistogramParameters m_zoomedGram;
int m_tableSizes[2]; int m_tableSizes[2];
int m_totalSlots; int m_totalSlots;
CutParams m_newCutParams; CutParams m_newCutParams;

View File

@ -48,10 +48,8 @@ namespace Navigator {
void Histogram1D::FillData() void Histogram1D::FillData()
{ {
ParameterMap& parMap = ParameterMap::GetInstance(); ParameterMap& parMap = ParameterMap::GetInstance();
if (!parMap.IsParameterValid(m_params.x_par)) ParameterData x = parMap.GetParameter(m_params.x_par);
return; if(!x.validFlag || x.value < m_params.min_x || x.value >= m_params.max_x || !m_initFlag)
double x = parMap.GetParameterValue(m_params.x_par);
if(x < m_params.min_x || x >= m_params.max_x || !m_initFlag)
return; return;
auto& cutmap = CutMap::GetInstance(); auto& cutmap = CutMap::GetInstance();
for (auto& cut : m_params.cutsAppliedTo) for (auto& cut : m_params.cutsAppliedTo)
@ -60,7 +58,7 @@ namespace Navigator {
return; return;
} }
int bin = int((x - m_params.min_x)/(m_binWidth)); int bin = int((x.value - m_params.min_x)/(m_binWidth));
m_binCounts[bin] += 1.0; m_binCounts[bin] += 1.0;
} }
@ -122,9 +120,9 @@ namespace Navigator {
CutMap& cutMap = CutMap::GetInstance(); CutMap& cutMap = CutMap::GetInstance();
if (!parMap.IsParameterValid(m_params.x_par) || !parMap.IsParameterValid(m_params.y_par)) if (!parMap.IsParameterValid(m_params.x_par) || !parMap.IsParameterValid(m_params.y_par))
return; return;
double x = parMap.GetParameterValue(m_params.x_par); ParameterData x = parMap.GetParameter(m_params.x_par);
double y = parMap.GetParameterValue(m_params.y_par); ParameterData y = parMap.GetParameter(m_params.y_par);
if(x < m_params.min_x || x >= m_params.max_x || y < m_params.min_y || y >= m_params.max_y || !m_initFlag) if(!x.validFlag || !y.validFlag || x.value < m_params.min_x || x.value >= m_params.max_x || y.value < m_params.min_y || y.value >= m_params.max_y || !m_initFlag)
return; return;
for (auto& cut : m_params.cutsAppliedTo) for (auto& cut : m_params.cutsAppliedTo)
{ {
@ -132,8 +130,8 @@ namespace Navigator {
return; return;
} }
int bin_x = int((x - m_params.min_x)/m_binWidthX); int bin_x = int((x.value - m_params.min_x)/m_binWidthX);
int bin_y = int((m_params.max_y - y)/m_binWidthY); int bin_y = int((m_params.max_y - y.value)/m_binWidthY);
int bin = bin_y*m_params.nbins_x + bin_x; int bin = bin_y*m_params.nbins_x + bin_x;
m_binCounts[bin] += 1.0; m_binCounts[bin] += 1.0;

View File

@ -15,6 +15,7 @@ namespace Navigator {
void HistogramMap::AddHistogram(const HistogramParameters& params) void HistogramMap::AddHistogram(const HistogramParameters& params)
{ {
std::lock_guard<std::mutex> guard(m_histoMutex);
if (params.y_par == "None") if (params.y_par == "None")
m_map[params.name].reset(new Histogram1D(params)); m_map[params.name].reset(new Histogram1D(params));
else else
@ -23,11 +24,13 @@ namespace Navigator {
void HistogramMap::RemoveHistogram(const std::string& name) void HistogramMap::RemoveHistogram(const std::string& name)
{ {
std::lock_guard<std::mutex> guard(m_histoMutex);
m_map.erase(name); m_map.erase(name);
} }
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> guard(m_histoMutex);
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);
@ -35,6 +38,7 @@ 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> guard(m_histoMutex);
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);
@ -42,6 +46,7 @@ namespace Navigator {
void HistogramMap::RemoveCutFromHistograms(const std::string& cutname) void HistogramMap::RemoveCutFromHistograms(const std::string& cutname)
{ {
std::lock_guard<std::mutex> guard(m_histoMutex);
for (auto& gram : m_map) for (auto& gram : m_map)
{ {
auto& params = gram.second->GetParameters(); auto& params = gram.second->GetParameters();
@ -64,6 +69,7 @@ namespace Navigator {
void HistogramMap::UpdateHistograms() void HistogramMap::UpdateHistograms()
{ {
std::lock_guard<std::mutex> guard(m_histoMutex);
for (auto& pair : m_map) for (auto& pair : m_map)
pair.second->FillData(); pair.second->FillData();
} }
@ -71,6 +77,7 @@ namespace Navigator {
const HistogramParameters& HistogramMap::GetHistogramParams(const std::string& name) const HistogramParameters& HistogramMap::GetHistogramParams(const std::string& name)
{ {
std::lock_guard<std::mutex> guard(m_histoMutex);
auto iter = m_map.find(name); auto iter = m_map.find(name);
if (iter != m_map.end()) if (iter != m_map.end())
return iter->second->GetParameters(); return iter->second->GetParameters();
@ -78,9 +85,22 @@ namespace Navigator {
return m_nullResult; return m_nullResult;
} }
std::vector<HistogramParameters> HistogramMap::GetListOfHistograms()
{
std::lock_guard<std::mutex> guard(m_histoMutex);
std::vector<HistogramParameters> list;
list.reserve(m_map.size());
for(auto& gram : m_map)
{
list.push_back(gram.second->GetParameters());
}
return list;
}
//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_histoMutex);
for (auto& pair : m_map) for (auto& pair : m_map)
pair.second->Draw(); pair.second->Draw();
} }
@ -88,6 +108,7 @@ 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_histoMutex);
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();

View File

@ -4,6 +4,8 @@
#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
@ -30,14 +32,12 @@ namespace Navigator {
const HistogramParameters& GetHistogramParams(const std::string& name); const HistogramParameters& GetHistogramParams(const std::string& name);
std::vector<HistogramParameters> GetListOfHistograms();
static HistogramMap& GetInstance() { return *s_instance; } static HistogramMap& GetInstance() { return *s_instance; }
inline Iter begin() { return m_map.begin(); }
inline Iter end() { return m_map.end(); }
inline size_t size() { return m_map.size(); }
private: private:
std::mutex m_histoMutex;
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_map; std::unordered_map<std::string, std::shared_ptr<Histogram>> m_map;
HistogramParameters m_nullResult; HistogramParameters m_nullResult;

View File

@ -20,13 +20,6 @@ namespace Navigator {
NAV_INFO("Making a new parameter named {0}...",name); NAV_INFO("Making a new parameter named {0}...",name);
m_pdata = nullptr; m_pdata = nullptr;
ParameterMap& map = ParameterMap::GetInstance(); ParameterMap& map = ParameterMap::GetInstance();
auto iter = map.find(name);
if(iter == map.end())
{
NAV_INFO("Added it to the map.");
map.AddParameter(name);
}
NAV_INFO("Setting the memory..."); NAV_INFO("Setting the memory...");
map.SetParameter(name, m_pdata); map.SetParameter(name, m_pdata);
} }
@ -36,9 +29,6 @@ namespace Navigator {
void NavParameter::SetParameter(const std::string& name) void NavParameter::SetParameter(const std::string& name)
{ {
ParameterMap& map = ParameterMap::GetInstance(); ParameterMap& map = ParameterMap::GetInstance();
auto iter = map.find(name);
if(iter == map.end())
map.AddParameter(name);
map.SetParameter(name, m_pdata); map.SetParameter(name, m_pdata);
} }
@ -50,17 +40,31 @@ namespace Navigator {
ParameterMap::~ParameterMap() {} ParameterMap::~ParameterMap() {}
double ParameterMap::GetParameterValue(const std::string& name) void ParameterMap::SetParameter(const std::string& name, std::shared_ptr<ParameterData>& param)
{ {
std::lock_guard<std::mutex> guard(m_paramMutex);
auto iter = m_map.find(name);
if(iter == m_map.end())
{
m_map[name].reset(new ParameterData());
}
param = m_map[name];
}
ParameterData ParameterMap::GetParameter(const std::string& name)
{
std::lock_guard<std::mutex> guard(m_paramMutex);
auto iter = m_map.find(name); auto iter = m_map.find(name);
if(iter != m_map.end()) if(iter != m_map.end())
return iter->second->value; return *(iter->second);
else else
return 0.0; return ParameterData();
} }
bool ParameterMap::IsParameterValid(const std::string& name) bool ParameterMap::IsParameterValid(const std::string& name)
{ {
std::lock_guard<std::mutex> guard(m_paramMutex);
auto iter = m_map.find(name); auto iter = m_map.find(name);
if(iter != m_map.end()) if(iter != m_map.end())
return iter->second->validFlag; return iter->second->validFlag;
@ -70,6 +74,7 @@ namespace Navigator {
void ParameterMap::InvalidateParameters() void ParameterMap::InvalidateParameters()
{ {
std::lock_guard<std::mutex> guard(m_paramMutex);
for(auto& iter : m_map) for(auto& iter : m_map)
{ {
iter.second->validFlag = false; iter.second->validFlag = false;
@ -79,6 +84,7 @@ namespace Navigator {
std::vector<std::string> ParameterMap::GetListOfParameters() std::vector<std::string> ParameterMap::GetListOfParameters()
{ {
std::lock_guard<std::mutex> guard(m_paramMutex);
std::vector<std::string> list; std::vector<std::string> list;
list.reserve(m_map.size()); list.reserve(m_map.size());
for (auto iter : m_map) for (auto iter : m_map)

View File

@ -2,6 +2,7 @@
#define PARAMETER_MAP_H #define PARAMETER_MAP_H
#include "NavCore.h" #include "NavCore.h"
#include <thread>
namespace Navigator { namespace Navigator {
@ -45,23 +46,20 @@ namespace Navigator {
ParameterMap(); ParameterMap();
~ParameterMap(); ~ParameterMap();
inline void AddParameter(const std::string& name) { m_map[name] = std::make_shared<ParameterData>(); } void SetParameter(const std::string& name, std::shared_ptr<ParameterData>& param);
inline void SetParameter(const std::string& name, std::shared_ptr<ParameterData>& param) { param = m_map[name]; } ParameterData GetParameter(const std::string& name);
double GetParameterValue(const std::string& name);
bool IsParameterValid(const std::string& name); bool IsParameterValid(const std::string& name);
void InvalidateParameters(); void InvalidateParameters();
std::vector<std::string> GetListOfParameters(); std::vector<std::string> GetListOfParameters();
inline Iter end() { return m_map.end(); }
inline Iter begin() { return m_map.begin(); }
inline Iter find(const std::string& name) { return m_map.find(name); }
inline static ParameterMap& GetInstance() { return *s_instance; } inline static ParameterMap& GetInstance() { return *s_instance; }
private: private:
std::unordered_map<std::string, std::shared_ptr<ParameterData>> m_map; std::unordered_map<std::string, std::shared_ptr<ParameterData>> m_map;
static ParameterMap* s_instance; static ParameterMap* s_instance;
std::mutex m_paramMutex;
}; };
} }

View File

@ -7,20 +7,24 @@
namespace Navigator { namespace Navigator {
PhysicsLayer::PhysicsLayer() : PhysicsLayer::PhysicsLayer() :
m_activeFlag(false), m_source(nullptr) m_activeFlag(false), m_source(nullptr), m_physThread(nullptr)
{ {
} }
PhysicsLayer::~PhysicsLayer() PhysicsLayer::~PhysicsLayer()
{ {
DetachDataSource();
DestroyPhysThread();
} }
void PhysicsLayer::OnAttach() void PhysicsLayer::OnAttach()
{ {
/* For debugging
NavParameter par("joseph"); NavParameter par("joseph");
par.SetValue(8); par.SetValue(8);
NAV_INFO("Does the par exist? {0}", ParameterMap::GetInstance().IsParameterValid("joseph")); NAV_INFO("Does the par exist? {0}", ParameterMap::GetInstance().IsParameterValid("joseph"));
NAV_INFO("What is its value? {0}", ParameterMap::GetInstance().GetParameterValue("joseph")); NAV_INFO("What is its value? {0}", ParameterMap::GetInstance().GetParameterValue("joseph"));
*/
} }
void PhysicsLayer::OnDetach() void PhysicsLayer::OnDetach()
@ -36,6 +40,60 @@ namespace Navigator {
bool PhysicsLayer::OnPhysicsStartEvent(PhysicsStartEvent& event) bool PhysicsLayer::OnPhysicsStartEvent(PhysicsStartEvent& event)
{ {
if(m_activeFlag)
{
DetachDataSource();
DestroyPhysThread();
}
AttachDataSource(event);
if(m_activeFlag)
{
NAV_INFO("Starting new analysis thread...");
m_physThread = new std::thread(&PhysicsLayer::RunSource, std::ref(*this));
}
return true;
}
bool PhysicsLayer::OnPhysicsStopEvent(PhysicsStopEvent& event)
{
DetachDataSource();
DestroyPhysThread();
return true;
}
void PhysicsLayer::PushStage(AnalysisStage* stage)
{
m_physStack.PushStage(stage);
}
void PhysicsLayer::OnUpdate() {}
/*Threaded functions*/
void PhysicsLayer::DestroyPhysThread()
{
NAV_INFO("Destroying the analysis thread...");
if(m_physThread != nullptr && m_physThread->joinable())
{
m_physThread->join();
}
if(m_physThread != nullptr)
{
delete m_physThread;
m_physThread = nullptr;
}
NAV_INFO("Thread destroyed.");
}
void PhysicsLayer::AttachDataSource(PhysicsStartEvent& event)
{
std::lock_guard<std::mutex> guard(m_sourceMutex);
m_rawSort.SetCoincidenceWindow(event.GetCoincidenceWindow()); m_rawSort.SetCoincidenceWindow(event.GetCoincidenceWindow());
m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetSourceType())); m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetSourceType()));
if (m_source->IsValid()) if (m_source->IsValid())
@ -48,73 +106,66 @@ namespace Navigator {
NAV_ERROR("DataSource attach failed... check for error conditions."); NAV_ERROR("DataSource attach failed... check for error conditions.");
m_source.reset(nullptr); m_source.reset(nullptr);
} }
return true;
} }
bool PhysicsLayer::OnPhysicsStopEvent(PhysicsStopEvent& event) void PhysicsLayer::DetachDataSource()
{ {
std::lock_guard<std::mutex> guard(m_sourceMutex);
NAV_INFO("Detaching physics data source..."); NAV_INFO("Detaching physics data source...");
m_activeFlag = false; m_activeFlag = false;
m_source.reset(nullptr); m_source.reset(nullptr);
NAV_INFO("Detach succesful."); NAV_INFO("Detach succesful.");
return true;
} }
void PhysicsLayer::PushStage(AnalysisStage* stage) void PhysicsLayer::RunSource()
{
m_physStack.PushStage(stage);
}
void PhysicsLayer::OnUpdate()
{ {
HistogramMap& histMap = HistogramMap::GetInstance(); 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; CompassHit hit;
hit = m_source->GetData();
while(m_activeFlag)
{
{
std::lock_guard<std::mutex> guard(m_sourceMutex);
if (m_source == nullptr || !m_source->IsValid())
{
//NAV_WARN("Internal state of PhysicsEventBuilder not set properly! Either histogram map or data source not initialized!");
m_activeFlag = false;
return;
}
/*
Looks funny, but two conditions lead to !IsValid(). Either source prev. shutdown,
OR we reached end of source, indicated after prev. data grab
*/
hit = m_source->GetData();
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
Looks funny, but two conditions lead to !IsValid(). Either source prev. shutdown, ParameterMap::GetInstance().InvalidateParameters();
OR we reached end of source, indicated after prev. data grab m_rawSort.ClearRawPhysicsEvent();
*/ //Need to add hit in hand, start new event
if(!m_source->IsValid()) m_rawSort.AddHit(hit);
{ }
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);
}
} }
} }

View File

@ -10,6 +10,10 @@
#include "PhysicsHitSort.h" #include "PhysicsHitSort.h"
#include "DataSource.h" #include "DataSource.h"
#include <thread>
#include <mutex>
#include <atomic>
namespace Navigator { namespace Navigator {
class NAV_API PhysicsLayer : public Layer class NAV_API PhysicsLayer : public Layer
@ -29,13 +33,23 @@ namespace Navigator {
void PushStage(AnalysisStage* stage); void PushStage(AnalysisStage* stage);
private: private:
void DestroyPhysThread();
void AttachDataSource(PhysicsStartEvent& event);
void DetachDataSource();
void RunSource();
AnalysisStack m_physStack; AnalysisStack m_physStack;
bool m_activeFlag; std::atomic<bool> m_activeFlag;
PhysicsHitSort m_rawSort; PhysicsHitSort m_rawSort;
std::mutex m_sourceMutex;
std::unique_ptr<DataSource> m_source; std::unique_ptr<DataSource> m_source;
std::thread* m_physThread;
}; };
} }

View File

@ -1,6 +1,4 @@
#include "SpectrumSerializer.h" #include "SpectrumSerializer.h"
#include "HistogramMap.h"
#include "CutMap.h"
#include <fstream> #include <fstream>
@ -13,9 +11,9 @@ namespace Navigator {
SpectrumSerializer::~SpectrumSerializer() {} SpectrumSerializer::~SpectrumSerializer() {}
void SpectrumSerializer::SerializeData() void SpectrumSerializer::SerializeData(const std::vector<HistogramParameters>& histoList, const std::vector<CutParams>& cutList)
{ {
HistogramMap& histMap = HistogramMap::GetInstance(); //HistogramMap& histMap = HistogramMap::GetInstance();
CutMap& cutMap = CutMap::GetInstance(); CutMap& cutMap = CutMap::GetInstance();
std::ofstream output(m_filename); std::ofstream output(m_filename);
@ -26,31 +24,34 @@ namespace Navigator {
} }
output << "begin_cuts" << std::endl; output << "begin_cuts" << std::endl;
for (auto& iter : cutMap) for (auto& cut : cutList)
{ {
if (iter.second->Is1D()) if (cut.y_par == "None")
{ {
auto xpoints = cutMap.GetCutXPoints(cut.name);
output << "\tbegin_cut1D" << std::endl; output << "\tbegin_cut1D" << std::endl;
output << "\t\tname: " << iter.second->GetName() << std::endl; output << "\t\tname: " << cut.name << std::endl;
output << "\t\txparam: " << iter.second->GetXParameter() << std::endl; output << "\t\txparam: " << cut.x_par << std::endl;
output << "\t\tminValue: " << iter.second->GetXValues()[0] << std::endl; output << "\t\tminValue: " << xpoints[0] << std::endl;
output << "\t\tmaxValue: " << iter.second->GetXValues()[1] << std::endl; output << "\t\tmaxValue: " << xpoints[1] << std::endl;
output << "\tend_cut1D" << std::endl; output << "\tend_cut1D" << std::endl;
} }
else if (iter.second->Is2D()) else
{ {
auto xpoints = cutMap.GetCutXPoints(cut.name);
auto ypoints = cutMap.GetCutYPoints(cut.name);
output << "\tbegin_cut2D" << std::endl; output << "\tbegin_cut2D" << std::endl;
output << "\t\tname: " << iter.second->GetName() << std::endl; output << "\t\tname: " << cut.name << std::endl;
output << "\t\txparam: " << iter.second->GetXParameter() << std::endl; output << "\t\txparam: " << cut.x_par << std::endl;
output << "\t\typaram: " << iter.second->GetYParameter() << std::endl; output << "\t\typaram: " << cut.y_par << std::endl;
output << "\t\tbegin_xvalues" << std::endl; output << "\t\tbegin_xvalues" << std::endl;
for (const auto& value : iter.second->GetXValues()) for (const auto& value : xpoints)
{ {
output << "\t\t\t" << value << std::endl; output << "\t\t\t" << value << std::endl;
} }
output << "\t\tend_xvalues" << std::endl; output << "\t\tend_xvalues" << std::endl;
output << "\t\tbegin_yvalues" << std::endl; output << "\t\tbegin_yvalues" << std::endl;
for (const auto& value : iter.second->GetYValues()) for (const auto& value : ypoints)
{ {
output << "\t\t\t" << value << std::endl; output << "\t\t\t" << value << std::endl;
} }
@ -61,11 +62,10 @@ namespace Navigator {
output << "end_cuts" << std::endl; output << "end_cuts" << std::endl;
output << "begin_histograms" << std::endl; output << "begin_histograms" << std::endl;
for (auto& iter : histMap) for (auto& params : histoList)
{ {
if (iter.second->Is1D()) if (params.y_par == "None")
{ {
const auto& params = iter.second->GetParameters();
output << "\tbegin_histogram1D" << std::endl; output << "\tbegin_histogram1D" << std::endl;
output << "\t\tname: " << params.name << std::endl; output << "\t\tname: " << params.name << std::endl;
output << "\t\txparam: " << params.x_par << std::endl; output << "\t\txparam: " << params.x_par << std::endl;
@ -86,9 +86,8 @@ namespace Navigator {
output << "\t\tend_cutsapplied" << std::endl; output << "\t\tend_cutsapplied" << std::endl;
output << "\tend_histogram1D" << std::endl; output << "\tend_histogram1D" << std::endl;
} }
else if (iter.second->Is2D()) else
{ {
const auto& params = iter.second->GetParameters();
output << "\tbegin_histogram2D" << std::endl; output << "\tbegin_histogram2D" << std::endl;
output << "\t\tname: " << params.name << std::endl; output << "\t\tname: " << params.name << std::endl;
output << "\t\txparam: " << params.x_par << std::endl; output << "\t\txparam: " << params.x_par << std::endl;
@ -134,7 +133,6 @@ namespace Navigator {
std::string check; std::string check;
double value_doub; double value_doub;
int value_int;
CutParams cut_data, reset_cut; CutParams cut_data, reset_cut;
std::vector<double> cut_xdata; std::vector<double> cut_xdata;
std::vector<double> cut_ydata; std::vector<double> cut_ydata;

View File

@ -1,6 +1,9 @@
#ifndef SPECTRUM_SERIALIZER_H #ifndef SPECTRUM_SERIALIZER_H
#define SPECTRUM_SERIALIZER_H #define SPECTRUM_SERIALIZER_H
#include "HistogramMap.h"
#include "CutMap.h"
namespace Navigator { namespace Navigator {
class NAV_API SpectrumSerializer class NAV_API SpectrumSerializer
@ -9,7 +12,7 @@ namespace Navigator {
SpectrumSerializer(const std::string& filepath); SpectrumSerializer(const std::string& filepath);
~SpectrumSerializer(); ~SpectrumSerializer();
void SerializeData(); void SerializeData(const std::vector<HistogramParameters>& histoList, const std::vector<CutParams>& cutList);
void DeserializeData(); void DeserializeData();
inline const std::string& GetFilename() { return m_filename; } inline const std::string& GetFilename() { return m_filename; }

57
debug_spectra.nav Normal file
View File

@ -0,0 +1,57 @@
begin_cuts
begin_cut1D
name: joe_cut
xparam: joseph
minValue: 0
maxValue: 7
end_cut1D
begin_cut2D
name: joe2D_cut
xparam: joseph
yparam: joseph
begin_xvalues
1
3
3
1
1
end_xvalues
begin_yvalues
1
1
3
3
1
end_yvalues
end_cut2D
end_cuts
begin_histograms
begin_histogram1D
name: myHisto
xparam: joseph
Nxbins: 100
XMin: 0
XMax: 10
begin_cutsdrawn
joe_cut
end_cutsdrawn
begin_cutsapplied
end_cutsapplied
end_histogram1D
begin_histogram2D
name: myHisto2D
xparam: joseph
yparam: joseph
Nxbins: 100
XMin: 0
XMax: 10
Nybins: 100
YMin: 0
YMax: 10
begin_cutsdrawn
joe2D_cut
end_cutsdrawn
begin_cutsapplied
end_cutsapplied
end_histogram2D
end_histograms

View File

@ -140,7 +140,8 @@ project "NavProject"
objdir ("bin-int/" .. outputdir .. "/%{prj.name}") objdir ("bin-int/" .. outputdir .. "/%{prj.name}")
files { files {
"NavProject/main.cpp" "NavProject/*.h",
"NavProject/*.cpp"
} }
includedirs { includedirs {