ATLAS Offline Software
Loading...
Searching...
No Matches
ZdcID.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 <set>
13#include <iostream>
14
15//______________________________________________________
17 : AtlasDetectorID("ZdcID", "ZDC"),
18 m_dict(nullptr)
19{
20}
21//______________________________________________________
23
24}
25
26int
28{
29 ATH_MSG_INFO("Initialize from dictionary");
30
31 // Check whether this helper should be reinitialized
32 if (!reinitialize(dict_mgr)) {
33 ATH_MSG_INFO("Request to reinitialize not satisfied - tags have not changed");
34 return (0);
35 }
36 else {
37 ATH_MSG_DEBUG("(Re)initialize");
38 }
39
40 // init base object
41 if(AtlasDetectorID::initialize_from_dictionary(dict_mgr)) return (1);
42
43 // Register version of ForwardDetectors dictionary
44 if (register_dict_tag(dict_mgr, "ForwardDetectors")) return(1);
45
46 m_dict = dict_mgr.find_dictionary ("ForwardDetectors");
47 if(!m_dict) {
48 ATH_MSG_ERROR("ZdcID::initialize_from_dict - cannot access ForwardDetectors dictionary");
49 return 1;
50 }
51
52 // Initialize the field indices
53 if(initLevelsFromDict()) return (1);
54
55
56 //
57 // Build multirange for the valid set of identifiers
58 //
59
60
61 // Find value for the field ForwardDetectors
62 const IdDictDictionary* atlasDict = dict_mgr.find_dictionary ("ATLAS");
63 int fwdField = -1;
64 if (atlasDict->get_label_value("subdet", "ForwardDetectors", fwdField)) {
65 ATH_MSG_ERROR("Could not get value for label 'ForwardDetectors' of field 'subdet' in dictionary "
66 << atlasDict->name());
67 return (1);
68 }
69
70 // Find value for the field ZDC
71 int zdcField = -1;
72 if (m_dict->get_label_value("part", "ZDC", zdcField)) {
73 ATH_MSG_ERROR("Could not get value for label 'ZDC' of field 'part' in dictionary "
74 << m_dict->name());
75 return (1);
76 }
77 ATH_MSG_DEBUG("ZdcID::initialize_from_dict "
78 << "Found field values: ZDC " << zdcField);
79
80 // Set up id for region and range prefix
81 ExpandedIdentifier region_id;
82 region_id.add(fwdField);
83 region_id.add(zdcField);
84 Range prefix;
85 m_full_module_range = m_dict->build_multirange(region_id, prefix, "module");
86 m_full_channel_range = m_dict->build_multirange(region_id, prefix);
87
88 ATH_MSG_INFO("ZdcID::initialize_from_dict");
89 ATH_MSG_DEBUG("Module range -> " << (std::string)m_full_module_range);
90 ATH_MSG_DEBUG("Channel range -> " << (std::string)m_full_channel_range);
91
92 // Setup the hash tables
93 if(init_hashes()) return (1);
94
95 return 0;
96}
97
98
99
100int
102{
103 if(!m_dict) {
104 ATH_MSG_ERROR("ZdcID::initLevelsFromDict - dictionary NOT initialized");
105 return (1);
106 }
107
108 // Find out which identifier field corresponds to each level. Use
109 // names to find each field/level.
110
111 m_zdc_region_index = 999;
112 m_FORWARD_INDEX = 999;
113 m_ZDC_INDEX = 999;
114 m_SIDE_INDEX = 999;
115 m_MODULE_INDEX = 999;
116 m_TYPE_INDEX = 999;
117 m_CHANNEL_INDEX = 999;
118
119 // Save index to a ZDC region for unpacking
122 if (m_dict->find_region(id, m_zdc_region_index)) {
123 ATH_MSG_ERROR("ZdcID::initLevelsFromDict - unable to find zdc region index: id, reg "
124 << (std::string)id << " " << m_zdc_region_index);
125 return (1);
126 }
127
128 // Find a ZDC region
129 const IdDictField* field = m_dict->find_field("subdet");
130 if (field) {
131 m_FORWARD_INDEX = field->index();
132 }
133 else {
134 ATH_MSG_ERROR("ZdcID::initLevelsFromDict - unable to find 'subdet' field");
135 return (1);
136 }
137 field = m_dict->find_field("part");
138 if (field) {
139 m_ZDC_INDEX = field->index();
140 }
141 else {
142 ATH_MSG_ERROR("ZdcID::initLevelsFromDict - unable to find 'part' field");
143 return (1);
144 }
145 field = m_dict->find_field("side");
146 if (field) {
147 m_SIDE_INDEX = field->index();
148 }
149 else {
150 ATH_MSG_ERROR("ZdcID::initLevelsFromDict - unable to find 'side' field");
151 return (1);
152 }
153 field = m_dict->find_field("module");
154 if (field) {
155 m_MODULE_INDEX = field->index();
156 }
157 else {
158 ATH_MSG_ERROR("ZdcID::initLevelsFromDict - unable to find 'module' field");
159 return (1);
160 }
161 field = m_dict->find_field("type");
162 if (field) {
163 m_TYPE_INDEX = field->index();
164 }
165 else {
166 ATH_MSG_ERROR("ZdcID::initLevelsFromDict - unable to find 'type' field");
167 return (1);
168 }
169 field = m_dict->find_field("channel");
170 if (field) {
171 m_CHANNEL_INDEX = field->index();
172 }
173 else {
174 ATH_MSG_ERROR("ZdcID::initLevelsFromDict - unable to find 'channel' field");
175 return (1);
176 }
177
178 // Set the field implementations: for bec, lay/disk, eta/phi mod
179
180 const IdDictRegion& region = m_dict->region(m_zdc_region_index);
181
188
189 ATH_MSG_DEBUG("decode index and bit fields for each level:");
190 ATH_MSG_DEBUG("forward " << m_forward_impl.show_to_string());
191 ATH_MSG_DEBUG("zdc " << m_zdc_impl.show_to_string());
192 ATH_MSG_DEBUG("side " << m_side_impl.show_to_string());
193 ATH_MSG_DEBUG("module " << m_module_impl.show_to_string());
194 ATH_MSG_DEBUG("type " << m_type_impl.show_to_string());
195 ATH_MSG_DEBUG("channel " << m_channel_impl.show_to_string());
196
197 return (0);
198
199}
200
201
202int
204{
205 //
206 // create a vector(s) to retrieve the hashes for compact ids.
207 //
208
209 // module hash
212 unsigned int nids = 0;
213 std::set<Identifier> ids;
214 for (unsigned int i = 0; i < m_full_module_range.size(); ++i) {
215 const Range& range = m_full_module_range[i];
216 ConstRangeIterator rit(range);
217 auto first = rit.begin();
218 auto last = rit.end();
219 for (; first != last; ++first) {
220 const ExpandedIdentifier& exp_id = (*first);
221 Identifier id = module_id(exp_id[m_SIDE_INDEX],
222 exp_id[m_MODULE_INDEX]);
223 if(!(ids.insert(id)).second) {
224 ATH_MSG_ERROR("ZDC_ID::init_hashes "
225 << " Error: duplicated id for module id. nid " << nids
226 << " compact id " << MSG::hex << id.get_compact() << MSG::dec
227 << " id " << (std::string)exp_id);
228 return (1);
229 }
230 nids++;
231 }
232 }
233 if(ids.size() != m_module_hash_max) {
234 ATH_MSG_ERROR("ZDC_ID::init_hashes "
235 << " Error: set size NOT EQUAL to hash max. size " << ids.size()
236 << " hash max " << m_module_hash_max);
237 return (1);
238 }
239
240 nids = 0;
241 std::set<Identifier>::const_iterator first = ids.begin();
242 std::set<Identifier>::const_iterator last = ids.end();
243 for (; first != last && nids < m_module_vec.size(); ++first) {
244 m_module_vec[nids] = (*first);
245 nids++;
246 }
247
248 // channel hash
251 nids = 0;
252 ids.clear();
253 for (unsigned int i = 0; i < m_full_channel_range.size(); ++i) {
254 const Range& range = m_full_channel_range[i];
255 ConstRangeIterator rit(range);
256 auto first = rit.begin();
257 auto last = rit.end();
258 for (; first != last; ++first) {
259 const ExpandedIdentifier& exp_id = (*first);
261 exp_id[m_MODULE_INDEX],
262 exp_id[m_TYPE_INDEX],
263 exp_id[m_CHANNEL_INDEX]);
264
265 if(!(ids.insert(id)).second) {
266 ATH_MSG_ERROR("ZDC_ID::init_hashes "
267 << " Error: duplicated id for channel id. nid " << nids
268 << " compact id " << MSG::hex << id.get_compact() << MSG::dec
269 << " id " << (std::string)exp_id);
270 return (1);
271 }
272 nids++;
273 }
274 }
275 if(ids.size() != m_channel_hash_max) {
276 ATH_MSG_ERROR("ZDC_ID::init_hashes "
277 << " Error: set size NOT EQUAL to hash max. size " << ids.size()
278 << " hash max " << m_channel_hash_max);
279 return (1);
280 }
281
282 nids = 0;
283 first = ids.begin();
284 last = ids.end();
285 for (; first != last && nids < m_channel_vec.size(); ++first) {
286 m_channel_vec[nids] = (*first);
287 nids++;
288 }
289 return (0);
290}
291
292void
294{
295 if (m_dict) {
296
297 int nids = 0;
298 int nerr = 0;
300 const_id_iterator first = m_module_vec.begin();
301 const_id_iterator last = m_module_vec.end();
302 for (; first != last; ++first, ++nids) {
303 Identifier id = (*first);
304 Identifier new_id = module_id(side(id),
305 module(id));
306 if (id != new_id) {
307 ATH_MSG_ERROR("ZDC_ID::test_packing: new and old compacts not equal. New/old/expanded ids "
308 << show_to_string(id) << " " << show_to_string(new_id));
309 nerr++;
310 continue;
311 }
312 IdentifierHash idHash = module_hash(id);
313 Identifier new_id_1 = module_id(idHash);
314 if (id != new_id_1) {
315 ATH_MSG_ERROR("ZDC_ID::test_packing: new and old compacts from hash not equal. New/old/expanded ids. hash " << idHash << " "
316 << show_to_string(id) << " " << show_to_string(new_id_1));
317 nerr++;
318 continue;
319 }
320 }
321
322 ATH_MSG_DEBUG("ZDC_ID::test_packing: tested module ids. nids, errors "
323 << nids << " " << nerr);
324
325 first = m_channel_vec.begin();
326 last = m_channel_vec.end();
327 for (; first != last; ++first, ++nids) {
328 Identifier id = (*first);
329 Identifier new_id = channel_id(side(id),
330 module(id),
331 type(id),
332 channel(id));
333 if (id != new_id) {
334 ATH_MSG_ERROR("ZDC_ID::test_packing: new and old compacts not equal. New/old/expanded ids "
335 << show_to_string(id) << " " << show_to_string(new_id));
336 nerr++;
337 continue;
338 }
339 IdentifierHash idHash = channel_hash(id);
340 Identifier new_id_1 = channel_id(idHash);
341 if (id != new_id_1) {
342 ATH_MSG_ERROR("ZDC_ID::test_packing: new and old compacts from hash not equal. New/old/expanded ids hash " << idHash << " "
343 << show_to_string(id) << " " << show_to_string(new_id_1));
344 nerr++;
345 continue;
346 }
347 }
348
349 ATH_MSG_DEBUG("ZDC_ID::test_packing: tested channel ids. nids, errors "
350 << nids << " " << nerr);
351
352 ATH_MSG_DEBUG("ZDC_ID::test_packing: Successfully tested "
353 << nids << " ids.");
354 }
355 else {
356 ATH_MSG_ERROR("ZDC_ID::test_packing: Unable to test module/channel is packing - no dictionary has been defined.");
357 }
358}
359
361{
362 return (m_module_vec.begin());
363}
364
366{
367 return (m_module_vec.end());
368}
369
371{
372 return (m_channel_vec.begin());
373}
374
376{
377 return (m_channel_vec.end());
378}
379
380
381
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
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.
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 forward_field_value() const
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
int zdc_field_value() const
AtlasDetectorID(const std::string &name, const std::string &group)
ConstRangeIterator end() const
ConstRangeIterator begin() const
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
This is a "hash" representation of an Identifier.
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
IdDictFieldImplementation m_forward_impl
Definition ZdcID.h:119
id_vec m_module_vec
Definition ZdcID.h:116
~ZdcID()
Definition ZdcID.cxx:22
Identifier module_id(int side, int module) const
Definition ZdcID.h:182
ZdcID()
Definition ZdcID.cxx:16
MultiRange m_full_channel_range
Definition ZdcID.h:113
IdentifierHash module_hash(Identifier module_id) const
module hash from id - optimized
Definition ZdcID.h:134
size_type m_FORWARD_INDEX
Definition ZdcID.h:105
IdDictFieldImplementation m_zdc_impl
Definition ZdcID.h:120
size_type m_channel_hash_max
Definition ZdcID.h:115
int side(const Identifier &id) const
Values of different levels (failure returns 0)
Definition ZdcID.h:157
const_id_iterator modules_end() const
Definition ZdcID.cxx:365
size_type m_SIDE_INDEX
Definition ZdcID.h:107
size_type m_module_hash_max
Definition ZdcID.h:114
size_type m_zdc_region_index
Definition ZdcID.h:104
std::vector< Identifier >::const_iterator const_id_iterator
Definition ZdcID.h:30
const IdDictDictionary * m_dict
Definition ZdcID.h:111
void test_packing() const
Tests of packing.
Definition ZdcID.cxx:293
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
Initialization from the identifier dictionary.
Definition ZdcID.cxx:27
MultiRange m_full_module_range
Definition ZdcID.h:112
size_type m_ZDC_INDEX
Definition ZdcID.h:106
const_id_iterator modules_begin() const
Iterators over full set of ids. modules iterator is sorted.
Definition ZdcID.cxx:360
const_id_iterator channels_begin() const
Iterators over full set of ids. channels iterator is sorted.
Definition ZdcID.cxx:370
int type(const Identifier &id) const
Definition ZdcID.h:169
IdDictFieldImplementation m_side_impl
Definition ZdcID.h:121
id_vec m_channel_vec
Definition ZdcID.h:117
const_id_iterator channels_end() const
Definition ZdcID.cxx:375
Identifier channel_id(int side, int module, int type, int channel) const
Definition ZdcID.h:205
int channel(const Identifier &id) const
Definition ZdcID.h:175
size_type m_MODULE_INDEX
Definition ZdcID.h:108
int initLevelsFromDict()
Definition ZdcID.cxx:101
IdDictFieldImplementation m_type_impl
Definition ZdcID.h:123
IdDictFieldImplementation m_module_impl
Definition ZdcID.h:122
int init_hashes()
Definition ZdcID.cxx:203
IdDictFieldImplementation m_channel_impl
Definition ZdcID.h:124
size_type m_CHANNEL_INDEX
Definition ZdcID.h:110
IdentifierHash channel_hash(Identifier channel_id) const
channel hash from id - optimized
Definition ZdcID.h:143
size_type m_TYPE_INDEX
Definition ZdcID.h:109