CMS 3D CMS Logo

PMTDSimAccumulator.h
Go to the documentation of this file.
1 #ifndef DataFormats_FTLDigi_PMTDSimAccumulator_h
2 #define DataFormats_FTLDigi_PMTDSimAccumulator_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, unsigned char row, unsigned char col):
16  detId_(detId), row_(row), column_(col)
17  {}
18 
19  void increaseSize() {
20  ++size_;
21  }
22 
23  unsigned int detId() const { return detId_; }
24  unsigned char row() const { return row_; }
25  unsigned char column() const { return column_; }
26  unsigned int size() const { return size_; }
27 
28  private:
29  unsigned int detId_ = 0;
30  unsigned char row_ = 0;
31  unsigned char column_ = 0;
32  unsigned char size_ = 0;
33  };
34  class Data {
35  public:
36  constexpr static unsigned energyOffset = 15;
37  constexpr static unsigned energyMask = 0x1;
38  constexpr static unsigned sampleOffset = 11;
39  constexpr static unsigned sampleMask = 0xf;
40  constexpr static unsigned dataOffset = 0;
41  constexpr static unsigned dataMask = 0x7ff;
42 
43  Data(): data_(0) {}
44  Data(unsigned short ei, unsigned short si, unsigned short d):
45  data_((ei << energyOffset) | (si << sampleOffset) | d)
46  {}
47 
48  unsigned int energyIndex() const { return data_ >> energyOffset; }
49  unsigned int sampleIndex() const { return (data_ >> sampleOffset) & sampleMask; }
50  unsigned int data() const { return data_ & dataMask; }
51 
52  private:
53  unsigned short data_;
54  };
55 
56  PMTDSimAccumulator() = default;
57  ~PMTDSimAccumulator() = default;
58 
59  void reserve(size_t size) {
60  detIdSize_.reserve(size);
61  data_.reserve(size);
62  }
63 
64  void shrink_to_fit() {
65  detIdSize_.shrink_to_fit();
66  data_.shrink_to_fit();
67  }
68 
76  void emplace_back(unsigned int detId, unsigned char row, unsigned char column, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data) {
77  if(detIdSize_.empty() || detIdSize_.back().detId() != detId || detIdSize_.back().row() != row || detIdSize_.back().column() != column) {
78  detIdSize_.emplace_back(detId, row, column);
79  }
80  data_.emplace_back(energyIndex, sampleIndex, data);
81  detIdSize_.back().increaseSize();
82  }
83 
84  class TmpElem {
85  public:
86  TmpElem(unsigned int detId, unsigned char row, unsigned char column, Data data):
87  detId_(detId), data_(data), row_(row), column_(column)
88  {}
89 
90  unsigned int detId() const { return detId_; }
91  unsigned char row() const { return row_; }
92  unsigned char column() const { return column_; }
93  unsigned short energyIndex() const { return data_.energyIndex(); }
94  unsigned short sampleIndex() const { return data_.sampleIndex(); }
95  unsigned short data() const { return data_.data(); }
96  private:
97  unsigned int detId_;
99  unsigned char row_;
100  unsigned char column_;
101  };
102 
104  public:
105  // begin
107  acc_(acc), iDet_(0), iData_(0),
108  endData_(acc->detIdSize_.empty() ? 0 : acc->detIdSize_.front().size())
109  {}
110 
111  // end
112  const_iterator(const PMTDSimAccumulator *acc, unsigned int detSize, unsigned int dataSize):
113  acc_(acc), iDet_(detSize), iData_(dataSize), endData_(0)
114  {}
115 
116  bool operator==(const const_iterator& other) const {
117  return iDet_ == other.iDet_ && iData_ == other.iData_;
118  }
119  bool operator!=(const const_iterator& other) const {
120  return !operator==(other);
121  }
123  ++iData_;
124  if(iData_ == endData_) {
125  ++iDet_;
126  endData_ += (iDet_ == acc_->detIdSize_.size()) ? 0 : acc_->detIdSize_[iDet_].size();
127  }
128  return *this;
129  }
131  auto tmp = *this;
132  ++(*this);
133  return tmp;
134  }
136  const auto& id = acc_->detIdSize_[iDet_];
137  return TmpElem(id.detId(), id.row(), id.column(),
138  acc_->data_[iData_]);
139  }
140 
141  private:
143  unsigned int iDet_;
144  unsigned int iData_;
145  unsigned int endData_;
146  };
147 
148  TmpElem back() const {
149  const auto& id = detIdSize_.back();
150  return TmpElem(id.detId(), id.row(), id.column(),
151  data_.back());
152  }
153 
154  const_iterator cbegin() const { return const_iterator(this); }
155  const_iterator begin() const { return cbegin(); }
156  const_iterator cend() const { return const_iterator(this, detIdSize_.size(), data_.size()); }
157  const_iterator end() const { return cend(); }
158 
159 private:
160  std::vector<DetIdSize> detIdSize_;
161  std::vector<Data> data_;
162 };
163 
164 #endif
unsigned short sampleIndex() const
const_iterator cend() const
unsigned int detId() const
unsigned char row() const
unsigned char column() const
const_iterator(const PMTDSimAccumulator *acc, unsigned int detSize, unsigned int dataSize)
bool operator==(const const_iterator &other) const
void emplace_back(unsigned int detId, unsigned char row, unsigned char column, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data)
std::vector< Data > data_
void reserve(size_t size)
unsigned int data() const
const_iterator(const PMTDSimAccumulator *acc)
bool operator!=(const const_iterator &other) const
const PMTDSimAccumulator * acc_
PMTDSimAccumulator()=default
unsigned int sampleIndex() const
const_iterator end() const
unsigned short energyIndex() const
~PMTDSimAccumulator()=default
bool operator==(const QGLikelihoodParameters &lhs, const QGLikelihoodCategory &rhs)
Test if parameters are compatible with category.
unsigned int energyIndex() const
unsigned char column() const
std::vector< DetIdSize > detIdSize_
Data(unsigned short ei, unsigned short si, unsigned short d)
unsigned short data() const
TmpElem(unsigned int detId, unsigned char row, unsigned char column, Data data)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
const_iterator cbegin() const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
col
Definition: cuy.py:1010
TmpElem back() const
DetIdSize(unsigned int detId, unsigned char row, unsigned char col)
const_iterator begin() const
unsigned char row() const
#define constexpr