ATLAS Offline Software
Loading...
Searching...
No Matches
IdHashTableHelper.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5/***************************************************************************
6 * Identifier Hashes
7 * -----------------------------------------
8 *
9 * Author : Martin Woudstra
10 * Creation Date: 03 May 2004
11 * Last Update : 27 April 2005
12 ***************************************************************************/
13
15
16#ifndef MUONCALIBIDENTIFIER_IDHASHTABLEHELPER_H
17# define MUONCALIBIDENTIFIER_IDHASHTABLEHELPER_H
18// std
19#include <limits.h>
20// other packages
21// this package
22
23template < unsigned int N, class ID, class HASH >
25public:
26 //
27 // nested types
28 //
31 enum { NFIELDS = N, NMAX=UINT_MAX };
35 typedef HASH HashType;
37 typedef HASH ValueType;
38 //
39 // Member functions
40 //
44 explicit IdHashTableHelper( const IdentifierType& id );
46 explicit IdHashTableHelper( int fields[N] );
50 const IdentifierType& getId() const;
52 void setId( const IdentifierType& id );
54 int operator[]( unsigned int fieldIndex ) const;
56 void setField( int index, int value );
58 void setFields( int fields[N] );
63 static void setDefaults( const IdentifierType& defId, const HashType& defHash );
64 /* Return whether identifier is valid by comparing it with the default.
65 Can be overloaded in derived class (probably not needed). */
66 static bool isValid( const IdentifierType& );
73private:
74 //
75 // Member data
76 //
78 int m_fields[N]; // the expanded identifier fields to use as indices
79 //
80 // Static members
81 //
84};
85
86template < unsigned int N, class ID, class HASH >
88 for ( unsigned int i = 0; i < N; ++i ) m_fields[i] = INT_MAX;
89}
90
91template < unsigned int N, class ID, class HASH >
92inline
95 : m_id(id)
96{
97 for ( unsigned int i = 0; i < N; ++i ) m_fields[i] = INT_MAX;
98}
99
100template < unsigned int N, class ID, class HASH >
102 for ( unsigned int i = 0; i < N; ++i ) m_fields[i] = fields[i];
103}
104
105template < unsigned int N, class ID, class HASH >
107 // nothing to do
108}
109
110template < unsigned int N, class ID, class HASH >
111inline int IdHashTableHelper<N,ID,HASH>::operator[]( unsigned int index ) const {
112 return m_fields[index];
113}
114
115template < unsigned int N, class ID, class HASH >
118 return m_id;
119}
120
121template < unsigned int N, class ID, class HASH >
122inline void
126
127template < unsigned int N, class ID, class HASH >
128inline void IdHashTableHelper<N,ID,HASH>::setField( int index, int value ) {
129 m_fields[index] = value;
130}
131
132template < unsigned int N, class ID, class HASH >
133inline void IdHashTableHelper<N,ID,HASH>::setFields( int fields[N] ) {
134 for ( unsigned int i = 0; i < N; ++i ) m_fields[i] = fields[i];
135}
136
137template < unsigned int N, class ID, class HASH >
140 const typename IdHashTableHelper<N,ID,HASH>::HashType& defHash ) {
141 s_defaultId = defId;
142 s_defaultHash = defHash;
143}
144
145template < unsigned int N, class ID, class HASH >
150
151template < unsigned int N, class ID, class HASH >
156
157template < unsigned int N, class ID, class HASH >
162
163template < unsigned int N, class ID, class HASH >
165 return id != s_defaultId;
166}
167
168//
169// static members
170//
171template < unsigned int N, class ID, class HASH >
175
176template < unsigned int N, class ID, class HASH >
180
181#endif // MUONCALIBIDENTIFIER_IDHASHTABLEHELPER_H
std::vector< Identifier > ID
@ HASH
Definition RegSelEnums.h:51
void setFields(int fields[N])
Set fields from array.
IdHashTableHelper(int fields[N])
Constructor to initialise fields.
HASH ValueType
needed for MultiDimArray<> instantiation
static void setDefaults(const IdentifierType &defId, const HashType &defHash)
Set the default (invalid) values for identifier and hash.
ID IdentifierType
define type IdentifierType
static ValueType defaultValue()
Return default hash.
static bool isValid(const IdentifierType &)
virtual ~IdHashTableHelper()
virtual destructor needed because of derivation
void setField(int index, int value)
Set field at index to value.
const IdentifierType & getId() const
Get the identifier.
HASH HashType
define type HashType
void setId(const IdentifierType &id)
Set (only) the identifier.
IdHashTableHelper()
Default constructor.
static HashType defaultHash()
Returns default (=invalid) hash.
static IdentifierType defaultIdentifier()
Return default (=invalid) identifier.
int operator[](unsigned int fieldIndex) const
Return the value encoded in field.
IdHashTableHelper(const IdentifierType &id)
Constructor to initialise identifier.
Definition index.py:1