ATLAS Offline Software
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 */
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.
24 template <class T>
26 
27 
28 namespace CaloEvent_detail {
29 
30 
51 template <class T, class TAG>
53 {
55  typedef int param_t;
56 
59 
60 
61 private:
62  friend class CaloCellPrefetchIterator<T>;
63 
65  void next ();
66 
68  void fetch (const T& it);
69 };
70 
71 
75 template <class T>
77 {
79  typedef typename T::tokenParameter param_t;
80 
83 
84 
85 private:
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  */
157 template <class T>
159  : public CaloEvent_detail::paramholder<T, typename T::iterator_category>
160 {
161 public:
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;
168  using pointer = value_type*;
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 
211 private:
213  void init();
214 
217 
220 
223 
226 };
227 
228 
230 
231 
232 #endif // not CALOEVENT_CALOCELLPREFETCHITERATOR_H
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::m_param
param_t m_param
The current parameter.
Definition: CaloCellPrefetchIterator.h:95
CaloCellPrefetchIterator::CaloCellPrefetchIterator
CaloCellPrefetchIterator(const CONTAINER &cont)
Constructor, from a container.
CaloCellPrefetchIterator::paramholder
CaloEvent_detail::paramholder< T, typename T::iterator_category > paramholder
The base paramholder class.
Definition: CaloCellPrefetchIterator.h:173
NavigationTokenIteratorTag
Definition: NavigationToken.h:43
NavigationToken.h
CaloCellPrefetchIterator
Definition: CaloCellPrefetchIterator.h:25
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:423
CaloCellPrefetchIterator::m_it
T m_it
Current iterator. Points at the next element.
Definition: CaloCellPrefetchIterator.h:222
CaloCell.h
CaloCellPrefetchIterator::operator*
const CaloCell * operator*() const
Dereference the iterator.
CaloEvent_detail::paramholder
Interface to NavigableToken weights.
Definition: CaloCellPrefetchIterator.h:53
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::fetch
void fetch(const T &it)
Fetch the next weight from the iterator (a no-op).
CaloCellPrefetchIterator::next
bool next()
Move to the next element.
CaloCellPrefetchIterator.icc
CaloEvent_detail::paramholder::next
void next()
Move to the next weight (a no-op).
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::param_t
T::tokenParameter param_t
Type for the parameter (from the token iterator).
Definition: CaloCellPrefetchIterator.h:79
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::getParameter
param_t getParameter() const
Return the current parameter.
CaloCellPrefetchIterator::m_end
T m_end
End iterator.
Definition: CaloCellPrefetchIterator.h:225
CaloCellPrefetchIterator::m_cellp
const CaloCell * m_cellp
Current cell pointer.
Definition: CaloCellPrefetchIterator.h:216
CaloCellPrefetchIterator::CaloCellPrefetchIterator
CaloCellPrefetchIterator(const base_iterator &begin, const base_iterator &end)
Constructor.
CaloCellPrefetchIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: CaloCellPrefetchIterator.h:165
CaloCellPrefetchIterator::init
void init()
Initialize before first use.
CaloEvent_detail::paramholder::getParameter
param_t getParameter() const
Return the current parameter (will always be 1).
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::next
void next()
Move to the next weight.
CaloCellPrefetchIterator::base_iterator
T base_iterator
The base iterator, on which we're templated.
Definition: CaloCellPrefetchIterator.h:163
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::m_next_param
param_t m_next_param
The next parameter.
Definition: CaloCellPrefetchIterator.h:98
CaloCellPrefetchIterator::m_next_cellp
const CaloCell * m_next_cellp
Next cell pointer.
Definition: CaloCellPrefetchIterator.h:219
CaloCell
Data object for each calorimeter readout cell.
Definition: CaloCell.h:57
CaloCellPrefetchIterator::difference_type
std::ptrdiff_t difference_type
Definition: CaloCellPrefetchIterator.h:167
CaloEvent_detail::paramholder::fetch
void fetch(const T &it)
Fetch the next weight from the iterator (a no-op).
CaloEvent_detail::paramholder::param_t
int param_t
Type for the parameter (a dummy here).
Definition: CaloCellPrefetchIterator.h:55
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
CaloEvent_detail
Definition: CaloCellPrefetchIterator.h:28