CMS 3D CMS Logo

PHGCSimAccumulator.h
Go to the documentation of this file.
1 #ifndef DataFormats_HGCDigi_PHGCSimAccumulator_h
2 #define DataFormats_HGCDigi_PHGCSimAccumulator_h
3 
5 
6 #include <vector>
7 #include <cassert>
8 
10 public:
11  // These two structs are public only because of dictionary generation
12  class DetIdSize {
13  public:
14  DetIdSize() {}
15  DetIdSize(unsigned int detId) : detId_(detId) {}
16 
17  void increaseSize() { ++size_; }
18 
19  unsigned int detId() const { return detId_; }
20  unsigned int size() const { return size_; }
21 
22  private:
23  unsigned int detId_ = 0;
24  unsigned char size_ = 0;
25  };
26  class Data {
27  public:
28  constexpr static unsigned energyOffset = 15;
29  constexpr static unsigned energyMask = 0x1;
30  constexpr static unsigned sampleOffset = 11;
31  constexpr static unsigned sampleMask = 0xf;
32  constexpr static unsigned dataOffset = 0;
33  constexpr static unsigned dataMask = 0x7ff;
34 
35  Data() : data_(0) {}
36  Data(unsigned short ei, unsigned short si, unsigned short d)
37  : data_((ei << energyOffset) | (si << sampleOffset) | d) {}
38 
39  unsigned int energyIndex() const { return data_ >> energyOffset; }
40  unsigned int sampleIndex() const { return (data_ >> sampleOffset) & sampleMask; }
41  unsigned int data() const { return data_ & dataMask; }
42 
43  private:
44  unsigned short data_;
45  };
46 
47  PHGCSimAccumulator() = default;
48  ~PHGCSimAccumulator() = default;
49 
50  void reserve(size_t size) {
51  detIdSize_.reserve(size);
52  data_.reserve(size);
53  }
54 
55  void shrink_to_fit() {
56  detIdSize_.shrink_to_fit();
57  data_.shrink_to_fit();
58  }
59 
67  void emplace_back(unsigned int detId, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data) {
68  if (detIdSize_.empty() || detIdSize_.back().detId() != detId) {
69  detIdSize_.emplace_back(detId);
70  }
71  data_.emplace_back(energyIndex, sampleIndex, data);
72  detIdSize_.back().increaseSize();
73  }
74 
75  class TmpElem {
76  public:
77  TmpElem(unsigned int detId, Data data) : detId_(detId), data_(data) {}
78 
79  unsigned int detId() const { return detId_; }
80  unsigned short energyIndex() const { return data_.energyIndex(); }
81  unsigned short sampleIndex() const { return data_.sampleIndex(); }
82  unsigned short data() const { return data_.data(); }
83 
84  private:
85  unsigned int detId_;
87  };
88 
90  public:
91  // begin
93  : acc_(acc), iDet_(0), iData_(0), endData_(acc->detIdSize_.empty() ? 0 : acc->detIdSize_.front().size()) {}
94 
95  // end
96  const_iterator(const PHGCSimAccumulator* acc, unsigned int detSize, unsigned int dataSize)
97  : acc_(acc), iDet_(detSize), iData_(dataSize), endData_(0) {}
98 
99  bool operator==(const const_iterator& other) const { return iDet_ == other.iDet_ && iData_ == other.iData_; }
100  bool operator!=(const const_iterator& other) const { return !operator==(other); }
102  ++iData_;
103  if (iData_ == endData_) {
104  ++iDet_;
105  endData_ += (iDet_ == acc_->detIdSize_.size()) ? 0 : acc_->detIdSize_[iDet_].size();
106  }
107  return *this;
108  }
110  auto tmp = *this;
111  ++(*this);
112  return tmp;
113  }
114  TmpElem operator*() { return TmpElem(acc_->detIdSize_[iDet_].detId(), acc_->data_[iData_]); }
115 
116  private:
118  unsigned int iDet_;
119  unsigned int iData_;
120  unsigned int endData_;
121  };
122 
123  TmpElem back() const { return TmpElem(detIdSize_.back().detId(), data_.back()); }
124 
125  const_iterator cbegin() const { return const_iterator(this); }
126  const_iterator begin() const { return cbegin(); }
127  const_iterator cend() const { return const_iterator(this, detIdSize_.size(), data_.size()); }
128  const_iterator end() const { return cend(); }
129 
130 private:
131  std::vector<DetIdSize> detIdSize_;
132  std::vector<Data> data_;
133 };
134 
135 #endif
unsigned short data() const
unsigned int data() const
const PHGCSimAccumulator * acc_
void emplace_back(unsigned int detId, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data)
std::vector< Data > data_
std::map< l1t::HGCalMulticluster::EnergyInterpretation, double > ei
Definition: classes.h:67
bool operator!=(const const_iterator &other) const
const_iterator cend() const
const_iterator begin() const
unsigned int energyIndex() const
TmpElem(unsigned int detId, Data data)
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
~PHGCSimAccumulator()=default
PHGCSimAccumulator()=default
d
Definition: ztail.py:151
unsigned int sampleIndex() const
unsigned short sampleIndex() const
const_iterator(const PHGCSimAccumulator *acc)
void reserve(size_t size)
unsigned short energyIndex() const
std::vector< DetIdSize > detIdSize_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
TmpElem back() const
const_iterator cbegin() const
bool operator==(const const_iterator &other) const
unsigned int detId() const
tmp
align.sh
Definition: createJobs.py:716
const_iterator(const PHGCSimAccumulator *acc, unsigned int detSize, unsigned int dataSize)
#define constexpr
Data(unsigned short ei, unsigned short si, unsigned short d)
const_iterator end() const