ATLAS Offline Software
Loading...
Searching...
No Matches
AssociationVectorIterator.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifdef ASSOCIATION_CONTEXT
13
14 class AssociationVectorIterator
15 {
16 public:
17 using iterator_category = std::bidirectional_iterator_tag;
18 using value_type = asso_type*;
19 using difference_type = std::ptrdiff_t;
20 using pointer = value_type*;
21 using reference = value_type&;
22
23
31 AssociationVectorIterator(const asso_store& assoStore)
32 : m_store(&assoStore)
33 , m_actual(assoStore.begin())
34 { }
35
44 AssociationVectorIterator(const asso_store& assoStore,
45 const asso_store_iterator& pos)
46 : m_store(&assoStore)
47 , m_actual(pos)
48 { }
49
51 ~AssociationVectorIterator() { };
52
61 AssociationVectorIterator begin()
62 {
63 if ( m_store) {
64 return AssociationVectorIterator(*m_store);
65 } else {
66 throw std::runtime_error( "Null pointer to store of associations" );
67 // dead-code
68 return AssociationVectorIterator( *m_store );
69 }
70 }
71
72 AssociationVectorIterator end()
73 {
74 if ( m_store ) {
75 return AssociationVectorIterator(*m_store);
76 } else {
77 throw std::runtime_error( "Null pointer to store of associations" );
78 // dead-code
79 return AssociationVectorIterator( *m_store );
80 }
81 }
82
83 AssociationVectorIterator begin() const
84 {
85 if ( m_store) {
86 return AssociationVectorIterator(*m_store, m_store->begin());
87 } else {
88 throw std::runtime_error( "Null pointer to store of associations" );
89 // dead-code
90 return AssociationVectorIterator( *m_store );
91 }
92 }
93
94 AssociationVectorIterator end() const
95 {
96 if ( m_store ) {
97 return AssociationVectorIterator(*m_store, m_store->end());
98 } else {
99 throw std::runtime_error( "Null pointer to store of associations" );
100 }
101 }
102
103 AssociationVectorIterator next() { ++m_actual; return *this; }
104 AssociationVectorIterator prev() { --m_actual; return *this; }
105
106 AssociationVectorIterator find(const asso_type* anAsso) const
107 {
108 typename asso_store::const_iterator assoEnd = m_store->end();
109 //m_actual = m_store->begin();
110 //size_t iCtr = 0;
111 for ( typename asso_store::const_iterator itr = m_store->begin();
112 itr != assoEnd; ++itr ) {
113 if ( **itr == anAsso ) {
114 return AssociationVectorIterator( *m_store, itr );
115 }
116 }
117 return this->end();
118 }
120
123
125 AssociationVectorIterator operator++()
126 {
127 AssociationVectorIterator tmp(*this);
128 ++m_actual;
129 return tmp;
130 }
131
133 AssociationVectorIterator operator++(int) { return this->next(); }
134
136 AssociationVectorIterator operator--() { return this->prev(); }
137
139 AssociationVectorIterator operator--(int)
140 {
141 AssociationVectorIterator tmp(*this);
142 --m_actual;
143 return tmp;
144 }
145
146 // bool operator==(AssociationVectorIterator& anOther)
147 // { return m_actual == anOther.m_actual; }
148 bool operator==(const AssociationVectorIterator& anOther) const
149 { return m_actual == anOther.m_actual; }
150
151 // bool operator!=(AssociationVectorIterator& anOther)
152 // { return m_actual != anOther.m_actual; }
153 bool operator!=(const AssociationVectorIterator& anOther) const
154 { return m_actual != anOther.m_actual; }
155
157 const asso_type* operator*() const
158 {
159 return m_actual != m_store->end()
160 ? *(*m_actual)
161 : 0;
162 }
163 const asso_type* operator->() const
164 {
165 return m_actual != m_store->end()
166 ? *(*m_actual)
167 : 0;
168 }
169
170 asso_link getLink() const
171 {
172 return *m_actual;
173 }
174
175 bool isValid() const
176 {
177 return m_actual != m_store->end() && m_actual->isValid();
178 }
179
181
184 size_t size() const { return m_store->size(); }
186
187 private:
188
190 AssociationVectorIterator() :
191 m_store (0),
192 m_actual()
193 { };
194
195 private:
196
198 const asso_store* m_store;
199
201 //asso_store_iterator m_actual;
202 typename asso_store::const_iterator m_actual;
203 };
204
205#endif // ASSOCIATION_CONTEXT
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
bool operator!=(const DataVector< T > &a, const DataVector< T > &b)
Based on operator==.
bool operator==(const DataVector< T > &a, const DataVector< T > &b)
Vector equality comparison.
xAOD::MissingET_v1 operator*(const xAOD::MissingET_v1 &met, float scale)
Create new MET object from source with scaled (weighted) kinematics.
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:138
TGCHBChip operator++(TGCHBChip &rs, int)
const T * getLink(const xAOD::IParticle *, const std::string &, bool debug=false)