ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DetectorDescription
Identifier
src
MultiRange.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "
Identifier/MultiRange.h
"
6
#include "GaudiKernel/MsgStream.h"
7
#include <iostream>
8
#include <sstream>
9
#include <algorithm>
//remove_if
10
#include <ranges>
11
#include <numeric>
12
13
MultiRange::MultiRange
(
const
Range
&
r
,
const
Range
& s) {
14
m_ranges
.push_back (
r
);
15
m_ranges
.push_back (s);
16
}
17
18
//-----------------------------------------------
19
void
MultiRange::clear
() {
20
m_ranges
.clear ();
21
}
22
23
//-----------------------------------------------
24
void
MultiRange::add
(
const
Range
& range) {
25
// Add new range ONLY if an equivalent does NOT exist
26
if
(std::ranges::find(
m_ranges
, range) ==
m_ranges
.end()) {
27
m_ranges
.push_back(range);
28
}
29
}
30
31
//-----------------------------------------------
32
void
MultiRange::add
(
Range
&& range) {
33
// Add new range ONLY if an equivalent does NOT exist
34
if
(std::ranges::find(
m_ranges
, range) ==
m_ranges
.end()) {
35
m_ranges
.emplace_back (std::move(range));
36
}
37
}
38
39
//-----------------------------------------------
40
void
MultiRange::add
(
const
ExpandedIdentifier
&
id
) {
41
m_ranges
.emplace_back (
id
);
42
}
43
44
//-----------------------------------------------
45
void
MultiRange::remove_range
(
const
ExpandedIdentifier
&
id
) {
46
// Remove all ranges for which id matches
47
[[maybe_unused]]
auto
erased =
std::erase_if
(
m_ranges
,
48
[&
id
] (
const
Range
&
r
) {
return
r
.match(
id
); });
49
}
50
51
52
53
//-----------------------------------------------
54
Range
&
MultiRange::back
() {
55
return
(
m_ranges
.back());
56
}
57
58
//-----------------------------------------------
59
int
MultiRange::match
(
const
ExpandedIdentifier
&
id
)
const
{
60
bool
result = std::ranges::any_of(
m_ranges
, [&
id
](
const
Range
&
r
){
return
r
.match(
id
);});
61
return
result ? 1:0;
62
}
63
64
//-----------------------------------------------
65
const
Range
&
MultiRange::operator []
(
MultiRange::size_type
index
)
const
{
66
static
const
Range
null_range;
67
if
(
index
>=
m_ranges
.size ())
return
(null_range);
68
return
(
m_ranges
[
index
]);
69
}
70
71
//-----------------------------------------------
72
MultiRange::size_type
MultiRange::size
()
const
{
73
return
(
m_ranges
.size ());
74
}
75
76
MultiRange::const_iterator
MultiRange::begin
()
const
{
77
return
(
m_ranges
.begin ());
78
}
79
80
MultiRange::const_iterator
MultiRange::end
()
const
{
81
return
(
m_ranges
.end ());
82
}
83
84
MultiRange::size_type
MultiRange::cardinality
()
const
{
85
size_type
init = 0;
86
return
std::accumulate(
m_ranges
.begin(),
m_ranges
.end(), init,
87
[](
size_type
a
,
const
Range
& b){return a + b.cardinality();});
88
}
89
90
MultiRange::size_type
MultiRange::cardinalityUpTo
(
const
ExpandedIdentifier
&
id
)
const
{
91
// Loop over ranges in MultiRange and calculate hash for each
92
// range
93
size_type
init = 0;
94
return
std::accumulate(
m_ranges
.begin(),
m_ranges
.end(), init,
95
[&
id
](
size_type
a
,
const
Range
& b){return a + b.cardinalityUpTo(id);});
96
}
97
98
99
//-----------------------------------------------
100
bool
MultiRange::has_overlap
()
const
{
101
range_vector::size_type i;
102
range_vector::size_type j;
103
for
(i = 0; i <
m_ranges
.size (); ++i) {
104
const
Range
&
r
=
m_ranges
[i];
105
for
(j = i + 1; j <
m_ranges
.size (); ++j) {
106
const
Range
& s =
m_ranges
[j];
107
if
(
r
.overlaps_with (s))
return
(
true
);
108
}
109
}
110
return
(
false
);
111
}
112
113
//-----------------------------------------------
114
MultiRange::identifier_factory
MultiRange::factory_begin
() {
115
const
MultiRange
& me = *
this
;
116
return
(
identifier_factory
(me));
117
}
118
119
//-----------------------------------------------
120
MultiRange::const_identifier_factory
MultiRange::factory_begin
()
const
{
121
const
MultiRange
& me = *
this
;
122
return
(
const_identifier_factory
(me));
123
}
124
125
//-----------------------------------------------
126
MultiRange::identifier_factory
MultiRange::factory_end
() {
127
static
const
identifier_factory
factory(*
this
);
128
return
(factory);
129
}
130
131
//-----------------------------------------------
132
MultiRange::const_identifier_factory
MultiRange::factory_end
()
const
{
133
static
const
const_identifier_factory
factory;
134
return
(factory);
135
}
136
137
//-----------------------------------------------
138
MultiRange::identifier_factory::identifier_factory
(
const
MultiRange
& multirange)
139
:
140
m_range_it
(multirange.
m_ranges
.
begin
()),
141
m_range_end
(multirange.
m_ranges
.
end
()){
142
if
(
m_range_it
==
m_range_end
)
return
;
// no ranges
146
if
(
m_range_it
!=
m_range_end
) {
147
m_id_fac_it
=
ConstRangeIterator
(*m_range_it).
begin
();
148
m_id_fac_end
=
ConstRangeIterator
(*m_range_it).
end
();
149
if
(
m_id_fac_it
!=
m_id_fac_end
) {
150
// Set id
151
m_id
= *
m_id_fac_it
;
152
}
153
}
154
}
155
156
//-----------------------------------------------
157
void
MultiRange::identifier_factory::operator ++
() {
158
if
(
m_id
.fields () == 0)
return
;
159
m_id
.clear();
160
if
(
m_range_it
!=
m_range_end
) {
161
if
(
m_id_fac_it
!=
m_id_fac_end
) {
162
++
m_id_fac_it
;
163
}
164
if
(
m_id_fac_it
==
m_id_fac_end
) {
165
++
m_range_it
;
166
if
(
m_range_it
!=
m_range_end
) {
167
m_id_fac_it
=
ConstRangeIterator
(*m_range_it).
begin
();
168
m_id_fac_end
=
ConstRangeIterator
(*m_range_it).
end
();
169
}
170
}
171
if
(
m_id_fac_it
!=
m_id_fac_end
) {
172
m_id
= *
m_id_fac_it
;
173
}
174
}
175
}
176
177
//-----------------------------------------------
178
const
ExpandedIdentifier
&
MultiRange::identifier_factory::operator *
()
const
{
179
return
(
m_id
);
180
}
181
182
//-----------------------------------------------
183
bool
MultiRange::identifier_factory::operator ==
(
const
identifier_factory
& other)
const
{
184
return
(
m_id
== other.m_id);
185
}
186
187
//-----------------------------------------------
188
MultiRange::const_identifier_factory::const_identifier_factory
(
const
MultiRange
& multirange)
189
:
190
m_range_it
(multirange.
m_ranges
.
begin
()),
191
m_range_end
(multirange.
m_ranges
.
end
()){
192
193
if
(
m_range_it
==
m_range_end
)
return
;
// no ranges
197
if
(
m_range_it
!=
m_range_end
) {
198
m_id_fac_it
=
ConstRangeIterator
(*m_range_it).
begin
();
199
m_id_fac_end
=
ConstRangeIterator
(*m_range_it).
end
();
200
if
(
m_id_fac_it
!=
m_id_fac_end
) {
201
// Set id
202
m_id
= *
m_id_fac_it
;
203
}
204
}
205
}
206
207
//-----------------------------------------------
208
void
MultiRange::const_identifier_factory::operator ++
() {
209
if
(
m_id
.fields () == 0)
return
;
210
m_id
.clear();
211
if
(
m_range_it
!=
m_range_end
) {
212
if
(
m_id_fac_it
!=
m_id_fac_end
) {
213
++
m_id_fac_it
;
214
}
215
if
(
m_id_fac_it
==
m_id_fac_end
) {
216
++
m_range_it
;
217
if
(
m_range_it
!=
m_range_end
) {
218
m_id_fac_it
=
ConstRangeIterator
(*m_range_it).
begin
();
219
m_id_fac_end
=
ConstRangeIterator
(*m_range_it).
end
();
220
}
221
}
222
if
(
m_id_fac_it
!=
m_id_fac_end
) {
223
m_id
= *
m_id_fac_it
;
224
}
225
}
226
}
227
228
//-----------------------------------------------
229
const
ExpandedIdentifier
&
MultiRange::const_identifier_factory::operator *
()
const
{
230
return
(
m_id
);
231
}
232
233
//-----------------------------------------------
234
bool
MultiRange::const_identifier_factory::operator ==
(
const
const_identifier_factory
& other)
const
{
235
return
(
m_id
== other.m_id);
236
}
237
238
239
240
void
MultiRange::show
(std::ostream& s)
const
{
241
range_vector::size_type i;
242
for
(i = 0; i <
m_ranges
.size (); ++i) {
243
if
(i > 0) s << std::endl;
244
const
Range
&
r
=
m_ranges
[i];
245
r
.show (s);
246
}
247
}
248
249
void
MultiRange::show
(MsgStream & out)
const
{
250
std::ostringstream os;
251
show
(os);
252
out << os.str();
253
}
254
255
//-----------------------------------------------
256
MultiRange::operator std::string ()
const
{
257
std::string result;
258
range_vector::size_type i{};
259
for
( ; i <
m_ranges
.size (); ++i){
260
if
(i > 0) result +=
" | "
;
261
const
Range
&
r
=
m_ranges
[i];
262
result += (std::string)
r
;
263
}
264
return
(result);
265
}
a
static Double_t a
Definition
LArPhysWaveHECTool.cxx:38
MultiRange.h
ConstRangeIterator
Definition
RangeIterator.h:46
ConstRangeIterator::end
ConstRangeIterator end() const
Definition
RangeIterator.cxx:32
ConstRangeIterator::begin
ConstRangeIterator begin() const
Definition
RangeIterator.cxx:18
ExpandedIdentifier
Definition
DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:105
MultiRange::const_identifier_factory
Definition
MultiRange.h:52
MultiRange::const_identifier_factory::m_range_end
range_vector::const_iterator m_range_end
Definition
MultiRange.h:69
MultiRange::const_identifier_factory::operator*
const ExpandedIdentifier & operator*() const
Definition
MultiRange.cxx:229
MultiRange::const_identifier_factory::operator==
bool operator==(const const_identifier_factory &other) const
Definition
MultiRange.cxx:234
MultiRange::const_identifier_factory::operator++
void operator++()
Definition
MultiRange.cxx:208
MultiRange::const_identifier_factory::m_id
ExpandedIdentifier m_id
Definition
MultiRange.h:65
MultiRange::const_identifier_factory::m_id_fac_end
ConstRangeIterator m_id_fac_end
Definition
MultiRange.h:67
MultiRange::const_identifier_factory::const_identifier_factory
const_identifier_factory()=default
MultiRange::const_identifier_factory::m_id_fac_it
ConstRangeIterator m_id_fac_it
Definition
MultiRange.h:66
MultiRange::const_identifier_factory::m_range_it
range_vector::const_iterator m_range_it
Definition
MultiRange.h:68
MultiRange::identifier_factory
This factory is able to generate all possible identifiers, from a fully bounded Range.
Definition
MultiRange.h:30
MultiRange::identifier_factory::m_range_it
range_vector::const_iterator m_range_it
Definition
MultiRange.h:46
MultiRange::identifier_factory::operator==
bool operator==(const identifier_factory &other) const
Definition
MultiRange.cxx:183
MultiRange::identifier_factory::m_range_end
range_vector::const_iterator m_range_end
Definition
MultiRange.h:47
MultiRange::identifier_factory::m_id_fac_it
ConstRangeIterator m_id_fac_it
Definition
MultiRange.h:44
MultiRange::identifier_factory::m_id_fac_end
ConstRangeIterator m_id_fac_end
Definition
MultiRange.h:45
MultiRange::identifier_factory::identifier_factory
identifier_factory()=default
MultiRange::identifier_factory::operator*
const ExpandedIdentifier & operator*() const
Definition
MultiRange.cxx:178
MultiRange::identifier_factory::operator++
void operator++()
Definition
MultiRange.cxx:157
MultiRange::identifier_factory::m_id
ExpandedIdentifier m_id
Definition
MultiRange.h:43
MultiRange::clear
void clear()
Definition
MultiRange.cxx:19
MultiRange::cardinalityUpTo
size_type cardinalityUpTo(const ExpandedIdentifier &id) const
Definition
MultiRange.cxx:90
MultiRange::has_overlap
bool has_overlap() const
Check if there are overlaps between any couple of Ranges.
Definition
MultiRange.cxx:100
MultiRange::show
void show(std::ostream &s) const
Definition
MultiRange.cxx:240
MultiRange::const_iterator
range_vector::const_iterator const_iterator
Definition
MultiRange.h:22
MultiRange::factory_end
identifier_factory factory_end()
Definition
MultiRange.cxx:126
MultiRange::operator[]
const Range & operator[](size_type index) const
Accessors.
Definition
MultiRange.cxx:65
MultiRange::remove_range
void remove_range(const ExpandedIdentifier &id)
Remove a Range made from a single ExpandedIdentifier.
Definition
MultiRange.cxx:45
MultiRange::m_ranges
range_vector m_ranges
Definition
MultiRange.h:131
MultiRange::cardinality
size_type cardinality() const
Computes a possible cardinality from all ranges.
Definition
MultiRange.cxx:84
MultiRange::begin
const_iterator begin() const
Definition
MultiRange.cxx:76
MultiRange::back
Range & back()
Get the last entered Range.
Definition
MultiRange.cxx:54
MultiRange::size_type
ExpandedIdentifier::size_type size_type
Definition
MultiRange.h:21
MultiRange::factory_begin
identifier_factory factory_begin()
Definition
MultiRange.cxx:114
MultiRange::end
const_iterator end() const
Definition
MultiRange.cxx:80
MultiRange::add
void add(const Range &range)
Definition
MultiRange.cxx:24
MultiRange::match
int match(const ExpandedIdentifier &id) const
Match an identifier.
Definition
MultiRange.cxx:59
MultiRange::MultiRange
MultiRange()=default
MultiRange::size
size_type size() const
Definition
MultiRange.cxx:72
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition
DetectorDescription/Identifier/Identifier/Range.h:31
r
int r
Definition
globals.cxx:22
index
Definition
index.py:1
std::erase_if
std::size_t erase_if(T_container &container, T_Func pred)
Definition
TruthParticleHitCountAlg.cxx:21
Generated on
for ATLAS Offline Software by
1.17.0