ATLAS Offline Software
Loading...
Searching...
No Matches
LArHVLineID.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
8#include "IdDict/IdDictMgr.h"
12#include <algorithm>
13#include <cassert>
14#include <cmath>
15#include <cstdio>
16#include <set>
17#include <string>
18
19
21 AtlasDetectorID("LArHVLineID", "LArHV"),
23 m_atlas_index(999),
26 m_canline_index(999),
27 m_cannode_index(999),
28 m_hvline_index(999),
29 m_dict(nullptr),
31{
32
33}
34
36
37
43
44/*
45IdContext LArHVLineID::canlineContext() const
46{
47 ExpandedIdentifier id;
48 return (IdContext(id, 0, m_canline_index));
49}
50*/
51
52//==========================================================================
54//==========================================================================
55{
56
57 ATH_MSG_INFO(" => initialize_from_dictionary()");
58
59 // Check whether this helper should be reinitialized
60 // -------------------------------------------------
61 if (!reinitialize(dict_mgr)) {
62 ATH_MSG_DEBUG("Request to reinitialize not satisfied - tags have not changed");
63 return (0);
64 }
65 else {
66 ATH_MSG_DEBUG("(Re)initialize");
67 }
68 ATH_MSG_DEBUG(" => Initialization of dict_mgr done ! " << m_dict);
69
70 // init base object
71 // ----------------
73 return (1);
74 }
75 else{
76 ATH_MSG_INFO(" => initialize_from_dictionary(dict_mgr) ="
78 }
79 m_dict = dict_mgr.find_dictionary ("LArHighVoltage");
80
81 if(!m_dict)
82 {
83 ATH_MSG_ERROR("initialize_from_dictionary - cannot access LArHighVoltage dictionary ");
84 return 1;
85 }
86
87 // Register version of the dictionary used
88 // ---------------------------------------
89 if (register_dict_tag(dict_mgr, "LArHighVoltage")) return(1);
90 ATH_MSG_INFO("Register_dict_tag of LArHighVoltage is OK");
91
92 // initialize dictionary version
93 // -----------------------------
94 AtlasDetectorID::setDictVersion(dict_mgr, "LArHighVoltage");
95 ATH_MSG_INFO("setDictVersion of LArHighVoltage is OK");
96
97
98 // Initialize the field indices
99 // =========================================================================
100 if(initLevelsFromDict()) return (1);
101
102 /* Find value for the field Calorimeter */
103 const IdDictDictionary* atlasDict = dict_mgr.find_dictionary ("ATLAS");
104 int larHVValue = -1;
105 if (atlasDict->get_label_value("subdet", "LArHighVoltage", larHVValue)) {
106 ATH_MSG_ERROR("Could not get value for label 'LArHighVoltage' of field 'subdet' in dictionary "
107 << atlasDict->name());
108 return (1);
109 }
110 ATH_MSG_DEBUG("[init_from_dictionary] > larHV value = " << larHVValue);
111
112
113 /* Find values for the field Configuration */
114 int configurationValue = 1;
115 if (m_dict->get_label_value("configuration", "Atlas", configurationValue)) {
116 ATH_MSG_WARNING("Could not get value for label 'configuration' in dictionary "
117 << m_dict->name());
118 return (0);
119 }
120 ATH_MSG_DEBUG("[init_from_dictionary] > configurationValue = " << configurationValue);
121
122 // Set up Expanded identifier for hvline range prefix
123 // =========================================================
124 ExpandedIdentifier reg_id;
125 reg_id.add(larHVValue);
126 reg_id.add(configurationValue);
127 Range prefix;
128
129 /*Full range for all lines */
130 m_full_atlas_highvoltage_range=m_dict->build_multirange(reg_id, prefix);
131 m_full_hvline_range = m_dict->build_multirange(reg_id, prefix, "hvline");
132 m_full_canline_range = m_dict->build_multirange(reg_id, prefix, "canline");
133 ATH_MSG_INFO("[initialize_from_dictionary] > HV line range -> " << (std::string)m_full_hvline_range);
134
135 // Setup the hash tables
136 // =========================================================
137 if(init_hashes()) return (1);
138
139 return 0;
140}
141
142
143//=====================================================================================
145 ExpandedIdentifier& exp_id,
146 const IdContext* context) const
147//=====================================================================================
148{
149 // We assume that the context is >= hvline
150 exp_id.clear();
151 exp_id << lar_field_value()
153 << partition(id)
154 << can_line(id)
155 << can_node(id)
156 << hv_line(id);
157 if(context && context->end_index() >= m_hvline_index) {
158 exp_id << hv_line(id);
159 }
160 return (0);
161}
162
163
164//=============================================================================
166//=============================================================================
167{
168 ATH_MSG_DEBUG("[initLevelsFromDict] Entering routine...");
169
170 if(!m_dict) {
171 ATH_MSG_INFO("LArHVLineID::initLevelsFromDict - dictionary NOT initialized");
172 return (1);
173 }
174
175 ATH_MSG_INFO("[initLevelsFromDict] m_dict OK ...");
176
177 // Find out which identifier field corresponds to each level.
178 // ========================================================================
179 m_atlas_index = 999;
181 m_partition_index = 999;
182 m_canline_index = 999;
183 m_cannode_index = 999;
184 m_hvline_index = 999;
185
186 ATH_MSG_DEBUG("[initLevelsFromDict] data member initialization OK ...");
187
188 // Search with region name
189 const IdDictRegion* reg = m_dict->find_region("LArHV-HEC-A");
190 if (reg) {
191 m_larhvRegion_index = reg->index();}
192 else {
193 ATH_MSG_INFO("WARNING : LArHVLineID::initLevelsFromDict - unable to find 'barrel-region1' region");
194 return (0);
195 }
196 ATH_MSG_DEBUG("[initLevelsFromDict] region 'LAr-HV-HEC-A' found OK ...");
197
198 // Find ATLAS field
199 // ========================================================================
200 const IdDictField* field = m_dict->find_field("subdet") ;
201 if (field) {
202 m_atlas_index = field->index();}
203 else {
204 ATH_MSG_INFO("LArHVLineID::initLevelsFromDict - unable to find 'subdet' field");
205 return (1);
206 }
207 ATH_MSG_DEBUG("[initLevelsFromDict] field 'LArHighVoltage' found OK");
208
209 // Find Configuration field
210 // ========================================================================
211 field = m_dict->find_field("configuration") ;
212 if (field) {
213 m_configuration_index = field->index();}
214 else {
215 ATH_MSG_INFO("LArHVLineID::initLevelsFromDict - unable to find 'configuration' field");
216 return (1);
217 }
218 ATH_MSG_DEBUG("[initLevelsFromDict] field config=Atlas found OK");
219
220 // Look for Field 'partition'
221 // ========================================================================
222 field = m_dict->find_field("partition") ;
223 if (field) {
224 m_partition_index = field->index();}
225 else {
226 ATH_MSG_INFO("LArHVLineID::initLevelsFromDict - unable to find 'partition' field");
227 return (1);
228 }
229 ATH_MSG_DEBUG("[initLevelsFromDict] field 'partition' found OK");
230
231
232 // Look for Field 'CAN LINE'
233 // ========================================================================
234 field = m_dict->find_field("canline") ;
235 if (field) {
236 m_canline_index = field->index();}
237 else {
238 ATH_MSG_INFO("LArHVLineID::initLevelsFromDict - unable to find 'canline' field");
239 return (1);
240 }
241 ATH_MSG_DEBUG("[initLevelsFromDict] field 'canline' found OK");
242
243
244 // Look for Fields 'CAN NODE'
245 // ========================================================================
246 field = m_dict->find_field("cannode") ;
247 if (field) {
248 m_cannode_index = field->index();
249 }
250 else {
251 ATH_MSG_INFO("LArHVLineID::initLevelsFromDict - unable to find 'cannode' field");
252 return (1);
253 }
254 ATH_MSG_DEBUG("[initLevelsFromDict] field 'cannode' found OK");
255
256
257 // Look for Fields 'HV_line'
258 // ========================================================================
259 field = m_dict->find_field("hvline") ;
260 if (field) {
261 m_hvline_index = field->index();
262 }
263 else {
264 ATH_MSG_INFO("LArHVLineID::initLevelsFromDict - unable to find 'hvline' field");
265 return (1);
266 }
267 ATH_MSG_DEBUG("[initLevelsFromDict] field 'hvline' found OK");
268
269
270 // Set the field implementation
271 // ========================================================================
272
273 const IdDictRegion& region = m_dict->region(m_larhvRegion_index);
274 ATH_MSG_DEBUG("[initLevelsFromDict] Found levels:");
275 ATH_MSG_DEBUG("[initLevelsFromDict] > larHV " << m_atlas_index);
276 ATH_MSG_DEBUG("[initLevelsFromDict] > larConfiguration " << m_configuration_index);
277 ATH_MSG_DEBUG("[initLevelsFromDict] > CAN Node " << m_cannode_index);
278 ATH_MSG_DEBUG("[initLevelsFromDict] > HV line " << m_hvline_index);
279 ATH_MSG_DEBUG("[initLevelsFromDict] > partition " << m_partition_index);
280 ATH_MSG_DEBUG("[initLevelsFromDict] > CAN line " << m_canline_index);
281
282
283 ATH_MSG_DEBUG("[initLevelsFromDict] > ...fields implementation...");
284 ATH_MSG_DEBUG("[initLevelsFromDict] > ...implementation: m_larhvcalo_index");
291
292 ATH_MSG_DEBUG("[initLevelsFromDict] Decode index and bit fields for each level:");
293 ATH_MSG_DEBUG("[initLevelsFromDict] > larHV " << m_atlas_impl.show_to_string());
294 ATH_MSG_DEBUG("[initLevelsFromDict] > larConfig " << m_configuration_impl.show_to_string());
295 ATH_MSG_DEBUG("[initLevelsFromDict] > partition " << m_partition_impl.show_to_string());
296 ATH_MSG_DEBUG("[initLevelsFromDict] > can line " << m_canline_impl.show_to_string());
297 ATH_MSG_DEBUG("[initLevelsFromDict] > can node " << m_cannode_impl.show_to_string());
298 ATH_MSG_DEBUG("[initLevelsFromDict] > hv line " << m_hvline_impl.show_to_string());
299
300
301 return(0) ;
302}
303
304
305
306
307//=====================================================
309//=====================================================
310{
311 // tower hash
312 // -----------
315 unsigned int nids = 0;
316 std::set<HWIdentifier> ids;
317 for (unsigned int i = 0; i < m_full_atlas_highvoltage_range.size(); ++i) {
318 const Range& range = m_full_atlas_highvoltage_range[i];
319 ConstRangeIterator rit(range);
320 for (const auto & exp_id :rit) {
321 HWIdentifier hv_id = HVLineId(
322 exp_id[m_partition_index] ,
323 exp_id[m_canline_index] ,
324 exp_id[m_cannode_index] ,
325 exp_id[m_hvline_index]
326 );
327 if(!(ids.insert(hv_id)).second){
328 ATH_MSG_ERROR("[init_hashes] > duplicated id for channel nb = " << nids);
329 ATH_MSG_ERROR(" expanded Id= " << show_to_string(hv_id));
330 }
331 nids++;
332 }
333 }
334 if(ids.size() != m_hvlineHashMax) {
335 ATH_MSG_ERROR("[init_hashes] >");
336 ATH_MSG_ERROR(" set size NOT EQUAL to hash max. size " << ids.size());
337 ATH_MSG_ERROR(" hash max " << m_hvlineHashMax);
338 return (1);
339 }
340
341 nids=0;
342 std::set<HWIdentifier>::const_iterator first = ids.begin();
343 std::set<HWIdentifier>::const_iterator last = ids.end();
344 for (;first != last && nids < m_hvline_vec.size(); ++first) {
345 m_hvline_vec[nids] = (*first) ;
346 nids++;
347 }
348 ATH_MSG_INFO("[init_hashes()] > Hvline_size= " << m_hvline_vec.size());
349 return (0);
350}
351
352
353
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static const int s_lar_atlas_value
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
bool reinitialize(const IdDictMgr &dict_mgr)
Test whether an idhelper should be reinitialized based on the change of tags.
virtual void setDictVersion(const IdDictMgr &dict_mgr, const std::string &name) override
int register_dict_tag(const IdDictMgr &dict_mgr, const std::string &dict_name)
Register the file and tag names for a particular IdDict dictionary.
int lar_field_value() const
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
AtlasDetectorID(const std::string &name, const std::string &group)
void add(element_type value)
Append a value into a new field.
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
int get_label_value(const std::string &field, const std::string &label, int &value) const
const std::string & name() const
Dictionary name.
const IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
const IdDictFieldImplementation & implementation(size_t i) const
size_type m_canline_index
size_type m_atlas_index
virtual ~LArHVLineID()
size_type m_partition_index
IdDictFieldImplementation m_partition_impl
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
Initialization from the identifier dictionary.
IdDictFieldImplementation m_canline_impl
MultiRange m_full_atlas_highvoltage_range
const IdDictDictionary * m_dict
size_type m_configuration_index
int can_node(const HWIdentifier id) const
Return the CAN node from an HighVoltage line identifier.
LArHVLineID()
only allowed constructor
IdDictFieldImplementation m_atlas_impl
Field Implementation.
IdDictFieldImplementation m_hvline_impl
size_type m_hvlineHashMax
int can_line(const HWIdentifier id) const
Return the CAN line from an HighVoltage line identifier.
int get_expanded_id(const HWIdentifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
std::vector< HWIdentifier > m_hvline_vec
int initLevelsFromDict()
IdContext hvlineContext() const
int partition(const HWIdentifier id) const
Return the partition from an HighVoltage line identifier.
IdDictFieldImplementation m_cannode_impl
size_type m_larhvRegion_index
size_type m_cannode_index
IdDictFieldImplementation m_configuration_impl
MultiRange m_full_canline_range
int hv_line(const HWIdentifier id) const
Return the HV line number from an HighVoltage line identifier.
size_type m_hvline_index
MultiRange m_full_hvline_range
HWIdentifier HVLineId(int part, int canline, int cannode, int line) const
Create an HighVoltage line identifier from fields.
A Range describes the possible ranges for the field values of an ExpandedIdentifier.