Project
Loading...
Searching...
No Matches
DecoderImpl.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_DECODERIMPL_H_
17#define RANS_INTERNAL_DECODE_DECODERIMPL_H_
18
19#include <vector>
20#include <cstdint>
21#include <cassert>
22#include <tuple>
23#include <type_traits>
24
27
28namespace o2::rans::internal
29{
30
31template <size_t LowerBound_V>
33{
34 public:
39 using size_type = std::size_t;
40 using difference_type = std::ptrdiff_t;
41
42 explicit DecoderImpl(size_type symbolTablePrecission) noexcept : mSymbolTablePrecission{symbolTablePrecission} {};
43
44 template <typename stream_IT>
45 stream_IT init(stream_IT inputIter);
46
47 inline cumulative_frequency_type get() { return mState & ((utils::pow2(mSymbolTablePrecission)) - 1); };
48
49 template <typename stream_IT>
50 stream_IT advanceSymbol(stream_IT inputIter, const symbol_type& sym);
51
52 [[nodiscard]] inline static constexpr size_type getNstreams() noexcept { return N_STREAMS; };
53
54 private:
55 state_type mState{};
56 size_type mSymbolTablePrecission{};
57
58 template <typename stream_IT>
59 std::tuple<state_type, stream_IT> renorm(state_type x, stream_IT iter);
60
61 inline static constexpr size_type N_STREAMS = 1;
62
63 inline static constexpr state_type LOWER_BOUND = utils::pow2(LowerBound_V); // lower bound of our normalization interval
64
65 inline static constexpr state_type STREAM_BITS = utils::toBits<stream_type>(); // lower bound of our normalization interval
66};
67
68template <size_t LowerBound_V>
69template <typename stream_IT>
70stream_IT DecoderImpl<LowerBound_V>::init(stream_IT inputIter)
71{
72
73 state_type newState = 0;
74 stream_IT streamPosition = inputIter;
75
76 newState = static_cast<state_type>(*streamPosition) << 0;
77 --streamPosition;
78 newState |= static_cast<state_type>(*streamPosition) << 32;
79 --streamPosition;
80 assert(std::distance(streamPosition, inputIter) == 2);
81
82 mState = newState;
83 return streamPosition;
84};
85
86template <size_t LowerBound_V>
87template <typename stream_IT>
88inline stream_IT DecoderImpl<LowerBound_V>::advanceSymbol(stream_IT inputIter, const symbol_type& symbol)
89{
90 static_assert(std::is_same<typename std::iterator_traits<stream_IT>::value_type, stream_type>::value);
91
92 state_type mask = (utils::pow2(mSymbolTablePrecission)) - 1;
93
94 // s, x = D(x)
95 state_type newState = mState;
96 newState = symbol.getFrequency() * (newState >> mSymbolTablePrecission) + (newState & mask) - symbol.getCumulative();
97
98 // renormalize
99 const auto [renormedState, newStreamPosition] = this->renorm(newState, inputIter);
100 mState = renormedState;
101 return newStreamPosition;
102};
103
104template <size_t LowerBound_V>
105template <typename stream_IT>
106inline auto DecoderImpl<LowerBound_V>::renorm(state_type state, stream_IT inputIter) -> std::tuple<state_type, stream_IT>
107{
108 static_assert(std::is_same<typename std::iterator_traits<stream_IT>::value_type, stream_type>::value);
109
110 stream_IT streamPosition = inputIter;
111
112 // renormalize
113 if (state < LOWER_BOUND) {
114 state = (state << STREAM_BITS) | *streamPosition;
115 --streamPosition;
116 assert(state >= LOWER_BOUND);
117 }
118 return std::make_tuple(state, streamPosition);
119};
120
121} // namespace o2::rans::internal
122
123#endif /* RANS_INTERNAL_DECODE_DECODERIMPL_H_ */
unsigned int uint32_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
SurfaceTrackState state
Contains statistical information for one source symbol, required for encoding/decoding.
common helper classes and functions
constexpr size_t LOWER_BOUND
cumulative_frequency_type get()
Definition DecoderImpl.h:47
static constexpr size_type getNstreams() noexcept
Definition DecoderImpl.h:52
DecoderImpl(size_type symbolTablePrecission) noexcept
Definition DecoderImpl.h:42
stream_IT init(stream_IT inputIter)
Definition DecoderImpl.h:70
stream_IT advanceSymbol(stream_IT inputIter, const symbol_type &sym)
Definition DecoderImpl.h:88
constexpr value_type getCumulative() const noexcept
Definition Symbol.h:43
constexpr value_type getFrequency() const noexcept
Definition Symbol.h:42
GLint GLenum GLint x
Definition glcorearb.h:403
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLuint mask
Definition glcorearb.h:291
constexpr size_t pow2(size_t n) noexcept
Definition utils.h:165
decltype(auto) renorm(histogram_T histogram, size_t newPrecision, RenormingPolicy renormingPolicy=RenormingPolicy::Auto, size_t lowProbabilityCutoffBits=0)
Definition renorm.h:203