Falcon
Loading...
Searching...
No Matches
eventfilter.hpp
1// ---------------------------------------------------------------------
2// This file is part of falcon-core.
3//
4// Copyright (C) 2015, 2016, 2017 Neuro-Electronics Research Flanders
5//
6// Falcon-server is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10//
11// Falcon-server is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with falcon-core. If not, see <http://www.gnu.org/licenses/>.
18// ---------------------------------------------------------------------
19
20#pragma once
21
22#include <chrono>
23#include <limits>
24#include <tuple>
25#include <vector>
26
27#include "eventsync/eventsync.hpp"
28#include "options/options.hpp"
29#include "utilities/time.hpp"
30
31class DetectionCriterionValue : public options::Value<SlotType, false> {
32 public:
33 using options::Value<SlotType, false>::Value;
34 void from_yaml(const YAML::Node& node) override;
35};
36
37class EventFilter : public EventSync {
38 // CONSTRUCTOR and OVERLOADED METHODS
39 public:
40 EventFilter();
41 void CreatePorts() override;
42 void Prepare(GlobalContext& context) override;
43 void Preprocess(ProcessingContext& context) override;
44 void Process(ProcessingContext& context) override;
45 void Postprocess(ProcessingContext& context) override;
46
47 // METHODS
48 protected:
49 /* Check for every slot after a read on the input port if a target is found
50 * @input input_port input port to read
51 * @input event_counter structure with three counters (all received, target,
52 * non target) updated when meeting events
53 * @input arrival_times keep track of every event arrival in the processor
54 * @input arrival_timestamps keeps track of every event timestamp hardware
55 *
56 * @return the alive status of the processor, the flag of found target and
57 * the timestamp of the target event detected
58 */
59 std::tuple<bool, bool, std::size_t> is_there_target(PortIn<EventType>* input_port,
60 EventCounter& event_counter,
61 std::vector<TimePoint>& arrival_times,
62 std::vector<uint64_t>& arrival_timestamps);
63
64 // return time in milliseconds past from two given time points t1 and t2
65 inline double time_between(TimePoint t2, TimePoint t1) {
66 duration = t2 - t1;
67 return duration.count();
68 }
69
70 // return the time in milliseconds past from a given time point t
71 inline double time_since(TimePoint t) { return time_between(Clock::now(), t); }
72
73 // DATA PORTS
74 protected:
75 PortIn<EventType>* block_in_port_;
76
77 // VARIABLES
78 protected:
79 unsigned int n_blocked_events_;
80 EventCounter blocking_events_counter_;
81 TimePoint gate_close_time_;
82 std::chrono::duration<double, std::milli> duration;
83
84 // CONSTANTS
85 protected:
86 const uint64_t NULL_TIMESTAMP = std::numeric_limits<uint64_t>::max();
87
88 // OPTIONS
89 protected:
90 options::Measurement<double, false> blockout_time_{10., "ms", options::positive<double>()};
91
92 options::Measurement<double, false> block_wait_time_{1.5, "ms", options::positive<double>()};
93
94 options::Measurement<double, false> sync_time_{3.5, "ms", options::positive<double>()};
95
96 options::Bool discard_warnings_{false};
97 DetectionCriterionValue detections_to_criterion_{1};
98};
Definition eventfilter.hpp:31
Definition context.hpp:54
IPortIn * input_port(const std::string &port)
Definition iprocessor.hpp:318
Definition streamports.hpp:256
Definition runinfo.hpp:248