ATLAS Offline Software
Loading...
Searching...
No Matches
CaloIDHelper.icc
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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 */
23template <class T>
24inline
25int
26CaloIDHelper::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 parent.msg() << MSG::ERROR << "init_hashes "
44 << " duplicated id for channel id. nids= " << ids.size()
45 << " compact Id " << parent.show_to_string(id)
46 << endmsg;
47 }
48 }
49 }
50 return init (parent.name() + "." + type,
51 ids, end_index, &full_range);
52}
53
54
55/**
56 * @brief Return one more than the largest hash code.
57 */
58inline
59CaloIDHelper::size_type CaloIDHelper::HashGroup::hash_max() const
60{
61 return m_id_vec.size();
62}
63
64
65/**
66 * @brief Return a begin iterator over the group's Identifiers.
67 */
68inline
69CaloIDHelper::id_iterator CaloIDHelper::HashGroup::begin() const
70{
71 return m_id_vec.begin();
72}
73
74
75/**
76 * @brief Return an end iterator over the group's Identifiers.
77 */
78inline
79CaloIDHelper::id_iterator CaloIDHelper::HashGroup::end() const
80{
81 return m_id_vec.end();
82}
83
84
85/**
86 * @brief Return a iterator range over the group's Identifiers.
87 */
88inline
89CaloIDHelper::id_range CaloIDHelper::HashGroup::range() const
90{
91 return id_range(begin(), end());
92}
93
94
95/**
96 * @brief Return the identifier for a given hash code (no checking).
97 */
98inline
99Identifier CaloIDHelper::HashGroup::id (IdentifierHash hashId) const
100{
101 return m_id_vec.at(hashId);
102}
103
104
105/**
106 * @brief Look up the hash code corresponding to an Identifier.
107 * Uses binary search.
108 * @param id The identifier to look up.
109 * @return The corresponding hash code.
110 * An invalid IdentifierHash will be returned if the Identifier
111 * is not found.
112 */
113inline
114IdentifierHash CaloIDHelper::HashGroup::hash (Identifier id) const
115{
116 IdentifierHash ret;
117 get_hash (id, ret);
118 return ret;
119}
120
121
122/**
123 * @brief Return a vector of all Identifiers for this group.
124 */
125inline
126const std::vector<Identifier>& CaloIDHelper::HashGroup::ids() const
127{
128 return m_id_vec;
129}
130
131
132/**
133 * @brief Return the ending index of the context for this group.
134 */
135inline
136CaloIDHelper::size_type CaloIDHelper::HashGroup::end_index() const
137{
138 return m_end_index;
139}
140
141
142//*************************************************************************
143
144
145/**
146 * @brief Return the @c HashGroup for channels (cells).
147 */
148inline
149const CaloIDHelper::HashGroup& CaloIDHelper::channels() const
150{
151 return m_channels;
152}
153
154
155/**
156 * @brief Return the @c HashGroup for regions.
157 */
158inline
159const CaloIDHelper::HashGroup& CaloIDHelper::regions() const
160{
161 return m_regions;
162}
163
164
165/**
166 * @brief Return the channel Identifier for a given hash code (no checking).
167 */
168inline
169Identifier CaloIDHelper::channel_id (IdentifierHash hashId) const
170{
171 return m_channels.id(hashId);
172}
173
174
175/**
176 * @brief Return the region Identifier for a given hash code (no checking).
177 */
178inline
179Identifier CaloIDHelper::region_id (IdentifierHash hashId) const
180{
181 return m_regions.id(hashId);
182}
183
184
185/**
186 * @brief Convert a connected channel (cell) Identifier to a hash code.
187 * Some subdetector helpers may override this with a faster version.
188 */
189inline
190IdentifierHash CaloIDHelper::channel_hash (Identifier channelId) const
191{
192 return m_channels.hash (channelId);
193}
194
195
196/**
197 * @brief Convert a connected region Identifier to a hash code.
198 * Some subdetector helpers may override this with a faster version.
199 */
200inline
201IdentifierHash CaloIDHelper::region_hash (Identifier regionId) const
202{
203 return m_regions.hash (regionId);
204}
205
206
207
208/**
209 * @brief One more than the largest channel (cell) hash code.
210 */
211inline
212CaloIDHelper::size_type CaloIDHelper::channel_hash_max() const
213{
214 return m_channels.hash_max();
215}
216
217
218/**
219 * @brief One more than the largest region hash code.
220 */
221inline
222CaloIDHelper::size_type CaloIDHelper::region_hash_max() const
223{
224 return m_regions.hash_max();
225}
226
227
228/**
229 * @brief Return the context for channels (cells).
230 */
231inline
232IdContext CaloIDHelper::channel_context() const
233{
234 return m_channels.context();
235}
236
237
238/**
239 * @brief Return the context for regions.
240 */
241inline
242IdContext CaloIDHelper::region_context() const
243{
244 return m_regions.context();
245}
246
247
248/**
249 * @brief Return the vector of @c IdDictRegion, accessed via region hash.
250 */
251inline
252const std::vector<const IdDictRegion*>& CaloIDHelper::dictRegions() const
253{
254 return m_vecOfDictRegions;
255}
256
257
258/**
259 * @brief Return the @c HashGroup for channels (cells). non-const.
260 */
261inline
262CaloIDHelper::HashGroup& CaloIDHelper::channels()
263{
264 return m_channels;
265}
266
267
268/**
269 * @brief Return the @c HashGroup for regions. non-const.
270 */
271inline
272CaloIDHelper::HashGroup& CaloIDHelper::regions()
273{
274 return m_regions;
275}
276
277
278/**
279 * @brief Return the dictionary for this subdetector.
280 */
281inline
282const IdDictDictionary* CaloIDHelper::dict() const
283{
284 return m_dict;
285}
286
287
288/**
289 * @brief Return the name for this helper.
290 */
291inline
292const std::string& CaloIDHelper::name() const
293{
294 return m_name;
295}
296