Skip to content

Commit ca6ef8f

Browse files
authored
DPL Analysis: fix configurables placeholders in expressions (#5803)
1 parent e0aba31 commit ca6ef8f

File tree

4 files changed

+17
-30
lines changed

4 files changed

+17
-30
lines changed

Analysis/Tutorials/src/filters.cxx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,26 @@ struct BTask {
5252
Spawns<aod::MTracks> mtrk;
5353

5454
float fPI = static_cast<float>(M_PI);
55-
float ptlow = 0.5f;
56-
float ptup = 2.0f;
55+
Configurable<float> ptlow{"ptlow", 0.5f, ""};
56+
Configurable<float> ptup{"ptup", 2.0f, ""};
5757
Filter ptFilter_a = aod::track::pt > ptlow;
5858
Filter ptFilter_b = aod::track::pt < ptup;
5959

60-
float etalow = -1.0f;
61-
float etaup = 1.0f;
60+
Configurable<float> etalow{"etalow", -1.0f, ""};
61+
Configurable<float> etaup{"etaup", 1.0f, ""};
6262
Filter etafilter = (aod::track::eta < etaup) && (aod::track::eta > etalow);
6363

6464
float philow = 1.0f;
6565
float phiup = 2.0f;
6666
Filter phifilter = (aod::etaphi::nphi < phiup) && (aod::etaphi::nphi > philow);
6767

68-
Filter posZfilter = nabs(aod::collision::posZ) < 10.0f;
68+
Configurable<float> vtxZ{"vtxZ", 10.f, ""};
69+
Filter posZfilter = nabs(aod::collision::posZ) < vtxZ;
6970

7071
void process(soa::Filtered<aod::Collisions>::iterator const& collision, soa::Filtered<soa::Join<aod::Tracks, aod::TPhi>> const& tracks)
7172
{
72-
LOGF(INFO, "Collision: %d [N = %d out of %d], -10 < %.3f < 10",
73-
collision.globalIndex(), tracks.size(), tracks.tableSize(), collision.posZ());
73+
LOGF(INFO, "Collision: %d [N = %d out of %d], -%.1f < %.3f < %.1f",
74+
collision.globalIndex(), tracks.size(), tracks.tableSize(), vtxZ, collision.posZ(), vtxZ);
7475
for (auto& track : tracks) {
7576
LOGF(INFO, "id = %d; eta: %.3f < %.3f < %.3f; phi: %.3f < %.3f < %.3f; pt: %.3f < %.3f < %.3f",
7677
track.collisionId(), etalow, track.eta(), etaup, philow, track.nphi(), phiup, ptlow, track.pt(), ptup);

Framework/Core/include/Framework/AnalysisTask.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,11 @@ DataProcessorSpec adaptAnalysisTask(ConfigContext const& ctx, Args&&... args)
677677
if constexpr (has_process_v<T>) {
678678
/// update configurables in filters
679679
std::apply(
680-
[&ic](auto&&... x) { return (FilterManager<std::decay_t<decltype(x)>>::updatePlaceholders(x, ic), ...); },
680+
[&ic](auto&... x) { return (FilterManager<std::decay_t<decltype(x)>>::updatePlaceholders(x, ic), ...); },
681681
tupledTask);
682682
/// update configurables in partitions
683683
std::apply(
684-
[&ic](auto&&... x) { return (PartitionManager<std::decay_t<decltype(x)>>::updatePlaceholders(x, ic), ...); },
684+
[&ic](auto&... x) { return (PartitionManager<std::decay_t<decltype(x)>>::updatePlaceholders(x, ic), ...); },
685685
tupledTask);
686686
/// create for filters gandiva trees matched to schemas and store the pointers into expressionInfos
687687
std::apply([&expressionInfos](auto&... x) {

Framework/Core/include/Framework/Expressions.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ struct PlaceholderNode : LiteralNode {
123123
if constexpr (variant_trait_v<typename std::decay<T>::type> != VariantType::Unknown) {
124124
retrieve = [](InitContext& context, std::string const& name) { return LiteralNode::var_t{context.options().get<T>(name.c_str())}; };
125125
} else {
126-
retrieve = [](InitContext& context, std::string const& name) {
127-
auto pt = context.options().get<boost::property_tree::ptree>(name.c_str());
128-
return LiteralNode::var_t{RootConfigParamHelpers::as<T>(pt)};
129-
};
126+
runtime_error("Unknown parameter used in expression.");
130127
}
131128
}
132129

Framework/Core/src/Expressions.cxx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,20 @@ void updatePlaceholders(Filter& filter, InitContext& context)
132132
}
133133
};
134134

135-
auto isLeaf = [](Node const* const node) {
136-
return ((node->left == nullptr) && (node->right == nullptr));
137-
};
138-
139135
// while the stack is not empty
140136
while (path.empty() == false) {
141137
auto& top = path.top();
142-
143138
updateNode(top.node_ptr);
144139

140+
auto leftp = top.node_ptr->left.get();
141+
auto rightp = top.node_ptr->right.get();
145142
path.pop();
146143

147-
if (top.node_ptr->left != nullptr) {
148-
if (isLeaf(top.node_ptr->left.get())) {
149-
updateNode(top.node_ptr->left.get());
150-
} else {
151-
path.emplace(top.node_ptr->left.get(), 0);
152-
}
144+
if (leftp != nullptr) {
145+
path.emplace(leftp, 0);
153146
}
154-
if (top.node_ptr->right != nullptr) {
155-
if (isLeaf(top.node_ptr->right.get())) {
156-
updateNode(top.node_ptr->right.get());
157-
} else {
158-
path.emplace(top.node_ptr->right.get(), 0);
159-
}
147+
if (rightp != nullptr) {
148+
path.emplace(rightp, 0);
160149
}
161150
}
162151
}

0 commit comments

Comments
 (0)