Skip to content

Commit f919b12

Browse files
committed
update for preslice
1 parent 844c74f commit f919b12

File tree

3 files changed

+91
-84
lines changed

3 files changed

+91
-84
lines changed

Framework/Core/include/Framework/ASoA.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,7 @@ template <typename T, typename Policy, bool OPT = false>
14161416
struct PresliceBase : public Policy {
14171417
constexpr static bool optional = OPT;
14181418
using target_t = T;
1419+
using policy_t = Policy;
14191420
const std::string binding;
14201421

14211422
PresliceBase(expressions::BindingNode index_)
@@ -1453,6 +1454,15 @@ using Preslice = PresliceBase<T, PreslicePolicySorted, false>;
14531454
template <typename T>
14541455
using PresliceOptional = PresliceBase<T, PreslicePolicySorted, true>;
14551456

1457+
template <typename T>
1458+
concept is_preslice = requires(T t) {
1459+
std::same_as<decltype(t.binding), std::string>;
1460+
std::same_as<decltype(t.bindingKey), StringPair>;
1461+
&T::isMising;
1462+
&T::updateSliceInfo;
1463+
&T::getSliceFor;
1464+
};
1465+
14561466
} // namespace o2::framework
14571467

14581468
namespace o2::soa

Framework/Core/include/Framework/AnalysisManagers.h

Lines changed: 72 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -509,98 +509,95 @@ static void setGroupedCombination(C& comb, TG& grouping, std::tuple<Ts...>& asso
509509
}
510510
}
511511

512-
} // namespace analysis_task_parsers
512+
/// Preslice handling
513+
template <typename T>
514+
bool registerCache(T&, std::vector<StringPair>&, std::vector<StringPair>&)
515+
{
516+
return false;
517+
}
513518

