Skip to content

Commit 811c56e

Browse files
committed
fix uint deserialization in expressions
1 parent 80082d5 commit 811c56e

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

Framework/Core/src/ExpressionJSONHelpers.cxx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,7 @@ struct ExpressionReader : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
365365
value = (uint16_t)i;
366366
break;
367367
case atype::UINT32:
368-
value = i;
369-
break;
370-
case atype::UINT64:
371-
value = (uint64_t)i;
372-
break;
373-
case atype::INT64:
374-
value = (int64_t)i;
368+
value = (uint32_t)i;
375369
break;
376370
default:
377371
states.push(State::IN_ERROR);
@@ -450,7 +444,17 @@ struct ExpressionReader : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
450444
debug << "Int64(" << i << ")" << std::endl;
451445
// can only be a literal node value
452446
if (states.top() == State::IN_NODE_LITERAL && currentKey.compare("value") == 0) {
453-
value = i;
447+
switch (type) {
448+
case atype::UINT64:
449+
value = (uint64_t)i;
450+
break;
451+
case atype::INT64:
452+
value = (int64_t)i;
453+
break;
454+
default:
455+
states.push(State::IN_ERROR);
456+
return false;
457+
}
454458
return true;
455459
}
456460
states.push(State::IN_ERROR); // no other contexts allow int64s
@@ -460,13 +464,9 @@ struct ExpressionReader : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>,
460464
bool Uint64(uint64_t i)
461465
{
462466
debug << "Uint64(" << i << ")" << std::endl;
463-
// can only be a literal node value
464-
if (states.top() == State::IN_NODE_LITERAL && currentKey.compare("value") == 0) {
465-
value = i;
466-
return true;
467-
}
468-
states.push(State::IN_ERROR); // no other contexts allow uints
469-
return false;
467+
// any positive value will be first read as unsigned, however the actual type is determined by node's arrow_type
468+
debug << ">> falling back to Int64" << std::endl;
469+
return Int64(i);
470470
}
471471

472472
bool Double(double d)

Framework/Core/test/test_Expressions.cxx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,15 @@ TEST_CASE("TestExpressionSerialization")
397397
{
398398
Filter f = o2::aod::track::signed1Pt > 0.f && ifnode(nabs(o2::aod::track::eta) < 1.0f, nabs(o2::aod::track::x) > 2.0f, nabs(o2::aod::track::y) > 3.0f);
399399
Projector p = -1.f * nlog(ntan(o2::constants::math::PIQuarter - 0.5f * natan(o2::aod::fwdtrack::tgl)));
400+
Projector p1 = ifnode(o2::aod::track::itsClusterSizes > (uint32_t)0, static_cast<uint8_t>(o2::aod::track::ITS), (uint8_t)0x0) |
401+
ifnode(o2::aod::track::tpcNClsFindable > (uint8_t)0, static_cast<uint8_t>(o2::aod::track::TPC), (uint8_t)0x0) |
402+
ifnode(o2::aod::track::trdPattern > (uint8_t)0, static_cast<uint8_t>(o2::aod::track::TRD), (uint8_t)0x0) |
403+
ifnode((o2::aod::track::tofChi2 >= 0.f) && (o2::aod::track::tofExpMom > 0.f), static_cast<uint8_t>(o2::aod::track::TOF), (uint8_t)0x0);
400404

401405
std::vector<Projector> projectors;
402406
projectors.emplace_back(std::move(f));
403407
projectors.emplace_back(std::move(p));
408+
projectors.emplace_back(std::move(p1));
404409

405410
std::stringstream osm;
406411
ExpressionJSONHelpers::write(osm, projectors);
@@ -423,6 +428,15 @@ TEST_CASE("TestExpressionSerialization")
423428
auto t22 = createExpressionTree(s22, schemap);
424429
REQUIRE(t12->ToString() == t22->ToString());
425430

431+
auto s13 = createOperations(projectors[2]);
432+
auto s23 = createOperations(ps[2]);
433+
auto schemap1 = std::make_shared<arrow::Schema>(std::vector{o2::aod::track::ITSClusterSizes::asArrowField(), o2::aod::track::TPCNClsFindable::asArrowField(),
434+
o2::aod::track::TRDPattern::asArrowField(), o2::aod::track::TOFChi2::asArrowField(),
435+
o2::aod::track::TOFExpMom::asArrowField()});
436+
auto t13 = createExpressionTree(s13, schemap1);
437+
auto t23 = createExpressionTree(s23, schemap1);
438+
REQUIRE(t13->ToString() == t23->ToString());
439+
426440
osm.clear();
427441
osm.str("");
428442
ArrowJSONHelpers::write(osm, schemaf);

0 commit comments

Comments
 (0)