forked from mcoquet642/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncoderBase.h
More file actions
91 lines (73 loc) · 3.14 KB
/
EncoderBase.h
File metadata and controls
91 lines (73 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// @file EncoderBase.h
/// @author michael.lettrich@cern.ch
/// @since Feb 8, 2021
/// @brief
#ifndef INCLUDE_RANS_INTERNAL_ENCODERBASE_H_
#define INCLUDE_RANS_INTERNAL_ENCODERBASE_H_
#include <memory>
#include <algorithm>
#include <iomanip>
#include <fairlogger/Logger.h>
#include <stdexcept>
#include "rANS/internal/Encoder.h"
#include "rANS/internal/EncoderSymbol.h"
#include "rANS/internal/helper.h"
#include "rANS/internal/SymbolTable.h"
#include "rANS/FrequencyTable.h"
namespace o2
{
namespace rans
{
namespace internal
{
template <typename coder_T, typename stream_T, typename source_T>
class EncoderBase
{
protected:
using encoderSymbolTable_t = typename internal::SymbolTable<internal::EncoderSymbol<coder_T>>;
public:
using symbol_t = typename FrequencyTable::symbol_t;
using coder_t = coder_T;
using stream_t = stream_T;
using source_t = source_T;
//TODO(milettri): fix once ROOT cling respects the standard http://wg21.link/p1286r2
EncoderBase() noexcept {}; //NOLINT
EncoderBase(encoderSymbolTable_t&& e, size_t symbolTablePrecission) noexcept;
EncoderBase(const FrequencyTable& frequencies, size_t symbolTablePrecission);
inline size_t getSymbolTablePrecision() const noexcept { return mSymbolTablePrecission; }
inline size_t getAlphabetRangeBits() const noexcept { return mSymbolTable.getAlphabetRangeBits(); }
inline symbol_t getMinSymbol() const noexcept { return mSymbolTable.getMinSymbol(); }
inline symbol_t getMaxSymbol() const noexcept { return mSymbolTable.getMaxSymbol(); }
protected:
encoderSymbolTable_t mSymbolTable{};
size_t mSymbolTablePrecission{};
using ransCoder_t = typename internal::Encoder<coder_T, stream_T>;
};
template <typename coder_T, typename stream_T, typename source_T>
EncoderBase<coder_T, stream_T, source_T>::EncoderBase(encoderSymbolTable_t&& e, size_t symbolTablePrecission) noexcept : mSymbolTable{std::move(e)}, mSymbolTablePrecission{symbolTablePrecission} {};
template <typename coder_T, typename stream_T, typename source_T>
EncoderBase<coder_T, stream_T, source_T>::EncoderBase(const FrequencyTable& frequencies,
size_t symbolTablePrecission) : mSymbolTablePrecission{symbolTablePrecission}
{
SymbolStatistics stats{frequencies, mSymbolTablePrecission};
mSymbolTablePrecission = stats.getSymbolTablePrecision();
RANSTimer t;
t.start();
mSymbolTable = encoderSymbolTable_t{stats};
t.stop();
LOG(debug1) << "Encoder SymbolTable inclusive time (ms): " << t.getDurationMS();
}
} // namespace internal
} // namespace rans
} // namespace o2
#endif /* INCLUDE_RANS_INTERNAL_ENCODERBASE_H_ */