ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
DetectorDescription
IdDict
src
IdDictRange.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
IdDict/IdDictRange.h
"
5
#include "
IdDict/IdDictField.h
"
6
#include "
IdDict/IdDictRegion.h
"
7
#include "
IdDict/IdDictMgr.h
"
8
#include "
IdDict/IdDictDictionary.h
"
9
#include "
IdDict/IdDictFieldImplementation.h
"
10
11
#include "
src/Debugger.h
"
12
#include <iostream>
13
14
16
IdDictRange::IdDictRange
(
const
std::string&
field_name
)
17
:
m_field_name
(
field_name
)
18
{
19
}
20
21
23
IdDictRange::IdDictRange
(
const
std::string&
field_name
,
24
const
std::string&
label
)
25
:
m_field_name
(
field_name
)
26
{
27
set_range
(
label
);
28
}
29
30
32
IdDictRange::IdDictRange
(
const
std::string&
field_name
,
33
int
value)
34
:
m_field_name
(
field_name
)
35
{
36
set_range
(value);
37
}
38
39
41
IdDictRange::IdDictRange
(
const
std::string&
field_name
,
42
int
minvalue,
int
maxvalue)
43
:
m_field_name
(
field_name
)
44
{
45
set_range
(minvalue, maxvalue);
46
}
47
48
50
IdDictRange::IdDictRange
(
const
std::string&
field_name
,
51
const
std::vector<int>&
values
)
52
:
m_field_name
(
field_name
)
53
{
54
set_range
(
values
);
55
}
56
57
59
IdDictRange::IdDictRange
(
const
std::string&
field_name
,
60
const
std::vector<std::string>&
labels
)
61
:
m_field_name
(
field_name
)
62
{
63
set_range
(
labels
);
64
}
65
66
68
void
IdDictRange::set_range
(
const
std::string&
label
)
69
{
70
m_specification
=
by_label
;
71
m_label
=
label
;
72
}
73
74
76
void
IdDictRange::set_range
(
int
value)
77
{
78
m_specification
=
by_value
;
79
m_value
= value;
80
}
81
82
84
void
IdDictRange::set_range
(
int
minvalue,
int
maxvalue)
85
{
86
m_specification
=
by_minmax
;
87
m_minvalue
= minvalue;
88
m_maxvalue
= maxvalue;
89
}
90
91
93
void
IdDictRange::set_range
(
const
std::vector<int>&
values
)
94
{
95
m_specification
=
by_values
;
96
m_values
=
values
;
97
}
98
99
101
void
IdDictRange::set_range
(
const
std::vector<std::string>&
labels
)
102
{
103
m_specification
=
by_labels
;
104
m_labels
=
labels
;
105
}
106
107
109
void
IdDictRange::set_prev
(
int
prev)
110
{
111
m_prev_value
= prev;
112
m_continuation_mode
= (
m_continuation_mode
==
has_next
) ?
has_both
:
has_previous
;
113
}
114
115
117
void
IdDictRange::set_next
(
int
next)
118
{
119
m_next_value
= next;
120
m_continuation_mode
= (
m_continuation_mode
==
has_previous
) ?
has_both
:
has_next
;
121
}
122
123
125
void
IdDictRange::set_wrap_around
()
126
{
127
m_continuation_mode
=
wrap_around
;
128
}
129
130
131
void
132
IdDictRange::resolve_references
(
IdDictMgr
&
/*idd*/
,
133
IdDictDictionary
& dictionary,
IdDictRegion
&
/*region*/
) {
134
if
(!
m_resolved_references
) {
135
m_field
= dictionary.find_field(
m_field_name
);
136
if
(
m_field
==
nullptr
) {
137
m_field
= dictionary.add_field(std::make_unique<IdDictField> (
m_field_name
));
138
}
139
140
if
(
m_specification
==
unknown
) {
150
unsigned
int
labels
=
m_field
->get_label_number();
151
if
(
labels
== 1) {
152
m_specification
=
by_label
;
153
m_label
=
m_field
->get_label(0);
154
}
else
if
(
labels
> 1) {
155
m_specification
=
by_labels
;
156
for
(
size_t
i = 0; i <
labels
; ++i) {
157
m_labels
.push_back(
m_field
->get_label(i));
158
}
159
}
160
}
161
162
if
(
m_specification
==
by_label
) {
163
m_value
=
m_field
->get_label_value(
m_label
);
164
}
else
if
(
m_specification
==
by_labels
) {
165
m_values
.clear();
166
for
(
size_t
i = 0; i <
m_labels
.size(); ++i) {
167
const
std::string&
label
=
m_labels
[i];
168
int
value =
m_field
->get_label_value(
label
);
169
m_values
.push_back(value);
170
}
171
}
172
m_resolved_references
=
true
;
173
}
174
}
175
176
void
177
IdDictRange::generate_implementation
(
const
IdDictMgr
&
/*idd*/
,
178
IdDictDictionary
& dictionary,
IdDictRegion
& region, std::string_view
/*tag*/
) {
179
// Add IdDictFieldImplementation to this region
180
181
// NOTE: we DO NOT protect this method with
182
// m_generated_implementation because the same object may be
183
// called more than once because there are IdDictRangeRef's which
184
// point to the same IdDictRange's.
185
186
if
(
Debugger::debug
()) {
187
std::cout <<
"IdDictRange::generate_implementation>"
<< std::endl;
188
}
189
190
IdDictFieldImplementation
&
impl
= region.
new_implementation
();
191
impl
.set_range(
this
);
192
if
(
m_field
->index() == 0) {
193
m_field
->set_index(region.
fieldSize
() - 1);
194
}
else
if
(
m_field
->index() != (region.
fieldSize
() - 1)) {
195
std::cout <<
"Bad field index for "
<<
m_field_name
196
<<
" index "
<<
m_field
->index()
197
<<
" in dictionary "
<< dictionary.name()
198
<<
" region #"
<< region.
index
()
199
<<
" group "
<< region.
group_name
()
200
<<
" tag "
<< region.
tag
()
201
<<
" size "
<< (region.
n_implementation
() - 1)
202
<< std::endl;
203
}
204
205
size_t
index
= region.
n_implementation
() - 1;
206
if
(region.
n_implementation
() <=
index
) {
207
std::cout <<
"IdDictRange::generate_implementation: index >= impl size - "
208
<<
index
<<
" "
<< region.
fieldSize
()
209
<< std::endl;
210
return
;
211
}
212
213
Range::field
field
;
214
switch
(
m_specification
) {
215
case
by_value
:
216
case
by_label
: {
217
impl
.set_field(
Range::field
(
m_value
,
m_value
));
218
break
;
219
}
220
221
case
by_values
:
222
case
by_labels
: {
223
impl
.set_field(
Range::field
(
m_values
));
224
}
225
break
;
226
227
case
by_minmax
:
228
impl
.set_field(
Range::field
(
m_minvalue
,
m_maxvalue
));
229
break
;
230
231
case
unknown
:
232
break
;
233
}
234
}
235
236
Range
237
IdDictRange::build_range
()
const
{
238
Range
result;
239
240
Range::field
field
;
241
switch
(
m_specification
) {
242
case
by_value
:
243
case
by_label
: {
244
field
.set(
m_value
,
m_value
);
245
break
;
246
}
247
248
case
by_values
:
249
case
by_labels
: {
250
field
.set(
m_values
);
251
break
;
252
}
253
254
case
by_minmax
: {
255
field
.set(
m_minvalue
,
m_maxvalue
);
256
break
;
257
}
258
259
case
unknown
: {
260
break
;
261
}
262
}
263
if
(
wrap_around
==
m_continuation_mode
) {
264
field
.set(
true
);
265
}
else
if
(
has_previous
==
m_continuation_mode
) {
266
field
.set_previous(
m_prev_value
);
267
}
else
if
(
has_next
==
m_continuation_mode
) {
268
field
.set_next(
m_next_value
);
269
}
else
if
(
has_both
==
m_continuation_mode
) {
270
field
.set_previous(
m_prev_value
);
271
field
.set_next(
m_next_value
);
272
}
273
result.add(std::move(
field
));
274
return
(result);
275
}
Debugger.h
IdDictDictionary.h
IdDictFieldImplementation.h
IdDictField.h
IdDictMgr.h
IdDictRange.h
IdDictRegion.h
Debugger::debug
static bool debug()
Definition
Debugger.h:18
IdDictDictionary
Definition
IdDictDictionary.h:33
IdDictFieldImplementation
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
Definition
IdDictFieldImplementation.h:59
IdDictMgr
Definition
IdDictMgr.h:17
IdDictRange::m_value
int m_value
Definition
IdDictRange.h:129
IdDictRange::m_values
std::vector< int > m_values
Definition
IdDictRange.h:136
IdDictRange::m_prev_value
int m_prev_value
Definition
IdDictRange.h:132
IdDictRange::m_maxvalue
int m_maxvalue
Definition
IdDictRange.h:131
IdDictRange::m_next_value
int m_next_value
Definition
IdDictRange.h:133
IdDictRange::field_name
const std::string & field_name() const
Definition
IdDictRange.h:143
IdDictRange::label
const std::string & label() const
Definition
IdDictRange.h:150
IdDictRange::values
const std::vector< int > & values() const
Definition
IdDictRange.h:171
IdDictRange::wrap_around
@ wrap_around
Definition
IdDictRange.h:34
IdDictRange::has_previous
@ has_previous
Definition
IdDictRange.h:32
IdDictRange::has_next
@ has_next
Definition
IdDictRange.h:31
IdDictRange::has_both
@ has_both
Definition
IdDictRange.h:33
IdDictRange::set_range
void set_range(const std::string &label)
By label.
Definition
IdDictRange.cxx:68
IdDictRange::build_range
virtual Range build_range() const override
Definition
IdDictRange.cxx:237
IdDictRange::m_label
std::string m_label
Definition
IdDictRange.h:128
IdDictRange::m_minvalue
int m_minvalue
Definition
IdDictRange.h:130
IdDictRange::set_next
void set_next(int next)
Set next value and adjust continuation mode.
Definition
IdDictRange.cxx:117
IdDictRange::set_prev
void set_prev(int prev)
Set previous value and adjust continuation mode.
Definition
IdDictRange.cxx:109
IdDictRange::m_labels
std::vector< std::string > m_labels
Definition
IdDictRange.h:135
IdDictRange::generate_implementation
virtual void generate_implementation(const IdDictMgr &idd, IdDictDictionary &dictionary, IdDictRegion ®ion, std::string_view tag="") override
Definition
IdDictRange.cxx:177
IdDictRange::IdDictRange
IdDictRange(const std::string &field_name)
Set name only; no range information.
Definition
IdDictRange.cxx:16
IdDictRange::m_field_name
std::string m_field_name
Definition
IdDictRange.h:123
IdDictRange::by_labels
@ by_labels
Definition
IdDictRange.h:26
IdDictRange::by_value
@ by_value
Definition
IdDictRange.h:23
IdDictRange::by_label
@ by_label
Definition
IdDictRange.h:25
IdDictRange::by_minmax
@ by_minmax
Definition
IdDictRange.h:27
IdDictRange::by_values
@ by_values
Definition
IdDictRange.h:24
IdDictRange::unknown
@ unknown
Definition
IdDictRange.h:22
IdDictRange::field
const IdDictField * field() const
Definition
IdDictRange.h:157
IdDictRange::resolve_references
virtual void resolve_references(IdDictMgr &idd, IdDictDictionary &dictionary, IdDictRegion ®ion) override
Definition
IdDictRange.cxx:132
IdDictRange::m_specification
specification_type m_specification
Definition
IdDictRange.h:126
IdDictRange::set_wrap_around
void set_wrap_around()
Enable wraparound.
Definition
IdDictRange.cxx:125
IdDictRange::m_continuation_mode
continuation_mode m_continuation_mode
Definition
IdDictRange.h:134
IdDictRange::labels
const std::vector< std::string > & labels() const
Definition
IdDictRange.h:178
IdDictRange::m_resolved_references
bool m_resolved_references
Definition
IdDictRange.h:138
IdDictRange::m_field
IdDictField * m_field
Definition
IdDictRange.h:124
IdDictRegion
Definition
IdDictRegion.h:22
IdDictRegion::group_name
virtual std::string group_name() const override
Definition
IdDictRegion.cxx:27
IdDictRegion::new_implementation
IdDictFieldImplementation & new_implementation()
Add a new implementation object and return a reference to it.
Definition
IdDictRegion.cxx:69
IdDictRegion::fieldSize
size_t fieldSize() const
Definition
IdDictRegion.cxx:228
IdDictRegion::tag
const std::string & tag() const
Definition
IdDictRegion.h:169
IdDictRegion::index
size_t index() const
Definition
IdDictRegion.h:176
IdDictRegion::n_implementation
size_t n_implementation() const
Definition
IdDictRegion.cxx:32
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition
DetectorDescription/Identifier/Identifier/Range.h:31
Range::field
IdentifierField field
Definition
DetectorDescription/Identifier/Identifier/Range.h:36
impl
Definition
CaloGPUClusterAndCellDataMonitorOptions.h:46
index
Definition
index.py:1
Generated on
for ATLAS Offline Software by
1.17.0