ATLAS Offline Software
CaloIDHelper.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 /**
5  * @file CaloIdentifier/CaloIDHelper.icc
6  * @author scott snyder <snyder@bnl.gov>
7  * @date May, 2013
8  * @brief Base class to factor out code common among Calo ID helpers.
9  * Inline implementations.
10  */
11 
12 
13 /**
14  * @brief Initialize.
15  * @param parent The parent ID helper (in which @c idfunc is defined).
16  * @param type A string to add on to the name.
17  * @param full_range The @c MultiRange for to this group.
18  * @param idfunc Function to convert from an @c ExpandedIdentifier
19  * to an @c Identifier for this group.
20  * @param end_index The ending index for the context for this group.
21  * @return 0 on success; non-zero on failure.
22  */
23 template <class T>
24 inline
25 int
26 CaloIDHelper::HashGroup::init (T& parent,
27  const std::string& type,
28  const MultiRange& full_range,
29  Identifier (T::*idfunc)
30  (const ExpandedIdentifier&) const,
31  size_type end_index)
32 {
33  std::set<Identifier> ids;
34  for (unsigned int i = 0; i < full_range.size(); ++i) {
35  const Range& range = full_range[i];
36  ConstRangeIterator rit(range);
37  auto first = rit.begin();
38  auto last = rit.end();
39  for (; first != last; ++first) {
40  const ExpandedIdentifier& exp_id = (*first);
41  Identifier id = (parent.*idfunc) (exp_id);
42  if(!(ids.insert(id)).second){
43  MsgStream log (parent.msgSvc(), "CaloIDHelper::HashGroup");
44  log << MSG::ERROR << parent.name() << "init_hashes "
45  << " duplicated id for channel id. nids= " << ids.size()
46  << " compact Id " << parent.show_to_string(id)
47  << endmsg;
48  }
49  }
50  }
51  return init (parent.name() + "." + type,
52  ids, end_index, parent.msgSvc(), &full_range);
53 }
54 
55 
56 /**
57  * @brief Return one more than the largest hash code.
58  */
59 inline
60 CaloIDHelper::size_type CaloIDHelper::HashGroup::hash_max() const
61 {
62  return m_id_vec.size();
63 }
64 
65 
66 /**
67  * @brief Return a begin iterator over the group's Identifiers.
68  */
69 inline
70 CaloIDHelper::id_iterator CaloIDHelper::HashGroup::begin() const
71 {
72  return m_id_vec.begin();
73 }
74 
75 
76 /**
77  * @brief Return an end iterator over the group's Identifiers.
78  */
79 inline
80 CaloIDHelper::id_iterator CaloIDHelper::HashGroup::end() const
81 {
82  return m_id_vec.end();
83 }
84 
85 
86 /**
87  * @brief Return a iterator range over the group's Identifiers.
88  */
89 inline
90 CaloIDHelper::id_range CaloIDHelper::HashGroup::range() const
91 {
92  return id_range(begin(), end());
93 }
94 
95 
96 /**
97  * @brief Return the identifier for a given hash code (no checking).
98  */
99 inline
100 Identifier CaloIDHelper::HashGroup::id (IdentifierHash hashId) const
101 {
102  return m_id_vec[hashId];
103 }
104 
105 
106 /**
107  * @brief Look up the hash code corresponding to an Identifier.
108  * Uses binary search.
109  * @param id The identifier to look up.
110  * @return The corresponding hash code.
111  * An invalid IdentifierHash will be returned if the Identifier
112  * is not found.
113  */
114 inline
115 IdentifierHash CaloIDHelper::HashGroup::hash (Identifier id) const
116 {
117  IdentifierHash ret;
118  get_hash (id, ret);
119  return ret;
120 }
121 
122 
123 /**
124  * @brief Return a vector of all Identifiers for this group.
125  */
126 inline
127 const std::vector<Identifier>& CaloIDHelper::HashGroup::ids() const
128 {
129  return m_id_vec;
130 }
131 
132 
133 /**
134  * @brief Return the ending index of the context for this group.
135  */
136 inline
137 CaloIDHelper::size_type CaloIDHelper::HashGroup::end_index() const
138 {
139  return m_end_index;
140 }
141 
142 
143 //*************************************************************************
144 
145 
146 /**
147  * @brief Return the @c HashGroup for channels (cells).
148  */
149 inline
150 const CaloIDHelper::HashGroup& CaloIDHelper::channels() const
151 {
152  return m_channels;
153 }
154 
155 
156 /**
157  * @brief Return the @c HashGroup for regions.
158  */
159 inline
160 const CaloIDHelper::HashGroup& CaloIDHelper::regions() const
161 {
162  return m_regions;
163 }
164 
165 
166 /**
167  * @brief Return the channel Identifier for a given hash code (no checking).
168  */
169 inline
170 Identifier CaloIDHelper::channel_id (IdentifierHash hashId) const
171 {
172  return m_channels.id(hashId);
173 }
174 
175 
176 /**
177  * @brief Return the region Identifier for a given hash code (no checking).
178  */
179 inline
180 Identifier CaloIDHelper::region_id (IdentifierHash hashId) const
181 {
182  return m_regions.id(hashId);
183 }
184 
185 
186 /**
187  * @brief Convert a connected channel (cell) Identifier to a hash code.
188  * Some subdetector helpers may override this with a faster version.
189  */
190 inline
191 IdentifierHash CaloIDHelper::channel_hash (Identifier channelId) const
192 {
193  return m_channels.hash (channelId);
194 }
195 
196 
197 /**
198  * @brief Convert a connected region Identifier to a hash code.
199  * Some subdetector helpers may override this with a faster version.
200  */
201 inline
202 IdentifierHash CaloIDHelper::region_hash (Identifier regionId) const
203 {
204  return m_regions.hash (regionId);
205 }
206 
207 
208 
209 /**
210  * @brief One more than the largest channel (cell) hash code.
211  */
212 inline
213 CaloIDHelper::size_type CaloIDHelper::channel_hash_max() const
214 {
215  return m_channels.hash_max();
216 }
217 
218 
219 /**
220  * @brief One more than the largest region hash code.
221  */
222 inline
223 CaloIDHelper::size_type CaloIDHelper::region_hash_max() const
224 {
225  return m_regions.hash_max();
226 }
227 
228 
229 /**
230  * @brief Return the context for channels (cells).
231  */
232 inline
233 IdContext CaloIDHelper::channel_context() const
234 {
235  return m_channels.context();
236 }
237 
238 
239 /**
240  * @brief Return the context for regions.
241  */
242 inline
243 IdContext CaloIDHelper::region_context() const
244 {
245  return m_regions.context();
246 }
247 
248 
249 /**
250  * @brief Return the vector of @c IdDictRegion, accessed via region hash.
251  */
252 inline
253 const std::vector<const IdDictRegion*>& CaloIDHelper::dictRegions() const
254 {
255  return m_vecOfDictRegions;
256 }
257 
258 
259 /**
260  * @brief Return the @c HashGroup for channels (cells). non-const.
261  */
262 inline
263 CaloIDHelper::HashGroup& CaloIDHelper::channels()
264 {
265  return m_channels;
266 }
267 
268 
269 /**
270  * @brief Return the @c HashGroup for regions. non-const.
271  */
272 inline
273 CaloIDHelper::HashGroup& CaloIDHelper::regions()
274 {
275  return m_regions;
276 }
277 
278 
279 /**
280  * @brief Return the dictionary for this subdetector.
281  */
282 inline
283 const IdDictDictionary* CaloIDHelper::dict() const
284 {
285  return m_dict;
286 }
287 
288 
289 /**
290  * @brief Return the name for this helper.
291  */
292 inline
293 const std::string& CaloIDHelper::name() const
294 {
295  return m_name;
296 }
297 
298 
299 /**
300  * @brief Return the message service for this helper.
301  */
302 inline
303 IMessageSvc* CaloIDHelper::msgSvc()
304 {
305  return m_msgSvc;
306 }