CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
HGCalVFECompressionImpl Class Reference

#include <HGCalVFECompressionImpl.h>

Public Member Functions

void compress (const std::unordered_map< uint32_t, uint32_t > &, std::unordered_map< uint32_t, std::array< uint64_t, 2 > > &)
 
void compressSingle (const uint64_t value, uint32_t &compressedCode, uint64_t &compressedValue) const
 
 HGCalVFECompressionImpl (const edm::ParameterSet &conf)
 

Private Attributes

uint32_t exponentBits_
 
uint32_t mantissaBits_
 
bool rounding_
 
uint32_t saturationCode_
 
uint64_t saturationValue_
 
uint32_t truncationBits_
 

Detailed Description

Definition at line 9 of file HGCalVFECompressionImpl.h.

Constructor & Destructor Documentation

◆ HGCalVFECompressionImpl()

HGCalVFECompressionImpl::HGCalVFECompressionImpl ( const edm::ParameterSet conf)

Definition at line 7 of file HGCalVFECompressionImpl.cc.

References Exception, exponentBits_, mantissaBits_, saturationCode_, saturationValue_, and truncationBits_.

8  : exponentBits_(conf.getParameter<uint32_t>("exponentBits")),
9  mantissaBits_(conf.getParameter<uint32_t>("mantissaBits")),
10  truncationBits_(conf.getParameter<uint32_t>("truncationBits")),
11  rounding_(conf.getParameter<bool>("rounding")) {
12  if (((1 << exponentBits_) + mantissaBits_ - 1) >= 64) {
13  throw cms::Exception("CodespaceCannotFit") << "The code space cannot fit into the unsigned 64-bit space.\n";
14  }
18  : ((1ULL << (mantissaBits_ + truncationBits_ + 1)) - 1) << ((1 << exponentBits_) - 2);
19 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:307

Member Function Documentation

◆ compress()

void HGCalVFECompressionImpl::compress ( const std::unordered_map< uint32_t, uint32_t > &  payload,
std::unordered_map< uint32_t, std::array< uint64_t, 2 > > &  compressed_payload 
)

Definition at line 76 of file HGCalVFECompressionImpl.cc.

References compressSingle(), B2GTnPMonitor_cfi::item, and jetsAK4_Puppi_cff::payload.

77  {
78  for (const auto& item : payload) {
79  const uint64_t value = static_cast<uint64_t>(item.second);
80  uint32_t code(0);
81  uint64_t compressed_value(0);
82  compressSingle(value, code, compressed_value);
83  std::array<uint64_t, 2> compressed_item = {{static_cast<uint64_t>(code), compressed_value}};
84  compressed_payload.emplace(item.first, compressed_item);
85  }
86 }
void compressSingle(const uint64_t value, uint32_t &compressedCode, uint64_t &compressedValue) const
Definition: value.py:1
unsigned long long uint64_t
Definition: Time.h:13

◆ compressSingle()

void HGCalVFECompressionImpl::compressSingle ( const uint64_t  value,
uint32_t &  compressedCode,
uint64_t &  compressedValue 
) const

Definition at line 21 of file HGCalVFECompressionImpl.cc.

References cms::cuda::assert(), HLT_2024v14_cff::exponent, mantissaBits_, rounding_, saturationCode_, saturationValue_, and truncationBits_.

Referenced by HGCalConcentratorCoarsenerImpl::assignCoarseTriggerCellEnergy(), compress(), and HGCalConcentratorSuperTriggerCellImpl::getCompressedSTCEnergy().

23  {
24  // check for saturation
25  if (value > saturationValue_) {
26  compressedCode = saturationCode_;
27  compressedValue = saturationValue_;
28  return;
29  }
30 
31  // count bit length
32  uint32_t bitlen;
33  uint64_t shifted_value = value >> truncationBits_;
34  uint64_t valcopy = shifted_value;
35  for (bitlen = 0; valcopy != 0; valcopy >>= 1, bitlen++) {
36  }
37  if (bitlen <= mantissaBits_) {
38  compressedCode = shifted_value;
39  compressedValue = shifted_value << truncationBits_;
40  return;
41  }
42 
43  // build exponent and mantissa
44  const uint32_t exponent = bitlen - mantissaBits_;
45  assert(exponent - 1 < 64);
46  const uint64_t mantissa = (shifted_value >> (exponent - 1)) & ~(1ULL << mantissaBits_);
47 
48  // assemble floating-point
49  const uint32_t floatval = (exponent << mantissaBits_) | mantissa;
50 
51  // we will never want to round up maximum code here
52  // Also, rounding doesn't apply if exponent==1 since there is no actual compression
53  // from the conversion to floating point in that case
54  if (!rounding_ || floatval == saturationCode_ || exponent <= 1) {
55  compressedCode = floatval;
56  compressedValue = ((1ULL << mantissaBits_) | mantissa) << (exponent - 1);
57  } else {
58  const bool roundup = ((shifted_value >> (exponent - 2)) & 1ULL) == 1ULL;
59  if (!roundup) {
60  compressedCode = floatval;
61  compressedValue = ((1ULL << mantissaBits_) | mantissa) << (exponent - 1);
62  } else {
63  compressedCode = floatval + 1;
64  uint64_t rmantissa = mantissa + 1;
65  uint32_t rexponent = exponent;
66  if (rmantissa >= (1ULL << mantissaBits_)) {
67  rexponent++;
68  rmantissa &= ~(1ULL << mantissaBits_);
69  }
70  compressedValue = ((1ULL << mantissaBits_) | rmantissa) << (rexponent - 1);
71  }
72  }
73  compressedValue <<= truncationBits_;
74 }
assert(be >=bs)
Definition: value.py:1
unsigned long long uint64_t
Definition: Time.h:13

Member Data Documentation

◆ exponentBits_

uint32_t HGCalVFECompressionImpl::exponentBits_
private

Definition at line 17 of file HGCalVFECompressionImpl.h.

Referenced by HGCalVFECompressionImpl().

◆ mantissaBits_

uint32_t HGCalVFECompressionImpl::mantissaBits_
private

Definition at line 18 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().

◆ rounding_

bool HGCalVFECompressionImpl::rounding_
private

Definition at line 20 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle().

◆ saturationCode_

uint32_t HGCalVFECompressionImpl::saturationCode_
private

Definition at line 21 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().

◆ saturationValue_

uint64_t HGCalVFECompressionImpl::saturationValue_
private

Definition at line 22 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().

◆ truncationBits_

uint32_t HGCalVFECompressionImpl::truncationBits_
private

Definition at line 19 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().