1919
2020namespace o2 ::framework
2121{
22- using ListVector = std::vector<std::vector<int64_t >>;
23-
2422struct SliceInfoPtr {
2523 gsl::span<int64_t const > offsets;
2624 gsl::span<int64_t const > sizes;
2725
2826 std::pair<int64_t , int64_t > getSliceFor (int value) const ;
2927};
3028
29+ // / view of an unsorted slice-info table: rows of group v are rows[offsets[v], offsets[v + 1])
3130struct SliceInfoUnsortedPtr {
32- std::span<int const > values ;
33- ListVector const * groups ;
31+ std::span<int32_t const > offsets ;
32+ std::span< int64_t const > rows ;
3433
3534 std::span<int64_t const > getSliceFor (int value) const ;
3635};
@@ -56,6 +55,28 @@ struct Entry {
5655 }
5756};
5857
58+ // / Layout of the slice-info tables produced by the internal slicer device.
59+ // / Row v describes the group with index value v, for v in [0, max index value];
60+ // / rows with negative index values do not belong to any group.
61+ struct SliceInfo {
62+ // / sorted: group v is the contiguous range [fOffset, fOffset + fSize)
63+ static constexpr const char * offsetsLabel = " fOffset" ; // int64
64+ static constexpr const char * sizesLabel = " fSize" ; // int64
65+ // / unsorted: group v is the list of row numbers in fRows
66+ static constexpr const char * rowsLabel = " fRows" ; // list<int64>
67+
68+ static std::shared_ptr<arrow::Schema> sortedSchema ();
69+ static std::shared_ptr<arrow::Schema> unsortedSchema ();
70+
71+ // / build slice-info tables for the index column entry.key of the source table
72+ static std::shared_ptr<arrow::Table> makeSorted (Entry const & entry, std::shared_ptr<arrow::Table> const & source);
73+ static std::shared_ptr<arrow::Table> makeUnsorted (Entry const & entry, std::shared_ptr<arrow::Table> const & source);
74+
75+ // / non-owning views of the slice-info tables, valid as long as the table is alive
76+ static SliceInfoPtr readSorted (std::shared_ptr<arrow::Table> const & table);
77+ static SliceInfoUnsortedPtr readUnsorted (std::shared_ptr<arrow::Table> const & table);
78+ };
79+
5980using Cache = std::vector<Entry>;
6081
6182void updatePairList (Cache& list, Entry& entry);
@@ -77,13 +98,14 @@ struct ArrowTableSlicingCacheDef {
7798struct ArrowTableSlicingCache {
7899 constexpr static ServiceKind service_kind = ServiceKind::Stream;
79100
101+ // slice-info tables (see SliceInfo) for the current timeframe and views into them
80102 Cache bindingsKeys;
81- std::vector<std::vector< int64_t >> offsets ;
82- std::vector<std::vector< int64_t >> sizes ;
103+ std::vector<std::shared_ptr<arrow::Table >> sliceInfos ;
104+ std::vector<SliceInfoPtr> sliceInfoPtrs ;
83105
84106 Cache bindingsKeysUnsorted;
85- std::vector<std::vector< int >> valuesUnsorted ;
86- std::vector<ListVector> groups ;
107+ std::vector<std::shared_ptr<arrow::Table >> sliceInfosUnsorted ;
108+ std::vector<SliceInfoUnsortedPtr> sliceInfoPtrsUnsorted ;
87109
88110 header::DataOrigin newOrigin = header::DataOrigin{" AOD" };
89111
@@ -92,7 +114,13 @@ struct ArrowTableSlicingCache {
92114 // set caching information externally
93115 void setCaches (Cache&& bsks, Cache&& bsksUnsorted = {});
94116
95- // update slicing info cache entry (assumes it is already present)
117+ // store slice-info table received for the cache entry (assumes it is already present)
118+ void setCacheEntry (int pos, std::shared_ptr<arrow::Table> sliceInfo);
119+ void setCacheEntryUnsorted (int pos, std::shared_ptr<arrow::Table> sliceInfo);
120+ // drop all slice-info tables, e.g. at the start of a new timeframe
121+ void clearCacheEntries ();
122+
123+ // compute slice-info table for the cache entry locally from the sliced table (assumes it is already present)
96124 arrow::Status updateCacheEntry (int pos, std::shared_ptr<arrow::Table> const & table);
97125 arrow::Status updateCacheEntryUnsorted (int pos, std::shared_ptr<arrow::Table> const & table);
98126
@@ -107,12 +135,6 @@ struct ArrowTableSlicingCache {
107135 SliceInfoPtr getCacheForPos (int pos) const ;
108136 SliceInfoUnsortedPtr getCacheUnsortedForPos (int pos) const ;
109137
110- // get a cached empty (0-row) slice of the given table, so that empty groups
111- // do not slice every column only to produce 0 rows (the common case for
112- // sparse grouping). One-slot cache keyed by the table pointer.
113- std::shared_ptr<arrow::Table> getEmptySliceFor (std::shared_ptr<arrow::Table> const & table);
114- std::pair<arrow::Table const *, std::shared_ptr<arrow::Table>> emptySlice{nullptr , nullptr };
115-
116138 static void validateOrder (Entry const & bindingKey, std::shared_ptr<arrow::Table> const & input);
117139};
118140} // namespace o2::framework
0 commit comments