ATLAS Offline Software
LArHVLineID.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "GaudiKernel/MsgStream.h"
7 #include "IdDict/IdDictDefs.h"
9 #include <algorithm>
10 #include <cassert>
11 #include <cmath>
12 #include <cstdio>
13 #include <iostream>
14 #include <set>
15 #include <string>
16 
17 
19  m_larhvRegion_index(999),
20  m_atlas_index(999),
21  m_configuration_index(999),
22  m_partition_index(999),
23  m_canline_index(999),
24  m_cannode_index(999),
25  m_hvline_index(999),
26  m_dict(nullptr),
27  m_hvlineHashMax(0)
28 {
29 
30 }
31 
33 
34 
36 {
38  return (IdContext(id, 0, m_hvline_index));
39 }
40 
41 /*
42 IdContext LArHVLineID::canlineContext(void) const
43 {
44  ExpandedIdentifier id;
45  return (IdContext(id, 0, m_canline_index));
46 }
47 */
48 
49 //==========================================================================
51 //==========================================================================
52 {
53 
54  MsgStream log(m_msgSvc, "LArHVLineID" );
55  std::string strg = " => initialize_from_dictionary()";
56  if(m_msgSvc) {
57  log << MSG::INFO << strg << endmsg;
58  }
59  else {
60  std::cout << strg << std::endl;
61  }
62 
63  // Check whether this helper should be reinitialized
64  // -------------------------------------------------
65  if (!reinitialize(dict_mgr)) {
66  if(m_msgSvc)log << MSG::DEBUG
67  << "Request to reinitialize not satisfied - tags have not changed"
68  << endmsg;
69  return (0);
70  }
71  else {
72  log << MSG::DEBUG << "(Re)initialize" << endmsg;
73  }
74  log << MSG::DEBUG << " => Initialization of dict_mgr done ! " << m_dict << endmsg;
75 
76  // init base object
77  // ----------------
79  return (1);
80  }
81  else{
82  log << MSG::INFO << " => initialize_from_dictionary(dict_mgr) ="
84  << endmsg;
85  }
86  m_dict = dict_mgr.find_dictionary ("LArHighVoltage");
87 
88  if(!m_dict)
89  {
90  strg = " initialize_from_dictionary - cannot access LArHighVoltage dictionary ";
91  if(m_msgSvc) {
92  log << MSG::ERROR << strg << endmsg;
93  }
94  else
95  {
96  std::cout << "LArHVLineID::" << strg << std::endl;
97  }
98  return 1;
99  }
100 
101  // Register version of the dictionary used
102  // ---------------------------------------
103  if (register_dict_tag(dict_mgr, "LArHighVoltage")) return(1);
104  log << MSG::INFO << "Register_dict_tag of LArHighVoltage is OK" << endmsg;
105 
106  // initialize dictionary version
107  // -----------------------------
108  AtlasDetectorID::setDictVersion(dict_mgr, "LArHighVoltage");
109  log << MSG::INFO << "setDictVersion of LArHighVoltage is OK" << endmsg;
110 
111 
112  // Initialize the field indices
113  // =========================================================================
114  if(initLevelsFromDict()) return (1);
115 
116  /* Find value for the field Calorimeter */
117  const IdDictDictionary* atlasDict = dict_mgr.find_dictionary ("ATLAS");
118  int larHVValue = -1;
119  if (atlasDict->get_label_value("subdet", "LArHighVoltage", larHVValue)) {
120  std::stringstream strm;
121  strm << atlasDict->m_name;
122  strg= " Could not get value for label 'LArHighVoltage' of field 'subdet' in dictionary "+strm.str();
123  if(m_msgSvc){
124  log << MSG::ERROR << strg << endmsg;
125  }
126  else{
127  std::cout << "LArHVLineID:" << strg << std::endl;
128  }
129  return (1);
130  }
131  log << MSG::DEBUG << "[init_from_dictionary] > larHV value = "<< larHVValue << endmsg;
132 
133 
134  /* Find values for the field Configuration */
135  int configurationValue = 1;
136  if (m_dict->get_label_value("configuration", "Atlas", configurationValue)) {
137  std::stringstream strm;
138  strm << m_dict->m_name;
139  strg = "WARNING : Could not get value for label 'configuration' in dictionary "+strm.str();
140  if(m_msgSvc) {
141  log << MSG::INFO << strg << endmsg;
142  }
143  else{
144  std::cout << strg << std::endl;
145  }
146  return (0);
147  }
148  log << MSG::DEBUG << "[init_from_dictionary] > configurationValue = "
149  << configurationValue << endmsg;
150 
151  // Set up Expanded identifier for hvline range prefix
152  // =========================================================
153  ExpandedIdentifier reg_id;
154  reg_id.add(larHVValue);
155  reg_id.add(configurationValue);
156  Range prefix;
157 
158  /*Full range for all lines */
160  m_full_hvline_range = m_dict->build_multirange(reg_id, prefix, "hvline");
161  m_full_canline_range = m_dict->build_multirange(reg_id, prefix, "canline");
162  log << MSG::INFO << "[initialize_from_dictionary] > HV line range -> "
163  << (std::string)m_full_hvline_range << endmsg;
164 
165  // Setup the hash tables
166  // =========================================================
167  if(init_hashes()) return (1);
168 
169  return 0;
170 }
171 
172 
173 //=====================================================================================
175  ExpandedIdentifier& exp_id,
176  const IdContext* context) const
177 //=====================================================================================
178 {
179  MsgStream log(m_msgSvc, "LArHVLineID" );
180  // We assume that the context is >= hvline
181  exp_id.clear();
182  exp_id << lar_field_value()
183  << s_lar_atlas_value
184  << partition(id)
185  << can_line(id)
186  << can_node(id)
187  << hv_line(id);
188  if(context && context->end_index() >= m_hvline_index) {
189  exp_id << hv_line(id);
190  }
191  return (0);
192 }
193 
194 
195 //=============================================================================
197 //=============================================================================
198 {
199  MsgStream log(m_msgSvc, "LArHVLineID" );
200  log << MSG::DEBUG << "[initLevelsFromDict] Entering routine... " << endmsg;
201 
202  if(!m_dict) {
203  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - dictionary NOT initialized "
204  << endmsg ;
205  return (1);
206  }
207 
208  log << MSG::INFO << "[initLevelsFromDict] m_dict OK ... " << endmsg;
209 
210  // Find out which identifier field corresponds to each level.
211  // ========================================================================
212  m_atlas_index = 999;
213  m_configuration_index = 999;
214  m_partition_index = 999;
215  m_canline_index = 999;
216  m_cannode_index = 999;
217  m_hvline_index = 999;
218 
219  log << MSG::DEBUG << "[initLevelsFromDict] data member initialization OK ... " << endmsg;
220 
221  // Search with region name
222  IdDictRegion* reg = m_dict->find_region("LArHV-HEC-A");
223  if (reg) {
224  m_larhvRegion_index = reg->m_index;}
225  else {
226  log << MSG::INFO << "WARNING : LArHVLineID::initLevelsFromDict - unable to find 'barrel-region1' region"
227  << endmsg;
228  return (0);
229  }
230  log << MSG::DEBUG << "[initLevelsFromDict] region 'LAr-HV-HEC-A' found OK ... " << endmsg;
231 
232  // Find ATLAS field
233  // ========================================================================
234  IdDictField* field = m_dict->find_field("subdet") ;
235  if (field) {
236  m_atlas_index = field->m_index ;}
237  else {
238  log << MSG::INFO
239  << "LArHVLineID::initLevelsFromDict - unable to find 'subdet' field " << endmsg ;
240  return (1);
241  }
242  log << MSG::DEBUG
243  << "[initLevelsFromDict] field 'LArHighVoltage' found OK " << endmsg;
244 
245  // Find Configuration field
246  // ========================================================================
247  field = m_dict->find_field("configuration") ;
248  if (field) {
249  m_configuration_index = field->m_index ;}
250  else {
251  log << MSG::INFO
252  << "LArHVLineID::initLevelsFromDict - unable to find 'configuration' field " << endmsg ;
253  return (1);
254  }
255  log << MSG::DEBUG
256  << "[initLevelsFromDict] field config=Atlas found OK " << endmsg;
257 
258  // Look for Field 'partition'
259  // ========================================================================
260  field = m_dict->find_field("partition") ;
261  if (field) {
262  m_partition_index = field->m_index ;}
263  else {
264  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - unable to find 'partition' field "
265  << endmsg ;
266  return (1);
267  }
268  log << MSG::DEBUG << "[initLevelsFromDict] field 'partition' found OK " << endmsg;
269 
270 
271  // Look for Field 'CAN LINE'
272  // ========================================================================
273  field = m_dict->find_field("canline") ;
274  if (field) {
275  m_canline_index = field->m_index ;}
276  else {
277  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - unable to find 'canline' field "
278  << endmsg ;
279  return (1);
280  }
281  log << MSG::DEBUG << "[initLevelsFromDict] field 'canline' found OK " << endmsg;
282 
283 
284  // Look for Fields 'CAN NODE'
285  // ========================================================================
286  field = m_dict->find_field("cannode") ;
287  if (field) {
288  m_cannode_index = field->m_index ;
289  }
290  else {
291  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - unable to find 'cannode' field "
292  << endmsg ;
293  return (1);
294  }
295  log << MSG::DEBUG << "[initLevelsFromDict] field 'cannode' found OK " << endmsg;
296 
297 
298  // Look for Fields 'HV_line'
299  // ========================================================================
300  field = m_dict->find_field("hvline") ;
301  if (field) {
302  m_hvline_index = field->m_index ;
303  }
304  else {
305  log << MSG::INFO << "LArHVLineID::initLevelsFromDict - unable to find 'hvline' field "
306  << endmsg ;
307  return (1);
308  }
309  log << MSG::DEBUG << "[initLevelsFromDict] field 'hvline' found OK " << endmsg;
310 
311 
312  // Set the field implementation
313  // ========================================================================
314 
316  log << MSG::DEBUG << "[initLevelsFromDict] Found levels: " << endmsg ;
317  log << MSG::DEBUG << "[initLevelsFromDict] > larHV " << m_atlas_index << endmsg ;
318  log << MSG::DEBUG << "[initLevelsFromDict] > larConfiguration " << m_configuration_index << endmsg ;
319  log << MSG::DEBUG << "[initLevelsFromDict] > CAN Node " << m_cannode_index << endmsg ;
320  log << MSG::DEBUG << "[initLevelsFromDict] > HV line " << m_hvline_index << endmsg ;
321  log << MSG::DEBUG << "[initLevelsFromDict] > partition " << m_partition_index << endmsg ;
322  log << MSG::DEBUG << "[initLevelsFromDict] > CAN line " << m_canline_index << endmsg ;
323 
324 
325  log << MSG::DEBUG << "[initLevelsFromDict] > ...fields implementation... " << endmsg;
326  log << MSG::DEBUG << "[initLevelsFromDict] > ...implementation: m_larhvcalo_index " << endmsg;
333 
334  log << MSG::DEBUG << "[initLevelsFromDict] Decode index and bit fields for each level: " << endmsg;
335  log << MSG::DEBUG << "[initLevelsFromDict] > larHV " << m_atlas_impl.show_to_string() << endmsg;
336  log << MSG::DEBUG << "[initLevelsFromDict] > larConfig " << m_configuration_impl.show_to_string() << endmsg;
337  log << MSG::DEBUG << "[initLevelsFromDict] > partition " << m_partition_impl.show_to_string() << endmsg;
338  log << MSG::DEBUG << "[initLevelsFromDict] > can line " << m_canline_impl.show_to_string() << endmsg;
339  log << MSG::DEBUG << "[initLevelsFromDict] > can node " << m_cannode_impl.show_to_string() << endmsg;
340  log << MSG::DEBUG << "[initLevelsFromDict] > hv line " << m_hvline_impl.show_to_string() << endmsg;
341 
342 
343  return(0) ;
344 }
345 
346 
347 
348 
349 //=====================================================
351 //=====================================================
352 {
353  MsgStream log(m_msgSvc, "LArHVLineID" );
354  std::stringstream strm1;
355  std::stringstream strm2;
356  std::stringstream strm3;
357  std::string strg1;
358  std::string strg2;
359  std::string strg3;
360 
361  // tower hash
362  // -----------
365  unsigned int nids = 0;
366  std::set<HWIdentifier> ids;
367  for (unsigned int i = 0; i < m_full_atlas_highvoltage_range.size(); ++i) {
369  Range::const_identifier_factory first = range.factory_begin();
370  Range::const_identifier_factory last = range.factory_end();
371  for (; first != last; ++first) {
372  const ExpandedIdentifier& exp_id = (*first);
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: IdDictMgr.cxx:366
LArHVLineID::hvlineContext
IdContext hvlineContext(void) const
Definition: LArHVLineID.cxx:35
IdDictDictionary::build_multirange
MultiRange build_multirange() const
Get MultiRange for full dictionary.
Definition: IdDictMgr.cxx:1048
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:57
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)
LArHVLineID::m_configuration_impl
IdDictFieldImplementation m_configuration_impl
Definition: LArHVLineID.h:191
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:108
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:350
LArHVLineID.h
HWIdentifier
Definition: HWIdentifier.h:13
python.DomainsRegistry.reg
reg
globals -----------------------------------------------------------------—
Definition: DomainsRegistry.py:343
IdDictDictionary::find_field
IdDictField * find_field(const std::string &name) const
Definition: IdDictMgr.cxx:309
IdDictRegion
Definition: IdDictDefs.h:448
LArHVLineID::LArHVLineID
LArHVLineID(void)
only allowed constructor
Definition: LArHVLineID.cxx:18
LArHVLineID::initLevelsFromDict
int initLevelsFromDict(void)
Definition: LArHVLineID.cxx:196
LArHVLineID::get_expanded_id
int get_expanded_id(const HWIdentifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const
Definition: LArHVLineID.cxx:174
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:161
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
Range::const_identifier_factory
Definition: DetectorDescription/Identifier/Identifier/Range.h:191
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:338
LArHVLineID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr)
Initialization from the identifier dictionary.
Definition: LArHVLineID.cxx:50
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:191
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
IdentifierHash.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:27
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: DetectorDescription/Identifier/src/Range.cxx:2488
DeMoScan.first
bool first
Definition: DeMoScan.py:534
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:318
MultiRange::cardinality
size_type cardinality() const
Computes a possible cardinality from all ranges.
Definition: DetectorDescription/Identifier/src/Range.cxx:2503
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
class IdContext
Definition: IdContext.h:34
IdDictRegion::m_implementation
std::vector< IdDictFieldImplementation > m_implementation
Definition: IdDictDefs.h:474
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