Project
Loading...
Searching...
No Matches
Decoder.h
Go to the documentation of this file.
1// Copyright 2019-2023 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
15
16#ifndef RANS_INTERNAL_DECODE_DECODER_H_
17#define RANS_INTERNAL_DECODE_DECODER_H_
18
23
24#include <fairlogger/Logger.h>
25#include <gsl/span>
26
28
29namespace o2::rans
30{
31
32template <typename source_T, class decoder_T>
34{
35
36 public:
38 using coder_type = decoder_T;
39
40 private:
43
44 static_assert(std::is_same_v<typename lowRangeTable_type::symbol_type, typename highRangeTable_type::symbol_type>);
45 using symbol_type = typename lowRangeTable_type::symbol_type;
46
49
50 using decoder_type = std::variant<lowRangeDecoder_type, highRangDecoder_type>;
51
52 public:
53 using stream_type = typename coder_type::stream_type;
54 using size_type = std::size_t;
55 using difference_type = std::ptrdiff_t;
56
57 Decoder() noexcept = default;
58
59 template <typename container_T>
60 explicit Decoder(const RenormedHistogramConcept<container_T>& renormedHistogram)
61 {
62
63 const auto [min, max] = internal::getMinMax(renormedHistogram);
64 const size_t alphabetRangeBits = utils::getRangeBits(min, max);
65
66 if (renormedHistogram.getRenormingBits() > alphabetRangeBits) {
67 mImpl.template emplace<lowRangeDecoder_type>(renormedHistogram);
68 } else {
69 mImpl.template emplace<highRangDecoder_type>(renormedHistogram);
70 }
71 };
72
73 [[nodiscard]] inline size_t getSymbolTablePrecision() const noexcept
74 {
75 size_t precision{};
76 std::visit([&precision](auto&& decoder) { precision = decoder.getSymbolTable().getPrecision(); }, mImpl);
77 return precision;
78 };
79
80 template <typename stream_IT, typename source_IT, typename literals_IT = std::nullptr_t>
81 void process(stream_IT inputEnd, source_IT outputBegin, size_t messageLength, size_t nStreams, literals_IT literalsEnd = nullptr) const
82 {
83 static_assert(utils::isCompatibleIter_v<source_type, source_IT>);
84 std::visit([&](auto&& decoder) { decoder.process(inputEnd, outputBegin, messageLength, nStreams, literalsEnd); }, mImpl);
85 }
86
87 template <typename literals_IT = std::nullptr_t>
88 inline void process(gsl::span<const stream_type> inputStream, gsl::span<source_type> outputStream, size_t messageLength, size_t nStreams, literals_IT literalsEnd = nullptr) const
89 {
90 process(inputStream.data() + inputStream.size(), outputStream.data(), nStreams, literalsEnd);
91 };
92
93 protected:
94 decoder_type mImpl{};
95
96 static_assert(coder_type::getNstreams() == 1, "implementation supports only single stream encoders");
97};
98
99} // namespace o2::rans
100
101#endif /* RANS_INTERNAL_DECODE_DECODER_H_ */
DecoderConcept - User facing class to decode a rANS encoded stream back into the source data based on...
Maps rANS state information back to source symbol, used for decoding.
Maps rANS state information back to source symbol, used for decoding.
Histogram renormed to sum of frequencies being 2^P for use in fast rans coding.
common helper classes and functions
size_t getSymbolTablePrecision() const noexcept
Definition Decoder.h:73
typename coder_type::stream_type stream_type
Definition Decoder.h:53
void process(stream_IT inputEnd, source_IT outputBegin, size_t messageLength, size_t nStreams, literals_IT literalsEnd=nullptr) const
Definition Decoder.h:81
decoder_T coder_type
Definition Decoder.h:38
std::size_t size_type
Definition Decoder.h:54
std::ptrdiff_t difference_type
Definition Decoder.h:55
void process(gsl::span< const stream_type > inputStream, gsl::span< source_type > outputStream, size_t messageLength, size_t nStreams, literals_IT literalsEnd=nullptr) const
Definition Decoder.h:88
decoder_type mImpl
Definition Decoder.h:94
Decoder() noexcept=default
GLenum GLint GLint * precision
Definition glcorearb.h:1899
auto getMinMax(const container_T &container, typename container_T::const_iterator begin, typename container_T::const_iterator end, typename container_T::const_reference zeroElem={}) -> std::pair< typename container_T::source_type, typename container_T::source_type >
Definition algorithm.h:134
constexpr uint32_t getRangeBits(T min, T max) noexcept
Definition utils.h:200
constexpr size_t min
constexpr size_t max