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