ATLAS Offline Software
ZdcID.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/MsgStream.h"
7 
8 #include "ZdcIdentifier/ZdcID.h"
10 #include "IdDict/IdDictDefs.h"
11 #include <set>
12 #include <iostream>
13 
14 //______________________________________________________
15 ZdcID::ZdcID(void) {
16  m_dict = nullptr;
17 }
18 //______________________________________________________
20 
21 }
22 
23 int
25 {
26  MsgStream log(m_msgSvc, "ZdcID");
27  log << MSG::INFO << "Initialize from dictionary" << endmsg;
28 
29  // Check whether this helper should be reinitialized
30  if (!reinitialize(dict_mgr)) {
31  log << MSG::INFO << "Request to reinitialize not satisfied - tags have not changed" << endmsg;
32  return (0);
33  }
34  else {
35  if (m_msgSvc) {
36  log << MSG::DEBUG << "(Re)initialize" << endmsg;
37  }
38  else {
39  std::cout << " DEBUG (Re)initialize" << std::endl;
40  }
41  }
42 
43  // init base object
44  if(AtlasDetectorID::initialize_from_dictionary(dict_mgr)) return (1);
45 
46  // Register version of ForwardDetectors dictionary
47  if (register_dict_tag(dict_mgr, "ForwardDetectors")) return(1);
48 
49  m_dict = dict_mgr.find_dictionary ("ForwardDetectors");
50  if(!m_dict) {
51  log << MSG::ERROR << " ZdcID::initialize_from_dict - cannot access ForwardDetectors dictionary " << endmsg;
52  return 1;
53  }
54 
55  // Initialize the field indices
56  if(initLevelsFromDict()) return (1);
57 
58 
59  //
60  // Build multirange for the valid set of identifiers
61  //
62 
63 
64  // Find value for the field ForwardDetectors
65  const IdDictDictionary* atlasDict = dict_mgr.find_dictionary ("ATLAS");
66  int fwdField = -1;
67  if (atlasDict->get_label_value("subdet", "ForwardDetectors", fwdField)) {
68  log << MSG::ERROR << "Could not get value for label 'ForwardDetectors' of field 'subdet' in dictionary "
69  << atlasDict->m_name
70  << endmsg;
71  return (1);
72  }
73 
74  // Find value for the field ZDC
75  int zdcField = -1;
76  if (m_dict->get_label_value("part", "ZDC", zdcField)) {
77  log << MSG::ERROR << "Could not get value for label 'ZDC' of field 'part' in dictionary "
78  << m_dict->m_name
79  << endmsg;
80  return (1);
81  }
82  if (m_msgSvc) {
83  log << MSG::DEBUG << " ZdcID::initialize_from_dict "
84  << "Found field values: ZDC "
85  << zdcField
86  << std::endl;
87  }
88  else {
89  std::cout << " DEBUG ZdcID::initialize_from_dict "
90  << "Found field values: ZDC "
91  << zdcField
92  << std::endl;
93  }
94 
95  // Set up id for region and range prefix
97  region_id.add(fwdField);
98  region_id.add(zdcField);
99  Range prefix;
102 
103  if (m_msgSvc) {
104  log << MSG::INFO << " ZdcID::initialize_from_dict " << endmsg;
105  log << MSG::DEBUG
106  << "Module range -> " << (std::string)m_full_module_range
107  << endmsg;
108  log << MSG::DEBUG
109  << "Channel range -> " << (std::string)m_full_channel_range
110  << endmsg;
111  }
112  else {
113  std::cout << " INFO ZdcID::initialize_from_dict " << std::endl;
114  std::cout << " DEBUG module range -> " << (std::string)m_full_module_range
115  << std::endl;
116  std::cout << " DEBUG Channel range -> " << (std::string)m_full_channel_range
117  << std::endl;
118  }
119 
120  // Setup the hash tables
121  if(init_hashes()) return (1);
122 
123  return 0;
124 }
125 
126 
127 
128 int
130 {
131  MsgStream log(m_msgSvc, "ZdcID");
132  if(!m_dict) {
133  log << MSG::ERROR << " ZdcID::initLevelsFromDict - dictionary NOT initialized " << endmsg;
134  return (1);
135  }
136 
137  // Find out which identifier field corresponds to each level. Use
138  // names to find each field/level.
139 
140  m_zdc_region_index = 999;
141  m_FORWARD_INDEX = 999;
142  m_ZDC_INDEX = 999;
143  m_SIDE_INDEX = 999;
144  m_MODULE_INDEX = 999;
145  m_TYPE_INDEX = 999;
146  m_CHANNEL_INDEX = 999;
147 
148  // Save index to a ZDC region for unpacking
152  log << MSG::ERROR << "ZdcID::initLevelsFromDict - unable to find zdc region index: id, reg "
153  << (std::string)id << " " << m_zdc_region_index
154  << endmsg;
155  return (1);
156  }
157 
158  // Find a ZDC region
159  IdDictField* field = m_dict->find_field("subdet");
160  if (field) {
161  m_FORWARD_INDEX = field->m_index;
162  }
163  else {
164  log << MSG::ERROR << "ZdcID::initLevelsFromDict - unable to find 'subdet' field " << endmsg;
165  return (1);
166  }
167  field = m_dict->find_field("part");
168  if (field) {
169  m_ZDC_INDEX = field->m_index;
170  }
171  else {
172  log << MSG::ERROR << "ZdcID::initLevelsFromDict - unable to find 'part' field " << endmsg;
173  return (1);
174  }
175  field = m_dict->find_field("side");
176  if (field) {
177  m_SIDE_INDEX = field->m_index;
178  }
179  else {
180  log << MSG::ERROR << "ZdcID::initLevelsFromDict - unable to find 'side' field " << endmsg;
181  return (1);
182  }
183  field = m_dict->find_field("module");
184  if (field) {
185  m_MODULE_INDEX = field->m_index;
186  }
187  else {
188  log << MSG::ERROR << "ZdcID::initLevelsFromDict - unable to find 'module' field " << endmsg;
189  return (1);
190  }
191  field = m_dict->find_field("type");
192  if (field) {
193  m_TYPE_INDEX = field->m_index;
194  }
195  else {
196  log << MSG::ERROR<< "ZdcID::initLevelsFromDict - unable to find 'type' field " << endmsg;
197  return (1);
198  }
199  field = m_dict->find_field("channel");
200  if (field) {
201  m_CHANNEL_INDEX = field->m_index;
202  }
203  else {
204  log << MSG::ERROR << "ZdcID::initLevelsFromDict - unable to find 'channel' field " << endmsg;
205  return (1);
206  }
207 
208  // Set the field implementations: for bec, lay/disk, eta/phi mod
209 
210  const IdDictRegion& region = *m_dict->m_regions[m_zdc_region_index];
211 
218 
219  if (m_msgSvc) {
220  log << MSG::DEBUG << "decode index and bit fields for each level: " << endmsg;
221  log << MSG::DEBUG << "forward " << m_forward_impl.show_to_string() << endmsg;
222  log << MSG::DEBUG << "zdc " << m_zdc_impl.show_to_string() << endmsg;
223  log << MSG::DEBUG << "side " << m_side_impl.show_to_string() << endmsg;
224  log << MSG::DEBUG << "module " << m_module_impl.show_to_string() << endmsg;
225  log << MSG::DEBUG << "type " << m_type_impl.show_to_string() << endmsg;
226  log << MSG::DEBUG << "channel " << m_channel_impl.show_to_string() << endmsg;
227  }
228  else {
229  std::cout << " DEBUG decode index and bit fields for each level: " << std::endl;
230  std::cout << " DEBUG forward " << m_forward_impl.show_to_string() << std::endl;
231  std::cout << " DEBUG zdc " << m_zdc_impl.show_to_string() << std::endl;
232  std::cout << " DEBUG side " << m_side_impl.show_to_string() << std::endl;
233  std::cout << " DEBUG module " << m_module_impl.show_to_string() << std::endl;
234  std::cout << " DEBUG type " << m_type_impl.show_to_string() << std::endl;
235  std::cout << " DEBUG channel " << m_channel_impl.show_to_string() << std::endl;
236  }
237 
238  return (0);
239 
240 }
241 
242 
243 int
245 {
246  //
247  // create a vector(s) to retrieve the hashes for compact ids.
248  //
249  MsgStream log(m_msgSvc, "ZDC_ID");
250 
251 
252  // module hash
255  unsigned int nids = 0;
256  std::set<Identifier> ids;
257  for (unsigned int i = 0; i < m_full_module_range.size(); ++i) {
258  const Range& range = m_full_module_range[i];
259  Range::const_identifier_factory first = range.factory_begin();
260  Range::const_identifier_factory last = range.factory_end();
261  for (; first != last; ++first) {
262  const ExpandedIdentifier& exp_id = (*first);
263  Identifier id = module_id(exp_id[m_SIDE_INDEX],
264  exp_id[m_MODULE_INDEX]);
265  if(!(ids.insert(id)).second) {
266  log << MSG::ERROR << " ZDC_ID::init_hashes "
267  << " Error: duplicated id for module id. nid " << nids
268  << " compact id " << MSG::hex << id.get_compact() << MSG::dec
269  << " id " << (std::string)exp_id << endmsg;
270  return (1);
271  }
272  nids++;
273  }
274  }
275  if(ids.size() != m_module_hash_max) {
276  log << MSG::ERROR << " ZDC_ID::init_hashes "
277  << " Error: set size NOT EQUAL to hash max. size " << ids.size()
278  << " hash max " << m_module_hash_max
279  << endmsg;
280  return (1);
281  }
282 
283  nids = 0;
284  std::set<Identifier>::const_iterator first = ids.begin();
285  std::set<Identifier>::const_iterator last = ids.end();
286  for (; first != last && nids < m_module_vec.size(); ++first) {
287  m_module_vec[nids] = (*first);
288  nids++;
289  }
290 
291  // channel hash
294  nids = 0;
295  ids.clear();
296  for (unsigned int i = 0; i < m_full_channel_range.size(); ++i) {
297  const Range& range = m_full_channel_range[i];
298  Range::const_identifier_factory first = range.factory_begin();
299  Range::const_identifier_factory last = range.factory_end();
300  for (; first != last; ++first) {
301  const ExpandedIdentifier& exp_id = (*first);
302  Identifier id = channel_id(exp_id[m_SIDE_INDEX],
303  exp_id[m_MODULE_INDEX],
304  exp_id[m_TYPE_INDEX],
305  exp_id[m_CHANNEL_INDEX]);
306 
307  if(!(ids.insert(id)).second) {
308  log << MSG::ERROR << " ZDC_ID::init_hashes "
309  << " Error: duplicated id for channel id. nid " << nids
310  << " compact id " << MSG::hex << id.get_compact() << MSG::dec
311  << " id " << (std::string)exp_id << endmsg;
312  return (1);
313  }
314  nids++;
315  }
316  }
317  if(ids.size() != m_channel_hash_max) {
318  log << MSG::ERROR << " ZDC_ID::init_hashes "
319  << " Error: set size NOT EQUAL to hash max. size " << ids.size()
320  << " hash max " << m_channel_hash_max
321  << endmsg;
322  return (1);
323  }
324 
325  nids = 0;
326  first = ids.begin();
327  last = ids.end();
328  for (; first != last && nids < m_channel_vec.size(); ++first) {
329  m_channel_vec[nids] = (*first);
330  nids++;
331  }
332  return (0);
333 }
334 
335 void
337 {
338  MsgStream log(m_msgSvc, "ZDC_ID");
339 
340  if (m_dict) {
341 
342  int nids = 0;
343  int nerr = 0;
346  const_id_iterator last = m_module_vec.end();
347  for (; first != last; ++first, ++nids) {
348  Identifier id = (*first);
349  Identifier new_id = module_id(side(id),
350  module(id));
351  if (id != new_id) {
352  log << MSG::ERROR << "ZDC_ID::test_packing: new and old compacts not equal. New/old/expanded ids "
353  << show_to_string(id) << " " << show_to_string(new_id) << endmsg;
354  nerr++;
355  continue;
356  }
357  IdentifierHash idHash = module_hash(id);
358  Identifier new_id_1 = module_id(idHash);
359  if (id != new_id_1) {
360  log << MSG::ERROR << "ZDC_ID::test_packing: new and old compacts from hash not equal. New/old/expanded ids. hash " << idHash << " "
361  << show_to_string(id) << " " << show_to_string(new_id_1) << endmsg;
362  nerr++;
363  continue;
364  }
365 
366  // std::cout << "module ids: " << idHash << " " << std::hex << id.get_compact() << std::dec << " " << new_id_1.get_compact() << " " << show_to_string(id) << " " << show_to_string(new_id) << " " << show_to_string(new_id_1) << std::endl;
367 
368  }
369 
370  if (m_msgSvc) {
371  log << MSG::DEBUG << "ZDC_ID::test_packing: tested module ids. nids, errors "
372  << nids << " " << nerr << endmsg;
373  }
374  else {
375  std::cout << " DEBUG ZDC_ID::test_packing: tested module ids. nids, errors "
376  << nids << " " << nerr << std::endl;
377  }
378 
379  first = m_channel_vec.begin();
380  last = m_channel_vec.end();
381  for (; first != last; ++first, ++nids) {
382  Identifier id = (*first);
383  Identifier new_id = channel_id(side(id),
384  module(id),
385  type(id),
386  channel(id));
387  if (id != new_id) {
388  log << MSG::ERROR << "ZDC_ID::test_packing: new and old compacts not equal. New/old/expanded ids "
389  << show_to_string(id) << " " << show_to_string(new_id) << endmsg;
390  nerr++;
391  continue;
392  }
393  IdentifierHash idHash = channel_hash(id);
394  Identifier new_id_1 = channel_id(idHash);
395  if (id != new_id_1) {
396  log << MSG::ERROR << "ZDC_ID::test_packing: new and old compacts from hash not equal. New/old/expanded ids hash " << idHash << " "
397  << show_to_string(id) << " " << show_to_string(new_id_1) << endmsg;
398  nerr++;
399  continue;
400  }
401 
402  // std::cout << "channel ids: " << idHash << " " << show_to_string(id) << " " << show_to_string(new_id) << " " << show_to_string(new_id_1) << std::endl;
403 
404 
405  }
406 
407  if (m_msgSvc) {
408  log << MSG::DEBUG << "ZDC_ID::test_packing: tested channel ids. nids, errors "
409  << nids << " " << nerr << endmsg;
410  }
411  else {
412  std::cout << " DEBUG ZDC_ID::test_packing: tested channel ids. nids, errors "
413  << nids << " " << nerr << std::endl;
414  }
415 
416  if (m_msgSvc) {
417  log << MSG::DEBUG << "ZDC_ID::test_packing: Successful tested "
418  << nids << " ids. "
419  << endmsg;
420  }
421  else {
422  std::cout << " DEBUG ZDC_ID::test_packing: Successful tested "
423  << nids << " ids. "
424  << std::endl;
425  }
426  }
427  else {
428  log << MSG::ERROR << "ZDC_ID::test_packing: Unable to test module/channel is packing - no dictionary has been defined. "
429  << endmsg;
430  }
431 }
432 
434 {
435  return (m_module_vec.begin());
436 }
437 
439 {
440  return (m_module_vec.end());
441 }
442 
444 {
445  return (m_channel_vec.begin());
446 }
447 
449 {
450  return (m_channel_vec.end());
451 }
452 
453 
454 
IdDictDictionary::find_region
IdDictRegion * find_region(const std::string &region_name) const
Definition: IdDictMgr.cxx:366
ZdcID::m_channel_vec
id_vec m_channel_vec
Definition: ZdcID.h:117
IdDictDictionary::build_multirange
MultiRange build_multirange() const
Get MultiRange for full dictionary.
Definition: IdDictMgr.cxx:1048
AtlasDetectorID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
Definition: AtlasDetectorID.cxx:320
ZdcID::m_dict
const IdDictDictionary * m_dict
Definition: ZdcID.h:111
getMessageSvc.h
singleton-like access to IMessageSvc via open function and helper
ZdcID::m_ZDC_INDEX
size_type m_ZDC_INDEX
Definition: ZdcID.h:106
ZdcID::init_hashes
int init_hashes(void)
Definition: ZdcID.cxx:244
IdDictFieldImplementation::show_to_string
std::string show_to_string(void) const
Definition: IdDictFieldImplementation.cxx:57
ZdcID::module_hash
IdentifierHash module_hash(Identifier module_id) const
module hash from id - optimized
Definition: ZdcID.h:134
ZdcID::module
int module(const Identifier &id) const
Definition: ZdcID.h:163
ZdcID::module_id
Identifier module_id(int side, int module) const
Definition: ZdcID.h:182
ZdcID::m_SIDE_INDEX
size_type m_SIDE_INDEX
Definition: ZdcID.h:107
AtlasDetectorID::forward_field_value
int forward_field_value() const
Definition: AtlasDetectorID.h:671
ZdcID::m_FORWARD_INDEX
size_type m_FORWARD_INDEX
Definition: ZdcID.h:105
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:108
ZdcID::modules_begin
const_id_iterator modules_begin(void) const
Iterators over full set of ids. modules iterator is sorted.
Definition: ZdcID.cxx:433
ZdcID::modules_end
const_id_iterator modules_end(void) const
Definition: ZdcID.cxx:438
AtlasDetectorID::m_msgSvc
IMessageSvc * m_msgSvc
pointer to the message service
Definition: AtlasDetectorID.h:368
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
ZdcID::m_full_module_range
MultiRange m_full_module_range
Definition: ZdcID.h:112
IdDictDictionary::find_field
IdDictField * find_field(const std::string &name) const
Definition: IdDictMgr.cxx:309
CalibDbCompareRT.region_id
region_id
Definition: CalibDbCompareRT.py:68
IdDictRegion
Definition: IdDictDefs.h:448
ZdcID::m_type_impl
IdDictFieldImplementation m_type_impl
Definition: ZdcID.h:123
ZdcID::m_channel_hash_max
size_type m_channel_hash_max
Definition: ZdcID.h:115
ZdcID::channel_id
Identifier channel_id(int side, int module, int type, int channel) const
Definition: ZdcID.h:205
IdDictDefs.h
ZdcID::m_zdc_region_index
size_type m_zdc_region_index
Definition: ZdcID.h:104
ZdcID::initLevelsFromDict
int initLevelsFromDict(void)
Definition: ZdcID.cxx:129
IdDictMgr
Definition: IdDictDefs.h:32
IdDictMgr::find_dictionary
IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:161
lumiFormat.i
int i
Definition: lumiFormat.py:92
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
ZdcID::channels_end
const_id_iterator channels_end(void) const
Definition: ZdcID.cxx:448
IdDictDictionary::m_regions
std::vector< IdDictRegion * > m_regions
Definition: IdDictDefs.h:302
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
ZdcID::m_module_impl
IdDictFieldImplementation m_module_impl
Definition: ZdcID.h:122
ZdcID::const_id_iterator
std::vector< Identifier >::const_iterator const_id_iterator
Definition: ZdcID.h:30
ZdcID::m_full_channel_range
MultiRange m_full_channel_range
Definition: ZdcID.h:113
Range::const_identifier_factory
Definition: DetectorDescription/Identifier/Identifier/Range.h:191
ZdcID::m_MODULE_INDEX
size_type m_MODULE_INDEX
Definition: ZdcID.h:108
ZdcID::channels_begin
const_id_iterator channels_begin(void) const
Iterators over full set of ids. channels iterator is sorted.
Definition: ZdcID.cxx:443
AtlasDetectorID::register_dict_tag
int register_dict_tag(const IdDictMgr &dict_mgr, const std::string &dict_name)
Register the file and tag names for a particular IdDict dictionary.
Definition: AtlasDetectorID.cxx:266
IdDictDictionary::get_label_value
int get_label_value(const std::string &field, const std::string &label, int &value) const
Definition: IdDictMgr.cxx:338
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
ZdcID::ZdcID
ZdcID(void)
Definition: ZdcID.cxx:15
IdentifierHash.h
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition: DetectorDescription/Identifier/Identifier/Range.h:27
ZdcID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
Initialization from the identifier dictionary.
Definition: ZdcID.cxx:24
IdDictDictionary
Definition: IdDictDefs.h:97
ZdcID::~ZdcID
~ZdcID(void)
Definition: ZdcID.cxx:19
ZdcID::m_forward_impl
IdDictFieldImplementation m_forward_impl
Definition: ZdcID.h:119
ZdcID.h
ZdcID::test_packing
void test_packing(void) const
Tests of packing.
Definition: ZdcID.cxx:336
AtlasDetectorID::reinitialize
bool reinitialize(const IdDictMgr &dict_mgr)
Test whether an idhelper should be reinitialized based on the change of tags.
Definition: AtlasDetectorID.cxx:284
IdDictDictionary::m_name
std::string m_name
Definition: IdDictDefs.h:283
AtlasDetectorID::show_to_string
std::string show_to_string(Identifier id, const IdContext *context=0, char sep='.') const
or provide the printout in string form
Definition: AtlasDetectorID.cxx:574
ZdcID::m_side_impl
IdDictFieldImplementation m_side_impl
Definition: ZdcID.h:121
ZdcID::m_CHANNEL_INDEX
size_type m_CHANNEL_INDEX
Definition: ZdcID.h:110
MultiRange::size
size_type size() const
Definition: DetectorDescription/Identifier/src/Range.cxx:2488
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DEBUG
#define DEBUG
Definition: page_access.h:11
ZdcID::side
int side(const Identifier &id) const
Values of different levels (failure returns 0)
Definition: ZdcID.h:157
ZdcID::type
int type(const Identifier &id) const
Definition: ZdcID.h:169
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
ZdcID::channel_hash
IdentifierHash channel_hash(Identifier channel_id) const
channel hash from id - optimized
Definition: ZdcID.h:143
AtlasDetectorID::zdc_field_value
int zdc_field_value() const
Definition: AtlasDetectorID.h:679
IdDictField
Definition: IdDictDefs.h:318
MultiRange::cardinality
size_type cardinality() const
Computes a possible cardinality from all ranges.
Definition: DetectorDescription/Identifier/src/Range.cxx:2503
ZdcID::m_zdc_impl
IdDictFieldImplementation m_zdc_impl
Definition: ZdcID.h:120
IdentifierHash
Definition: IdentifierHash.h:38
ZdcID::m_channel_impl
IdDictFieldImplementation m_channel_impl
Definition: ZdcID.h:124
IdDictRegion::m_implementation
std::vector< IdDictFieldImplementation > m_implementation
Definition: IdDictDefs.h:474
ZdcID::m_module_vec
id_vec m_module_vec
Definition: ZdcID.h:116
ZdcID::m_module_hash_max
size_type m_module_hash_max
Definition: ZdcID.h:114
ZdcID::channel
int channel(const Identifier &id) const
Definition: ZdcID.h:175
ZdcID::m_TYPE_INDEX
size_type m_TYPE_INDEX
Definition: ZdcID.h:109