DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dunedaq::oks::OksIndex Class Reference

#include <index.hpp>

Inheritance diagram for dunedaq::oks::OksIndex:
[legend]
Collaboration diagram for dunedaq::oks::OksIndex:
[legend]

Classes

struct  SortByName

Public Types

typedef std::map< const OksAttribute *, OksIndex *, SortByNameMap
typedef std::multiset< OksObject *, OksObjectSortBy >::iterator Position
typedef std::multiset< OksObject *, OksObjectSortBy >::const_iterator ConstPosition

Public Member Functions

 OksIndex (OksClass *, OksAttribute *)
 ~OksIndex ()
OksObjectFindFirst (OksData *d) const
OksObject::ListFindEqual (OksData *d) const
OksObject::ListFindLessEqual (OksData *d) const
OksObject::ListFindGreatEqual (OksData *d) const
OksObject::ListFindLess (OksData *d) const
OksObject::ListFindGreat (OksData *d) const
OksObject::ListFindLessAndGreat (OksData *d1, OksData *d2) const
OksObject::ListFindLessAndGreatEqual (OksData *d1, OksData *d2) const
OksObject::ListFindLessEqualAndGreat (OksData *d1, OksData *d2) const
OksObject::ListFindLessEqualAndGreatEqual (OksData *d1, OksData *d2) const
OksObject::ListFindEqualAndEqual (OksData *d1, OksData *d2) const
OksObject::ListFindEqualAndLess (OksData *d1, OksData *d2) const
OksObject::ListFindEqualAndLessEqual (OksData *d1, OksData *d2) const
OksObject::ListFindEqualAndGreat (OksData *d1, OksData *d2) const
OksObject::ListFindEqualAndGreatEqual (OksData *d1, OksData *d2) const
OksObject::ListFindLessOrGreat (OksData *d1, OksData *d2) const
OksObject::ListFindLessOrGreatEqual (OksData *d1, OksData *d2) const
OksObject::ListFindLessEqualOrGreat (OksData *d1, OksData *d2) const
OksObject::ListFindLessEqualOrGreatEqual (OksData *d1, OksData *d2) const
OksObject::ListFindEqualOrEqual (OksData *d1, OksData *d2) const
OksObject::ListFindEqualOrLess (OksData *d1, OksData *d2) const
OksObject::ListFindEqualOrLessEqual (OksData *d1, OksData *d2) const
OksObject::ListFindEqualOrGreat (OksData *d1, OksData *d2) const
OksObject::ListFindEqualOrGreatEqual (OksData *d1, OksData *d2) const

Private Member Functions

OksObjectremove_obj (OksObject *)
OksObject::Listfind_all (OksData *, OksQuery::Comparator) const
OksObject::Listfind_all (bool, OksData *, OksQuery::Comparator, OksData *, OksQuery::Comparator) const
void find_interval (OksData *, OksQuery::Comparator, ConstPosition &, ConstPosition &) const

Static Private Member Functions

static size_t get_offset (OksClass *, OksAttribute *)

Private Attributes

OksClassc
OksAttributea
size_t offset

Friends

class OksClass
class OksObject

Detailed Description

Definition at line 35 of file index.hpp.

Member Typedef Documentation

◆ ConstPosition

typedef std::multiset<OksObject*,OksObjectSortBy>::const_iterator dunedaq::oks::OksIndex::ConstPosition

Definition at line 53 of file index.hpp.

◆ Map

Definition at line 50 of file index.hpp.

◆ Position

typedef std::multiset<OksObject*,OksObjectSortBy>::iterator dunedaq::oks::OksIndex::Position

Definition at line 52 of file index.hpp.

Constructor & Destructor Documentation

◆ OksIndex()

dunedaq::oks::OksIndex::OksIndex ( OksClass * cl,
OksAttribute * attr )

Definition at line 23 of file index.cpp.

