ATLAS Offline Software
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 
6 #include "GaudiKernel/MsgStream.h"
7 #include "IdDict/IdDictDefs.h"
10 #include <algorithm>
11 #include <cassert>
12 #include <cmath>
13 #include <cstdio>
14 #include <iostream>
15 #include <set>
16 #include <string>
17 
18 
20  AtlasDetectorID("LArHVLineID", "LArHV"),
21  m_larhvRegion_index(999),
22  m_atlas_index(999),
23  m_configuration_index(999),
24  m_partition_index(999),
25  m_canline_index(999),
26  m_cannode_index(999),
27  m_hvline_index(999),
28  m_dict(nullptr),
29  m_hvlineHashMax(0)
30 {
31 
32 }
33 
35 
36 
38 {
40  return (IdContext(id, 0, m_hvline_index));
41 }
42 
43 /*
44 IdContext LArHVLineID::canlineContext() const
45 {
46  ExpandedIdentifier id;
47  return (IdContext(id, 0, m_canline_index));
48 }
49 */
50 
51 //==========================================================================
53 //==========================================================================
54 {
55 
56  MsgStream log(m_msgSvc, "LArHVLineID" );
57  std::string strg = " => initialize_from_dictionary()";
58  if(m_msgSvc) {
59  log << MSG::INFO << strg << endmsg;
60  }
61  else {
62  std::cout << strg << std::endl;
63  }
64 
65  // Check whether this helper should be reinitialized
66  // -------------------------------------------------
67  if (!reinitialize(dict_mgr)) {
68  if(m_msgSvc)log << MSG::DEBUG
69  << "Request to reinitialize not satisfied - tags have not changed"
70  << endmsg;
71  return (0);
72  }
73  else {
74  log << MSG::DEBUG << "(Re)initialize" << endmsg;
75  }
76  log << MSG::DEBUG << " => Initialization of dict_mgr done ! " << m_dict << endmsg;
77 
78  // init base object
79  // ----------------
81  return (1);
82  }
83  else{
84  log << MSG::INFO << " => initialize_from_dictionary(dict_mgr) ="
86  << endmsg;
87  }
88  m_dict = dict_mgr.find_dictionary ("LArHighVoltage");
89 
90  if(!m_dict)
91  {
92  strg = " initialize_from_dictionary - cannot access LArHighVoltage dictionary ";
93  if(m_msgSvc) {
94  log << MSG::ERROR << strg << endmsg;
95  }
96  else
97  {
98  std::cout << "LArHVLineID::" << strg << std::endl;
99  }
100  return 1;
101  }
102 
103  // Register version of the dictionary used
104  // ---------------------------------------
105  if (register_dict_tag(dict_mgr, "LArHighVoltage")) return(1);
106  log << MSG::INFO << "Register_dict_tag of LArHighVoltage is OK" << endmsg;
107 
108  // initialize dictionary version
109  // -----------------------------
110  AtlasDetectorID::setDictVersion(dict_mgr, "LArHighVoltage");
111  log << MSG::INFO << "setDictVersion of LArHighVoltage is OK" << endmsg;
112 
113 
114  // Initialize the field indices
115  // =========================================================================
116  if(initLevelsFromDict()) return (1);
117 
118  /* Find value for the field Calorimeter */
119  const IdDictDictionary* atlasDict = dict_mgr.find_dictionary ("ATLAS");
120  int larHVValue = -1;
121  if (atlasDict->get_label_value("subdet", "LArHighVoltage", larHVValue)) {
122  std::stringstream strm;
123  strm << atlasDict->name();
124  strg= " Could not get value for label 'LArHighVoltage' of field 'subdet' in dictionary "+strm.str();
125  if(m_msgSvc){
126  log << MSG::ERROR << strg << endmsg;
127  }
128  else{
129  std::cout << "LArHVLineID:" << strg << std::endl;
130  }
131  return (1);
132  }
133  log << MSG::DEBUG << "[init_from_dictionary] > larHV value = "<< larHVValue << endmsg;
134 
135 
136  /* Find values for the field Configuration */
137  int configurationValue = 1;
138  if (m_dict->get_label_value("configuration", "Atlas", configurationValue)) {
139  std::stringstream strm;
140  strm << m_dict->name();
141  strg = "WARNING : Could not get value for label 'configuration' in dictionary "+strm.str();
142  if(m_msgSvc) {
143  log << MSG::INFO << strg << endmsg;
144  }
145  else{
146  std::cout << strg << std::endl;
147  }
148  return (0);
149  }
150  log << MSG::DEBUG << "[init_from_dictionary] > configurationValue = "
151  << configurationValue << endmsg;
152 
153  // Set up Expanded identifier for hvline range prefix
154  // =========================================================
155  ExpandedIdentifier reg_id;
156  reg_id.add(larHVValue);
157  reg_id.add(configurationValue);
158  Range prefix;
159 
160  /*Full range for all lines */
162  m_full_hvline_range = m_dict->build_multirange(reg_id, prefix, "hvline");
163  m_full_canline_range = m_dict->build_multirange(reg_id, prefix, "canline");
164  log << MSG::INFO << "[initialize_from_dictionary] > HV line range -> "
165  << (std::string)m_full_hvline_range << endmsg;
166 
167  // Setup the hash tables
168  // =========================================================
169  if(init_hashes()) return (1);
170 
171  return 0;
172 }
173 
174 
175 //=====================================================================================
177  ExpandedIdentifier& exp_id,
178  const IdContext* context) const
179 //=====================================================================================
180 {
181  MsgStream log(m_msgSvc, "LArHVLineID" );
182  // We assume that the context is >= hvline
183  exp_id.clear();
184  exp_id << lar_field_value()
185  << s_lar_atlas_value
186  << partition(id)
187  << can_line(id)
188  << can_node(id)
189  << hv_line(id);
190  if(context && context->end_index() >= m_hvline_index) {
191  exp_id << hv_line(id);
192  }
193  return (0);
194 }
195 
196 
197 //=============================================================================
199 //=============================================================================
200 {
201  MsgStream log(m_msgSvc, "LArHVLineID" );
202  log << MSG::DEBUG << "[initLevelsFromDict] Entering routine... " << endmsg;
203 
204  if(!m_dict) {
205  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - dictionary NOT initialized "
206  << endmsg ;
207  return (1);
208  }
209 
210  log << MSG::INFO << "[initLevelsFromDict] m_dict OK ... " << endmsg;
211 
212  // Find out which identifier field corresponds to each level.
213  // ========================================================================
214  m_atlas_index = 999;
215  m_configuration_index = 999;
216  m_partition_index = 999;
217  m_canline_index = 999;
218  m_cannode_index = 999;
219  m_hvline_index = 999;
220 
221  log << MSG::DEBUG << "[initLevelsFromDict] data member initialization OK ... " << endmsg;
222 
223  // Search with region name
224  IdDictRegion* reg = m_dict->find_region("LArHV-HEC-A");
225  if (reg) {
226  m_larhvRegion_index = reg->index();}
227  else {
228  log << MSG::INFO << "WARNING : LArHVLineID::initLevelsFromDict - unable to find 'barrel-region1' region"
229  << endmsg;
230  return (0);
231  }
232  log << MSG::DEBUG << "[initLevelsFromDict] region 'LAr-HV-HEC-A' found OK ... " << endmsg;
233 
234  // Find ATLAS field
235  // ========================================================================
236  IdDictField* field = m_dict->find_field("subdet") ;
237  if (field) {
238  m_atlas_index = field->index();}
239  else {
240  log << MSG::INFO
241  << "LArHVLineID::initLevelsFromDict - unable to find 'subdet' field " << endmsg ;
242  return (1);
243  }
244  log << MSG::DEBUG
245  << "[initLevelsFromDict] field 'LArHighVoltage' found OK " << endmsg;
246 
247  // Find Configuration field
248  // ========================================================================
249  field = m_dict->find_field("configuration") ;
250  if (field) {
251  m_configuration_index = field->index();}
252  else {
253  log << MSG::INFO
254  << "LArHVLineID::initLevelsFromDict - unable to find 'configuration' field " << endmsg ;
255  return (1);
256  }
257  log << MSG::DEBUG
258  << "[initLevelsFromDict] field config=Atlas found OK " << endmsg;
259 
260  // Look for Field 'partition'
261  // ========================================================================
262  field = m_dict->find_field("partition") ;
263  if (field) {
264  m_partition_index = field->index();}
265  else {
266  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - unable to find 'partition' field "
267  << endmsg ;
268  return (1);
269  }
270  log << MSG::DEBUG << "[initLevelsFromDict] field 'partition' found OK " << endmsg;
271 
272 
273  // Look for Field 'CAN LINE'
274  // ========================================================================
275  field = m_dict->find_field("canline") ;
276  if (field) {
277  m_canline_index = field->index();}
278  else {
279  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - unable to find 'canline' field "
280  << endmsg ;
281  return (1);
282  }
283  log << MSG::DEBUG << "[initLevelsFromDict] field 'canline' found OK " << endmsg;
284 
285 
286  // Look for Fields 'CAN NODE'
287  // ========================================================================
288  field = m_dict->find_field("cannode") ;
289  if (field) {
290  m_cannode_index = field->index();
291  }
292  else {
293  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - unable to find 'cannode' field "
294  << endmsg ;
295  return (1);
296  }
297  log << MSG::DEBUG << "[initLevelsFromDict] field 'cannode' found OK " << endmsg;
298 
299 
300  // Look for Fields 'HV_line'
301  // ========================================================================
302  field = m_dict->find_field("hvline") ;
303  if (field) {
304  m_hvline_index = field->index();
305  }
306  else {
307  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - unable to find 'hvline' field "
308  << endmsg ;
309  return (1);
310  }
311  log << MSG::DEBUG << "[initLevelsFromDict] field 'hvline' found OK " << endmsg;
312 
313 
314  // Set the field implementation
315  // ========================================================================
316 
317  const IdDictRegion& region = m_dict->region(m_larhvRegion_index);
318  log << MSG::DEBUG << "[initLevelsFromDict] Found levels: " << endmsg ;
319  log << MSG::DEBUG << "[initLevelsFromDict] > larHV " << m_atlas_index << endmsg ;
320  log << MSG::DEBUG << "[initLevelsFromDict] > larConfiguration " << m_configuration_index << endmsg ;
321  log << MSG::DEBUG << "[initLevelsFromDict] > CAN Node " << m_cannode_index << endmsg ;
322  log << MSG::DEBUG << "[initLevelsFromDict] > HV line " << m_hvline_index << endmsg ;
323  log << MSG::DEBUG << "[initLevelsFromDict] > partition " << m_partition_index << endmsg ;
324  log << MSG::DEBUG << "[initLevelsFromDict] > CAN line " << m_canline_index << endmsg ;
325 
326 
327  log << MSG::DEBUG << "[initLevelsFromDict] > ...fields implementation... " << endmsg;
328  log << MSG::DEBUG << "[initLevelsFromDict] > ...implementation: m_larhvcalo_index " << endmsg;
335 
336  log << MSG::DEBUG << "[initLevelsFromDict] Decode index and bit fields for each level: " << endmsg;
337  log << MSG::DEBUG << "[initLevelsFromDict] > larHV " << m_atlas_impl.show_to_string() << endmsg;
338  log << MSG::DEBUG << "[initLevelsFromDict] > larConfig " << m_configuration_impl.show_to_string() << endmsg;
339  log << MSG::DEBUG << "[initLevelsFromDict] > partition " << m_partition_impl.show_to_string() << endmsg;
340  log << MSG::DEBUG << "[initLevelsFromDict] > can line " << m_canline_impl.show_to_string() << endmsg;
341  log << MSG::DEBUG << "[initLevelsFromDict] > can node " << m_cannode_impl.show_to_string() << endmsg;
342  log << MSG::DEBUG << "[initLevelsFromDict] > hv line " << m_hvline_impl.show_to_string() << endmsg;
343 
344 
345  return(0) ;
346 }
347 
348 
349 
350 
351 //=====================================================
353 //=====================================================
354 {
355  MsgStream log(m_msgSvc, "LArHVLineID" );
356  std::stringstream strm1;
357  std::stringstream strm2;
358  std::stringstream strm3;
359  std::string strg1;
360  std::string strg2;
361  std::string strg3;
362 
363  // tower hash
364  // -----------
367  unsigned int nids = 0;
368  std::set<HWIdentifier> ids;
369  for (unsigned int i = 0; i < m_full_atlas_highvoltage_range.size(); ++i) {
372  for (const auto & exp_id :rit) {
373  HWIdentifier hv_id = HVLineId(
374  exp_id[m_partition_index] ,
375  exp_id[m_canline_index] ,
376  exp_id[m_cannode_index] ,
377  exp_id[m_hvline_index]
378  );
379  if(!(ids.insert(hv_id)).second){
380  strm1 << nids;
381  strg1 = "[init_hashes] > duplicated id for channel nb = "+strm1.str();
382  strm3 << show_to_string(hv_id);
383  strg3 = " expanded Id= "+strm3.str();
384  if(m_msgSvc){
385  log << MSG::ERROR << strg1 << endmsg;
386  log << MSG::ERROR << strg3 << endmsg;
387  }
388  }
389  nids++;
390  }
391  }
392  if(ids.size() != m_hvlineHashMax) {
393  strm1 << ids.size();
394  strm2 << m_hvlineHashMax;
395  strg1 = "[init_hashes] >";
396  strg2 = " set size NOT EQUAL to hash max. size "+strm1.str();
397  strg3 = " hash max "+strm2.str();
398  if(m_msgSvc)
399  {
400  log << MSG::ERROR << strg1 << endmsg;
401  log << MSG::ERROR << strg2 << endmsg;
402  log << MSG::ERROR << strg3 << endmsg;
403  }
404  else
405  {
406  std::cout << "LArOnlineID::" << strg1 << std::endl;
407  std::cout << "Error" << strg2 << std::endl;
408  std::cout << strg3 << std::endl;
409  }
410  return (1);
411  }
412 
413  nids=0;
414  std::set<HWIdentifier>::const_iterator first = ids.begin();
415  std::set<HWIdentifier>::const_iterator last = ids.end();
416  for (;first != last && nids < m_hvline_vec.size(); ++first) {
417  m_hvline_vec[nids] = (*first) ;
418  nids++;
419  }
420  log << MSG::INFO << "[init_hashes()] > Hvline_size= " << m_hvline_vec.size() << endmsg;
421  return (0);
422 }
423 
424 
425 
IdDictDictionary::find_region
IdDictRegion * find_region(const std::string &region_name) const
Definition: IdDictDictionary.cxx:92
ConstRangeIterator
Definition: RangeIterator.h:46
IdDictDictionary::build_multirange
MultiRange build_multirange() const
Get MultiRange for full dictionary.
Definition: IdDictDictionary.cxx:291
LArHVLineID::m_hvline_vec
std::vector< HWIdentifier > m_hvline_vec
Definition: LArHVLineID.h:187
LArHVLineID::HVLineId
HWIdentifier HVLineId(int part, int canline, int cannode, int line) const
Create an HighVoltage line identifier from fields.
Definition: LArHVLineID.h:216
AtlasDetectorID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
Definition: AtlasDetectorID.cxx:250
LArHVLineID::m_cannode_index
size_type m_cannode_index
Definition: LArHVLineID.h:178
python.ZdcOnlineRecMonitorConfig.partition
partition
Definition: ZdcOnlineRecMonitorConfig.py:328
IdDictFieldImplementation::show_to_string
std::string show_to_string(void) const
Definition: IdDictFieldImplementation.cxx:38
LArHVLineID::m_hvline_index
size_type m_hvline_index
Definition: LArHVLineID.h:179
IdDictDictionary::region
const IdDictRegion & region(size_t i) const
Region at index i.
Definition: IdDictDictionary.h:341
LArHVLineID::m_partition_index
size_type m_partition_index
Definition: LArHVLineID.h:176
ExpandedIdentifier::add
void add(element_type value)
Append a value into a new field.
LArHVLineID::m_configuration_impl
IdDictFieldImplementation m_configuration_impl
Definition: LArHVLineID.h:191
LArHVLineID::hvlineContext
IdContext hvlineContext() const
Definition: LArHVLineID.cxx:37
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:102
AtlasDetectorID::m_msgSvc
IMessageSvc * m_msgSvc
pointer to the message service
Definition: AtlasDetectorID.h:369
LArHVLineID::m_partition_impl
IdDictFieldImplementation m_partition_impl
Definition: LArHVLineID.h:192
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
IdDictDictionary::name
const std::string & name() const
Dictionary name.
Definition: IdDictDictionary.h:323
LArHVLineID.h
HWIdentifier
Definition: HWIdentifier.h:13
LArHVLineID::init_hashes
int init_hashes()
Definition: LArHVLineID.cxx:352
LArHVLineID::~LArHVLineID
~LArHVLineID()
IdDictDictionary::find_field
IdDictField * find_field(const std::string &name) const
Definition: IdDictDictionary.cxx:36
IdDictRegion
Definition: IdDictRegion.h:20
LArHVLineID::get_expanded_id
int get_expanded_id(const HWIdentifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
Definition: LArHVLineID.cxx:176
IdDictDefs.h
LArHVLineID::m_canline_index
size_type m_canline_index
Definition: LArHVLineID.h:177
IdDictRegion::implementation
const IdDictFieldImplementation & implementation(size_t i) const
Definition: IdDictRegion.cxx:17
IdDictMgr
Definition: IdDictMgr.h:14
IdDictMgr::find_dictionary
IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:115
LArHVLineID::LArHVLineID
LArHVLineID()
only allowed constructor
Definition: LArHVLineID.cxx:19
lumiFormat.i
int i
Definition: lumiFormat.py:85
LArHVLineID::initLevelsFromDict
int initLevelsFromDict()
Definition: LArHVLineID.cxx:198
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
LArHVLineID::m_atlas_impl
IdDictFieldImplementation m_atlas_impl
Field Implementation.
Definition: LArHVLineID.h:190
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:194
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
LArHVLineID::m_full_hvline_range
MultiRange m_full_hvline_range
Definition: LArHVLineID.h:184
LArHVLineID::m_configuration_index
size_type m_configuration_index
Definition: LArHVLineID.h:175
LArHVLineID::m_dict
const IdDictDictionary * m_dict
Definition: LArHVLineID.h:182
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:196
IdDictDictionary::get_label_value
int get_label_value(const std::string &field, const std::string &label, int &value) const
Definition: IdDictDictionary.cxx:64
LArHVLineID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
Initialization from the identifier dictionary.
Definition: LArHVLineID.cxx:52
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:239
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
IdentifierHash.h
RangeIterator.h
AtlasDetectorID::setDictVersion
virtual void setDictVersion(const IdDictMgr &dict_mgr, const std::string &name) override
Definition: AtlasDetectorID.cxx:494
Range
A Range describes the possible ranges for the field values of an ExpandedIdentifier.
Definition: DetectorDescription/Identifier/Identifier/Range.h:29
IdDictDictionary
Definition: IdDictDictionary.h:30
AtlasDetectorID::reinitialize
bool reinitialize(const IdDictMgr &dict_mgr)
Test whether an idhelper should be reinitialized based on the change of tags.
Definition: AtlasDetectorID.cxx:216
LArHVLineID::m_cannode_impl
IdDictFieldImplementation m_cannode_impl
Definition: LArHVLineID.h:194
LArHVLineID::m_hvlineHashMax
size_type m_hvlineHashMax
Definition: LArHVLineID.h:186
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:360
python.Constants.INFO
int INFO
Definition: Control/AthenaCommon/python/Constants.py:15
MultiRange::size
size_type size() const
Definition: MultiRange.cxx:70
DeMoScan.first
bool first
Definition: DeMoScan.py:534
DEBUG
#define DEBUG
Definition: page_access.h:11
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
IdDictRegion::index
size_t index() const
Definition: IdDictRegion.h:119
LArHVLineID::m_atlas_index
size_type m_atlas_index
Definition: LArHVLineID.h:174
IdDictField
Definition: IdDictField.h:15
MultiRange::cardinality
size_type cardinality() const
Computes a possible cardinality from all ranges.
Definition: MultiRange.cxx:82
LArHVLineID::m_full_canline_range
MultiRange m_full_canline_range
Definition: LArHVLineID.h:185
LArHVLineID::m_canline_impl
IdDictFieldImplementation m_canline_impl
Definition: LArHVLineID.h:193
LArHVLineID::m_hvline_impl
IdDictFieldImplementation m_hvline_impl
Definition: LArHVLineID.h:195
IdContext
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition: IdContext.h:26
AtlasDetectorID
This class provides an interface to generate or decode an identifier for the upper levels of the dete...
Definition: AtlasDetectorID.h:52
LArHVLineID::m_full_atlas_highvoltage_range
MultiRange m_full_atlas_highvoltage_range
Definition: LArHVLineID.h:183
LArHVLineID::m_larhvRegion_index
size_type m_larhvRegion_index
Definition: LArHVLineID.h:173