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_
 
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 5 of file HGCalVFECompressionImpl.cc.

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

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

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 71 of file HGCalVFECompressionImpl.cc.

72  {
73  for (const auto& item : payload) {
74  const uint32_t value = item.second;
75  uint32_t code(0);
76  uint32_t compressed_value(0);
77  compressSingle(value, code, compressed_value);
78  std::array<uint32_t, 2> compressed_item = {{code, compressed_value}};
79  compressed_payload.emplace(item.first, compressed_item);
80  }
81 }

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 19 of file HGCalVFECompressionImpl.cc.

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

References HLT_FULL_cff::exponent, mantissaBits_, rounding_, saturationCode_, saturationValue_, truncationBits_, and mitigatedMETSequence_cff::U.

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

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_

uint32_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().

HGCalVFECompressionImpl::saturationCode_
uint32_t saturationCode_
Definition: HGCalVFECompressionImpl.h:21
HGCalVFECompressionImpl::exponentBits_
uint32_t exponentBits_
Definition: HGCalVFECompressionImpl.h:17
HGCalVFECompressionImpl::rounding_
bool rounding_
Definition: HGCalVFECompressionImpl.h:20
HGCalVFECompressionImpl::mantissaBits_
uint32_t mantissaBits_
Definition: HGCalVFECompressionImpl.h:18
HLT_FULL_cff.exponent
exponent
Definition: HLT_FULL_cff.py:52788
jets_cff.payload
payload
Definition: jets_cff.py:32
HGCalVFECompressionImpl::truncationBits_
uint32_t truncationBits_
Definition: HGCalVFECompressionImpl.h:19
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
value
Definition: value.py:1
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
Exception
Definition: hltDiff.cc:246
HGCalVFECompressionImpl::saturationValue_
uint32_t saturationValue_
Definition: HGCalVFECompressionImpl.h:22
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
HGCalVFECompressionImpl::compressSingle
void compressSingle(const uint32_t value, uint32_t &compressedCode, uint32_t &compressedValue) const
Definition: HGCalVFECompressionImpl.cc:19