ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Calorimeter
CaloEvent
CaloEvent
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
"
19
#include "
Navigation/NavigationToken.h
"
20
#include <iterator>
21
22
23
// Forward declaration.
24
template
<
class
T>
25
class
CaloCellPrefetchIterator
;
26
27
28
namespace
CaloEvent_detail
{
29
30
51
template
<
class
T,
class
TAG>
52
struct
paramholder
53
{
55
typedef
int
param_t
;
56
58
param_t
getParameter
()
const
;
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>
76
struct
paramholder
<T,
NavigationTokenIteratorTag
>
77
{
79
typedef
typename
T::tokenParameter
param_t
;
80
82
param_t
getParameter
()
const
;
83
84
85
private
:
86
friend
class
CaloCellPrefetchIterator
<T>;
87
89
void
next
();
90
92
void
fetch
(
const
T& it);
93
95
param_t
m_param
;
96
98
param_t
m_next_param
;
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>
158
class
CaloCellPrefetchIterator
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
*;
169
using
reference
=
value_type
&;
170
172
typedef
CaloEvent_detail::paramholder<T, typename T::iterator_category>
173
paramholder
;
174
175
181
CaloCellPrefetchIterator
(
const
base_iterator
& begin,
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
208
using
paramholder::getParameter
;
209
210
211
private
:
213
void
init
();
214
216
const
CaloCell
*
m_cellp
;
217
219
const
CaloCell
*
m_next_cellp
;
220
222
T
m_it
;
223
225
T
m_end
;
226
};
227
228
229
#include "
CaloEvent/CaloCellPrefetchIterator.icc
"
230
231
232
#endif
// not CALOEVENT_CALOCELLPREFETCHITERATOR_H
CaloCellPrefetchIterator.icc
CaloCell.h
NavigationToken.h
CaloCellPrefetchIterator
Definition
CaloCellPrefetchIterator.h:160
CaloCellPrefetchIterator::pointer
value_type * pointer
Definition
CaloCellPrefetchIterator.h:168
CaloCellPrefetchIterator::next
bool next()
Move to the next element.
CaloCellPrefetchIterator::difference_type
std::ptrdiff_t difference_type
Definition
CaloCellPrefetchIterator.h:167
CaloCellPrefetchIterator::m_cellp
const CaloCell * m_cellp
Current cell pointer.
Definition
CaloCellPrefetchIterator.h:216
CaloCellPrefetchIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition
CaloCellPrefetchIterator.h:165
CaloCellPrefetchIterator::m_end
T m_end
End iterator.
Definition
CaloCellPrefetchIterator.h:225
CaloCellPrefetchIterator::paramholder
CaloEvent_detail::paramholder< T, typename T::iterator_category > paramholder
The base paramholder class.
Definition
CaloCellPrefetchIterator.h:173
CaloCellPrefetchIterator::m_next_cellp
const CaloCell * m_next_cellp
Next cell pointer.
Definition
CaloCellPrefetchIterator.h:219
CaloCellPrefetchIterator::base_iterator
T base_iterator
The base iterator, on which we're templated.
Definition
CaloCellPrefetchIterator.h:163
CaloCellPrefetchIterator::CaloCellPrefetchIterator
CaloCellPrefetchIterator(const CONTAINER &cont)
Constructor, from a container.
CaloCellPrefetchIterator::value_type
const CaloCell * value_type
Definition
CaloCellPrefetchIterator.h:166
CaloCellPrefetchIterator::m_it
T m_it
Current iterator. Points at the next element.
Definition
CaloCellPrefetchIterator.h:222
CaloCellPrefetchIterator::CaloCellPrefetchIterator
CaloCellPrefetchIterator(const base_iterator &begin, const base_iterator &end)
Constructor.
CaloCellPrefetchIterator::reference
value_type & reference
Definition
CaloCellPrefetchIterator.h:169
CaloCellPrefetchIterator::init
void init()
Initialize before first use.
CaloCellPrefetchIterator::operator*
const CaloCell * operator*() const
Dereference the iterator.
CaloCell
Data object for each calorimeter readout cell.
Definition
CaloCell.h:57
CaloEvent_detail
Definition
CaloCellPrefetchIterator.h:28
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::fetch
void fetch(const T &it)
Fetch the next weight from the iterator (a no-op).
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::m_next_param
param_t m_next_param
The next parameter.
Definition
CaloCellPrefetchIterator.h:98
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 >::m_param
param_t m_param
The current parameter.
Definition
CaloCellPrefetchIterator.h:95
CaloEvent_detail::paramholder< T, NavigationTokenIteratorTag >::next
void next()
Move to the next weight.
CaloEvent_detail::paramholder
Interface to NavigableToken weights.
Definition
CaloCellPrefetchIterator.h:53
CaloEvent_detail::paramholder::getParameter
param_t getParameter() const
Return the current parameter (will always be 1).
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
CaloEvent_detail::paramholder::next
void next()
Move to the next weight (a no-op).
NavigationTokenIteratorTag
Definition
NavigationToken.h:43
Generated on
for ATLAS Offline Software by
1.17.0