5#ifndef MUONCALIBIDENTIFIER_IDENTIFIERTOHASH_H
6#define MUONCALIBIDENTIFIER_IDENTIFIERTOHASH_H
18#include "GaudiKernel/MsgStream.h"
49 typedef typename T::IdentifierType
IdType;
56 return T::defaultHash();
61 template <
unsigned int N,
class K >
64 static const typename K::ValueType&
getConstRef(
const K& obj,
const T& indices ) {
65 int idx = indices[N-1];
66#ifdef IDENTIFIERTOHASH_DEBUG
68 log<<MSG::DEBUG<<
"[" << idx <<
"]"<<
endmsg;
72 static typename K::ValueType&
getRef( K& obj,
const T& indices ) {
73 int idx = indices[N-1];
74#ifdef IDENTIFIERTOHASH_DEBUG
75 log<<MSG::DEBUG<<
"{" << idx <<
"}"<<
endmsg;
85 static const typename K::ValueType&
getConstRef(
const K& obj,
const T& indices ) {
87#ifdef IDENTIFIERTOHASH_DEBUG
89 log<<MSG::DEBUG<<
"[" << idx <<
"]"<<
endmsg;
93 static typename K::ValueType&
getRef( K& obj,
const T& indices ) {
95#ifdef IDENTIFIERTOHASH_DEBUG
96 log<<MSG::DEBUG<<
"{" << idx <<
"}"<<
endmsg;
109 template <
unsigned int N,
class K>
112 static bool isInRange(
const K& obj,
const T& indices ) {
113 int idx = indices[N-1];
114 bool bOK = obj.isInRange( idx );
115#ifdef IDENTIFIERTOHASH_DEBUG
117 log<<MSG::DEBUG<<
"(" << idx <<
")"<<
endmsg;
119 log<<MSG::DEBUG<<
" CHECK: " << idx <<
" Out of range (" << obj.minIndex() <<
"," << obj.maxIndex() <<
")"<<
endmsg;
130 static bool isInRange(
const K& obj,
const T& indices ) {
131 int idx = indices[0];
132 bool bOK = obj.isInRange( idx );
133#ifdef IDENTIFIERTOHASH_DEBUG
135 log<<MSG::DEBUG<<
"(" << idx <<
")"<<
endmsg;
137 log<<MSG::DEBUG<<
" CHECK: Out of range (" << obj.minIndex() <<
"," << obj.maxIndex() <<
")"<<
endmsg;
139 log<<MSG::DEBUG<<
" CHECK: Range OK"<<
endmsg;
160 unsigned int size()
const;
179 void dump( std::ostream& os = std::cout )
const;
202#ifdef IDENTIFIERTOHASH_DEBUG
204 log<<MSG::DEBUG<<
"IdentifierToHash<T>::addEntry(0x" << std::hex <<
id << std::dec <<
"," << aHash <<
")"<<
endmsg;
206 if ( !T::isValid(
id ) ) {
207#ifdef IDENTIFIERTOHASH_DEBUG
208 log<<MSG::DEBUG<<
": id is invalid. Nothing added."<<
endmsg;
212 m_idFields.setAll(
id );
214 log<<MSG::DEBUG<<
"::IdToHashTable"<<
endmsg;
218 RecursiveIndexCall< NFIELDS, ArrayType >::getRef( m_data, m_idFields );
220 if ( hashRef != defaultHashValue() ) {
221#ifdef IDENTIFIERTOHASH_DEBUG
222 log<<MSG::WARNING<<
"id already taken by hash=" << hashRef <<
". Nothing added."<<
endmsg;
228#ifdef IDENTIFIERTOHASH_DEBUG
240 HashType aHash = m_entries;
241 if ( !addEntry(
id, aHash ) )
return defaultHashValue();
271 return m_data.totalSize();
276 std::ostream& os )
const {
294 return m_data.dumpToString();
static const K::ValueType & getConstRef(const K &obj, const T &indices)
static K::ValueType & getRef(K &obj, const T &indices)
Helper class for IdentifierToHash to automate recursive index call.
static const K::ValueType & getConstRef(const K &obj, const T &indices)
static K::ValueType & getRef(K &obj, const T &indices)
static bool isInRange(const K &obj, const T &indices)
Helper class for one-go recursive range check on all indices.
static bool isInRange(const K &obj, const T &indices)
T::HashType HashType
define type HashType
HashType addEntry(const IdType &id)
Add an identifier to the table, and return the hash value belonging to it.
T::IdentifierType IdType
define type IdType
void clear()
Clear the hashtable.
static HashType defaultHashValue()
Helper function to get a properly initialised hash.
HashType getHash(const IdType &id) const
Get hash from 0 to size()-1.
void dumpOneEntry(const IdType &id, std::ostream &os) const
Dump one entry for given id to os.
unsigned int size() const
Number of valid hashes in the table.
MultiDimArray< T, NFIELDS > ArrayType
define type ArrayType
std::string dumpToString() const
Dump complete table into a string.
IdentifierToHash()
Default constructor makes empty hash table and creates default idFields object.
unsigned int totalSize() const
Total number of hashes in the table.
std::string dumpOneEntryToString(const IdType &id) const
Dump one entry for given id to a string.
bool addEntry(const IdType &id, const HashType &aHash)
Add an identifier+hash pair to the table.
void dump(std::ostream &os=std::cout) const
Dump complete table to output stream.
Multi-dimensional array with a compile-time number of dimensions, and a run-time complete freedom ove...
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)