DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
datahandlinglibs
include
datahandlinglibs
models
detail
BinarySearchQueueModel.hxx
Go to the documentation of this file.
1
// Declarations for BinarySearchQueueModel
2
3
namespace
dunedaq
{
4
namespace
datahandlinglibs
{
5
6
template
<
typename
T>
7
typename
IterableQueueModel<T>::Iterator
8
BinarySearchQueueModel<T>::lower_bound
(T& element,
bool
)
9
{
10
unsigned
int
start_index =
11
IterableQueueModel<T>::readIndex_
.load(std::memory_order_relaxed);
// NOLINT(build/unsigned)
12
unsigned
int
end_index =
13
IterableQueueModel<T>::writeIndex_
.load(std::memory_order_acquire);
// NOLINT(build/unsigned)
14
15
if
(start_index == end_index) {
16
TLOG
() <<
"Queue is empty"
<< std::endl;
17
return
IterableQueueModel<T>::end
();
18
}
19
end_index = end_index == 0 ?
IterableQueueModel<T>::size_
- 1 : end_index - 1;
20
21
T& left_element =
IterableQueueModel<T>::records_
[start_index];
22
23
if
(element < left_element) {
24
TLOG
() <<
"Could not find element"
<< std::endl;
25
return
IterableQueueModel<T>::end
();
26
}
27
28
while
(
true
) {
29
unsigned
int
diff =
30
start_index <= end_index ? end_index - start_index :
IterableQueueModel<T>::size_
+ end_index - start_index;
31
unsigned
int
middle_index = start_index + ((diff + 1) / 2);
32
if
(middle_index >=
IterableQueueModel<T>::size_
)
33
middle_index -=
IterableQueueModel<T>::size_
;
34
T& element_between =
IterableQueueModel<T>::records_
[middle_index];
35
36
//if we landed on our element, let's get out of here.
37
if
(element.get_timestamp()==element_between.get_timestamp())
38
return
typename
IterableQueueModel<T>::Iterator
(*
this
, middle_index);
39
40
if
( diff == 0 ) {
41
42
//if we satisfy the lower_bound condition, we have the right index
43
if
(element < element_between)
44
return
typename
IterableQueueModel<T>::Iterator
(*
this
, middle_index);
45
46
//if we don't, we need to increment one up. for safety check size too
47
if
(++middle_index >=
IterableQueueModel<T>::size_
)
48
middle_index -=
IterableQueueModel<T>::size_
;
49
50
return
typename
IterableQueueModel<T>::Iterator
(*
this
, middle_index);
51
}
52
53
if
(element < element_between) {
54
end_index = middle_index != 0 ? middle_index - 1 :
IterableQueueModel<T>::size_
- 1;
55
}
else
{
56
start_index = middle_index;
57
}
58
}
59
}
60
61
}
// namespace datahandlinglibs
62
}
// namespace dunedaq
dunedaq::datahandlinglibs::BinarySearchQueueModel::lower_bound
IterableQueueModel< T >::Iterator lower_bound(T &element, bool=false)
Definition
BinarySearchQueueModel.hxx:8
TLOG
#define TLOG(...)
Definition
macro.hpp:22
dunedaq::datahandlinglibs
Definition
DataHandlingConcept.hpp:16
dunedaq
Including Qt Headers.
Definition
module.cpp:16
dunedaq::datahandlinglibs::IterableQueueModel::Iterator
Definition
IterableQueueModel.hpp:213
dunedaq::datahandlinglibs::IterableQueueModel::size_
uint32_t size_
Definition
IterableQueueModel.hpp:314
dunedaq::datahandlinglibs::IterableQueueModel::end
Iterator end()
Definition
IterableQueueModel.hpp:278
dunedaq::datahandlinglibs::IterableQueueModel::readIndex_
std::atomic< unsigned int > readIndex_
Definition
IterableQueueModel.hpp:317
dunedaq::datahandlinglibs::IterableQueueModel::records_
T * records_
Definition
IterableQueueModel.hpp:315
dunedaq::datahandlinglibs::IterableQueueModel::writeIndex_
std::atomic< unsigned int > writeIndex_
Definition
IterableQueueModel.hpp:319
Generated on
for DUNE-DAQ by
1.17.0