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