ATLAS Offline Software
Loading...
Searching...
No Matches
IdDictFieldImplementation.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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 Identifier new_pack (int value) const; //pack to a new Identifier
79 void reset (Identifier& id) const; // reset field bits
80
82 const IdDictRange* range() const;
83 const Range::field& field() const;
84 const Range::field& ored_field() const;
85 size_type bits() const;
86 size_type bits_offset() const;
87 size_type mask() const;
88 value_type zeroing_mask() const;
89 size_type shift() const;
90 bool decode_index() const;
91
93 void set_range (const IdDictRange* range);
94 void set_field (const Range::field& field);
99 void optimize (void);
100
101 // Printout
102 void show (void) const;
103 std::string show_to_string (void) const;
104
105private:
106
107 // Initialize derived fields
108 void initialize();
109
119
120};
121
123std::ostream & operator<<(std::ostream & os, const IdDictFieldImplementation &);
125MsgStream & operator<<(MsgStream & ms, const IdDictFieldImplementation &);
126
127//<<<<<< INLINE MEMBER FUNCTIONS >>>>>>
128
129//-----------------------------------------------------------------
131//-----------------------------------------------------------------
132 :
133 m_range(0),
134 m_field(0),
135 m_ored_field(0),
136 m_bits(0),
137 m_bits_offset(0),
138 m_mask(0),
139 m_zeroing_mask(0),
140 m_shift(0),
142{}
143
144
152//-----------------------------------------------------------------
154//-----------------------------------------------------------------
155{
156 // Unpack field
157 size_type index = id.extract(m_shift, m_mask);
158 int field = index;
159 if (m_decode_index) field = m_ored_field.get_value_at (index);
160 return (field);
161}
162
163
169//-----------------------------------------------------------------
170inline Identifier::size_type IdDictFieldImplementation::unpackToIndex (Identifier id) const
171//-----------------------------------------------------------------
172{
173 // Unpack field
174 size_type index = id.extract(m_shift, m_mask);
175 return (index);
176}
177
178//-----------------------------------------------------------------
179inline void IdDictFieldImplementation::pack (int value, Identifier& id) const
180//-----------------------------------------------------------------
181{
182 // Pack value into this field
183 size_type index = (size_type)value;
184 if (m_decode_index) index = m_ored_field.get_value_index (value);
185 id |= (index << m_shift);
186}
187
188//-----------------------------------------------------------------
190//-----------------------------------------------------------------
191{
192 // Pack value into this field
193 size_type index = (size_type)value;
194 if (m_decode_index) index = m_ored_field.get_value_index (value);
195 return Identifier(index << m_shift);
196}
197
198//-----------------------------------------------------------------
200//-----------------------------------------------------------------
201{
202 // Reset field to 0
203 id &= m_zeroing_mask;
204}
205
206//-----------------------------------------------------------------
208//-----------------------------------------------------------------
209{ return (m_field); }
210
211//-----------------------------------------------------------------
213//-----------------------------------------------------------------
214{ return (m_ored_field); }
215
216//-----------------------------------------------------------------
219//-----------------------------------------------------------------
220{ return (m_bits); }
221
222//-----------------------------------------------------------------
225//-----------------------------------------------------------------
226{ return (m_bits_offset); }
227
228//-----------------------------------------------------------------
231//-----------------------------------------------------------------
232{ return (m_mask); }
233
234//-----------------------------------------------------------------
237//-----------------------------------------------------------------
238{ return (m_zeroing_mask); }
239
240//-----------------------------------------------------------------
243//-----------------------------------------------------------------
244{ return (m_shift); }
245
246//-----------------------------------------------------------------
248//-----------------------------------------------------------------
249{ return (m_decode_index); }
250
251//-----------------------------------------------------------------
253//-----------------------------------------------------------------
254{
255 // Initialize masks and shift
256 m_mask = (static_cast<size_type>(1) << m_bits) - 1;
258
259 // Shifting by NBITS is undefined behavior.
262 else
264}
265
266//-----------------------------------------------------------------
268//-----------------------------------------------------------------
269{
270 m_field = field;
271}
272
273
274//-----------------------------------------------------------------
276//-----------------------------------------------------------------
277{
278 // Set ored field and bits, and init
280 m_bits = m_ored_field.get_bits();
281 initialize();
282}
283
284//-----------------------------------------------------------------
286//-----------------------------------------------------------------
287{
288 // Set offset and init
290 initialize();
291}
292
293//-----------------------------------------------------------------
295//-----------------------------------------------------------------
296{
297 // Set bits, offset and init
298 m_bits = bits;
300 initialize();
301}
302
303//-----------------------------------------------------------------
305//-----------------------------------------------------------------
306{
308}
309
311{
312 m_ored_field.optimize(); // optimize for decoding
313}
314
315#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.
Identifier new_pack(int value) const
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