Skip to content

Commit 1e234df

Browse files
authored
DPL Analysis: Dynamic extraction matchers (#15402)
1 parent 4a5adf1 commit 1e234df

21 files changed

Lines changed: 491 additions & 327 deletions

Framework/AnalysisSupport/src/AODJAlienReaderHelpers.cxx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,9 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
240240
// create header
241241
auto concrete = DataSpecUtils::asConcreteDataMatcher(route.matcher);
242242
auto dh = header::DataHeader(concrete.description, concrete.origin, concrete.subSpec);
243+
bool wasAOD = std::ranges::any_of(route.matcher.metadata, [](ConfigParamSpec const& p) { return p.name.starts_with("aod-origin-replaced"); });
243244

244-
if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed)) {
245+
if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD)) {
245246
if (first) {
246247
// check if there is a next file to read
247248
fcnt += device.maxInputTimeslices;
@@ -255,7 +256,7 @@ AlgorithmSpec AODJAlienReaderHelpers::rootFileReaderCallback(ConfigContext const
255256
}
256257
// get first folder of next file
257258
ntf = 0;
258-
if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed)) {
259+
if (!didir->readTree(outputs, dh, fcnt, ntf, totalSizeCompressed, totalSizeUncompressed, wasAOD)) {
259260
LOGP(fatal, "Can not retrieve tree for table {}: fileCounter {}, timeFrame {}", concrete.origin.as<std::string>(), fcnt, ntf);
260261
throw std::runtime_error("Processing is stopped!");
261262
}

Framework/AnalysisSupport/src/DataInputDirector.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ uint64_t DataInputDirector::getTimeFrameNumber(header::DataHeader dh, int counte
900900
return didesc->getTimeFrameNumber(counter, numTF, wantedLevel, origin);
901901
}
902902

903-
bool DataInputDirector::readTree(DataAllocator& outputs, header::DataHeader dh, int counter, int numTF, size_t& totalSizeCompressed, size_t& totalSizeUncompressed)
903+
bool DataInputDirector::readTree(DataAllocator& outputs, header::DataHeader dh, int counter, int numTF, size_t& totalSizeCompressed, size_t& totalSizeUncompressed, bool wasAOD)
904904
{
905905
std::string treename;
906906

@@ -913,7 +913,7 @@ bool DataInputDirector::readTree(DataAllocator& outputs, header::DataHeader dh,
913913
// . filename from defaultDataInputDescriptor
914914
// . treename from DataHeader
915915
didesc = mdefaultDataInputDescriptor;
916-
treename = aod::datamodel::getTreeName(dh);
916+
treename = aod::datamodel::getTreeName(dh, wasAOD);
917917
}
918918
std::string origin = dh.dataOrigin.as<std::string>();
919919

Framework/AnalysisSupport/src/DataInputDirector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class DataInputDirector
160160
int getNumberInputDescriptors() { return mdataInputDescriptors.size(); }
161161
void createDefaultDataInputDescriptor();
162162

163-
bool readTree(DataAllocator& outputs, header::DataHeader dh, int counter, int numTF, size_t& totalSizeCompressed, size_t& totalSizeUncompressed);
163+
bool readTree(DataAllocator& outputs, header::DataHeader dh, int counter, int numTF, size_t& totalSizeCompressed, size_t& totalSizeUncompressed, bool wasAOD);
164164
uint64_t getTimeFrameNumber(header::DataHeader dh, int counter, int numTF);
165165
arrow::dataset::FileSource getFileFolder(header::DataHeader dh, int counter, int numTF);
166166
int getTimeFramesInFile(header::DataHeader dh, int counter);

Framework/Core/include/Framework/ASoA.h

Lines changed: 35 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,9 +1410,9 @@ static constexpr std::string getLabelFromType()
14101410
}
14111411

14121412
template <typename... C>
1413-
static constexpr auto hasColumnForKey(framework::pack<C...>, std::string const& key)
1413+
static constexpr auto hasColumnForKey(framework::pack<C...>, std::string_view key)
14141414
{
1415-
auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string& str2) {
1415+
auto caseInsensitiveCompare = [](const std::string_view& str1, const std::string_view& str2) {
14161416
return std::ranges::equal(
14171417
str1, str2,
14181418
[](char c1, char c2) {
@@ -1424,43 +1424,31 @@ static constexpr auto hasColumnForKey(framework::pack<C...>, std::string const&
14241424
}
14251425

14261426
template <TableRef ref>
1427-
static constexpr std::pair<bool, std::string> hasKey(std::string const& key)
1427+
static constexpr std::pair<bool, std::string> hasKey(std::string_view key)
14281428
{
14291429
return {hasColumnForKey(typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{}, key), aod::label<ref>()};
14301430
}
14311431

14321432
template <TableRef ref>
1433-
static constexpr std::pair<bool, framework::ConcreteDataMatcher> hasKeyM(std::string const& key)
1433+
static constexpr std::pair<bool, framework::ConcreteDataMatcher> hasKeyM(std::string_view key)
14341434
{
14351435
return {hasColumnForKey(typename aod::MetadataTrait<o2::aod::Hash<ref.desc_hash>>::metadata::columns{}, key), aod::matcher<ref>()};
14361436
}
14371437

1438-
template <typename... C>
1439-
static constexpr auto haveKey(framework::pack<C...>, std::string const& key)
1440-
{
1441-
return std::vector{hasKey<C>(key)...};
1442-
}
1443-
14441438
void notFoundColumn(const char* label, const char* key);
14451439
void missingOptionalPreslice(const char* label, const char* key);
14461440

14471441
template <with_originals T, bool OPT = false>
1448-
static constexpr std::string getLabelFromTypeForKey(std::string const& key)
1442+
static constexpr std::string getLabelFromTypeForKey(std::string_view key)
14491443
{
1450-
if constexpr (T::originals.size() == 1) {
1451-
auto locate = hasKey<T::originals[0]>(key);
1452-
if (locate.first) {
1453-
return locate.second;
1454-
}
1455-
} else {
1456-
auto locate = [&]<size_t... Is>(std::index_sequence<Is...>) {
1457-
return std::vector{hasKey<T::originals[Is]>(key)...};
1458-
}(std::make_index_sequence<T::originals.size()>{});
1459-
auto it = std::find_if(locate.begin(), locate.end(), [](auto const& x) { return x.first; });
1460-
if (it != locate.end()) {
1461-
return it->second;
1462-
}
1444+
auto locate = []<size_t... Is>(std::index_sequence<Is...>, std::string_view key) {
1445+
return std::array{hasKey<T::originals[Is]>(key)...} |
1446+
std::views::filter([](auto const& x) { return x.first; });
1447+
}(std::make_index_sequence<T::originals.size()>{}, key);
1448+
if (!locate.empty()) {
1449+
return locate.front().second;
14631450
}
1451+
14641452
if constexpr (!OPT) {
14651453
notFoundColumn(getLabelFromType<std::decay_t<T>>().data(), key.data());
14661454
} else {
@@ -1470,22 +1458,16 @@ static constexpr std::string getLabelFromTypeForKey(std::string const& key)
14701458
}
14711459

14721460
template <with_originals T, bool OPT = false>
1473-
static constexpr framework::ConcreteDataMatcher getMatcherFromTypeForKey(std::string const& key)
1461+
static constexpr framework::ConcreteDataMatcher getMatcherFromTypeForKey(std::string_view key)
14741462
{
1475-
if constexpr (T::originals.size() == 1) {
1476-
auto locate = hasKeyM<T::originals[0]>(key);
1477-
if (locate.first) {
1478-
return locate.second;
1479-
}
1480-
} else {
1481-
auto locate = [&]<size_t... Is>(std::index_sequence<Is...>) {
1482-
return std::vector{hasKeyM<T::originals[Is]>(key)...};
1483-
}(std::make_index_sequence<T::originals.size()>{});
1484-
auto it = std::find_if(locate.begin(), locate.end(), [](auto const& x) { return x.first; });
1485-
if (it != locate.end()) {
1486-
return it->second;
1487-
}
1463+
auto locate = []<size_t... Is>(std::index_sequence<Is...>, std::string_view key) {
1464+
return std::array{hasKeyM<T::originals[Is]>(key)...} |
1465+
std::views::filter([](auto const& x) { return x.first; });
1466+
}(std::make_index_sequence<T::originals.size()>{}, key);
1467+
if (!locate.empty()) {
1468+
return locate.front().second;
14881469
}
1470+
14891471
if constexpr (!OPT) {
14901472
notFoundColumn(getLabelFromType<std::decay_t<T>>().data(), key.data());
14911473
} else {
@@ -1521,7 +1503,7 @@ consteval static bool relatedBySortedIndex()
15211503

15221504
namespace o2::framework
15231505
{
1524-
1506+
/// tracks origin in bindingKey matcher to handle the correct arguments
15251507
struct PreslicePolicyBase {
15261508
const std::string binding;
15271509
Entry bindingKey;
@@ -1547,7 +1529,7 @@ struct PreslicePolicyGeneral : public PreslicePolicyBase {
15471529
template <typename T>
15481530
concept is_preslice_policy = std::derived_from<T, PreslicePolicyBase>;
15491531

1550-
template <typename T, is_preslice_policy Policy, bool OPT = false>
1532+
template <soa::is_table T, is_preslice_policy Policy, bool OPT = false>
15511533
struct PresliceBase : public Policy {
15521534
constexpr static bool optional = OPT;
15531535
using target_t = T;
@@ -1580,13 +1562,13 @@ struct PresliceBase : public Policy {
15801562
}
15811563
};
15821564

1583-
template <typename T>
1565+
template <soa::is_table T>
15841566
using PresliceUnsorted = PresliceBase<T, PreslicePolicyGeneral, false>;
1585-
template <typename T>
1567+
template <soa::is_table T>
15861568
using PresliceUnsortedOptional = PresliceBase<T, PreslicePolicyGeneral, true>;
1587-
template <typename T>
1569+
template <soa::is_table T>
15881570
using Preslice = PresliceBase<T, PreslicePolicySorted, false>;
1589-
template <typename T>
1571+
template <soa::is_table T>
15901572
using PresliceOptional = PresliceBase<T, PreslicePolicySorted, true>;
15911573

15921574
template <typename T>
@@ -1741,10 +1723,13 @@ auto doFilteredSliceBy(T const* table, o2::framework::PresliceBase<C, framework:
17411723
return prepareFilteredSlice(table, slice, offset);
17421724
}
17431725

1726+
std::function<framework::ConcreteDataMatcher(framework::ConcreteDataMatcher&&)> originReplacement(header::DataOrigin newOrigin);
1727+
17441728
template <soa::is_table T>
17451729
auto doSliceByCached(T const* table, framework::expressions::BindingNode const& node, int value, o2::framework::SliceCache& cache)
17461730
{
1747-
auto localCache = cache.ptr->getCacheFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1731+
auto localCache = cache.ptr->getCacheFor({"", originReplacement(cache.ptr->newOrigin)(o2::soa::getMatcherFromTypeForKey<T>(node.name)),
1732+
node.name});
17481733
auto [offset, count] = localCache.getSliceFor(value);
17491734
auto t = typename T::self_t({table->asArrowTable()->Slice(static_cast<uint64_t>(offset), count)}, static_cast<uint64_t>(offset));
17501735
if (t.tableSize() != 0) {
@@ -1756,7 +1741,8 @@ auto doSliceByCached(T const* table, framework::expressions::BindingNode const&
17561741
template <soa::is_filtered_table T>
17571742
auto doFilteredSliceByCached(T const* table, framework::expressions::BindingNode const& node, int value, o2::framework::SliceCache& cache)
17581743
{
1759-
auto localCache = cache.ptr->getCacheFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1744+
auto localCache = cache.ptr->getCacheFor({"", originReplacement(cache.ptr->newOrigin)(o2::soa::getMatcherFromTypeForKey<T>(node.name)),
1745+
node.name});
17601746
auto [offset, count] = localCache.getSliceFor(value);
17611747
auto slice = table->asArrowTable()->Slice(static_cast<uint64_t>(offset), count);
17621748
return prepareFilteredSlice(table, slice, offset);
@@ -1765,7 +1751,8 @@ auto doFilteredSliceByCached(T const* table, framework::expressions::BindingNode
17651751
template <soa::is_table T>
17661752
auto doSliceByCachedUnsorted(T const* table, framework::expressions::BindingNode const& node, int value, o2::framework::SliceCache& cache)
17671753
{
1768-
auto localCache = cache.ptr->getCacheUnsortedFor({"", o2::soa::getMatcherFromTypeForKey<T>(node.name), node.name});
1754+
auto localCache = cache.ptr->getCacheUnsortedFor({"", originReplacement(cache.ptr->newOrigin)(o2::soa::getMatcherFromTypeForKey<T>(node.name)),
1755+
node.name});
17691756
if constexpr (soa::is_filtered_table<T>) {
17701757
auto t = typename T::self_t({table->asArrowTable()}, localCache.getSliceFor(value));
17711758
if (t.tableSize() != 0) {
@@ -1837,12 +1824,6 @@ consteval auto computeOriginals()
18371824
return o2::soa::mergeOriginals<Ts...>();
18381825
}
18391826

1840-
// template <size_t N, std::array<TableRef, N> refs>
1841-
// consteval auto commonOrigin()
1842-
// {
1843-
// return (refs | std::ranges::views::filter([](TableRef const& r) { return (!(r.origin_hash == "DYN"_h || r.origin_hash == "IDX"_h)); })).front().origin_hash;
1844-
// }
1845-
18461827
/// A Table class which observes an arrow::Table and provides
18471828
/// It is templated on a set of Column / DynamicColumn types.
18481829
template <aod::is_aod_hash L, aod::is_aod_hash D, aod::is_origin_hash O, typename... Ts>
@@ -4285,7 +4266,7 @@ using SmallGroupsUnfiltered = SmallGroupsBase<T, false>;
42854266

42864267
template <typename T>
42874268
concept is_smallgroups = requires {
4288-
[]<typename B, bool A>(SmallGroupsBase<B, A>*) {}(std::declval<T*>());
4269+
[]<typename B, bool A>(SmallGroupsBase<B, A>*) {}(std::declval<std::decay_t<T>*>());
42894270
};
42904271
} // namespace o2::soa
42914272

Framework/Core/include/Framework/AnalysisDataModelHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616

1717
namespace o2::aod::datamodel
1818
{
19-
std::string getTreeName(header::DataHeader dh);
19+
std::string getTreeName(header::DataHeader dh, bool wasAOD);
2020
} // namespace o2::aod::datamodel
2121
#endif // O2_FRAMEWORK_ANALYSISDATAMODELHELPERS_H_

0 commit comments

Comments
 (0)