GCC Code Coverage Report


Directory: ./
File: src/event/hdql-augments.test.cc
Date: 2025-09-01 06:19:01
Exec Total Coverage
Lines: 276 278 99.3%
Functions: 29 29 100.0%
Branches: 342 402 85.1%

Line Branch Exec Source
1 #include "na64calib/dispatcher.hh"
2 #include "na64detID/TBName.hh"
3 #include "na64detID/detectorID.hh"
4 #include "na64event/data/event.hh"
5 #include "na64event/data/sadc.hh"
6 #include "na64event/hdql-assets.hh"
7 #include "na64sw-config.h"
8 #include "na64utest/testing-environment.hh"
9 #include <exception>
10 #include <gtest/gtest.h>
11 #include <hdql/helpers/compounds.hh>
12 #include <log4cpp/Category.hh>
13
14 #if defined(hdql_FOUND) && hdql_FOUND
15
16 #include "na64utest/testing-fixture.hh"
17
18 namespace na64dp {
19 namespace test {
20
21 //
22 // Fixture
23
24 ///\brief Testing fixture for HDQL expressions
25 class HDQLIntegrationTests : public BasicEventDataOperations {
26 protected:
27 ::hdql::helpers::CompoundTypes * _compounds;
28 public:
29 void SetUp() override;
30 void TearDown() override;
31
32 // NOTE: always instantiates queries on the event type
33 //hdql::helpers::Query compile_hdql_expression(
34 // const std::string & exprStr
35 // , bool keysNeeded=false
36 // , const std::vector<std::string> & order={}
37 // );
38 };
39
40 void
41 9 HDQLIntegrationTests::SetUp() {
42 9 BasicEventDataOperations::SetUp();
43
44 // NOTE: ususally this `init_root_hdql_context()` is called within
45 // `HDQLAssets::configure()`, but here we instantiate context locally
46 // for a single fixture scope
47
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
9 assert(Environment::self());
48 9 init_root_hdql_context( _compounds
49 9 , Environment::self()->calib_mgr()
50 );
51
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 assert(hdql_context_custom_data_get(_compounds->context_ptr(), "na64sw/calib-dispatcher-ptr")); // XXX
52 9 }
53
54 void
55 9 HDQLIntegrationTests::TearDown() {
56 9 BasicEventDataOperations::TearDown();
57 // NOTE: ususally this `destroy_root_hdql_context()` is called within
58 // `HDQLAssets::cleanup()`, but here we cleanup context locally
59 // for a single fixture scope
60 9 na64dp::destroy_root_hdql_context(_compounds);
61 9 }
62
63 //std::shared_ptr<hdql::helpers::Query>
64 //HDQLIntegrationTests::compile_hdql_expression(const std::string & exprStr
65 // , bool keysNeeded, const std::vector<std::string> & order) {
66 // auto eventCompoundIt = _compounds->find(typeid(event::Event));
67 // if(eventCompoundIt == _compounds->end()) {
68 // NA64DP_RUNTIME_ERROR("Handlers HDQL compounds collection does not have"
69 // " Event type.");
70 // }
71 // assert(eventCompoundIt->second);
72 //
73 // return std::make_shared<hdql_int::CompiledExpression>( exprStr
74 // , eventCompoundIt->second
75 // , false
76 // , log4cpp::Category::getInstance("testing.hdql")
77 // , order
78 // );
79 //}
80
81 //
82 // Tests
83
84 // Test basic value retrieval and to-boolean value casting
85 8 TEST_F(HDQLIntegrationTests, HDQLSimpleLogicCastWorksOn1stLvlScalarAtomic) {
86 2 _reallocate_event_buffer(5*1024);
87
88 // check trigger flags are casted to bool
89 {
90 // cast Event::trigger field to boolean type
91
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".trigger", false);
92 {
93
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
94
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
95 2 event.trigger = 0;
96
97 2 size_t nResults = 0;
98
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<bool>(event); qc; ++qc, ++nResults) {
99
2/3
✓ Branch 1 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
2 EXPECT_FALSE(qc.get());
100 2 }
101
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
102 2 }
103 {
104
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
105
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
106 2 event.trigger = 1;
107
108 2 size_t nResults = 0;
109
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<bool>(event); qc; ++qc, ++nResults) {
110
2/3
✓ Branch 1 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
2 EXPECT_TRUE(qc.get());
111 2 }
112
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
113 2 }
114 2 }
115 2 }
116
117 // Test basic value retrieval, without value type casting
118 8 TEST_F(HDQLIntegrationTests, HDQLScalarAtomic1stLvlValueForwardedWOutConversion) {
119 2 _reallocate_event_buffer(5*1024);
120
121 // check trigger flags are casted to integer, possible of another size
122 // (uint16_t or other to int64_t) preserving its absolute value -- tests
123 // implicit conversions
124 {
125
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".trigger", false);
126 {
127
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
128
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
129 2 event.trigger = 0;
130
131 2 size_t nResults = 0;
132
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<decltype(event::Event::trigger)>(event); qc; ++qc, ++nResults) {
133
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0);
134
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0);
135 2 }
136
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
137 2 }
138 {
139
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
140
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
141 2 event.trigger = 0107;
142
143 2 size_t nResults = 0;
144
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<decltype(event::Event::trigger)>(event); qc; ++qc, ++nResults) {
145
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0107);
146
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0107);
147 2 }
148
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
149 2 }
150 2 }
151 2 }
152
153 // Test basic value retrieval, with value type casting
154 8 TEST_F(HDQLIntegrationTests, HDQLScalarAtomic1stLvlValueForwardedWithConversion) {
155 2 _reallocate_event_buffer(5*1024);
156
157 // check trigger flags are casted to integer, possible of another size
158 // (uint16_t or other to int64_t) preserving its absolute value -- tests
159 // implicit conversions
160 {
161
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".trigger", false);
162 {
163
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
164
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
165 2 event.trigger = 0;
166
167 2 size_t nResults = 0;
168
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<int64_t>(event); qc; ++qc, ++nResults) {
169
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0);
170
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0);
171 2 }
172
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
173 2 }
174 {
175
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
176
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
177 2 event.trigger = 0107;
178
179 2 size_t nResults = 0;
180
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<int64_t>(event); qc; ++qc, ++nResults) {
181
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0107);
182
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0107);
183 2 }
184
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
185 2 }
186 2 }
187 2 }
188
189 // Important case of bitwise arithmetics performing selection based on bit
190 8 TEST_F(HDQLIntegrationTests, HDQLScalarAtomic1stLvlBitwiseOperations) {
191 2 _reallocate_event_buffer(5*1024);
192
193
194 { // simple bitwise-and test
195
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".trigger & 0x4", false);
196 { // by-value retrieval
197
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
198
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
199 2 event.trigger = 0x1 | 0x4 | 0x8;
200
201 2 size_t nResults = 0;
202
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<int64_t>(event); qc; ++qc, ++nResults) {
203
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0x4);
204
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0x4);
205 2 }
206
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
207 2 }
208 { // retrieval with to-bool cast
209
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event eventTrue(this->lmem());
210
1/1
✓ Branch 1 taken 1 times.
2 util::reset(eventTrue);
211 2 eventTrue.trigger = 0x1 | 0x4 | 0x8;
212
213 2 size_t nResults = 0;
214
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<bool>(eventTrue); qc; ++qc, ++nResults) {
215
2/3
✓ Branch 1 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
2 EXPECT_TRUE(qc.get());
216
2/3
✓ Branch 1 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
2 EXPECT_TRUE(qc.get());
217 2 }
218
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
219
220
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
4 event::Event eventFalse(this->lmem());
221
1/1
✓ Branch 1 taken 1 times.
2 util::reset(eventFalse);
222 2 eventFalse.trigger = 0x1 | 0x10;
223
224 2 nResults = 0;
225
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<bool>(eventFalse); qc; ++qc, ++nResults) {
226
2/3
✓ Branch 1 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
2 EXPECT_FALSE(qc.get());
227
2/3
✓ Branch 1 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1 times.
2 EXPECT_FALSE(qc.get());
228 2 }
229
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
230 2 }
231 2 }
232 { // complex expression
233
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>("(~.trigger) & 0x15", false);
234 { // by-value retrieval
235
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
236
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
237 2 event.trigger = 0x2 | 0x4 | 0x8;
238
239 2 size_t nResults = 0;
240
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<int64_t>(event); qc; ++qc, ++nResults) {
241
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0x11);
242
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0x11);
243 2 }
244
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
245 2 }
246 2 }
247 2 }
248
249 // Test simple arithmetics on scalar value
250 8 TEST_F(HDQLIntegrationTests, HDQLScalarAtomic1stLvlArithmetics) {
251 2 _reallocate_event_buffer(5*1024);
252 {
253 // Test HDQL is capable to evaluate simple integer arithmetics
254 // on 1st level integer attribute
255
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>("((.trigger >> 1) + 1)%3", false);
256 {
257
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
258
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
259 2 event.trigger = 2;
260
261 2 size_t nResults = 0;
262
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<int64_t>(event); qc; ++qc, ++nResults) {
263
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 2);
264 2 }
265
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
266 2 }
267 {
268
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
269
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
270 2 event.trigger = 4;
271
272 2 size_t nResults = 0;
273
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 2 times.
✓ Branch 9 taken 1 times.
✓ Branch 10 taken 1 times.
4 for(auto qc = q.cursor_on<int64_t>(event); qc; ++qc, ++nResults) {
274
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 times.
2 EXPECT_EQ(qc.get(), 0);
275 2 }
276
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResults, 1);
277 2 }
278 2 }
279 2 }
280
281 // Test basic collection iteration
282 8 TEST_F(HDQLIntegrationTests, HDQLHandlesHitsCollection) {
283
1/1
✓ Branch 1 taken 1 times.
2 _reallocate_event_buffer(5*1024);
284
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
285
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
286 // fill event's sadcHits collection with some items
287
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit1 = lmem().create<event::SADCHit>(lmem());
288 2 hit1->eDep = 1.0;
289
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x2, 0, 0x0)
290 , hit1 );
291
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit2 = lmem().create<event::SADCHit>(lmem());
292 2 hit2->eDep = 2.0;
293
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x2, 1, 0x0)
294 , hit2 );
295
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit3 = lmem().create<event::SADCHit>(lmem());
296 2 hit3->eDep = 3.0;
297
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x2, 2, 0x0)
298 , hit3 );
299
300 // test empty collection is not iterated
301 {
302
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".apvHits.time", false);
303 2 size_t nResult = 0;
304
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
2 for(auto qc = q.cursor_on<double>(event); qc; ++qc) {
305 ++nResult;
306 2 }
307
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResult, 0);
308 2 }
309
310 // test non-empty collection returns all the data items
311 {
312 2 std::map<int, bool> valuesMet;
313
1/1
✓ Branch 2 taken 1 times.
2 valuesMet.emplace(hit1->eDep, false);
314
1/1
✓ Branch 2 taken 1 times.
2 valuesMet.emplace(hit2->eDep, false);
315
1/1
✓ Branch 2 taken 1 times.
2 valuesMet.emplace(hit3->eDep, false);
316 // Test HDQL is capable to handle 1st level collections dereferenced up
317 // to scalar attributes. Should return SADCHit::eDep for every hit in
318 // event::Event::sadcHits
319
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".sadcHits.eDep", false);
320
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 4 times.
✓ Branch 9 taken 3 times.
✓ Branch 10 taken 1 times.
14 for(auto qc = q.cursor_on<double>(event); qc; ++qc) {
321
2/2
✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
6 auto it = valuesMet.find(qc.get());
322
3/5
✓ Branch 2 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 3 times.
✓ Branch 20 taken 3 times.
✗ Branch 21 not taken.
6 ASSERT_NE(it, valuesMet.end());
323
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
6 EXPECT_FALSE(it->second);
324 6 it->second = true;
325 2 }
326
2/2
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 1 times.
8 for(auto & p : valuesMet) {
327
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
6 EXPECT_TRUE(p.second);
328 }
329 2 }
330 2 }
331
332 // Test by-value collection iteration with selector by value
333 8 TEST_F(HDQLIntegrationTests, HDQLHandlesValueSelectionHitsCollection) {
334
1/1
✓ Branch 1 taken 1 times.
2 _reallocate_event_buffer(5*1024);
335
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
336
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
337 // fill event's sadcHits collection with some items
338
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit1 = lmem().create<event::SADCHit>(lmem());
339 2 hit1->eDep = 1.0;
340 2 hit1->eDepError = .6;
341
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x2, 0, 0x0)
342 , hit1 );
343
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit2 = lmem().create<event::SADCHit>(lmem());
344 2 hit2->eDep = 2.0;
345 2 hit2->eDepError = .3; // must be omitted by selector expression
346
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x2, 1, 0x0)
347 , hit2 );
348
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit3 = lmem().create<event::SADCHit>(lmem());
349 2 hit3->eDep = 3.0;
350 2 hit3->eDepError = .9;
351
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x2, 2, 0x0)
352 , hit3 );
353
354 // test empty selected set is not iterated
355 {
356
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".sadcHits{:.eDepError < 0}.eDep", false);
357 2 size_t nResult = 0;
358
3/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
2 for(auto qc = q.cursor_on<double>(event); qc; ++qc) {
359 ++nResult;
360 2 }
361
2/3
✓ Branch 1 taken 1 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1 times.
2 EXPECT_EQ(nResult, 0);
362 2 }
363
364 // test non-empty collection returns all the data items
365 {
366 2 std::map<int, bool> valuesMet;
367
1/1
✓ Branch 2 taken 1 times.
2 valuesMet.emplace(hit1->eDep, false);
368
1/1
✓ Branch 2 taken 1 times.
2 valuesMet.emplace(hit3->eDep, false);
369 // Test HDQL is capable to handle 1st level collections dereferenced up
370 // to scalar attributes. Should return SADCHit::eDep for every hit in
371 // event::Event::sadcHits
372
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".sadcHits{:.eDepError*10/2 > 2.5}.eDep", false);
373
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 3 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 1 times.
10 for(auto qc = q.cursor_on<double>(event); qc; ++qc) {
374
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
4 auto it = valuesMet.find(qc.get());
375
3/5
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 20 taken 2 times.
✗ Branch 21 not taken.
4 ASSERT_NE(it, valuesMet.end());
376
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
4 EXPECT_FALSE(it->second);
377 4 it->second = true;
378 2 }
379
2/2
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 times.
6 for(auto & p : valuesMet) {
380
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
4 EXPECT_TRUE(p.second);
381 }
382 2 }
383 2 }
384
385 // Test by-value collection iteration with selector by value
386 // NOTE/TODO: this test prints error message to stderr (should be redirected by HDQL API)
387 8 TEST_F(HDQLIntegrationTests, HDQLDSuLTrowsExceptionOnNoNamingSet) {
388
1/1
✓ Branch 1 taken 1 times.
2 _reallocate_event_buffer(5*1024);
389
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
390
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
391 // fill event's sadcHits collection with some items
392
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit1 = lmem().create<event::SADCHit>(lmem());
393 2 hit1->eDep = 1.0;
394 2 hit1->eDepError = .6;
395
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x1, 0, 0x0)
396 , hit1 );
397
398 calib::Dispatcher * cdsp; {
399
1/1
✓ Branch 2 taken 1 times.
2 void * cdsp_ = hdql_context_custom_data_get(_compounds->context_ptr(), "na64sw/calib-dispatcher-ptr");
400
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
2 ASSERT_TRUE( cdsp_ );
401 2 cdsp = reinterpret_cast<calib::Dispatcher*>(cdsp_);
402 }
403 (void) cdsp; // quiet unused warning; TODO: do we really need this?
404
405 { // expect exception when dispatcher is not initialized
406
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".sadcHits[kin == SRD].eDep", false);
407
5/11
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 1 times.
✓ Branch 31 taken 1 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
2 EXPECT_THROW(q.cursor_on<double>(event), std::exception);
408 2 }
409 2 }
410
411 // Test by-value collection iteration with selector by value
412 8 TEST_F(HDQLIntegrationTests, HDQLHandlesKeySelectionHitsCollection) {
413
1/1
✓ Branch 1 taken 1 times.
2 _reallocate_event_buffer(5*1024);
414
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event::Event event(this->lmem());
415
1/1
✓ Branch 1 taken 1 times.
2 util::reset(event);
416 // fill event's sadcHits collection with some items
417
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit1 = lmem().create<event::SADCHit>(lmem());
418 2 hit1->eDep = 1.0;
419 2 hit1->eDepError = .6;
420
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x2, 0, 0x0)
421 , hit1 );
422
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit2 = lmem().create<event::SADCHit>(lmem());
423 2 hit2->eDep = 2.0;
424 2 hit2->eDepError = .3; // must be omitted by selector expression
425
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x1, 1, 0x0)
426 , hit2 );
427
3/3
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
2 auto hit3 = lmem().create<event::SADCHit>(lmem());
428 2 hit3->eDep = 3.0;
429 2 hit3->eDepError = .9;
430
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
2 event.sadcHits.emplace(DetID(0x1, 0x2, 2, 0x0)
431 , hit3 );
432
433 calib::Dispatcher * cdsp; {
434
1/1
✓ Branch 2 taken 1 times.
2 void * cdsp_ = hdql_context_custom_data_get(_compounds->context_ptr(), "na64sw/calib-dispatcher-ptr");
435
2/4
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 21 taken 1 times.
✗ Branch 22 not taken.
2 ASSERT_TRUE( cdsp_ );
436 2 cdsp = reinterpret_cast<calib::Dispatcher*>(cdsp_);
437 }
438
439 2 nameutils::DetectorNaming nm;
440
4/4
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
12 nm.chip_add("SADC", 0x1);
441
6/6
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
20 nm.define_kin("HCAL", 0x2, "SADC");
442
6/6
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
✓ Branch 7 taken 1 times.
✓ Branch 10 taken 1 times.
✓ Branch 13 taken 1 times.
✓ Branch 16 taken 1 times.
18 nm.define_kin("SRD", 0x4, "SADC");
443
444 #if 0
445 // test empty selected set is not iterated
446 {
447 auto q = _compounds->query<event::Event>(".sadcHits[kin == SRD].eDep", false);
448 cdsp->set("default", const_cast<const nameutils::DetectorNaming &>(nm)); // TODO: segfault if no cast?
449 size_t nResult = 0;
450 for(auto qc = q.cursor_on<double>(event); qc; ++qc) {
451 ++nResult;
452 }
453 EXPECT_EQ(nResult, 0);
454 }
455 #endif
456
457 // test non-empty collection returns all the data items
458 {
459 2 std::map<int, bool> valuesMet;
460
1/1
✓ Branch 2 taken 1 times.
2 valuesMet.emplace(hit1->eDep, false);
461
1/1
✓ Branch 2 taken 1 times.
2 valuesMet.emplace(hit3->eDep, false);
462 // Test HDQL is capable to handle 1st level collections dereferenced up
463 // to scalar attributes. Should return SADCHit::eDep for every hit in
464 // event::Event::sadcHits
465
1/1
✓ Branch 1 taken 1 times.
2 auto q = _compounds->query<event::Event>(".sadcHits[kin == HCAL].eDep", false);
466
2/2
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 1 times.
4 cdsp->set("default", const_cast<const nameutils::DetectorNaming &>(nm)); // TODO: segfault if no cast?
467
5/5
✓ Branch 1 taken 1 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 3 times.
✓ Branch 9 taken 2 times.
✓ Branch 10 taken 1 times.
6 for(auto qc = q.cursor_on<double>(event); qc; ++qc) {
468
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
4 auto it = valuesMet.find(qc.get());
469
3/5
✓ Branch 2 taken 2 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 29 taken 2 times.
✗ Branch 30 not taken.
4 ASSERT_NE(it, valuesMet.end()) << "not found for val=" << qc.get();
470
1/2
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
4 EXPECT_FALSE(it->second);
471 4 it->second = true;
472 2 }
473
2/2
✓ Branch 5 taken 2 times.
✓ Branch 6 taken 1 times.
6 for(auto & p : valuesMet) {
474
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
4 EXPECT_TRUE(p.second);
475 }
476 2 }
477 2 }
478
479 #if 0
480 // Test by-value collection iteration with selector by value
481 TEST_F(HDQLIntegrationTests, HDQLHandlesPair) {
482 _reallocate_event_buffer(5*1024);
483 event::Event event(this->lmem());
484 util::reset(event);
485 // fill event's sadcHits collection with some items
486 auto hit1 = lmem().create<event::SADCHit>(lmem());
487 hit1->eDep = 1.0;
488 hit1->eDepError = .6;
489 event.sadcHits.emplace(DetID(0x1, 0x2, 0, 0x0)
490 , hit1 );
491 auto hit2 = lmem().create<event::SADCHit>(lmem());
492 hit2->eDep = 2.0;
493 hit2->eDepError = .3; // must be omitted by selector expression
494 event.sadcHits.emplace(DetID(0x1, 0x2, 1, 0x0)
495 , hit2 );
496 auto hit3 = lmem().create<event::SADCHit>(lmem());
497 hit3->eDep = 3.0;
498 hit3->eDepError = .9;
499 event.sadcHits.emplace(DetID(0x1, 0x2, 2, 0x0)
500 , hit3 );
501
502 // test pair retrieval from v-compound
503 {
504 auto expr = compile_hdql_expression(
505 ".sadcHits{a := .eDep*.eDep, b := .eDepError*.eDepError}"
506 , false
507 , {"a", "b"}
508 );
509 size_t nResult = 0;
510 for(auto q = expr->query<std::pair<double, double>>(event); q; q.next()) {
511 ++nResult;
512 // TODO: check all are visited
513 std::cout << nResult << " " << q.get().first << ", " << q.get().second << std::endl; // XXX
514 }
515 EXPECT_EQ(nResult, 3);
516 }
517 // test pair retrieval from mixed compound
518 {
519 auto expr = compile_hdql_expression(
520 ".sadcHits{a := .eDep*.eDep}"
521 , false
522 , {"eDep", "a"}
523 );
524 size_t nResult = 0;
525 for(auto q = expr->query<std::pair<double, double>>(event); q; q.next()) {
526 ++nResult;
527 // TODO: check all are visited
528 std::cout << nResult << " " << q.get().first << ", " << q.get().second << std::endl; // XXX
529 }
530 EXPECT_EQ(nResult, 3);
531 }
532 // vice-versa (kinda similar to prev, but left here as we had order issue
533 // here once)
534 {
535 auto expr = compile_hdql_expression(
536 ".sadcHits{a := .eDep*.eDep}"
537 , false
538 , {"a", "eDep"}
539 );
540 size_t nResult = 0;
541 for(auto q = expr->query<std::pair<double, double>>(event); q; q.next()) {
542 ++nResult;
543 // TODO: check all are visited
544 std::cout << nResult << " " << q.get().first << ", " << q.get().second << std::endl; // XXX
545 }
546 EXPECT_EQ(nResult, 3);
547 }
548 }
549 #endif
550
551 } // namespace ::na64dp::test
552 } // namespace na64dp
553
554 #endif // defined(hdql_FOUND) && hdql_FOUND
555