ATLAS Offline Software
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 
20 class IdDictRange;
21 
58 {
59 public:
60 
63 
64  typedef enum
65  {
66  NBITS = sizeof(value_type) * 8, // bits per byte
67  MAX_BIT = (static_cast<value_type>(1) << (NBITS - 1)),
68  ALL_BITS = ~(static_cast<value_type>(0))
70 
72 
74  int unpack (Identifier id) const; // access to field value
75  size_type unpackToIndex (Identifier id) const; // access to field index, i.e. from 0
76  void pack (int value, Identifier& id) const;
77  void reset (Identifier& id) const; // reset field bits
78 
80  const IdDictRange* range() const;
81  const Range::field& field() const;
82  const Range::field& ored_field() const;
83  size_type bits() const;
84  size_type bits_offset() const;
85  size_type mask() const;
86  value_type zeroing_mask() const;
87  size_type shift() const;
88  bool decode_index() const;
89 
91  void set_range (const IdDictRange* range);
92  void set_field (const Range::field& field);
96  void set_decode_index (bool decode_index);
97  void optimize (void);
98 
99  // Printout
100  void show (void) const;
101  std::string show_to_string (void) const;
102 
103 private:
104 
105  // Initialize derived fields
106  void initialize();
107 
117 
118 };
119 
120 
121 //<<<<<< INLINE MEMBER FUNCTIONS >>>>>>
122 
123 //-----------------------------------------------------------------
125 //-----------------------------------------------------------------
126  :
127  m_range(0),
128  m_field(0),
129  m_ored_field(0),
130  m_bits(0),
131  m_bits_offset(0),
132  m_mask(0),
133  m_zeroing_mask(0),
134  m_shift(0),
135  m_decode_index(0)
136 {}
137 
138 
146 //-----------------------------------------------------------------
148 //-----------------------------------------------------------------
149 {
150  // Unpack field
151  size_type index = id.extract(m_shift, m_mask);
152  int field = index;
153  if (m_decode_index) field = m_ored_field.get_value_at (index);
154  return (field);
155 }
156 
157 
163 //-----------------------------------------------------------------
165 //-----------------------------------------------------------------
166 {
167  // Unpack field
168  size_type index = id.extract(m_shift, m_mask);
169  return (index);
170 }
171 
172 //-----------------------------------------------------------------
174 //-----------------------------------------------------------------
175 {
176  // Pack value into this field
178  if (m_decode_index) index = m_ored_field.get_value_index (value);
179  id |= (index << m_shift);
180 }
181 
182 //-----------------------------------------------------------------
184 //-----------------------------------------------------------------
185 {
186  // Reset field to 0
187  id &= m_zeroing_mask;
188 }
189 
190 //-----------------------------------------------------------------
192 //-----------------------------------------------------------------
193 { return (m_field); }
194 
195 //-----------------------------------------------------------------
197 //-----------------------------------------------------------------
198 { return (m_ored_field); }
199 
200 //-----------------------------------------------------------------
203 //-----------------------------------------------------------------
204 { return (m_bits); }
205 
206 //-----------------------------------------------------------------
209 //-----------------------------------------------------------------
210 { return (m_bits_offset); }
211 
212 //-----------------------------------------------------------------
215 //-----------------------------------------------------------------
216 { return (m_mask); }
217 
218 //-----------------------------------------------------------------
221 //-----------------------------------------------------------------
222 { return (m_zeroing_mask); }
223 
224 //-----------------------------------------------------------------
227 //-----------------------------------------------------------------
228 { return (m_shift); }
229 
230 //-----------------------------------------------------------------
232 //-----------------------------------------------------------------
233 { return (m_decode_index); }
234 
235 //-----------------------------------------------------------------
237 //-----------------------------------------------------------------
238 {
239  // Initialize masks and shift
240  m_mask = (static_cast<size_type>(1) << m_bits) - 1;
242 
243  // Shifting by NBITS is undefined behavior.
246  else
248 }
249 
250 //-----------------------------------------------------------------
252 //-----------------------------------------------------------------
253 {
254  m_field = field;
255 }
256 
257 
258 //-----------------------------------------------------------------
260 //-----------------------------------------------------------------
261 {
262  // Set ored field and bits, and init
265  initialize();
266 }
267 
268 //-----------------------------------------------------------------
270 //-----------------------------------------------------------------
271 {
272  // Set offset and init
274  initialize();
275 }
276 
277 //-----------------------------------------------------------------
279 //-----------------------------------------------------------------
280 {
281  // Set bits, offset and init
282  m_bits = bits;
284  initialize();
285 }
286 
287 //-----------------------------------------------------------------
288 inline void IdDictFieldImplementation::set_decode_index (bool decode_index)
289 //-----------------------------------------------------------------
290 {
292 }
293 
295 {
296  m_ored_field.optimize(); // optimize for decoding
297 }
298 
299 #endif // IDDICT_IDDICTFIELDIMPLEMENTATION_H
IdDictFieldImplementation::bit_defs
bit_defs
Definition: IdDictFieldImplementation.h:65
IdDictFieldImplementation::value_type
Identifier::value_type value_type
Definition: IdDictFieldImplementation.h:61
IdDictFieldImplementation::set_field
void set_field(const Range::field &field)
Definition: IdDictFieldImplementation.h:251
IdDictFieldImplementation::IdDictFieldImplementation
IdDictFieldImplementation()
Definition: IdDictFieldImplementation.h:124
IdentifierField::get_bits
size_type get_bits() const
Definition: IdentifierField.cxx:40
IdDictFieldImplementation::show_to_string
std::string show_to_string(void) const
Definition: IdDictFieldImplementation.cxx:38
IdDictFieldImplementation::initialize
void initialize()
Definition: IdDictFieldImplementation.h:236
index
Definition: index.py:1
IdDictFieldImplementation::m_field
Range::field m_field
Definition: IdDictFieldImplementation.h:109
Range.h
IdDictFieldImplementation::pack
void pack(int value, Identifier &id) const
Definition: IdDictFieldImplementation.h:173
athena.value
value
Definition: athena.py:124
IdDictFieldImplementation::decode_index
bool decode_index() const
Definition: IdDictFieldImplementation.h:231
ReadOfcFromCool.field
field
Definition: ReadOfcFromCool.py:48
const
bool const RAWDATA *ch2 const
Definition: LArRodBlockPhysicsV0.cxx:560
IdDictFieldImplementation::m_decode_index
bool m_decode_index
Definition: IdDictFieldImplementation.h:116
IdDictFieldImplementation::m_range
const IdDictRange * m_range
Definition: IdDictFieldImplementation.h:108
IdDictFieldImplementation::unpack
int unpack(Identifier id) const
Identifier manipulation methods.
Definition: IdDictFieldImplementation.h:147
IdDictFieldImplementation::set_bits_offset
void set_bits_offset(size_type bits_offset)
Definition: IdDictFieldImplementation.h:269
m_range
float m_range[NbCaloPart][2]
Definition: CellClusterLinkTool.h:55
IdDictFieldImplementation::reset
void reset(Identifier &id) const
Definition: IdDictFieldImplementation.h:183
IdDictFieldImplementation::m_bits_offset
size_type m_bits_offset
Definition: IdDictFieldImplementation.h:112
IdDictFieldImplementation::m_mask
size_type m_mask
Definition: IdDictFieldImplementation.h:113
IdDictFieldImplementation::unpackToIndex
size_type unpackToIndex(Identifier id) const
Unpack a single field index of the id.
Definition: IdDictFieldImplementation.h:164
IdDictFieldImplementation::shift
size_type shift() const
Definition: IdDictFieldImplementation.h:226
IdDictFieldImplementation::field
const Range::field & field() const
Definition: IdDictFieldImplementation.h:191
IdDictFieldImplementation::set_ored_field
void set_ored_field(const Range::field &ored_field)
Definition: IdDictFieldImplementation.h:259
IdDictFieldImplementation::m_zeroing_mask
value_type m_zeroing_mask
Definition: IdDictFieldImplementation.h:114
IdDictFieldImplementation::set_bits
void set_bits(size_type bits, size_type bits_offset)
Definition: IdDictFieldImplementation.h:278
IdDictFieldImplementation::ALL_BITS
@ ALL_BITS
Definition: IdDictFieldImplementation.h:68
IdDictFieldImplementation::optimize
void optimize(void)
Definition: IdDictFieldImplementation.h:294
IdDictFieldImplementation::bits_offset
size_type bits_offset() const
Definition: IdDictFieldImplementation.h:208
IdDictFieldImplementation::ored_field
const Range::field & ored_field() const
Definition: IdDictFieldImplementation.h:196
IdDictFieldImplementation::range
const IdDictRange * range() const
Accessors.
Definition: IdDictFieldImplementation.cxx:25
IdDictFieldImplementation::show
void show(void) const
Definition: IdDictFieldImplementation.cxx:33
IdDictFieldImplementation::set_range
void set_range(const IdDictRange *range)
Modifiers.
Definition: IdDictFieldImplementation.cxx:28
IdDictFieldImplementation::m_bits
size_type m_bits
Definition: IdDictFieldImplementation.h:111
IdDictRange
Definition: IdDictRange.h:18
DeMoScan.index
string index
Definition: DeMoScan.py:364
IdDictFieldImplementation::zeroing_mask
value_type zeroing_mask() const
Definition: IdDictFieldImplementation.h:220
IdDictFieldImplementation::set_decode_index
void set_decode_index(bool decode_index)
Definition: IdDictFieldImplementation.h:288
IdentifierField
This is the individual specification for the range of one ExpandedIdentifier IdentifierField.
Definition: IdentifierField.h:21
IdDictFieldImplementation::MAX_BIT
@ MAX_BIT
Definition: IdDictFieldImplementation.h:67
IdDictFieldImplementation::NBITS
@ NBITS
Definition: IdDictFieldImplementation.h:66
Identifier::value_type
unsigned long long value_type
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:27
IdDictFieldImplementation::m_ored_field
Range::field m_ored_field
Definition: IdDictFieldImplementation.h:110
Identifier::size_type
unsigned long long size_type
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:29
IdentifierField::optimize
void optimize()
Optimize - try to switch mode to both_bounded, set up lookup table for finding index from value.
Definition: IdentifierField.cxx:422
IdDictFieldImplementation
IdDictFieldImplementation is used to capture the specification of a single field of an Identifier.
Definition: IdDictFieldImplementation.h:58
value_type
Definition: EDM_MasterSearch.h:11
IdDictFieldImplementation::m_shift
size_type m_shift
Definition: IdDictFieldImplementation.h:115
IdDictFieldImplementation::mask
size_type mask() const
Definition: IdDictFieldImplementation.h:214
IdDictFieldImplementation::size_type
Identifier::size_type size_type
Definition: IdDictFieldImplementation.h:62
IdDictFieldImplementation::bits
size_type bits() const
Definition: IdDictFieldImplementation.h:202
Identifier
Definition: IdentifierFieldParser.cxx:14