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