514-
template <typename ANY>
515-
struct UpdateProcessSwitches {
516-
static bool set(std::pair<std::string, bool>, ANY&)
517-
{
518-
return false;
519-
}
520-
};
521-
522-
template <typename R, typename T, typename... As>
523-
struct UpdateProcessSwitches<ProcessConfigurable<R, T, As...>> {
524-
static bool set(std::pair<std::string, bool> setting, ProcessConfigurable<R, T, As...>& what)
525-
{
526-
if (what.name == setting.first) {
527-
what.value = setting.second;
519+
template <is_preslice T>
520+
requires std::same_as<typename T::policy_t, framework::PreslicePolicySorted>
521+
bool registerCache(T& preslice, std::vector<StringPair>& bsks, std::vector<StringPair>&)
522+
{
523+
if constexpr (T::optional) {
524+
if (preslice.binding == "[MISSING]") {
528525
return true;
529526
}
530-
return false;
531527
}
532-
};
533-
534-
/// Manager template to handle slice caching
535-
template <typename T>
536-
struct PresliceManager {
537-
static bool registerCache(T&, std::vector<StringPair>&, std::vector<StringPair>&)
538-
{
539-
return false;
528+
auto locate = std::find_if(bsks.begin(), bsks.end(), [&](auto const& entry) { return (entry.first == preslice.bindingKey.first) && (entry.second == preslice.bindingKey.second); });
529+
if (locate == bsks.end()) {
530+
bsks.emplace_back(preslice.getBindingKey());
540531
}
532+
return true;
533+
}
541534

542-
static bool updateSliceInfo(T&, ArrowTableSlicingCache&)
543-
{
544-
return false;
545-
}
546-
};
547-
548-
template <typename T, typename Policy, bool OPT>
549-
struct PresliceManager<PresliceBase<T, Policy, OPT>> {
550-
static bool registerCache(PresliceBase<T, Policy, OPT>& container, std::vector<StringPair>& bsks, std::vector<StringPair>&)
551-
requires std::same_as<Policy, framework::PreslicePolicySorted>
552-
{
553-
if constexpr (OPT) {
554-
if (container.binding == "[MISSING]") {
555-
return true;
556-
}
557-
}
558-
auto locate = std::find_if(bsks.begin(), bsks.end(), [&](auto const& entry) { return (entry.first == container.bindingKey.first) && (entry.second == container.bindingKey.second); });
559-
if (locate == bsks.end()) {
560-
bsks.emplace_back(container.getBindingKey());
535+
template <is_preslice T>
536+
requires std::same_as<typename T::policy_t, framework::PreslicePolicyGeneral>
537+
bool registerCache(T& preslice, std::vector<StringPair>&, std::vector<StringPair>& bsksU)
538+
{
539+
if constexpr (T::optional) {
540+
if (preslice.binding == "[MISSING]") {
541+
return true;
561542
}
562-
return true;
563543
}
544+
auto locate = std::find_if(bsksU.begin(), bsksU.end(), [&](auto const& entry) { return (entry.first == preslice.bindingKey.first) && (entry.second == preslice.bindingKey.second); });
545+
if (locate == bsksU.end()) {
546+
bsksU.emplace_back(preslice.getBindingKey());
547+
}
548+
return true;
549+
}
564550

565-
static bool registerCache(PresliceBase<T, Policy, OPT>& container, std::vector<StringPair>&, std::vector<StringPair>& bsksU)
566-
requires std::same_as<Policy, framework::PreslicePolicyGeneral>
567-
{
568-
if constexpr (OPT) {
569-
if (container.binding == "[MISSING]") {
570-
return true;
571-
}
572-
}
573-
auto locate = std::find_if(bsksU.begin(), bsksU.end(), [&](auto const& entry) { return (entry.first == container.bindingKey.first) && (entry.second == container.bindingKey.second); });
574-
if (locate == bsksU.end()) {
575-
bsksU.emplace_back(container.getBindingKey());
551+
template <typename T>
552+
bool updateSliceInfo(T&, ArrowTableSlicingCache&)
553+
{
554+
return false;
555+
}
556+
557+
template <is_preslice T>
558+
static bool updateSliceInfo(T& preslice, ArrowTableSlicingCache& cache)
559+
requires std::same_as<typename T::policy_t, framework::PreslicePolicySorted>
560+
{
561+
if constexpr (T::optional) {
562+
if (preslice.binding == "[MISSING]") {
563+
return true;
576564
}
577-
return true;
578565
}
566+
preslice.updateSliceInfo(cache.getCacheFor(preslice.getBindingKey()));
567+
return true;
568+
}
579569

580-
static bool updateSliceInfo(PresliceBase<T, Policy, OPT>& container, ArrowTableSlicingCache& cache)
581-
requires std::same_as<Policy, framework::PreslicePolicySorted>
582-
{
583-
if constexpr (OPT) {
584-
if (container.binding == "[MISSING]") {
585-
return true;
586-
}
570+
template <is_preslice T>
571+
static bool updateSliceInfo(T& preslice, ArrowTableSlicingCache& cache)
572+
requires std::same_as<typename T::policy_t, framework::PreslicePolicyGeneral>
573+
{
574+
if constexpr (T::optional) {
575+
if (preslice.binding == "[MISSING]") {
576+
return true;
587577
}
588-
container.updateSliceInfo(cache.getCacheFor(container.getBindingKey()));
589-
return true;
590578
}
579+
preslice.updateSliceInfo(cache.getCacheUnsortedFor(preslice.getBindingKey()));
580+
return true;
581+
}
591582

592-
static bool updateSliceInfo(PresliceBase<T, Policy, OPT>& container, ArrowTableSlicingCache& cache)
593-
requires std::same_as<Policy, framework::PreslicePolicyGeneral>
594-
{
595-
if constexpr (OPT) {
596-
if (container.binding == "[MISSING]") {
597-
return true;
598-
}
599-
}
600-
container.updateSliceInfo(cache.getCacheUnsortedFor(container.getBindingKey()));
583+
/// Process switches handling
584+
template <typename T>
585+
static bool setProcessSwitch(std::pair<std::string, bool>, T&)
586+
{
587+
return false;
588+
}
589+
590+
template <is_process_configurable T>
591+
static bool setProcessSwitch(std::pair<std::string, bool> setting, T& pc)
592+
{
593+
if (pc.name == setting.first) {
594+
pc.value = setting.second;
601595
return true;
602596
}
603-
};
597+
return false;
598+
}
599+
600+
} // namespace analysis_task_parsers
604601
} // namespace o2::framework
605602

606603
#endif // ANALYSISMANAGERS_H

Framework/Core/include/Framework/AnalysisTask.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,8 @@ auto getTaskNameSetProcesses(std::string& outputName, TaskName first, SetDefault
444444
auto task = std::make_shared<T>(std::forward<A>(args)...);
445445
for (auto& setting : second.map) {
446446
homogeneous_apply_refs(
447-
[&](auto& x) {
448-
return UpdateProcessSwitches<std::decay_t<decltype(x)>>::set(setting, x);
447+
[&](auto& element) {
448+
return analysis_task_parsers::setProcessSwitch(setting, element);
449449
},
450450
*task.get());
451451
}
@@ -459,8 +459,8 @@ auto getTaskNameSetProcesses(std::string& outputName, SetDefaultProcesses first,
459459
auto task = std::make_shared<T>(std::forward<A>(args)...);
460460
for (auto& setting : first.map) {
461461
homogeneous_apply_refs(
462-
[&](auto& x) {
463-
return UpdateProcessSwitches<std::decay_t<decltype(x)>>::set(setting, x);
462+
[&](auto& element) {
463+
return analysis_task_parsers::setProcessSwitch(setting, element);
464464
},
465465
*task.get());
466466
}
@@ -474,8 +474,8 @@ auto getTaskNameSetProcesses(std::string& outputName, SetDefaultProcesses first,
474474
auto task = std::make_shared<T>(std::forward<A>(args)...);
475475
for (auto& setting : first.map) {
476476
homogeneous_apply_refs(
477-
[&](auto& x) {
478-
return UpdateProcessSwitches<std::decay_t<decltype(x)>>::set(setting, x);
477+
[&](auto& element) {
478+
return analysis_task_parsers::setProcessSwitch(setting, element);
479479
},
480480
*task.get());
481481
}
@@ -550,7 +550,7 @@ DataProcessorSpec adaptAnalysisTask(ConfigContext const& ctx, Args&&... args)
550550
*task.get());
551551

552552
// add preslice declarations to slicing cache definition
553-
homogeneous_apply_refs([&bindingsKeys, &bindingsKeysUnsorted](auto& x) { return PresliceManager<std::decay_t<decltype(x)>>::registerCache(x, bindingsKeys, bindingsKeysUnsorted); }, *task.get());
553+
homogeneous_apply_refs([&bindingsKeys, &bindingsKeysUnsorted](auto& element) { return analysis_task_parsers::registerCache(element, bindingsKeys, bindingsKeysUnsorted); }, *task.get());
554554

555555
// request base tables for spawnable extended tables and indices to be built
556556
// this checks for duplications
@@ -620,8 +620,8 @@ DataProcessorSpec adaptAnalysisTask(ConfigContext const& ctx, Args&&... args)
620620
}
621621
// reset pre-slice for the next dataframe
622622
auto slices = pc.services().get<ArrowTableSlicingCache>();
623-
homogeneous_apply_refs([&pc, &slices](auto& x) {
624-
return PresliceManager<std::decay_t<decltype(x)>>::updateSliceInfo(x, slices);
623+
homogeneous_apply_refs([&pc, &slices](auto& element) {
624+
return analysis_task_parsers::updateSliceInfo(element, slices);
625625
},
626626
*(task.get()));
627627
// initialize local caches

0 commit comments

Comments
 (0)