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

Better encapsulate data in Scalars and Variables.

This commit is contained in:
Gordon McCann 2022-11-06 15:38:00 -05:00
parent 632004b52e
commit d34f5d676b
6 changed files with 33 additions and 16 deletions

View File

@ -26,7 +26,7 @@ namespace Specter {
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
//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("Vendor: {0}", glGetString(GL_VENDOR));

View File

@ -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.
//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.
struct VariableData
{
std::atomic<double> value = 0.0;
bool isValid = true;
};
class Variable
{
public:
@ -71,17 +77,28 @@ namespace Specter {
Variable(const std::string& name);
~Variable();
inline void SetValue(double value) { *(m_pdata) = value; }
inline double GetValue() { return *(m_pdata); }
inline void SetValue(double value) { m_pdata->value = value; }
inline double GetValue() { return m_pdata->value; }
inline const std::string& GetName() { return m_name; }
void SetName(const std::string& name);
friend class SpectrumManager;
private:
std::shared_ptr<std::atomic<double>> m_pdata;
std::shared_ptr<VariableData> m_pdata;
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
{
public:
@ -89,15 +106,15 @@ namespace Specter {
Scaler(const std::string& name);
~Scaler();
inline void Increment() { ++(*m_pdata); }
inline void Increment() { ++(m_pdata->value); }
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);
friend class SpectrumManager;
private:
std::shared_ptr<std::atomic<uint64_t>> m_pdata;
std::shared_ptr<ScalerData> m_pdata;
std::string m_name;
};

View File

@ -260,7 +260,7 @@ namespace Specter {
auto scalerIter = m_scalerMap.find(graph.second->GetScaler());
if (scalerIter != m_scalerMap.end())
{
scalerVal = *(scalerIter->second);
scalerVal = scalerIter->second->value;
graph.second->UpdatePoints(step, scalerVal);
}
}
@ -385,7 +385,7 @@ namespace Specter {
auto iter = m_varMap.find(var.GetName());
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()];
}
@ -409,7 +409,7 @@ namespace Specter {
auto iter = m_scalerMap.find(scaler.GetName());
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()];
@ -427,7 +427,7 @@ namespace Specter {
std::scoped_lock<std::mutex> guard(m_managerMutex);
for (auto& scaler : m_scalerMap)
{
*(scaler.second) = 0;
scaler.second->value = 0;
}
}

View File

@ -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<Cut>> m_cutMap;
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<VariableData>> m_varMap;
std::unordered_map<std::string, std::shared_ptr<ScalerData>> m_scalerMap;
std::unordered_map<std::string, std::shared_ptr<ScalerGraph>> m_graphMap;
HistogramArgs m_nullHistoResult; //For handling bad query

View File

@ -141,7 +141,7 @@ namespace Specter {
for (auto& stage : m_physStack)
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();
//Invalidate all parameters to get ready for next event
m_manager->InvalidateParameters();

View File

@ -52,9 +52,9 @@ namespace Specter {
}
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;
}
};