mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Added HistogramMap class. Fixed ParameterMap usage, now isolated to the evb.
This commit is contained in:
parent
34bf7e741b
commit
13a7805cde
|
@ -10,7 +10,9 @@ int main(int argc, const char** argv)
|
|||
|
||||
auto app = Navigator::CreateApplication();
|
||||
auto evb = Navigator::CreatePhysicsEventBuilder();
|
||||
Navigator::Application::LinkHistogramMap();
|
||||
app->Run();
|
||||
|
||||
delete app;
|
||||
delete evb;
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
#include "Application.h"
|
||||
#include "ParameterMap.h"
|
||||
#include "Renderer/Renderer.h"
|
||||
#include "Renderer/RenderCommand.h"
|
||||
|
||||
|
@ -15,16 +14,10 @@ namespace Navigator {
|
|||
m_window = std::unique_ptr<Window>(Window::Create());
|
||||
m_window->SetEventCallback(BIND_EVENT_FUNCTION(Application::OnEvent));
|
||||
|
||||
/*order is important, must be pMap then evb*/
|
||||
CreateParameterMap();
|
||||
|
||||
NavParameter par("joseph","mama");
|
||||
par.SetValue(8);
|
||||
NAV_INFO("Does the par exist? {0}", ParameterMap::GetInstance().IsParameterValid("joseph"));
|
||||
NAV_INFO("What is its value? {0}", ParameterMap::GetInstance().GetParameterValue("joseph"));
|
||||
|
||||
PushLayer(new Layer());
|
||||
|
||||
m_histMap.AddHistogram("myHisto", "joseph", 100, 0, 10);
|
||||
|
||||
m_imgui_layer = new ImGuiLayer();
|
||||
PushOverlay(m_imgui_layer);
|
||||
}
|
||||
|
@ -111,6 +104,7 @@ namespace Navigator {
|
|||
{
|
||||
//PhysicsStartEvent junk("/media/gordon/GordonData/gwm17/NavTests/data/", DataSource::SourceType::CompassOffline, 2000000);
|
||||
//OnEvent(junk);
|
||||
m_histMap.UpdateHistograms();
|
||||
while(m_runFlag)
|
||||
{
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "Navigator/Window.h"
|
||||
#include "Navigator/ImGui/ImGuiLayer.h"
|
||||
#include "Navigator/Physics/PhysicsEventBuilder.h"
|
||||
#include "Navigator/HistogramMap.h"
|
||||
#include <thread>
|
||||
|
||||
namespace Navigator {
|
||||
|
@ -26,7 +27,10 @@ namespace Navigator {
|
|||
void PushLayer(Layer* layer);
|
||||
void PushOverlay(Layer* layer);
|
||||
|
||||
inline void AttachHistogramMap() { PhysicsEventBuilder::Get().AttachHistogramMap(&m_histMap); }
|
||||
|
||||
inline static Application& Get() { return *s_instance; }
|
||||
inline static void LinkHistogramMap() { s_instance->AttachHistogramMap(); }
|
||||
|
||||
inline Window& GetWindow() { return *m_window; }
|
||||
|
||||
|
@ -40,6 +44,7 @@ namespace Navigator {
|
|||
std::thread* m_physThread;
|
||||
|
||||
LayerStack m_stack;
|
||||
HistogramMap m_histMap;
|
||||
std::unique_ptr<Window> m_window;
|
||||
ImGuiLayer* m_imgui_layer;
|
||||
bool m_runFlag;
|
||||
|
|
|
@ -8,15 +8,19 @@ namespace Navigator {
|
|||
class NAV_API Histogram
|
||||
{
|
||||
public:
|
||||
Histogram() :
|
||||
m_name("None"), m_xParam("None"), m_yParam("None"), m_initFlag(false)
|
||||
{
|
||||
}
|
||||
Histogram(const std::string& name, const std::string& param_x, const std::string& param_y="None") :
|
||||
m_name(name), m_xParam(param_x), m_yParam(param_y), m_initFlag(false)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Histogram() {};
|
||||
virtual void FillData(double x, double y=0) = 0;
|
||||
virtual void Draw() = 0;
|
||||
virtual void ClearData() = 0;
|
||||
virtual void FillData(double x, double y = 0) { NAV_WARN("Trying to fill a default histogram!"); }
|
||||
virtual void Draw() {}
|
||||
virtual void ClearData() {}
|
||||
inline const std::string& GetXParam() const { return m_xParam; };
|
||||
inline const std::string& GetYParam() const { return m_yParam; };
|
||||
inline const std::string& GetName() const { return m_name; }
|
||||
|
|
57
Navigator/src/Navigator/HistogramMap.cpp
Normal file
57
Navigator/src/Navigator/HistogramMap.cpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#include "HistogramMap.h"
|
||||
#include "ParameterMap.h"
|
||||
|
||||
namespace Navigator {
|
||||
Navigator::HistogramMap::HistogramMap()
|
||||
{
|
||||
}
|
||||
|
||||
Navigator::HistogramMap::~HistogramMap()
|
||||
{
|
||||
}
|
||||
|
||||
void Navigator::HistogramMap::UpdateHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histMutex);
|
||||
std::string xpar, ypar;
|
||||
ParameterMap& pmap = ParameterMap::GetInstance();
|
||||
for (auto& pair : m_map)
|
||||
{
|
||||
xpar = pair.second->GetXParam();
|
||||
ypar = pair.second->GetYParam();
|
||||
|
||||
if (ypar == "None")
|
||||
{
|
||||
auto iter = pmap.find(xpar);
|
||||
if (iter == pmap.end() || !iter->second->validFlag)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
pair.second->FillData(iter->second->value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto iterx = pmap.find(xpar);
|
||||
auto itery = pmap.find(ypar);
|
||||
if (iterx == pmap.end() || itery == pmap.end() || !iterx->second->validFlag || !itery->second->validFlag)
|
||||
continue;
|
||||
else
|
||||
{
|
||||
pair.second->FillData(iterx->second->value, itery->second->value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Only to be used within ImGui context!!
|
||||
void Navigator::HistogramMap::DrawHistograms()
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_histMutex);
|
||||
for (auto& pair : m_map)
|
||||
pair.second->Draw();
|
||||
}
|
||||
}
|
40
Navigator/src/Navigator/HistogramMap.h
Normal file
40
Navigator/src/Navigator/HistogramMap.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef HISTOGRAM_MAP_H
|
||||
#define HISTOGRAM_MAP_H
|
||||
|
||||
#include "NavCore.h"
|
||||
#include "Histogram.h"
|
||||
#include <thread>
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
class NAV_API HistogramMap
|
||||
{
|
||||
public:
|
||||
|
||||
using Iter = std::unordered_map<std::string, std::unique_ptr<Histogram>>::iterator;
|
||||
|
||||
HistogramMap();
|
||||
~HistogramMap();
|
||||
|
||||
inline void AddHistogram(const std::string& name, const std::string& param, int bins, double min, double max) { m_map[name].reset(new Histogram1D(name, param, bins, min, max)); }
|
||||
inline void AddHistogram(const std::string& name, const std::string& paramx, const std::string& paramy, int bins_x, double min_x, double max_x,
|
||||
int bins_y, double min_y, double max_y)
|
||||
{
|
||||
m_map[name].reset(new Histogram2D(name, paramx, paramy, bins_x, min_x, max_x, bins_y, min_y, max_y));
|
||||
}
|
||||
|
||||
void UpdateHistograms();
|
||||
|
||||
void DrawHistograms();
|
||||
|
||||
inline Iter begin() { return m_map.begin(); }
|
||||
inline Iter end() { return m_map.end(); }
|
||||
|
||||
private:
|
||||
std::unordered_map<std::string, std::unique_ptr<Histogram>> m_map;
|
||||
std::mutex m_histMutex;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -60,4 +60,13 @@ namespace Navigator {
|
|||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void ParameterMap::InvalidateParameters()
|
||||
{
|
||||
for(auto& iter : m_map)
|
||||
{
|
||||
iter.second->validFlag = false;
|
||||
iter.second->value = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ namespace Navigator {
|
|||
inline void SetParameter(const std::string& name, std::shared_ptr<ParameterData>& param) { param = m_map[name]; }
|
||||
double GetParameterValue(const std::string& name);
|
||||
bool IsParameterValid(const std::string& name);
|
||||
void ResetParameters();
|
||||
void InvalidateParameters();
|
||||
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); }
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define ANALYSIS_STAGE_H
|
||||
|
||||
#include "Navigator/NavCore.h"
|
||||
#include "Navigator/ParameterMap.h"
|
||||
#include "CompassHit.h"
|
||||
|
||||
namespace Navigator {
|
||||
|
@ -16,8 +17,6 @@ namespace Navigator {
|
|||
|
||||
virtual void AnalyzeRawPhysicsEvent(const RawPhysicsEvent& event) {};
|
||||
|
||||
void AttachParameterMap() {};
|
||||
|
||||
inline std::string GetName() { return m_name; }
|
||||
private:
|
||||
std::string m_name;
|
||||
|
|
|
@ -1,16 +1,15 @@
|
|||
#include "PhysicsEventBuilder.h"
|
||||
#include "Navigator/ParameterMap.h"
|
||||
|
||||
//temp
|
||||
#include "CompassHit.h"
|
||||
|
||||
//GWM Jan. 3 2021 -- Make DataSource to unique ptr
|
||||
|
||||
namespace Navigator {
|
||||
|
||||
PhysicsEventBuilder* PhysicsEventBuilder::s_instance = nullptr;
|
||||
|
||||
PhysicsEventBuilder::PhysicsEventBuilder() :
|
||||
m_runFlag(false), m_source(nullptr)
|
||||
m_runFlag(false), m_source(nullptr), m_histMap(nullptr)
|
||||
{
|
||||
if(s_instance != nullptr)
|
||||
{
|
||||
|
@ -18,6 +17,13 @@ namespace Navigator {
|
|||
return;
|
||||
}
|
||||
s_instance = this;
|
||||
|
||||
CreateParameterMap();
|
||||
|
||||
NavParameter par("joseph", "mama");
|
||||
par.SetValue(8);
|
||||
NAV_INFO("Does the par exist? {0}", ParameterMap::GetInstance().IsParameterValid("joseph"));
|
||||
NAV_INFO("What is its value? {0}", ParameterMap::GetInstance().GetParameterValue("joseph"));
|
||||
}
|
||||
|
||||
PhysicsEventBuilder::~PhysicsEventBuilder()
|
||||
|
@ -64,6 +70,11 @@ namespace Navigator {
|
|||
{
|
||||
NAV_WARN("Trying to Run PhysicsEventBuilder without a Data Source, killing thread!");
|
||||
}
|
||||
else if (m_histMap == nullptr || m_source == nullptr)
|
||||
{
|
||||
NAV_WARN("Internal state of PhysicsEventBuilder not set properly! Either histogram map or data source not initialized!");
|
||||
return;
|
||||
}
|
||||
|
||||
CompassHit hit;
|
||||
|
||||
|
@ -105,7 +116,15 @@ namespace Navigator {
|
|||
//NAV_INFO("Obtaining built event...");
|
||||
auto event = m_rawSort.GetRawPhysicsEvent();
|
||||
//NAV_INFO("Built event size: {0}", event.size());
|
||||
for (auto& stage : m_physStack)
|
||||
stage->AnalyzeRawPhysicsEvent(event);
|
||||
m_histMap->UpdateHistograms();
|
||||
|
||||
//Cleanup to be ready for next event
|
||||
ParameterMap::GetInstance().InvalidateParameters();
|
||||
m_rawSort.ClearRawPhysicsEvent();
|
||||
//Need to add hit in hand, start new event
|
||||
m_rawSort.AddHit(hit);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define PHYSICS_EVENT_BUILDER_H
|
||||
|
||||
#include "Navigator/NavCore.h"
|
||||
#include "Navigator/HistogramMap.h"
|
||||
#include "AnalysisStack.h"
|
||||
#include "AnalysisStage.h"
|
||||
#include "PhysicsHitSort.h"
|
||||
|
@ -25,6 +26,7 @@ namespace Navigator {
|
|||
void SetCoincidenceWindow(uint64_t window) { m_rawSort.SetCoincidenceWindow(window); }
|
||||
void PushStage(AnalysisStage* stage);
|
||||
bool IsRunning() { return m_runFlag; }
|
||||
inline void AttachHistogramMap(HistogramMap* map) { m_histMap = map; }
|
||||
|
||||
static PhysicsEventBuilder& Get() { return *s_instance; }
|
||||
|
||||
|
@ -38,6 +40,8 @@ namespace Navigator {
|
|||
|
||||
std::unique_ptr<DataSource> m_source;
|
||||
|
||||
HistogramMap* m_histMap; //Not owned by PhysicsEventBuilder!
|
||||
|
||||
};
|
||||
|
||||
NAV_API PhysicsEventBuilder* CreatePhysicsEventBuilder();
|
||||
|
|
Loading…
Reference in New Issue
Block a user