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) : detId_(detId), row_(row), column_(col) {}
16 
17  void increaseSize() { ++size_; }
18 
19  unsigned int detId() const { return detId_; }
20  unsigned char row() const { return row_; }
21  unsigned char column() const { return column_; }
22  unsigned int size() const { return size_; }
23 
24  private:
25  unsigned int detId_ = 0;
26  unsigned char row_ = 0;
27  unsigned char column_ = 0;
28  unsigned char size_ = 0;
29  };
30  class Data {
31  public:
32  constexpr static unsigned energyOffset = 4;
33  constexpr static unsigned energyMask = 0x3;
34  constexpr static unsigned sampleMask = 0xf;
35  constexpr static unsigned dataMask = 0xffff;
36 
37  Data() : data_(0), indices_(0) {}
38  Data(unsigned short ei, unsigned short si, unsigned short d) : data_(d), indices_((ei << energyOffset) | si) {}
39 
40  unsigned int energyIndex() const { return indices_ >> energyOffset; }
41  unsigned int sampleIndex() const { return indices_ & sampleMask; }
42  unsigned int data() const { return data_ & dataMask; }
43 
44  private:
45  unsigned short data_;
46  unsigned char indices_;
47  };
48 
49  PMTDSimAccumulator() = default;
50  ~PMTDSimAccumulator() = default;
51 
52  void reserve(size_t size) {
53  detIdSize_.reserve(size);
54  data_.reserve(size);
55  }
56 
57  void shrink_to_fit() {
58  detIdSize_.shrink_to_fit();
59  data_.shrink_to_fit();
60  }
61 
69  void emplace_back(unsigned int detId,
70  unsigned char row,
71  unsigned char column,
72  unsigned short energyIndex,
73  unsigned short sampleIndex,
74  unsigned short data) {
75  if (detIdSize_.empty() || detIdSize_.back().detId() != detId || detIdSize_.back().row() != row ||
76  detIdSize_.back().column() != column) {
77  detIdSize_.emplace_back(detId, row, column);
78  }
79  data_.emplace_back(energyIndex, sampleIndex, data);
80  detIdSize_.back().increaseSize();
81  }
82 
83  class TmpElem {
84  public:
85  TmpElem(unsigned int detId, unsigned char row, unsigned char column, Data data)
87 
88  unsigned int detId() const { return detId_; }
89  unsigned char row() const { return row_; }
90  unsigned char column() const { return column_; }
91  unsigned short energyIndex() const { return data_.energyIndex(); }
92  unsigned short sampleIndex() const { return data_.sampleIndex(); }
93  unsigned short data() const { return data_.data(); }
94 
95  private:
96  unsigned int detId_;
98  unsigned char row_;
99  unsigned char column_;
100  };
101 
103  public:
104  // begin
106  : acc_(acc), iDet_(0), iData_(0), endData_(acc->detIdSize_.empty() ? 0 : acc->detIdSize_.front().size()) {}
107 
108  // end
109  const_iterator(const PMTDSimAccumulator* acc, unsigned int detSize, unsigned int dataSize)
110  : acc_(acc), iDet_(detSize), iData_(dataSize), endData_(0) {}
111 
112  bool operator==(const const_iterator& other) const { return iDet_ == other.iDet_ && iData_ == other.iData_; }
113  bool operator!=(const const_iterator& other) const { return !operator==(other); }
115  ++iData_;
116  if (iData_ == endData_) {
117  ++iDet_;
118  endData_ += (iDet_ == acc_->detIdSize_.size()) ? 0 : acc_->detIdSize_[iDet_].size();
119  }
120  return *this;
121  }
123  auto tmp = *this;
124  ++(*this);
125  return tmp;
126  }
128  const auto& id = acc_->detIdSize_[iDet_];
129  return TmpElem(id.detId(), id.row(), id.column(), acc_->data_[iData_]);
130  }
131 
132  private:
134  unsigned int iDet_;
135  unsigned int iData_;
136  unsigned int endData_;
137  };
138 
139  TmpElem back() const {
140  const auto& id = detIdSize_.back();
141  return TmpElem(id.detId(), id.row(), id.column(), data_.back());
142  }
143 
144  const_iterator cbegin() const { return const_iterator(this); }
145  const_iterator begin() const { return cbegin(); }
146  const_iterator cend() const { return const_iterator(this, detIdSize_.size(), data_.size()); }
147  const_iterator end() const { return cend(); }
148 
149 private:
150  std::vector<DetIdSize> detIdSize_;
151  std::vector<Data> data_;
152 };
153 
154 #endif
size
Write out results.
static constexpr unsigned energyOffset
static constexpr unsigned energyMask
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 char column() const
const_iterator(const PMTDSimAccumulator *acc)
unsigned char row() const
const_iterator cend() const
const PMTDSimAccumulator * acc_
PMTDSimAccumulator()=default
unsigned short energyIndex() const
~PMTDSimAccumulator()=default
const_iterator cbegin() const
const_iterator end() const
d
Definition: ztail.py:151
unsigned short sampleIndex() const
unsigned short data() const
std::vector< DetIdSize > detIdSize_
bool operator==(const const_iterator &other) const
Data(unsigned short ei, unsigned short si, unsigned short d)
TmpElem(unsigned int detId, unsigned char row, unsigned char column, Data data)
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
static constexpr unsigned dataMask
col
Definition: cuy.py:1009
unsigned int data() const
static constexpr unsigned sampleMask
unsigned char column() const
unsigned int detId() const
unsigned int energyIndex() const
TmpElem back() const
DetIdSize(unsigned int detId, unsigned char row, unsigned char col)
tmp
align.sh
Definition: createJobs.py:716
unsigned int sampleIndex() const
const_iterator begin() const