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; // how many Bytes is the rANS encoder emmiting during a stream-out step.
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
53 void clear()
54 {
55 nStreams = 0;
56 messageLength = 0;
57 nLiterals = 0;
59 coderType = 0;
60 streamSize = 0;
62 min = 0;
63 max = 0;
66 nDictWords = 0;
67 nDataWords = 0;
68 nLiteralWords = 0;
69 }
71};
72
73namespace detail
74{
75
76template <typename source_T, typename state_T, typename stream_T>
77[[nodiscard]] inline constexpr Metadata makeMetadataRansCompat(size_t nStreams, size_t messageLength,
78 size_t nLiterals, size_t symbolTablePrecision,
79 source_T min, source_T max, size_t dictWords,
80 size_t dataWords, size_t literalWords) noexcept
81{
82 return Metadata{
83 static_cast<uint8_t>(nStreams),
84 messageLength,
85 nLiterals,
86 static_cast<uint8_t>(sizeof(source_T)),
87 static_cast<uint8_t>(sizeof(state_T)),
88 static_cast<uint8_t>(sizeof(stream_T)),
89 static_cast<uint8_t>(symbolTablePrecision),
91 static_cast<int32_t>(min),
92 static_cast<int32_t>(max),
93 static_cast<int32_t>(0),
94 static_cast<uint8_t>(sizeof(source_T)),
95 static_cast<int32_t>(dictWords),
96 static_cast<int32_t>(dataWords),
97 static_cast<int32_t>(literalWords)};
98};
99
100template <typename source_T>
101[[nodiscard]] inline constexpr Metadata makeMetadataRansDict(size_t symbolTablePrecision, source_T min,
102 source_T max, size_t dictWords, ctf::Metadata::OptStore optStore) noexcept
103{
104 return Metadata{
105 static_cast<uint8_t>(0),
106 static_cast<uint8_t>(0),
107 static_cast<uint8_t>(0),
108 static_cast<uint8_t>(sizeof(source_T)),
109 static_cast<uint8_t>(0),
110 static_cast<uint8_t>(0),
111 static_cast<uint8_t>(symbolTablePrecision),
112 optStore,
113 static_cast<int32_t>(min),
114 static_cast<int32_t>(max),
115 static_cast<int32_t>(0),
116 static_cast<uint8_t>(0),
117 static_cast<int32_t>(dictWords),
118 static_cast<int32_t>(0),
119 static_cast<int32_t>(0)};
120};
121
122template <typename source_T, typename state_T, typename stream_T>
123[[nodiscard]] inline constexpr Metadata makeMetadataRansV1(size_t nStreams, size_t streamingLowerBound, size_t messageLength,
124 size_t nLiterals, size_t symbolTablePrecision,
125 source_T dictMin, source_T dictMax,
126 source_T literalsOffset, size_t literalsPackingWidth, size_t dictWords,
127 size_t dataWords, size_t literalWords) noexcept
128{
129 return Metadata{
130 static_cast<uint8_t>(nStreams),
131 messageLength,
132 nLiterals,
133 static_cast<uint8_t>(sizeof(source_T)),
134 static_cast<uint8_t>(sizeof(state_T)),
135 static_cast<uint8_t>(streamingLowerBound),
136 static_cast<uint8_t>(symbolTablePrecision),
138 static_cast<int32_t>(dictMin),
139 static_cast<int32_t>(dictMax),
140 static_cast<int32_t>(literalsOffset),
141 static_cast<uint8_t>(literalsPackingWidth),
142 static_cast<int32_t>(dictWords),
143 static_cast<int32_t>(dataWords),
144 static_cast<int32_t>(literalWords)};
145};
146
147template <typename source_T>
148[[nodiscard]] inline constexpr Metadata makeMetadataPack(size_t messageLength, size_t packingWidth,
149 source_T packingOffset, size_t dataWords) noexcept
150{
151 return Metadata{
152 static_cast<uint8_t>(1),
153 messageLength,
154 static_cast<size_t>(0),
155 static_cast<uint8_t>(sizeof(source_T)),
156 static_cast<uint8_t>(0),
157 static_cast<uint8_t>(0),
158 static_cast<uint8_t>(packingWidth),
160 static_cast<int32_t>(packingOffset),
161 static_cast<int32_t>(0),
162 static_cast<int32_t>(0),
163 static_cast<uint8_t>(0),
164 static_cast<int32_t>(0),
165 static_cast<int32_t>(dataWords),
166 static_cast<int32_t>(0)};
167};
168
169template <typename source_T, typename buffer_T>
170[[nodiscard]] inline constexpr Metadata makeMetadataStore(size_t messageLength, Metadata::OptStore opStore, size_t dataWords) noexcept
171{
172 return Metadata{
173 static_cast<uint8_t>(0),
174 messageLength,
175 static_cast<size_t>(0),
176 static_cast<uint8_t>(sizeof(source_T)),
177 static_cast<uint8_t>(0),
178 static_cast<uint8_t>(sizeof(buffer_T)),
179 static_cast<uint8_t>(0),
180 opStore,
181 static_cast<int32_t>(0),
182 static_cast<int32_t>(0),
183 static_cast<int32_t>(0),
184 static_cast<int32_t>(0),
185 static_cast<int32_t>(0),
186 static_cast<int32_t>(dataWords),
187 static_cast<int32_t>(0)};
188};
189
190} // namespace detail
191} // namespace o2::ctf
192
193#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:77
constexpr Metadata makeMetadataRansDict(size_t symbolTablePrecision, source_T min, source_T max, size_t dictWords, ctf::Metadata::OptStore optStore) noexcept
Definition Metadata.h:101
constexpr Metadata makeMetadataPack(size_t messageLength, size_t packingWidth, source_T packingOffset, size_t dataWords) noexcept
Definition Metadata.h:148
constexpr Metadata makeMetadataStore(size_t messageLength, Metadata::OptStore opStore, size_t dataWords) noexcept
Definition Metadata.h:170
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:123
pair of input and output size
Definition ANSHeader.h:25
size_t getUncompressedSize() const
Definition Metadata.h:51
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
Definition Metadata.h:52
constexpr size_t min
constexpr size_t max