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
PMTDSimAccumulator::const_iterator::operator!=
bool operator!=(const const_iterator &other) const
Definition: PMTDSimAccumulator.h:113
PMTDSimAccumulator::TmpElem::column_
unsigned char column_
Definition: PMTDSimAccumulator.h:99
PMTDSimAccumulator::TmpElem::row_
unsigned char row_
Definition: PMTDSimAccumulator.h:98
PMTDSimAccumulator::Data::Data
Data()
Definition: PMTDSimAccumulator.h:37
PMTDSimAccumulator::Data::data
unsigned int data() const
Definition: PMTDSimAccumulator.h:42
PMTDSimAccumulator::DetIdSize::row_
unsigned char row_
Definition: PMTDSimAccumulator.h:26
PMTDSimAccumulator::shrink_to_fit
void shrink_to_fit()
Definition: PMTDSimAccumulator.h:57
PMTDSimAccumulator::const_iterator
Definition: PMTDSimAccumulator.h:102
PMTDSimAccumulator::TmpElem
Definition: PMTDSimAccumulator.h:83
PMTDSimAccumulator
Definition: PMTDSimAccumulator.h:9
cuy.col
col
Definition: cuy.py:1009
PMTDSimAccumulator::DetIdSize::detId_
unsigned int detId_
Definition: PMTDSimAccumulator.h:25
PMTDSimAccumulator::Data::energyOffset
constexpr static unsigned energyOffset
Definition: PMTDSimAccumulator.h:32
PMTDSimAccumulator::TmpElem::sampleIndex
unsigned short sampleIndex() const
Definition: PMTDSimAccumulator.h:92
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
PMTDSimAccumulator::const_iterator::acc_
const PMTDSimAccumulator * acc_
Definition: PMTDSimAccumulator.h:133
PMTDSimAccumulator::data_
std::vector< Data > data_
Definition: PMTDSimAccumulator.h:151
PMTDSimAccumulator::begin
const_iterator begin() const
Definition: PMTDSimAccumulator.h:145
PMTDSimAccumulator::reserve
void reserve(size_t size)
Definition: PMTDSimAccumulator.h:52
PMTDSimAccumulator::DetIdSize::DetIdSize
DetIdSize(unsigned int detId, unsigned char row, unsigned char col)
Definition: PMTDSimAccumulator.h:15
PMTDSimAccumulator::const_iterator::operator*
TmpElem operator*()
Definition: PMTDSimAccumulator.h:127
PMTDSimAccumulator::detIdSize_
std::vector< DetIdSize > detIdSize_
Definition: PMTDSimAccumulator.h:150
PMTDSimAccumulator::const_iterator::const_iterator
const_iterator(const PMTDSimAccumulator *acc)
Definition: PMTDSimAccumulator.h:105
PMTDSimAccumulator::end
const_iterator end() const
Definition: PMTDSimAccumulator.h:147
PMTDSimAccumulator::const_iterator::operator==
bool operator==(const const_iterator &other) const
Definition: PMTDSimAccumulator.h:112
PMTDSimAccumulator::Data::data_
unsigned short data_
Definition: PMTDSimAccumulator.h:45
trackingPlots.other
other
Definition: trackingPlots.py:1464
PMTDSimAccumulator::~PMTDSimAccumulator
~PMTDSimAccumulator()=default
PMTDSimAccumulator::TmpElem::data
unsigned short data() const
Definition: PMTDSimAccumulator.h:93
PMTDSimAccumulator::DetIdSize::size
unsigned int size() const
Definition: PMTDSimAccumulator.h:22
PMTDSimAccumulator::Data::indices_
unsigned char indices_
Definition: PMTDSimAccumulator.h:46
PMTDSimAccumulator::back
TmpElem back() const
Definition: PMTDSimAccumulator.h:139
PMTDSimAccumulator::DetIdSize::column_
unsigned char column_
Definition: PMTDSimAccumulator.h:27
PMTDSimAccumulator::TmpElem::row
unsigned char row() const
Definition: PMTDSimAccumulator.h:89
PMTDSimAccumulator::DetIdSize::column
unsigned char column() const
Definition: PMTDSimAccumulator.h:21
PMTDSimAccumulator::DetIdSize::increaseSize
void increaseSize()
Definition: PMTDSimAccumulator.h:17
PMTDSimAccumulator::PMTDSimAccumulator
PMTDSimAccumulator()=default
PMTDSimAccumulator::const_iterator::iData_
unsigned int iData_
Definition: PMTDSimAccumulator.h:135
PMTDSimAccumulator::Data::Data
Data(unsigned short ei, unsigned short si, unsigned short d)
Definition: PMTDSimAccumulator.h:38
PMTDSimAccumulator::const_iterator::const_iterator
const_iterator(const PMTDSimAccumulator *acc, unsigned int detSize, unsigned int dataSize)
Definition: PMTDSimAccumulator.h:109
PMTDSimAccumulator::cbegin
const_iterator cbegin() const
Definition: PMTDSimAccumulator.h:144
PMTDSimAccumulator::Data::dataMask
constexpr static unsigned dataMask
Definition: PMTDSimAccumulator.h:35
PMTDSimAccumulator::TmpElem::column
unsigned char column() const
Definition: PMTDSimAccumulator.h:90
PMTDSimAccumulator::cend
const_iterator cend() const
Definition: PMTDSimAccumulator.h:146
PMTDSimAccumulator::TmpElem::detId
unsigned int detId() const
Definition: PMTDSimAccumulator.h:88
PMTDSimAccumulator::TmpElem::TmpElem
TmpElem(unsigned int detId, unsigned char row, unsigned char column, Data data)
Definition: PMTDSimAccumulator.h:85
PMTDSimAccumulator::DetIdSize::detId
unsigned int detId() const
Definition: PMTDSimAccumulator.h:19
PMTDSimAccumulator::const_iterator::operator++
const_iterator operator++(int)
Definition: PMTDSimAccumulator.h:122
PMTDSimAccumulator::Data
Definition: PMTDSimAccumulator.h:30
PMTDSimAccumulator::TmpElem::energyIndex
unsigned short energyIndex() const
Definition: PMTDSimAccumulator.h:91
PMTDSimAccumulator::Data::energyIndex
unsigned int energyIndex() const
Definition: PMTDSimAccumulator.h:40
DetId.h
PMTDSimAccumulator::DetIdSize::row
unsigned char row() const
Definition: PMTDSimAccumulator.h:20
relativeConstraints.empty
bool empty
Definition: relativeConstraints.py:46
PMTDSimAccumulator::DetIdSize
Definition: PMTDSimAccumulator.h:12
PMTDSimAccumulator::Data::energyMask
constexpr static unsigned energyMask
Definition: PMTDSimAccumulator.h:33
PMTDSimAccumulator::const_iterator::endData_
unsigned int endData_
Definition: PMTDSimAccumulator.h:136
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
PMTDSimAccumulator::emplace_back
void emplace_back(unsigned int detId, unsigned char row, unsigned char column, unsigned short energyIndex, unsigned short sampleIndex, unsigned short data)
Definition: PMTDSimAccumulator.h:69
ztail.d
d
Definition: ztail.py:151
PMTDSimAccumulator::DetIdSize::DetIdSize
DetIdSize()
Definition: PMTDSimAccumulator.h:14
PMTDSimAccumulator::Data::sampleIndex
unsigned int sampleIndex() const
Definition: PMTDSimAccumulator.h:41
PMTDSimAccumulator::const_iterator::operator++
const_iterator & operator++()
Definition: PMTDSimAccumulator.h:114
PMTDSimAccumulator::TmpElem::data_
Data data_
Definition: PMTDSimAccumulator.h:97
PMTDSimAccumulator::TmpElem::detId_
unsigned int detId_
Definition: PMTDSimAccumulator.h:96
PMTDSimAccumulator::DetIdSize::size_
unsigned char size_
Definition: PMTDSimAccumulator.h:28
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
PMTDSimAccumulator::const_iterator::iDet_
unsigned int iDet_
Definition: PMTDSimAccumulator.h:134
PMTDSimAccumulator::Data::sampleMask
constexpr static unsigned sampleMask
Definition: PMTDSimAccumulator.h:34