Project
Loading...
Searching...
No Matches
ArrowTableSlicingCache.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12#ifndef ARROWTABLESLICINGCACHE_H
13#define ARROWTABLESLICINGCACHE_H
14
17#include <arrow/array.h>
18#include <gsl/span>
19
20namespace o2::framework
21{
22using ListVector = std::vector<std::vector<int64_t>>;
23
25 gsl::span<int64_t const> offsets;
26 gsl::span<int64_t const> sizes;
27
28 std::pair<int64_t, int64_t> getSliceFor(int value) const;
29};
30
32 std::span<int const> values;
34
35 std::span<int64_t const> getSliceFor(int value) const;
36};
37
38struct Entry {
39 std::string binding;
41 std::string key;
42 bool enabled;
43
44 Entry(std::string b, ConcreteDataMatcher m, std::string k, bool e = true)
45 : binding{b},
46 matcher{m},
47 key{k},
48 enabled{e}
49 {
50 }
51
52 friend bool operator==(Entry const& lhs, Entry const& rhs)
53 {
54 return (lhs.matcher == rhs.matcher) &&
55 (lhs.key == rhs.key);
56 }
57};
58
59using Cache = std::vector<Entry>;
60
61void updatePairList(Cache& list, Entry& entry);
62
76
79
81 std::vector<std::vector<int64_t>> offsets;
82 std::vector<std::vector<int64_t>> sizes;
83
85 std::vector<std::vector<int>> valuesUnsorted;
86 std::vector<ListVector> groups;
87
89
90 ArrowTableSlicingCache(Cache&& bsks, Cache&& bsksUnsorted = {}, header::DataOrigin newOrigin_ = header::DataOrigin{"AOD"});
91
92 // set caching information externally
93 void setCaches(Cache&& bsks, Cache&& bsksUnsorted = {});
94
95 // update slicing info cache entry (assumes it is already present)
96 arrow::Status updateCacheEntry(int pos, std::shared_ptr<arrow::Table> const& table);
97 arrow::Status updateCacheEntryUnsorted(int pos, std::shared_ptr<arrow::Table> const& table);
98
99 // helper to locate cache position
100 std::pair<int, bool> getCachePos(Entry const& bindingKey) const;
101 int getCachePosSortedFor(Entry const& bindingKey) const;
102 int getCachePosUnsortedFor(Entry const& bindingKey) const;
103
104 // get slice from cache for a given value
105 SliceInfoPtr getCacheFor(Entry const& bindingKey) const;
106 SliceInfoUnsortedPtr getCacheUnsortedFor(Entry const& bindingKey) const;
107 SliceInfoPtr getCacheForPos(int pos) const;
108 SliceInfoUnsortedPtr getCacheUnsortedForPos(int pos) const;
109
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
116 static void validateOrder(Entry const& bindingKey, std::shared_ptr<arrow::Table> const& input);
117};
118} // namespace o2::framework
119
120#endif // ARROWTABLESLICINGCACHE_H
uint16_t pos
Definition RawData.h:3
const GLfloat * m
Definition glcorearb.h:4066
GLuint entry
Definition glcorearb.h:5735
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition glcorearb.h:2513
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLsizei const GLfloat * value
Definition glcorearb.h:819
Defining ITS Vertex explicitly as messageable.
Definition Cartesian.h:288
void updatePairList(Cache &list, Entry &entry)
ServiceKind
The kind of service we are asking for.
std::vector< Entry > Cache
std::vector< std::vector< int64_t > > ListVector
void setOrigin(header::DataOrigin newOrigin_=header::DataOrigin{"AOD"})
std::vector< std::vector< int64_t > > offsets
SliceInfoUnsortedPtr getCacheUnsortedFor(Entry const &bindingKey) const
arrow::Status updateCacheEntryUnsorted(int pos, std::shared_ptr< arrow::Table > const &table)
int getCachePosSortedFor(Entry const &bindingKey) const
std::vector< std::vector< int64_t > > sizes
arrow::Status updateCacheEntry(int pos, std::shared_ptr< arrow::Table > const &table)
std::pair< int, bool > getCachePos(Entry const &bindingKey) const
SliceInfoPtr getCacheFor(Entry const &bindingKey) const
void setCaches(Cache &&bsks, Cache &&bsksUnsorted={})
static constexpr ServiceKind service_kind
std::pair< arrow::Table const *, std::shared_ptr< arrow::Table > > emptySlice
SliceInfoUnsortedPtr getCacheUnsortedForPos(int pos) const
std::shared_ptr< arrow::Table > getEmptySliceFor(std::shared_ptr< arrow::Table > const &table)
int getCachePosUnsortedFor(Entry const &bindingKey) const
std::vector< std::vector< int > > valuesUnsorted
static void validateOrder(Entry const &bindingKey, std::shared_ptr< arrow::Table > const &input)
ConcreteDataMatcher matcher
friend bool operator==(Entry const &lhs, Entry const &rhs)
Entry(std::string b, ConcreteDataMatcher m, std::string k, bool e=true)
gsl::span< int64_t const > sizes
gsl::span< int64_t const > offsets
std::pair< int64_t, int64_t > getSliceFor(int value) const
std::span< int64_t const > getSliceFor(int value) const