Commit 29e9ca97 authored by Jens Kroeger's avatar Jens Kroeger
Browse files

EventLoaderEUDAQ2: changed implementation of time-sorting from std::vector +...

EventLoaderEUDAQ2: changed implementation of time-sorting from std::vector + std::sort to std::priority_queue
parent 8e8b13ef
......@@ -132,29 +132,18 @@ std::shared_ptr<eudaq::StandardEvent> EventLoaderEUDAQ2::get_next_sorted_std_eve
LOG(DEBUG) << "Filling buffer with new event.";
// fill buffer with new std event:
auto new_event = get_next_std_event();
sorted_events_.push_back(new_event);
sorted_events_.push(new_event);
}
LOG(DEBUG) << "Timestamps in unsorted buffer:";
for(auto& ev : sorted_events_) {
LOG(DEBUG) << "\ttimestamp = " << Units::display(ev->GetTimeBegin() / 1000, {"us", "ns"}); // convert from ps to ns
}
// sort chronologically in time:
sort(sorted_events_.begin(),
sorted_events_.end(),
[](const std::shared_ptr<eudaq::StandardEvent> a, const std::shared_ptr<eudaq::StandardEvent> b) -> bool {
return a->GetTimeBegin() < b->GetTimeBegin();
});
LOG(DEBUG) << "Timestamps in sorted buffer:";
for(auto& ev : sorted_events_) {
LOG(DEBUG) << "\ttimestamp = " << Units::display(ev->GetTimeBegin() / 1000, {"us", "ns"}); // convert from ps to ns
}
// LOG(DEBUG) << "Timestamps in sorted buffer:";
// for(auto& ev : sorted_events_) {
// LOG(DEBUG) << "\ttimestamp = " << Units::display(ev->GetTimeBegin() / 1000, {"us", "ns"}); // convert from ps to
// ns
// }
// get first element of vector and erase it
auto stdevt = sorted_events_.front();
sorted_events_.erase(sorted_events_.begin());
// get first element of queue and erase it
auto stdevt = sorted_events_.top();
sorted_events_.pop();
return stdevt;
}
......
......@@ -96,8 +96,17 @@ namespace corryvreckan {
// Currently processed decoded EUDAQ StandardEvent:
std::shared_ptr<eudaq::StandardEvent> event_;
// Buffer of timesorted decoded EUDAQ StandardEvents:
std::vector<std::shared_ptr<eudaq::StandardEvent>> sorted_events_;
// custom comparator for time-sorted priority_queue
struct CompareTimeGreater {
bool operator()(const std::shared_ptr<eudaq::StandardEvent> a, const std::shared_ptr<eudaq::StandardEvent> b) {
return a->GetTimeBegin() > b->GetTimeBegin();
}
};
// Buffer of timesorted decoded EUDAQ StandardEvents: (need to use greater here!)
std::priority_queue<std::shared_ptr<eudaq::StandardEvent>,
std::vector<std::shared_ptr<eudaq::StandardEvent>>,
CompareTimeGreater>
sorted_events_;
// EUDAQ configuration to be passed to the decoder instance
eudaq::ConfigurationSPC eudaq_config_;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment