CMS 3D CMS Logo

List of all members | Public Member Functions | Private 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 > > &)
 
 HGCalVFECompressionImpl (const edm::ParameterSet &conf)
 

Private Member Functions

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

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 ( const edm::ParameterSet conf)

Definition at line 3 of file HGCalVFECompressionImpl.cc.

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

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 }
T getParameter(std::string const &) const

Member Function Documentation

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.

References compressSingle().

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 }
Definition: value.py:1
void compressSingle(const uint32_t value, uint32_t &compressedCode, uint32_t &compressedValue)
void HGCalVFECompressionImpl::compressSingle ( const uint32_t  value,
uint32_t &  compressedCode,
uint32_t &  compressedValue 
)
private

Definition at line 15 of file HGCalVFECompressionImpl.cc.

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

Referenced by compress().

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 }
Definition: value.py:1

Member Data Documentation

uint32_t HGCalVFECompressionImpl::exponentBits_
private

Definition at line 16 of file HGCalVFECompressionImpl.h.

Referenced by HGCalVFECompressionImpl().

uint32_t HGCalVFECompressionImpl::mantissaBits_
private

Definition at line 17 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().

bool HGCalVFECompressionImpl::rounding_
private

Definition at line 18 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle().

uint32_t HGCalVFECompressionImpl::saturationCode_
private

Definition at line 19 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().

uint32_t HGCalVFECompressionImpl::saturationValue_
private

Definition at line 20 of file HGCalVFECompressionImpl.h.

Referenced by compressSingle(), and HGCalVFECompressionImpl().