-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDedupDecoder.h
More file actions
104 lines (84 loc) · 3.68 KB
/
DedupDecoder.h
File metadata and controls
104 lines (84 loc) · 3.68 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
92
93
94
95
96
97
98
99
100
101
102
103
104
// Copyright CERN and copyright holders of ALICE O2. This software is
// distributed under the terms of the GNU General Public License v3 (GPL
// Version 3), copied verbatim in the file "COPYING".
//
// See http://alice-o2.web.cern.ch/license for full licensing information.
//
// 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 Decoder.h
/// @author Michael Lettrich
/// @since 2020-04-06
/// @brief Decoder - decode a rANS encoded state back into source symbols
#ifndef RANS_DEDUPDECODER_H
#define RANS_DEDUPDECODER_H
#include "Decoder.h"
#include <cstddef>
#include <type_traits>
#include <iostream>
#include <string>
#include <fairlogger/Logger.h>
#include "internal/DecoderSymbol.h"
#include "internal/ReverseSymbolLookupTable.h"
#include "internal/SymbolTable.h"
#include "internal/Decoder.h"
namespace o2
{
namespace rans
{
template <typename coder_T, typename stream_T, typename source_T>
class DedupDecoder : public Decoder<coder_T, stream_T, source_T>
{
//inherit constructors;
using Decoder<coder_T, stream_T, source_T>::Decoder;
public:
using duplicatesMap_t = std::map<uint32_t, uint32_t>;
template <typename stream_IT, typename source_IT, std::enable_if_t<internal::isCompatibleIter_v<stream_T, stream_IT> && internal::isCompatibleIter_v<source_T, source_IT>, bool> = true>
void process(const source_IT outputBegin, const stream_IT inputEnd, size_t messageLength, duplicatesMap_t& duplicates) const;
};
template <typename coder_T, typename stream_T, typename source_T>
template <typename stream_IT, typename source_IT, std::enable_if_t<internal::isCompatibleIter_v<stream_T, stream_IT> && internal::isCompatibleIter_v<source_T, source_IT>, bool>>
void DedupDecoder<coder_T, stream_T, source_T>::process(const source_IT outputBegin, const stream_IT inputEnd, size_t messageLength, duplicatesMap_t& duplicates) const
{
using namespace internal;
using ransDecoder = internal::Decoder<coder_T, stream_T>;
LOG(trace) << "start decoding";
RANSTimer t;
t.start();
static_assert(std::is_same<typename std::iterator_traits<source_IT>::value_type, source_T>::value);
static_assert(std::is_same<typename std::iterator_traits<stream_IT>::value_type, stream_T>::value);
if (messageLength == 0) {
LOG(warning) << "Empty message passed to decoder, skipping decode process";
return;
}
stream_IT inputIter = inputEnd;
source_IT it = outputBegin;
// make Iter point to the last last element
--inputIter;
ransDecoder rans;
inputIter = rans.init(inputIter);
for (size_t i = 0; i < (messageLength); i++) {
const auto s = (*this->mReverseLUT)[rans.get(this->mProbabilityBits)];
// deduplication
auto duplicatesIter = duplicates.find(i);
if (duplicatesIter != duplicates.end()) {
LOG(trace) << "pos[" << i << "]: restoring " << duplicatesIter->second << " duplicates of symbol " << (char)s;
for (int d = 0; d < duplicatesIter->second; d++) {
*it++ = s;
i++;
}
}
*it++ = s;
inputIter = rans.advanceSymbol(inputIter, (*this->mSymbolTable)[s], this->mProbabilityBits);
}
t.stop();
LOG(debug1) << "Decoder::" << __func__ << " { DecodedSymbols: " << messageLength << ","
<< "processedBytes: " << messageLength * sizeof(source_T) << ","
<< " inclusiveTimeMS: " << t.getDurationMS() << ","
<< " BandwidthMiBPS: " << std::fixed << std::setprecision(2) << (messageLength * sizeof(source_T) * 1.0) / (t.getDurationS() * 1.0 * (1 << 20)) << "}";
LOG(trace) << "done decoding";
}
} // namespace rans
} // namespace o2
#endif /* RANS_DEDUPDECODER_H */