CMS 3D CMS Logo

HGCalDenseIndexerBase.h
Go to the documentation of this file.
1 #ifndef CondFormats_HGCalObjects_interface_HGCalDenseIndexerBase_h
2 #define CondFormats_HGCalObjects_interface_HGCalDenseIndexerBase_h
3 
6 #include <array>
7 #include <numeric>
8 
15 public:
17 
18  HGCalDenseIndexerBase(int n) : n_(n), maxIdx_(0), vmax_(n, 0) {}
19 
20  HGCalDenseIndexerBase(std::vector<uint32_t> const &o) : n_(o.size()) { updateRanges(o); }
21 
22  void updateRanges(std::vector<uint32_t> const &o) {
23  check(o.size());
24  vmax_ = o;
25  maxIdx_ = std::accumulate(vmax_.begin(), vmax_.end(), 1, std::multiplies<uint32_t>());
26  }
27 
28  uint32_t denseIndex(std::vector<uint32_t> v) const {
29  uint32_t rtn = v[0];
30  for (size_t i = 1; i < n_; i++)
31  rtn = rtn * vmax_[i] + v[i];
32  return rtn;
33  }
34 
35  std::vector<uint32_t> unpackDenseIndex(uint32_t rtn) const {
36  std::vector<uint32_t> codes(n_, 0);
37 
38  const auto rend = vmax_.rend();
39  for (auto rit = vmax_.rbegin(); rit != rend; ++rit) {
40  size_t i = rend - rit - 1;
41  codes[i] = rtn % (*rit);
42  rtn = rtn / (*rit);
43  }
44 
45  return codes;
46  }
47 
48  uint32_t getMaxIndex() const { return maxIdx_; }
49 
50  ~HGCalDenseIndexerBase() = default;
51 
52 private:
53  void check(size_t osize) const {
54  if (osize != n_)
55  throw cms::Exception("ValueError") << " unable to update indexer max values. Expected " << n_ << " received "
56  << osize;
57  }
58 
59  uint32_t n_;
60  uint32_t maxIdx_;
61  std::vector<uint32_t> vmax_;
62 
64 };
65 
66 #endif
size
Write out results.
std::vector< uint32_t > unpackDenseIndex(uint32_t rtn) const
uint32_t getMaxIndex() const
void check(size_t osize) const
this is a simple class that takes care of building a dense index for a set of categories the maximum ...
~HGCalDenseIndexerBase()=default
HGCalDenseIndexerBase(std::vector< uint32_t > const &o)
uint32_t denseIndex(std::vector< uint32_t > v) const
#define COND_SERIALIZABLE
Definition: Serializable.h:39
std::vector< uint32_t > vmax_
void updateRanges(std::vector< uint32_t > const &o)