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 30 of file index.hpp.

Member Typedef Documentation

◆ ConstPosition

Definition at line 48 of file index.hpp.

◆ Map

Definition at line 45 of file index.hpp.

◆ Position

Definition at line 47 of file index.hpp.

Constructor & Destructor Documentation

◆ OksIndex()

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

Definition at line 18 of file index.cpp.

18 :
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}
const std::string & get_name() const noexcept
out stream operator
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
friend class OksObject
Definition index.hpp:32
static std::ostream & error_msg(const char *)
Definition kernel.cpp:556
FELIX Initialization std::string initerror FELIX queue timed std::string queuename Unexpected chunk size

◆ ~OksIndex()

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

Definition at line 80 of file index.cpp.

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}

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 187 of file index.cpp.

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

◆ find_all() [2/2]

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

Definition at line 169 of file index.cpp.

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}

◆ find_interval()

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

Definition at line 125 of file index.cpp.

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}
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
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

◆ FindEqual()

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

Definition at line 56 of file index.hpp.

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

◆ FindEqualAndEqual()

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

Definition at line 66 of file index.hpp.

66{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 69 of file index.hpp.

◆ FindEqualAndGreatEqual()

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

Definition at line 70 of file index.hpp.

◆ FindEqualAndLess()

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

Definition at line 67 of file index.hpp.

67{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 68 of file index.hpp.

◆ FindEqualOrEqual()

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

Definition at line 75 of file index.hpp.

75{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 78 of file index.hpp.

78{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 79 of file index.hpp.

◆ FindEqualOrLess()

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

Definition at line 76 of file index.hpp.

76{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 77 of file index.hpp.

◆ FindFirst()

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

Definition at line 112 of file index.cpp.

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}

◆ FindGreat()

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

Definition at line 60 of file index.hpp.

◆ FindGreatEqual()

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

Definition at line 58 of file index.hpp.

◆ FindLess()

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

Definition at line 59 of file index.hpp.

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

◆ FindLessAndGreat()

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

Definition at line 62 of file index.hpp.

◆ FindLessAndGreatEqual()

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

Definition at line 63 of file index.hpp.

◆ FindLessEqual()

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

Definition at line 57 of file index.hpp.

◆ FindLessEqualAndGreat()

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

Definition at line 64 of file index.hpp.

◆ FindLessEqualAndGreatEqual()

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

Definition at line 65 of file index.hpp.

◆ FindLessEqualOrGreat()

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

Definition at line 73 of file index.hpp.

◆ FindLessEqualOrGreatEqual()

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

Definition at line 74 of file index.hpp.

◆ FindLessOrGreat()

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

Definition at line 71 of file index.hpp.

71{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 72 of file index.hpp.

◆ get_offset()

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

Definition at line 11 of file index.cpp.

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}

◆ remove_obj()

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

Definition at line 94 of file index.cpp.

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

Friends And Related Symbol Documentation

◆ OksClass

friend class OksClass
friend

Definition at line 31 of file index.hpp.

◆ OksObject

friend class OksObject
friend

Definition at line 32 of file index.hpp.

Member Data Documentation

◆ a

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

Definition at line 84 of file index.hpp.

◆ c

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

Definition at line 83 of file index.hpp.

◆ offset

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

Definition at line 85 of file index.hpp.


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