Skip to content

Commit 533035d

Browse files
authored
DPL Analysis: Make filter/table matching rely on a type hash rather than a string name (#5868)
1 parent 1066045 commit 533035d

6 files changed

Lines changed: 145 additions & 117 deletions

File tree

Framework/Core/include/Framework/ASoA.h

Lines changed: 98 additions & 92 deletions
Large diffs are not rendered by default.

Framework/Core/include/Framework/AnalysisTask.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ struct AnalysisDataProcessorBuilder {
107107
{
108108
using dT = std::decay_t<T>;
109109
if constexpr (framework::is_specialization<dT, soa::Filtered>::value) {
110-
eInfos.push_back({at, o2::soa::createSchemaFromColumns(typename dT::table_t::persistent_columns_t{}), nullptr});
110+
eInfos.push_back({at, dT::hashes(), o2::soa::createSchemaFromColumns(typename dT::table_t::persistent_columns_t{}), nullptr});
111111
} else if constexpr (soa::is_soa_iterator_t<dT>::value) {
112112
if constexpr (std::is_same_v<typename dT::policy_t, soa::FilteredIndexPolicy>) {
113-
eInfos.push_back({at, o2::soa::createSchemaFromColumns(typename dT::table_t::persistent_columns_t{}), nullptr});
113+
eInfos.push_back({at, dT::parent_t::hashes(), o2::soa::createSchemaFromColumns(typename dT::table_t::persistent_columns_t{}), nullptr});
114114
}
115115
}
116116
doAppendInputWithMetadata(soa::make_originals_from_type<dT>(), inputs);

Framework/Core/include/Framework/Expressions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ class Filter;
4040
#include <variant>
4141
#include <string>
4242
#include <memory>
43+
#include <typeinfo>
44+
#include <set>
4345

4446
using atype = arrow::Type;
4547
struct ExpressionInfo {
4648
size_t index;
49+
std::set<size_t> hashes;
4750
gandiva::SchemaPtr schema;
4851
gandiva::NodePtr tree;
4952
};
@@ -104,8 +107,9 @@ struct LiteralNode {
104107
struct BindingNode {
105108
BindingNode(BindingNode const&) = default;
106109
BindingNode(BindingNode&&) = delete;
107-
BindingNode(std::string const& name_, atype::type type_) : name{name_}, type{type_} {}
110+
BindingNode(std::string const& name_, std::size_t hash_, atype::type type_) : name{name_}, hash{hash_}, type{type_} {}
108111
std::string name;
112+
std::size_t hash;
109113
atype::type type;
110114
};
111115

Framework/Core/src/ExpressionHelpers.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ struct DatumSpec {
4949
/// datum spec either contains an index, a value of a literal or a binding label
5050
using datum_t = std::variant<std::monostate, size_t, LiteralNode::var_t, std::string>;
5151
datum_t datum = std::monostate{};
52+
size_t hash = 0;
5253
atype::type type = atype::NA;
54+
5355
explicit DatumSpec(size_t index, atype::type type_) : datum{index}, type{type_} {}
5456
explicit DatumSpec(LiteralNode::var_t literal, atype::type type_) : datum{literal}, type{type_} {}
55-
explicit DatumSpec(std::string binding, atype::type type_) : datum{binding}, type{type_} {}
57+
explicit DatumSpec(std::string binding, size_t hash_, atype::type type_) : datum{binding}, hash{hash_}, type{type_} {}
5658
DatumSpec() = default;
5759
DatumSpec(DatumSpec const&) = default;
5860
DatumSpec(DatumSpec&&) = default;

Framework/Core/src/Expressions.cxx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct LiteralNodeHelper {
3737
struct BindingNodeHelper {
3838
DatumSpec operator()(BindingNode node) const
3939
{
40-
return DatumSpec{node.name, node.type};
40+
return DatumSpec{node.name, node.hash, node.type};
4141
}
4242
};
4343

@@ -527,6 +527,22 @@ gandiva::NodePtr createExpressionTree(Operations const& opSpecs,
527527
return tree;
528528
}
529529

530+
bool isTableCompatible(std::set<size_t> const& hashes, Operations const& specs)
531+
{
532+
std::set<size_t> opHashes;
533+
for (auto& spec : specs) {
534+
if (spec.left.datum.index() == 3) {
535+
opHashes.insert(spec.left.hash);
536+
}
537+
if (spec.right.datum.index() == 3) {
538+
opHashes.insert(spec.right.hash);
539+
}
540+
}
541+
542+
return std::includes(hashes.begin(), hashes.end(),
543+
opHashes.begin(), opHashes.end());
544+
}
545+
530546
bool isSchemaCompatible(gandiva::SchemaPtr const& Schema, Operations const& opSpecs)
531547
{
532548
std::set<std::string> opFieldNames;
@@ -555,7 +571,7 @@ void updateExpressionInfos(expressions::Filter const& filter, std::vector<Expres
555571
}
556572
Operations ops = createOperations(filter);
557573
for (auto& info : eInfos) {
558-
if (isSchemaCompatible(info.schema, ops)) {
574+
if (isTableCompatible(info.hashes, ops)) {
559575
auto tree = createExpressionTree(ops, info.schema);
560576
/// If the tree is already set, add a new tree to it with logical 'and'
561577
if (info.tree != nullptr) {

Framework/Core/test/test_Expressions.cxx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ using namespace o2::framework::expressions;
2323

2424
namespace nodes
2525
{
26-
static BindingNode pt{"pt", atype::FLOAT};
27-
static BindingNode phi{"phi", atype::FLOAT};
28-
static BindingNode eta{"eta", atype::FLOAT};
26+
static BindingNode pt{"pt", 1, atype::FLOAT};
27+
static BindingNode phi{"phi", 2, atype::FLOAT};
28+
static BindingNode eta{"eta", 3, atype::FLOAT};
2929

30-
static BindingNode tgl{"tgl", atype::FLOAT};
31-
static BindingNode signed1Pt{"signed1Pt", atype::FLOAT};
32-
static BindingNode testInt{"testInt", atype::INT32};
30+
static BindingNode tgl{"tgl", 4, atype::FLOAT};
31+
static BindingNode signed1Pt{"signed1Pt", 5, atype::FLOAT};
32+
static BindingNode testInt{"testInt", 6, atype::INT32};
3333
} // namespace nodes
3434

3535
namespace o2::aod::track
@@ -45,19 +45,19 @@ BOOST_AUTO_TEST_CASE(TestTreeParsing)
4545
BOOST_REQUIRE_EQUAL(specs[0].right, (DatumSpec{2u, atype::BOOL}));
4646
BOOST_REQUIRE_EQUAL(specs[0].result, (DatumSpec{0u, atype::BOOL}));
4747

48-
BOOST_REQUIRE_EQUAL(specs[1].left, (DatumSpec{std::string{"eta"}, atype::FLOAT}));
48+
BOOST_REQUIRE_EQUAL(specs[1].left, (DatumSpec{std::string{"eta"}, 3, atype::FLOAT}));
4949
BOOST_REQUIRE_EQUAL(specs[1].right, (DatumSpec{LiteralNode::var_t{1}, atype::INT32}));
5050
BOOST_REQUIRE_EQUAL(specs[1].result, (DatumSpec{2u, atype::BOOL}));
5151

5252
BOOST_REQUIRE_EQUAL(specs[2].left, (DatumSpec{3u, atype::BOOL}));
5353
BOOST_REQUIRE_EQUAL(specs[2].right, (DatumSpec{4u, atype::BOOL}));
5454
BOOST_REQUIRE_EQUAL(specs[2].result, (DatumSpec{1u, atype::BOOL}));
5555

56-
BOOST_REQUIRE_EQUAL(specs[3].left, (DatumSpec{std::string{"phi"}, atype::FLOAT}));
56+
BOOST_REQUIRE_EQUAL(specs[3].left, (DatumSpec{std::string{"phi"}, 2, atype::FLOAT}));
5757
BOOST_REQUIRE_EQUAL(specs[3].right, (DatumSpec{LiteralNode::var_t{2}, atype::INT32}));
5858
BOOST_REQUIRE_EQUAL(specs[3].result, (DatumSpec{4u, atype::BOOL}));
5959

60-
BOOST_REQUIRE_EQUAL(specs[4].left, (DatumSpec{std::string{"phi"}, atype::FLOAT}));
60+
BOOST_REQUIRE_EQUAL(specs[4].left, (DatumSpec{std::string{"phi"}, 2, atype::FLOAT}));
6161
BOOST_REQUIRE_EQUAL(specs[4].right, (DatumSpec{LiteralNode::var_t{1}, atype::INT32}));
6262
BOOST_REQUIRE_EQUAL(specs[4].result, (DatumSpec{3u, atype::BOOL}));
6363

@@ -71,15 +71,15 @@ BOOST_AUTO_TEST_CASE(TestTreeParsing)
7171
BOOST_REQUIRE_EQUAL(gspecs[1].right, (DatumSpec{LiteralNode::var_t{3}, atype::INT32}));
7272
BOOST_REQUIRE_EQUAL(gspecs[1].result, (DatumSpec{2u, atype::BOOL}));
7373

74-
BOOST_REQUIRE_EQUAL(gspecs[2].left, (DatumSpec{std::string{"phi"}, atype::FLOAT}));
74+
BOOST_REQUIRE_EQUAL(gspecs[2].left, (DatumSpec{std::string{"phi"}, 2, atype::FLOAT}));
7575
BOOST_REQUIRE_EQUAL(gspecs[2].right, (DatumSpec{LiteralNode::var_t{M_PI}, atype::DOUBLE}));
7676
BOOST_REQUIRE_EQUAL(gspecs[2].result, (DatumSpec{3u, atype::DOUBLE}));
7777

7878
BOOST_REQUIRE_EQUAL(gspecs[3].left, (DatumSpec{4u, atype::FLOAT}));
7979
BOOST_REQUIRE_EQUAL(gspecs[3].right, (DatumSpec{LiteralNode::var_t{0.5}, atype::DOUBLE}));
8080
BOOST_REQUIRE_EQUAL(gspecs[3].result, (DatumSpec{1u, atype::BOOL}));
8181

82-
BOOST_REQUIRE_EQUAL(gspecs[4].left, (DatumSpec{std::string{"eta"}, atype::FLOAT}));
82+
BOOST_REQUIRE_EQUAL(gspecs[4].left, (DatumSpec{std::string{"eta"}, 3, atype::FLOAT}));
8383
BOOST_REQUIRE_EQUAL(gspecs[4].right, (DatumSpec{LiteralNode::var_t{2.f}, atype::FLOAT}));
8484
BOOST_REQUIRE_EQUAL(gspecs[4].result, (DatumSpec{4u, atype::FLOAT}));
8585

@@ -90,11 +90,11 @@ BOOST_AUTO_TEST_CASE(TestTreeParsing)
9090
BOOST_REQUIRE_EQUAL(hspecs[0].right, (DatumSpec{2u, atype::BOOL}));
9191
BOOST_REQUIRE_EQUAL(hspecs[0].result, (DatumSpec{0u, atype::BOOL}));
9292

93-
BOOST_REQUIRE_EQUAL(hspecs[1].left, (DatumSpec{std::string{"phi"}, atype::FLOAT}));
93+
BOOST_REQUIRE_EQUAL(hspecs[1].left, (DatumSpec{std::string{"phi"}, 2, atype::FLOAT}));
9494
BOOST_REQUIRE_EQUAL(hspecs[1].right, (DatumSpec{LiteralNode::var_t{3}, atype::INT32}));
9595
BOOST_REQUIRE_EQUAL(hspecs[1].result, (DatumSpec{2u, atype::BOOL}));
9696

97-
BOOST_REQUIRE_EQUAL(hspecs[2].left, (DatumSpec{std::string{"phi"}, atype::FLOAT}));
97+
BOOST_REQUIRE_EQUAL(hspecs[2].left, (DatumSpec{std::string{"phi"}, 2, atype::FLOAT}));
9898
BOOST_REQUIRE_EQUAL(hspecs[2].right, (DatumSpec{LiteralNode::var_t{0}, atype::INT32}));
9999
BOOST_REQUIRE_EQUAL(hspecs[2].result, (DatumSpec{1u, atype::BOOL}));
100100

@@ -112,15 +112,15 @@ BOOST_AUTO_TEST_CASE(TestTreeParsing)
112112
BOOST_REQUIRE_EQUAL(uspecs[2].right, (DatumSpec{}));
113113
BOOST_REQUIRE_EQUAL(uspecs[2].result, (DatumSpec{3u, atype::DOUBLE}));
114114

115-
BOOST_REQUIRE_EQUAL(uspecs[3].left, (DatumSpec{std::string{"phi"}, atype::FLOAT}));
115+
BOOST_REQUIRE_EQUAL(uspecs[3].left, (DatumSpec{std::string{"phi"}, 2, atype::FLOAT}));
116116
BOOST_REQUIRE_EQUAL(uspecs[3].right, (DatumSpec{LiteralNode::var_t{2.0 * M_PI}, atype::DOUBLE}));
117117
BOOST_REQUIRE_EQUAL(uspecs[3].result, (DatumSpec{4u, atype::DOUBLE}));
118118

119119
BOOST_REQUIRE_EQUAL(uspecs[4].left, (DatumSpec{5u, atype::FLOAT}));
120120
BOOST_REQUIRE_EQUAL(uspecs[4].right, (DatumSpec{LiteralNode::var_t{1.0}, atype::DOUBLE}));
121121
BOOST_REQUIRE_EQUAL(uspecs[4].result, (DatumSpec{1u, atype::BOOL}));
122122

123-
BOOST_REQUIRE_EQUAL(uspecs[5].left, (DatumSpec{std::string{"eta"}, atype::FLOAT}));
123+
BOOST_REQUIRE_EQUAL(uspecs[5].left, (DatumSpec{std::string{"eta"}, 3, atype::FLOAT}));
124124
BOOST_REQUIRE_EQUAL(uspecs[5].right, (DatumSpec{}));
125125
BOOST_REQUIRE_EQUAL(uspecs[5].result, (DatumSpec{5u, atype::FLOAT}));
126126

@@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(TestTreeParsing)
130130
BOOST_REQUIRE_EQUAL(ptfilter.node->left->self.index(), 1);
131131
BOOST_REQUIRE_EQUAL(ptfilter.node->right->self.index(), 3);
132132
auto ptfilterspecs = createOperations(ptfilter);
133-
BOOST_REQUIRE_EQUAL(ptfilterspecs[0].left, (DatumSpec{std::string{"fPt"}, atype::FLOAT}));
133+
BOOST_REQUIRE_EQUAL(ptfilterspecs[0].left, (DatumSpec{std::string{"fPt"}, typeid(o2::aod::track::Pt).hash_code(), atype::FLOAT}));
134134
BOOST_REQUIRE_EQUAL(ptfilterspecs[0].right, (DatumSpec{LiteralNode::var_t{0.5f}, atype::FLOAT}));
135135
BOOST_REQUIRE_EQUAL(ptfilterspecs[0].result, (DatumSpec{0u, atype::BOOL}));
136136
}
@@ -139,12 +139,12 @@ BOOST_AUTO_TEST_CASE(TestGandivaTreeCreation)
139139
{
140140
Projector pze = o2::aod::track::Pze::Projector();
141141
auto pzspecs = createOperations(std::move(pze));
142-
BOOST_REQUIRE_EQUAL(pzspecs[0].left, (DatumSpec{std::string{"fTgl"}, atype::FLOAT}));
142+
BOOST_REQUIRE_EQUAL(pzspecs[0].left, (DatumSpec{std::string{"fTgl"}, typeid(o2::aod::track::Tgl).hash_code(), atype::FLOAT}));
143143
BOOST_REQUIRE_EQUAL(pzspecs[0].right, (DatumSpec{1u, atype::FLOAT}));
144144
BOOST_REQUIRE_EQUAL(pzspecs[0].result, (DatumSpec{0u, atype::FLOAT}));
145145

146146
BOOST_REQUIRE_EQUAL(pzspecs[1].left, (DatumSpec{LiteralNode::var_t{1.f}, atype::FLOAT}));
147-
BOOST_REQUIRE_EQUAL(pzspecs[1].right, (DatumSpec{std::string{"fSigned1Pt"}, atype::FLOAT}));
147+
BOOST_REQUIRE_EQUAL(pzspecs[1].right, (DatumSpec{std::string{"fSigned1Pt"}, typeid(o2::aod::track::Signed1Pt).hash_code(), atype::FLOAT}));
148148
BOOST_REQUIRE_EQUAL(pzspecs[1].result, (DatumSpec{1u, atype::FLOAT}));
149149
auto infield1 = o2::aod::track::Signed1Pt::asArrowField();
150150
auto infield2 = o2::aod::track::Tgl::asArrowField();
@@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE(TestGandivaTreeCreation)
163163
BOOST_REQUIRE_EQUAL(ptespecs[0].result, (DatumSpec{0u, atype::FLOAT}));
164164

165165
BOOST_REQUIRE_EQUAL(ptespecs[1].left, (DatumSpec{LiteralNode::var_t{1.f}, atype::FLOAT}));
166-
BOOST_REQUIRE_EQUAL(ptespecs[1].right, (DatumSpec{std::string{"fSigned1Pt"}, atype::FLOAT}));
166+
BOOST_REQUIRE_EQUAL(ptespecs[1].right, (DatumSpec{std::string{"fSigned1Pt"}, typeid(o2::aod::track::Signed1Pt).hash_code(), atype::FLOAT}));
167167
BOOST_REQUIRE_EQUAL(ptespecs[1].result, (DatumSpec{1u, atype::FLOAT}));
168168

169169
auto infield3 = o2::aod::track::Signed1Pt::asArrowField();

0 commit comments

Comments
 (0)