mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Added in scaler graphing class (ScalerGraph) and implemented in the manager. Next step to forge into UI.
This commit is contained in:
parent
da33a550e3
commit
a4c731f100
42
Navigator/src/Navigator/Core/Graph.cpp
Normal file
42
Navigator/src/Navigator/Core/Graph.cpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include "Graph.h"
|
||||
#include "implot.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
ScalerGraph::ScalerGraph(const GraphArgs& args) :
|
||||
m_args(args), m_lastScalerVal(0)
|
||||
{
|
||||
m_xPoints.reserve(m_args.maxPoints);
|
||||
m_xPoints.reserve(m_args.maxPoints);
|
||||
}
|
||||
|
||||
ScalerGraph::~ScalerGraph() {}
|
||||
|
||||
void ScalerGraph::UpdatePoints(double timeStep, uint64_t scalerVal)
|
||||
{
|
||||
double rate = (scalerVal - m_lastScalerVal) / timeStep;
|
||||
if (m_xPoints.size() < m_args.maxPoints)
|
||||
{
|
||||
m_xPoints.push_back(timeStep);
|
||||
m_yPoints.push_back(rate);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < (m_args.maxPoints - 1); i++)
|
||||
{
|
||||
m_xPoints[i] = m_xPoints[i + 1];
|
||||
m_yPoints[i] = m_yPoints[i + 1];
|
||||
}
|
||||
m_xPoints[m_args.maxPoints - 1] = timeStep;
|
||||
m_yPoints[m_args.maxPoints - 1] = rate;
|
||||
}
|
||||
|
||||
m_lastScalerVal = scalerVal;
|
||||
}
|
||||
|
||||
void ScalerGraph::Draw()
|
||||
{
|
||||
ImPlot::SetupAxes("time (s)", "rate (Hz)");
|
||||
ImPlot::PlotLine(m_args.name.c_str(), m_xPoints.data(), m_yPoints.data(), m_xPoints.size());
|
||||
}
|
||||
}
|
41
Navigator/src/Navigator/Core/Graph.h
Normal file
41
Navigator/src/Navigator/Core/Graph.h
Normal file
|
@ -0,0 +1,41 @@
|
|||
#ifndef GRAPH_H
|
||||
#define GRAPH_H
|
||||
|
||||
#include <queue>
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
struct GraphArgs
|
||||
{
|
||||
std::string name;
|
||||
std::string scalerName;
|
||||
size_t maxPoints;
|
||||
};
|
||||
|
||||
class ScalerGraph
|
||||
{
|
||||
public:
|
||||
ScalerGraph(const GraphArgs& args);
|
||||
~ScalerGraph();
|
||||
|
||||
void UpdatePoints(double timeStep, uint64_t scalerVal);
|
||||
void Draw();
|
||||
inline void Clear() { m_xPoints.clear(); m_yPoints.clear(); }
|
||||
|
||||
inline const std::string& GetName() const { return m_args.name; }
|
||||
inline const std::string& GetScaler() const { return m_args.scalerName; }
|
||||
inline const GraphArgs& GetArgs() const { return m_args; }
|
||||
|
||||
private:
|
||||
|
||||
GraphArgs m_args;
|
||||
|
||||
uint64_t m_lastScalerVal;
|
||||
|
||||
std::vector<double> m_yPoints;
|
||||
std::vector<double> m_xPoints;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -239,6 +239,78 @@ namespace Navigator {
|
|||
|
||||
/*************Histogram Functions End*************/
|
||||
|
||||
/*************Graph Functions Begin*************/
|
||||
|
||||
void SpectrumManager::AddGraph(const GraphArgs& args)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
m_graphMap[args.name].reset(new ScalerGraph(args));
|
||||
}
|
||||
|
||||
void SpectrumManager::RemoveGraph(const std::string& name)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
m_graphMap.erase(name);
|
||||
}
|
||||
|
||||
void SpectrumManager::UpdateGraphs(const Timestep& step)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
uint64_t scalerVal;
|
||||
for (auto& graph : m_graphMap)
|
||||
{
|
||||
auto& scalerIter = m_scalerMap.find(graph.second->GetScaler());
|
||||
if (scalerIter != m_scalerMap.end())
|
||||
{
|
||||
scalerVal = *(scalerIter->second);
|
||||
graph.second->UpdatePoints(step, scalerVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpectrumManager::ClearGraphs()
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
for (auto& graph : m_graphMap)
|
||||
graph.second->Clear();
|
||||
}
|
||||
|
||||
void SpectrumManager::ClearGraph(const std::string& name)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
auto& iter = m_graphMap.find(name);
|
||||
if (iter != m_graphMap.end())
|
||||
iter->second->Clear();
|
||||
}
|
||||
|
||||
void SpectrumManager::DrawGraph(const std::string& name)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
auto& iter = m_graphMap.find(name);
|
||||
if (iter != m_graphMap.end())
|
||||
iter->second->Draw();
|
||||
}
|
||||
|
||||
const GraphArgs& SpectrumManager::GetGraphArgs(const std::string& name)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
auto& iter = m_graphMap.find(name);
|
||||
if (iter != m_graphMap.end())
|
||||
return iter->second->GetArgs();
|
||||
return m_nullGraphResult;
|
||||
}
|
||||
|
||||
std::vector<GraphArgs> SpectrumManager::GetListOfGraphs()
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
std::vector<GraphArgs> list;
|
||||
list.reserve(m_graphMap.size());
|
||||
for (auto& graph : m_graphMap)
|
||||
list.push_back(graph.second->GetArgs());
|
||||
return list;
|
||||
}
|
||||
|
||||
/*************Graph Functions End*************/
|
||||
|
||||
/*************Parameter Functions Begin*************/
|
||||
|
||||
|
@ -366,6 +438,24 @@ namespace Navigator {
|
|||
|
||||
/*************Cut Functions Begin*************/
|
||||
|
||||
void SpectrumManager::AddCut(const CutArgs& params, double min, double max)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap[params.name].reset(new Cut1D(params, min, max));
|
||||
}
|
||||
|
||||
void SpectrumManager::AddCut(const CutArgs& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap[params.name].reset(new Cut2D(params, xpoints, ypoints));
|
||||
}
|
||||
|
||||
void SpectrumManager::AddCut(const CutArgs& params, const std::vector<std::string>& subhistos, double min, double max)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap[params.name].reset(new CutSummary(params, subhistos, min, max));
|
||||
}
|
||||
|
||||
void SpectrumManager::RemoveCut(const std::string& name)
|
||||
{
|
||||
NAV_PROFILE_FUNCTION();
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#include "Histogram.h"
|
||||
#include "Cut.h"
|
||||
#include "Parameter.h"
|
||||
#include "Graph.h"
|
||||
#include "Timestep.h"
|
||||
|
||||
#include <thread>
|
||||
|
||||
|
@ -55,6 +57,17 @@ namespace Navigator {
|
|||
std::vector<HistogramArgs> GetListOfHistograms();
|
||||
/********************/
|
||||
|
||||
/*ScalerGraph Functions*/
|
||||
void AddGraph(const GraphArgs& args);
|
||||
void RemoveGraph(const std::string& name);
|
||||
void UpdateGraphs(const Timestep& step);
|
||||
void ClearGraphs();
|
||||
void ClearGraph(const std::string& name);
|
||||
void DrawGraph(const std::string& name);
|
||||
const GraphArgs& GetGraphArgs(const std::string& name);
|
||||
std::vector<GraphArgs> GetListOfGraphs();
|
||||
/********************/
|
||||
|
||||
/*Parameter Functions*/
|
||||
void BindParameter(Parameter& param);
|
||||
void BindParameter(Parameter& param, int nbins, double maxVal, double minVal);
|
||||
|
@ -74,21 +87,9 @@ namespace Navigator {
|
|||
/******************/
|
||||
|
||||
/*Cut Functions*/
|
||||
inline void AddCut(const CutArgs& params, double min, double max)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap[params.name].reset(new Cut1D(params, min, max));
|
||||
}
|
||||
inline void AddCut(const CutArgs& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap[params.name].reset(new Cut2D(params, xpoints, ypoints));
|
||||
}
|
||||
inline void AddCut(const CutArgs& params, const std::vector<std::string>& subhistos, double min, double max)
|
||||
{
|
||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||
m_cutMap[params.name].reset(new CutSummary(params, subhistos, min, max));
|
||||
}
|
||||
void AddCut(const CutArgs& params, double min, double max);
|
||||
void AddCut(const CutArgs& params, const std::vector<double>& xpoints, const std::vector<double>& ypoints);
|
||||
void AddCut(const CutArgs& params, const std::vector<std::string>& subhistos, double min, double max);
|
||||
void RemoveCut(const std::string& name);
|
||||
std::vector<double> GetCutXPoints(const std::string& name);
|
||||
std::vector<double> GetCutYPoints(const std::string& name);
|
||||
|
@ -112,8 +113,10 @@ namespace Navigator {
|
|||
std::unordered_map<std::string, std::shared_ptr<ParameterData>> m_paramMap;
|
||||
std::unordered_map<std::string, std::shared_ptr<std::atomic<double>>> m_varMap;
|
||||
std::unordered_map<std::string, std::shared_ptr<std::atomic<uint64_t>>> m_scalerMap;
|
||||
std::unordered_map<std::string, std::shared_ptr<ScalerGraph>> m_graphMap;
|
||||
|
||||
HistogramArgs m_nullHistoResult; //For handling bad query
|
||||
GraphArgs m_nullGraphResult; //For handling bad query
|
||||
|
||||
std::mutex m_managerMutex; //synchronization
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Navigator {
|
|||
|
||||
void SetTime(float time) { m_time = time; }
|
||||
|
||||
operator float() { return m_time; }
|
||||
operator float() const { return m_time; }
|
||||
|
||||
float GetElapsedSeconds() const { return m_time; }
|
||||
float GetElapsedMilliseconds() const { return m_time * 1000.0f; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user