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  unsigned int nhits() const { return nhits_; }
54  unsigned int sampleIndex() const { return (chargeArray_[0] >> sampleOffset) & sampleMask; }
55  const std::vector<unsigned short>& chargeArray() const { return chargeArray_; }
56  const std::vector<unsigned short>& timeArray() const { return timeArray_; }
57 
58  private:
59  unsigned int nhits_;
60  std::vector<unsigned short> chargeArray_;
61  std::vector<unsigned short> timeArray_;
62  };
63 
64  PHGCSimAccumulator() = default;
65  ~PHGCSimAccumulator() = default;
66 
67  void reserve(size_t size) {
68  detIdSize_.reserve(size);
69  simhitCollection_.reserve(size);
70  }
71  void shrink_to_fit() {
72  detIdSize_.shrink_to_fit();
73  simhitCollection_.shrink_to_fit();
74  }
75 
76  void emplace_back(unsigned int detId,
77  unsigned short sampleIndex,
78  const std::vector<unsigned short>& accCharge,
79  const std::vector<unsigned short>& timing) {
80  if (detIdSize_.empty() || detIdSize_.back().detId() != detId) {
81  detIdSize_.emplace_back(detId);
82  }
83  simhitCollection_.emplace_back(sampleIndex, accCharge, timing);
84  detIdSize_.back().increaseSize();
85  }
86 
87  class TmpElem {
88  public:
89  TmpElem(const unsigned int detId, const SimHitCollection& simhitCollection)
90  : detId_(detId), simhitcollection_(simhitCollection) {}
91 
92  unsigned int detId() const { return detId_; }
93  unsigned short sampleIndex() const { return simhitcollection_.sampleIndex(); }
94  unsigned int nhits() const { return simhitcollection_.nhits(); }
95  const std::vector<unsigned short> chargeArray() const { return simhitcollection_.chargeArray(); }
96  const std::vector<unsigned short> timeArray() const { return simhitcollection_.timeArray(); }
97 
98  private:
99  unsigned int detId_;
101  };
102 
104  public:
105  // begin
107  : ncc_(ncc), iDet_(0), iData_(0), endData_(ncc->detIdSize_.empty() ? 0 : ncc->detIdSize_.front().size()) {}
108  // end
109  const_iterator(const PHGCSimAccumulator* ncc, unsigned int detSize, unsigned int dataSize)
110  : ncc_(ncc), 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_ == ncc_->detIdSize_.size()) ? 0 : ncc_->detIdSize_[iDet_].size();
119  }
120  return *this;
121  }
123  auto tmp = *this;
124  ++(*this);
125  return tmp;
126  }
127 
129 
130  private:
132  unsigned int iDet_;
133  unsigned int iData_;
134  unsigned int endData_;
135  };
136 
137  TmpElem back() const { return TmpElem(detIdSize_.back().detId(), simhitCollection_.back()); }
138 
139  const_iterator cbegin() const { return const_iterator(this); }
140  const_iterator begin() const { return cbegin(); }
141  const_iterator cend() const { return const_iterator(this, detIdSize_.size(), simhitCollection_.size()); }
142  const_iterator end() const { return cend(); }
143 
144 private:
145  std::vector<DetIdSize> detIdSize_;
146  std::vector<SimHitCollection> simhitCollection_;
147 };
148 
149 #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