ATLAS Offline Software
Loading...
Searching...
No Matches
LArElectrodeID.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("LArElectrodeID", "LArElec"),
24 m_atlas_index(999),
27 m_zside_index(999),
28 m_module_index(999),
29 m_hvphi_index(999),
30 m_hveta_index(999),
31 m_hvgap_index(999),
33 m_dict(nullptr),
35{
36
37}
38
40
41
47
48
49//==========================================================================
51//==========================================================================
52{
53
54 ATH_MSG_INFO(" => initialize_from_dictionary()");
55
56 // Check whether this helper should be reinitialized
57 // -------------------------------------------------
58 if (!reinitialize(dict_mgr)) {
59 ATH_MSG_DEBUG("Request to reinitialize not satisfied - tags have not changed");
60 return (0);
61 }
62 else {
63 ATH_MSG_DEBUG("(Re)initialize");
64 }
65 ATH_MSG_DEBUG(" => Initialization of dict_mgr done ! " << m_dict);
66
67 // init base object
68 // ----------------
70 return (1);
71 }
72 else{
73 ATH_MSG_DEBUG(" => initialize_from_dictionary(dict_mgr) ="
75 }
76 m_dict = dict_mgr.find_dictionary ("LArElectrode");
77 ATH_MSG_DEBUG(" => defined m_dict from find_dictionary(LArElectrode) = " << m_dict);
78 if(!m_dict) {
79 ATH_MSG_ERROR("initialize_from_dictionary - cannot access LArElectrode dictionary");
80 return 1;
81 }
82
83 // Register version of the dictionary used
84 // ---------------------------------------
85 if (register_dict_tag(dict_mgr, "LArElectrode")) return(1);
86 ATH_MSG_DEBUG("Register_dict_tag of LArElectrode is OK");
87
88 // initialize dictionary version
89 // -----------------------------
90 AtlasDetectorID::setDictVersion(dict_mgr, "LArElectrode");
91 ATH_MSG_DEBUG("setDictVersion of LArElectrode is OK");
92
93
94 // Initialize the field indices
95 // =========================================================================
96 if(initLevelsFromDict()) return (1);
97
98 /* Find value for the field Calorimeter */
99 const IdDictDictionary* atlasDict = dict_mgr.find_dictionary ("ATLAS");
100 int larField = -1;
101 if (atlasDict->get_label_value("subdet", "LArElectrode", larField)) {
102 ATH_MSG_ERROR("Could not get value for label 'LArElectrode' of field 'subdet' in dictionary "
103 << atlasDict->name());
104 return (1);
105 }
106 ATH_MSG_DEBUG("[init_from_dictionary] > larField value = " << larField);
107
108
109 /* Find values for the field Detector */
110 int configurationValue = 1;
111 if (m_dict->get_label_value("configuration", "Atlas", configurationValue)) {
112 ATH_MSG_WARNING("Could not get value for label 'configuration' in dictionary "
113 << m_dict->name());
114 return (0);
115 }
116 ATH_MSG_DEBUG("[init_from_dictionary] > configurationValue = " << configurationValue);
117
118 // Set up Expanded identifier for electrode range prefix
119 // =========================================================
120 ExpandedIdentifier reg_id;
121 reg_id.add(larField);
122 reg_id.add(configurationValue);
123 Range prefix;
124
125 /*Full range for all lines */
126 m_full_larelectrode_range=m_dict->build_multirange(reg_id, prefix);
127 m_full_electrode_range = m_dict->build_multirange(reg_id, prefix, "electrode");
128 ATH_MSG_DEBUG("[initialize_from_dictionary] > Electrode range -> "
129 << (std::string)m_full_electrode_range);
130
131 // Setup the hash tables
132 // =========================================================
133 if(init_hashes()) return (1);
134
135 return 0;
136}
137
138
139//=====================================================================================
141 ExpandedIdentifier& exp_id,
142 const IdContext* context) const
143//=====================================================================================
144{
145 // We assume that the context is >= electrode
146 exp_id.clear();
147 exp_id << lar_field_value()
149 << detector(id)
150 << zside(id)
151 << module(id)
152 << hv_phi(id)
153 << hv_eta(id)
154 << gap(id);
155 if(context && context->end_index() >= m_electrode_index) {
156 exp_id << electrode(id);
157 }
158 return (0);
159}
160
161
162
163//=============================================================================
165//=============================================================================
166{
167 ATH_MSG_DEBUG("[initLevelsFromDict] Entering routine...");
168
169 if(!m_dict) {
170 ATH_MSG_INFO("LArElectrodeID::initLevelsFromDict - dictionary NOT initialized");
171 return (1);
172 }
173
174 ATH_MSG_DEBUG("[initLevelsFromDict] m_dict OK ...");
175
176 // Find out which identifier field corresponds to each level.
177 // ========================================================================
178 m_atlas_index = 999;
180 m_detector_index = 999;
181 m_zside_index = 999;
182 m_module_index = 999;
183 m_hvphi_index = 999;
184 m_hveta_index = 999;
185 m_hvgap_index = 999;
186 m_electrode_index = 999;
187 ATH_MSG_DEBUG("[initLevelsFromDict] data member initialization OK ...");
188
189 // Search with region name
190 const IdDictRegion* reg = m_dict->find_region("EM-BARREL-ALL");
191 if (reg) {
192 m_larElectrodeRegion_index = reg->index();}
193 else {
194 ATH_MSG_WARNING("[initLevelsFromDict] - unable to find 'EM-BARREL-ALL' region");
195 return (0);
196 }
197 ATH_MSG_DEBUG("[initLevelsFromDict] region 'EM-BARREL-ALL' found OK ...");
198
199 // Find LArElectrode field
200 // ========================================================================
201 const IdDictField* field = m_dict->find_field("subdet") ;
202 if (field) {
203 m_atlas_index = field->index();}
204 else {
205 ATH_MSG_INFO("LArElectrodeID::initLevelsFromDict - unable to find 'subdet' field");
206 return (1);
207 }
208 ATH_MSG_DEBUG("[initLevelsFromDict] field 'LArElectrode' found OK");
209
210 // Find Configuration field
211 // ========================================================================
212 field = m_dict->find_field("configuration") ;
213 if (field) {
214 m_configuration_index = field->index();}
215 else {
216 ATH_MSG_INFO("LArHVLineID::initLevelsFromDict - unable to find 'configuration' field");
217 return (1);
218 }
219 ATH_MSG_DEBUG("[initLevelsFromDict] field config=Atlas found OK");
220
221 // Find Detector field
222 // ========================================================================
223 field = m_dict->find_field("detector") ;
224 if (field) {
225 m_detector_index = field->index();}
226 else {
227 ATH_MSG_INFO("LArElectrodeID::initLevelsFromDict - unable to find 'detector' field");
228 return (1);
229 }
230 ATH_MSG_DEBUG("[initLevelsFromDict] field 'detector' found OK");
231
232
233 // Look for Field 'zside'
234 // ========================================================================
235 field = m_dict->find_field("zside") ;
236 if (field) {
237 m_zside_index = field->index();}
238 else {
239 ATH_MSG_INFO("LArElectrodeID::initLevelsFromDict - unable to find 'zside' field");
240 return (1);
241 }
242 ATH_MSG_DEBUG("[initLevelsFromDict] field 'zside' found OK");
243
244
245 // Look for Fields 'module'
246 // ========================================================================
247 field = m_dict->find_field("module") ;
248 if (field) {
249 m_module_index = field->index();
250 }
251 else {
252 ATH_MSG_INFO("LArElectrodeID::initLevelsFromDict - unable to find 'module' field");
253 return (1);
254 }
255 ATH_MSG_DEBUG("[initLevelsFromDict] field 'module' found OK");
256
257 // Look for Fields 'hvphi'
258 // ========================================================================
259 field = m_dict->find_field("hvphi") ;
260 if (field) {
261 m_hvphi_index = field->index();
262 }
263 else {
264 ATH_MSG_INFO("initLevelsFromDict - unable to find 'hvphi' field");
265 return (1);
266 }
267 ATH_MSG_DEBUG("[initLevelsFromDict] field 'hvphi' found OK");
268
269 // Look for Fields 'hveta'
270 // ========================================================================
271 field = m_dict->find_field("hveta") ;
272 if (field) {
273 m_hveta_index = field->index();
274 }
275 else {
276 ATH_MSG_INFO("[initLevelsFromDict] - unable to find 'hveta' field");
277 return (1);
278 }
279 ATH_MSG_DEBUG("[initLevelsFromDict] field 'hveta' found OK");
280
281 // Look for Fields 'hvgap'
282 // ========================================================================
283 field = m_dict->find_field("hvgap") ;
284 if (field) {
285 m_hvgap_index = field->index();
286 }
287 else {
288 ATH_MSG_INFO("[initLevelsFromDict] - unable to find 'hvgap' field");
289 return (1);
290 }
291 ATH_MSG_DEBUG("[initLevelsFromDict] field 'hvgap' found OK");
292
293
294 // Look for Fields 'electrode'
295 // ========================================================================
296 field = m_dict->find_field("electrode") ;
297 if (field) {
298 m_electrode_index = field->index();
299 }
300 else {
301 ATH_MSG_INFO("[initLevelsFromDict] - unable to find 'electrode' field");
302 return (1);
303 }
304 ATH_MSG_DEBUG("[initLevelsFromDict] field 'electrode' found OK");
305
306
307 // Set the field implementation
308 // ========================================================================
309
310 const IdDictRegion& region = m_dict->region(m_larElectrodeRegion_index);
311 ATH_MSG_DEBUG("[initLevelsFromDict] Found levels:");
312 ATH_MSG_DEBUG("[initLevelsFromDict] > Atlas : " << m_atlas_index);
313 ATH_MSG_DEBUG("[initLevelsFromDict] > Configurat: " << m_configuration_index);
314 ATH_MSG_DEBUG("[initLevelsFromDict] > detector : " << m_detector_index);
315 ATH_MSG_DEBUG("[initLevelsFromDict] > zside : " << m_zside_index);
316 ATH_MSG_DEBUG("[initLevelsFromDict] > hvphi : " << m_hvphi_index);
317 ATH_MSG_DEBUG("[initLevelsFromDict] > hveta : " << m_hveta_index);
318 ATH_MSG_DEBUG("[initLevelsFromDict] > hvgap : " << m_hvgap_index);
319 ATH_MSG_DEBUG("[initLevelsFromDict] > electrode : " << m_electrode_index);
329
330 ATH_MSG_DEBUG("[initLevelsFromDict] Decode index and bit fields for each level:");
331 ATH_MSG_DEBUG("[initLevelsFromDict] > Atlas " << m_atlas_impl.show_to_string());
332 ATH_MSG_DEBUG("[initLevelsFromDict] > larConfig " << m_configuration_impl.show_to_string());
333 ATH_MSG_DEBUG("[initLevelsFromDict] > detector " << m_detector_impl.show_to_string());
334 ATH_MSG_DEBUG("[initLevelsFromDict] > z-side " << m_zside_impl.show_to_string());
335 ATH_MSG_DEBUG("[initLevelsFromDict] > module " << m_module_impl.show_to_string());
336 ATH_MSG_DEBUG("[initLevelsFromDict] > hvphi " << m_hvphi_impl.show_to_string());
337 ATH_MSG_DEBUG("[initLevelsFromDict] > hveta " << m_hveta_impl.show_to_string());
338 ATH_MSG_DEBUG("[initLevelsFromDict] > hvgap " << m_hvgap_impl.show_to_string());
339 ATH_MSG_DEBUG("[initLevelsFromDict] > hv line " << m_electrode_impl.show_to_string());
340
341
342 return(0) ;
343}
344
345
346
347
348//=====================================================
350//=====================================================
351{
352 // tower hash
353 // -----------
356 unsigned int nids = 0;
357 std::set<HWIdentifier> ids;
358 for (unsigned int i = 0; i < m_full_larelectrode_range.size(); ++i) {
359 const Range& range = m_full_larelectrode_range[i];
360 ConstRangeIterator rit(range);
361 for (const auto & exp_id :rit) {
362 HWIdentifier elec_id = ElectrodeId(
363 exp_id[m_detector_index] ,
364 exp_id[m_zside_index] ,
365 exp_id[m_module_index] ,
366 exp_id[m_hvphi_index] ,
367 exp_id[m_hveta_index] ,
368 exp_id[m_hvgap_index] ,
369 exp_id[m_electrode_index]
370 );
371 if(!(ids.insert(elec_id)).second){
372 ATH_MSG_ERROR("[init_hashes] > duplicated id for channel nb = " << nids);
373 ATH_MSG_ERROR(" expanded Id= " << show_to_string(elec_id));
374 }
375 nids++;
376 }
377 }
378 if(ids.size() != m_electrodeHashMax) {
379 ATH_MSG_ERROR("[init_hashes] >");
380 ATH_MSG_ERROR(" set size NOT EQUAL to hash max. size " << ids.size());
381 ATH_MSG_ERROR(" hash max " << m_electrodeHashMax);
382 return (1);
383 }
384
385 nids=0;
386 std::set<HWIdentifier>::const_iterator first = ids.begin();
387 std::set<HWIdentifier>::const_iterator last = ids.end();
388 for (;first != last && nids < m_electrode_vec.size(); ++first) {
389 m_electrode_vec[nids] = (*first) ;
390 nids++;
391 }
392 ATH_MSG_DEBUG("[init_hashes()] > Electrode_size= " << m_electrode_vec.size());
393 return (0);
394}
395
396
397
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
static const int s_larconfig_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
IdDictFieldImplementation m_atlas_impl
Field Implementation.
size_type m_detector_index
IdDictFieldImplementation m_hveta_impl
IdDictFieldImplementation m_hvphi_impl
IdDictFieldImplementation m_detector_impl
size_type m_electrode_index
IdDictFieldImplementation m_configuration_impl
IdDictFieldImplementation m_hvgap_impl
size_type m_larelectrode_index
size_type m_hvphi_index
MultiRange m_full_larelectrode_range
IdContext electrodeContext() const
Define feedthrough Context.
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
Initialization from the identifier dictionary.
size_type m_atlas_index
virtual ~LArElectrodeID()
Default destructor.
IdDictFieldImplementation m_electrode_impl
size_type m_configuration_index
IdDictFieldImplementation m_zside_impl
size_type m_larElectrodeRegion_index
HWIdentifier ElectrodeId(int det, int side, int mod, int phi, int eta, int gap, int elec) const
Create an Electrode identifier from fields.
int hv_eta(const HWIdentifier id) const
Return an integer corresponding to the high volatge eta sector of an hardware electrode identifier.
LArElectrodeID()
Default constructor.
int zside(const HWIdentifier id) const
Return an integer corresponding to the side of an hardware electrode identifier.
size_type m_hveta_index
std::vector< HWIdentifier > m_electrode_vec
int get_expanded_id(const HWIdentifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
int gap(const HWIdentifier id) const
Return an integer corresponding to the cell gap of an hardware electrode identifier.
size_type m_module_index
size_type m_electrodeHashMax
const IdDictDictionary * m_dict
int electrode(const HWIdentifier id) const
Return an integer corresponding to the electrode number of an hardware electrode identifier.
size_type m_hvgap_index
int detector(const HWIdentifier id) const
Return an integer corresponding to the detector of an hardware electrode identifier.
IdDictFieldImplementation m_module_impl
MultiRange m_full_electrode_range
size_type m_zside_index
int hv_phi(const HWIdentifier id) const
Return an integer corresponding to the high voltage phi sector of an hardware electrode identifier.
A Range describes the possible ranges for the field values of an ExpandedIdentifier.