Skip to content

Commit 7a7cedc

Browse files
MichaelLettrichdavidrohr
authored andcommitted
[Fix] Correct Reporting of CTF Compressed Payload in Metadata
1 parent 9910bc1 commit 7a7cedc

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/EncodedBlocks.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,11 @@ CTFIOSize EncodedBlocks<H, N, W>::decode(D_IT dest, // it
929929
const auto& md = mMetadata[slot];
930930
LOGP(debug, "Slot{} | NStored={} Ndict={} nData={}, MD: messageLength:{} opt:{} min:{} max:{} offs:{} width:{} ", slot, block.getNStored(), block.getNDict(), block.getNData(), md.messageLength, (int)md.opt, md.min, md.max, md.literalsPackingOffset, md.literalsPackingWidth);
931931

932+
constexpr size_t word_size = sizeof(W);
933+
932934
if (ansVersion == ANSVersionCompat) {
933935
if (!block.getNStored()) {
934-
return {0, md.getUncompressedSize(), md.getCompressedSize()};
936+
return {0, md.getUncompressedSize(), md.getCompressedSize() * word_size};
935937
}
936938
if (md.opt == Metadata::OptStore::EENCODE) {
937939
return decodeCompatImpl(dest, slot, decoderExt);
@@ -943,7 +945,7 @@ CTFIOSize EncodedBlocks<H, N, W>::decode(D_IT dest, // it
943945
return decodeUnpackImpl(dest, slot);
944946
}
945947
if (!block.getNStored()) {
946-
return {0, md.getUncompressedSize(), md.getCompressedSize()};
948+
return {0, md.getUncompressedSize(), md.getCompressedSize() * word_size};
947949
}
948950
if (md.opt == Metadata::OptStore::EENCODE) {
949951
return decodeRansV1Impl(dest, slot, decoderExt);
@@ -991,7 +993,7 @@ CTFIOSize EncodedBlocks<H, N, W>::decodeCompatImpl(dst_IT dstBegin, int slot, co
991993
} else {
992994
getDecoder().process(block.getData() + block.getNData(), dstBegin, md.messageLength, NDecoderStreams);
993995
}
994-
return {0, md.getUncompressedSize(), md.getCompressedSize()};
996+
return {0, md.getUncompressedSize(), md.getCompressedSize() * sizeof(W)};
995997
};
996998

997999
template <typename H, int N, typename W>
@@ -1045,7 +1047,7 @@ CTFIOSize EncodedBlocks<H, N, W>::decodeRansV1Impl(dst_IT dstBegin, int slot, co
10451047
} else {
10461048
getDecoder().process(block.getData() + block.getNData(), dstBegin, md.messageLength, md.nStreams);
10471049
}
1048-
return {0, md.getUncompressedSize(), md.getCompressedSize()};
1050+
return {0, md.getUncompressedSize(), md.getCompressedSize() * sizeof(W)};
10491051
};
10501052

10511053
template <typename H, int N, typename W>
@@ -1079,7 +1081,7 @@ CTFIOSize EncodedBlocks<H, N, W>::decodeUnpackImpl(dst_IT dest, int slot) const
10791081
} else {
10801082
rans::unpack(srcIt, messageLength, dest, packingWidth, offset);
10811083
}
1082-
return {0, md.getUncompressedSize(), md.getCompressedSize()};
1084+
return {0, md.getUncompressedSize(), md.getCompressedSize() * sizeof(W)};
10831085
};
10841086

10851087
template <typename H, int N, typename W>
@@ -1098,7 +1100,7 @@ CTFIOSize EncodedBlocks<H, N, W>::decodeCopyImpl(dst_IT dest, int slot) const
10981100
destPtr_t srcEnd = srcBegin + md.messageLength * sizeof(dest_t);
10991101
std::copy(srcBegin, srcEnd, dest);
11001102

1101-
return {0, md.getUncompressedSize(), md.getCompressedSize()};
1103+
return {0, md.getUncompressedSize(), md.getCompressedSize() * sizeof(W)};
11021104
};
11031105

