2 Copyright (C) 2002-2024 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.
26 CaloIDHelper::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 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)
51 return init (parent.name() + "." + type,
52 ids, end_index, parent.msgSvc(), &full_range);
57 * @brief Return one more than the largest hash code.
60 CaloIDHelper::size_type CaloIDHelper::HashGroup::hash_max() const
62 return m_id_vec.size();
67 * @brief Return a begin iterator over the group's Identifiers.
70 CaloIDHelper::id_iterator CaloIDHelper::HashGroup::begin() const
72 return m_id_vec.begin();
77 * @brief Return an end iterator over the group's Identifiers.
80 CaloIDHelper::id_iterator CaloIDHelper::HashGroup::end() const
82 return m_id_vec.end();
87 * @brief Return a iterator range over the group's Identifiers.
90 CaloIDHelper::id_range CaloIDHelper::HashGroup::range() const
92 return id_range(begin(), end());
97 * @brief Return the identifier for a given hash code (no checking).
100 Identifier CaloIDHelper::HashGroup::id (IdentifierHash hashId) const
102 return m_id_vec[hashId];
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
115 IdentifierHash CaloIDHelper::HashGroup::hash (Identifier id) const
124 * @brief Return a vector of all Identifiers for this group.
127 const std::vector<Identifier>& CaloIDHelper::HashGroup::ids() const
134 * @brief Return the ending index of the context for this group.
137 CaloIDHelper::size_type CaloIDHelper::HashGroup::end_index() const
143 //*************************************************************************
147 * @brief Return the @c HashGroup for channels (cells).
150 const CaloIDHelper::HashGroup& CaloIDHelper::channels() const
157 * @brief Return the @c HashGroup for regions.
160 const CaloIDHelper::HashGroup& CaloIDHelper::regions() const
167 * @brief Return the channel Identifier for a given hash code (no checking).
170 Identifier CaloIDHelper::channel_id (IdentifierHash hashId) const
172 return m_channels.id(hashId);
177 * @brief Return the region Identifier for a given hash code (no checking).
180 Identifier CaloIDHelper::region_id (IdentifierHash hashId) const
182 return m_regions.id(hashId);
187 * @brief Convert a connected channel (cell) Identifier to a hash code.
188 * Some subdetector helpers may override this with a faster version.
191 IdentifierHash CaloIDHelper::channel_hash (Identifier channelId) const
193 return m_channels.hash (channelId);
198 * @brief Convert a connected region Identifier to a hash code.
199 * Some subdetector helpers may override this with a faster version.
202 IdentifierHash CaloIDHelper::region_hash (Identifier regionId) const
204 return m_regions.hash (regionId);
210 * @brief One more than the largest channel (cell) hash code.
213 CaloIDHelper::size_type CaloIDHelper::channel_hash_max() const
215 return m_channels.hash_max();
220 * @brief One more than the largest region hash code.
223 CaloIDHelper::size_type CaloIDHelper::region_hash_max() const
225 return m_regions.hash_max();
230 * @brief Return the context for channels (cells).
233 IdContext CaloIDHelper::channel_context() const
235 return m_channels.context();
240 * @brief Return the context for regions.
243 IdContext CaloIDHelper::region_context() const
245 return m_regions.context();
250 * @brief Return the vector of @c IdDictRegion, accessed via region hash.
253 const std::vector<const IdDictRegion*>& CaloIDHelper::dictRegions() const
255 return m_vecOfDictRegions;
260 * @brief Return the @c HashGroup for channels (cells). non-const.
263 CaloIDHelper::HashGroup& CaloIDHelper::channels()
270 * @brief Return the @c HashGroup for regions. non-const.
273 CaloIDHelper::HashGroup& CaloIDHelper::regions()
280 * @brief Return the dictionary for this subdetector.
283 const IdDictDictionary* CaloIDHelper::dict() const
290 * @brief Return the name for this helper.
293 const std::string& CaloIDHelper::name() const
300 * @brief Return the message service for this helper.
303 IMessageSvc* CaloIDHelper::msgSvc()