23 :
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}
static size_t get_offset(OksClass *, OksAttribute *)
Definition index.cpp:16
OksAttribute * a
Definition index.hpp:89
std::map< const OksAttribute *, OksIndex *, SortByName > Map
Definition index.hpp:50
friend class OksObject
Definition index.hpp:37
static std::ostream & error_msg(const char *)
Definition kernel.cpp:561
msgpack::object obj
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size

◆ ~OksIndex()

dunedaq::oks::OksIndex::~OksIndex ( )

Definition at line 85 of file index.cpp.

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}

Member Function Documentation

◆ find_all() [1/2]

OksObject::List * dunedaq::oks::OksIndex::find_all ( bool andOperation,
OksData * d1,
OksQuery::Comparator f1,
OksData * d2,
OksQuery::Comparator f2 ) const
private

Definition at line 192 of file index.cpp.

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}
std::multiset< OksObject *, OksObjectSortBy >::const_iterator ConstPosition
Definition index.hpp:53
void find_interval(OksData *, OksQuery::Comparator, ConstPosition &, ConstPosition &) const
Definition index.cpp:130
std::list< OksObject * > List
Definition object.hpp:880

◆ find_all() [2/2]

OksObject::List * dunedaq::oks::OksIndex::find_all ( OksData * d,
OksQuery::Comparator f ) const
private

Definition at line 174 of file index.cpp.

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}

◆ find_interval()

void dunedaq::oks::OksIndex::find_interval ( OksData * d,
OksQuery::Comparator f,
ConstPosition & i1,
ConstPosition & i2 ) const
private

Definition at line 130 of file index.cpp.

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 }
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}
static bool equal_cmp(const OksData *, const OksData *)
Definition query.cpp:56
static bool greater_cmp(const OksData *, const OksData *)
Definition query.cpp:61
static bool less_or_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:58
static bool greater_or_equal_cmp(const OksData *, const OksData *)
Definition query.cpp:59
static bool less_cmp(const OksData *, const OksData *)
Definition query.cpp:60

◆ FindEqual()

OksObject::List * dunedaq::oks::OksIndex::FindEqual ( OksData * d) const
inline

Definition at line 61 of file index.hpp.

61{return find_all(d, OksQuery::equal_cmp);}
OksObject::List * find_all(OksData *, OksQuery::Comparator) const
Definition index.cpp:174

◆ FindEqualAndEqual()

OksObject::List * dunedaq::oks::OksIndex::FindEqualAndEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 71 of file index.hpp.

71{return find_all(true, d1, OksQuery::equal_cmp, d2, OksQuery::equal_cmp);}

◆ FindEqualAndGreat()

OksObject::List * dunedaq::oks::OksIndex::FindEqualAndGreat ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 74 of file index.hpp.

◆ FindEqualAndGreatEqual()

OksObject::List * dunedaq::oks::OksIndex::FindEqualAndGreatEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 75 of file index.hpp.

◆ FindEqualAndLess()

OksObject::List * dunedaq::oks::OksIndex::FindEqualAndLess ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 72 of file index.hpp.

72{return find_all(true, d1, OksQuery::equal_cmp, d2, OksQuery::less_cmp);}

◆ FindEqualAndLessEqual()

OksObject::List * dunedaq::oks::OksIndex::FindEqualAndLessEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 73 of file index.hpp.

◆ FindEqualOrEqual()

OksObject::List * dunedaq::oks::OksIndex::FindEqualOrEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 80 of file index.hpp.

80{return find_all(false, d1, OksQuery::equal_cmp, d2, OksQuery::equal_cmp);}

◆ FindEqualOrGreat()

OksObject::List * dunedaq::oks::OksIndex::FindEqualOrGreat ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 83 of file index.hpp.

83{return find_all(false, d1, OksQuery::equal_cmp, d2, OksQuery::greater_cmp);}

◆ FindEqualOrGreatEqual()

OksObject::List * dunedaq::oks::OksIndex::FindEqualOrGreatEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 84 of file index.hpp.

