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