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 // Constructor
40 : m_skip_list(folly::ConcurrentSkipList<T>::createInstance(unconfigured_head_height))
41 {
42 TLOG(TLVL_WORK_STEPS) << "Initializing non configured latency buffer";
43 }
44
45 // Iterator for SkipList
46 struct Iterator
47 {
48 using iterator_category = std::forward_iterator_tag;
49 using difference_type = std::ptrdiff_t;
50 using value_type = T;
51 using pointer = T*;
52 using reference = T&;
53
55 : m_acc(std::move(acc))
56 , m_iter(iter)
57 {}
58
59 reference operator*() const { return *m_iter; }
60 pointer operator->() { return &(*m_iter); }
61 Iterator& operator++() // NOLINT(runtime/increment_decrement) :)
62 {
63 m_iter++;
64 return *this;
65 }
66
67 friend bool operator==(const Iterator& a, const Iterator& b) { return a.m_iter == b.m_iter; }
68 friend bool operator!=(const Iterator& a, const Iterator& b) { return a.m_iter != b.m_iter; }
69
70 bool good() { return m_iter.good(); }
71
72
73private:
76 };
77
78 // Configure
79 void conf(const appmodel::LatencyBuffer* /*conf*/) override
80 {
81 // Reset datastructure
82 m_skip_list = folly::ConcurrentSkipList<T>::createInstance(unconfigured_head_height);
83 }
84
85 // Unconfigure
86 void scrap(const nlohmann::json& /*args*/) override
87 {
88 // RS -> Cross-check, we don't need to flush first?
89 m_skip_list = folly::ConcurrentSkipList<T>::createInstance(unconfigured_head_height);
90 }
91
92 // Get whole skip-list helper function
93 std::shared_ptr<SkipListT>& get_skip_list() { return std::ref(m_skip_list); }
94
95 // Override interface implementations
96 size_t occupancy() const override;
97 void flush() override { pop(occupancy()); }
98 bool write(T&& new_element) override;
99 bool put(T& new_element); // override
100 bool read(T& element) override;
101
102 void allocate_memory(size_t) override
103 {
104 TLOG(TLVL_DEBUG) << "SkipListLatencyBufferModel::allocate_memory not implemented.";
105 }
106
107 // Iterator support
108 Iterator begin();
109 Iterator end();
110 Iterator lower_bound(T& element, bool with_errors=false);
111
112 // Front/back accessors override
113 const T* front() override;
114 const T* back() override;
115
116 // Pop X override
117 void pop(size_t num = 1) override; // NOLINT(build/unsigned)
118protected:
119 virtual void generate_opmon_data() override;
120
121private:
122 // Concurrent SkipList
123 std::shared_ptr<SkipListT> m_skip_list;
124
125 // Configuration for datastructure head-hight
126 static constexpr uint32_t unconfigured_head_height = 2; // NOLINT(build/unsigned)
127};
128
129} // namespace datahandlinglibs
130} // namespace dunedaq
131
132// Declarations
134
135#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
void scrap(const nlohmann::json &) override
Unconfigure the LB.
bool read(T &element) override
Move object from LB to referenced.
bool write(T &&new_element) override
Move referenced object into 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
Including Qt Headers.