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