mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-26 12:18:51 -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
|
@ -78,8 +78,16 @@ namespace Navigator {
|
|||
|
||||
if (ImGui::Button("Ok"))
|
||||
{
|
||||
PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort);
|
||||
Application::Get().OnEvent(event);
|
||||
if (m_chosenType == DataSource::SourceType::CompassOffline)
|
||||
{
|
||||
PhysicsStartEvent event(m_chosenLocation, m_chosenType, m_chosenWindow, m_chosenPort);
|
||||
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::SameLine();
|
||||
|
|
|
@ -16,14 +16,15 @@ namespace Navigator {
|
|||
class NAV_API PhysicsStartEvent : public Event
|
||||
{
|
||||
public:
|
||||
PhysicsStartEvent(const std::string& loc, DataSource::SourceType type, uint64_t window, const std::string& port = "51489") :
|
||||
m_sourceLocation(loc), m_port(port), m_sourceType(type), m_coincidenceWindow(window)
|
||||
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_sortFlag(sortFlag)
|
||||
{}
|
||||
|
||||
inline std::string GetSourceLocation() { return m_sourceLocation; }
|
||||
inline std::string GetSourcePort() { return m_port; }
|
||||
inline DataSource::SourceType GetSourceType() { return m_sourceType; }
|
||||
inline uint64_t GetCoincidenceWindow() { return m_coincidenceWindow; }
|
||||
inline bool GetSortFlag() { return m_sortFlag; }
|
||||
|
||||
std::string ToString() const override
|
||||
{
|
||||
|
@ -38,6 +39,7 @@ namespace Navigator {
|
|||
std::string m_port;
|
||||
DataSource::SourceType m_sourceType;
|
||||
uint64_t m_coincidenceWindow;
|
||||
bool m_sortFlag;
|
||||
};
|
||||
|
||||
class NAV_API PhysicsStopEvent : public Event
|
||||
|
|
|
@ -44,7 +44,6 @@ namespace Navigator {
|
|||
void GetHit();
|
||||
|
||||
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)
|
||||
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.
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
namespace Navigator {
|
||||
|
||||
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();
|
||||
if (datum.timestamp == 0) //Ignore empty data (need a valid timestamp)
|
||||
return false;
|
||||
|
||||
if (m_eventStartTime == 0) //first ever event
|
||||
{
|
||||
m_eventStartTime = datum.timestamp;
|
||||
m_event.push_back(datum);
|
||||
m_dataBuffer[m_bufferIndex] = datum;
|
||||
m_bufferIndex++;
|
||||
if (m_bufferIndex < s_maxDataBuffer) //If we haven't filled the buffer keep going
|
||||
return false;
|
||||
}
|
||||
else if (datum.timestamp - m_eventStartTime < m_coincWindow) //are we within active window
|
||||
else if (m_sortFlag)
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
else // found one that falls outside
|
||||
{
|
||||
m_readyEvent = m_event;
|
||||
m_event.clear();
|
||||
m_eventStartTime = datum.timestamp;
|
||||
m_event.push_back(datum);
|
||||
return true;
|
||||
if (data.timestamp - eventStartTime < m_coincWindow) //are we within active window
|
||||
{
|
||||
event.push_back(data);
|
||||
}
|
||||
else // found one that falls outside
|
||||
{
|
||||
m_readyEvents.push_back(event);
|
||||
event.clear();
|
||||
eventStartTime = data.timestamp;
|
||||
event.push_back(data);
|
||||
}
|
||||
}
|
||||
m_bufferIndex = 0;
|
||||
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();
|
||||
inline void SetCoincidenceWindow(uint64_t windowSize) { m_coincWindow = windowSize; }
|
||||
inline void SetSortFlag(bool flag) { m_sortFlag = flag; }
|
||||
inline void ClearAll() // reset all internal structures
|
||||
{
|
||||
m_event.clear();
|
||||
m_readyEvent.clear();
|
||||
m_eventStartTime = 0;
|
||||
m_bufferIndex = 0;
|
||||
m_readyEvents.clear();
|
||||
}
|
||||
bool AddDatumToEvent(const NavData& datum);
|
||||
const NavEvent& GetReadyEvent() const;
|
||||
bool AddDatum(const NavData& datum);
|
||||
const std::vector<NavEvent>& GetReadyEvents() const;
|
||||
|
||||
private:
|
||||
NavEvent m_event;
|
||||
NavEvent m_readyEvent;
|
||||
bool m_sortFlag;
|
||||
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_eventStartTime;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ namespace Navigator {
|
|||
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_eventBuilder.SetCoincidenceWindow(event.GetCoincidenceWindow());
|
||||
m_eventBuilder.SetSortFlag(event.GetSortFlag());
|
||||
m_eventBuilder.ClearAll(); //Protect against stopping mid-event
|
||||
if (m_source->IsValid())
|
||||
{
|
||||
|
@ -144,7 +145,7 @@ namespace Navigator {
|
|||
NAV_PROFILE_FUNCTION();
|
||||
SpectrumManager& manager = SpectrumManager::GetInstance();
|
||||
|
||||
NavEvent event;
|
||||
std::vector<NavEvent> events;
|
||||
NavData datum;
|
||||
while(m_activeFlag)
|
||||
{
|
||||
|
@ -167,17 +168,20 @@ namespace Navigator {
|
|||
}
|
||||
}
|
||||
|
||||
//Pass data from source to event builder. True from AddDatumToEvent indicates event is ready
|
||||
if (m_eventBuilder.AddDatumToEvent(datum))
|
||||
//Pass data from source to event builder. True from AddDatum indicates events are ready
|
||||
if (m_eventBuilder.AddDatum(datum))
|
||||
{
|
||||
event = m_eventBuilder.GetReadyEvent();
|
||||
for (auto& stage : m_physStack)
|
||||
stage->AnalyzePhysicsEvent(event);
|
||||
|
||||
//Now that the analysis stack has filled all our NavParameters with data, update the histogram counts
|
||||
manager.UpdateHistograms();
|
||||
//Invalidate all parameters to get ready for next event
|
||||
manager.InvalidateParameters();
|
||||
events = m_eventBuilder.GetReadyEvents();
|
||||
for (auto& event : events)
|
||||
{
|
||||
for (auto& stage : m_physStack)
|
||||
stage->AnalyzePhysicsEvent(event);
|
||||
|
||||
//Now that the analysis stack has filled all our NavParameters with data, update the histogram counts
|
||||
manager.UpdateHistograms();
|
||||
//Invalidate all parameters to get ready for next event
|
||||
manager.InvalidateParameters();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user