ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Control
AthenaKernel
src
ThinningDecisionBase.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3
*/
10
11
12
#include "
AthenaKernel/ThinningDecisionBase.h
"
13
#include <stdexcept>
14
15
16
namespace
SG
{
17
18
23
ThinningDecisionBase::ThinningDecisionBase
(
size_t
sz
/*= 0*/
)
24
:
m_mask
(
sz
)
25
{
26
}
27
28
33
void
ThinningDecisionBase::resize
(
const
size_t
size
)
34
{
35
m_mask
.resize (
size
);
36
}
37
38
42
size_t
ThinningDecisionBase::thinnedSize
()
const
43
{
44
return
m_mask
.size() -
m_mask
.count();
45
}
46
47
51
void
ThinningDecisionBase::thinAll
()
52
{
53
m_mask
.set();
54
}
55
56
60
void
ThinningDecisionBase::keepAll
()
61
{
62
m_mask
.reset();
63
}
64
65
70
void
ThinningDecisionBase::thin
(
size_t
ndx)
71
{
72
if
(ndx >=
m_mask
.size()) {
73
throw
std::out_of_range (
"ThinningDecisionBase::thin"
);
74
}
75
m_mask
.set (ndx,
true
);
76
}
77
78
84
void
ThinningDecisionBase::keep
(
size_t
ndx)
85
{
86
if
(ndx >=
m_mask
.size()) {
87
throw
std::out_of_range (
"ThinningDecisionBase::thin"
);
88
}
89
m_mask
.set (ndx,
false
);
90
}
91
92
102
void
ThinningDecisionBase::thin
(
size_t
ndx,
bool
flag,
Op
op
/*= Op::Set*/
)
103
{
104
if
(ndx >=
m_mask
.size()) {
105
throw
std::out_of_range (
"ThinningDecisionBase::thin"
);
106
}
107
if
(op ==
Op::And
)
108
flag &=
m_mask
[ndx];
109
else
if
(op ==
Op::Or
)
110
flag |=
m_mask
[ndx];
111
m_mask
.set (ndx, flag);
112
}
113
114
124
void
ThinningDecisionBase::keep
(
size_t
ndx,
bool
flag,
Op
op
/*= Op::Set*/
)
125
{
126
if
(ndx >=
m_mask
.size()) {
127
throw
std::out_of_range (
"ThinningDecisionBase::thin"
);
128
}
129
if
(op ==
Op::And
)
130
flag &= !
m_mask
[ndx];
131
else
if
(op ==
Op::Or
)
132
flag |= !
m_mask
[ndx];
133
m_mask
.set (ndx, !flag);
134
}
135
136
146
void
ThinningDecisionBase::thin
(
const
std::vector<bool>& v,
Op
op
/*= Op::Set*/
)
147
{
148
size_t
sz
=
m_mask
.size();
149
if
(
sz
!= v.size()) {
150
throw
std::out_of_range (
"ThinningDecisionBase::thin(): inconsistent vector sizes."
);
151
}
152
for
(
size_t
i = 0; i <
sz
; i++) {
153
bool
flag = v[i];
154
if
(op ==
Op::And
)
155
flag &=
m_mask
[i];
156
else
if
(op ==
Op::Or
)
157
flag |=
m_mask
[i];
158
m_mask
.set (i, flag);
159
}
160
}
161
162
172
void
ThinningDecisionBase::keep
(
const
std::vector<bool>& v,
Op
op
/*= Op::Set*/
)
173
{
174
size_t
sz
=
m_mask
.size();
175
if
(
sz
!= v.size()) {
176
throw
std::out_of_range (
"ThinningDecisionBase::keep(): inconsistent vector sizes."
);
177
}
178
for
(
size_t
i = 0; i <
sz
; i++) {
179
bool
flag = v[i];
180
if
(op ==
Op::And
)
181
flag &= !
m_mask
[i];
182
else
if
(op ==
Op::Or
)
183
flag |= !
m_mask
[i];
184
m_mask
.set (i, !flag);
185
}
186
}
187
188
198
void
ThinningDecisionBase::thin
(
const
ThinningDecisionBase
& other,
Op
op
/*= Op::Set*/
)
199
{
200
size_t
sz
=
m_mask
.size();
201
if
(
sz
!= other.size()) {
202
throw
std::out_of_range (
"ThinningDecisionBase::thin(): inconsistent vector sizes."
);
203
}
204
if
(op ==
Op::And
)
205
m_mask
&= other.m_mask;
206
else
if
(op ==
Op::Or
)
207
m_mask
|= other.m_mask;
208
else
209
m_mask
= other.m_mask;
210
}
211
212
222
void
ThinningDecisionBase::keep
(
const
ThinningDecisionBase
& other,
Op
op
/*= Op::Set*/
)
223
{
224
size_t
sz
=
m_mask
.size();
225
if
(
sz
!= other.size()) {
226
throw
std::out_of_range (
"ThinningDecisionBase::keep(): inconsistent vector sizes."
);
227
}
228
if
(op ==
Op::And
)
229
m_mask
|= ~other.m_mask;
230
else
if
(op ==
Op::Or
)
231
m_mask
&= ~other.m_mask;
232
else
233
m_mask
= ~other.m_mask;
234
}
235
236
240
void
ThinningDecisionBase::buildIndexMap
()
241
{
242
assert (
m_indexMap
.empty());
243
size_t
sz
=
m_mask
.size();
244
m_indexMap
.resize (
sz
);
245
size_t
pos = 0;
246
for
(
size_t
i = 0; i <
sz
; i++) {
247
m_indexMap
[i] =
thinned
(i) ?
RemovedIdx
: pos++ ;
248
}
249
}
250
251
252
}
// namespace SG
sz
static Double_t sz
Definition
LArPhysWaveHECTool.cxx:37
ThinningDecisionBase.h
Hold thinning decisions for one container.
SG::ThinningDecisionBase::RemovedIdx
static const std::size_t RemovedIdx
Flag used to show that an index has been thinned away.
Definition
ThinningDecisionBase.h:42
SG::ThinningDecisionBase::m_indexMap
std::vector< size_t > m_indexMap
Mapping from original indices to thinned indices.
Definition
ThinningDecisionBase.h:207
SG::ThinningDecisionBase::ThinningDecisionBase
ThinningDecisionBase(size_t sz=0)
Constructor.
Definition
ThinningDecisionBase.cxx:23
SG::ThinningDecisionBase::thinAll
void thinAll()
Mark that all elements should be thinned away.
Definition
ThinningDecisionBase.cxx:51
SG::ThinningDecisionBase::keepAll
void keepAll()
Mark that all elements should be kept (not thinned).
Definition
ThinningDecisionBase.cxx:60
SG::ThinningDecisionBase::keep
void keep(size_t ndx)
Mark that index ndx in the container should be kept (not thinned away).
Definition
ThinningDecisionBase.cxx:84
SG::ThinningDecisionBase::Op
Op
Definition
ThinningDecisionBase.h:44
SG::ThinningDecisionBase::Op::Or
@ Or
Definition
ThinningDecisionBase.h:47
SG::ThinningDecisionBase::Op::And
@ And
Definition
ThinningDecisionBase.h:46
SG::ThinningDecisionBase::thin
void thin(size_t ndx)
Mark that index ndx in the container should be thinned away.
Definition
ThinningDecisionBase.cxx:70
SG::ThinningDecisionBase::thinned
bool thinned(size_t ndx) const
Return true if element ndx should be thinned.
SG::ThinningDecisionBase::buildIndexMap
void buildIndexMap()
Build the index map.
Definition
ThinningDecisionBase.cxx:240
SG::ThinningDecisionBase::size
size_t size() const
Return the total size of the container being thinned.
SG::ThinningDecisionBase::thinnedSize
size_t thinnedSize() const
Return the size of the container being thinned after thinning.
Definition
ThinningDecisionBase.cxx:42
SG::ThinningDecisionBase::m_mask
boost::dynamic_bitset m_mask
Thinning map. Set to 1 for thinned elements.
Definition
ThinningDecisionBase.h:204
SG::ThinningDecisionBase::resize
void resize(const size_t size)
Change the number of elements.
Definition
ThinningDecisionBase.cxx:33
SG
Forward declaration.
Definition
CaloCellPacker_400_500.h:32
Generated on
for ATLAS Offline Software by
1.17.0