ATLAS Offline Software
Loading...
Searching...
No Matches
IdDictRange.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
7#include "IdDict/IdDictMgr.h"
10
11#include "src/Debugger.h"
12#include <iostream>
13
14
18{
19}
20
21
24 const std::string& label)
26{
28}
29
30
33 int value)
35{
36 set_range (value);
37}
38
39
42 int minvalue, int maxvalue)
44{
45 set_range (minvalue, maxvalue);
46}
47
48
51 const std::vector<int>& values)
53{
55}
56
57
60 const std::vector<std::string>& labels)
62{
64}
65
66
68void IdDictRange::set_range (const std::string& label)
69{
71 m_label = label;
72}
73
74
76void IdDictRange::set_range (int value)
77{
79 m_value = value;
80}
81
82
84void IdDictRange::set_range (int minvalue, int maxvalue)
85{
87 m_minvalue = minvalue;
88 m_maxvalue = maxvalue;
89}
90
91
93void IdDictRange::set_range (const std::vector<int>& values)
94{
97}
98
99
101void IdDictRange::set_range (const std::vector<std::string>& labels)
102{
105}
106
107
114
115
122
123
129
130
131void
133 IdDictDictionary& dictionary, IdDictRegion& /*region*/) {
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) {
153 m_label = m_field->get_label(0);
154 } else if (labels > 1) {
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 }
173 }
174}
175
176void
178 IdDictDictionary& dictionary, IdDictRegion& region, const std::string& /*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
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
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:
229 break;
230
231 case unknown:
232 break;
233 }
234}
235
236Range
239
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: {
256 break;
257 }
258
259 case unknown: {
260 break;
261 }
262 }
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}
static bool debug()
Definition Debugger.h:18
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
std::vector< int > m_values
const std::string & field_name() const
const std::string & label() const
const std::vector< int > & values() const
void set_range(const std::string &label)
By label.
virtual Range build_range() const override
std::string m_label
void set_next(int next)
Set next value and adjust continuation mode.
void set_prev(int prev)
Set previous value and adjust continuation mode.
std::vector< std::string > m_labels
IdDictRange(const std::string &field_name)
Set name only; no range information.
std::string m_field_name
virtual void generate_implementation(const IdDictMgr &idd, IdDictDictionary &dictionary, IdDictRegion &region, const std::string &tag="") override
const IdDictField * field() const
virtual void resolve_references(IdDictMgr &idd, IdDictDictionary &dictionary, IdDictRegion &region) override
specification_type m_specification
void set_wrap_around()
Enable wraparound.
continuation_mode m_continuation_mode
const std::vector< std::string > & labels() const
bool m_resolved_references
IdDictField * m_field
virtual std::string group_name() const override
IdDictFieldImplementation & new_implementation()
Add a new implementation object and return a reference to it.
size_t fieldSize() const
const std::string & tag() const
size_t index() const
size_t n_implementation() const
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition index.py:1