ATLAS Offline Software
Loading...
Searching...
No Matches
CaloClusterCellLink.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5//Dear emacs, this is -*-c++-*-
6#ifndef CALOEVENT_CALOCLUSTERCELLLINK_H
7#define CALOEVENT_CALOCLUSTERCELLLINK_H
8
9#include "AthLinks/DataLink.h"
11#include <map>
12#include <iterator>
13
21
22
23
25
26 public:
27 typedef double weight_t;
28
29 private:
30 //Typedef std::map<unsigned,weight_t> linkAndWeightCollType;
31 typedef std::vector<std::pair<unsigned, weight_t> > linkAndWeightCollType;
32
33 public:
36
41
46
47
51
57 {
58 public:
59 using iterator_category = std::bidirectional_iterator_tag;
60 using value_type = const CaloCell*;
61 using difference_type = std::ptrdiff_t;
64
65 const_iterator() = delete; //C++11
66
71 const_iterator(const CaloCellContainer* cellCont, linkAndWeightCollType::const_iterator it) :
72 m_ccc(cellCont), m_it(it) {};
73
77 const CaloCell* operator*() const {return (*m_ccc)[m_it->first];}
78 const CaloCell* operator->() const {return (*m_ccc)[m_it->first];}
79
82 weight_t weight() const {return m_it->second;}
83
86 unsigned index() const {return m_it->first;}
87
88 const_iterator operator++() {++m_it; return *this;}
89 const_iterator operator--() {--m_it; return *this;}
90 const_iterator operator++(int) {++m_it; return *this;}
91 const_iterator operator--(int) {--m_it; return *this;}
92 bool operator==(const const_iterator& b) const { return m_it==b.m_it;}
93 bool operator!=(const const_iterator& b) const { return m_it!=b.m_it;}
94
95 private:
97 linkAndWeightCollType::const_iterator m_it;
98 };//end class CaloClusterCellLink::const_iterator
99
100
103
108
113
117 size_t size() const {return m_indicesAndWeights.size();}
118
119 //Non-const interface:
120
126 {
128 public:
129 using iterator_category = std::bidirectional_iterator_tag;
130 using value_type = const CaloCell*;
131 using difference_type = std::ptrdiff_t;
134
135 iterator() = delete;
136
141 iterator(const CaloCellContainer* ccc, linkAndWeightCollType::iterator it) :
142 m_ccc(ccc), m_it(it) {};
143 const CaloCell* operator*() const {return (*m_ccc)[m_it->first];}
144 const CaloCell* operator->() const {return (*m_ccc)[m_it->first];}
147 weight_t weight() const {return m_it->second;}
148
151 unsigned index() const {return m_it->first;}
152
153 iterator operator++() {++m_it; return *this;}
154 iterator operator--() {--m_it; return *this;}
155 iterator operator++(int) {++m_it; return *this;}
156 iterator operator--(int) {--m_it; return *this;}
157 bool operator==(const iterator& b) const { return m_it==b.m_it;}
158 bool operator!=(const iterator& b) const { return m_it!=b.m_it;}
159
160 //Non-const manipulations:
164 void reweight(const weight_t newWeight) {m_it->second=newWeight;}
165
169 void reindex(const unsigned newIndex) {m_it->first=newIndex;}
170
171
172 private:
174 linkAndWeightCollType::iterator m_it;
175 };//end class CaloClusterCellLink::iterator
176
181
186
187
193 bool addCell(const unsigned cellIdx, const weight_t weight=1.0);
194
200
201
206 bool removeCell(const CaloCell* ptr);
207
208
212 const CaloCellContainer* getCellContainer() const { return m_cellCont.cptr();}
214
216 void reserve(const size_t s) { m_indicesAndWeights.reserve(s);}
217
218
220 void clear() {m_indicesAndWeights.clear();}
221
224 void toPersistent();
225
226 private:
229
230 const static linkAndWeightCollType m_dummyIndicesAndWeights; //0-size vector for dummy iterator
231
232};
233
234inline bool CaloClusterCellLink::addCell(const unsigned cellIdx, const weight_t weight) {
235
236 /* map version - with uniqueness check
237 std::pair<linkAndWeightCollType::iterator,bool> tryInsert=
238 m_indicesAndWeights.insert(std::make_pair(cellIdx,weight));
239 if (!tryInsert.second) {
240 //Cell existed before, need to overwrite
241 tryInsert.first->second=weight;
242 }
243 return !tryInsert.second;
244 */
245 m_indicesAndWeights.emplace_back(cellIdx,weight);
246 return true;
247
248}
249
250#endif
251
252
Container class for CaloCell.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57