ATLAS Offline Software
AssociationVectorIterator.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 #ifdef ASSOCIATION_CONTEXT
6 
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  // dead-code
101  return AssociationVectorIterator( *m_store );
102  }
103  }
104 
105  AssociationVectorIterator next() { ++m_actual; return *this; }
106  AssociationVectorIterator prev() { --m_actual; return *this; }
107 
108  AssociationVectorIterator find(const asso_type* anAsso) const
109  {
110  typename asso_store::const_iterator assoEnd = m_store->end();
111  //m_actual = m_store->begin();
112  //size_t iCtr = 0;
113  for ( typename asso_store::const_iterator itr = m_store->begin();
114  itr != assoEnd; ++itr ) {
115  if ( **itr == anAsso ) {
116  return AssociationVectorIterator( *m_store, itr );
117  }
118  }
119  return this->end();
120  }
125 
127  AssociationVectorIterator operator++()
128  {
129  AssociationVectorIterator tmp(*this);
130  ++m_actual;
131  return tmp;
132  }
133 
135  AssociationVectorIterator operator++(int) { return this->next(); }
136 
138  AssociationVectorIterator operator--() { return this->prev(); }
139 
141  AssociationVectorIterator operator--(int)
142  {
143  AssociationVectorIterator tmp(*this);
144  --m_actual;
145  return tmp;
146  }
147 
148  // bool operator==(AssociationVectorIterator& anOther)
149  // { return m_actual == anOther.m_actual; }
150  bool operator==(const AssociationVectorIterator& anOther) const
151  { return m_actual == anOther.m_actual; }
152 
153  // bool operator!=(AssociationVectorIterator& anOther)
154  // { return m_actual != anOther.m_actual; }
155  bool operator!=(const AssociationVectorIterator& anOther) const
156  { return m_actual != anOther.m_actual; }
157 
159  const asso_type* operator*() const
160  {
161  return m_actual != m_store->end()
162  ? *(*m_actual)
163  : 0;
164  }
165  const asso_type* operator->() const
166  {
167  return m_actual != m_store->end()
168  ? *(*m_actual)
169  : 0;
170  }
171 
172  asso_link getLink() const
173  {
174  return *m_actual;
175  }
176 
177  bool isValid() const
178  {
179  return m_actual != m_store->end() && m_actual->isValid();
180  }
181 
186  size_t size() const { return m_store->size(); }
189  private:
190 
192  AssociationVectorIterator() :
193  m_store (0),
194  m_actual()
195  { };
196 
197  private:
198 
200  const asso_store* m_store;
201 
203  //asso_store_iterator m_actual;
204  typename asso_store::const_iterator m_actual;
205  };
206 
207 #endif // ASSOCIATION_CONTEXT
operator==
bool operator==(const DataVector< T > &a, const DataVector< T > &b)
Vector equality comparison.
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
reference
Definition: hcg.cxx:437
isValid
bool isValid(const T &p)
Definition: AtlasPID.h:214
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
InDetDD::operator*
SiLocalPosition operator*(const SiLocalPosition &position, const double factor)
Definition: SiLocalPosition.cxx:98
operator!=
bool operator!=(const DataVector< T > &a, const DataVector< T > &b)
Based on operator==.
fillPileUpNoiseLumi.next
next
Definition: fillPileUpNoiseLumi.py:52
xAOD::EgammaHelpers::getLink
const T * getLink(const xAOD::IParticle *particle, std::string name)
Access to element link to object of type T stored in auxdata.
Definition: EgammaTruthxAODHelpers.h:27
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
LVL1TGCTrigger::operator++
TGCHBChip operator++(TGCHBChip &rs, int)
Definition: TGCHighPtBoard.h:28
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
value_type
Definition: EDM_MasterSearch.h:11