ATLAS Offline Software
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 
16 #ifndef MUONCALIBIDENTIFIER_IDHASHTABLEHELPER_H
17 # define MUONCALIBIDENTIFIER_IDHASHTABLEHELPER_H
18 // std
19 #include <limits.h>
20 // other packages
21 // this package
22 
23 template < unsigned int N, class ID, class HASH >
25 public:
26  //
27  // nested types
28  //
31  enum { NFIELDS = N, NMAX=UINT_MAX };
33  typedef ID IdentifierType;
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] );
48  virtual ~IdHashTableHelper();
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& );
68  static HashType defaultHash();
72  static ValueType defaultValue();
73 private:
74  //
75  // Member data
76  //
78  int m_fields[N]; // the expanded identifier fields to use as indices
79  //
80  // Static members
81  //
83  static HashType s_defaultHash;
84 };
85 
86 template < unsigned int N, class ID, class HASH >
88  for ( unsigned int i = 0; i < N; ++i ) m_fields[i] = INT_MAX;
89 }
90 
91 template < unsigned int N, class ID, class HASH >
92 inline
95  : m_id(id)
96 {
97  for ( unsigned int i = 0; i < N; ++i ) m_fields[i] = INT_MAX;
98 }
99 
100 template < unsigned int N, class ID, class HASH >
102  for ( unsigned int i = 0; i < N; ++i ) m_fields[i] = fields[i];
103 }
104 
105 template < unsigned int N, class ID, class HASH >
107  // nothing to do
108 }
109 
110 template < unsigned int N, class ID, class HASH >
111 inline int IdHashTableHelper<N,ID,HASH>::operator[]( unsigned int index ) const {
112  return m_fields[index];
113 }
114 
115 template < unsigned int N, class ID, class HASH >
118  return m_id;
119 }
120 
121 template < unsigned int N, class ID, class HASH >
122 inline void
124  m_id = id;
125 }
126 
127 template < unsigned int N, class ID, class HASH >
129  m_fields[index] = value;
130 }
131 
132 template < unsigned int N, class ID, class HASH >
134  for ( unsigned int i = 0; i < N; ++i ) m_fields[i] = fields[i];
135 }
136 
137 template < unsigned int N, class ID, class HASH >
139  const typename IdHashTableHelper<N,ID,HASH>::IdentifierType& defId,
140  const typename IdHashTableHelper<N,ID,HASH>::HashType& defHash ) {
141  s_defaultId = defId;
142  s_defaultHash = defHash;
143 }
144 
145 template < unsigned int N, class ID, class HASH >
148  return s_defaultHash;
149 }
150 
151 template < unsigned int N, class ID, class HASH >
154  return s_defaultId;
155 }
156 
157 template < unsigned int N, class ID, class HASH >
160  return defaultHash();
161 }
162 
163 template < unsigned int N, class ID, class HASH >
165  return id != s_defaultId;
166 }
167 
168 //
169 // static members
170 //
171 template < unsigned int N, class ID, class HASH >
175 
176 template < unsigned int N, class ID, class HASH >
180 
181 #endif // MUONCALIBIDENTIFIER_IDHASHTABLEHELPER_H
IdHashTableHelper::m_fields
int m_fields[N]
Definition: IdHashTableHelper.h:85
IdHashTableHelper::m_id
IdentifierType m_id
Definition: IdHashTableHelper.h:84
IdHashTableHelper::~IdHashTableHelper
virtual ~IdHashTableHelper()
virtual destructor needed because of derivation
Definition: IdHashTableHelper.h:106
ID
std::vector< Identifier > ID
Definition: CalibHitIDCheck.h:24
IdHashTableHelper::isValid
static bool isValid(const IdentifierType &)
Definition: IdHashTableHelper.h:164
index
Definition: index.py:1
IdHashTableHelper::setField
void setField(int index, int value)
Set field at index to value.
Definition: IdHashTableHelper.h:128
IdHashTableHelper::setFields
void setFields(int fields[N])
Set fields from array.
Definition: IdHashTableHelper.h:133
IdHashTableHelper::operator[]
int operator[](unsigned int fieldIndex) const
Return the value encoded in field.
Definition: IdHashTableHelper.h:111
IdHashTableHelper::NFIELDS
@ NFIELDS
Definition: IdHashTableHelper.h:45
athena.value
value
Definition: athena.py:124
IdHashTableHelper::defaultIdentifier
static IdentifierType defaultIdentifier()
Return default (=invalid) identifier.
Definition: IdHashTableHelper.h:153
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
IdHashTableHelper::s_defaultId
static IdentifierType s_defaultId
Definition: IdHashTableHelper.h:89
IdHashTableHelper::getId
const IdentifierType & getId() const
Get the identifier.
Definition: IdHashTableHelper.h:117
lumiFormat.i
int i
Definition: lumiFormat.py:85
IdHashTableHelper::ValueType
HASH ValueType
needed for MultiDimArray<> instantiation
Definition: IdHashTableHelper.h:44
IdHashTableHelper::NMAX
@ NMAX
Definition: IdHashTableHelper.h:45
HASH
@ HASH
Definition: RegSelEnums.h:51
IdHashTableHelper::IdentifierType
ID IdentifierType
define type IdentifierType
Definition: IdHashTableHelper.h:40
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
IdHashTableHelper::IdHashTableHelper
IdHashTableHelper()
Default constructor.
Definition: IdHashTableHelper.h:87
IdHashTableHelper::defaultHash
static HashType defaultHash()
Returns default (=invalid) hash.
Definition: IdHashTableHelper.h:147
IdHashTableHelper::setDefaults
static void setDefaults(const IdentifierType &defId, const HashType &defHash)
Set the default (invalid) values for identifier and hash.
Definition: IdHashTableHelper.h:138
DeMoScan.index
string index
Definition: DeMoScan.py:364
IdHashTableHelper::s_defaultHash
static HashType s_defaultHash
Definition: IdHashTableHelper.h:90
IdHashTableHelper
Helper base class for instantiation of templated class IdentifierHashTable.
Definition: IdHashTableHelper.h:24
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
IdHashTableHelper::HashType
HASH HashType
define type HashType
Definition: IdHashTableHelper.h:42
IdHashTableHelper::defaultValue
static ValueType defaultValue()
Return default hash.
Definition: IdHashTableHelper.h:159
IdHashTableHelper::setId
void setId(const IdentifierType &id)
Set (only) the identifier.
Definition: IdHashTableHelper.h:123