11041106
///_____________________________________________________________________________
@@ -1268,7 +1270,7 @@ o2::ctf::CTFIOSize EncodedBlocks<H, N, W>::entropyCodeRANSCompat(const input_IT
12681270
dataSize,
12691271
nLiteralWords);
12701272

1271-
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize()};
1273+
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize() * sizeof(W)};
12721274
}
12731275

12741276
template <typename H, int N, typename W>
@@ -1349,7 +1351,7 @@ CTFIOSize EncodedBlocks<H, N, W>::encodeRANSV1External(const input_IT srcBegin,
13491351
dataSize,
13501352
literalsSize);
13511353

1352-
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize()};
1354+
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize() * sizeof(W)};
13531355
};
13541356

13551357
template <typename H, int N, typename W>
@@ -1458,7 +1460,7 @@ CTFIOSize EncodedBlocks<H, N, W>::encodeRANSV1Inplace(const input_IT srcBegin, c
14581460
dataSize,
14591461
literalsSize);
14601462

1461-
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize()};
1463+
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize() * sizeof(W)};
14621464
}; // namespace ctf
14631465

14641466
template <typename H, int N, typename W>
@@ -1491,7 +1493,7 @@ o2::ctf::CTFIOSize EncodedBlocks<H, N, W>::pack(const input_IT srcBegin, const i
14911493
}
14921494

14931495
LOGP(debug, "StoreData {} bytes, offs: {}:{}", packedSize * sizeof(storageBuffer_t), thisBlock->getOffsData(), thisBlock->getOffsData() + packedSize * sizeof(storageBuffer_t));
1494-
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize()};
1496+
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize() * sizeof(W)};
14951497
};
14961498

14971499
template <typename H, int N, typename W>
@@ -1513,7 +1515,7 @@ o2::ctf::CTFIOSize EncodedBlocks<H, N, W>::store(const input_IT srcBegin, const
15131515

15141516
*thisMetadata = detail::makeMetadataStore<input_t, storageBuffer_t>(messageLength, opt, nBufferElems);
15151517

1516-
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize()};
1518+
return {0, thisMetadata->getUncompressedSize(), thisMetadata->getCompressedSize() * sizeof(W)};
15171519
};
15181520

15191521
/// create a special EncodedBlocks containing only dictionaries made from provided vector of frequency tables

DataFormats/Detectors/Common/include/DetectorsCommonDataFormats/Metadata.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct Metadata {
3737
size_t nLiterals = 0; // Number of samples that were stored as literals.
3838
uint8_t messageWordSize = 0; // size in Bytes of a symbol in the encoded message.
3939
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.
40+
uint8_t streamSize = 0; // number of Bytes emmitted during rANS stream out (ransCompat) or lower renorming bound (ransV1).
4141
uint8_t probabilityBits = 0; // The encoder renormed the distribution of source symbols to sum up to 2^probabilityBits.
4242
OptStore opt = OptStore::EENCODE; // The type of storage operation that was conducted.
4343
int32_t min = 0; // min symbol of the source dataset.
@@ -48,8 +48,21 @@ struct Metadata {
4848
int nDataWords = 0; // Amount of words used to store the actual data.
4949
int nLiteralWords = 0; // Amount of words used to store literal (incompressible) samples.
5050

51+
/**
52+
* @brief Uncompressed size of stored data in bytes
53+
*
54+
* @return size_t Uncompressed size in bytes
55+
*/
5156
size_t getUncompressedSize() const { return messageLength * messageWordSize; }
52-
size_t getCompressedSize() const { return (nDictWords + nDataWords + nLiteralWords) * streamSize; }
57+
58+
/**
59+
* @brief Size of the stored, compressed data in multiples of the underlying buffer word size
60+
*
61+
* @return size_t The size in multiples of the underlying buffer word size
62+
* @warning This size is in number of words of the underlying storage buffer.
63+
* Multiply with the size of the storage buffer type to get the correct size in bytes.
64+
*/
65+
size_t getCompressedSize() const { return nDictWords + nDataWords + nLiteralWords; }
5366
void clear()
5467
{
5568
nStreams = 0;

0 commit comments

Comments
 (0)