50 return serializeRegistry(data_buffer, branchIDLists, thinnedAssociationsHelper, psetMap);
57 FDEBUG(6) <<
"StreamSerializer::serializeRegistry" << std::endl;
60 FDEBUG(9) <<
"Product List: " << std::endl;
64 FDEBUG(9) <<
"StreamOutput got product = " <<
selection.first->className() << std::endl;
67 sd.setBranchIDLists(branchIDLists);
68 sd.setThinnedAssociationsHelper(thinnedAssociationsHelper);
69 sd.setParameterSetMap(psetMap);
76 int bres = data_buffer.
rootbuf_.WriteObjectAny((
char *)&
sd, tc);
81 throw cms::Exception(
"StreamTranslation",
"Registry serialization failed")
82 <<
"StreamSerializer failed to serialize registry\n";
89 throw cms::Exception(
"StreamTranslation",
"Registry serialization truncated")
90 <<
"StreamSerializer module attempted to serialize\n"
91 <<
"a registry that is to big for the allocated buffers\n";
96 throw cms::Exception(
"StreamTranslation",
"Registry serialization failed")
97 <<
"StreamSerializer module got an unknown error code\n"
98 <<
" while attempting to serialize registry\n";
105 data_buffer.
ptr_ = (
unsigned char *)data_buffer.
rootbuf_.Buffer();
137 unsigned int reserveSize)
const {
139 selectionIDs.push_back(selectorConfig);
140 SendEvent se(
event.eventAuxiliary(),
event.processHistory(), selectionIDs,
event.branchListIndexes());
164 if (
result.provenance()->productProvenance()) {
168 se.products().push_back(
180 int bres = data_buffer.
rootbuf_.WriteObjectAny(&se,
tc_);
184 throw cms::Exception(
"StreamTranslation",
"Event serialization failed")
185 <<
"StreamSerializer failed to serialize event: " <<
event.id();
192 throw cms::Exception(
"StreamTranslation",
"Event serialization truncated")
193 <<
"StreamSerializer module attempted to serialize an event\n"
194 <<
"that is to big for the allocated buffers: " <<
event.id();
199 throw cms::Exception(
"StreamTranslation",
"Event serialization failed")
200 <<
"StreamSerializer module got an unknown error code\n"
201 <<
" while attempting to serialize event: " <<
event.id();
207 data_buffer.
ptr_ = (
unsigned char *)data_buffer.
rootbuf_.Buffer();
210 if(data_buffer.
ptr_ != data_.ptr_) {
211 std::cerr <<
"ROOT reset the buffer!!!!\n";
212 data_.ptr_ = data_buffer.
ptr_;
222 unsigned int dest_size = 0;
223 switch (compressionAlgo) {
246 dest_size = data_buffer.
rootbuf_.Length();
247 if (data_buffer.
comp_buf_.size() < dest_size + reserveSize)
248 data_buffer.
comp_buf_.resize(dest_size + reserveSize);
250 (
char *)data_buffer.
rootbuf_.Buffer() + dest_size,
271 unsigned int inputSize,
272 std::vector<unsigned char> &outputBuffer,
274 unsigned int reserveSize) {
275 unsigned int resultSize = 0;
278 unsigned long dest_size = (
unsigned long)(
double(inputSize) * 1.002 + 1.0) + 12;
280 if (outputBuffer.size() < dest_size + reserveSize)
281 outputBuffer.resize(dest_size + reserveSize);
284 int ret = compress2(&outputBuffer[reserveSize], &dest_size, inputBuffer, inputSize,
compressionLevel);
289 resultSize = dest_size;
291 FDEBUG(1) <<
" original size = " << inputSize <<
" final size = " << dest_size
292 <<
" ratio = " << double(dest_size) / double(inputSize) << std::endl;
295 <<
"Compression Return value: " <<
ret <<
" Okay = " << Z_OK << std::endl;
303 unsigned int inputSize,
304 std::vector<unsigned char> &outputBuffer,
306 unsigned int reserveSize,
309 unsigned int hdr_size = addHeader ? 4 : 0;
310 unsigned long dest_size = (
unsigned long)(
double(inputSize) * 1.01 + 1.0) + 12;
311 if (outputBuffer.size() < dest_size + reserveSize)
312 outputBuffer.resize(dest_size + reserveSize);
315 uint32_t dict_size_est = inputSize / 4;
316 lzma_stream
stream = LZMA_STREAM_INIT;
317 lzma_options_lzma opt_lzma2;
319 {.id = LZMA_FILTER_LZMA2, .options = &opt_lzma2},
320 {.id = LZMA_VLI_UNKNOWN, .options =
nullptr},
322 lzma_ret returnStatus;
324 unsigned char *tgt = &outputBuffer[reserveSize];
335 throw cms::Exception(
"StreamSerializer",
"compressBufferLZMA") <<
"LZMA preset return status: " << presetStatus;
338 if (LZMA_DICT_SIZE_MIN > dict_size_est) {
339 dict_size_est = LZMA_DICT_SIZE_MIN;
341 if (opt_lzma2.dict_size > dict_size_est) {
345 opt_lzma2.dict_size = dict_size_est;
349 lzma_stream_encoder(&
stream,
352 if (returnStatus != LZMA_OK) {
354 <<
"LZMA compression encoder return value: " << returnStatus;
357 stream.next_in = (
const uint8_t *)inputBuffer;
358 stream.avail_in = (size_t)(inputSize);
360 stream.next_out = (uint8_t *)(&tgt[hdr_size]);
361 stream.avail_out = (size_t)(dest_size - hdr_size);
363 returnStatus = lzma_code(&
stream, LZMA_FINISH);
365 if (returnStatus != LZMA_STREAM_END) {
368 <<
"LZMA compression return value: " << returnStatus;
380 FDEBUG(1) <<
" LZMA original size = " << inputSize <<
" final size = " <<
stream.total_out
381 <<
" ratio = " << double(
stream.total_out) / double(inputSize) << std::endl;
383 return stream.total_out + hdr_size;
387 unsigned int inputSize,
388 std::vector<unsigned char> &outputBuffer,
390 unsigned int reserveSize,
392 unsigned int hdr_size = addHeader ? 4 : 0;
393 unsigned int resultSize = 0;
396 size_t worst_size = ZSTD_compressBound(inputSize);
398 if (outputBuffer.size() < worst_size + reserveSize + hdr_size)
399 outputBuffer.resize(worst_size + reserveSize + hdr_size);
402 unsigned char *tgt = &outputBuffer[reserveSize];
411 size_t dest_size = ZSTD_compress(
412 (
void *)&outputBuffer[reserveSize + hdr_size], worst_size, (
void *)inputBuffer, inputSize,
compressionLevel);
415 if (!ZSTD_isError(dest_size)) {
417 resultSize = (
unsigned int)dest_size + hdr_size;
419 FDEBUG(1) <<
" original size = " << inputSize <<
" final size = " << dest_size
420 <<
" ratio = " << double(dest_size) / double(inputSize) << std::endl;
423 <<
"Compression (ZSTD) Error: " << ZSTD_getErrorName(dest_size);