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() {
18  ++size_;
19  }
20 
21  unsigned int detId() const { return detId_; }
22  unsigned int size() const { return size_; }
23 
24  private:
25  unsigned int detId_ = 0;
26  unsigned char size_ = 0;
27  };
28  class Data {
29  public:
30  constexpr static unsigned energyOffset = 15;
31  constexpr static unsigned energyMask = 0x1;
32  constexpr static unsigned sampleOffset = 11;
33  constexpr static unsigned sampleMask = 0xf;
34  constexpr static unsigned dataOffset = 0;
35  constexpr static unsigned dataMask = 0x7ff;
36 
37  Data(): data_(0) {}
38  Data(unsigned short ei, unsigned short si, unsigned short d):
39  data_((ei << energyOffset) | (si << sampleOffset) | d)
40  {}
41 
42  unsigned int energyIndex() const { return data_ >> energyOffset; }
43  unsigned int sampleIndex() const { return (data_ >> sampleOffset) & sampleMask; }
44  unsigned int data() const { return data_ & dataMask; }
45 
46  private:
47  unsigned short data_;
48  };
49 
50  PHGCSimAccumulator() = default;
51  ~PHGCSimAccumulator() = default;
52 
53  void reserve(size_t size) {
54  detIdSize_.reserve(size);
55  data_.reserve(size);
56  }
57 
58  void shrink_to_fit() {
59  detIdSize_.shrink_to_fit();
60  data_.shrink_to_fit();
61  }
62 
70  void emplace_back(unsigned int detId, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data) {
71  if(detIdSize_.empty() || detIdSize_.back().detId() != detId) {
72  detIdSize_.emplace_back(detId);
73  }
74  data_.emplace_back(energyIndex, sampleIndex, data);
75  detIdSize_.back().increaseSize();
76  }
77 
78  class TmpElem {
79  public:
80  TmpElem(unsigned int detId, Data data): detId_(detId), data_(data) {}
81 
82  unsigned int detId() const { return detId_; }
83  unsigned short energyIndex() const { return data_.energyIndex(); }
84  unsigned short sampleIndex() const { return data_.sampleIndex(); }
85  unsigned short data() const { return data_.data(); }
86  private:
87  unsigned int detId_;
89  };
90 
92  public:
93  // begin
95  acc_(acc), iDet_(0), iData_(0),
96  endData_(acc->detIdSize_.empty() ? 0 : acc->detIdSize_.front().size())
97  {}
98 
99  // end
100  const_iterator(const PHGCSimAccumulator *acc, unsigned int detSize, unsigned int dataSize):
101  acc_(acc), iDet_(detSize), iData_(dataSize), endData_(0)
102  {}
103 
104  bool operator==(const const_iterator& other) const {
105  return iDet_ == other.iDet_ && iData_ == other.iData_;
106  }
107  bool operator!=(const const_iterator& other) const {
108  return !operator==(other);
109  }
111  ++iData_;
112  if(iData_ == endData_) {
113  ++iDet_;
114  endData_ += (iDet_ == acc_->detIdSize_.size()) ? 0 : acc_->detIdSize_[iDet_].size();
115  }
116  return *this;
117  }
119  auto tmp = *this;
120  ++(*this);
121  return tmp;
122  }
124  return TmpElem(acc_->detIdSize_[iDet_].detId(),
125  acc_->data_[iData_]);
126  }
127 
128  private:
130  unsigned int iDet_;
131  unsigned int iData_;
132  unsigned int endData_;
133  };
134 
135  TmpElem back() const {
136  return TmpElem(detIdSize_.back().detId(),
137  data_.back());
138  }
139 
140  const_iterator cbegin() const { return const_iterator(this); }
141  const_iterator begin() const { return cbegin(); }
142  const_iterator cend() const { return const_iterator(this, detIdSize_.size(), data_.size()); }
143  const_iterator end() const { return cend(); }
144 
145 private:
146  std::vector<DetIdSize> detIdSize_;
147  std::vector<Data> data_;
148 };
149 
150 #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_
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
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_
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
TmpElem back() const
const_iterator cbegin() const
bool operator==(const const_iterator &other) const
unsigned int detId() const
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