ATLAS Offline Software
CaloCellPrefetchIterator.icc
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 
3 /*
4  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5 */
6 
7 // $Id: CaloCellPrefetchIterator.icc,v 1.2 2008-08-02 14:57:07 ssnyder Exp $
8 
9 /**
10  * @file CaloEvent/CaloCellPrefetchIterator.icc
11  * @author scott snyder
12  * @date Aug 2008
13  * @brief To iterate over @c CaloCell's, prefetching the detector description.
14  */
15 
16 
17 //****************************************************************************
18 
19 
20 namespace CaloEvent_detail {
21 
22 
23 /**
24  * @brief Return the current parameter (will always be 1).
25  */
26 template <class T, class TAG>
27 inline
28 typename paramholder<T, TAG>::param_t
29 paramholder<T, TAG>::getParameter() const
30 {
31  return 1;
32 }
33 
34 
35 /**
36  * @brief Move to the next weight (a no-op).
37  */
38 template <class T, class TAG>
39 inline
40 void paramholder<T, TAG>::next()
41 {
42 }
43 
44 
45 /**
46  * @brief Fetch the next weight from the iterator (a no-op).
47  */
48 template <class T, class TAG>
49 inline
50 void paramholder<T, TAG>::fetch (const T& /*it*/)
51 {
52 }
53 
54 
55 /**
56  * @brief Return the current parameter.
57  */
58 template <class T>
59 inline
60 typename paramholder<T, NavigationTokenIteratorTag>::param_t
61 paramholder<T, NavigationTokenIteratorTag>::getParameter() const
62 {
63  return m_param;
64 }
65 
66 
67 /**
68  * @brief Move to the next weight.
69  */
70 template <class T>
71 inline
72 void paramholder<T, NavigationTokenIteratorTag>::next()
73 {
74  m_param = m_next_param;
75 }
76 
77 
78 /**
79  * @brief Fetch the next weight from the iterator.
80  */
81 template <class T>
82 inline
83 void paramholder<T, NavigationTokenIteratorTag>::fetch (const T& it)
84 {
85  m_next_param = it.getParameter();
86 }
87 
88 
89 } // namespace CaloEvent_detail
90 
91 
92 //****************************************************************************
93 
94 
95 /**
96  * @brief Constructor.
97  * @param begin Underlying begin iterator.
98  * @param end Underlying end iterator.
99  */
100 template <class T>
101 CaloCellPrefetchIterator<T>::CaloCellPrefetchIterator
102  (const base_iterator& begin,
103  const base_iterator& end)
104 
105  : m_it (begin),
106  m_end (end)
107 {
108  init();
109 }
110 
111 
112 /**
113  * @brief Constructor, from a container.
114  * @param cont Container over which to iterate.
115  */
116 template <class T>
117 template <class CONTAINER>
118 CaloCellPrefetchIterator<T>::CaloCellPrefetchIterator
119  (const CONTAINER& cont)
120  : m_it (cont.begin()),
121  m_end (cont.end())
122 {
123  init();
124 }
125 
126 
127 /**
128  * @brief Move to the next element.
129  *
130  * Returns true if more elements, false otherwise.
131  * This should be called before processing the first element.
132  */
133 template <class T>
134 inline
135 bool CaloCellPrefetchIterator<T>::next()
136 {
137  // Are we at the end (use the saved result of the comparison).
138  if (!m_next_cellp)
139  return false;
140 
141  // Move to the next cell/weight.
142  m_cellp = m_next_cellp;
143  paramholder::next ();
144 
145  // Is the iterator (now pointing at the next element) at the end?
146  if (m_it != m_end) {
147  // No, fetch the contents of the next element.
148  m_next_cellp = *m_it;
149  paramholder::fetch (m_it);
150  // And prefetch the DDE.
151  __builtin_prefetch (m_next_cellp->caloDDE());
152  // Bump the iterator.
153  ++m_it;
154  }
155  else {
156  // This is the last element. Remember that for next time.
157  m_next_cellp = 0;
158  }
159 
160  // Keep going.
161  return true;
162 }
163 
164 
165 /**
166  * @brief Dereference the iterator.
167  */
168 template <class T>
169 inline
170 const CaloCell* CaloCellPrefetchIterator<T>::operator*() const
171 {
172  return m_cellp;
173 }
174 
175 
176 /**
177  * @brief Initialize before first use.
178  */
179 template <class T>
180 void CaloCellPrefetchIterator<T>::init()
181 {
182  m_cellp = 0;
183  if (m_it != m_end) {
184  m_next_cellp = *m_it;
185  paramholder::fetch (m_it);
186  ++m_it;
187  }
188  else
189  m_next_cellp = 0;
190 }
191 
192 
193