|
14 | 14 | * Please consult core software group if in doubt. |
15 | 15 | **/ |
16 | 16 | namespace v1 { |
17 | | -class SiStripApproximateClusterCollection { |
18 | | -public: |
19 | | - // Helper classes to make creation and iteration easier |
20 | | - class Filler { |
| 17 | + class SiStripApproximateClusterCollection { |
21 | 18 | public: |
22 | | - void push_back(SiStripApproximateCluster_v1 const& cluster) { clusters_.push_back(cluster); } |
| 19 | + // Helper classes to make creation and iteration easier |
| 20 | + class Filler { |
| 21 | + public: |
| 22 | + void push_back(SiStripApproximateCluster_v1 const& cluster) { clusters_.push_back(cluster); } |
23 | 23 |
|
24 | | - private: |
25 | | - friend SiStripApproximateClusterCollection; |
26 | | - Filler(std::vector<SiStripApproximateCluster_v1>& clusters) : clusters_(clusters) {} |
| 24 | + private: |
| 25 | + friend SiStripApproximateClusterCollection; |
| 26 | + Filler(std::vector<SiStripApproximateCluster_v1>& clusters) : clusters_(clusters) {} |
27 | 27 |
|
28 | | - std::vector<SiStripApproximateCluster_v1>& clusters_; |
29 | | - }; |
| 28 | + std::vector<SiStripApproximateCluster_v1>& clusters_; |
| 29 | + }; |
30 | 30 |
|
31 | | - class const_iterator; |
32 | | - class DetSet { |
33 | | - public: |
34 | | - using const_iterator = std::vector<SiStripApproximateCluster_v1>::const_iterator; |
| 31 | + class const_iterator; |
| 32 | + class DetSet { |
| 33 | + public: |
| 34 | + using const_iterator = std::vector<SiStripApproximateCluster_v1>::const_iterator; |
35 | 35 |
|
36 | | - unsigned int id() const { return std::accumulate(coll_->detIds_.cbegin(), coll_->detIds_.cbegin()+detIndex_+1, 0); } |
| 36 | + unsigned int id() const { |
| 37 | + return std::accumulate(coll_->detIds_.cbegin(), coll_->detIds_.cbegin() + detIndex_ + 1, 0); |
| 38 | + } |
37 | 39 |
|
38 | | - void move(unsigned int clusBegin) const { clusBegin_ = clusBegin; } |
39 | | - const_iterator begin() const { return coll_->clusters_.begin() + clusBegin_; } |
40 | | - const_iterator cbegin() const { return begin(); } |
41 | | - const_iterator end() const { return coll_->clusters_.begin() + clusEnd_; } |
42 | | - const_iterator cend() const { return end(); } |
| 40 | + void move(unsigned int clusBegin) const { clusBegin_ = clusBegin; } |
| 41 | + const_iterator begin() const { return coll_->clusters_.begin() + clusBegin_; } |
| 42 | + const_iterator cbegin() const { return begin(); } |
| 43 | + const_iterator end() const { return coll_->clusters_.begin() + clusEnd_; } |
| 44 | + const_iterator cend() const { return end(); } |
| 45 | + |
| 46 | + private: |
| 47 | + friend SiStripApproximateClusterCollection::const_iterator; |
| 48 | + DetSet(SiStripApproximateClusterCollection const* coll, unsigned int detIndex) |
| 49 | + : coll_(coll), detIndex_(detIndex), clusEnd_(coll->clusters_.size()) {} |
| 50 | + |
| 51 | + SiStripApproximateClusterCollection const* const coll_; |
| 52 | + unsigned int const detIndex_; |
| 53 | + mutable unsigned int clusBegin_ = 0; |
| 54 | + unsigned int const clusEnd_; |
| 55 | + }; |
| 56 | + |
| 57 | + class const_iterator { |
| 58 | + public: |
| 59 | + DetSet operator*() const { return DetSet(coll_, index_); } |
| 60 | + |
| 61 | + const_iterator& operator++() { |
| 62 | + ++index_; |
| 63 | + if (index_ == coll_->detIds_.size()) { |
| 64 | + *this = const_iterator(); |
| 65 | + } |
| 66 | + return *this; |
| 67 | + } |
43 | 68 |
|
44 | | - private: |
45 | | - friend SiStripApproximateClusterCollection::const_iterator; |
46 | | - DetSet(SiStripApproximateClusterCollection const* coll, unsigned int detIndex) |
47 | | - : coll_(coll), |
48 | | - detIndex_(detIndex), |
49 | | - clusEnd_(coll->clusters_.size()) |
50 | | - {} |
51 | | - |
52 | | - SiStripApproximateClusterCollection const* const coll_; |
53 | | - unsigned int const detIndex_; |
54 | | - mutable unsigned int clusBegin_ = 0; |
55 | | - unsigned int const clusEnd_; |
56 | | - }; |
| 69 | + const_iterator operator++(int) { |
| 70 | + const_iterator clone = *this; |
| 71 | + ++(*this); |
| 72 | + return clone; |
| 73 | + } |
57 | 74 |
|
58 | | - class const_iterator { |
59 | | - public: |
60 | | - DetSet operator*() const { return DetSet(coll_, index_); } |
| 75 | + bool operator==(const_iterator const& other) const { return coll_ == other.coll_ and index_ == other.index_; } |
| 76 | + bool operator!=(const_iterator const& other) const { return not operator==(other); } |
61 | 77 |
|
62 | | - const_iterator& operator++() { |
63 | | - ++index_; |
64 | | - if (index_ == coll_->detIds_.size()) { |
65 | | - *this = const_iterator(); |
66 | | - } |
67 | | - return *this; |
68 | | - } |
| 78 | + private: |
| 79 | + friend SiStripApproximateClusterCollection; |
| 80 | + // default-constructed object acts as the sentinel |
| 81 | + const_iterator() = default; |
| 82 | + const_iterator(SiStripApproximateClusterCollection const* coll) : coll_(coll) {} |
69 | 83 |
|
70 | | - const_iterator operator++(int) { |
71 | | - const_iterator clone = *this; |
72 | | - ++(*this); |
73 | | - return clone; |
74 | | - } |
| 84 | + SiStripApproximateClusterCollection const* coll_ = nullptr; |
| 85 | + unsigned int index_ = 0; |
| 86 | + }; |
75 | 87 |
|
76 | | - bool operator==(const_iterator const& other) const { return coll_ == other.coll_ and index_ == other.index_; } |
77 | | - bool operator!=(const_iterator const& other) const { return not operator==(other); } |
| 88 | + // Actual public interface |
| 89 | + SiStripApproximateClusterCollection() = default; |
78 | 90 |
|
79 | | - private: |
80 | | - friend SiStripApproximateClusterCollection; |
81 | | - // default-constructed object acts as the sentinel |
82 | | - const_iterator() = default; |
83 | | - const_iterator(SiStripApproximateClusterCollection const* coll) : coll_(coll) {} |
| 91 | + void reserve(std::size_t dets, std::size_t clusters); |
| 92 | + Filler beginDet(unsigned int detId); |
84 | 93 |
|
85 | | - SiStripApproximateClusterCollection const* coll_ = nullptr; |
86 | | - unsigned int index_ = 0; |
87 | | - }; |
| 94 | + const_iterator begin() const { return clusters_.empty() ? end() : const_iterator(this); } |
| 95 | + const_iterator cbegin() const { return begin(); } |
| 96 | + const_iterator end() const { return const_iterator(); } |
| 97 | + const_iterator cend() const { return end(); } |
88 | 98 |
|
89 | | - // Actual public interface |
90 | | - SiStripApproximateClusterCollection() = default; |
91 | | - |
92 | | - void reserve(std::size_t dets, std::size_t clusters); |
93 | | - Filler beginDet(unsigned int detId); |
94 | | - |
95 | | - const_iterator begin() const { return clusters_.empty() ? end() : const_iterator(this); } |
96 | | - const_iterator cbegin() const { return begin(); } |
97 | | - const_iterator end() const { return const_iterator(); } |
98 | | - const_iterator cend() const { return end(); } |
99 | | - |
100 | | -private: |
101 | | - // The detIds_ and beginIndices_ have one element for each Det. An |
102 | | - // element of beginIndices_ points to the first cluster of the Det |
103 | | - // in clusters_. |
104 | | - std::vector<unsigned int> detIds_; // DetId for the Det |
105 | | - std::vector<SiStripApproximateCluster_v1> clusters_; |
106 | | -}; |
107 | | -} |
| 99 | + private: |
| 100 | + // The detIds_ and beginIndices_ have one element for each Det. An |
| 101 | + // element of beginIndices_ points to the first cluster of the Det |
| 102 | + // in clusters_. |
| 103 | + std::vector<unsigned int> detIds_; // DetId for the Det |
| 104 | + std::vector<SiStripApproximateCluster_v1> clusters_; |
| 105 | + }; |
| 106 | +} // namespace v1 |
108 | 107 | #endif |
0 commit comments