DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
oks
src
index.cpp
Go to the documentation of this file.
1
// DUNE DAQ modification notice:
2
// This file has been modified from the original ATLAS oks source for the DUNE DAQ project.
3
// Fork baseline commit: oks-08-03-04 (2022-04-14).
4
// Renamed since fork: no.
5
6
#define _OksBuildDll_
7
8
#include "
oks/index.hpp
"
9
#include "
oks/attribute.hpp
"
10
#include "
oks/class.hpp
"
11
12
namespace
dunedaq
{
13
namespace
oks
{
14
15
size_t
16
OksIndex::get_offset
(
OksClass
*cl,
OksAttribute
*
a
)
17
{
18
OksDataInfo::Map::const_iterator x = cl->
p_data_info
->find(
a
->p_name);
19
return
(x == cl->
p_data_info
->end()) ? 0 : x->second->offset;
20
}
21
22
23
OksIndex::OksIndex
(
OksClass
*cl,
OksAttribute
*attr) :
24
std
::multiset<
OksObject
*,
OksObjectSortBy
> (
get_offset
(cl, attr)),
25
c
(cl),
26
a
(attr)
27
{
28
const
char
* fname =
"OksIndex::OksIndex(OksClass *, OksAttribute *"
;
29
30
if
(!
c
) {
31
Oks::error_msg
(fname) <<
"Can't build index for NIL class\n"
;
32
return
;
33
}
34
35
if
(
c
->get_is_abstract()) {
36
Oks::error_msg(fname)
37
<<
"Can't build index for ABSTRACT class \""
<< c->get_name() <<
"\"\n"
;
38
return;
39
}
40
41
if
(!
a
) {
42
Oks::error_msg(fname) <<
"Can't build index for NIL attribute\n"
;
43
return;
44
}
45
46
if
(
c
->find_attribute(
a
->get_name()) == 0) {
47
Oks::error_msg(fname)
48
<<
"Can't find attribute \""
<< a->p_name <<
"\" in class \""
49
<< c->get_name() <<
"\" to build index.\n"
;
50
return;
51
}
52
53
if
(
c
->p_indices &&
c
->p_indices->find(
a
) !=
c
->p_indices->end()) {
54
Oks::error_msg(fname)
55
<<
"Class \""
<< c->get_name() <<
"\" already has index for attribute \""
56
<< a->p_name <<
"\".\n"
;
57
return;
58
}
59
60
offset
= ((*
c
->p_data_info)[
a
->p_name])->offset;
61
62
if
(!
c
->p_indices)
63
c
->p_indices =
new
OksIndex::Map
();
64
65
(*
c
->p_indices)[
a
] =
this
;
66
67
if
(
c
->p_objects && !
c
->p_objects->empty()) {
68
for(OksObject::Map::iterator i = c->p_objects->begin(); i != c->p_objects->end(); ++i)
69
insert((*i).second);
70
}
71
72
std::cout <<
"Build index for attribute \'"
<<
a
->p_name <<
"\' in class \'"
<<
c
->get_name()
73
<<
"\' for "
<<
size
() <<
" instances\n"
;
74
75
#ifdef DEBUG_INDICES
76
for
(
int
j=0; j<entries(); j++) {
77
OksObject
*
obj
= at(j);
78
79
std::cout << j <<
".\tobject id \'"
<<
obj
->GetId() <<
"\' "
80
<<
"\tvalue: \'"
<<
obj
->data[
offset
] <<
"\'\n"
;
81
}
82
#endif
83
}
84
85
OksIndex::~OksIndex
()
86
{
87
if
(
c
&&
a
) {
88
c
->p_indices->erase(
a
);
89
90
if
(
c
->p_indices->empty()) {
91
delete
c
->p_indices;
92
c
->p_indices = 0;
93
}
94
}
95
}
96
97
98
OksObject
*
99
OksIndex::remove_obj
(
OksObject
*o)
100
{
101
std::pair<Position, Position> positions = equal_range(o);
102
Position
i = positions.first;
103
Position
i2 = positions.second;
104
105
for
(; i != i2; ++i) {
106
if
(o == *i) {
107
erase(i);
108
return
o;
109
}
110
}
111
112
return
0;
113
}
114
115
116
OksObject
*
117
OksIndex::FindFirst
(
OksData
*d)
const
118
{
119
OksObject
test_o(
offset
, d);
120
121
ConstPosition
pos = lower_bound(&test_o);
122
123
if
(pos != end())
return
*pos;
124
125
return
0;
126
}
127
128
129
void
130
OksIndex::find_interval
(
OksData
*d,
OksQuery::Comparator
f,
ConstPosition
& i1,
ConstPosition
& i2)
const
131
{
132
i1 = i2 = end();
133
134
if
(empty())
return
;
135
136
OksObject
test_o(
offset
, d);
137
138
if
(f ==
OksQuery::equal_cmp
) {
139
i1 = lower_bound(&test_o);
140
141
if
(i1 != end()) {
142
if
((*i1)->data[
offset
] == *d) {
143
i2 = upper_bound(&test_o);
144
}
145
else
{
146
i2 = i1;
147
}
148
}
149
}
150
else
if
(f ==
OksQuery::less_or_equal_cmp
|| f ==
OksQuery::less_cmp
) {
151
i1 = begin();
152
153
if
(f ==
OksQuery::less_cmp
) {
154
i2 = lower_bound(&test_o);
155
}
156
else
{
157
i2 = upper_bound(&test_o);
158
}
159
}
160
else
if
(f ==
OksQuery::greater_or_equal_cmp
|| f ==
OksQuery::greater_cmp
) {
161
i2 = end();
162
163
if
(f ==
OksQuery::greater_cmp
) {
164
i1 = upper_bound(&test_o);
165
}
166
else
{
167
i1 = lower_bound(&test_o);
168
}
169
}
170
}
171
172
173
OksObject::List
*
174
OksIndex::find_all
(
OksData
*d,
OksQuery::Comparator
f)
const
175
{
176
OksObject::List
* olist = 0;
177
178
ConstPosition
pos1, pos2;
179
180
find_interval
(d, f, pos1, pos2);
181
182
if
(pos1 != pos2) {
183
olist =
new
OksObject::List
();
184
for
(;pos1 != pos2; ++pos1) olist->push_back(*pos1);
185
}
186
187
return
olist;
188
}
189
190
191
OksObject::List
*
192
OksIndex::find_all
(
bool
andOperation,
OksData
*d1,
OksQuery::Comparator
f1,
OksData
*d2,
OksQuery::Comparator
f2)
const
193
{
194
OksObject::List
* olist = 0;
195
196
ConstPosition
a1, b1;
197
198
find_interval
(d1, f1, a1, b1);
199
200
if
((andOperation ==
true
) && (a1 == b1))
return
0;
201
202
ConstPosition
a2, b2;
203
204
find_interval
(d2, f2, a2, b2);
205
206
if
(andOperation ==
true
) {
207
if
(a2 == b2)
return
0;
208
209
210
//
211
// find intersection ([pos1,pos2] or NIL) of [a1,b1] and [a2,b2]
212
// where begin() <= {a1,b1,a2,b2} <= end())
213
//
214
// (note that a1 and a2 are not equal to end() but b1 nad b2 have to be tested)
215
//
216
217
ConstPosition
pos1, pos2;
218
219
if
((*a2)->data[
offset
] <= (*a1)->data[
offset
]) {
220
if
((b2 != end()) && ((*b2)->data[
offset
] < (*a1)->data[
offset
]))
return
0;
221
pos1 = a1;
222
}
223
else
{
224
if
((b1 != end()) && (*a2)->data[
offset
] > (*b1)->data[
offset
])
return
0;
225
pos1 = a2;
226
}
227
228
if
(b2 == end() || b1 == end()) {
229
pos2 = (b2 != end()) ? b2 : b1;
230
}
231
else
232
pos2 = ((*b2)->data[
offset
] <= (*b1)->data[
offset
]) ? b2 : b1;
233
234
olist =
new
OksObject::List
();
235
for
(;pos1 != pos2; ++pos1) olist->push_back(*pos1);
236
}
237
else
{
238
if
(a1 != b1 && a2 == b2) {
239
olist =
new
OksObject::List
();
240
for
(;a1 != b1; ++a1) olist->push_back(*a1);
241
}
242
else
if
(a2 != b2 && a1 == b1) {
243
olist =
new
OksObject::List
();
244
for
(;a2 != b2; ++a2) olist->push_back(*a2);
245
}
246
else
if
(a1 != b1 && a2 != b2) {
247
olist =
new
OksObject::List
();
248
249
250
//
251
// find union of [a1,b1] and [a2,b2] (i.e. [pos1,pos2] or [a1,b1],[a2,b2])
252
// where begin() <= {a1,b1,a2,b2} <= end())
253
//
254
// (note that a1 and a2 are not equal to end() but b1 nad b2 have to be tested)
255
//
256
257
ConstPosition
pos1, pos2;
258
259
if
((*a2)->data[
offset
] <= (*a1)->data[
offset
]) {
260
if
(b2 != end() && (*b2)->data[
offset
] < (*a1)->data[
offset
]) {
261
for
(;a2 != b2; ++a2) olist->push_back(*a2);
262
for
(;a1 != b1; ++a1) olist->push_back(*a1);
263
264
return
olist;
265
}
266
267
pos1 = a2;
268
}
269
else
{
270
if
(b1 != end() && (*a2)->data[
offset
] > (*b1)->data[
offset
]) {
271
for
(;a1 != b1; ++a1) olist->push_back(*a1);
272
for
(;a2 != b2; ++a2) olist->push_back(*a2);
273
274
return
olist;
275
}
276
277
pos1 = a1;
278
}
279
280
if
(b2 == end() || b1 == end()) {
281
pos2 = (b2 == end()) ? b2 : b1;
282
}
283
else
284
pos2 = ((*b2)->data[
offset
] >= (*b1)->data[
offset
]) ? b2 : b1;
285
286
for
(;pos1 != pos2; ++pos1) olist->push_back(*pos1);
287
}
288
}
289
290
return
olist;
291
}
292
293
}
// namespace oks
294
}
// namespace dunedaq
attribute.hpp
class.hpp
dunedaq::oks::OksAttribute
OKS attribute class.
Definition
attribute.hpp:107
dunedaq::oks::OksClass::p_data_info
OksDataInfo::Map * p_data_info
Definition
class.hpp:962
dunedaq::oks::OksIndex::get_offset
static size_t get_offset(OksClass *, OksAttribute *)
Definition
index.cpp:16
dunedaq::oks::OksIndex::OksClass
friend class OksClass
Definition
index.hpp:36
dunedaq::oks::OksIndex::ConstPosition
std::multiset< OksObject *, OksObjectSortBy >::const_iterator ConstPosition
Definition
index.hpp:53
dunedaq::oks::OksIndex::~OksIndex
~OksIndex()
Definition
index.cpp:85
dunedaq::oks::OksIndex::Position
std::multiset< OksObject *, OksObjectSortBy >::iterator Position
Definition
index.hpp:52
dunedaq::oks::OksIndex::a
OksAttribute * a
Definition
index.hpp:89
dunedaq::oks::OksIndex::c
OksClass * c
Definition
index.hpp:88
dunedaq::oks::OksIndex::FindFirst
OksObject * FindFirst(OksData *d) const
Definition
index.cpp:117
dunedaq::oks::OksIndex::Map
std::map< const OksAttribute *, OksIndex *, SortByName > Map
Definition
index.hpp:50
dunedaq::oks::OksIndex::remove_obj
OksObject * remove_obj(OksObject *)
Definition
index.cpp:99
dunedaq::oks::OksIndex::find_all
OksObject::List * find_all(OksData *, OksQuery::Comparator) const
Definition
index.cpp:174
dunedaq::oks::OksIndex::OksObject
friend class OksObject
Definition
index.hpp:37
dunedaq::oks::OksIndex::offset
size_t offset
Definition
index.hpp:90
dunedaq::oks::OksIndex::OksIndex
OksIndex(OksClass *, OksAttribute *)
Definition
index.cpp:23
dunedaq::oks::OksIndex::find_interval
void find_interval(OksData *, OksQuery::Comparator, ConstPosition &, ConstPosition &) const
Definition
index.cpp:130
dunedaq::oks::OksObjectSortBy
Definition
index.hpp:17
dunedaq::oks::OksObject
OksObject describes instance of OksClass.
Definition
object.hpp:841
dunedaq::oks::OksObject::List
std::list< OksObject * > List
Definition
object.hpp:880
dunedaq::oks::OksQuery::equal_cmp
static bool equal_cmp(const OksData *, const OksData *)
Definition
query.cpp:56
dunedaq::oks::OksQuery::greater_cmp
static bool greater_cmp(const OksData *, const OksData *)
Definition
query.cpp:61
dunedaq::oks::OksQuery::less_or_equal_cmp
static bool less_or_equal_cmp(const OksData *, const OksData *)
Definition
query.cpp:58
dunedaq::oks::OksQuery::greater_or_equal_cmp
static bool greater_or_equal_cmp(const OksData *, const OksData *)
Definition
query.cpp:59
dunedaq::oks::OksQuery::less_cmp
static bool less_cmp(const OksData *, const OksData *)
Definition
query.cpp:60
dunedaq::oks::OksQuery::Comparator
bool(* Comparator)(const OksData *, const OksData *)
Definition
query.hpp:93
dunedaq::oks::Oks::error_msg
static std::ostream & error_msg(const char *)
Definition
kernel.cpp:561
index.hpp
dunedaq
Including Qt Headers.
Definition
module.cpp:16
dunedaq::obj
msgpack::object obj
Definition
Serialization.hpp:257
dunedaq::size
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size
Definition
FelixIssues.hpp:28
oks
Definition
ral.hpp:35
std
Definition
SchemaUtils.hpp:118
dunedaq::oks::OksData
the structure to pass common parameters to various read() methods of OksData and OksObject class
Definition
object.hpp:454
Generated on
for DUNE-DAQ by
1.17.0