2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
7 * @file CaloIdentifier/CaloIDHelper.icc
8 * @author scott snyder <snyder@bnl.gov>
10 * @brief Base class to factor out code common among Calo ID helpers.
11 * Inline implementations.
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.
28 CaloIDHelper::HashGroup::init (T& parent,
29 const std::string& type,
30 const MultiRange& full_range,
31 Identifier (T::*idfunc)
32 (const ExpandedIdentifier&) const,
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)
52 return init (parent.name() + "." + type,
53 ids, end_index, parent.msgSvc(), &full_range);
58 * @brief Return one more than the largest hash code.
61 CaloIDHelper::size_type CaloIDHelper::HashGroup::hash_max() const
63 return m_id_vec.size();
68 * @brief Return a begin iterator over the group's Identifiers.
71 CaloIDHelper::id_iterator CaloIDHelper::HashGroup::begin() const
73 return m_id_vec.begin();
78 * @brief Return an end iterator over the group's Identifiers.
81 CaloIDHelper::id_iterator CaloIDHelper::HashGroup::end() const
83 return m_id_vec.end();
88 * @brief Return a iterator range over the group's Identifiers.
91 CaloIDHelper::id_range CaloIDHelper::HashGroup::range() const
93 return id_range(begin(), end());
98 * @brief Return the identifier for a given hash code (no checking).
101 Identifier CaloIDHelper::HashGroup::id (IdentifierHash hashId) const
103 return m_id_vec[hashId];
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
116 IdentifierHash CaloIDHelper::HashGroup::hash (Identifier id) const
125 * @brief Return a vector of all Identifiers for this group.
128 const std::vector<Identifier>& CaloIDHelper::HashGroup::ids() const
135 * @brief Return the ending index of the context for this group.
138 CaloIDHelper::size_type CaloIDHelper::HashGroup::end_index() const
144 //*************************************************************************
148 * @brief Return the @c HashGroup for channels (cells).
151 const CaloIDHelper::HashGroup& CaloIDHelper::channels() const
158 * @brief Return the @c HashGroup for regions.
161 const CaloIDHelper::HashGroup& CaloIDHelper::regions() const
168 * @brief Return the channel Identifier for a given hash code (no checking).
171 Identifier CaloIDHelper::channel_id (IdentifierHash hashId) const
173 return m_channels.id(hashId);
178 * @brief Return the region Identifier for a given hash code (no checking).
181 Identifier CaloIDHelper::region_id (IdentifierHash hashId) const
183 return m_regions.id(hashId);
188 * @brief Convert a connected channel (cell) Identifier to a hash code.
189 * Some subdetector helpers may override this with a faster version.
192 IdentifierHash CaloIDHelper::channel_hash (Identifier channelId) const
194 return m_channels.hash (channelId);
199 * @brief Convert a connected region Identifier to a hash code.
200 * Some subdetector helpers may override this with a faster version.
203 IdentifierHash CaloIDHelper::region_hash (Identifier regionId) const
205 return m_regions.hash (regionId);
211 * @brief One more than the largest channel (cell) hash code.
214 CaloIDHelper::size_type CaloIDHelper::channel_hash_max() const
216 return m_channels.hash_max();
221 * @brief One more than the largest region hash code.
224 CaloIDHelper::size_type CaloIDHelper::region_hash_max() const
226 return m_regions.hash_max();
231 * @brief Return the context for channels (cells).
234 IdContext CaloIDHelper::channel_context() const
236 return m_channels.context();
241 * @brief Return the context for regions.
244 IdContext CaloIDHelper::region_context() const
246 return m_regions.context();
251 * @brief Return the vector of @c IdDictRegion, accessed via region hash.
254 const std::vector<const IdDictRegion*>& CaloIDHelper::dictRegions() const
256 return m_vecOfDictRegions;
261 * @brief Return the @c HashGroup for channels (cells). non-const.
264 CaloIDHelper::HashGroup& CaloIDHelper::channels()
271 * @brief Return the @c HashGroup for regions. non-const.
274 CaloIDHelper::HashGroup& CaloIDHelper::regions()
281 * @brief Return the dictionary for this subdetector.
284 const IdDictDictionary* CaloIDHelper::dict() const
291 * @brief Return the name for this helper.
294 std::string CaloIDHelper::name() const
301 * @brief Return the message service for this helper.
304 IMessageSvc* CaloIDHelper::msgSvc()