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