mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Better encapsulate data in Scalars and Variables.
This commit is contained in:
parent
632004b52e
commit
d34f5d676b
|
@ -26,7 +26,7 @@ namespace Specter {
|
||||||
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||||
|
|
||||||
//Report graphics status
|
//Report graphics status
|
||||||
SPEC_TRACE("Loaded OpenGL with glad Init status {0}", status);
|
SPEC_INFO("Loaded OpenGL with glad Init status {0}", status);
|
||||||
|
|
||||||
SPEC_INFO("Loaded OpenGL renderer");
|
SPEC_INFO("Loaded OpenGL renderer");
|
||||||
SPEC_INFO("Vendor: {0}", glGetString(GL_VENDOR));
|
SPEC_INFO("Vendor: {0}", glGetString(GL_VENDOR));
|
||||||
|
|
|
@ -64,6 +64,12 @@ namespace Specter {
|
||||||
//in the manager. To help with this, Variables are atomics. So unlike Parameters they are implicity thread safe on read and write.
|
//in the manager. To help with this, Variables are atomics. So unlike Parameters they are implicity thread safe on read and write.
|
||||||
//However, this does not mean they can be modified in the analysis! To the AnalysisStage they should be treated as constant, while the UI
|
//However, this does not mean they can be modified in the analysis! To the AnalysisStage they should be treated as constant, while the UI
|
||||||
//should view them as modifiable. These are real god damn dangerous, but I think the power they offer outweighs the risk, for now.
|
//should view them as modifiable. These are real god damn dangerous, but I think the power they offer outweighs the risk, for now.
|
||||||
|
struct VariableData
|
||||||
|
{
|
||||||
|
std::atomic<double> value = 0.0;
|
||||||
|
bool isValid = true;
|
||||||
|
};
|
||||||
|
|
||||||
class Variable
|
class Variable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -71,17 +77,28 @@ namespace Specter {
|
||||||
Variable(const std::string& name);
|
Variable(const std::string& name);
|
||||||
~Variable();
|
~Variable();
|
||||||
|
|
||||||
inline void SetValue(double value) { *(m_pdata) = value; }
|
inline void SetValue(double value) { m_pdata->value = value; }
|
||||||
inline double GetValue() { return *(m_pdata); }
|
inline double GetValue() { return m_pdata->value; }
|
||||||
inline const std::string& GetName() { return m_name; }
|
inline const std::string& GetName() { return m_name; }
|
||||||
void SetName(const std::string& name);
|
void SetName(const std::string& name);
|
||||||
|
|
||||||
friend class SpectrumManager;
|
friend class SpectrumManager;
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<std::atomic<double>> m_pdata;
|
std::shared_ptr<VariableData> m_pdata;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//Similar to parameters are scalers. Scalers are basically just counters tied to specific
|
||||||
|
//data channels in an experiment. They can be quite useful for checking the status of
|
||||||
|
//various experimental components. In our implementation, simply bind a Scaler as you would do for a
|
||||||
|
//Parameter, and then call the Increment() function when the appropriate data channel is present.
|
||||||
|
struct ScalerData
|
||||||
|
{
|
||||||
|
std::atomic<uint64_t> value;
|
||||||
|
bool isValid = true;
|
||||||
|
};
|
||||||
|
|
||||||
class Scaler
|
class Scaler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -89,15 +106,15 @@ namespace Specter {
|
||||||
Scaler(const std::string& name);
|
Scaler(const std::string& name);
|
||||||
~Scaler();
|
~Scaler();
|
||||||
|
|
||||||
inline void Increment() { ++(*m_pdata); }
|
inline void Increment() { ++(m_pdata->value); }
|
||||||
|
|
||||||
inline const std::string& GetName() { return m_name; }
|
inline const std::string& GetName() { return m_name; }
|
||||||
inline uint64_t GetCounts() { return *m_pdata; }
|
inline uint64_t GetCounts() { return m_pdata->value; }
|
||||||
void SetName(const std::string& name);
|
void SetName(const std::string& name);
|
||||||
|
|
||||||
friend class SpectrumManager;
|
friend class SpectrumManager;
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<std::atomic<uint64_t>> m_pdata;
|
std::shared_ptr<ScalerData> m_pdata;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -260,7 +260,7 @@ namespace Specter {
|
||||||
auto scalerIter = m_scalerMap.find(graph.second->GetScaler());
|
auto scalerIter = m_scalerMap.find(graph.second->GetScaler());
|
||||||
if (scalerIter != m_scalerMap.end())
|
if (scalerIter != m_scalerMap.end())
|
||||||
{
|
{
|
||||||
scalerVal = *(scalerIter->second);
|
scalerVal = scalerIter->second->value;
|
||||||
graph.second->UpdatePoints(step, scalerVal);
|
graph.second->UpdatePoints(step, scalerVal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ namespace Specter {
|
||||||
auto iter = m_varMap.find(var.GetName());
|
auto iter = m_varMap.find(var.GetName());
|
||||||
if (iter == m_varMap.end())
|
if (iter == m_varMap.end())
|
||||||
{
|
{
|
||||||
m_varMap[var.GetName()].reset(new std::atomic<double>(0.0));
|
m_varMap[var.GetName()].reset(new VariableData());
|
||||||
}
|
}
|
||||||
var.m_pdata = m_varMap[var.GetName()];
|
var.m_pdata = m_varMap[var.GetName()];
|
||||||
}
|
}
|
||||||
|
@ -409,7 +409,7 @@ namespace Specter {
|
||||||
auto iter = m_scalerMap.find(scaler.GetName());
|
auto iter = m_scalerMap.find(scaler.GetName());
|
||||||
if (iter == m_scalerMap.end())
|
if (iter == m_scalerMap.end())
|
||||||
{
|
{
|
||||||
m_scalerMap[scaler.GetName()].reset(new std::atomic<uint64_t>(0));
|
m_scalerMap[scaler.GetName()].reset(new ScalerData());
|
||||||
}
|
}
|
||||||
scaler.m_pdata = m_scalerMap[scaler.GetName()];
|
scaler.m_pdata = m_scalerMap[scaler.GetName()];
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ namespace Specter {
|
||||||
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
std::scoped_lock<std::mutex> guard(m_managerMutex);
|
||||||
for (auto& scaler : m_scalerMap)
|
for (auto& scaler : m_scalerMap)
|
||||||
{
|
{
|
||||||
*(scaler.second) = 0;
|
scaler.second->value = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,8 @@ namespace Specter {
|
||||||
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_histoMap;
|
std::unordered_map<std::string, std::shared_ptr<Histogram>> m_histoMap;
|
||||||
std::unordered_map<std::string, std::shared_ptr<Cut>> m_cutMap;
|
std::unordered_map<std::string, std::shared_ptr<Cut>> m_cutMap;
|
||||||
std::unordered_map<std::string, std::shared_ptr<ParameterData>> m_paramMap;
|
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<VariableData>> m_varMap;
|
||||||
std::unordered_map<std::string, std::shared_ptr<std::atomic<uint64_t>>> m_scalerMap;
|
std::unordered_map<std::string, std::shared_ptr<ScalerData>> m_scalerMap;
|
||||||
std::unordered_map<std::string, std::shared_ptr<ScalerGraph>> m_graphMap;
|
std::unordered_map<std::string, std::shared_ptr<ScalerGraph>> m_graphMap;
|
||||||
|
|
||||||
HistogramArgs m_nullHistoResult; //For handling bad query
|
HistogramArgs m_nullHistoResult; //For handling bad query
|
||||||
|
|
|
@ -141,7 +141,7 @@ namespace Specter {
|
||||||
for (auto& stage : m_physStack)
|
for (auto& stage : m_physStack)
|
||||||
stage->AnalyzePhysicsEvent(event);
|
stage->AnalyzePhysicsEvent(event);
|
||||||
|
|
||||||
//Now that the analysis stack has filled all our NavParameters with data, update the histogram counts
|
//Now that the analysis stack has filled all our Parameters with data, update the histogram counts
|
||||||
m_manager->UpdateHistograms();
|
m_manager->UpdateHistograms();
|
||||||
//Invalidate all parameters to get ready for next event
|
//Invalidate all parameters to get ready for next event
|
||||||
m_manager->InvalidateParameters();
|
m_manager->InvalidateParameters();
|
||||||
|
|
|
@ -52,9 +52,9 @@ namespace Specter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::mt19937& GetGenerator()
|
static std::mt19937_64& GetGenerator()
|
||||||
{
|
{
|
||||||
static thread_local std::mt19937 generator((std::random_device())());
|
static thread_local std::mt19937_64 generator((std::random_device())());
|
||||||
return generator;
|
return generator;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user