Project
Loading...
Searching...
No Matches
Metadata.h
Go to the documentation of this file.
1// Copyright 2019-2020 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
14
16
17#ifndef ALICEO2_METADATA_H
18#define ALICEO2_METADATA_H
19
20#include <cstddef>
21#include <Rtypes.h>
22
23namespace o2::ctf
24{
25
26struct Metadata {
27 enum class OptStore : uint8_t { // describe how the store the data described by this metadata
28 EENCODE, // entropy encoding applied
29 ROOTCompression, // original data repacked to array with slot-size = streamSize and saved with root compression
30 NONE, // original data repacked to array with slot-size = streamSize and saved w/o compression
31 NODATA, // no data was provided
32 PACK, // use Bitpacking
33 EENCODE_OR_PACK // decide at runtime if to encode or pack
34 };
35 uint8_t nStreams = 0; // Amount of concurrent Streams used by the encoder. only used by rANS version >=1.
36 size_t messageLength = 0; // Message length (multiply with messageWordSize to get size in Bytes).
37 size_t nLiterals = 0; // Number of samples that were stored as literals.
38 uint8_t messageWordSize = 0; // size in Bytes of a symbol in the encoded message.
39 uint8_t coderType = 0; // what type of CTF Coder is used? (32 vs 64 bit coders).
40 uint8_t streamSize = 0; // number of Bytes emmitted during rANS stream out (ransCompat) or lower renorming bound (ransV1).
41 uint8_t probabilityBits = 0; // The encoder renormed the distribution of source symbols to sum up to 2^probabilityBits.
42 OptStore opt = OptStore::EENCODE; // The type of storage operation that was conducted.
43 int32_t min = 0; // min symbol of the source dataset.
44 int32_t max = 0; // max symbol of the source dataset.
45 int32_t literalsPackingOffset = 0; // Offset from 0 used for bit packing of literal (incompressible) symbols. only used by rANS version >=1.
46 uint8_t literalsPackingWidth = 0; // Amount of bits used to pack literal (incompressible) symbols. only used by rANS version >=1.
47 int nDictWords = 0; // Amount of words used to store the encoding dictionary.
48 int nDataWords = 0; // Amount of words used to store the actual data.
49 int nLiteralWords = 0; // Amount of words used to store literal (incompressible) samples.
50
57
66 void clear()
67 {
68 nStreams = 0;
69 messageLength = 0;
70 nLiterals = 0;
72 coderType = 0;
73 streamSize = 0;
75 min = 0;
76 max = 0;
79 nDictWords = 0;
80 nDataWords = 0;
81 nLiteralWords = 0;
82 }
84};
85
86namespace detail
87{
88
89template <typename source_T, typename state_T, typename stream_T>
90[[nodiscard]] inline constexpr Metadata makeMetadataRansCompat(size_t nStreams, size_t messageLength,
91 size_t nLiterals, size_t symbolTablePrecision,
92 source_T min, source_T max, size_t dictWords,
93 size_t dataWords, size_t literalWords) noexcept
94{
95 return Metadata{
96 static_cast<uint8_t>(nStreams),
97 messageLength,
98 nLiterals,
99 static_cast<uint8_t>(sizeof(source_T)),
100 static_cast<uint8_t>(sizeof(state_T)),
101 static_cast<uint8_t>(sizeof(stream_T)),
102 static_cast<uint8_t>(symbolTablePrecision),
104 static_cast<int32_t>(min),
105 static_cast<int32_t>(max),
106 static_cast<int32_t>(0),
107 static_cast<uint8_t>(sizeof(source_T)),
108 static_cast<int32_t>(dictWords),
109 static_cast<int32_t>(dataWords),
110 static_cast<int32_t>(literalWords)};
111};
112
113template <typename source_T>
114[[nodiscard]] inline constexpr Metadata makeMetadataRansDict(size_t symbolTablePrecision, source_T min,
115 source_T max, size_t dictWords, ctf::Metadata::OptStore optStore) noexcept
116{
117 return Metadata{
118 static_cast<uint8_t>(0),
119 static_cast<uint8_t>(0),
120 static_cast<uint8_t>(0),
121 static_cast<uint8_t>(sizeof(source_T)),
122 static_cast<uint8_t>(0),
123 static_cast<uint8_t>(0),
124 static_cast<uint8_t>(symbolTablePrecision),
125 optStore,
126 static_cast<int32_t>(min),
127 static_cast<int32_t>(max),
128 static_cast<int32_t>(0),
129 static_cast<uint8_t>(0),
130 static_cast<int32_t>(dictWords),
131 static_cast<int32_t>(0),
132 static_cast<int32_t>(0)};
133};
134
135template <typename source_T, typename state_T, typename stream_T>
136[[nodiscard]] inline constexpr Metadata makeMetadataRansV1(size_t nStreams, size_t streamingLowerBound, size_t messageLength,
137 size_t nLiterals, size_t symbolTablePrecision,
138 source_T dictMin, source_T dictMax,
139 source_T literalsOffset, size_t literalsPackingWidth, size_t dictWords,
140 size_t dataWords, size_t literalWords) noexcept
141{
142 return Metadata{
143 static_cast<uint8_t>(nStreams),
144 messageLength,
145 nLiterals,
146 static_cast<uint8_t>(sizeof(source_T)),
147 static_cast<uint8_t>(sizeof(state_T)),
148 static_cast<uint8_t>(streamingLowerBound),
149 static_cast<uint8_t>(symbolTablePrecision),
151 static_cast<int32_t>(dictMin),
152 static_cast<int32_t>(dictMax),
153 static_cast<int32_t>(literalsOffset),
154 static_cast<uint8_t>(literalsPackingWidth),
155 static_cast<int32_t>(dictWords),
156 static_cast<int32_t>(dataWords),
157 static_cast<int32_t>(literalWords)};
158};
159
160template <typename source_T>
161[[nodiscard]] inline constexpr Metadata makeMetadataPack(size_t messageLength, size_t packingWidth,
162 source_T packingOffset, size_t dataWords) noexcept
163{
164 return Metadata{
165 static_cast<uint8_t>(1),
166 messageLength,
167 static_cast<size_t>(0),
168 static_cast<uint8_t>(sizeof(source_T)),
169 static_cast<uint8_t>(0),
170 static_cast<uint8_t>(0),
171 static_cast<uint8_t>(packingWidth),
173 static_cast<int32_t>(packingOffset),
174 static_cast<int32_t>(0),
175 static_cast<int32_t>(0),
176 static_cast<uint8_t>(0),
177 static_cast<int32_t>(0),
178 static_cast<int32_t>(dataWords),
179 static_cast<int32_t>(0)};
180};
181
182template <typename source_T, typename buffer_T>
183[[nodiscard]] inline constexpr Metadata makeMetadataStore(size_t messageLength, Metadata::OptStore opStore, size_t dataWords) noexcept
184{
185 return Metadata{
186 static_cast<uint8_t>(0),
187 messageLength,
188 static_cast<size_t>(0),
189 static_cast<uint8_t>(sizeof(source_T)),
190 static_cast<uint8_t>(0),
191 static_cast<uint8_t>(sizeof(buffer_T)),
192 static_cast<uint8_t>(0),
193 opStore,
194 static_cast<int32_t>(0),
195 static_cast<int32_t>(0),
196 static_cast<int32_t>(0),
197 static_cast<int32_t>(0),
198 static_cast<int32_t>(0),
199 static_cast<int32_t>(dataWords),
200 static_cast<int32_t>(0)};
201};
202
203} // namespace detail
204} // namespace o2::ctf
205
206#endif
constexpr Metadata makeMetadataRansCompat(size_t nStreams, size_t messageLength, size_t nLiterals, size_t symbolTablePrecision, source_T min, source_T max, size_t dictWords, size_t dataWords, size_t literalWords) noexcept
Definition Metadata.h:90
constexpr Metadata makeMetadataRansDict(size_t symbolTablePrecision, source_T min, source_T max, size_t dictWords, ctf::Metadata::OptStore optStore) noexcept
Definition Metadata.h:114
constexpr Metadata makeMetadataPack(size_t messageLength, size_t packingWidth, source_T packingOffset, size_t dataWords) noexcept
Definition Metadata.h:161
constexpr Metadata makeMetadataStore(size_t messageLength, Metadata::OptStore opStore, size_t dataWords) noexcept
Definition Metadata.h:183
constexpr Metadata makeMetadataRansV1(size_t nStreams, size_t streamingLowerBound, size_t messageLength, size_t nLiterals, size_t symbolTablePrecision, source_T dictMin, source_T dictMax, source_T literalsOffset, size_t literalsPackingWidth, size_t dictWords, size_t dataWords, size_t literalWords) noexcept
Definition Metadata.h:136
pair of input and output size
Definition ANSHeader.h:25
size_t getUncompressedSize() const
Uncompressed size of stored data in bytes.
Definition Metadata.h:56
uint8_t messageWordSize
Definition Metadata.h:38
uint8_t nStreams
Definition Metadata.h:35
ClassDefNV(Metadata, 3)
uint8_t literalsPackingWidth
Definition Metadata.h:46
size_t messageLength
Definition Metadata.h:36
uint8_t probabilityBits
Definition Metadata.h:41
uint8_t streamSize
Definition Metadata.h:40
int32_t literalsPackingOffset
Definition Metadata.h:45
uint8_t coderType
Definition Metadata.h:39
size_t getCompressedSize() const
Size of the stored, compressed data in multiples of the underlying buffer word size.
Definition Metadata.h:65
constexpr size_t min
constexpr size_t max