ATLAS Offline Software
Loading...
Searching...
No Matches
IdDictFieldImplementation.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
5/***************************************************************************
6 IdDict package
7 ***************************************************************************/
8
9//<doc><file> $Id: IdDictFieldImplementation.h,v 1.2 2007-11-08 21:21:47 ssnyder Exp $
10//<version> $Name: not supported by cvs2svn $
11
12#ifndef IDDICT_IDDICTFIELDIMPLEMENTATION_H
13# define IDDICT_IDDICTFIELDIMPLEMENTATION_H
14
15//<<<<<< INCLUDES >>>>>>
16
17#include "Identifier/Identifier.h"
18#include "Identifier/Range.h"
19#include <iosfwd>
20class IdDictRange;
21class MsgStream;
22
56
57
59{
60public:
61
62 typedef Identifier::value_type value_type;
63 typedef Identifier::size_type size_type;
64
65 typedef enum
66 {
67 NBITS = sizeof(value_type) * 8, // bits per byte
68 MAX_BIT = (static_cast<value_type>(1) << (NBITS - 1)),
69 ALL_BITS = ~(static_cast<value_type>(0))
70 } bit_defs;
71
73
75 int unpack (Identifier id) const; // access to field value
76 size_type unpackToIndex (Identifier id) const; // access to field index, i.e. from 0
77 void pack (int value, Identifier& id) const;
78 void reset (Identifier& id) const; // reset field bits
79
81 const IdDictRange* range() const;
82 const Range::field& field() const;
83 const Range::field& ored_field() const;
84 size_type bits() const;
85 size_type bits_offset() const;
86 size_type mask() const;
87 value_type zeroing_mask() const;
88 size_type shift() const;
89 bool decode_index() const;
90
92 void set_range (const IdDictRange* range);
93 void set_field (const Range::field& field);
98 void optimize (void);
99
100 // Printout
101 void show (void) const;
102 std::string show_to_string (void) const;
103
104private:
105
106 // Initialize derived fields
107 void initialize();
108
118
119};
120
122std::ostream & operator<<(std::ostream & os, const IdDictFieldImplementation &);
124MsgStream & operator<<(MsgStream & ms, const IdDictFieldImplementation &);
125
126//<<<<<< INLINE MEMBER FUNCTIONS >>>>>>
127
128//-----------------------------------------------------------------
130//-----------------------------------------------------------------
131 :
132 m_range(0),
133 m_field(0),
134 m_ored_field(0),
135 m_bits(0),
136 m_bits_offset(0),
137 m_mask(0),
138 m_zeroing_mask(0),
139 m_shift(0),
141{}
142
143
151//-----------------------------------------------------------------
153//-----------------------------------------------------------------
154{
155 // Unpack field
156 size_type index = id.extract(m_shift, m_mask);
157 int field = index;
158 if (m_decode_index) field = m_ored_field.get_value_at (index);
159 return (field);
160}
161
162
168//-----------------------------------------------------------------
169inline Identifier::size_type IdDictFieldImplementation::unpackToIndex (Identifier id) const
170//-----------------------------------------------------------------
171{
172 // Unpack field
173 size_type index = id.extract(m_shift, m_mask);
174 return (index);
175}
176
177//-----------------------------------------------------------------
178inline void IdDictFieldImplementation::pack (int value, Identifier& id) const
179//-----------------------------------------------------------------
180{
181 // Pack value into this field
182 size_type index = (size_type)value;
183 if (m_decode_index) index = m_ored_field.get_value_index (value);
184 id |= (index << m_shift);
185}
186
187//-----------------------------------------------------------------
189//-----------------------------------------------------------------
190{
191 // Reset field to 0
192 id &= m_zeroing_mask;
193}
194
195//-----------------------------------------------------------------
197//-----------------------------------------------------------------
198{ return (m_field); }
199
200//-----------------------------------------------------------------
202//-----------------------------------------------------------------
203{ return (m_ored_field); }
204
205//-----------------------------------------------------------------
208//-----------------------------------------------------------------
209{ return (m_bits); }
210
211//-----------------------------------------------------------------
214//-----------------------------------------------------------------
215{ return (m_bits_offset); }
216
217//-----------------------------------------------------------------
220//-----------------------------------------------------------------
221{ return (m_mask); }
222
223//-----------------------------------------------------------------
226//-----------------------------------------------------------------
227{ return (m_zeroing_mask); }
228
229//-----------------------------------------------------------------
232//-----------------------------------------------------------------
233{ return (m_shift); }
234
235//-----------------------------------------------------------------
237//-----------------------------------------------------------------
238{ return (m_decode_index); }
239
240//-----------------------------------------------------------------
242//-----------------------------------------------------------------
243{
244 // Initialize masks and shift
245 m_mask = (static_cast<size_type>(1) << m_bits) - 1;
247
248 // Shifting by NBITS is undefined behavior.
251 else
253}
254
255//-----------------------------------------------------------------
257//-----------------------------------------------------------------
258{
259 m_field = field;
260}
261
262
263//-----------------------------------------------------------------
265//-----------------------------------------------------------------
266{
267 // Set ored field and bits, and init
269 m_bits = m_ored_field.get_bits();
270 initialize();
271}
272
273//-----------------------------------------------------------------
275//-----------------------------------------------------------------
276{
277 // Set offset and init
279 initialize();
280}
281
282//-----------------------------------------------------------------
284//-----------------------------------------------------------------
285{
286 // Set bits, offset and init
287 m_bits = bits;
289 initialize();
290}
291
292//-----------------------------------------------------------------
294//-----------------------------------------------------------------
295{
297}
298
300{
301 m_ored_field.optimize(); // optimize for decoding
302}
303
304#endif // IDDICT_IDDICTFIELDIMPLEMENTATION_H
std::ostream & operator<<(std::ostream &os, const IdDictFieldImplementation &)
stream insertion operator uses show_to_string
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
const IdDictRange * range() const
Accessors.
void reset(Identifier &id) const
void set_bits_offset(size_type bits_offset)
void set_range(const IdDictRange *range)
Modifiers.
void set_ored_field(const Range::field &ored_field)
void set_field(const Range::field &field)
const Range::field & ored_field() const
void pack(int value, Identifier &id) const
size_type unpackToIndex(Identifier id) const
Unpack a single field index of the id.
std::string show_to_string(void) const
void set_decode_index(bool decode_index)
void set_bits(size_type bits, size_type bits_offset)
int unpack(Identifier id) const
Identifier manipulation methods.
const Range::field & field() const
Definition index.py:1