CMS 3D CMS Logo

PHGCSimAccumulator.h
Go to the documentation of this file.
1 #ifndef DataFormats_HGCalDigis_PHGCSimAccumulator_h
2 #define DataFormats_HGCalDigis_PHGCSimAccumulator_h
3 
5 #include <iostream>
6 #include <vector>
7 
9 public:
10  class DetIdSize {
11  public:
12  DetIdSize() {}
13  DetIdSize(unsigned int detId) : detId_(detId) {}
14  void increaseSize() { ++size_; }
15  unsigned int detId() const { return detId_; }
16  unsigned int size() const { return size_; }
17 
18  private:
19  unsigned int detId_ = 0;
20  unsigned char size_ = 0;
21  };
22 
24  public:
25  constexpr static unsigned energyOffset = 15;
26  constexpr static unsigned energyMask = 0x1;
27  constexpr static unsigned sampleOffset = 11;
28  constexpr static unsigned sampleMask = 0xf;
29  constexpr static unsigned dataOffset = 0;
30  constexpr static unsigned dataMask = 0x7ff;
31 
33  SimHitCollection(unsigned int nhits) : nhits_(nhits) {}
34  SimHitCollection(const unsigned short si,
35  const std::vector<unsigned short>& accCharge,
36  const std::vector<unsigned short>& time)
37  : nhits_(accCharge.size()) {
38  chargeArray_.reserve(nhits_);
39  timeArray_.reserve(nhits_);
40  for (size_t i = 0; i < nhits_; ++i) {
41  unsigned short ei = 0;
42  unsigned short d = accCharge[i];
43  unsigned short data = ((ei << energyOffset) | (si << sampleOffset) | d);
44  chargeArray_.emplace_back(data);
45  }
46  for (size_t i = 0; i < nhits_; ++i) {
47  unsigned short ei = 1;
48  unsigned short d = time[i];
49  unsigned short data = ((ei << energyOffset) | (si << sampleOffset) | d);
50  timeArray_.emplace_back(data);
51  }
52  }
53  SimHitCollection(const SimHitCollection& simhitcollection) = default;
54  unsigned int nhits() const { return nhits_; }
55  unsigned int sampleIndex() const { return (chargeArray_[0] >> sampleOffset) & sampleMask; }
56  const std::vector<unsigned short>& chargeArray() const { return chargeArray_; }
57  const std::vector<unsigned short>& timeArray() const { return timeArray_; }
58 
59  private:
60  unsigned int nhits_;
61  std::vector<unsigned short> chargeArray_;
62  std::vector<unsigned short> timeArray_;
63  };
64 
65  PHGCSimAccumulator() = default;
66  ~PHGCSimAccumulator() = default;
67 
68  void reserve(size_t size) {
69  detIdSize_.reserve(size);
70  simhitCollection_.reserve(size);
71  }
72  void shrink_to_fit() {
73  detIdSize_.shrink_to_fit();
74  simhitCollection_.shrink_to_fit();
75  }
76 
77  void emplace_back(unsigned int detId,
78  unsigned short sampleIndex,
79  const std::vector<unsigned short>& accCharge,
80  const std::vector<unsigned short>& timing) {
81  if (detIdSize_.empty() || detIdSize_.back().detId() != detId) {
82  detIdSize_.emplace_back(detId);
83  }
84  simhitCollection_.emplace_back(sampleIndex, accCharge, timing);
85  detIdSize_.back().increaseSize();
86  }
87 
88  class TmpElem {
89  public:
90  TmpElem(const unsigned int detId, const SimHitCollection& simhitCollection)
91  : detId_(detId), simhitcollection_(simhitCollection) {}
92 
93  unsigned int detId() const { return detId_; }
94  unsigned short sampleIndex() const { return simhitcollection_.sampleIndex(); }
95  unsigned int nhits() const { return simhitcollection_.nhits(); }
96  const std::vector<unsigned short> chargeArray() const { return simhitcollection_.chargeArray(); }
97  const std::vector<unsigned short> timeArray() const { return simhitcollection_.timeArray(); }
98 
99  private:
100  unsigned int detId_;
102  };
103 
105  public:
106  // begin
108  : ncc_(ncc), iDet_(0), iData_(0), endData_(ncc->detIdSize_.empty() ? 0 : ncc->detIdSize_.front().size()) {}
109  // end
110  const_iterator(const PHGCSimAccumulator* ncc, unsigned int detSize, unsigned int dataSize)
111  : ncc_(ncc), iDet_(detSize), iData_(dataSize), endData_(0) {}
112 
113  bool operator==(const const_iterator& other) const { return iDet_ == other.iDet_ && iData_ == other.iData_; }
114  bool operator!=(const const_iterator& other) const { return !operator==(other); }
116  ++iData_;
117  if (iData_ == endData_) {
118  ++iDet_;
119  endData_ += (iDet_ == ncc_->detIdSize_.size()) ? 0 : ncc_->detIdSize_[iDet_].size();
120  }
121  return *this;
122  }
124  auto tmp = *this;
125  ++(*this);
126  return tmp;
127  }
128 
130 
131  private:
133  unsigned int iDet_;
134  unsigned int iData_;
135  unsigned int endData_;
136  };
137 
138  TmpElem back() const { return TmpElem(detIdSize_.back().detId(), simhitCollection_.back()); }
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(), simhitCollection_.size()); }
143  const_iterator end() const { return cend(); }
144 
145 private:
146  std::vector<DetIdSize> detIdSize_;
147  std::vector<SimHitCollection> simhitCollection_;
148 };
149 
150 #endif
size
Write out results.
void emplace_back(unsigned int detId, unsigned short sampleIndex, const std::vector< unsigned short > &accCharge, const std::vector< unsigned short > &timing)
const_iterator end() const
TmpElem(const unsigned int detId, const SimHitCollection &simhitCollection)
const std::vector< unsigned short > timeArray() const
SimHitCollection(const unsigned short si, const std::vector< unsigned short > &accCharge, const std::vector< unsigned short > &time)
const std::vector< unsigned short > & timeArray() const
const_iterator cend() const
static constexpr unsigned dataMask
std::vector< unsigned short > timeArray_
bool operator==(const const_iterator &other) const
unsigned short sampleIndex() const
const_iterator begin() const
static constexpr unsigned energyOffset
static constexpr unsigned sampleOffset
std::vector< SimHitCollection > simhitCollection_
const_iterator(const PHGCSimAccumulator *ncc)
~PHGCSimAccumulator()=default
static constexpr unsigned dataOffset
const std::vector< unsigned short > chargeArray() const
PHGCSimAccumulator()=default
const_iterator(const PHGCSimAccumulator *ncc, unsigned int detSize, unsigned int dataSize)
d
Definition: ztail.py:151
const_iterator cbegin() const
const std::vector< unsigned short > & chargeArray() const
unsigned int nhits() const
void reserve(size_t size)
unsigned int detId() const
std::vector< DetIdSize > detIdSize_
bool operator!=(const const_iterator &other) const
std::vector< unsigned short > chargeArray_
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
TmpElem back() const
const PHGCSimAccumulator * ncc_
tmp
align.sh
Definition: createJobs.py:716
static constexpr unsigned energyMask
static constexpr unsigned sampleMask