◆ FindEqualOrLess()

OksObject::List * dunedaq::oks::OksIndex::FindEqualOrLess ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 81 of file index.hpp.

81{return find_all(false, d1, OksQuery::equal_cmp, d2, OksQuery::less_cmp);}

◆ FindEqualOrLessEqual()

OksObject::List * dunedaq::oks::OksIndex::FindEqualOrLessEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 82 of file index.hpp.

◆ FindFirst()

OksObject * dunedaq::oks::OksIndex::FindFirst ( OksData * d) const

Definition at line 117 of file index.cpp.

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}

◆ FindGreat()

OksObject::List * dunedaq::oks::OksIndex::FindGreat ( OksData * d) const
inline

Definition at line 65 of file index.hpp.

◆ FindGreatEqual()

OksObject::List * dunedaq::oks::OksIndex::FindGreatEqual ( OksData * d) const
inline

Definition at line 63 of file index.hpp.

◆ FindLess()

OksObject::List * dunedaq::oks::OksIndex::FindLess ( OksData * d) const
inline

Definition at line 64 of file index.hpp.

64{return find_all(d, OksQuery::less_cmp);}

◆ FindLessAndGreat()

OksObject::List * dunedaq::oks::OksIndex::FindLessAndGreat ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 67 of file index.hpp.

◆ FindLessAndGreatEqual()

OksObject::List * dunedaq::oks::OksIndex::FindLessAndGreatEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 68 of file index.hpp.

◆ FindLessEqual()

OksObject::List * dunedaq::oks::OksIndex::FindLessEqual ( OksData * d) const
inline

Definition at line 62 of file index.hpp.

◆ FindLessEqualAndGreat()

OksObject::List * dunedaq::oks::OksIndex::FindLessEqualAndGreat ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 69 of file index.hpp.

◆ FindLessEqualAndGreatEqual()

OksObject::List * dunedaq::oks::OksIndex::FindLessEqualAndGreatEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 70 of file index.hpp.

◆ FindLessEqualOrGreat()

OksObject::List * dunedaq::oks::OksIndex::FindLessEqualOrGreat ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 78 of file index.hpp.

◆ FindLessEqualOrGreatEqual()

OksObject::List * dunedaq::oks::OksIndex::FindLessEqualOrGreatEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 79 of file index.hpp.

◆ FindLessOrGreat()

OksObject::List * dunedaq::oks::OksIndex::FindLessOrGreat ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 76 of file index.hpp.

76{return find_all(false, d1, OksQuery::less_cmp, d2, OksQuery::greater_cmp);}

◆ FindLessOrGreatEqual()

OksObject::List * dunedaq::oks::OksIndex::FindLessOrGreatEqual ( OksData * d1,
OksData * d2 ) const
inline

Definition at line 77 of file index.hpp.

◆ get_offset()

size_t dunedaq::oks::OksIndex::get_offset ( OksClass * cl,
OksAttribute * a )
staticprivate

Definition at line 16 of file index.cpp.

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}

◆ remove_obj()

OksObject * dunedaq::oks::OksIndex::remove_obj ( OksObject * o)
private

Definition at line 99 of file index.cpp.

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}
std::multiset< OksObject *, OksObjectSortBy >::iterator Position
Definition index.hpp:52

◆ OksClass

friend class OksClass
friend

Definition at line 36 of file index.hpp.

◆ OksObject

friend class OksObject
friend

Definition at line 37 of file index.hpp.

Member Data Documentation

◆ a

OksAttribute* dunedaq::oks::OksIndex::a
private

Definition at line 89 of file index.hpp.

◆ c

OksClass* dunedaq::oks::OksIndex::c
private

Definition at line 88 of file index.hpp.

◆ offset

size_t dunedaq::oks::OksIndex::offset
private

Definition at line 90 of file index.hpp.


The documentation for this class was generated from the following files: