ATLAS Offline Software
NavigableVector.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef NAVIGATION_NAVIGABLEVECTOR_H
6 #define NAVIGATION_NAVIGABLEVECTOR_H
7 // Simple container for navigable objects. //
10 
12 #include "AthLinks/ElementLink.h"
13 
15 
16 #include <vector>
17 
18 template < typename CONT, typename OBJCT=typename CONT::base_value_type >
20 {
21 public:
22 
23  // object container index type
26 
27  //
29  typedef std::vector<data_type> store_type;
30  typedef typename store_type::iterator store_iter;
31  typedef typename store_type::const_iterator store_const_iter;
33  typedef OBJCT* object_ptr;
34  typedef const OBJCT* object_const_ptr;
35 
37  { }
38 
39  virtual ~NavigableVector() = default;
40 
41  // add elements
42  void addElement(const CONT* aContainer, const OBJCT* anObject)
43  {
44  data_type aLink;
45  aLink.toContainedElement(*aContainer,(object_ptr)anObject);
46  m_store.push_back(aLink);
47  }
48 
49  void addElement(const CONT* aContainer, external_index_type anIndex)
50  {
51  data_type aLink;
52  aLink.toIndexedElement(*aContainer,anIndex);
53  m_store.push_back(aLink);
54  }
55 
56  void addElement(const data_type& aLink)
57  {
58  m_store.push_back(aLink);
59  }
60 
61  unsigned int size() const { return m_store.size(); }
62 
63  // iterator access
65  {
66  return const_iterator(m_store).begin();
67  }
69  {
70  return const_iterator(m_store).end();
71  }
72  const_iterator find(const OBJCT* anObject) const
73  {
74  return const_iterator(m_store).find(anObject);
75  }
76 
77  // operators
78  const OBJCT* operator[](int i) const
79  {
80  return i >= 0 && i < (int)m_store.size()
81  ? *(m_store[i])
82  : 0;
83  }
84  const OBJCT* operator[](size_t i) const
85  {
86  return i < m_store.size()
87  ? *(m_store[i])
88  : 0;
89  }
90 
91  // Return contained ElementLink directly.
92  const data_type& linkAt (size_t i) const
93  {
94  if (i < m_store.size())
95  return m_store[i];
96  static const data_type null;
97  return null;
98  }
99 
100  void push_back(data_type& theData)
101  {
102  m_store.push_back(theData);
103  }
104 
105 protected:
106 
108 };
109 #endif
NavigableVector::size
unsigned int size() const
Definition: NavigableVector.h:61
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
NavigableVector::store_const_iter
store_type::const_iterator store_const_iter
Definition: NavigableVector.h:31
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
NavigableVector::object_const_ptr
const OBJCT * object_const_ptr
Definition: NavigableVector.h:34
NavigableVectorIterator
Definition: NavigableVectorIterator.h:15
NavigableVector::find
const_iterator find(const OBJCT *anObject) const
Definition: NavigableVector.h:72
NavigableVector::external_index_type
SG::GenerateIndexingPolicy< CONT >::type::index_type external_index_type
Definition: NavigableVector.h:25
NavigableVector::begin
const_iterator begin() const
Definition: NavigableVector.h:64
NavigableVector::operator[]
const OBJCT * operator[](int i) const
Definition: NavigableVector.h:78
NavigableVector::addElement
void addElement(const CONT *aContainer, external_index_type anIndex)
Definition: NavigableVector.h:49
NavigableVector::data_type
ElementLink< CONT > data_type
Definition: NavigableVector.h:28
NavigableVector::object_ptr
OBJCT * object_ptr
Definition: NavigableVector.h:33
GenerateIndexingPolicy.h
lumiFormat.i
int i
Definition: lumiFormat.py:85
NavigableVector
Definition: NavigableVector.h:20
NavigableVector::m_store
store_type m_store
Definition: NavigableVector.h:107
NavigableVector::store_type
std::vector< data_type > store_type
Definition: NavigableVector.h:29
NavigableVector::operator[]
const OBJCT * operator[](size_t i) const
Definition: NavigableVector.h:84
NavigableVector::end
const_iterator end() const
Definition: NavigableVector.h:68
NavigableVector::store_iter
store_type::iterator store_iter
Definition: NavigableVector.h:30
NavigableVectorIterator.h
NavigableVector::addElement
void addElement(const CONT *aContainer, const OBJCT *anObject)
Definition: NavigableVector.h:42
NavigableVector::addElement
void addElement(const data_type &aLink)
Definition: NavigableVector.h:56
NavigableVector::const_iterator
NavigableVectorIterator< OBJCT, store_type > const_iterator
Definition: NavigableVector.h:32
NavigableVector::~NavigableVector
virtual ~NavigableVector()=default
NavigableVector::linkAt
const data_type & linkAt(size_t i) const
Definition: NavigableVector.h:92
SG::GenerateIndexingPolicy
Definition: GenerateIndexingPolicy.h:30
NavigableVector::push_back
void push_back(data_type &theData)
Definition: NavigableVector.h:100
NavigableVector::NavigableVector
NavigableVector()
Definition: NavigableVector.h:36