ATLAS Offline Software
Loading...
Searching...
No Matches
RangeIterator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "Identifier/Range.h"
7
8
9
10//-----------------------------------------------
13 return (*this);
14}
15
16//-----------------------------------------------
19 return (*this);
20}
21
22//-----------------------------------------------
25 Range r;
26 RangeIterator factory(r);
27 return (factory);
28}
29
30//-----------------------------------------------
33 static const Range r;
34 static const ConstRangeIterator factory(r);
35 return (factory);
36}
37
38
39
40//-----------------------------------------------
48 for (Range::size_type i = 0; i < range.fields (); ++i) {
49 Range::element_type minimum;
50 Range::element_type maximum;
51 m_indices.push_back (0);
52 const Range::field& f = range[i];
53 if (f.empty()){
54 m_id << 0;
55 m_min << 0;
56 m_max << 0;
57 } else {
58 minimum = f.get_minimum ();
59 maximum = f.get_maximum ();
60 m_id << minimum;
61 m_min << minimum;
62 m_max << maximum;
63 }
64 }
65}
66
67
68
69//-----------------------------------------------
72 if (m_id.fields () == 0) return *this;
73 Range::size_type fields = m_id.fields ();
74 Range::size_type i = fields - 1;
75
76 //
77 // Starting from the end, we try to increment the m_id fields
78 // If at a given position it's not possible (max reached)
79 // then we move back one pos and try again.
80 //
81 // As soon as increment is possible, then the rest of the m_id
82 // is reset to min values.
83 //
84
85 for (;;) {
86 const Range::field& f = (*m_range)[i];
87 bool done = false;
88 Range::element_type value = 0;
89
90 if (f.isEnumerated()) {
92 index++;
93 if (index < f.get_indices ()) {
94 m_indices[i] = index;
95 value = f.get_value_at (index);
96 done = true;
97 }
98 } else {
99 value = m_id[i];
100 if (value < m_max[i]) {
105 ++value;
106 done = true;
107 }
108 }
109 if (done) {
110 m_id[i] = value;
111 for (++i; i < fields; ++i) {
112 m_indices[i] = 0;
113 m_id[i] = m_min[i];
114 }
115
116 break;
117 }
118
123
124 if (i == 0) {
125 m_id.clear ();
126 break;
127 }
128
129 --i;
130
131 }
132 return *this;
133}
134
135//-----------------------------------------------
138 return (m_id);
139}
140
141//-----------------------------------------------
142bool
144 if (m_id == other.m_id) return (true);
145 return (false);
146}
147
148
149
150//-----------------------------------------------
152 m_range (&range) {
159 for (Range::size_type i = 0; i < range.fields (); ++i) {
160 Range::element_type minimum;
161 Range::element_type maximum;
162 m_indices.push_back (0);
163 const Range::field& f = range[i];
164 if (f.empty()){
165 m_id << 0;
166 m_min << 0;
167 m_max << 0;
168 } else {
169 minimum = f.get_minimum ();
170 maximum = f.get_maximum ();
171 m_id << minimum;
172 m_min << minimum;
173 m_max << maximum;
174 }
175 }
176}
177
178
179//-----------------------------------------------
182 if (m_id.fields () == 0) return *this;
183 Range::size_type fields = m_id.fields ();
184 Range::size_type i = fields - 1;
185 //
186 // Starting from the end, we try to increment the m_id fields
187 // If at a given position it's not possible (max reached)
188 // then we move back one pos and try again.
189 //
190 // As soon as increment is possible, then the rest of the m_id
191 // is reset to min values.
192 //
193 for (;;){
194 const Range::field& f = (*m_range)[i];
195 bool done = false;
196 Range::element_type value = 0;
197
198 if (f.isEnumerated()) {
200 index++;
201 if (index < f.get_indices ()) {
202 m_indices[i] = index;
203 value = f.get_value_at (index);
204 done = true;
205 }
206 }else {
207 value = m_id[i];
208 if (value < m_max[i]){
213 ++value;
214 done = true;
215 }
216 }
217
218 if (done) {
219 m_id[i] = value;
220 for (++i; i < fields; ++i) {
221 m_indices[i] = 0;
222 m_id[i] = m_min[i];
223 }
224 break;
225 }
226
231
232 if (i == 0) {
233 m_id.clear ();
234 break;
235 }
236 --i;
237
238 }
239 return *this;
240}
241
242//-----------------------------------------------
243const ExpandedIdentifier&
245 return (m_id);
246}
247
248//-----------------------------------------------
249bool
251 if (m_id == other.m_id) return (true);
252 return (false);
253}
bool operator==(const ConstRangeIterator &other) const
const ExpandedIdentifier & operator*() const
ConstRangeIterator operator++()
ConstRangeIterator()=default
const Range * m_range
ExpandedIdentifier m_max
ConstRangeIterator end() const
ExpandedIdentifier m_id
std::vector< std::size_t > m_indices
ExpandedIdentifier m_min
ConstRangeIterator begin() const
This iterator is able to generate all possible identifiers, from a fully bounded Range.
ExpandedIdentifier m_min
const Range * m_range
ExpandedIdentifier m_max
std::vector< std::size_t > m_indices
RangeIterator()=default
RangeIterator & operator++()
RangeIterator end() const
ExpandedIdentifier & operator*()
bool operator==(const RangeIterator &other) const
ExpandedIdentifier m_id
RangeIterator begin() const
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
ExpandedIdentifier::element_type element_type
ExpandedIdentifier::size_type size_type
int r
Definition globals.cxx:22
Definition index.py:1