mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-23 02:38:52 -05:00
Attempted fix to handling the online CoMPASS data. No changes to CompassOnlineSource really, instead make event builder handle this. Now buffer up 100 hits, and then can optionally sort the hits. Hits glomed into events, and then passed to analysis chain.
This commit is contained in:
parent
224f6089e8
commit
5b39589c17
|
@ -77,9 +77,17 @@ namespace Navigator {
|
||||||
|
|
||||||
|
|
||||||
if (ImGui::Button("Ok"))
|
if (ImGui::Button("Ok"))
|
||||||
|
{
|
||||||
|
if (m_chosenType == DataSource::SourceType::CompassOffline)
|
||||||
{
|
{
|
||||||
PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort);
|
PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort);
|
||||||
Application::Get().OnEvent(event);
|
Application::Get().OnEvent(event);
|
||||||
|
}
|
||||||
|
else if (m_chosenType == DataSource::SourceType::CompassOnline)
|
||||||
|
{
|
||||||
|
PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort, true);
|
||||||
|
Application::Get().OnEvent(event);
|
||||||
|
}
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
|
@ -16,14 +16,15 @@ namespace Navigator {
|
||||||
class NAV_API PhysicsStartEvent : public Event
|
class NAV_API PhysicsStartEvent : public Event
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PhysicsStartEvent(const std::string& loc, DataSource::SourceType type, uint64_t window, const std::string& port = "51489") :
|
PhysicsStartEvent(const std::string& loc, DataSource::SourceType type, uint64_t window, const std::string& port = "51489", bool sortFlag=false) :
|
||||||
m_sourceLocation(loc), m_port(port), m_sourceType(type), m_coincidenceWindow(window)
|
m_sourceLocation(loc), m_port(port), m_sourceType(type), m_coincidenceWindow(window), m_sortFlag(sortFlag)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
inline std::string GetSourceLocation() { return m_sourceLocation; }
|
inline std::string GetSourceLocation() { return m_sourceLocation; }
|
||||||
inline std::string GetSourcePort() { return m_port; }
|
inline std::string GetSourcePort() { return m_port; }
|
||||||
inline DataSource::SourceType GetSourceType() { return m_sourceType; }
|
inline DataSource::SourceType GetSourceType() { return m_sourceType; }
|
||||||
inline uint64_t GetCoincidenceWindow() { return m_coincidenceWindow; }
|
inline uint64_t GetCoincidenceWindow() { return m_coincidenceWindow; }
|
||||||
|
inline bool GetSortFlag() { return m_sortFlag; }
|
||||||
|
|
||||||
std::string ToString() const override
|
std::string ToString() const override
|
||||||
{
|
{
|
||||||
|
@ -38,6 +39,7 @@ namespace Navigator {
|
||||||
std::string m_port;
|
std::string m_port;
|
||||||
DataSource::SourceType m_sourceType;
|
DataSource::SourceType m_sourceType;
|
||||||
uint64_t m_coincidenceWindow;
|
uint64_t m_coincidenceWindow;
|
||||||
|
bool m_sortFlag;
|
||||||
};
|
};
|
||||||
|
|
||||||
class NAV_API PhysicsStopEvent : public Event
|
class NAV_API PhysicsStopEvent : public Event
|
||||||
|
|
|
@ -44,7 +44,6 @@ namespace Navigator {
|
||||||
void GetHit();
|
void GetHit();
|
||||||
|
|
||||||
std::vector<char> m_currentBuffer;
|
std::vector<char> m_currentBuffer;
|
||||||
std::vector<char> m_fragment;
|
|
||||||
static constexpr int m_datasize = 24; //size of CoMPASS hit in bytes, change as needed (if for example you have calibrated energies)
|
static constexpr int m_datasize = 24; //size of CoMPASS hit in bytes, change as needed (if for example you have calibrated energies)
|
||||||
const int m_nchannels_per_board = 16; //IMPORTANT: Used for ID'ing channels uniquely. If you use boards with 32 or 8 or 64 channels you must change this! If you mix boards with
|
const int m_nchannels_per_board = 16; //IMPORTANT: Used for ID'ing channels uniquely. If you use boards with 32 or 8 or 64 channels you must change this! If you mix boards with
|
||||||
//different numbers of channels, you will have to find a different id solution.
|
//different numbers of channels, you will have to find a different id solution.
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
PhysicsEventBuilder::PhysicsEventBuilder(uint64_t windowSize) :
|
PhysicsEventBuilder::PhysicsEventBuilder(uint64_t windowSize) :
|
||||||
m_coincWindow(windowSize), m_eventStartTime(0)
|
m_sortFlag(false), m_coincWindow(windowSize), m_bufferIndex(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,36 +21,45 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsEventBuilder::AddDatumToEvent(const NavData& datum)
|
bool PhysicsEventBuilder::AddDatum(const NavData& datum)
|
||||||
{
|
{
|
||||||
NAV_PROFILE_FUNCTION();
|
NAV_PROFILE_FUNCTION();
|
||||||
if (datum.timestamp == 0) //Ignore empty data (need a valid timestamp)
|
if (datum.timestamp == 0) //Ignore empty data (need a valid timestamp)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (m_eventStartTime == 0) //first ever event
|
m_dataBuffer[m_bufferIndex] = datum;
|
||||||
{
|
m_bufferIndex++;
|
||||||
m_eventStartTime = datum.timestamp;
|
if (m_bufferIndex < s_maxDataBuffer) //If we haven't filled the buffer keep going
|
||||||
m_event.push_back(datum);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
else if (m_sortFlag)
|
||||||
else if (datum.timestamp - m_eventStartTime < m_coincWindow) //are we within active window
|
std::sort(m_dataBuffer.begin(), m_dataBuffer.end(), [](NavData& i, NavData& j) { return i.timestamp < j.timestamp; });
|
||||||
|
|
||||||
|
//Generate our ready events
|
||||||
|
m_readyEvents.clear();
|
||||||
|
uint64_t eventStartTime = m_dataBuffer[0].timestamp;
|
||||||
|
NavEvent event;
|
||||||
|
event.push_back(m_dataBuffer[0]);
|
||||||
|
for (auto& data : m_dataBuffer)
|
||||||
{
|
{
|
||||||
m_event.push_back(datum);
|
if (data.timestamp - eventStartTime < m_coincWindow) //are we within active window
|
||||||
return false;
|
{
|
||||||
|
event.push_back(data);
|
||||||
}
|
}
|
||||||
else // found one that falls outside
|
else // found one that falls outside
|
||||||
{
|
{
|
||||||
m_readyEvent = m_event;
|
m_readyEvents.push_back(event);
|
||||||
m_event.clear();
|
event.clear();
|
||||||
m_eventStartTime = datum.timestamp;
|
eventStartTime = data.timestamp;
|
||||||
m_event.push_back(datum);
|
event.push_back(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_bufferIndex = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const NavEvent& PhysicsEventBuilder::GetReadyEvent() const
|
const std::vector<NavEvent>& PhysicsEventBuilder::GetReadyEvents() const
|
||||||
{
|
{
|
||||||
return m_readyEvent;
|
return m_readyEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -21,20 +21,23 @@ namespace Navigator {
|
||||||
PhysicsEventBuilder(uint64_t windowSize);
|
PhysicsEventBuilder(uint64_t windowSize);
|
||||||
~PhysicsEventBuilder();
|
~PhysicsEventBuilder();
|
||||||
inline void SetCoincidenceWindow(uint64_t windowSize) { m_coincWindow = windowSize; }
|
inline void SetCoincidenceWindow(uint64_t windowSize) { m_coincWindow = windowSize; }
|
||||||
|
inline void SetSortFlag(bool flag) { m_sortFlag = flag; }
|
||||||
inline void ClearAll() // reset all internal structures
|
inline void ClearAll() // reset all internal structures
|
||||||
{
|
{
|
||||||
m_event.clear();
|
m_bufferIndex = 0;
|
||||||
m_readyEvent.clear();
|
m_readyEvents.clear();
|
||||||
m_eventStartTime = 0;
|
|
||||||
}
|
}
|
||||||
bool AddDatumToEvent(const NavData& datum);
|
bool AddDatum(const NavData& datum);
|
||||||
const NavEvent& GetReadyEvent() const;
|
const std::vector<NavEvent>& GetReadyEvents() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NavEvent m_event;
|
bool m_sortFlag;
|
||||||
NavEvent m_readyEvent;
|
static constexpr int s_maxDataBuffer = 100;
|
||||||
|
std::array<NavData, s_maxDataBuffer> m_dataBuffer;
|
||||||
|
int m_bufferIndex;
|
||||||
|
std::vector<NavEvent> m_readyEvents;
|
||||||
uint64_t m_coincWindow;
|
uint64_t m_coincWindow;
|
||||||
uint64_t m_eventStartTime;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,6 +116,7 @@ namespace Navigator {
|
||||||
std::scoped_lock<std::mutex> guard(m_sourceMutex); //Shouldn't matter for this, but safety first
|
std::scoped_lock<std::mutex> guard(m_sourceMutex); //Shouldn't matter for this, but safety first
|
||||||
m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetSourceType()));
|
m_source.reset(CreateDataSource(event.GetSourceLocation(), event.GetSourcePort(), event.GetSourceType()));
|
||||||
m_eventBuilder.SetCoincidenceWindow(event.GetCoincidenceWindow());
|
m_eventBuilder.SetCoincidenceWindow(event.GetCoincidenceWindow());
|
||||||
|
m_eventBuilder.SetSortFlag(event.GetSortFlag());
|
||||||
m_eventBuilder.ClearAll(); //Protect against stopping mid-event
|
m_eventBuilder.ClearAll(); //Protect against stopping mid-event
|
||||||
if (m_source->IsValid())
|
if (m_source->IsValid())
|
||||||
{
|
{
|
||||||
|
@ -144,7 +145,7 @@ namespace Navigator {
|
||||||
NAV_PROFILE_FUNCTION();
|
NAV_PROFILE_FUNCTION();
|
||||||
SpectrumManager& manager = SpectrumManager::GetInstance();
|
SpectrumManager& manager = SpectrumManager::GetInstance();
|
||||||
|
|
||||||
NavEvent event;
|
std::vector<NavEvent> events;
|
||||||
NavData datum;
|
NavData datum;
|
||||||
while(m_activeFlag)
|
while(m_activeFlag)
|
||||||
{
|
{
|
||||||
|
@ -167,10 +168,12 @@ namespace Navigator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Pass data from source to event builder. True from AddDatumToEvent indicates event is ready
|
//Pass data from source to event builder. True from AddDatum indicates events are ready
|
||||||
if (m_eventBuilder.AddDatumToEvent(datum))
|
if (m_eventBuilder.AddDatum(datum))
|
||||||
|
{
|
||||||
|
events = m_eventBuilder.GetReadyEvents();
|
||||||
|
for (auto& event : events)
|
||||||
{
|
{
|
||||||
event = m_eventBuilder.GetReadyEvent();
|
|
||||||
for (auto& stage : m_physStack)
|
for (auto& stage : m_physStack)
|
||||||
stage->AnalyzePhysicsEvent(event);
|
stage->AnalyzePhysicsEvent(event);
|
||||||
|
|
||||||
|
@ -181,4 +184,5 @@ namespace Navigator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user