-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathDedupDecoder.h
More file actions
106 lines (85 loc) · 3.56 KB
/
DedupDecoder.h
File metadata and controls
106 lines (85 loc) · 3.56 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
105
106
// 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 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 <cstddef>
#include <type_traits>
#include <iostream>
#include <iomanip>
#include <string>
#include <fairlogger/Logger.h>
#include "rANS/internal/DecoderSymbol.h"
#include "rANS/internal/ReverseSymbolLookupTable.h"
#include "rANS/internal/SymbolTable.h"
#include "rANS/internal/Decoder.h"
#include "rANS/internal/DecoderBase.h"
namespace o2
{
namespace rans
{
template <typename coder_T, typename stream_T, typename source_T>
class DedupDecoder : public internal::DecoderBase<coder_T, stream_T, source_T>
{
public:
using duplicatesMap_t = std::map<uint32_t, uint32_t>;
// inherit constructors;
using internal::DecoderBase<coder_T, stream_T, source_T>::DecoderBase;
template <typename stream_IT, typename source_IT, std::enable_if_t<internal::isCompatibleIter_v<stream_T, stream_IT>, bool> = true>
void process(stream_IT inputEnd, source_IT outputBegin, size_t messageLength, duplicatesMap_t& duplicates) const;
private:
using ransDecoder_t = typename internal::DecoderBase<coder_T, stream_T, source_T>::ransDecoder_t;
};
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>, bool>>
void DedupDecoder<coder_T, stream_T, source_T>::process(stream_IT inputEnd, source_IT outputBegin, size_t messageLength, duplicatesMap_t& duplicates) const
{
using namespace internal;
LOG(trace) << "start decoding";
RANSTimer t;
t.start();
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_t rans{this->mSymbolTable.getPrecision()};
inputIter = rans.init(inputIter);
for (size_t i = 0; i < (messageLength); i++) {
const auto s = (this->mReverseLUT)[rans.get()];
// deduplication
auto duplicatesIter = duplicates.find(i);
if (duplicatesIter != duplicates.end()) {
LOG(trace) << "pos[" << i << "]: restoring " << duplicatesIter->second << " duplicates of symbol " << (char)s;
for (unsigned int d = 0; d < duplicatesIter->second; d++) {
*it++ = s;
i++;
}
}
*it++ = s;
inputIter = rans.advanceSymbol(inputIter, (this->mSymbolTable)[s]);
}
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 */