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< uint32_t, 2 > > &)
 
void compressSingle (const uint32_t value, uint32_t &compressedCode, uint32_t &compressedValue) const
 
 HGCalVFECompressionImpl (const edm::ParameterSet &conf)
 

Private Attributes

uint32_t exponentBits_
 
uint32_t mantissaBits_
 
bool rounding_
 
uint32_t saturationCode_
 
uint32_t saturationValue_
 

Detailed Description

Definition at line 7 of file HGCalVFECompressionImpl.h.

Constructor & Destructor Documentation

◆ HGCalVFECompressionImpl()

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

Definition at line 3 of file HGCalVFECompressionImpl.cc.

4  : exponentBits_(conf.getParameter<uint32_t>("exponentBits")),
5  mantissaBits_(conf.getParameter<uint32_t>("mantissaBits")),
6  rounding_(conf.getParameter<bool>("rounding")) {
7  if (((1 << exponentBits_) + mantissaBits_ - 1) >= 32) {
8  throw cms::Exception("CodespaceCannotFit") << "The code space cannot fit into the unsigned 32-bit space.\n";
9  }
12  (exponentBits_ == 0) ? saturationCode_ : ((1 << (mantissaBits_ + 1)) - 1) << ((1 << exponentBits_) - 2);
13 }

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

Member Function Documentation

◆ compress()

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

Definition at line 65 of file HGCalVFECompressionImpl.cc.

66  {
67  for (const auto& item : payload) {
68  const uint32_t value = item.second;
69  uint32_t code(0);
70  uint32_t compressed_value(0);
71  compressSingle(value, code, compressed_value);
72  std::array<uint32_t, 2> compressed_item = {{code, compressed_value}};
73  compressed_payload.emplace(item.first, compressed_item);
74  }
75 }

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

◆ compressSingle()

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

Definition at line 15 of file HGCalVFECompressionImpl.cc.

17  {
18  // check for saturation
19  if (value > saturationValue_) {
20  compressedCode = saturationCode_;
21  compressedValue = saturationValue_;
22  return;
23  }
24 
25  // count bit length
26  uint32_t bitlen;
27  uint32_t valcopy = value;
28  for (bitlen = 0; valcopy != 0; valcopy >>= 1, bitlen++) {
29  }
30  if (bitlen <= mantissaBits_) {
31  compressedCode = value;
32  compressedValue = value;
33  return;
34  }
35 
36  // build exponent and mantissa
37  const uint32_t exponent = bitlen - mantissaBits_;
38  const uint32_t mantissa = (value >> (exponent - 1)) & ~(1 << mantissaBits_);
39 
40  // assemble floating-point
41  const uint32_t floatval = (exponent << mantissaBits_) | mantissa;
42 
43  // we will never want to round up maximum code here
44  if (!rounding_ || floatval == saturationCode_) {
45  compressedCode = floatval;
46  compressedValue = ((1 << mantissaBits_) | mantissa) << (exponent - 1);
47  } else {
48  const bool roundup = ((value >> (exponent - 2)) & 1) == 1;
49  if (!roundup) {
50  compressedCode = floatval;
51  compressedValue = ((1 << mantissaBits_) | mantissa) << (exponent - 1);
52  } else {
53  compressedCode = floatval + 1;
54  uint32_t rmantissa = mantissa + 1;
55  uint32_t rexponent = exponent;
56  if (rmantissa >= (1U << mantissaBits_)) {
57  rexponent++;
58  rmantissa &= ~(1 << mantissaBits_);
59  }
60  compressedValue = ((1 << mantissaBits_) | rmantissa) << (rexponent - 1);
61  }
62  }
63 }

References HLT_2018_cff::exponent, mantissaBits_, rounding_, saturationCode_, saturationValue_, mitigatedMETSequence_cff::U, and relativeConstraints::value.

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

Member Data Documentation

◆ exponentBits_

uint32_t HGCalVFECompressionImpl::exponentBits_
private

Definition at line 15 of file HGCalVFECompressionImpl.h.

Referenced by HGCalVFECompressionImpl().

◆ mantissaBits_

uint32_t HGCalVFECompressionImpl::mantissaBits_
private

Definition at line 16 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().

◆ rounding_

bool HGCalVFECompressionImpl::rounding_
private

Definition at line 17 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle().

◆ saturationCode_

uint32_t HGCalVFECompressionImpl::saturationCode_
private

Definition at line 18 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().

◆ saturationValue_

uint32_t HGCalVFECompressionImpl::saturationValue_
private

Definition at line 19 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().

HGCalVFECompressionImpl::saturationCode_
uint32_t saturationCode_
Definition: HGCalVFECompressionImpl.h:18
HLT_2018_cff.exponent
exponent
Definition: HLT_2018_cff.py:51310
HGCalVFECompressionImpl::exponentBits_
uint32_t exponentBits_
Definition: HGCalVFECompressionImpl.h:15
HGCalVFECompressionImpl::rounding_
bool rounding_
Definition: HGCalVFECompressionImpl.h:17
HGCalVFECompressionImpl::mantissaBits_
uint32_t mantissaBits_
Definition: HGCalVFECompressionImpl.h:16
jets_cff.payload
payload
Definition: jets_cff.py:34
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
value
Definition: value.py:1
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
relativeConstraints.value
value
Definition: relativeConstraints.py:53
Exception
Definition: hltDiff.cc:246
HGCalVFECompressionImpl::saturationValue_
uint32_t saturationValue_
Definition: HGCalVFECompressionImpl.h:19
HGCalVFECompressionImpl::compressSingle
void compressSingle(const uint32_t value, uint32_t &compressedCode, uint32_t &compressedValue) const
Definition: HGCalVFECompressionImpl.cc:15