ATLAS Offline Software
Loading...
Searching...
No Matches
CaloCellPrefetchIterator.h
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-2022 CERN for the benefit of the ATLAS collaboration
5*/
12
13
14#ifndef CALOEVENT_CALOCELLPREFETCHITERATOR_H
15#define CALOEVENT_CALOCELLPREFETCHITERATOR_H
16
17
18#include "CaloEvent/CaloCell.h"
20#include <iterator>
21
22
23// Forward declaration.
24template <class T>
26
27
29
30
51template <class T, class TAG>
53{
55 typedef int param_t;
56
59
60
61private:
62 friend class CaloCellPrefetchIterator<T>;
63
65 void next ();
66
68 void fetch (const T& it);
69};
70
71
75template <class T>
77{
79 typedef typename T::tokenParameter param_t;
80
83
84
85private:
86 friend class CaloCellPrefetchIterator<T>;
87
89 void next ();
90
92 void fetch (const T& it);
93
96
99};
100
101
102} // namespace CaloEvent_detail
103
104
105
106/*
107 * @brief To iterate over @a CaloCell's, prefetching the detector description.
108 *
109 * A typical use of @a CaloCell's is to iterate over a container of them;
110 * for each cell, we then call methods on the detector descriptor element
111 * for that cell. It will often be the case, though, that the DDE data
112 * are not in cache when first accessed. This will show up in profiles
113 * as the first DDE accessor method taking much longer than subsequent ones.
114 *
115 * A way to mitigate this is to use the prefetch feature of the x86 CPUs.
116 * At the start of the loop, we look ahead at the next cell to be processed
117 * and issue a prefetch for its DDE. The prefetch itself won't stall, and
118 * when we come around to the next iteration of the loop, it is likely
119 * that the DDE data are now in cache.
120 *
121 * Here is an example of how to use this:
122 *
123 *@code
124 CONTAINER container = ...;
125 CaloCellPrefetchIterator<CONTAINER::const_iterator> it
126 (container.begin(), container.end());
127 while (it.next()) {
128 const CaloCell* cellp = *it;
129 }
130 @endcode
131 *
132 * If the container is a @a NavigableToken, you can also get the parameter
133 * with <code>it.getParameter()</code>.
134 *
135 * As a convenience, you can also say
136 *
137 *@code
138 CaloCellPrefetchIterator<CONTAINER::const_iterator> it (container);
139 @endcode
140 *
141 * Note that there must be no null pointers in the collection.
142 *
143 * Also note that the prefetch instructions won't actually be generated
144 * unless -msse is used during compilation. (This is for x86; other
145 * architectures may require other switches.)
146 *
147 * (Originally, the intention was to make this be a STL-style iterator
148 * so that it could be a drop-in replacement. It proved impractical
149 * to do it that way and have it also be efficient and robust.)
150 *
151 * Because iterators may be heavy-weight (such as for
152 * @c NavigableTokenIterator), we keep only the current and end
153 * iterators here. We separately cache the cell pointers (and weights)
154 * for the current and next elements. We're careful to only
155 * do the iterator comparison once per loop.
156 */
157template <class T>
159 : public CaloEvent_detail::paramholder<T, typename T::iterator_category>
160{
161public:
163 typedef T base_iterator;
164
165 using iterator_category = std::forward_iterator_tag;
166 using value_type = const CaloCell*;
167 using difference_type = std::ptrdiff_t;
170
174
175
182 const base_iterator& end);
183
184
189 template <class CONTAINER>
190 CaloCellPrefetchIterator (const CONTAINER& cont);
191
192
199 bool next();
200
201
205 const CaloCell* operator*() const;
206
209
210
211private:
213 void init();
214
217
220
223
226};
227
228
230
231
232#endif // not CALOEVENT_CALOCELLPREFETCHITERATOR_H
bool next()
Move to the next element.
const CaloCell * m_cellp
Current cell pointer.
std::forward_iterator_tag iterator_category
CaloEvent_detail::paramholder< T, typename T::iterator_category > paramholder
The base paramholder class.
const CaloCell * m_next_cellp
Next cell pointer.
T base_iterator
The base iterator, on which we're templated.
CaloCellPrefetchIterator(const CONTAINER &cont)
Constructor, from a container.
T m_it
Current iterator. Points at the next element.
CaloCellPrefetchIterator(const base_iterator &begin, const base_iterator &end)
Constructor.
void init()
Initialize before first use.
const CaloCell * operator*() const
Dereference the iterator.
Data object for each calorimeter readout cell.
Definition CaloCell.h:57
void fetch(const T &it)
Fetch the next weight from the iterator (a no-op).
T::tokenParameter param_t
Type for the parameter (from the token iterator).
Interface to NavigableToken weights.
param_t getParameter() const
Return the current parameter (will always be 1).
void fetch(const T &it)
Fetch the next weight from the iterator (a no-op).
int param_t
Type for the parameter (a dummy here).
void next()
Move to the next weight (a no-op).