ATLAS Offline Software
IdDictRange.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 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"
10 
11 #include "src/Debugger.h"
12 #include <iostream>
13 
14 
15 void
18  if (!m_resolved_references) {
19  m_field = dictionary.find_field(m_field_name);
20  if (m_field == nullptr) {
21  m_field = new IdDictField;
23  dictionary.add_field(m_field);
24  }
25 
26  if (m_specification == unknown) {
36  unsigned int labels = m_field->get_label_number();
37  if (labels == 1) {
40  } else if (labels > 1) {
42  for (size_t i = 0; i < labels; ++i) {
43  m_labels.push_back(m_field->get_label(i));
44  }
45  }
46  }
47 
48  if (m_specification == by_label) {
50  } else if (m_specification == by_labels) {
51  m_values.clear();
52  for (size_t i = 0; i < m_labels.size(); ++i) {
53  const std::string& label = m_labels[i];
55  m_values.push_back(value);
56  }
57  }
58  m_resolved_references = true;
59  }
60 }
61 
62 void
64  IdDictDictionary& dictionary, IdDictRegion& region, const std::string& /*tag*/) {
65  // Add IdDictFieldImplementation to this region
66 
67  // NOTE: we DO NOT protect this method with
68  // m_generated_implementation because the same object may be
69  // called more than once because there are IdDictRangeRef's which
70  // point to the same IdDictRange's.
71 
72  if (Debugger::debug()) {
73  std::cout << "IdDictRange::generate_implementation>" << std::endl;
74  }
75 
76  region.m_implementation.resize(region.m_implementation.size() + 1);
78  impl.set_range(this);
79  if (m_field->m_index == 0) {
80  m_field->m_index = region.fieldSize() - 1;
81  } else if (m_field->m_index != (region.fieldSize() - 1)) {
82  std::cout << "Bad field index for " << m_field_name
83  << " index " << m_field->m_index
84  << " in dictionary " << dictionary.m_name
85  << " region #" << region.m_index
86  << " group " << region.m_group
87  << " tag " << region.m_tag
88  << " size " << (region.m_implementation.size() - 1)
89  << std::endl;
90  }
91 
92  size_t index = region.m_implementation.size() - 1;
93  if (region.m_implementation.size() <= index) {
94  std::cout << "IdDictRange::generate_implementation: index >= impl size - "
95  << index << " " << region.fieldSize()
96  << std::endl;
97  return;
98  }
99 
101  switch (m_specification) {
102  case by_value:
103  case by_label: {
104  impl.set_field(Range::field(m_value, m_value));
105  break;
106  }
107 
108  case by_values:
109  case by_labels: {
110  impl.set_field(Range::field(m_values));
111  }
112  break;
113 
114  case by_minmax:
115  impl.set_field(Range::field(m_minvalue, m_maxvalue));
116  break;
117 
118  case unknown:
119  break;
120  }
121 }
122 
123 Range
125  Range result;
126 
128  switch (m_specification) {
129  case by_value:
130  case by_label: {
131  field.set(m_value, m_value);
132  break;
133  }
134 
135  case by_values:
136  case by_labels: {
137  field.set(m_values);
138  break;
139  }
140 
141  case by_minmax: {
143  break;
144  }
145 
146  case unknown: {
147  break;
148  }
149  }
151  field.set(true);
152  } else if (has_previous == m_continuation_mode) {
153  field.set_previous(m_prev_value);
154  } else if (has_next == m_continuation_mode) {
155  field.set_next(m_next_value);
156  } else if (has_both == m_continuation_mode) {
157  field.set_previous(m_prev_value);
158  field.set_next(m_next_value);
159  }
160  result.add(std::move(field));
161  return(result);
162 }
IdDictRange.h
IdDictMgr.h
IdDictField::m_index
size_t m_index
Definition: IdDictField.h:30
get_generator_info.result
result
Definition: get_generator_info.py:21
IdDictRange::by_minmax
@ by_minmax
Definition: IdDictRange.h:40
index
Definition: index.py:1
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
IdDictRange::by_label
@ by_label
Definition: IdDictRange.h:38
IdDictDictionary.h
IdDictRange::m_field_name
std::string m_field_name
Definition: IdDictRange.h:31
IdDictRange::by_labels
@ by_labels
Definition: IdDictRange.h:39
athena.value
value
Definition: athena.py:124
Debugger.h
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
IdDictRange::m_specification
specification_type m_specification
Definition: IdDictRange.h:50
IdDictRegion
Definition: IdDictRegion.h:20
IdDictRange::m_field
IdDictField * m_field
Definition: IdDictRange.h:32
IdDictRange::generate_implementation
void generate_implementation(const IdDictMgr &idd, IdDictDictionary &dictionary, IdDictRegion &region, const std::string &tag="")
Definition: IdDictRange.cxx:63
IdDictRange::has_previous
@ has_previous
Definition: IdDictRange.h:46
IdDictMgr
Definition: IdDictMgr.h:14
beamspotnt.labels
list labels
Definition: bin/beamspotnt.py:1447
IdDictRegion::m_index
size_t m_index
Definition: IdDictRegion.h:43
IdDictRange::m_maxvalue
int m_maxvalue
Definition: IdDictRange.h:55
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdDictField::m_name
std::string m_name
Definition: IdDictField.h:28
IdDictRange::has_both
@ has_both
Definition: IdDictRange.h:47
IdDictRange::m_prev_value
int m_prev_value
Definition: IdDictRange.h:56
IdDictField::get_label_number
size_t get_label_number() const
Definition: IdDictField.cxx:41
IdDictRegion::fieldSize
size_t fieldSize() const
Definition: IdDictRegion.cxx:137
IdDictRange::unknown
@ unknown
Definition: IdDictRange.h:35
IdDictRange::m_value
int m_value
Definition: IdDictRange.h:53
Debugger::debug
static bool debug()
Definition: Debugger.h:18
IdDictField::get_label_value
ExpandedIdentifier::element_type get_label_value(const std::string &name) const
Definition: IdDictField.cxx:58
IdDictRegion::m_group
std::string m_group
Definition: IdDictRegion.h:45
master.dictionary
dictionary
Definition: master.py:47
IdDictField::get_label
const std::string get_label(size_t index) const
Definition: IdDictField.cxx:46
IdDictRegion::m_tag
std::string m_tag
Definition: IdDictRegion.h:46
IdDictRange::m_labels
std::vector< std::string > m_labels
Definition: IdDictRange.h:59
IdDictRange::has_next
@ has_next
Definition: IdDictRange.h:45
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition: DetectorDescription/Identifier/Identifier/Range.h:29
IdDictRange::m_continuation_mode
continuation_mode m_continuation_mode
Definition: IdDictRange.h:58
IdDictDictionary
Definition: IdDictDictionary.h:30
IdDictFieldImplementation.h
impl
Definition: CaloGPUClusterAndCellDataMonitorOptions.h:46
DeMoScan.index
string index
Definition: DeMoScan.py:364
IdDictRange::build_range
Range build_range() const
Definition: IdDictRange.cxx:124
IdDictField.h
IdDictRange::m_resolved_references
bool m_resolved_references
Definition: IdDictRange.h:63
IdentifierField
This is the individual specification for the range of one ExpandedIdentifier IdentifierField.
Definition: IdentifierField.h:21
IdDictRange::by_values
@ by_values
Definition: IdDictRange.h:37
IdDictRange::m_label
std::string m_label
Definition: IdDictRange.h:52
IdDictRegion.h
IdDictRange::by_value
@ by_value
Definition: IdDictRange.h:36
IdDictField
Definition: IdDictField.h:15
IdDictRange::wrap_around
@ wrap_around
Definition: IdDictRange.h:48
IdDictFieldImplementation
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
Definition: IdDictFieldImplementation.h:58
IdDictRange::resolve_references
void resolve_references(const IdDictMgr &idd, IdDictDictionary &dictionary, IdDictRegion &region)
Definition: IdDictRange.cxx:16
IdDictRegion::m_implementation
std::vector< IdDictFieldImplementation > m_implementation
Definition: IdDictRegion.h:42
IdDictRange::m_minvalue
int m_minvalue
Definition: IdDictRange.h:54
IdDictRange::m_next_value
int m_next_value
Definition: IdDictRange.h:57
IdDictRange::m_values
std::vector< int > m_values
Definition: IdDictRange.h:60