ATLAS Offline Software
CaloIDHelper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // $Id$
15 #include "IdDict/IdDictDefs.h"
16 #include "Identifier/Range.h"
17 #include "GaudiKernel/MsgStream.h"
18 
19 
20 
26  : m_end_index(99999)
27 {
28 }
29 
30 
43 int CaloIDHelper::HashGroup::init (const std::string& name,
44  const std::set<Identifier>& ids,
45  size_type end_index,
46  IMessageSvc* msgSvc,
47  const MultiRange* full_range)
48 {
49  m_end_index = end_index;
50  if (full_range && full_range->cardinality() != ids.size()) {
51  MsgStream log (msgSvc, "CaloIDHelper");
52  log << MSG::ERROR << name << " set size " << ids.size()
53  << " not equal to hash max " << full_range->cardinality() << endmsg;
54  return 1;
55  }
56  m_id_vec.assign (ids.begin(), ids.end());
57  return 0;
58 }
59 
60 
69  IdentifierHash& hash_id) const
70 {
71  std::vector<Identifier>::const_iterator it = std::lower_bound(m_id_vec.begin(),m_id_vec.end(),id);
72  if ( it != m_id_vec.end() ){
73  hash_id = it - m_id_vec.begin();
74  return 0;
75  }
76  return 1;
77 }
78 
79 
84 {
86  return IdContext (id, 0, m_end_index);
87 }
88 
89 
90 //*************************************************************************
91 
92 
99 CaloIDHelper::CaloIDHelper (const std::string& name)
100  : m_name (name),
101  m_dict(nullptr)
102 {
103 }
104 
105 
120  Identifier& id,
121  const IdContext* context ) const
122 {
123  int result = 1;
124  id.clear();
125 
126  size_t begin = (context) ? context->begin_index(): 0;
127  size_t end = (context) ? context->end_index() : 0;
128 
129  if (0 == begin) {
130  const HashGroup* hg = nullptr;
131  if (m_channels.end_index() == end) hg = &m_channels;
132  else if (m_regions.end_index() == end) hg = &m_regions;
133 
134  if (hg) {
135  if (hash_id < hg->hash_max()) {
136  id = hg->id (hash_id);
137  result = 0;
138  }
139  }
140  }
141 
142  return(result);
143 }
144 
145 
161 int CaloIDHelper::get_hash (const Identifier& id, IdentifierHash& hash_id, const IdContext* context ) const
162 {
163  hash_id = IdentifierHash();
164 
165  size_t begin = (context) ? context->begin_index(): 0;
166  size_t end = (context) ? context->end_index() : 0;
167 
168  if (0 == begin) {
169  const HashGroup* hg = nullptr;
170  if (m_channels.end_index() == end) hg = &m_channels;
171  else if (m_regions.end_index() == end) hg = &m_regions;
172 
173  if (hg)
174  return hg->get_hash (id, hash_id);
175  }
176 
177  return 1;
178 }
179 
180 
186 {
187  if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
188  return m_vecOfDictRegions[regHash]->m_deta;
189 }
190 
191 
197 {
198  if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
199  return 2. * M_PI / m_vecOfDictRegions[regHash]->m_dphi ;
200 }
201 
202 
207 float CaloIDHelper::eta0(const IdentifierHash regHash) const
208 {
209  if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
210  return (m_vecOfDictRegions[regHash]->m_eta0);
211 }
212 
213 
218 float CaloIDHelper::phi0(const IdentifierHash regHash) const
219 {
220  if (regHash >= m_vecOfDictRegions.size()) return NOT_VALID;
221  return (m_vecOfDictRegions[regHash]->m_phi0);
222 }
223 
224 
231 int
233  const std::string& dict_name)
234 {
235  // init base object
236  if(AtlasDetectorID::initialize_from_dictionary(dict_mgr)) return (1);
237 
238  // Register version of dictionary
239  if (register_dict_tag(dict_mgr, dict_name)) return(1);
240 
241  m_dict = dict_mgr.find_dictionary (dict_name);
242  if(!m_dict) {
243  MsgStream log(m_msgSvc, "CaloIDHelper" );
244  log << MSG::ERROR << " cannot access " << dict_name << "dictionary"
245  << endmsg;
246  return 1;
247  }
248  return 0;
249 }
250 
251 
258 int
260 {
261  m_vecOfDictRegions.clear();
262  m_vecOfDictRegions.reserve (regions().hash_max());
263  IdContext region_cntxt = region_context();
264  ExpandedIdentifier expRegId;
265  for (Identifier id : regions().range()) {
266  if(!get_expanded_id(id, expRegId, &region_cntxt)) {
267  m_vecOfDictRegions.push_back (m_dict->find_region(expRegId,group_name));
268  }
269  }
270  // cppcheck-suppress assertWithSideEffect
271  assert (m_vecOfDictRegions.size() == regions().hash_max());
272  return 0;
273 }
274 
275 
IdDictDictionary::find_region
IdDictRegion * find_region(const std::string &region_name) const
Definition: IdDictMgr.cxx:368
CaloIDHelper::m_name
std::string m_name
Name of this helper.
Definition: CaloIDHelper.h:330
CaloIDHelper::NOT_VALID
@ NOT_VALID
Definition: CaloIDHelper.h:36
AtlasDetectorID::initialize_from_dictionary
virtual int initialize_from_dictionary(const IdDictMgr &dict_mgr) override
Initialization from the identifier dictionary.
Definition: AtlasDetectorID.cxx:320
get_generator_info.result
result
Definition: get_generator_info.py:21
CaloIDHelper::fill_vec_of_dict_regions
int fill_vec_of_dict_regions(const std::string &group_name="")
Initialize the list of detector regions.
Definition: CaloIDHelper.cxx:259
CaloIDHelper::HashGroup::init
int init(T &parent, const std::string &type, const MultiRange &full_range, Identifier(T::*idfunc)(const ExpandedIdentifier &) const, size_type end_index)
Initialize.
CaloIDHelper::HashGroup::end_index
size_type end_index() const
Return the ending index of the context for this group.
IdContext::end_index
size_type end_index() const
Definition: IdContext.h:46
CaloIDHelper::region_context
IdContext region_context() const
Return the context for regions.
Range.h
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
skel.it
it
Definition: skel.GENtoEVGEN.py:396
CaloIDHelper::HashGroup::id
Identifier id(IdentifierHash hashId) const
Return the identifier for a given hash code (no checking).
M_PI
#define M_PI
Definition: ActiveFraction.h:11
ExpandedIdentifier
Definition: DetectorDescription/Identifier/Identifier/ExpandedIdentifier.h:102
CaloIDHelper::get_id
virtual int get_id(const IdentifierHash &hash_id, Identifier &id, const IdContext *context=0) const
Convert a hash code to an Identifier for either channels or regions, depending on the context.
Definition: CaloIDHelper.cxx:119
AtlasDetectorID::m_msgSvc
IMessageSvc * m_msgSvc
pointer to the message service
Definition: AtlasDetectorID.h:368
CaloIDHelper::CaloIDHelper
CaloIDHelper(const std::string &name)
Constructor.
Definition: CaloIDHelper.cxx:99
CaloIDHelper::HashGroup::get_hash
int get_hash(Identifier id, IdentifierHash &hash_id) const
Look up the hash code corresponding to an Identifier.
Definition: CaloIDHelper.cxx:68
CaloIDHelper::regions
const HashGroup & regions() const
Return the HashGroup for regions.
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
IdDictDefs.h
CaloIDHelper::size_type
Identifier::size_type size_type
Definition: CaloIDHelper.h:39
CaloIDHelper::m_vecOfDictRegions
std::vector< const IdDictRegion * > m_vecOfDictRegions
List of IdDictRegion objects.
Definition: CaloIDHelper.h:342
IdDictMgr
Definition: IdDictDefs.h:32
IdContext::begin_index
size_type begin_index() const
Definition: IdContext.h:45
IdDictMgr::find_dictionary
IdDictDictionary * find_dictionary(const std::string &name) const
Access dictionary by name.
Definition: IdDictMgr.cxx:163
CaloIDHelper::etaGranularity
float etaGranularity(const IdentifierHash regHash) const
Return the eta granularity of a region, or NOT_VALID.
Definition: CaloIDHelper.cxx:185
CaloIDHelper::m_regions
HashGroup m_regions
Group of region Identifiers.
Definition: CaloIDHelper.h:336
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
CaloIDHelper::HashGroup::HashGroup
HashGroup()
Constructor.
Definition: CaloIDHelper.cxx:25
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
mc.group_name
group_name
Definition: mc.PhPy8EG_A14NNPDF23_NNLOPS_example.py:33
CaloIDHelper::initialize_base_from_dictionary
int initialize_base_from_dictionary(const IdDictMgr &dict_mgr, const std::string &dict_name)
Do basic initialization of the helper.
Definition: CaloIDHelper.cxx:232
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
MultiRange
A MultiRange combines several Ranges.
Definition: MultiRange.h:17
CaloIDHelper::eta0
float eta0(const IdentifierHash regHash) const
Return the minimum eta of region, or NOT_VALID.
Definition: CaloIDHelper.cxx:207
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:220
CaloIDHelper::name
const std::string & name() const
Return the name for this helper.
python.subdetectors.mmg.ids
ids
Definition: mmg.py:8
CaloIDHelper::get_hash
virtual int get_hash(const Identifier &id, IdentifierHash &hash_id, const IdContext *context=0) const
Convert an Identifier to a hash code for either channels or regions, depending on the context.
Definition: CaloIDHelper.cxx:161
CaloIDHelper::m_dict
const IdDictDictionary * m_dict
The dictionary for this helper.
Definition: CaloIDHelper.h:339
CaloIDHelper::msgSvc
IMessageSvc * msgSvc()
Return the message service for this helper (may be null).
CaloIDHelper::phi0
float phi0(const IdentifierHash regHash) const
Return the minimum phi of region, or NOT_VALID.
Definition: CaloIDHelper.cxx:218
CaloIDHelper::m_channels
HashGroup m_channels
Group of channel (cell) Identifiers.
Definition: CaloIDHelper.h:333
CaloIDHelper.h
Base class to factor out code common among Calo ID helpers.
CaloIDHelper::HashGroup::context
IdContext context() const
Return the context for this group.
Definition: CaloIDHelper.cxx:83
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
CaloIDHelper::phiGranularity
float phiGranularity(const IdentifierHash regHash) const
Return the phi granularity of a region, or NOT_VALID.
Definition: CaloIDHelper.cxx:196
CaloIDHelper::get_expanded_id
virtual int get_expanded_id(const Identifier &id, ExpandedIdentifier &exp_id, const IdContext *context) const =0
Create an expanded Identifier from an Identifier.
MultiRange::cardinality
size_type cardinality() const
Computes a possible cardinality from all ranges.
Definition: MultiRange.cxx:82
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
CaloIDHelper::HashGroup
Manage a list of identifiers.
Definition: CaloIDHelper.h:60
IdContext
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition: IdContext.h:26
Identifier
Definition: IdentifierFieldParser.cxx:14