ATLAS Offline Software
Loading...
Searching...
No Matches
CaloIDHelper::HashGroup Class Reference

Manage a list of identifiers. More...

#include <CaloIDHelper.h>

Collaboration diagram for CaloIDHelper::HashGroup:

Public Member Functions

 HashGroup ()
 Constructor.
template<class T>
int init (T &parent, const std::string &type, const MultiRange &full_range, Identifier(T::*idfunc)(const ExpandedIdentifier &) const, size_type end_index)
 Initialize.
int init (const std::string &name, const std::set< Identifier > &ids, size_type end_index, const MultiRange *full_range=0)
 Initialize.
size_type hash_max () const
 Return one more than the largest hash code.
id_iterator begin () const
 Return a begin iterator over the group's Identifiers.
id_iterator end () const
 Return an end iterator over the group's Identifiers.
id_range range () const
 Return an iterator range over the group's Identifiers.
Identifier id (IdentifierHash hashId) const
 Return the identifier for a given hash code (no checking).
int get_hash (Identifier id, IdentifierHash &hash_id) const
 Look up the hash code corresponding to an Identifier.
IdentifierHash hash (Identifier id) const
 Look up the hash code corresponding to an Identifier.
const std::vector< Identifier > & ids () const
 Return a vector of all Identifiers for this group.
size_type end_index () const
 Return the ending index of the context for this group.
IdContext context () const
 Return the context for this group.

Private Attributes

std::vector< Identifierm_id_vec
 List of Identifiers for this group.
size_type m_end_index
 Ending index for this group's context.

Detailed Description

Manage a list of identifiers.

The identifiers are kept in sorted order, and the index of an identifier in this list defines its hash value. We supply methods for converting between identifiers and the hash value; we also keep track of the corresponding ID context.

Most calo ID helpers will use two of these: one for channels (cells) and one for regiosn.

Definition at line 59 of file CaloIDHelper.h.

Constructor & Destructor Documentation

◆ HashGroup()

CaloIDHelper::HashGroup::HashGroup ( )

Constructor.

Starts in an uninitialized state.

Definition at line 25 of file CaloIDHelper.cxx.

26 : m_end_index(99999)
27{
28}
size_type m_end_index
Ending index for this group's context.

Member Function Documentation

◆ begin()

id_iterator CaloIDHelper::HashGroup::begin ( ) const

Return a begin iterator over the group's Identifiers.

◆ context()

IdContext CaloIDHelper::HashGroup::context ( ) const

Return the context for this group.

Definition at line 80 of file CaloIDHelper.cxx.

81{
82 ExpandedIdentifier id;
83 return IdContext (id, 0, m_end_index);
84}
Identifier id(IdentifierHash hashId) const
Return the identifier for a given hash code (no checking).

◆ end()

id_iterator CaloIDHelper::HashGroup::end ( ) const

Return an end iterator over the group's Identifiers.

◆ end_index()

size_type CaloIDHelper::HashGroup::end_index ( ) const

Return the ending index of the context for this group.

◆ get_hash()

int CaloIDHelper::HashGroup::get_hash ( Identifier id,
IdentifierHash & hash_id ) const

Look up the hash code corresponding to an Identifier.

Look up the hash code corresponding ot an Identifier.

Uses binary search.

Parameters
idThe identifier to look up.
[out]hash_idThe corresponding hash code.
Returns
0 if the Identifier was found; non-zero otherwise.

Definition at line 65 of file CaloIDHelper.cxx.

67{
68 std::vector<Identifier>::const_iterator it = std::lower_bound(m_id_vec.begin(),m_id_vec.end(),id);
69 if ( it != m_id_vec.end() ){
70 hash_id = it - m_id_vec.begin();
71 return 0;
72 }
73 return 1;
74}
std::vector< Identifier > m_id_vec
List of Identifiers for this group.

◆ hash()

IdentifierHash CaloIDHelper::HashGroup::hash ( Identifier id) const

Look up the hash code corresponding to an Identifier.

Uses binary search.

Parameters
idThe identifier to look up.
Returns
The corresponding hash code. An invalid IdentifierHash will be returned if the Identifier is not found.

◆ hash_max()

size_type CaloIDHelper::HashGroup::hash_max ( ) const

Return one more than the largest hash code.

◆ id()

Identifier CaloIDHelper::HashGroup::id ( IdentifierHash hashId) const

Return the identifier for a given hash code (no checking).

◆ ids()

const std::vector< Identifier > & CaloIDHelper::HashGroup::ids ( ) const

Return a vector of all Identifiers for this group.

◆ init() [1/2]

int CaloIDHelper::HashGroup::init ( const std::string & name,
const std::set< Identifier > & ids,
size_type end_index,
const MultiRange * full_range = 0 )

Initialize.

Parameters
nameName of this group (only for error reporting).
idsSet of Identifiers comprising this group.
end_indexThe ending index for the context for this group.
full_rangeThe MultiRange corresponding to this group. If supplied, the side of the ids set is checked against the range's cardinality.
Returns
0 on success; non-zero on failure.

Definition at line 41 of file CaloIDHelper.cxx.

45{
47 if (full_range && full_range->cardinality() != ids.size()) {
48 MsgStream log(Athena::getMessageSvc(), name);
49 log << MSG::ERROR << "set size " << ids.size()
50 << " not equal to hash max " << full_range->cardinality() << endmsg;
51 return 1;
52 }
53 m_id_vec.assign (ids.begin(), ids.end());
54 return 0;
55}
#define endmsg
const std::vector< Identifier > & ids() const
Return a vector of all Identifiers for this group.
size_type end_index() const
Return the ending index of the context for this group.
const std::string & name() const
Return the name for this helper.
size_type cardinality() const
Computes a possible cardinality from all ranges.
IMessageSvc * getMessageSvc(bool quiet=false)

◆ init() [2/2]

template<class T>
int CaloIDHelper::HashGroup::init ( T & parent,
const std::string & type,
const MultiRange & full_range,
Identifier(T::* idfunc )(const ExpandedIdentifier &) const,
size_type end_index )

Initialize.

Parameters
parentThe parent ID helper (in which idfunc is defined).
typeA string to add on to the name.
full_rangeThe MultiRange for to this group.
idfuncFunction to convert from an ExpandedIdentifier to an Identifier for this group.
end_indexThe ending index for the context for this group.
Returns
0 on success; non-zero on failure.

◆ range()

id_range CaloIDHelper::HashGroup::range ( ) const

Return an iterator range over the group's Identifiers.

Member Data Documentation

◆ m_end_index

size_type CaloIDHelper::HashGroup::m_end_index
private

Ending index for this group's context.

Definition at line 152 of file CaloIDHelper.h.

◆ m_id_vec

std::vector<Identifier> CaloIDHelper::HashGroup::m_id_vec
private

List of Identifiers for this group.

Definition at line 149 of file CaloIDHelper.h.


The documentation for this class was generated from the following files: