2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
5 * @file CaloIdentifier/CaloIDHelper.icc
6 * @author scott snyder <snyder@bnl.gov>
8 * @brief Base class to factor out code common among Calo ID helpers.
9 * Inline implementations.
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.
26CaloIDHelper::HashGroup::init (T& parent,
27 const std::string& type,
28 const MultiRange& full_range,
29 Identifier (T::*idfunc)
30 (const ExpandedIdentifier&) const,
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)
50 return init (parent.name() + "." + type,
51 ids, end_index, &full_range);
56 * @brief Return one more than the largest hash code.
59CaloIDHelper::size_type CaloIDHelper::HashGroup::hash_max() const
61 return m_id_vec.size();
66 * @brief Return a begin iterator over the group's Identifiers.
69CaloIDHelper::id_iterator CaloIDHelper::HashGroup::begin() const
71 return m_id_vec.begin();
76 * @brief Return an end iterator over the group's Identifiers.
79CaloIDHelper::id_iterator CaloIDHelper::HashGroup::end() const
81 return m_id_vec.end();
86 * @brief Return a iterator range over the group's Identifiers.
89CaloIDHelper::id_range CaloIDHelper::HashGroup::range() const
91 return id_range(begin(), end());
96 * @brief Return the identifier for a given hash code (no checking).
99Identifier CaloIDHelper::HashGroup::id (IdentifierHash hashId) const
101 return m_id_vec.at(hashId);
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
114IdentifierHash CaloIDHelper::HashGroup::hash (Identifier id) const
123 * @brief Return a vector of all Identifiers for this group.
126const std::vector<Identifier>& CaloIDHelper::HashGroup::ids() const
133 * @brief Return the ending index of the context for this group.
136CaloIDHelper::size_type CaloIDHelper::HashGroup::end_index() const
142//*************************************************************************
146 * @brief Return the @c HashGroup for channels (cells).
149const CaloIDHelper::HashGroup& CaloIDHelper::channels() const
156 * @brief Return the @c HashGroup for regions.
159const CaloIDHelper::HashGroup& CaloIDHelper::regions() const
166 * @brief Return the channel Identifier for a given hash code (no checking).
169Identifier CaloIDHelper::channel_id (IdentifierHash hashId) const
171 return m_channels.id(hashId);
176 * @brief Return the region Identifier for a given hash code (no checking).
179Identifier CaloIDHelper::region_id (IdentifierHash hashId) const
181 return m_regions.id(hashId);
186 * @brief Convert a connected channel (cell) Identifier to a hash code.
187 * Some subdetector helpers may override this with a faster version.
190IdentifierHash CaloIDHelper::channel_hash (Identifier channelId) const
192 return m_channels.hash (channelId);
197 * @brief Convert a connected region Identifier to a hash code.
198 * Some subdetector helpers may override this with a faster version.
201IdentifierHash CaloIDHelper::region_hash (Identifier regionId) const
203 return m_regions.hash (regionId);
209 * @brief One more than the largest channel (cell) hash code.
212CaloIDHelper::size_type CaloIDHelper::channel_hash_max() const
214 return m_channels.hash_max();
219 * @brief One more than the largest region hash code.
222CaloIDHelper::size_type CaloIDHelper::region_hash_max() const
224 return m_regions.hash_max();
229 * @brief Return the context for channels (cells).
232IdContext CaloIDHelper::channel_context() const
234 return m_channels.context();
239 * @brief Return the context for regions.
242IdContext CaloIDHelper::region_context() const
244 return m_regions.context();
249 * @brief Return the vector of @c IdDictRegion, accessed via region hash.
252const std::vector<const IdDictRegion*>& CaloIDHelper::dictRegions() const
254 return m_vecOfDictRegions;
259 * @brief Return the @c HashGroup for channels (cells). non-const.
262CaloIDHelper::HashGroup& CaloIDHelper::channels()
269 * @brief Return the @c HashGroup for regions. non-const.
272CaloIDHelper::HashGroup& CaloIDHelper::regions()
279 * @brief Return the dictionary for this subdetector.
282const IdDictDictionary* CaloIDHelper::dict() const
289 * @brief Return the name for this helper.
292const std::string& CaloIDHelper::name() const