DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
SkipListLatencyBufferModel.hpp
Go to the documentation of this file.
1
8#ifndef DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_SKIPLISTLATENCYBUFFERMODEL_HPP_
9#define DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_SKIPLISTLATENCYBUFFERMODEL_HPP_
10
14
15#include "logging/Logging.hpp"
16
17#include "folly/ConcurrentSkipList.h"
18
19#include <memory>
20#include <utility>
21
23
24namespace dunedaq {
25namespace datahandlinglibs {
26
27template<class T>
29{
30
31public:
32 // Using shorter Folly typenames
33 using SkipListT = typename folly::ConcurrentSkipList<T>;
34 using SkipListTIter = typename SkipListT::iterator;
35 using SkipListTAcc = typename folly::ConcurrentSkipList<T>::Accessor; // SKL Accessor
36 using SkipListTSkip = typename folly::ConcurrentSkipList<T>::Skipper; // Skipper accessor
37
38 static constexpr bool supports_delayed_postprocessing = true;
39
40 // Constructor
42 : m_skip_list(folly::ConcurrentSkipList<T>::createInstance(unconfigured_head_height))
43 {
44 TLOG(TLVL_WORK_STEPS) << "Initializing non configured latency buffer";
45 }
46
47 // Iterator for SkipList
48 struct Iterator
49 {
50 using iterator_category = std::forward_iterator_tag;
51 using difference_type = std::ptrdiff_t;
52 using value_type = T;
53 using pointer = T*;
54 using reference = T&;
55
57 : m_acc(std::move(acc))
58 , m_iter(iter)
59 {}
60
61 reference operator*() const { return *m_iter; }
62 pointer operator->() { return &(*m_iter); }
63 Iterator& operator++() // NOLINT(runtime/increment_decrement) :)
64 {
65 m_iter++;
66 return *this;
67 }
68
69 friend bool operator==(const Iterator& a, const Iterator& b) { return a.m_iter == b.m_iter; }
70 friend bool operator!=(const Iterator& a, const Iterator& b) { return a.m_iter != b.m_iter; }
71
72 bool good() { return m_iter.good(); }
73
74
75private:
78 };
79
80 // Configure
81 void conf(const appmodel::LatencyBuffer* /*conf*/) override
82 {
83 // Reset datastructure
84 m_skip_list = folly::ConcurrentSkipList<T>::createInstance(unconfigured_head_height);
85 }
86
87 // Unconfigure
88 void scrap(const appfwk::DAQModule::CommandData_t& /*args*/) override
89 {
90 // RS -> Cross-check, we don't need to flush first?
91 m_skip_list = folly::ConcurrentSkipList<T>::createInstance(unconfigured_head_height);
92 }
93
94 // Get whole skip-list helper function
95 std::shared_ptr<SkipListT>& get_skip_list() { return std::ref(m_skip_list); }
96
97 // Override interface implementations
98 size_t occupancy() const override;
99 void flush() override { pop(occupancy()); }
100 bool write(T&& new_element) override;
101 bool put(T& new_element); // override
102 bool read(T& element) override;
103
104 void allocate_memory(size_t) override
105 {
106 TLOG(TLVL_DEBUG) << "SkipListLatencyBufferModel::allocate_memory not implemented.";
107 }
108
109 // Iterator support
110 Iterator begin();
111 Iterator end();
112 Iterator lower_bound(T& element, bool with_errors=false);
113
114 // Front/back accessors override
115 const T* front() override;
116 const T* back() override;
117
118 // Pop X override
119 void pop(size_t num = 1) override; // NOLINT(build/unsigned)
120protected:
121 virtual void generate_opmon_data() override;
122
123private:
124 // Concurrent SkipList
125 std::shared_ptr<SkipListT> m_skip_list;
126
127 // Configuration for datastructure head-hight
128 static constexpr uint32_t unconfigured_head_height = 2; // NOLINT(build/unsigned)
129};
130
131} // namespace datahandlinglibs
132} // namespace dunedaq
133
134// Declarations
136
137#endif // DATAHANDLINGLIBS_INCLUDE_DATAHANDLINGLIBS_MODELS_SKIPLISTLATENCYBUFFERMODEL_HPP_
Iterator lower_bound(T &element, bool with_errors=false)
typename folly::ConcurrentSkipList< T >::Skipper SkipListTSkip
typename folly::ConcurrentSkipList< T >::Accessor SkipListTAcc
bool read(T &element) override
Move object from LB to referenced.
bool write(T &&new_element) override
Move referenced object into LB.
void scrap(const appfwk::DAQModule::CommandData_t &) override
Unconfigure the LB.
const T * back() override
Get pointer to the back of the LB.
void conf(const appmodel::LatencyBuffer *) override
Configure the LB.
void flush() override
Flush all elements from the latency buffer.
void allocate_memory(size_t) override
Whether or not the buffer is allocatable. false by default.
const T * front() override
Write referenced object into LB without moving it.
#define TLOG(...)
Definition macro.hpp:22
The DUNE-DAQ namespace.