Commit d7e6f68b authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'EventLoaderEUDAQ2_time_sorting' into 'master'

EventLoaderEUDAQ2: time sorting

See merge request !128
parents 8f26af3f d5d205a7
Pipeline #1026126 passed with stages
in 24 minutes and 34 seconds
......@@ -19,6 +19,7 @@ EventLoaderEUDAQ2::EventLoaderEUDAQ2(Configuration config, std::shared_ptr<Detec
m_get_time_residuals = m_config.get<bool>("get_time_residuals", false);
m_skip_time = m_config.get("skip_time", 0.);
m_adjust_event_times = m_config.getMatrix<std::string>("adjust_event_times", {});
m_buffer_depth = m_config.get<int>("buffer_depth", 0);
// Forward all settings to EUDAQ
// WARNING: the EUDAQ Configuration class is not very flexible and e.g. booleans have to be passed as 1 and 0.
......@@ -128,10 +129,24 @@ void EventLoaderEUDAQ2::initialise() {
}
}
std::shared_ptr<eudaq::StandardEvent> EventLoaderEUDAQ2::get_next_event() {
std::shared_ptr<eudaq::StandardEvent> stdevt;
bool decoding_failed = true;
std::shared_ptr<eudaq::StandardEvent> EventLoaderEUDAQ2::get_next_sorted_std_event() {
while(static_cast<int>(sorted_events_.size()) < m_buffer_depth) {
LOG(DEBUG) << "Filling buffer with new event.";
// fill buffer with new std event:
auto new_event = get_next_std_event();
sorted_events_.push(new_event);
}
// get first element of queue and erase it
auto stdevt = sorted_events_.top();
sorted_events_.pop();
return stdevt;
}
std::shared_ptr<eudaq::StandardEvent> EventLoaderEUDAQ2::get_next_std_event() {
auto stdevt = eudaq::StandardEvent::MakeShared();
bool decoding_failed = true;
do {
// Create new StandardEvent
stdevt = eudaq::StandardEvent::MakeShared();
......@@ -322,7 +337,13 @@ StatusCode EventLoaderEUDAQ2::run(std::shared_ptr<Clipboard> clipboard) {
// Retrieve next event from file/buffer:
if(!event_) {
try {
event_ = get_next_event();
if(m_buffer_depth == 0) {
// simply get next decoded EUDAQ StandardEvent from buffer
event_ = get_next_std_event();
} else {
// get next decoded EUDAQ StandardEvent from timesorted buffer
event_ = get_next_sorted_std_event();
}
} catch(EndOfFile&) {
return StatusCode::EndRun;
}
......
......@@ -59,10 +59,14 @@ namespace corryvreckan {
StatusCode run(std::shared_ptr<Clipboard> clipboard);
private:
/**
* @brief Read and return the next decoded StandardEvent (smallest possible granularity) from timesorted buffer
*/
std::shared_ptr<eudaq::StandardEvent> get_next_sorted_std_event();
/**
* @brief Read and return the next event (smallest possible granularity) and return the decoded StandardEvent
*/
std::shared_ptr<eudaq::StandardEvent> get_next_event();
std::shared_ptr<eudaq::StandardEvent> get_next_std_event();
/**
* @brief Check whether the current EUDAQ StandardEvent is within the defined Corryvreckan event
......@@ -84,6 +88,7 @@ namespace corryvreckan {
bool m_get_time_residuals;
double m_skip_time{};
Matrix<std::string> m_adjust_event_times;
int m_buffer_depth;
// EUDAQ file reader instance to retrieve data from
eudaq::FileReaderUP reader_;
......@@ -92,6 +97,18 @@ namespace corryvreckan {
// Currently processed decoded EUDAQ StandardEvent:
std::shared_ptr<eudaq::StandardEvent> event_;
// 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_;
......
......@@ -70,6 +70,8 @@ Also, more complex constructs such as arrays or matrices read by the Corryvrecka
* `skip_time`: Time that can be skipped at the start of a run. Default is `0ms`.
* `get_time_residuals`: Boolean to change if time residual plots should be outputted. Default value is `false`.
* `adjust_event_times`: Matrix that allows the user to shift the event start/end of all different types of EUDAQ events. The first entry of each row specifies the data type, the second is the offset which is added to the event start and the third entry is the offset added to the event end. A usage example is shown below. Default is `0ms, 0ms`, `"other"` is just a placeholder.
* `do_timesorting`: Boolean to enable timesorting of EUDAQ2 StandardEvents. This algorithm only works for StandardEvents with well-defined timestamps. Default is `false`.
* `buffer_depth`: Depth of buffer in which EUDAQ2 `StandardEvents` are timesorted. This algorithm only works for `StandardEvents` with well-defined timestamps. Setting it to `0` disables timesorting. Default is `0`.
### Plots produced
* 2D hitmap
......@@ -100,4 +102,5 @@ file_name = /path/to/data/examplerun_clicpix2.raw
type = "MIMOSA26"
file_name = /path/to/data/examplerun_telescope.raw
adjust_event_times = ["TluRawDataEvent", -115us, +230us], ["other", 0ns, 0ns]
buffer_depth = 1000
```
......@@ -267,7 +267,7 @@ StatusCode Tracking4D::run(std::shared_ptr<Clipboard> clipboard) {
<< Units::display(track_timestamp, "us") << " to track.";
track->setTimestamp(track_timestamp);
} else {
LOG(ERROR) << "Cannot asign timestamp to track. Use average cluster timestamp for track or set detector to "
LOG(ERROR) << "Cannot assign timestamp to track. Use average cluster timestamp for track or set detector to "
"set track timestamp. Please update the configuration file.";
return StatusCode::Failure;
}
......
Markdown is supported
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