CMS 3D CMS Logo

SiStripApproximateClusterCollection.h
Go to the documentation of this file.
1 #ifndef DataFormats_SiStripCluster_SiStripApproximateClusterCollection_h
2 #define DataFormats_SiStripCluster_SiStripApproximateClusterCollection_h
3 
4 #include <vector>
5 
7 
16 public:
17  // Helper classes to make creation and iteration easier
18  class Filler {
19  public:
20  void push_back(SiStripApproximateCluster const& cluster) { clusters_.push_back(cluster); }
21 
22  private:
24  Filler(std::vector<SiStripApproximateCluster>& clusters) : clusters_(clusters) {}
25 
26  std::vector<SiStripApproximateCluster>& clusters_;
27  };
28 
29  class const_iterator;
30  class DetSet {
31  public:
32  using const_iterator = std::vector<SiStripApproximateCluster>::const_iterator;
33 
34  unsigned int id() const { return coll_->detIds_[detIndex_]; }
35 
36  const_iterator begin() const { return coll_->clusters_.begin() + clusBegin_; }
37  const_iterator cbegin() const { return begin(); }
38  const_iterator end() const { return coll_->clusters_.begin() + clusEnd_; }
39  const_iterator cend() const { return end(); }
40 
41  private:
43  DetSet(SiStripApproximateClusterCollection const* coll, unsigned int detIndex)
44  : coll_(coll),
45  detIndex_(detIndex),
46  clusBegin_(coll_->beginIndices_[detIndex]),
47  clusEnd_(detIndex == coll_->beginIndices_.size() - 1 ? coll->clusters_.size()
48  : coll_->beginIndices_[detIndex + 1]) {}
49 
51  unsigned int const detIndex_;
52  unsigned int const clusBegin_;
53  unsigned int const clusEnd_;
54  };
55 
57  public:
58  DetSet operator*() const { return DetSet(coll_, index_); }
59 
61  ++index_;
62  if (index_ == coll_->detIds_.size()) {
63  *this = const_iterator();
64  }
65  return *this;
66  }
67 
69  const_iterator clone = *this;
70  ++(*this);
71  return clone;
72  }
73 
74  bool operator==(const_iterator const& other) const { return coll_ == other.coll_ and index_ == other.index_; }
75  bool operator!=(const_iterator const& other) const { return not operator==(other); }
76 
77  private:
79  // default-constructed object acts as the sentinel
80  const_iterator() = default;
82 
84  unsigned int index_ = 0;
85  };
86 
87  // Actual public interface
89 
90  void reserve(std::size_t dets, std::size_t clusters);
91  Filler beginDet(unsigned int detId);
92 
93  const_iterator begin() const { return clusters_.empty() ? end() : const_iterator(this); }
94  const_iterator cbegin() const { return begin(); }
95  const_iterator end() const { return const_iterator(); }
96  const_iterator cend() const { return end(); }
97 
98 private:
99  // The detIds_ and beginIndices_ have one element for each Det. An
100  // element of beginIndices_ points to the first cluster of the Det
101  // in clusters_.
102  std::vector<unsigned int> detIds_; // DetId for the Det
103  std::vector<unsigned int> beginIndices_;
104  std::vector<SiStripApproximateCluster> clusters_;
105 };
106 
107 #endif
size
Write out results.
void reserve(std::size_t dets, std::size_t clusters)
SiStripApproximateClusterCollection const *const coll_
std::vector< SiStripApproximateCluster >::const_iterator const_iterator
const_iterator(SiStripApproximateClusterCollection const *coll)
Filler(std::vector< SiStripApproximateCluster > &clusters)
void push_back(SiStripApproximateCluster const &cluster)
edmNew::DetSet< TTStub< Ref_Phase2TrackerDigi_ > > DetSet
Definition: Stub.h:28
DetSet(SiStripApproximateClusterCollection const *coll, unsigned int detIndex)
std::vector< SiStripApproximateCluster > clusters_
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
std::vector< SiStripApproximateCluster > & clusters_